2 // System.Data.SqlClient.SqlDataReader.cs
5 // Rodrigo Moya (rodrigo@ximian.com)
6 // Daniel Morgan (danmorg@sc.rr.com)
8 // (C) Ximian, Inc 2002
9 // (C) Daniel Morgan 2002
12 // SQL and concepts were used from libgda 0.8.190 (GNOME Data Access)
\r
13 // http://www.gnome-db.org/
\r
14 // with permission from the authors of the
\r
15 // PostgreSQL provider in libgda:
\r
16 // Michael Lausch <michael@lausch.at>
17 // Rodrigo Moya <rodrigo@gnome-db.org>
18 // Vivien Malerba <malerba@gnome-db.org>
19 // Gonzalo Paniagua Javier <gonzalo@gnome-db.org>
23 using System.Collections;
24 using System.ComponentModel;
27 namespace System.Data.SqlClient {
29 /// Provides a means of reading one or more forward-only streams
30 /// of result sets obtained by executing a command
31 /// at a SQL database.
33 //public sealed class SqlDataReader : MarshalByRefObject,
34 // IEnumerable, IDataReader, IDisposable, IDataRecord
35 public sealed class SqlDataReader : IEnumerable,
36 IDataReader, IDataRecord {
39 private SqlCommand cmd;
40 private DataTable table;
42 private object[] fields;
43 private string[] types; // PostgreSQL Type
44 private bool[] isNull;
46 private bool open = false;
47 IntPtr pgResult; // PGresult
51 private int currentRow = -1; // no Read() has been done yet
57 internal SqlDataReader (SqlCommand sqlCmd,
58 DataTable dataTableSchema, IntPtr pg_result,
59 int rowCount, int fieldCount, string[] pgtypes) {
62 table = dataTableSchema;
72 #region Public Methods
77 PostgresLibrary.PQclear (pgResult);
79 // TODO: change busy state on SqlConnection to not busy
83 public DataTable GetSchemaTable() {
88 public bool NextResult() {
89 throw new NotImplementedException ();
95 fields = new object[cols]; // re-init row
98 if(currentRow < rows - 1) {
101 for(c = 0; c < cols; c++) {
104 value = PostgresLibrary.
111 columnIsNull = PostgresLibrary.
112 PQgetisnull(pgResult,
117 actualLength = PostgresLibrary.
118 PQgetlength(pgResult,
121 dbType = PostgresHelper.
122 TypnameToSqlDbType(types[c]);
124 fields[c] = PostgresHelper.
125 ConvertDbTypeToSystem (
135 public byte GetByte(int i) {
136 throw new NotImplementedException ();
140 public long GetBytes(int i, long fieldOffset,
141 byte[] buffer, int bufferOffset,
143 throw new NotImplementedException ();
147 public char GetChar(int i) {
148 throw new NotImplementedException ();
152 public long GetChars(int i, long fieldOffset,
153 char[] buffer, int bufferOffset,
155 throw new NotImplementedException ();
159 public IDataReader GetData(int i) {
160 throw new NotImplementedException ();
164 public string GetDataTypeName(int i) {
165 throw new NotImplementedException ();
169 public DateTime GetDateTime(int i) {
170 throw new NotImplementedException ();
174 public decimal GetDecimal(int i) {
175 return (decimal) fields[i];
179 public double GetDouble(int i) {
180 return (double) fields[i];
184 public Type GetFieldType(int i) {
185 throw new NotImplementedException ();
189 public float GetFloat(int i) {
190 return (float) fields[i];
194 public Guid GetGuid(int i) {
195 throw new NotImplementedException ();
199 public short GetInt16(int i) {
200 return (short) fields[i];
204 public int GetInt32(int i) {
205 return (int) fields[i];
209 public long GetInt64(int i) {
210 return (long) fields[i];
214 public string GetName(int i) {
215 return table.Columns[i].ColumnName;
219 public int GetOrdinal(string name) {
220 throw new NotImplementedException ();
224 public string GetString(int i) {
225 return (string) fields[i];
229 public object GetValue(int i) {
234 public int GetValues(object[] values) {
235 throw new NotImplementedException ();
239 public bool IsDBNull(int i) {
240 throw new NotImplementedException ();
244 public bool GetBoolean(int i) {
245 return (bool) fields[i];
249 public IEnumerator GetEnumerator() {
250 throw new NotImplementedException ();
253 #endregion // Public Methods
258 public void Dispose () {
265 #endregion // Destructors
272 throw new NotImplementedException ();
276 public bool IsClosed {
286 public int RecordsAffected {
289 throw new NotImplementedException ();
293 public int FieldCount {
300 public object this[string name] {
304 for(i = 0; i < cols; i ++) {
305 if(table.Columns[i].ColumnName.Equals(name)) {
311 for(i = 0; i < cols; i++) {
315 ta = table.Columns[i].ColumnName.ToUpper();
323 throw new MissingFieldException("Missing field: " + name);
327 public object this[int i] {
334 #endregion // Properties