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. [MonoTODO]
  340. public
  341. #if NET_2_0
  342. override
  343. #endif
  344. Type GetFieldType (int index)
  345. {
  346. IntPtr value;
  347. GdaValueType type;
  348. if (currentResult == -1)
  349. throw new IndexOutOfRangeException ();
  350. value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
  351. index, currentRow);
  352. if (value == IntPtr.Zero)
  353. throw new IndexOutOfRangeException ();
  354. type = libgda.gda_value_get_type (value);
  355. switch (type) {
  356. case GdaValueType.Bigint : return typeof (long);
  357. case GdaValueType.Boolean : return typeof (bool);
  358. case GdaValueType.Date : return typeof (DateTime);
  359. case GdaValueType.Double : return typeof (double);
  360. case GdaValueType.Integer : return typeof (int);
  361. case GdaValueType.Single : return typeof (float);
  362. case GdaValueType.Smallint : return typeof (byte);
  363. case GdaValueType.String : return typeof (string);
  364. case GdaValueType.Time : return typeof (DateTime);
  365. case GdaValueType.Timestamp : return typeof (DateTime);
  366. case GdaValueType.Tinyint : return typeof (byte);
  367. }
  368. return typeof(string); // default
  369. }
  370. public
  371. #if NET_2_0
  372. override
  373. #endif
  374. float GetFloat (int ordinal)
  375. {
  376. IntPtr value;
  377. if (currentResult == -1)
  378. throw new InvalidCastException ();
  379. value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
  380. ordinal, currentRow);
  381. if (value == IntPtr.Zero)
  382. throw new InvalidCastException ();
  383. if (libgda.gda_value_get_type (value) != GdaValueType.Single)
  384. throw new InvalidCastException ();
  385. return libgda.gda_value_get_single (value);
  386. }
  387. [MonoTODO]
  388. public
  389. #if NET_2_0
  390. override
  391. #endif
  392. Guid GetGuid (int ordinal)
  393. {
  394. throw new NotImplementedException ();
  395. }
  396. public
  397. #if NET_2_0
  398. override
  399. #endif
  400. short GetInt16 (int ordinal)
  401. {
  402. IntPtr value;
  403. if (currentResult == -1)
  404. throw new InvalidCastException ();
  405. value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
  406. ordinal, currentRow);
  407. if (value == IntPtr.Zero)
  408. throw new InvalidCastException ();
  409. if (libgda.gda_value_get_type (value) != GdaValueType.Smallint)
  410. throw new InvalidCastException ();
  411. return (short) libgda.gda_value_get_smallint (value);
  412. }
  413. public
  414. #if NET_2_0
  415. override
  416. #endif
  417. int GetInt32 (int ordinal)
  418. {
  419. IntPtr value;
  420. if (currentResult == -1)
  421. throw new InvalidCastException ();
  422. value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
  423. ordinal, currentRow);
  424. if (value == IntPtr.Zero)
  425. throw new InvalidCastException ();
  426. if (libgda.gda_value_get_type (value) != GdaValueType.Integer)
  427. throw new InvalidCastException ();
  428. return libgda.gda_value_get_integer (value);
  429. }
  430. public
  431. #if NET_2_0
  432. override
  433. #endif
  434. long GetInt64 (int ordinal)
  435. {
  436. IntPtr value;
  437. if (currentResult == -1)
  438. throw new InvalidCastException ();
  439. value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
  440. ordinal, currentRow);
  441. if (value == IntPtr.Zero)
  442. throw new InvalidCastException ();
  443. if (libgda.gda_value_get_type (value) != GdaValueType.Bigint)
  444. throw new InvalidCastException ();
  445. return libgda.gda_value_get_bigint (value);
  446. }
  447. public
  448. #if NET_2_0
  449. override
  450. #endif
  451. string GetName (int index)
  452. {
  453. if (currentResult == -1)
  454. return null;
  455. return libgda.gda_data_model_get_column_title (
  456. (IntPtr) gdaResults[currentResult], index);
  457. }
  458. public
  459. #if NET_2_0
  460. override
  461. #endif
  462. int GetOrdinal (string name)
  463. {
  464. if (currentResult == -1)
  465. throw new IndexOutOfRangeException ();
  466. for (int i = 0; i < FieldCount; i++) {
  467. if (GetName (i) == name)
  468. return i;
  469. }
  470. throw new IndexOutOfRangeException ();
  471. }
  472. public
  473. #if NET_2_0
  474. override
  475. #endif
  476. DataTable GetSchemaTable ()
  477. {
  478. DataTable dataTableSchema = null;
  479. // Only Results from SQL SELECT Queries
  480. // get a DataTable for schema of the result
  481. // otherwise, DataTable is null reference
  482. if(this.FieldCount > 0) {
  483. IntPtr attrs;
  484. GdaValueType gdaType;
  485. long columnSize = 0;
  486. if (currentResult == -1) {
  487. // FIXME: throw an exception?
  488. #if DEBUG_OleDbDataReader
  489. Console.WriteLine("Error: current result -1");
  490. #endif
  491. return null;
  492. }
  493. dataTableSchema = new DataTable ();
  494. dataTableSchema.Columns.Add ("ColumnName", typeof (string));
  495. dataTableSchema.Columns.Add ("ColumnOrdinal", typeof (int));
  496. dataTableSchema.Columns.Add ("ColumnSize", typeof (int));
  497. dataTableSchema.Columns.Add ("NumericPrecision", typeof (int));
  498. dataTableSchema.Columns.Add ("NumericScale", typeof (int));
  499. dataTableSchema.Columns.Add ("IsUnique", typeof (bool));
  500. dataTableSchema.Columns.Add ("IsKey", typeof (bool));
  501. DataColumn dc = dataTableSchema.Columns["IsKey"];
  502. dc.AllowDBNull = true; // IsKey can have a DBNull
  503. dataTableSchema.Columns.Add ("BaseCatalogName", typeof (string));
  504. dataTableSchema.Columns.Add ("BaseColumnName", typeof (string));
  505. dataTableSchema.Columns.Add ("BaseSchemaName", typeof (string));
  506. dataTableSchema.Columns.Add ("BaseTableName", typeof (string));
  507. dataTableSchema.Columns.Add ("DataType", typeof(Type));
  508. dataTableSchema.Columns.Add ("AllowDBNull", typeof (bool));
  509. dataTableSchema.Columns.Add ("ProviderType", typeof (int));
  510. dataTableSchema.Columns.Add ("IsAliased", typeof (bool));
  511. dataTableSchema.Columns.Add ("IsExpression", typeof (bool));
  512. dataTableSchema.Columns.Add ("IsIdentity", typeof (bool));
  513. dataTableSchema.Columns.Add ("IsAutoIncrement", typeof (bool));
  514. dataTableSchema.Columns.Add ("IsRowVersion", typeof (bool));
  515. dataTableSchema.Columns.Add ("IsHidden", typeof (bool));
  516. dataTableSchema.Columns.Add ("IsLong", typeof (bool));
  517. dataTableSchema.Columns.Add ("IsReadOnly", typeof (bool));
  518. DataRow schemaRow;
  519. DbType dbType;
  520. Type typ;
  521. for (int i = 0; i < this.FieldCount; i += 1 ) {
  522. schemaRow = dataTableSchema.NewRow ();
  523. attrs = libgda.gda_data_model_describe_column ((IntPtr) gdaResults[currentResult],
  524. i);
  525. if (attrs == IntPtr.Zero){
  526. // FIXME: throw exception
  527. #if DEBUG_OleDbDataReader
  528. Console.WriteLine("Error: attrs null");
  529. #endif
  530. return null;
  531. }
  532. gdaType = libgda.gda_field_attributes_get_gdatype (attrs);
  533. columnSize = libgda.gda_field_attributes_get_defined_size (attrs);
  534. libgda.gda_field_attributes_free (attrs);
  535. schemaRow["ColumnName"] = this.GetName(i);
  536. schemaRow["ColumnOrdinal"] = i + 1;
  537. schemaRow["ColumnSize"] = (int) columnSize;
  538. schemaRow["NumericPrecision"] = 0;
  539. schemaRow["NumericScale"] = 0;
  540. // TODO: need to get KeyInfo
  541. //if((cmdBehavior & CommandBehavior.KeyInfo) == CommandBehavior.KeyInfo) {
  542. // bool IsUnique, IsKey;
  543. // GetKeyInfo(field[i].Name, out IsUnique, out IsKey);
  544. //}
  545. //else {
  546. schemaRow["IsUnique"] = false;
  547. schemaRow["IsKey"] = DBNull.Value;
  548. //}
  549. schemaRow["BaseCatalogName"] = "";
  550. schemaRow["BaseColumnName"] = this.GetName(i);
  551. schemaRow["BaseSchemaName"] = "";
  552. schemaRow["BaseTableName"] = "";
  553. schemaRow["DataType"] = this.GetFieldType(i);
  554. schemaRow["AllowDBNull"] = false;
  555. schemaRow["ProviderType"] = (int) gdaType;
  556. schemaRow["IsAliased"] = false;
  557. schemaRow["IsExpression"] = false;
  558. schemaRow["IsIdentity"] = false;
  559. schemaRow["IsAutoIncrement"] = false;
  560. schemaRow["IsRowVersion"] = false;
  561. schemaRow["IsHidden"] = false;
  562. schemaRow["IsLong"] = false;
  563. schemaRow["IsReadOnly"] = false;
  564. schemaRow.AcceptChanges();
  565. dataTableSchema.Rows.Add (schemaRow);
  566. }
  567. #if DEBUG_OleDbDataReader
  568. Console.WriteLine("********** DEBUG Table Schema BEGIN ************");
  569. foreach (DataRow myRow in dataTableSchema.Rows) {
  570. foreach (DataColumn myCol in dataTableSchema.Columns)
  571. Console.WriteLine(myCol.ColumnName + " = " + myRow[myCol]);
  572. Console.WriteLine();
  573. }
  574. Console.WriteLine("********** DEBUG Table Schema END ************");
  575. #endif // DEBUG_OleDbDataReader
  576. }
  577. return dataTableSchema;
  578. }
  579. public
  580. #if NET_2_0
  581. override
  582. #endif
  583. string GetString (int ordinal)
  584. {
  585. IntPtr value;
  586. if (currentResult == -1)
  587. throw new InvalidCastException ();
  588. value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
  589. ordinal, currentRow);
  590. if (value == IntPtr.Zero)
  591. throw new InvalidCastException ();
  592. if (libgda.gda_value_get_type (value) != GdaValueType.String)
  593. throw new InvalidCastException ();
  594. return libgda.gda_value_get_string (value);
  595. }
  596. [MonoTODO]
  597. public TimeSpan GetTimeSpan (int ordinal)
  598. {
  599. throw new NotImplementedException ();
  600. }
  601. public
  602. #if NET_2_0
  603. override
  604. #endif
  605. object GetValue (int ordinal)
  606. {
  607. IntPtr value;
  608. GdaValueType type;
  609. if (currentResult == -1)
  610. throw new IndexOutOfRangeException ();
  611. value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
  612. ordinal, currentRow);
  613. if (value == IntPtr.Zero)
  614. throw new IndexOutOfRangeException ();
  615. type = libgda.gda_value_get_type (value);
  616. switch (type) {
  617. case GdaValueType.Bigint : return GetInt64 (ordinal);
  618. case GdaValueType.Boolean : return GetBoolean (ordinal);
  619. case GdaValueType.Date : return GetDateTime (ordinal);
  620. case GdaValueType.Double : return GetDouble (ordinal);
  621. case GdaValueType.Integer : return GetInt32 (ordinal);
  622. case GdaValueType.Single : return GetFloat (ordinal);
  623. case GdaValueType.Smallint : return GetByte (ordinal);
  624. case GdaValueType.String : return GetString (ordinal);
  625. case GdaValueType.Time : return GetDateTime (ordinal);
  626. case GdaValueType.Timestamp : return GetDateTime (ordinal);
  627. case GdaValueType.Tinyint : return GetByte (ordinal);
  628. }
  629. return (object) libgda.gda_value_stringify (value);
  630. }
  631. [MonoTODO]
  632. public
  633. #if NET_2_0
  634. override
  635. #endif
  636. int GetValues (object[] values)
  637. {
  638. throw new NotImplementedException ();
  639. }
  640. #if !NET_2_0
  641. [MonoTODO]
  642. IDataReader IDataRecord.GetData (int ordinal)
  643. {
  644. throw new NotImplementedException ();
  645. }
  646. #endif
  647. #if NET_2_0
  648. public override IEnumerator GetEnumerator()
  649. #else
  650. IEnumerator IEnumerable.GetEnumerator ()
  651. #endif
  652. {
  653. return new DbEnumerator(this);
  654. }
  655. public
  656. #if NET_2_0
  657. override
  658. #endif
  659. bool IsDBNull (int ordinal)
  660. {
  661. IntPtr value;
  662. if (currentResult == -1)
  663. throw new IndexOutOfRangeException ();
  664. value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
  665. ordinal, currentRow);
  666. if (value == IntPtr.Zero)
  667. throw new IndexOutOfRangeException ();
  668. return libgda.gda_value_is_null (value);
  669. }
  670. public
  671. #if NET_2_0
  672. override
  673. #endif
  674. bool NextResult ()
  675. {
  676. int i = currentResult + 1;
  677. if (i >= 0 && i < gdaResults.Count) {
  678. currentResult++;
  679. return true;
  680. }
  681. return false;
  682. }
  683. public
  684. #if NET_2_0
  685. override
  686. #endif
  687. bool Read ()
  688. {
  689. if (currentResult < 0 || currentResult >= gdaResults.Count)
  690. return false;
  691. currentRow++;
  692. if (currentRow < libgda.gda_data_model_get_n_rows ((IntPtr) gdaResults[currentResult]))
  693. return true;
  694. return false;
  695. }
  696. #endregion
  697. #region Destructors
  698. private new void Dispose (bool disposing)
  699. {
  700. if (!this.disposed) {
  701. if (disposing) {
  702. // release any managed resources
  703. command = null;
  704. GC.SuppressFinalize (this);
  705. }
  706. // release any unmanaged resources
  707. if (gdaResults != null) {
  708. gdaResults.Clear ();
  709. gdaResults = null;
  710. }
  711. // close any handles
  712. if (open)
  713. Close ();
  714. this.disposed = true;
  715. }
  716. }
  717. void IDisposable.Dispose() {
  718. Dispose (true);
  719. }
  720. ~OleDbDataReader() {
  721. Dispose (false);
  722. }
  723. #endregion // Destructors
  724. }
  725. }