OleDbDataReader.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  1. //
  2. // System.Data.OleDb.OleDbDataReader
  3. //
  4. // Author:
  5. // Rodrigo Moya ([email protected])
  6. // Tim Coleman ([email protected])
  7. //
  8. // Copyright (C) Rodrigo Moya, 2002
  9. // Copyright (C) Tim Coleman, 2002
  10. // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. using System.Collections;
  32. using System.ComponentModel;
  33. using System.Data.Common;
  34. using System.Runtime.InteropServices;
  35. namespace System.Data.OleDb
  36. {
  37. #if NET_2_0
  38. public sealed class OleDbDataReader : DbDataReader, IDisposable
  39. #else
  40. public sealed class OleDbDataReader : MarshalByRefObject, IDataReader, IDisposable, IDataRecord, IEnumerable
  41. #endif
  42. {
  43. #region Fields
  44. private OleDbCommand command;
  45. private bool open;
  46. private ArrayList gdaResults;
  47. private int currentResult;
  48. private int currentRow;
  49. private bool disposed;
  50. #endregion
  51. #region Constructors
  52. internal OleDbDataReader (OleDbCommand command, ArrayList results)
  53. {
  54. this.command = command;
  55. open = true;
  56. if (results != null)
  57. gdaResults = results;
  58. else
  59. gdaResults = new ArrayList ();
  60. currentResult = -1;
  61. currentRow = -1;
  62. }
  63. #endregion
  64. #region Properties
  65. public
  66. #if NET_2_0
  67. override
  68. #endif
  69. int Depth {
  70. get {
  71. return 0; // no nested selects supported
  72. }
  73. }
  74. public
  75. #if NET_2_0
  76. override
  77. #endif
  78. int FieldCount {
  79. get {
  80. if (currentResult < 0 || currentResult >= gdaResults.Count)
  81. return 0;
  82. return libgda.gda_data_model_get_n_columns (
  83. (IntPtr) gdaResults[currentResult]);
  84. }
  85. }
  86. public
  87. #if NET_2_0
  88. override
  89. #endif
  90. bool IsClosed {
  91. get {
  92. return !open;
  93. }
  94. }
  95. public
  96. #if NET_2_0
  97. override
  98. #endif
  99. object this[string name] {
  100. get {
  101. int pos;
  102. if (currentResult == -1)
  103. throw new InvalidOperationException ();
  104. pos = libgda.gda_data_model_get_column_position (
  105. (IntPtr) gdaResults[currentResult],
  106. name);
  107. if (pos == -1)
  108. throw new IndexOutOfRangeException ();
  109. return this[pos];
  110. }
  111. }
  112. public
  113. #if NET_2_0
  114. override
  115. #endif
  116. object this[int index] {
  117. get {
  118. return (object) GetValue (index);
  119. }
  120. }
  121. public
  122. #if NET_2_0
  123. override
  124. #endif
  125. int RecordsAffected {
  126. get {
  127. int total_rows;
  128. if (currentResult < 0 || currentResult >= gdaResults.Count)
  129. return 0;
  130. total_rows = libgda.gda_data_model_get_n_rows (
  131. (IntPtr) gdaResults[currentResult]);
  132. if (total_rows > 0) {
  133. if (FieldCount > 0) {
  134. // It's a SELECT statement
  135. return -1;
  136. }
  137. }
  138. return FieldCount > 0 ? -1 : total_rows;
  139. }
  140. }
  141. [MonoTODO]
  142. public
  143. #if NET_2_0
  144. override
  145. #endif
  146. bool HasRows {
  147. get {
  148. throw new NotImplementedException ();
  149. }
  150. }
  151. #if NET_2_0
  152. [MonoTODO]
  153. public override int VisibleFieldCount {
  154. get {
  155. throw new NotImplementedException ();
  156. }
  157. }
  158. #endif
  159. #endregion
  160. #region Methods
  161. public
  162. #if NET_2_0
  163. override
  164. #endif
  165. void Close ()
  166. {
  167. for (int i = 0; i < gdaResults.Count; i++) {
  168. IntPtr obj = (IntPtr) gdaResults[i];
  169. libgda.FreeObject (obj);
  170. }
  171. gdaResults.Clear ();
  172. gdaResults = null;
  173. open = false;
  174. currentResult = -1;
  175. currentRow = -1;
  176. }
  177. public
  178. #if NET_2_0
  179. override
  180. #endif
  181. bool GetBoolean (int ordinal)
  182. {
  183. IntPtr value;
  184. if (currentResult == -1)
  185. throw new InvalidCastException ();
  186. value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
  187. ordinal, currentRow);
  188. if (value == IntPtr.Zero)
  189. throw new InvalidCastException ();
  190. if (libgda.gda_value_get_type (value) != GdaValueType.Boolean)
  191. throw new InvalidCastException ();
  192. return libgda.gda_value_get_boolean (value);
  193. }
  194. public
  195. #if NET_2_0
  196. override
  197. #endif
  198. byte GetByte (int ordinal)
  199. {
  200. IntPtr value;
  201. if (currentResult == -1)
  202. throw new InvalidCastException ();
  203. value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
  204. ordinal, currentRow);
  205. if (value == IntPtr.Zero)
  206. throw new InvalidCastException ();
  207. if (libgda.gda_value_get_type (value) != GdaValueType.Tinyint)
  208. throw new InvalidCastException ();
  209. return libgda.gda_value_get_tinyint (value);
  210. }
  211. [MonoTODO]
  212. public
  213. #if NET_2_0
  214. override
  215. #endif
  216. long GetBytes (int ordinal, long dataIndex, byte[] buffer, int bufferIndex, int length)
  217. {
  218. throw new NotImplementedException ();
  219. }
  220. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  221. public
  222. #if NET_2_0
  223. override
  224. #endif
  225. char GetChar (int ordinal)
  226. {
  227. IntPtr value;
  228. if (currentResult == -1)
  229. throw new InvalidCastException ();
  230. value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
  231. ordinal, currentRow);
  232. if (value == IntPtr.Zero)
  233. throw new InvalidCastException ();
  234. if (libgda.gda_value_get_type (value) != GdaValueType.Tinyint)
  235. throw new InvalidCastException ();
  236. return (char) libgda.gda_value_get_tinyint (value);
  237. }
  238. [MonoTODO]
  239. public
  240. #if NET_2_0
  241. override
  242. #endif
  243. long GetChars (int ordinal, long dataIndex, char[] buffer, int bufferIndex, int length)
  244. {
  245. throw new NotImplementedException ();
  246. }
  247. [MonoTODO]
  248. #if NET_2_0
  249. [EditorBrowsable (EditorBrowsableState.Advanced)]
  250. #endif
  251. public new OleDbDataReader GetData (int ordinal)
  252. {
  253. throw new NotImplementedException ();
  254. }
  255. #if NET_2_0
  256. protected override DbDataReader GetDbDataReader (int ordinal)
  257. {
  258. return this.GetData (ordinal);
  259. }
  260. #endif
  261. public
  262. #if NET_2_0
  263. override
  264. #endif
  265. string GetDataTypeName (int index)
  266. {
  267. IntPtr attrs;
  268. GdaValueType type;
  269. if (currentResult == -1)
  270. return "unknown";
  271. attrs = libgda.gda_data_model_describe_column ((IntPtr) gdaResults[currentResult],
  272. index);
  273. if (attrs == IntPtr.Zero)
  274. return "unknown";
  275. type = libgda.gda_field_attributes_get_gdatype (attrs);
  276. libgda.gda_field_attributes_free (attrs);
  277. return libgda.gda_type_to_string (type);
  278. }
  279. public
  280. #if NET_2_0
  281. override
  282. #endif
  283. DateTime GetDateTime (int ordinal)
  284. {
  285. IntPtr value;
  286. DateTime dt;
  287. if (currentResult == -1)
  288. throw new InvalidCastException ();
  289. value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
  290. ordinal, currentRow);
  291. if (value == IntPtr.Zero)
  292. throw new InvalidCastException ();
  293. if (libgda.gda_value_get_type (value) == GdaValueType.Date) {
  294. GdaDate gdt;
  295. gdt = (GdaDate) Marshal.PtrToStructure (libgda.gda_value_get_date (value),
  296. typeof (GdaDate));
  297. return new DateTime ((int) gdt.year, (int) gdt.month, (int) gdt.day);
  298. } else if (libgda.gda_value_get_type (value) == GdaValueType.Time) {
  299. GdaTime gdt;
  300. gdt = (GdaTime) Marshal.PtrToStructure (libgda.gda_value_get_time (value),
  301. typeof (GdaTime));
  302. return new DateTime (0, 0, 0, (int) gdt.hour, (int) gdt.minute, (int) gdt.second, 0);
  303. } else if (libgda.gda_value_get_type (value) == GdaValueType.Timestamp) {
  304. GdaTimestamp gdt;
  305. gdt = (GdaTimestamp) Marshal.PtrToStructure (libgda.gda_value_get_timestamp (value),
  306. typeof (GdaTimestamp));
  307. return new DateTime ((int) gdt.year, (int) gdt.month, (int) gdt.day,
  308. (int) gdt.hour, (int) gdt.minute, (int) gdt.second,
  309. (int) gdt.fraction);
  310. }
  311. throw new InvalidCastException ();
  312. }
  313. [MonoTODO]
  314. public
  315. #if NET_2_0
  316. override
  317. #endif
  318. decimal GetDecimal (int ordinal)
  319. {
  320. throw new NotImplementedException ();
  321. }
  322. public
  323. #if NET_2_0
  324. override
  325. #endif
  326. double GetDouble (int ordinal)
  327. {
  328. IntPtr value;
  329. if (currentResult == -1)
  330. throw new InvalidCastException ();
  331. value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
  332. ordinal, currentRow);
  333. if (value == IntPtr.Zero)
  334. throw new InvalidCastException ();
  335. if (libgda.gda_value_get_type (value) != GdaValueType.Double)
  336. throw new InvalidCastException ();
  337. return libgda.gda_value_get_double (value);
  338. }
  339. public
  340. #if NET_2_0
  341. override
  342. #endif
  343. Type GetFieldType (int index)
  344. {
  345. IntPtr value;
  346. GdaValueType type;
  347. if (currentResult == -1)
  348. throw new IndexOutOfRangeException ();
  349. value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
  350. index, currentRow);
  351. if (value == IntPtr.Zero)
  352. throw new IndexOutOfRangeException ();
  353. type = libgda.gda_value_get_type (value);
  354. switch (type) {
  355. case GdaValueType.Bigint : return typeof (long);
  356. case GdaValueType.Boolean : return typeof (bool);
  357. case GdaValueType.Date : return typeof (DateTime);
  358. case GdaValueType.Double : return typeof (double);
  359. case GdaValueType.Integer : return typeof (int);
  360. case GdaValueType.Single : return typeof (float);
  361. case GdaValueType.Smallint : return typeof (byte);
  362. case GdaValueType.String : return typeof (string);
  363. case GdaValueType.Time : return typeof (DateTime);
  364. case GdaValueType.Timestamp : return typeof (DateTime);
  365. case GdaValueType.Tinyint : return typeof (byte);
  366. }
  367. return typeof(string); // default
  368. }
  369. public
  370. #if NET_2_0
  371. override
  372. #endif
  373. float GetFloat (int ordinal)
  374. {
  375. IntPtr value;
  376. if (currentResult == -1)
  377. throw new InvalidCastException ();
  378. value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
  379. ordinal, currentRow);
  380. if (value == IntPtr.Zero)
  381. throw new InvalidCastException ();
  382. if (libgda.gda_value_get_type (value) != GdaValueType.Single)
  383. throw new InvalidCastException ();
  384. return libgda.gda_value_get_single (value);
  385. }
  386. [MonoTODO]
  387. public
  388. #if NET_2_0
  389. override
  390. #endif
  391. Guid GetGuid (int ordinal)
  392. {
  393. throw new NotImplementedException ();
  394. }
  395. public
  396. #if NET_2_0
  397. override
  398. #endif
  399. short GetInt16 (int ordinal)
  400. {
  401. IntPtr value;
  402. if (currentResult == -1)
  403. throw new InvalidCastException ();
  404. value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
  405. ordinal, currentRow);
  406. if (value == IntPtr.Zero)
  407. throw new InvalidCastException ();
  408. if (libgda.gda_value_get_type (value) != GdaValueType.Smallint)
  409. throw new InvalidCastException ();
  410. return (short) libgda.gda_value_get_smallint (value);
  411. }
  412. public
  413. #if NET_2_0
  414. override
  415. #endif
  416. int GetInt32 (int ordinal)
  417. {
  418. IntPtr value;
  419. if (currentResult == -1)
  420. throw new InvalidCastException ();
  421. value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
  422. ordinal, currentRow);
  423. if (value == IntPtr.Zero)
  424. throw new InvalidCastException ();
  425. if (libgda.gda_value_get_type (value) != GdaValueType.Integer)
  426. throw new InvalidCastException ();
  427. return libgda.gda_value_get_integer (value);
  428. }
  429. public
  430. #if NET_2_0
  431. override
  432. #endif
  433. long GetInt64 (int ordinal)
  434. {
  435. IntPtr value;
  436. if (currentResult == -1)
  437. throw new InvalidCastException ();
  438. value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
  439. ordinal, currentRow);
  440. if (value == IntPtr.Zero)
  441. throw new InvalidCastException ();
  442. if (libgda.gda_value_get_type (value) != GdaValueType.Bigint)
  443. throw new InvalidCastException ();
  444. return libgda.gda_value_get_bigint (value);
  445. }
  446. public
  447. #if NET_2_0
  448. override
  449. #endif
  450. string GetName (int index)
  451. {
  452. if (currentResult == -1)
  453. return null;
  454. return libgda.gda_data_model_get_column_title (
  455. (IntPtr) gdaResults[currentResult], index);
  456. }
  457. public
  458. #if NET_2_0
  459. override
  460. #endif
  461. int GetOrdinal (string name)
  462. {
  463. if (currentResult == -1)
  464. throw new IndexOutOfRangeException ();
  465. for (int i = 0; i < FieldCount; i++) {
  466. if (GetName (i) == name)
  467. return i;
  468. }
  469. throw new IndexOutOfRangeException ();
  470. }
  471. public
  472. #if NET_2_0
  473. override
  474. #endif
  475. DataTable GetSchemaTable ()
  476. {
  477. DataTable dataTableSchema = null;
  478. // Only Results from SQL SELECT Queries
  479. // get a DataTable for schema of the result
  480. // otherwise, DataTable is null reference
  481. if(this.FieldCount > 0) {
  482. IntPtr attrs;
  483. GdaValueType gdaType;
  484. long columnSize = 0;
  485. if (currentResult == -1) {
  486. // FIXME: throw an exception?
  487. #if DEBUG_OleDbDataReader
  488. Console.WriteLine("Error: current result -1");
  489. #endif
  490. return null;
  491. }
  492. dataTableSchema = new DataTable ();
  493. dataTableSchema.Columns.Add ("ColumnName", typeof (string));
  494. dataTableSchema.Columns.Add ("ColumnOrdinal", typeof (int));
  495. dataTableSchema.Columns.Add ("ColumnSize", typeof (int));
  496. dataTableSchema.Columns.Add ("NumericPrecision", typeof (int));
  497. dataTableSchema.Columns.Add ("NumericScale", typeof (int));
  498. dataTableSchema.Columns.Add ("IsUnique", typeof (bool));
  499. dataTableSchema.Columns.Add ("IsKey", typeof (bool));
  500. DataColumn dc = dataTableSchema.Columns["IsKey"];
  501. dc.AllowDBNull = true; // IsKey can have a DBNull
  502. dataTableSchema.Columns.Add ("BaseCatalogName", typeof (string));
  503. dataTableSchema.Columns.Add ("BaseColumnName", typeof (string));
  504. dataTableSchema.Columns.Add ("BaseSchemaName", typeof (string));
  505. dataTableSchema.Columns.Add ("BaseTableName", typeof (string));
  506. dataTableSchema.Columns.Add ("DataType", typeof(Type));
  507. dataTableSchema.Columns.Add ("AllowDBNull", typeof (bool));
  508. dataTableSchema.Columns.Add ("ProviderType", typeof (int));
  509. dataTableSchema.Columns.Add ("IsAliased", typeof (bool));
  510. dataTableSchema.Columns.Add ("IsExpression", typeof (bool));
  511. dataTableSchema.Columns.Add ("IsIdentity", typeof (bool));
  512. dataTableSchema.Columns.Add ("IsAutoIncrement", typeof (bool));
  513. dataTableSchema.Columns.Add ("IsRowVersion", typeof (bool));
  514. dataTableSchema.Columns.Add ("IsHidden", typeof (bool));
  515. dataTableSchema.Columns.Add ("IsLong", typeof (bool));
  516. dataTableSchema.Columns.Add ("IsReadOnly", typeof (bool));
  517. DataRow schemaRow;
  518. DbType dbType;
  519. Type typ;
  520. for (int i = 0; i < this.FieldCount; i += 1 ) {
  521. schemaRow = dataTableSchema.NewRow ();
  522. attrs = libgda.gda_data_model_describe_column ((IntPtr) gdaResults[currentResult],
  523. i);
  524. if (attrs == IntPtr.Zero){
  525. // FIXME: throw exception
  526. #if DEBUG_OleDbDataReader
  527. Console.WriteLine("Error: attrs null");
  528. #endif
  529. return null;
  530. }
  531. gdaType = libgda.gda_field_attributes_get_gdatype (attrs);
  532. columnSize = libgda.gda_field_attributes_get_defined_size (attrs);
  533. libgda.gda_field_attributes_free (attrs);
  534. schemaRow["ColumnName"] = this.GetName(i);
  535. schemaRow["ColumnOrdinal"] = i + 1;
  536. schemaRow["ColumnSize"] = (int) columnSize;
  537. schemaRow["NumericPrecision"] = 0;
  538. schemaRow["NumericScale"] = 0;
  539. // TODO: need to get KeyInfo
  540. //if((cmdBehavior & CommandBehavior.KeyInfo) == CommandBehavior.KeyInfo) {
  541. // bool IsUnique, IsKey;
  542. // GetKeyInfo(field[i].Name, out IsUnique, out IsKey);
  543. //}
  544. //else {
  545. schemaRow["IsUnique"] = false;
  546. schemaRow["IsKey"] = DBNull.Value;
  547. //}
  548. schemaRow["BaseCatalogName"] = "";
  549. schemaRow["BaseColumnName"] = this.GetName(i);
  550. schemaRow["BaseSchemaName"] = "";
  551. schemaRow["BaseTableName"] = "";
  552. schemaRow["DataType"] = this.GetFieldType(i);
  553. schemaRow["AllowDBNull"] = false;
  554. schemaRow["ProviderType"] = (int) gdaType;
  555. schemaRow["IsAliased"] = false;
  556. schemaRow["IsExpression"] = false;
  557. schemaRow["IsIdentity"] = false;
  558. schemaRow["IsAutoIncrement"] = false;
  559. schemaRow["IsRowVersion"] = false;
  560. schemaRow["IsHidden"] = false;
  561. schemaRow["IsLong"] = false;
  562. schemaRow["IsReadOnly"] = false;
  563. schemaRow.AcceptChanges();
  564. dataTableSchema.Rows.Add (schemaRow);
  565. }
  566. #if DEBUG_OleDbDataReader
  567. Console.WriteLine("********** DEBUG Table Schema BEGIN ************");
  568. foreach (DataRow myRow in dataTableSchema.Rows) {
  569. foreach (DataColumn myCol in dataTableSchema.Columns)
  570. Console.WriteLine(myCol.ColumnName + " = " + myRow[myCol]);
  571. Console.WriteLine();
  572. }
  573. Console.WriteLine("********** DEBUG Table Schema END ************");
  574. #endif // DEBUG_OleDbDataReader
  575. }
  576. return dataTableSchema;
  577. }
  578. public
  579. #if NET_2_0
  580. override
  581. #endif
  582. string GetString (int ordinal)
  583. {
  584. IntPtr value;
  585. if (currentResult == -1)
  586. throw new InvalidCastException ();
  587. value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
  588. ordinal, currentRow);
  589. if (value == IntPtr.Zero)
  590. throw new InvalidCastException ();
  591. if (libgda.gda_value_get_type (value) != GdaValueType.String)
  592. throw new InvalidCastException ();
  593. return libgda.gda_value_get_string (value);
  594. }
  595. [MonoTODO]
  596. public TimeSpan GetTimeSpan (int ordinal)
  597. {
  598. throw new NotImplementedException ();
  599. }
  600. public
  601. #if NET_2_0
  602. override
  603. #endif
  604. object GetValue (int ordinal)
  605. {
  606. IntPtr value;
  607. GdaValueType type;
  608. if (currentResult == -1)
  609. throw new IndexOutOfRangeException ();
  610. value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
  611. ordinal, currentRow);
  612. if (value == IntPtr.Zero)
  613. throw new IndexOutOfRangeException ();
  614. type = libgda.gda_value_get_type (value);
  615. switch (type) {
  616. case GdaValueType.Bigint : return GetInt64 (ordinal);
  617. case GdaValueType.Boolean : return GetBoolean (ordinal);
  618. case GdaValueType.Date : return GetDateTime (ordinal);
  619. case GdaValueType.Double : return GetDouble (ordinal);
  620. case GdaValueType.Integer : return GetInt32 (ordinal);
  621. case GdaValueType.Single : return GetFloat (ordinal);
  622. case GdaValueType.Smallint : return GetByte (ordinal);
  623. case GdaValueType.String : return GetString (ordinal);
  624. case GdaValueType.Time : return GetDateTime (ordinal);
  625. case GdaValueType.Timestamp : return GetDateTime (ordinal);
  626. case GdaValueType.Tinyint : return GetByte (ordinal);
  627. }
  628. return (object) libgda.gda_value_stringify (value);
  629. }
  630. [MonoTODO]
  631. public
  632. #if NET_2_0
  633. override
  634. #endif
  635. int GetValues (object[] values)
  636. {
  637. throw new NotImplementedException ();
  638. }
  639. #if !NET_2_0
  640. [MonoTODO]
  641. IDataReader IDataRecord.GetData (int ordinal)
  642. {
  643. throw new NotImplementedException ();
  644. }
  645. #endif
  646. #if NET_2_0
  647. public override IEnumerator GetEnumerator()
  648. #else
  649. IEnumerator IEnumerable.GetEnumerator ()
  650. #endif
  651. {
  652. return new DbEnumerator(this);
  653. }
  654. public
  655. #if NET_2_0
  656. override
  657. #endif
  658. bool IsDBNull (int ordinal)
  659. {
  660. IntPtr value;
  661. if (currentResult == -1)
  662. throw new IndexOutOfRangeException ();
  663. value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
  664. ordinal, currentRow);
  665. if (value == IntPtr.Zero)
  666. throw new IndexOutOfRangeException ();
  667. return libgda.gda_value_is_null (value);
  668. }
  669. public
  670. #if NET_2_0
  671. override
  672. #endif
  673. bool NextResult ()
  674. {
  675. int i = currentResult + 1;
  676. if (i >= 0 && i < gdaResults.Count) {
  677. currentResult++;
  678. return true;
  679. }
  680. return false;
  681. }
  682. public
  683. #if NET_2_0
  684. override
  685. #endif
  686. bool Read ()
  687. {
  688. if (currentResult < 0 || currentResult >= gdaResults.Count)
  689. return false;
  690. currentRow++;
  691. if (currentRow < libgda.gda_data_model_get_n_rows ((IntPtr) gdaResults[currentResult]))
  692. return true;
  693. return false;
  694. }
  695. #endregion
  696. #region Destructors
  697. private new void Dispose (bool disposing)
  698. {
  699. if (!this.disposed) {
  700. if (disposing) {
  701. // release any managed resources
  702. command = null;
  703. GC.SuppressFinalize (this);
  704. }
  705. // release any unmanaged resources
  706. if (gdaResults != null) {
  707. gdaResults.Clear ();
  708. gdaResults = null;
  709. }
  710. // close any handles
  711. if (open)
  712. Close ();
  713. this.disposed = true;
  714. }
  715. }
  716. void IDisposable.Dispose() {
  717. Dispose (true);
  718. }
  719. #if ONLY_1_1
  720. ~OleDbDataReader () {
  721. Dispose (false);
  722. }
  723. #endif
  724. #endregion // Destructors
  725. }
  726. }