OdbcDataReader.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. //
  2. // System.Data.Odbc.OdbcDataReader
  3. //
  4. // Author:
  5. // Brian Ritchie ([email protected])
  6. // Daniel Morgan <[email protected]>
  7. // Sureshkumar T <[email protected]> (2004)
  8. //
  9. // Copyright (C) Brian Ritchie, 2002
  10. // Copyright (C) Daniel Morgan, 2002
  11. //
  12. //
  13. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  14. //
  15. // Permission is hereby granted, free of charge, to any person obtaining
  16. // a copy of this software and associated documentation files (the
  17. // "Software"), to deal in the Software without restriction, including
  18. // without limitation the rights to use, copy, modify, merge, publish,
  19. // distribute, sublicense, and/or sell copies of the Software, and to
  20. // permit persons to whom the Software is furnished to do so, subject to
  21. // the following conditions:
  22. //
  23. // The above copyright notice and this permission notice shall be
  24. // included in all copies or substantial portions of the Software.
  25. //
  26. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  27. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  29. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  30. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  31. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  32. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  33. //
  34. using System.Collections;
  35. using System.ComponentModel;
  36. using System.Data;
  37. using System.Data.Common;
  38. using System.Text;
  39. namespace System.Data.Odbc
  40. {
  41. public sealed class OdbcDataReader : MarshalByRefObject, IDataReader, IDisposable, IDataRecord, IEnumerable
  42. {
  43. #region Fields
  44. private OdbcCommand command;
  45. private bool open;
  46. private int currentRow;
  47. private OdbcColumn[] cols;
  48. private IntPtr hstmt;
  49. private CommandBehavior behavior;
  50. #endregion
  51. #region Constructors
  52. internal OdbcDataReader (OdbcCommand command, CommandBehavior behavior)
  53. {
  54. this.command = command;
  55. this.behavior=behavior;
  56. open = true;
  57. currentRow = -1;
  58. hstmt=command.hStmt;
  59. // Init columns array;
  60. short colcount=0;
  61. libodbc.SQLNumResultCols(hstmt, ref colcount);
  62. cols=new OdbcColumn[colcount];
  63. GetSchemaTable ();
  64. }
  65. #endregion
  66. #region Properties
  67. public int Depth {
  68. get {
  69. return 0; // no nested selects supported
  70. }
  71. }
  72. public int FieldCount {
  73. get {
  74. return cols.Length;
  75. }
  76. }
  77. public bool IsClosed {
  78. get {
  79. return !open;
  80. }
  81. }
  82. public object this[string name] {
  83. get {
  84. int pos;
  85. if (currentRow == -1)
  86. throw new InvalidOperationException ();
  87. pos = ColIndex(name);
  88. if (pos == -1)
  89. throw new IndexOutOfRangeException ();
  90. return this[pos];
  91. }
  92. }
  93. public object this[int index] {
  94. get {
  95. return (object) GetValue (index);
  96. }
  97. }
  98. public int RecordsAffected {
  99. get {
  100. return -1;
  101. }
  102. }
  103. [MonoTODO]
  104. public bool HasRows {
  105. get { throw new NotImplementedException(); }
  106. }
  107. #endregion
  108. #region Methods
  109. private int ColIndex(string colname)
  110. {
  111. int i=0;
  112. foreach (OdbcColumn col in cols)
  113. {
  114. if (col != null && col.ColumnName==colname)
  115. return i;
  116. i++;
  117. }
  118. return -1;
  119. }
  120. // Dynamically load column descriptions as needed.
  121. private OdbcColumn GetColumn(int ordinal)
  122. {
  123. if (cols[ordinal]==null)
  124. {
  125. short bufsize=255;
  126. byte[] colname_buffer=new byte[bufsize];
  127. string colname;
  128. short colname_size=0;
  129. uint ColSize=0;
  130. short DecDigits=0, Nullable=0, dt=0;
  131. OdbcReturn ret=libodbc.SQLDescribeCol(hstmt, Convert.ToUInt16(ordinal+1),
  132. colname_buffer, bufsize, ref colname_size, ref dt, ref ColSize,
  133. ref DecDigits, ref Nullable);
  134. if ((ret!=OdbcReturn.Success) && (ret!=OdbcReturn.SuccessWithInfo))
  135. throw new OdbcException(new OdbcError("SQLDescribeCol",OdbcHandleType.Stmt,hstmt));
  136. colname=System.Text.Encoding.Default.GetString(colname_buffer);
  137. colname=colname.Replace((char) 0,' ').Trim();
  138. OdbcType t = libodbc.NativeToOdbcType ( (OdbcCType) dt);
  139. OdbcColumn c=new OdbcColumn(colname, t);
  140. c.AllowDBNull=(Nullable!=0);
  141. c.Digits=DecDigits;
  142. if (c.IsStringType)
  143. c.MaxLength=(int)ColSize;
  144. cols[ordinal]=c;
  145. }
  146. return cols[ordinal];
  147. }
  148. public void Close ()
  149. {
  150. // FIXME : have to implement output parameter binding
  151. OdbcReturn ret = libodbc.SQLFreeStmt (hstmt, libodbc.SQLFreeStmtOptions.Close);
  152. if ((ret!=OdbcReturn.Success) && (ret!=OdbcReturn.SuccessWithInfo))
  153. throw new OdbcException(new OdbcError("SQLCloseCursor",OdbcHandleType.Stmt,hstmt));
  154. open = false;
  155. currentRow = -1;
  156. ret = libodbc.SQLFreeHandle( (ushort) OdbcHandleType.Stmt, hstmt);
  157. if ((ret!=OdbcReturn.Success) && (ret!=OdbcReturn.SuccessWithInfo))
  158. throw new OdbcException(new OdbcError("SQLFreeHandle",OdbcHandleType.Stmt,hstmt));
  159. if ((behavior & CommandBehavior.CloseConnection)==CommandBehavior.CloseConnection)
  160. this.command.Connection.Close();
  161. }
  162. ~OdbcDataReader ()
  163. {
  164. if (open)
  165. Close ();
  166. }
  167. public bool GetBoolean (int ordinal)
  168. {
  169. return (bool) GetValue(ordinal);
  170. }
  171. public byte GetByte (int ordinal)
  172. {
  173. return (byte) Convert.ToByte(GetValue(ordinal));
  174. }
  175. public long GetBytes (int ordinal, long dataIndex, byte[] buffer, int bufferIndex, int length)
  176. {
  177. OdbcReturn ret = OdbcReturn.Error;
  178. bool copyBuffer = false;
  179. int returnVal = 0, outsize = 0;
  180. byte [] tbuff = new byte [length+1];
  181. length = buffer == null ? 0 : length;
  182. ret=libodbc.SQLGetData (hstmt, (ushort) (ordinal+1), OdbcCType.Binary, tbuff, length,
  183. ref outsize);
  184. if (ret == OdbcReturn.NoData)
  185. return 0;
  186. if ( (ret != OdbcReturn.Success) && (ret != OdbcReturn.SuccessWithInfo))
  187. throw new OdbcException (new OdbcError ("SQLGetData", OdbcHandleType.Stmt, hstmt));
  188. OdbcError odbcErr = null;
  189. if ( (ret == OdbcReturn.SuccessWithInfo))
  190. odbcErr = new OdbcError ("SQLGetData", OdbcHandleType.Stmt, hstmt);
  191. if (buffer == null)
  192. return outsize; //if buffer is null,return length of the field
  193. if (ret == OdbcReturn.SuccessWithInfo) {
  194. if (outsize == (int) OdbcLengthIndicator.NoTotal)
  195. copyBuffer = true;
  196. else if (outsize == (int) OdbcLengthIndicator.NullData) {
  197. copyBuffer = false;
  198. returnVal = -1;
  199. } else {
  200. string sqlstate = odbcErr.SQLState;
  201. //SQLState: String Data, Right truncated
  202. if (sqlstate != libodbc.SQLSTATE_RIGHT_TRUNC)
  203. throw new OdbcException ( odbcErr);
  204. copyBuffer = true;
  205. }
  206. } else {
  207. copyBuffer = outsize == -1 ? false : true;
  208. returnVal = outsize;
  209. }
  210. if (copyBuffer) {
  211. int i = 0;
  212. while (tbuff [i] != libodbc.C_NULL) {
  213. buffer [bufferIndex + i] = tbuff [i];
  214. i++;
  215. }
  216. returnVal = i;
  217. }
  218. return returnVal;
  219. }
  220. [MonoTODO]
  221. public char GetChar (int ordinal)
  222. {
  223. throw new NotImplementedException ();
  224. }
  225. [MonoTODO]
  226. public long GetChars (int ordinal, long dataIndex, char[] buffer, int bufferIndex, int length)
  227. {
  228. throw new NotImplementedException ();
  229. }
  230. [MonoTODO]
  231. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  232. public IDataReader GetData (int ordinal)
  233. {
  234. throw new NotImplementedException ();
  235. }
  236. public string GetDataTypeName (int index)
  237. {
  238. return GetColumn(index).OdbcType.ToString();
  239. }
  240. public DateTime GetDate(int ordinal) {
  241. return GetDateTime(ordinal);
  242. }
  243. public DateTime GetDateTime (int ordinal)
  244. {
  245. return (DateTime) GetValue(ordinal);
  246. }
  247. [MonoTODO]
  248. public decimal GetDecimal (int ordinal)
  249. {
  250. throw new NotImplementedException ();
  251. }
  252. public double GetDouble (int ordinal)
  253. {
  254. return (double) GetValue(ordinal);
  255. }
  256. public Type GetFieldType (int index)
  257. {
  258. return GetColumn(index).DataType;
  259. }
  260. public float GetFloat (int ordinal)
  261. {
  262. return (float) GetValue(ordinal);
  263. }
  264. [MonoTODO]
  265. public Guid GetGuid (int ordinal)
  266. {
  267. throw new NotImplementedException ();
  268. }
  269. public short GetInt16 (int ordinal)
  270. {
  271. return (short) GetValue(ordinal);
  272. }
  273. public int GetInt32 (int ordinal)
  274. {
  275. return (int) GetValue(ordinal);
  276. }
  277. public long GetInt64 (int ordinal)
  278. {
  279. return (long) GetValue(ordinal);
  280. }
  281. public string GetName (int index)
  282. {
  283. return GetColumn(index).ColumnName;
  284. }
  285. public int GetOrdinal (string name)
  286. {
  287. int i=ColIndex(name);
  288. if (i==-1)
  289. throw new IndexOutOfRangeException ();
  290. else
  291. return i;
  292. }
  293. [MonoTODO]
  294. public DataTable GetSchemaTable()
  295. {
  296. DataTable dataTableSchema = null;
  297. // Only Results from SQL SELECT Queries
  298. // get a DataTable for schema of the result
  299. // otherwise, DataTable is null reference
  300. if(cols.Length > 0)
  301. {
  302. dataTableSchema = new DataTable ();
  303. dataTableSchema.Columns.Add ("ColumnName", typeof (string));
  304. dataTableSchema.Columns.Add ("ColumnOrdinal", typeof (int));
  305. dataTableSchema.Columns.Add ("ColumnSize", typeof (int));
  306. dataTableSchema.Columns.Add ("NumericPrecision", typeof (int));
  307. dataTableSchema.Columns.Add ("NumericScale", typeof (int));
  308. dataTableSchema.Columns.Add ("IsUnique", typeof (bool));
  309. dataTableSchema.Columns.Add ("IsKey", typeof (bool));
  310. DataColumn dc = dataTableSchema.Columns["IsKey"];
  311. dc.AllowDBNull = true; // IsKey can have a DBNull
  312. dataTableSchema.Columns.Add ("BaseCatalogName", typeof (string));
  313. dataTableSchema.Columns.Add ("BaseColumnName", typeof (string));
  314. dataTableSchema.Columns.Add ("BaseSchemaName", typeof (string));
  315. dataTableSchema.Columns.Add ("BaseTableName", typeof (string));
  316. dataTableSchema.Columns.Add ("DataType", typeof(Type));
  317. dataTableSchema.Columns.Add ("AllowDBNull", typeof (bool));
  318. dataTableSchema.Columns.Add ("ProviderType", typeof (int));
  319. dataTableSchema.Columns.Add ("IsAliased", typeof (bool));
  320. dataTableSchema.Columns.Add ("IsExpression", typeof (bool));
  321. dataTableSchema.Columns.Add ("IsIdentity", typeof (bool));
  322. dataTableSchema.Columns.Add ("IsAutoIncrement", typeof (bool));
  323. dataTableSchema.Columns.Add ("IsRowVersion", typeof (bool));
  324. dataTableSchema.Columns.Add ("IsHidden", typeof (bool));
  325. dataTableSchema.Columns.Add ("IsLong", typeof (bool));
  326. dataTableSchema.Columns.Add ("IsReadOnly", typeof (bool));
  327. DataRow schemaRow;
  328. for (int i = 0; i < cols.Length; i += 1 )
  329. {
  330. OdbcColumn col=GetColumn(i);
  331. schemaRow = dataTableSchema.NewRow ();
  332. dataTableSchema.Rows.Add (schemaRow);
  333. schemaRow["ColumnName"] = col.ColumnName;
  334. schemaRow["ColumnOrdinal"] = i + 1;
  335. schemaRow["ColumnSize"] = col.MaxLength;
  336. schemaRow["NumericPrecision"] = 0;
  337. schemaRow["NumericScale"] = 0;
  338. // TODO: need to get KeyInfo
  339. schemaRow["IsUnique"] = false;
  340. schemaRow["IsKey"] = DBNull.Value;
  341. schemaRow["BaseCatalogName"] = "";
  342. schemaRow["BaseColumnName"] = col.ColumnName;
  343. schemaRow["BaseSchemaName"] = "";
  344. schemaRow["BaseTableName"] = "";
  345. schemaRow["DataType"] = col.DataType;
  346. schemaRow["AllowDBNull"] = col.AllowDBNull;
  347. schemaRow["ProviderType"] = (int) col.OdbcType;
  348. // TODO: all of these
  349. schemaRow["IsAliased"] = false;
  350. schemaRow["IsExpression"] = false;
  351. schemaRow["IsIdentity"] = false;
  352. schemaRow["IsAutoIncrement"] = false;
  353. schemaRow["IsRowVersion"] = false;
  354. schemaRow["IsHidden"] = false;
  355. schemaRow["IsLong"] = false;
  356. schemaRow["IsReadOnly"] = false;
  357. // FIXME: according to Brian,
  358. // this does not work on MS .NET
  359. // however, we need it for Mono
  360. // for now
  361. schemaRow.AcceptChanges();
  362. }
  363. }
  364. dataTableSchema.AcceptChanges();
  365. return dataTableSchema;
  366. }
  367. public string GetString (int ordinal)
  368. {
  369. return (string) GetValue(ordinal);
  370. }
  371. [MonoTODO]
  372. public TimeSpan GetTime (int ordinal)
  373. {
  374. throw new NotImplementedException ();
  375. }
  376. public object GetValue (int ordinal)
  377. {
  378. if (currentRow == -1)
  379. throw new IndexOutOfRangeException ();
  380. if (ordinal>cols.Length-1 || ordinal<0)
  381. throw new IndexOutOfRangeException ();
  382. OdbcReturn ret;
  383. int outsize=0, bufsize;
  384. byte[] buffer;
  385. OdbcColumn col=GetColumn(ordinal);
  386. object DataValue=null;
  387. ushort ColIndex=Convert.ToUInt16(ordinal+1);
  388. // Check cached values
  389. if (col.Value==null)
  390. {
  391. // odbc help file
  392. // mk:@MSITStore:C:\program%20files\Microsoft%20Data%20Access%20SDK\Docs\odbc.chm::/htm/odbcc_data_types.htm
  393. switch (col.OdbcType)
  394. {
  395. case OdbcType.Decimal:
  396. bufsize=50;
  397. buffer=new byte[bufsize]; // According to sqlext.h, use SQL_CHAR for decimal
  398. ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.Char, buffer, bufsize, ref outsize);
  399. byte[] temp = new byte[outsize];
  400. for (int i=0;i<outsize;i++)
  401. temp[i]=buffer[i];
  402. if (outsize!=-1)
  403. DataValue=Decimal.Parse(System.Text.Encoding.Default.GetString(temp));
  404. break;
  405. case OdbcType.TinyInt:
  406. short short_data=0;
  407. ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.TinyInt, ref short_data, 0, ref outsize);
  408. DataValue=System.Convert.ToByte(short_data);
  409. break;
  410. case OdbcType.Int:
  411. int int_data=0;
  412. ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.Int, ref int_data, 0, ref outsize);
  413. DataValue=int_data;
  414. break;
  415. case OdbcType.SmallInt:
  416. short sint_data=0;
  417. ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.SmallInt, ref sint_data, 0, ref outsize);
  418. DataValue=sint_data;
  419. break;
  420. case OdbcType.BigInt:
  421. long long_data=0;
  422. ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.SignedBigInt, ref long_data, 0, ref outsize);
  423. DataValue=long_data;
  424. break;
  425. case OdbcType.NVarChar:
  426. bufsize=col.MaxLength*2+1; // Unicode is double byte
  427. buffer=new byte[bufsize];
  428. ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.NVarChar, buffer, bufsize, ref outsize);
  429. if (outsize!=-1)
  430. DataValue=System.Text.Encoding.Unicode.GetString(buffer,0,outsize);
  431. break;
  432. case OdbcType.VarChar:
  433. bufsize=col.MaxLength+1;
  434. buffer=new byte[bufsize]; // According to sqlext.h, use SQL_CHAR for both char and varchar
  435. ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.Char, buffer, bufsize, ref outsize);
  436. if (outsize!=-1)
  437. DataValue=System.Text.Encoding.Default.GetString(buffer,0,outsize);
  438. break;
  439. case OdbcType.Real:
  440. float float_data=0;
  441. ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.Real, ref float_data, 0, ref outsize);
  442. DataValue=float_data;
  443. break;
  444. case OdbcType.Double:
  445. double double_data=0;
  446. ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.Double, ref double_data, 0, ref outsize);
  447. DataValue=double_data;
  448. break;
  449. case OdbcType.Timestamp:
  450. case OdbcType.DateTime:
  451. case OdbcType.Date:
  452. case OdbcType.Time:
  453. OdbcTimestamp ts_data=new OdbcTimestamp();
  454. if (col.OdbcType == OdbcType.Timestamp)
  455. ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.Timestamp, ref ts_data, 0, ref outsize);
  456. else if (col.OdbcType == OdbcType.DateTime)
  457. ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.DateTime, ref ts_data, 0, ref outsize);
  458. else if (col.OdbcType == OdbcType.Date)
  459. ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.Date, ref ts_data, 0, ref outsize);
  460. else // FIXME: how to get TIME datatype ??
  461. ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.DateTime, ref ts_data, 0, ref outsize);
  462. if (outsize!=-1) // This means SQL_NULL_DATA
  463. DataValue=new DateTime(ts_data.year,ts_data.month,ts_data.day,ts_data.hour,
  464. ts_data.minute,ts_data.second,Convert.ToInt32(ts_data.fraction));
  465. break;
  466. case OdbcType.Binary :
  467. case OdbcType.Image :
  468. bufsize = col.MaxLength + 1;
  469. buffer = new byte [bufsize];
  470. long read = GetBytes (ordinal, 0, buffer, 0, bufsize);
  471. ret = OdbcReturn.Success;
  472. DataValue = buffer;
  473. break;
  474. default:
  475. bufsize=255;
  476. buffer=new byte[bufsize];
  477. ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.Char, buffer, bufsize, ref outsize);
  478. DataValue=System.Text.Encoding.Default.GetString(buffer);
  479. break;
  480. }
  481. if ((ret!=OdbcReturn.Success) && (ret!=OdbcReturn.SuccessWithInfo))
  482. throw new OdbcException(new OdbcError("SQLGetData",OdbcHandleType.Stmt,hstmt));
  483. if (outsize==-1) // This means SQL_NULL_DATA
  484. col.Value=DBNull.Value;
  485. else
  486. col.Value=DataValue;
  487. }
  488. return col.Value;
  489. }
  490. public int GetValues (object[] values)
  491. {
  492. int numValues = 0;
  493. // copy values
  494. for (int i = 0; i < values.Length; i++) {
  495. if (i < FieldCount) {
  496. values[i] = GetValue(i);
  497. }
  498. else {
  499. values[i] = null;
  500. }
  501. }
  502. // get number of object instances in array
  503. if (values.Length < FieldCount)
  504. numValues = values.Length;
  505. else if (values.Length == FieldCount)
  506. numValues = FieldCount;
  507. else
  508. numValues = FieldCount;
  509. return numValues;
  510. }
  511. [MonoTODO]
  512. IDataReader IDataRecord.GetData (int ordinal)
  513. {
  514. throw new NotImplementedException ();
  515. }
  516. [MonoTODO]
  517. void IDisposable.Dispose ()
  518. {
  519. }
  520. [MonoTODO]
  521. IEnumerator IEnumerable.GetEnumerator ()
  522. {
  523. return new DbEnumerator (this);
  524. }
  525. public bool IsDBNull (int ordinal)
  526. {
  527. return (GetValue(ordinal) is DBNull);
  528. }
  529. /// <remarks>
  530. /// Move to the next result set.
  531. /// </remarks>
  532. public bool NextResult ()
  533. {
  534. OdbcReturn ret = OdbcReturn.Success;
  535. ret = libodbc.SQLMoreResults (hstmt);
  536. if (ret == OdbcReturn.Success) {
  537. short colcount = 0;
  538. libodbc.SQLNumResultCols (hstmt, ref colcount);
  539. cols = new OdbcColumn [colcount];
  540. GetSchemaTable ();
  541. }
  542. return (ret==OdbcReturn.Success);
  543. }
  544. /// <remarks>
  545. /// Load the next row in the current result set.
  546. /// </remarks>
  547. public bool NextRow ()
  548. {
  549. OdbcReturn ret=libodbc.SQLFetch (hstmt);
  550. if (ret != OdbcReturn.Success)
  551. currentRow = -1;
  552. else
  553. currentRow++;
  554. // Clear cached values from last record
  555. foreach (OdbcColumn col in cols)
  556. {
  557. if (col != null)
  558. col.Value = null;
  559. }
  560. return (ret == OdbcReturn.Success);
  561. }
  562. public bool Read ()
  563. {
  564. return NextRow ();
  565. }
  566. #endregion
  567. }
  568. }