Merge pull request #439 from mono-soc-2012/garyb/iconfix
[mono.git] / mcs / class / System.Data / System.Data.OleDb / OleDbConnection.cs
index 7ee3e9cceb8c5187ac5079c45fc32ce41ab184c7..2cf99546123cde59e1c2acd9b8e25b6574579f44 100644 (file)
@@ -36,11 +36,18 @@ using System.ComponentModel;
 using System.Data;
 using System.Data.Common;
 using System.EnterpriseServices;
+#if NET_2_0
+using System.Transactions;
+#endif
 
 namespace System.Data.OleDb
 {
-       [DefaultEvent ("InfoMessage")]  
+       [DefaultEvent ("InfoMessage")]
+#if NET_2_0
+       public sealed class OleDbConnection : DbConnection, ICloneable
+#else
        public sealed class OleDbConnection : Component, ICloneable, IDbConnection
+#endif
        {
                #region Fields
 
@@ -54,10 +61,8 @@ namespace System.Data.OleDb
                
                public OleDbConnection ()
                {
-                       libgda.gda_init ("System.Data.OleDb", "1.0", 0, new string [0]);
                        gdaConnection = IntPtr.Zero;
                        connectionTimeout = 15;
-                       connectionString = null;
                }
 
                public OleDbConnection (string connectionString) : this ()
@@ -71,12 +76,13 @@ namespace System.Data.OleDb
                
                [DataCategory ("Data")]
                [DefaultValue ("")]
-               [DataSysDescriptionAttribute ("Information used to connect to a Data Source.")]
                [EditorAttribute ("Microsoft.VSDesigner.Data.ADO.Design.OleDbConnectionStringEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
-               [RecommendedAsConfigurableAttribute (true)]
+               [RecommendedAsConfigurable (true)]
                [RefreshPropertiesAttribute (RefreshProperties.All)]
-               public string ConnectionString {
+               public override string ConnectionString {
                        get {
+                               if (connectionString == null)
+                                       return string.Empty;
                                return connectionString;
                        }
                        set {
@@ -85,71 +91,61 @@ namespace System.Data.OleDb
                }
 
                [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
-               [DataSysDescriptionAttribute ("Current connection timeout value, 'Connect Timeout=X' in the ConnectionString.")]
-               public int ConnectionTimeout {
+               public override int ConnectionTimeout {
                        get {
                                return connectionTimeout;
                        }
                }
 
                [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
-                [DataSysDescriptionAttribute ("Current data source catalog value, 'Initial Catalog=X' in the connection string.")]
-               public string Database { 
+               public override 
+               string Database {
                        get {
                                if (gdaConnection != IntPtr.Zero
-                                   && libgda.gda_connection_is_open (gdaConnection)) {
+                                       && libgda.gda_connection_is_open (gdaConnection)) {
                                        return libgda.gda_connection_get_database (gdaConnection);
                                }
 
-                               return null;
+                               return string.Empty;
                        }
                }
 
-               [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
-                [DataSysDescriptionAttribute ("Current data source, 'Data Source=X' in the connection string.")]
-               public string DataSource {
+               [BrowsableAttribute (true)]
+               public override string DataSource {
                        get {
                                if (gdaConnection != IntPtr.Zero
-                                   && libgda.gda_connection_is_open (gdaConnection)) {
+                                       && libgda.gda_connection_is_open (gdaConnection)) {
                                        return libgda.gda_connection_get_dsn (gdaConnection);
                                }
 
-                               return null;
+                               return string.Empty;
                        }
                }
 
                [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
-                [DataSysDescriptionAttribute ("Current OLE DB provider progid, 'Provider=X' in the connection string.")]
+               [BrowsableAttribute (true)]
                public string Provider {
                        get {
                                if (gdaConnection != IntPtr.Zero
-                                   && libgda.gda_connection_is_open (gdaConnection)) {
+                                       && libgda.gda_connection_is_open (gdaConnection)) {
                                        return libgda.gda_connection_get_provider (gdaConnection);
                                }
 
-                               return null;
+                               return string.Empty;
                        }
                }
 
-               [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
-                [DataSysDescriptionAttribute ("Version of the product accessed by the OLE DB Provider.")]
-               [BrowsableAttribute (false)]
-               public string ServerVersion {
+               public override string ServerVersion {
                        get {
-                               if (gdaConnection != IntPtr.Zero
-                                   && libgda.gda_connection_is_open (gdaConnection)) {
-                                       return libgda.gda_connection_get_server_version (gdaConnection);
-                               }
-
-                               return null;
+                               if (State == ConnectionState.Closed)
+                                       throw ExceptionHelper.ConnectionClosed ();
+                               return libgda.gda_connection_get_server_version (gdaConnection);
                        }
                }
 
                [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
-                [DataSysDescriptionAttribute ("The ConnectionState indicating whether the connection is open or closed.")]
-                [BrowsableAttribute (false)]
-               public ConnectionState State
-               {
+               [BrowsableAttribute (false)]
+               public override ConnectionState State {
                        get {
                                if (gdaConnection != IntPtr.Zero) {
                                        if (libgda.gda_connection_is_open (gdaConnection))
@@ -160,8 +156,7 @@ namespace System.Data.OleDb
                        }
                }
 
-               internal IntPtr GdaConnection
-               {
+               internal IntPtr GdaConnection {
                        get {
                                return gdaConnection;
                        }
@@ -171,44 +166,40 @@ namespace System.Data.OleDb
        
                #region Methods
        
-               public OleDbTransaction BeginTransaction ()
+               public new OleDbTransaction BeginTransaction ()
                {
-                       if (gdaConnection != IntPtr.Zero)
-                               return new OleDbTransaction (this);
-
-                       return null;
+                       if (State == ConnectionState.Closed)
+                               throw ExceptionHelper.ConnectionClosed ();
+                       return new OleDbTransaction (this);
                }
 
-               IDbTransaction IDbConnection.BeginTransaction ()
+               public new OleDbTransaction BeginTransaction (IsolationLevel isolationLevel)
                {
-                       return BeginTransaction ();
+                       if (State == ConnectionState.Closed)
+                               throw ExceptionHelper.ConnectionClosed ();
+                       return new OleDbTransaction (this, isolationLevel);
                }
-               
-               public OleDbTransaction BeginTransaction (IsolationLevel level)
-               {
-                       if (gdaConnection != IntPtr.Zero)
-                               return new OleDbTransaction (this, level);
 
-                       return null;
+               protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
+               {
+                       return BeginTransaction (isolationLevel);
                }
 
-               IDbTransaction IDbConnection.BeginTransaction (IsolationLevel level)
+               protected override DbCommand CreateDbCommand()
                {
-                       return BeginTransaction (level);
+                       return CreateCommand ();
                }
 
-               public void ChangeDatabase (string name)
+               public override void ChangeDatabase (string value)
                {
-                       if (gdaConnection == IntPtr.Zero)
-                               throw new ArgumentException ();
                        if (State != ConnectionState.Open)
                                throw new InvalidOperationException ();
 
-                       if (!libgda.gda_connection_change_database (gdaConnection, name))
+                       if (!libgda.gda_connection_change_database (gdaConnection, value))
                                throw new OleDbException (this);
                }
 
-               public void Close ()
+               public override void Close ()
                {
                        if (State == ConnectionState.Open) {
                                libgda.gda_connection_close (gdaConnection);
@@ -216,7 +207,7 @@ namespace System.Data.OleDb
                        }
                }
 
-               public OleDbCommand CreateCommand ()
+               public new OleDbCommand CreateCommand ()
                {
                        if (State == ConnectionState.Open)
                                return new OleDbCommand (null, this);
@@ -242,28 +233,28 @@ namespace System.Data.OleDb
                        throw new NotImplementedException();
                }
 
-               IDbCommand IDbConnection.CreateCommand ()
-               {
-                       return CreateCommand ();
-               }
-
-               public void Open ()
+               public
+#if NET_2_0
+               override
+#endif
+               void Open ()
                {
-                       string provider = "Default";
-                       string gdaCncStr = "";
-                       string[] args;
-                       int len;
-                       char [] separator = { ';' };
+//                     string provider = "Default";
+//                     string gdaCncStr = string.Empty;
+//                     string[] args;
+//                     int len;
+//                     char [] separator = { ';' };
                        
                        if (State == ConnectionState.Open)
                                throw new InvalidOperationException ();
 
+                       libgda.gda_init ("System.Data.OleDb", "1.0", 0, new string [0]);
+
                        gdaConnection = libgda.gda_client_open_connection (libgda.GdaClient,
-                                                                          connectionString,
-                                                                          "", "", 0);
+                               ConnectionString, string.Empty, string.Empty, 0);
 
-                       if (gdaConnection==IntPtr.Zero)
-                               throw new OleDbException (this);        
+                       if (gdaConnection == IntPtr.Zero)
+                               throw new OleDbException (this);
                        /* convert the connection string to its GDA equivalent */
                        //args = connectionString.Split (';');
                        //len = args.Length;
@@ -313,17 +304,58 @@ namespace System.Data.OleDb
                        throw new NotImplementedException ();
                }
 
+#if NET_2_0
+               [MonoTODO]
+               public override void EnlistTransaction (Transaction transaction)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               public override DataTable GetSchema ()
+               {
+                       if (State == ConnectionState.Closed)
+                               throw ExceptionHelper.ConnectionClosed ();
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               public override DataTable GetSchema(string collectionName)
+               {
+                       return GetSchema (collectionName, null);
+               }
+
+               [MonoTODO]
+               public override DataTable GetSchema (String collectionName, string [] restrictionValues)
+               {
+                       if (State == ConnectionState.Closed)
+                               throw ExceptionHelper.ConnectionClosed ();
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               public void ResetState ()
+               {
+                       throw new NotImplementedException ();
+               }
+#endif
+
                #endregion
 
                #region Events and Delegates
 
-                [DataSysDescription ("Event triggered when messages arrive from the DataSource.")]
-                [DataCategory ("DataCategory_InfoMessage")]
+#if !NET_2_0
+               [DataSysDescription ("Event triggered when messages arrive from the DataSource.")]
+#endif
+               [DataCategory ("DataCategory_InfoMessage")]
                public event OleDbInfoMessageEventHandler InfoMessage;
 
+#if !NET_2_0
                [DataSysDescription ("Event triggered when the connection changes state.")]
-                [DataCategory ("DataCategory_StateChange")]
+               [DataCategory ("DataCategory_StateChange")]
                public event StateChangeEventHandler StateChange;
+#endif
 
                #endregion
        }