Explorar el Código

2002-08-18 Rodrigo Moya <[email protected]>

	* 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
Rodrigo Moya hace 23 años
padre
commit
ab46838857

+ 15 - 0
mcs/class/System.Data/ChangeLog

@@ -1,3 +1,18 @@
+2002-08-18  Rodrigo Moya <[email protected]>
+
+	* 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 <[email protected]>
 
 	* System.Data.OleDb/OleDbConnection.cs (ServerVersion): implemented.

+ 7 - 1
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 ()

+ 29 - 8
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

+ 17 - 4
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) 
 		{

+ 76 - 9
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

+ 8 - 0
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)",

+ 19 - 0
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);
+		
 	}
 }