+2002-08-16 Rodrigo Moya <rodrigo@ximian.com>
+
+ * System.Data.OleDb/libgda.cs: added new needed libgda functions.
+
+ * System.Data.OleDb/OleDbDataReader.cs (GetBoolean): throw exceptions
+ when there are errors.
+ (GetByte, GetChar, GetDataTypeName, GetValue, Read): implemented.
+
+ * System.Data.OleDb/TestOleDb.cs: added more testing code for data
+ readers.
+
2002-08-15 Rodrigo Moya <rodrigo@ximian.com>
+ * System.Data.OleDb/libgda.cs: added new needed libgda functions.
+
* System.Data.OleDb/OleDbParameterCollection.cs (GdaParameterList):
create an empty GdaParameterList.
IntPtr value;
if (currentResult == -1)
- return false;
+ throw new InvalidCastException ();
value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
ordinal, currentRow);
- if (value != IntPtr.Zero) {
- if (libgda.gda_value_get_vtype (value) != GdaValueType.Boolean)
- throw new InvalidCastException ();
- return libgda.gda_value_get_boolean (value);
- }
-
- return false;
+ if (value == IntPtr.Zero)
+ throw new InvalidCastException ();
+
+ if (libgda.gda_value_get_vtype (value) != GdaValueType.Boolean)
+ throw new InvalidCastException ();
+ return libgda.gda_value_get_boolean (value);
}
- [MonoTODO]
public byte GetByte (int ordinal)
{
- throw new NotImplementedException ();
+ IntPtr value;
+
+ if (currentResult == -1)
+ throw new InvalidCastException ();
+
+ value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
+ ordinal, currentRow);
+ if (value == IntPtr.Zero)
+ throw new InvalidCastException ();
+
+ if (libgda.gda_value_get_vtype (value) != GdaValueType.Tinyint)
+ throw new InvalidCastException ();
+ return libgda.gda_value_get_tinyint (value);
}
[MonoTODO]
{
throw new NotImplementedException ();
}
-
- [MonoTODO]
+
public char GetChar (int ordinal)
{
- throw new NotImplementedException ();
+ IntPtr value;
+
+ if (currentResult == -1)
+ throw new InvalidCastException ();
+
+ value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
+ ordinal, currentRow);
+ if (value == IntPtr.Zero)
+ throw new InvalidCastException ();
+
+ if (libgda.gda_value_get_vtype (value) != GdaValueType.Tinyint)
+ throw new InvalidCastException ();
+ return (char) libgda.gda_value_get_tinyint (value);
}
[MonoTODO]
throw new NotImplementedException ();
}
- [MonoTODO]
public string GetDataTypeName (int index)
{
- throw new NotImplementedException ();
+ IntPtr value;
+
+ if (currentResult == -1)
+ return "unknown";
+
+ value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
+ index, currentRow);
+ if (value == IntPtr.Zero)
+ return "unknown";
+
+ return libgda.gda_type_to_string (libgda.gda_value_get_vtype (value));
}
[MonoTODO]
throw new NotImplementedException ();
}
- [MonoTODO]
public object GetValue (int ordinal)
{
- throw new NotImplementedException ();
+ IntPtr value;
+ GdaValueType type;
+
+ if (currentResult == -1)
+ throw new IndexOutOfRangeException ();
+
+ value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
+ ordinal, currentRow);
+ if (value == IntPtr.Zero)
+ throw new IndexOutOfRangeException ();
+
+ type = libgda.gda_value_get_vtype (value);
+ // FIXME: return correct type
+
+ return (object) libgda.gda_value_stringify (value);
}
[MonoTODO]
int i = currentResult + 1;
if (i >= 0 && i < gdaResults.Count) {
currentResult++;
- currentRow = 0;
return true;
}
public bool Read ()
{
- throw new NotImplementedException ();
+ if (currentResult < 0 ||
+ currentResult >= gdaResults.Count)
+ return false;
+
+ currentRow++;
+ if (currentRow <
+ libgda.gda_data_model_get_n_rows ((IntPtr) gdaResults[currentResult]))
+ return true;
+
+ return false;
}
#endregion
m_cnc.Open ();
}
+ void DisplayRow (IDataReader reader)
+ {
+ for (int i = 0; i < reader.FieldCount; i++) {
+ Console.WriteLine (" " + reader.GetDataTypeName (i) + ": " +
+ reader.GetValue (i).ToString ());
+ }
+ }
+
void TestDataReader ()
{
+ int i = 0;
string sql = "SELECT * FROM pg_tables";
+
+ Console.WriteLine ("Executing command...");
OleDbCommand cmd = new OleDbCommand (sql, m_cnc);
-
IDataReader reader = cmd.ExecuteReader ();
+
+ Console.WriteLine (" Recordset description:");
+ for (i = 0; i < reader.FieldCount; i++) {
+ Console.WriteLine (" Field " + i + ": " + reader.GetDataTypeName (i));
+ }
+
+ Console.WriteLine ("Reading data...");
+ i = 0;
+ while (reader.Read ()) {
+ Console.WriteLine ("Row " + i + ":");
+ DisplayRow (reader);
+ i++;
+ }
}
void Close ()