SqlDataReader.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. //
  2. // System.Data.SqlClient.SqlDataReader.cs
  3. //
  4. // Author:
  5. // Rodrigo Moya ([email protected])
  6. // Daniel Morgan ([email protected])
  7. //
  8. // (C) Ximian, Inc 2002
  9. //
  10. using System;
  11. using System.Collections;
  12. using System.ComponentModel;
  13. using System.Data;
  14. namespace System.Data.SqlClient
  15. {
  16. /// <summary>
  17. /// Provides a means of reading one or more forward-only streams
  18. /// of result sets obtained by executing a command
  19. /// at a SQL database.
  20. /// </summary>
  21. //public sealed class SqlDataReader : MarshalByRefObject,
  22. // IEnumerable, IDataReader, IDisposable, IDataRecord
  23. public sealed class SqlDataReader : IEnumerable,
  24. IDataReader, IDataRecord
  25. {
  26. #region Fields
  27. private SqlCommand cmd;
  28. private DataTable table;
  29. private object[] fields;
  30. private int[] oid; // PostgreSQL Type
  31. private bool open = false;
  32. IntPtr pgResult; // PGresult
  33. private int rows;
  34. private int cols;
  35. private int currentRow = -1; // no Read() has been done yet
  36. #endregion // Fields
  37. #region Constructors
  38. internal SqlDataReader (SqlCommand sqlCmd,
  39. DataTable dataTableSchema, IntPtr pg_result,
  40. int rowCount, int fieldCount, int[] oids) {
  41. cmd = sqlCmd;
  42. table = dataTableSchema;
  43. pgResult = pg_result;
  44. rows = rowCount;
  45. cols = fieldCount;
  46. oid = oids;
  47. }
  48. #endregion
  49. #region Public Methods
  50. [MonoTODO]
  51. public void Close()
  52. {
  53. // close result set
  54. PostgresLibrary.PQclear (pgResult);
  55. // TODO: change busy state on SqlConnection to not busy
  56. }
  57. [MonoTODO]
  58. public DataTable GetSchemaTable()
  59. {
  60. return table;
  61. }
  62. [MonoTODO]
  63. public bool NextResult()
  64. {
  65. throw new NotImplementedException ();
  66. }
  67. [MonoTODO]
  68. public bool Read()
  69. {
  70. string value;
  71. fields = new object[cols]; // re-init row
  72. if(currentRow < rows - 1) {
  73. currentRow++;
  74. int c;
  75. for(c = 0; c < cols; c++) {
  76. // get data value
  77. value = PostgresLibrary.
  78. PQgetvalue(
  79. pgResult,
  80. currentRow, c);
  81. int columnIsNull;
  82. // is column NULL?
  83. columnIsNull = PostgresLibrary.
  84. PQgetisnull(pgResult,
  85. currentRow, c);
  86. int actualLength;
  87. // get Actual Length
  88. actualLength = PostgresLibrary.
  89. PQgetlength(pgResult,
  90. currentRow, c);
  91. fields[c] = PostgresHelper.
  92. ConvertPgTypeToSystem (oid[c], value);
  93. }
  94. return true;
  95. }
  96. return false; // EOF
  97. }
  98. [MonoTODO]
  99. public byte GetByte(int i)
  100. {
  101. throw new NotImplementedException ();
  102. }
  103. [MonoTODO]
  104. public long GetBytes(int i, long fieldOffset,
  105. byte[] buffer, int bufferOffset,
  106. int length)
  107. {
  108. throw new NotImplementedException ();
  109. }
  110. [MonoTODO]
  111. public char GetChar(int i)
  112. {
  113. throw new NotImplementedException ();
  114. }
  115. [MonoTODO]
  116. public long GetChars(int i, long fieldOffset,
  117. char[] buffer, int bufferOffset,
  118. int length)
  119. {
  120. throw new NotImplementedException ();
  121. }
  122. [MonoTODO]
  123. public IDataReader GetData(int i)
  124. {
  125. throw new NotImplementedException ();
  126. }
  127. [MonoTODO]
  128. public string GetDataTypeName(int i)
  129. {
  130. throw new NotImplementedException ();
  131. }
  132. [MonoTODO]
  133. public DateTime GetDateTime(int i)
  134. {
  135. throw new NotImplementedException ();
  136. }
  137. [MonoTODO]
  138. public decimal GetDecimal(int i)
  139. {
  140. throw new NotImplementedException ();
  141. }
  142. [MonoTODO]
  143. public double GetDouble(int i)
  144. {
  145. throw new NotImplementedException ();
  146. }
  147. [MonoTODO]
  148. public Type GetFieldType(int i)
  149. {
  150. throw new NotImplementedException ();
  151. }
  152. [MonoTODO]
  153. public float GetFloat(int i)
  154. {
  155. throw new NotImplementedException ();
  156. }
  157. [MonoTODO]
  158. public Guid GetGuid(int i)
  159. {
  160. throw new NotImplementedException ();
  161. }
  162. [MonoTODO]
  163. public short GetInt16(int i)
  164. {
  165. return (short) fields[i];
  166. }
  167. [MonoTODO]
  168. public int GetInt32(int i)
  169. {
  170. return (int) fields[i];
  171. }
  172. [MonoTODO]
  173. public long GetInt64(int i)
  174. {
  175. return (long) fields[i];
  176. }
  177. [MonoTODO]
  178. public string GetName(int i)
  179. {
  180. return table.Columns[i].ColumnName;
  181. }
  182. [MonoTODO]
  183. public int GetOrdinal(string name)
  184. {
  185. throw new NotImplementedException ();
  186. }
  187. [MonoTODO]
  188. public string GetString(int i)
  189. {
  190. return (string) fields[i];
  191. }
  192. [MonoTODO]
  193. public object GetValue(int i)
  194. {
  195. return fields[i];
  196. }
  197. [MonoTODO]
  198. public int GetValues(object[] values)
  199. {
  200. throw new NotImplementedException ();
  201. }
  202. [MonoTODO]
  203. public bool IsDBNull(int i)
  204. {
  205. throw new NotImplementedException ();
  206. }
  207. [MonoTODO]
  208. public bool GetBoolean(int i)
  209. {
  210. throw new NotImplementedException ();
  211. }
  212. [MonoTODO]
  213. public IEnumerator GetEnumerator() {
  214. throw new NotImplementedException ();
  215. }
  216. #endregion // Public Methods
  217. #region Destructors
  218. [MonoTODO]
  219. public void Dispose () {
  220. }
  221. [MonoTODO]
  222. ~SqlDataReader() {
  223. }
  224. #endregion // Destructors
  225. #region Properties
  226. public int Depth {
  227. [MonoTODO]
  228. get {
  229. throw new NotImplementedException ();
  230. }
  231. }
  232. public bool IsClosed {
  233. [MonoTODO]
  234. get {
  235. throw new NotImplementedException ();
  236. }
  237. }
  238. public int RecordsAffected {
  239. [MonoTODO]
  240. get {
  241. throw new NotImplementedException ();
  242. }
  243. }
  244. public int FieldCount {
  245. [MonoTODO]
  246. get {
  247. return cols;
  248. }
  249. }
  250. public object this[string name] {
  251. [MonoTODO]
  252. get {
  253. int i;
  254. for(i = 0; i < cols; i ++) {
  255. if(table.Columns[i].ColumnName.Equals(name)) {
  256. return fields[i];
  257. }
  258. }
  259. if(i == cols) {
  260. for(i = 0; i < cols; i++) {
  261. string ta;
  262. string n;
  263. ta = table.Columns[i].ColumnName.ToUpper();
  264. n = name.ToUpper();
  265. if(ta.Equals(n)) {
  266. return fields[i];
  267. }
  268. }
  269. }
  270. throw new MissingFieldException("Missing field: " + name);
  271. }
  272. }
  273. public object this[int i] {
  274. [MonoTODO]
  275. get
  276. {
  277. return fields[i];
  278. }
  279. }
  280. #endregion // Properties
  281. }
  282. }