From ab468388578d622b1dccfee104ece5671fdbffa8 Mon Sep 17 00:00:00 2001 From: Rodrigo Moya Date: Sun, 18 Aug 2002 18:35:06 +0000 Subject: [PATCH] 2002-08-18 Rodrigo Moya * System.Data.OleDb/OleDbConnection.cs (ChangeDatabase): implemented. * System.Data.OleDb/OleDbException.cs (OleDbException): added internal constructor. (ErrorCode, Message, Source, Errors): implemented. * System.Data.OleDb/OleDbError.cs: implemented the full class. * System.Data.OleDb/libgda.cs: added more libgda functions. * System.Data.OleDb/TestOleDb.cs (TestOleDb): display properties for the opened connection. svn path=/trunk/mcs/; revision=6725 --- mcs/class/System.Data/ChangeLog | 15 ++++ .../System.Data.OleDb/OleDbConnection.cs | 8 +- .../System.Data.OleDb/OleDbError.cs | 37 ++++++-- .../System.Data.OleDb/OleDbErrorCollection.cs | 21 ++++- .../System.Data.OleDb/OleDbException.cs | 85 +++++++++++++++++-- .../System.Data.OleDb/TestOleDb.cs | 8 ++ .../System.Data/System.Data.OleDb/libgda.cs | 19 +++++ 7 files changed, 171 insertions(+), 22 deletions(-) diff --git a/mcs/class/System.Data/ChangeLog b/mcs/class/System.Data/ChangeLog index 7c1cc4e6533..c97b385addc 100644 --- a/mcs/class/System.Data/ChangeLog +++ b/mcs/class/System.Data/ChangeLog @@ -1,3 +1,18 @@ +2002-08-18 Rodrigo Moya + + * System.Data.OleDb/OleDbConnection.cs (ChangeDatabase): implemented. + + * System.Data.OleDb/OleDbException.cs (OleDbException): added internal + constructor. + (ErrorCode, Message, Source, Errors): implemented. + + * System.Data.OleDb/OleDbError.cs: implemented the full class. + + * System.Data.OleDb/libgda.cs: added more libgda functions. + + * System.Data.OleDb/TestOleDb.cs (TestOleDb): display properties for + the opened connection. + 2002-08-18 Rodrigo Moya * System.Data.OleDb/OleDbConnection.cs (ServerVersion): implemented. diff --git a/mcs/class/System.Data/System.Data.OleDb/OleDbConnection.cs b/mcs/class/System.Data/System.Data.OleDb/OleDbConnection.cs index 68854ce897d..a172246bfc5 100644 --- a/mcs/class/System.Data/System.Data.OleDb/OleDbConnection.cs +++ b/mcs/class/System.Data/System.Data.OleDb/OleDbConnection.cs @@ -156,7 +156,13 @@ namespace System.Data.OleDb public void ChangeDatabase (string name) { - // FIXME: see http://bugzilla.gnome.org/show_bug.cgi?id=83315 + if (gdaConnection == IntPtr.Zero) + throw new ArgumentException (); + if (State != ConnectionState.Open) + throw new InvalidOperationException (); + + if (!libgda.gda_connection_change_database (gdaConnection, name)) + throw new OleDbException (this); } public void Close () diff --git a/mcs/class/System.Data/System.Data.OleDb/OleDbError.cs b/mcs/class/System.Data/System.Data.OleDb/OleDbError.cs index 6be0721c2cb..b672820a095 100644 --- a/mcs/class/System.Data/System.Data.OleDb/OleDbError.cs +++ b/mcs/class/System.Data/System.Data.OleDb/OleDbError.cs @@ -16,26 +16,47 @@ namespace System.Data.OleDb { public sealed class OleDbError { + private string errorMessage; + private int nativeError; + private string errorSource; + private string sqlState; + + #region Constructors + + internal OleDbError (string msg, int code, string source, string sql) + { + errorMessage = msg; + nativeError = code; + errorSource = source; + sqlState = sql; + } + + #endregion // Constructors + #region Properties public string Message { - [MonoTODO] - get { throw new NotImplementedException (); } + get { + return errorMessage; + } } public int NativeError { - [MonoTODO] - get { throw new NotImplementedException (); } + get { + return nativeError; + } } public string Source { - [MonoTODO] - get { throw new NotImplementedException (); } + get { + return errorSource; + } } public string SqlState { - [MonoTODO] - get { throw new NotImplementedException (); } + get { + return sqlState; + } } #endregion diff --git a/mcs/class/System.Data/System.Data.OleDb/OleDbErrorCollection.cs b/mcs/class/System.Data/System.Data.OleDb/OleDbErrorCollection.cs index 9f0d412ce66..8768459bc2e 100644 --- a/mcs/class/System.Data/System.Data.OleDb/OleDbErrorCollection.cs +++ b/mcs/class/System.Data/System.Data.OleDb/OleDbErrorCollection.cs @@ -26,25 +26,38 @@ namespace System.Data.OleDb #region Properties public int Count { - get { return list.Count; } + get { + return list.Count; + } } public OleDbError this[int index] { - get { return (OleDbError) list[index]; } + get { + return (OleDbError) list[index]; + } } object ICollection.SyncRoot { - get { return list.SyncRoot; } + get { + return list.SyncRoot; + } } bool ICollection.IsSynchronized { - get { return list.IsSynchronized; } + get { + return list.IsSynchronized; + } } #endregion // Properties #region Methods + internal void Add (OleDbError error) + { + list.Add ((object) error); + } + [MonoTODO] public void CopyTo (Array array, int index) { diff --git a/mcs/class/System.Data/System.Data.OleDb/OleDbException.cs b/mcs/class/System.Data/System.Data.OleDb/OleDbException.cs index 9727f111f87..ad66403bd7e 100644 --- a/mcs/class/System.Data/System.Data.OleDb/OleDbException.cs +++ b/mcs/class/System.Data/System.Data.OleDb/OleDbException.cs @@ -19,26 +19,93 @@ namespace System.Data.OleDb [Serializable] public sealed class OleDbException : ExternalException { + private OleDbConnection connection; + + #region Constructors + + internal OleDbException (OleDbConnection cnc) + { + connection = cnc; + } + + #endregion // Constructors + #region Properties public override int ErrorCode { - [MonoTODO] - get { throw new NotImplementedException (); } + get { + GdaList glist; + IntPtr errors; + + errors = libgda.gda_connection_get_errors (connection.GdaConnection); + if (errors != IntPtr.Zero) { + glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList)); + return (int) libgda.gda_error_get_number (glist.data); + } + + return -1; + } } - public OleDbErrorCollection Errors { - [MonoTODO] - get { throw new NotImplementedException (); } + public OleDbErrorCollection Errors { + get { + GdaList glist; + IntPtr errors; + OleDbErrorCollection col = new OleDbErrorCollection (); + + errors = libgda.gda_connection_get_errors (connection.GdaConnection); + if (errors != IntPtr.Zero) { + glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList)); + while (glist != null) { + col.Add (new OleDbError ( + libgda.gda_error_get_description (glist.data), + (int) libgda.gda_error_get_number (glist.data), + libgda.gda_error_get_source (glist.data), + libgda.gda_error_get_sqlstate (glist.data))); + glist = (GdaList) Marshal.PtrToStructure (glist.next, + typeof (GdaList)); + } + } + + return col; + } } public override string Message { - [MonoTODO] - get { throw new NotImplementedException (); } + get { + GdaList glist; + IntPtr errors; + string msg = ""; + + errors = libgda.gda_connection_get_errors (connection.GdaConnection); + if (errors != IntPtr.Zero) { + glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList)); + while (glist != null) { + msg = msg + ";" + libgda.gda_error_get_description (glist.data); + glist = (GdaList) Marshal.PtrToStructure (glist.next, + typeof (GdaList)); + } + + return msg; + } + + return null; + } } public override string Source { - [MonoTODO] - get { throw new NotImplementedException (); } + get { + GdaList glist; + IntPtr errors; + + errors = libgda.gda_connection_get_errors (connection.GdaConnection); + if (errors != IntPtr.Zero) { + glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList)); + return libgda.gda_error_get_source (glist.data); + } + + return null; + } } #endregion // Properties diff --git a/mcs/class/System.Data/System.Data.OleDb/TestOleDb.cs b/mcs/class/System.Data/System.Data.OleDb/TestOleDb.cs index e54d5c0e589..e53495a88aa 100644 --- a/mcs/class/System.Data/System.Data.OleDb/TestOleDb.cs +++ b/mcs/class/System.Data/System.Data.OleDb/TestOleDb.cs @@ -14,6 +14,14 @@ namespace System.Data.OleDb.Test m_cnc = new OleDbConnection ("PostgreSQL"); m_cnc.Open (); + Console.WriteLine ("Connected to:"); + Console.WriteLine (" Data Source: " + m_cnc.DataSource); + Console.WriteLine (" Database: " + m_cnc.Database); + Console.WriteLine (" Connection string: " + m_cnc.ConnectionString); + Console.WriteLine (" Provider: " + m_cnc.Provider); + Console.WriteLine (" Server version:" + m_cnc.ServerVersion); + + /* create temporary table */ Console.WriteLine ("Creating temporary table..."); cmd = new OleDbCommand ("CREATE TABLE mono_test_table ( " + " name varchar(25), email varchar(50), date_entered timestamp)", diff --git a/mcs/class/System.Data/System.Data.OleDb/libgda.cs b/mcs/class/System.Data/System.Data.OleDb/libgda.cs index 513afd5372a..3011f6bda9c 100644 --- a/mcs/class/System.Data/System.Data.OleDb/libgda.cs +++ b/mcs/class/System.Data/System.Data.OleDb/libgda.cs @@ -212,6 +212,9 @@ namespace System.Data.OleDb [DllImport("gda-2")] public static extern string gda_connection_get_password (IntPtr cnc); + [DllImport("gda-2")] + public static extern bool gda_connection_change_database (IntPtr cnc, string name); + [DllImport("gda-2")] public static extern IntPtr gda_transaction_new (string name); @@ -239,6 +242,9 @@ namespace System.Data.OleDb [DllImport("gda-2")] public static extern IntPtr gda_connection_execute_single_command (IntPtr cnc, IntPtr command, IntPtr parameterList); + [DllImport("gda-2")] + public static extern IntPtr gda_connection_get_errors (IntPtr cnc); + [DllImport("gda-2")] public static extern IntPtr gda_command_new (string text, GdaCommandType type, GdaCommandOptions options); @@ -247,5 +253,18 @@ namespace System.Data.OleDb [DllImport("gda-2")] public static extern void gda_command_set_command_type (IntPtr cmd, GdaCommandType type); + + [DllImport("gda-2")] + public static extern string gda_error_get_description (IntPtr error); + + [DllImport("gda-2")] + public static extern long gda_error_get_number (IntPtr error); + + [DllImport("gda-2")] + public static extern string gda_error_get_source (IntPtr error); + + [DllImport("gda-2")] + public static extern string gda_error_get_sqlstate (IntPtr error); + } } -- 2.25.1