Author: anagappan
Date: 2007-10-19 01:37:24 -0400 (Fri, 19 Oct 2007)
New Revision: 87813

Modified:
   trunk/mcs/class/System.Data/System.Data.OleDb/ChangeLog
   trunk/mcs/class/System.Data/System.Data.OleDb/OleDbCommandBuilder.cs
Log:
* OleDbCommandBuilder.cs: Implemented ApplyParameterInfo, Dispose,
  GetParameterName, GetParameterPlaceholder, RefreshSchema methods.

Modified: trunk/mcs/class/System.Data/System.Data.OleDb/ChangeLog
===================================================================
--- trunk/mcs/class/System.Data/System.Data.OleDb/ChangeLog     2007-10-19 
05:36:00 UTC (rev 87812)
+++ trunk/mcs/class/System.Data/System.Data.OleDb/ChangeLog     2007-10-19 
05:37:24 UTC (rev 87813)
@@ -1,5 +1,10 @@
 2007-10-19  Nagappan <[EMAIL PROTECTED]> 
 
+       * OleDbCommandBuilder.cs: Implemented ApplyParameterInfo, Dispose,
+         GetParameterName, GetParameterPlaceholder, RefreshSchema methods.
+
+2007-10-19  Nagappan <[EMAIL PROTECTED]> 
+
        * OleDbCommand.cs: Implemented Clone, Dispose methods.
          Implemented CreateDbParameter, DbConnection, DbParameterCollection,
          DbTransaction, ExecuteDbDataReader properties.

Modified: trunk/mcs/class/System.Data/System.Data.OleDb/OleDbCommandBuilder.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data.OleDb/OleDbCommandBuilder.cs        
2007-10-19 05:36:00 UTC (rev 87812)
+++ trunk/mcs/class/System.Data/System.Data.OleDb/OleDbCommandBuilder.cs        
2007-10-19 05:37:24 UTC (rev 87813)
@@ -51,11 +51,18 @@
                #region Fields
 
                OleDbDataAdapter adapter;
-#if !NET_2_0
+#if ONLY_1_1
                string quotePrefix;
                string quoteSuffix;
 #endif
 
+               private DataTable               _schema;
+               private string                  _tableName;
+               private OleDbCommand    _insertCommand;
+               private OleDbCommand    _updateCommand;
+               private OleDbCommand    _deleteCommand;
+
+               bool _disposed;
                #endregion // Fields
 
                #region Constructors
@@ -122,23 +129,53 @@
                #region Methods
 
 #if NET_2_0
-               [MonoTODO]
-               protected override void ApplyParameterInfo (DbParameter 
parameter, DataRow datarow, StatementType statementType, bool whereClause)
+               protected override void ApplyParameterInfo (DbParameter 
dbParameter,
+                                                                   DataRow row,
+                                                                   
StatementType statementType,
+                                                                   bool 
whereClause)
                {
-                       throw new NotImplementedException ();
+                       OleDbParameter parameter = (OleDbParameter) dbParameter;
+                       parameter.Size = int.Parse (row ["ColumnSize"].ToString 
());
+                       if (row ["NumericPrecision"] != DBNull.Value) {
+                               parameter.Precision = byte.Parse (row 
["NumericPrecision"].ToString ());
+                       }
+                       if (row ["NumericScale"] != DBNull.Value) {
+                               parameter.Scale = byte.Parse (row 
["NumericScale"].ToString ());
+                       }
+                       parameter.DbType = (DbType) row ["ProviderType"];
                }
 #endif
 
+               [MonoTODO]
                public static void DeriveParameters (OleDbCommand command)
                {
+                       if (command.CommandType != CommandType.StoredProcedure) 
{
+                               throw new InvalidOperationException ("You can 
perform this " +
+                                                                            
"operation only on CommandTye" + 
+                                                                            " 
StoredProcedure");
+                       }
+                       // FIXME: Retrive info from server
                        throw new NotImplementedException ();
                }
 
 #if ONLY_1_1
-               [MonoTODO]
                protected override void Dispose (bool disposing)
                {
-                       throw new NotImplementedException ();
+                       if (_disposed)
+                               return;
+                       
+                       if (disposing) {
+                               // dispose managed resource
+                               if (_insertCommand != null) 
_insertCommand.Dispose ();
+                               if (_updateCommand != null) 
_updateCommand.Dispose ();
+                               if (_deleteCommand != null) 
_deleteCommand.Dispose ();
+
+                               _insertCommand = null;
+                               _updateCommand = null;
+                               _deleteCommand = null;
+                               _schema = null;
+                       }
+                       _disposed = true;
                }
 #endif
 
@@ -169,22 +206,21 @@
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
-               protected override string GetParameterName (int 
parameterOrdinal)
+               protected override string GetParameterName (int position)
                {
-                       throw new NotImplementedException ();
+                       return String.Format("@p{0}", position);
                }
 
                protected override string GetParameterName (string 
parameterName)
                {
-                       return parameterName;
+                       return String.Format("@{0}", parameterName);            
           
                }
-
-               [MonoTODO]
-               protected override string GetParameterPlaceholder(int 
parameterOrdinal)
+                
+               protected override string GetParameterPlaceholder (int position)
                {
-                       throw new NotImplementedException ();
+                       return GetParameterName (position);
                }
+                
 #endif
 
                [MonoTODO]
@@ -193,6 +229,15 @@
                        throw new NotImplementedException ();
                }
 
+               private OleDbCommand SelectCommand
+               {
+                       get {
+                               if (DataAdapter == null)
+                                       return null;
+                               return DataAdapter.SelectCommand;
+                       }
+               }
+
 #if NET_2_0
                [MonoTODO]
                public new OleDbCommand GetUpdateCommand (bool 
useColumnsForParameterNames)
@@ -230,10 +275,29 @@
                        throw new NotImplementedException ();
                }
 #else
-               [MonoTODO]
                public void RefreshSchema ()
                {
-                       throw new NotImplementedException ();
+                       // creates metadata
+                       if (SelectCommand == null)
+                               throw new InvalidOperationException 
("SelectCommand should be valid");
+                       if (SelectCommand.Connection == null)
+                               throw new InvalidOperationException 
("SelectCommand's Connection should be valid");
+                       
+                       CommandBehavior behavior = CommandBehavior.SchemaOnly | 
CommandBehavior.KeyInfo;
+                       if (SelectCommand.Connection.State != 
ConnectionState.Open) {
+                               SelectCommand.Connection.Open ();
+                               behavior |= CommandBehavior.CloseConnection;
+                       }
+                       
+                       OleDbDataReader reader = SelectCommand.ExecuteReader 
(behavior);
+                       _schema = reader.GetSchemaTable ();
+                       reader.Close ();
+                       
+                       // force creation of commands
+                       _insertCommand  = null;
+                       _updateCommand  = null;
+                       _deleteCommand  = null;
+                       _tableName      = String.Empty;
                }
 #endif
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to