2002-08-18 Rodrigo Moya <rodrigo@ximian.com>
authorRodrigo Moya <rodrigo@mono-cvs.ximian.com>
Sun, 18 Aug 2002 18:35:06 +0000 (18:35 -0000)
committerRodrigo Moya <rodrigo@mono-cvs.ximian.com>
Sun, 18 Aug 2002 18:35:06 +0000 (18:35 -0000)
* 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
mcs/class/System.Data/System.Data.OleDb/OleDbConnection.cs
mcs/class/System.Data/System.Data.OleDb/OleDbError.cs
mcs/class/System.Data/System.Data.OleDb/OleDbErrorCollection.cs
mcs/class/System.Data/System.Data.OleDb/OleDbException.cs
mcs/class/System.Data/System.Data.OleDb/TestOleDb.cs
mcs/class/System.Data/System.Data.OleDb/libgda.cs

index 7c1cc4e6533c9e4a53028625b86377f8b9edea40..c97b385addc1f972c362a8679b04ed5cd03256fd 100644 (file)
@@ -1,3 +1,18 @@
+2002-08-18  Rodrigo Moya <rodrigo@ximian.com>
+
+       * 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 <rodrigo@ximian.com>
 
        * System.Data.OleDb/OleDbConnection.cs (ServerVersion): implemented.
index 68854ce897dc9355671b1aada857ae0f412d08a9..a172246bfc5e7d0231832e5455b1b96f4fe0f61b 100644 (file)
@@ -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 ()
index 6be0721c2cb4f823dc2aeac385e58e5434636510..b672820a0956dc3ac7b5203de2483163dd4379d7 100644 (file)
@@ -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
index 9f0d412ce662205fd3d2fc1aea08439e4cf444eb..8768459bc2edfa327764ccd82b6fc840fd6b9718 100644 (file)
@@ -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) 
                {
index 9727f111f8785368000132822df6bb60735e0718..ad66403bd7e3411e614595ac0828d48edebaec01 100644 (file)
@@ -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
index e54d5c0e5898cf2f6a23c3b272542c7131ccddc2..e53495a88aaf2e29d7d23e8e334497a3b234b225 100644 (file)
@@ -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)",
index 513afd5372a4d3fa9578ce5eb56c82c70aa97222..3011f6bda9cee273c3ceb69180b9051804c78059 100644 (file)
@@ -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);
+               
        }
 }