From 533db1f6d6d847466b8f63b7ce4024b45d318225 Mon Sep 17 00:00:00 2001 From: Rodrigo Moya Date: Fri, 16 Aug 2002 02:31:27 +0000 Subject: [PATCH] 2002-08-16 Rodrigo Moya * 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 --- mcs/class/System.Data/ChangeLog | 13 +++ .../System.Data.OleDb/OleDbDataReader.cs | 89 +++++++++++++++---- .../System.Data.OleDb/TestOleDb.cs | 25 +++++- .../System.Data/System.Data.OleDb/libgda.cs | 12 +++ 4 files changed, 119 insertions(+), 20 deletions(-) diff --git a/mcs/class/System.Data/ChangeLog b/mcs/class/System.Data/ChangeLog index 496c39ab786..f7ca97baed2 100644 --- a/mcs/class/System.Data/ChangeLog +++ b/mcs/class/System.Data/ChangeLog @@ -1,5 +1,18 @@ +2002-08-16 Rodrigo Moya + + * 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 + * System.Data.OleDb/libgda.cs: added new needed libgda functions. + * System.Data.OleDb/OleDbParameterCollection.cs (GdaParameterList): create an empty GdaParameterList. 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 @@ -82,9 +82,21 @@ namespace System.Data.OleDb [DllImport("gda-2")] 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); -- 2.25.1