diff options
author | Rodrigo Moya <rodrigo@mono-cvs.ximian.com> | 2002-08-16 06:31:27 +0400 |
---|---|---|
committer | Rodrigo Moya <rodrigo@mono-cvs.ximian.com> | 2002-08-16 06:31:27 +0400 |
commit | 533db1f6d6d847466b8f63b7ce4024b45d318225 (patch) | |
tree | 4ee9d6f3905d026a2b5d2f982087ffa47d0bb4da /mcs/class/System.Data/System.Data.OleDb | |
parent | 9a9a2552ee44d4cf0f13d997c393c3d19e776001 (diff) |
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.
svn path=/trunk/mcs/; revision=6662
Diffstat (limited to 'mcs/class/System.Data/System.Data.OleDb')
-rw-r--r-- | mcs/class/System.Data/System.Data.OleDb/OleDbDataReader.cs | 89 | ||||
-rw-r--r-- | mcs/class/System.Data/System.Data.OleDb/TestOleDb.cs | 25 | ||||
-rw-r--r-- | mcs/class/System.Data/System.Data.OleDb/libgda.cs | 12 |
3 files changed, 106 insertions, 20 deletions
diff --git a/mcs/class/System.Data/System.Data.OleDb/OleDbDataReader.cs b/mcs/class/System.Data/System.Data.OleDb/OleDbDataReader.cs index afe0ed673f4..fdf8d785538 100644 --- a/mcs/class/System.Data/System.Data.OleDb/OleDbDataReader.cs +++ b/mcs/class/System.Data/System.Data.OleDb/OleDbDataReader.cs @@ -132,23 +132,33 @@ namespace System.Data.OleDb 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] @@ -156,11 +166,22 @@ namespace System.Data.OleDb { 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] @@ -175,10 +196,19 @@ namespace System.Data.OleDb 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] @@ -265,10 +295,23 @@ namespace System.Data.OleDb 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] @@ -306,7 +349,6 @@ namespace System.Data.OleDb int i = currentResult + 1; if (i >= 0 && i < gdaResults.Count) { currentResult++; - currentRow = 0; return true; } @@ -315,7 +357,16 @@ namespace System.Data.OleDb 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 diff --git a/mcs/class/System.Data/System.Data.OleDb/TestOleDb.cs b/mcs/class/System.Data/System.Data.OleDb/TestOleDb.cs index 2becacc4aef..bc9ebc26b86 100644 --- a/mcs/class/System.Data/System.Data.OleDb/TestOleDb.cs +++ b/mcs/class/System.Data/System.Data.OleDb/TestOleDb.cs @@ -13,12 +13,35 @@ namespace System.Data.OleDb.Test 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 () diff --git a/mcs/class/System.Data/System.Data.OleDb/libgda.cs b/mcs/class/System.Data/System.Data.OleDb/libgda.cs index 8a9dc3dd70b..070c3fbc868 100644 --- a/mcs/class/System.Data/System.Data.OleDb/libgda.cs +++ b/mcs/class/System.Data/System.Data.OleDb/libgda.cs @@ -83,9 +83,21 @@ namespace System.Data.OleDb public static extern bool gda_value_get_boolean (IntPtr value); [DllImport("gda-2")] + public static extern int gda_value_get_smallint (IntPtr value); + + [DllImport("gda-2")] + public static extern byte gda_value_get_tinyint (IntPtr value); + + [DllImport("gda-2")] + public static extern string gda_value_stringify (IntPtr value); + + [DllImport("gda-2")] public static extern IntPtr gda_parameter_list_new (); [DllImport("gda-2")] + public static extern string gda_type_to_string (GdaValueType type); + + [DllImport("gda-2")] public static extern int gda_data_model_get_n_rows (IntPtr model); [DllImport("gda-2")] |