2002-07-28 Rodrigo Moya <rodrigo@ximian.com>
[mono.git] / mcs / class / System.Data / System.Data.OleDb / OleDbCommand.cs
index 87bcfeb5bd8faa15cbc8f1ad6dfb3b4918c2746f..127f3c8f4000efb0c673da698b238cd8f52f4f8b 100644 (file)
@@ -32,7 +32,7 @@ namespace System.Data.OleDb
                bool designTimeVisible;
                OleDbDataReader dataReader;
                CommandBehavior behavior;
-               ArrayList gdaCommands;
+               IntPtr gdaCommand;
                ArrayList gdaResults;
 
                #endregion // Fields
@@ -50,7 +50,7 @@ namespace System.Data.OleDb
                        designTimeVisible = false;
                        dataReader = null;
                        behavior = CommandBehavior.Default;
-                       gdaCommands = new ArrayList ();
+                       gdaCommand = IntPtr.Zero;
                        gdaResults = new ArrayList ();
                }
 
@@ -80,13 +80,7 @@ namespace System.Data.OleDb
                {
                        get { return commandText; }
                        set { 
-                               string[] queries = value.Split (new Char[] {';'});
-                               gdaCommands.Clear ();
-
-                               foreach (string query in queries) 
-                                       gdaCommands.Add (libgda.gda_command_new (query, 0, 0));
-
-                               commandText = value; 
+                               commandText = value;
                        }
                }
 
@@ -160,12 +154,44 @@ namespace System.Data.OleDb
                        return new OleDbParameter ();
                }
 
+               IDbDataParameter IDbCommand.CreateParameter ()
+               {
+                       return CreateParameter ();
+               }
+               
                [MonoTODO]
                protected override void Dispose (bool disposing)
                {
                        throw new NotImplementedException ();
                }
 
+               private void SetupGdaCommand ()
+               {
+                       GdaCommandType type;
+                       
+                       switch (commandType) {
+                       case CommandType.TableDirect :
+                               type = GdaCommandType.Table;
+                               break;
+                       case CommandType.StoredProcedure :
+                               type = GdaCommandType.Procedure;
+                               break;
+                       case CommandType.Text :
+                       default :
+                               type = GdaCommandType.Sql;
+                               break;
+                       }
+                       
+                       if (gdaCommand != IntPtr.Zero) {
+                               libgda.gda_command_set_text (gdaCommand, commandText);
+                               libgda.gda_command_set_command_type (gdaCommand, type);
+                       } else {
+                               gdaCommand = libgda.gda_command_new (commandText, type, 0);
+                       }
+
+                       //libgda.gda_command_set_transaction 
+               }
+               
                public int ExecuteNonQuery ()
                {
                        if (connection == null)
@@ -177,7 +203,8 @@ namespace System.Data.OleDb
                        IntPtr gdaConnection = connection.GdaConnection;
                        IntPtr gdaParameterList = parameters.GdaParameterList;
 
-                       return libgda.gda_connection_execute_non_query (gdaConnection, (IntPtr) gdaCommands[0], gdaParameterList);
+                       SetupGdaCommand ();
+                       return libgda.gda_connection_execute_non_query (gdaConnection, (IntPtr) gdaCommand, gdaParameterList);
                }
 
                public OleDbDataReader ExecuteReader ()
@@ -185,6 +212,11 @@ namespace System.Data.OleDb
                        return ExecuteReader (CommandBehavior.Default);
                }
 
+               IDataReader IDbCommand.ExecuteReader ()
+               {
+                       return ExecuteReader ();
+               }
+
                public OleDbDataReader ExecuteReader (CommandBehavior behavior)
                {
                        if (connection.State != ConnectionState.Open)
@@ -195,42 +227,32 @@ namespace System.Data.OleDb
                        IntPtr gdaConnection = connection.GdaConnection;
                        IntPtr gdaParameterList = parameters.GdaParameterList;
 
-                       foreach (IntPtr gdaCommand in gdaCommands) 
-                               GdaResults.Add (libgda.gda_connection_execute_single_command (gdaConnection, gdaCommand, gdaParameterList));
+                       /* FIXME: split all returned resultsets into
+                          our internal GdaResults */
+                       GdaResults.Add (libgda.gda_connection_execute_command (
+                                               gdaConnection,
+                                               gdaCommand,
+                                               gdaParameterList));
 
                        dataReader = new OleDbDataReader (this);
-
                        dataReader.NextResult ();
 
                        return dataReader;
                }
 
-               [MonoTODO]
-               public object ExecuteScalar ()
-               {
-                       throw new NotImplementedException ();   
-               }
-
-               [MonoTODO]
-               object ICloneable.Clone ()
-               {
-                       throw new NotImplementedException ();   
-               }
-
-               [MonoTODO]
-               IDbDataParameter IDbCommand.CreateParameter ()
+               IDataReader IDbCommand.ExecuteReader (CommandBehavior behavior)
                {
-                       throw new NotImplementedException ();   
+                       return ExecuteReader (behavior);
                }
-
+               
                [MonoTODO]
-               IDataReader IDbCommand.ExecuteReader ()
+               public object ExecuteScalar ()
                {
                        throw new NotImplementedException ();   
                }
 
                [MonoTODO]
-               IDataReader IDbCommand.ExecuteReader (CommandBehavior behavior)
+               object ICloneable.Clone ()
                {
                        throw new NotImplementedException ();   
                }