* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Data / System.Data.OleDb / OleDbCommand.cs
index 9285bf3ab2c16b0f7604d98ced1f546cdee19150..734b6487909a078aa3d85564afb3443f7be33ac2 100644 (file)
@@ -9,6 +9,29 @@
 // Copyright (C) Tim Coleman, 2002
 //
 
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
 using System.ComponentModel;
 using System.Data;
 using System.Data.Common;
@@ -20,7 +43,15 @@ namespace System.Data.OleDb
        /// <summary>
        /// Represents an SQL statement or stored procedure to execute against a data source.
        /// </summary>
-       public sealed class OleDbCommand : Component, ICloneable, IDbCommand
+       [DesignerAttribute ("Microsoft.VSDesigner.Data.VS.OleDbCommandDesigner, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.IDesigner")]
+       [ToolboxItemAttribute ("System.Drawing.Design.ToolboxItem, "+ Consts.AssemblySystem_Drawing)]
+       public sealed class OleDbCommand : 
+#if NET_2_0
+       DbCommand
+#else
+       Component
+#endif
+       , ICloneable, IDbCommand
        {
                #region Fields
 
@@ -75,7 +106,18 @@ namespace System.Data.OleDb
 
                #region Properties
        
-               public string CommandText 
+               [DataCategory ("Data")]
+               [DefaultValue ("")]
+#if !NET_2_0
+                [DataSysDescriptionAttribute ("Command text to execute.")]
+#endif
+                [EditorAttribute ("Microsoft.VSDesigner.Data.ADO.Design.OleDbCommandTextEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
+               [RefreshPropertiesAttribute (RefreshProperties.All)]
+               public 
+#if NET_2_0
+               override
+#endif
+               string CommandText 
                {
                        get {
                                return commandText;
@@ -85,7 +127,15 @@ namespace System.Data.OleDb
                        }
                }
 
-               public int CommandTimeout {
+#if !NET_2_0
+               [DataSysDescriptionAttribute ("Time to wait for command to execute.")]
+#endif
+               [DefaultValue (30)]
+               public
+#if NET_2_0
+               override
+#endif
+               int CommandTimeout {
                        get {
                                return timeout;
                        }
@@ -94,7 +144,17 @@ namespace System.Data.OleDb
                        }
                }
 
-               public CommandType CommandType { 
+               [DataCategory ("Data")]
+                [DefaultValue ("Text")]
+#if !NET_2_0
+               [DataSysDescriptionAttribute ("How to interpret the CommandText.")]
+#endif
+               [RefreshPropertiesAttribute (RefreshProperties.All)]
+               public
+#if NET_2_0
+               override
+#endif
+               CommandType CommandType { 
                        get {
                                return commandType;
                        }
@@ -103,6 +163,12 @@ namespace System.Data.OleDb
                        }
                }
 
+               [DataCategory ("Behavior")]
+#if !NET_2_0
+               [DataSysDescriptionAttribute ("Connection used by the command.")]
+#endif
+               [DefaultValue (null)]
+               [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DbConnectionEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
                public OleDbConnection Connection { 
                        get {
                                return connection;
@@ -111,8 +177,15 @@ namespace System.Data.OleDb
                                connection = value;
                        }
                }
-
-               public bool DesignTimeVisible { 
+               
+               [BrowsableAttribute (false)]
+               [DesignOnlyAttribute (true)]
+               [DefaultValue (true)]
+               public
+#if NET_2_0
+               override
+#endif
+               bool DesignTimeVisible { 
                        get {
                                return designTimeVisible;
                        }
@@ -121,15 +194,22 @@ namespace System.Data.OleDb
                        }
                }
 
+               [DataCategory ("Data")]
+#if !NET_2_0
+               [DataSysDescriptionAttribute ("The parameters collection.")]
+#endif
+               [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
                public OleDbParameterCollection Parameters {
                        get {
                                return parameters;
                        }
-                       set {
-                               parameters = value;
-                       }
                }
-
+               
+               [BrowsableAttribute (false)]
+#if !NET_2_0
+               [DataSysDescriptionAttribute ("The transaction used by the command.")]
+#endif
+               [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
                public OleDbTransaction Transaction {
                        get {
                                return transaction;
@@ -139,7 +219,16 @@ namespace System.Data.OleDb
                        }
                }
 
-               public UpdateRowSource UpdatedRowSource { 
+               [DataCategory ("Behavior")]
+               [DefaultValue (UpdateRowSource.Both)]
+#if !NET_2_0
+               [DataSysDescriptionAttribute ("When used by a DataAdapter.Update, how command results are applied to the current DataRow.")]
+#endif
+               public
+#if NET_2_0
+               override
+#endif
+               UpdateRowSource UpdatedRowSource { 
                        [MonoTODO]
                        get {
                                throw new NotImplementedException ();
@@ -179,7 +268,11 @@ namespace System.Data.OleDb
                #region Methods
 
                [MonoTODO]
-               public void Cancel () 
+               public 
+#if NET_2_0
+               override 
+#endif
+               void Cancel () 
                {
                        throw new NotImplementedException ();
                }
@@ -226,16 +319,17 @@ namespace System.Data.OleDb
 
                        //libgda.gda_command_set_transaction 
                }
-               
-               public int ExecuteNonQuery ()
+               public 
+#if NET_2_0
+               override
+#endif
+               int ExecuteNonQuery ()
                {
                        if (connection == null)
-                               throw new InvalidOperationException ();
+                               throw new InvalidOperationException ("connection == null");
                        if (connection.State == ConnectionState.Closed)
-                               throw new InvalidOperationException ();
+                               throw new InvalidOperationException ("State == Closed");
                        // FIXME: a third check is mentioned in .NET docs
-                       if (connection.DataReader != null)
-                               throw new InvalidOperationException ();
 
                        IntPtr gdaConnection = connection.GdaConnection;
                        IntPtr gdaParameterList = parameters.GdaParameterList;
@@ -263,9 +357,7 @@ namespace System.Data.OleDb
                        GdaList glist_node;
 
                        if (connection.State != ConnectionState.Open)
-                               throw new InvalidOperationException ();
-                       if (connection.DataReader != null)
-                               throw new InvalidOperationException ();
+                               throw new InvalidOperationException ("State != Open");
 
                        this.behavior = behavior;
 
@@ -301,14 +393,24 @@ namespace System.Data.OleDb
                        return ExecuteReader (behavior);
                }
                
-               public object ExecuteScalar ()
+               public
+#if NET_2_0
+               override
+#endif
+               object ExecuteScalar ()
                {
-                       if (connection.DataReader != null)
-                               throw new InvalidOperationException ();
-                       
                        SetupGdaCommand ();
                        OleDbDataReader reader = ExecuteReader ();
-                       return reader.GetValue (0);
+                       if (reader == null) {
+                               return null;
+                       }
+                       if (!reader.Read ()) {
+                               reader.Close ();
+                               return null;
+                       }
+                       object o = reader.GetValue (0);
+                       reader.Close ();
+                       return o;
                }
 
                [MonoTODO]
@@ -318,7 +420,11 @@ namespace System.Data.OleDb
                }
 
                [MonoTODO]
-               public void Prepare ()
+               public 
+#if NET_2_0
+               override
+#endif
+               void Prepare ()
                {
                        throw new NotImplementedException ();   
                }
@@ -327,6 +433,37 @@ namespace System.Data.OleDb
                {
                        timeout = 30;
                }
+               
+#if NET_2_0
+               [MonoTODO]
+               protected override DbParameter CreateDbParameter ()
+               {
+                       throw new NotImplementedException ();   
+               }
+               
+               [MonoTODO]
+               protected override DbDataReader ExecuteDbDataReader (CommandBehavior behavior)
+               {
+                       throw new NotImplementedException ();   
+               }
+               
+               [MonoTODO]
+               protected override DbConnection DbConnection {
+                       get { throw new NotImplementedException (); }
+                       set { throw new NotImplementedException (); }
+               }
+               
+               [MonoTODO]
+               protected override DbParameterCollection DbParameterCollection {
+                       get { throw new NotImplementedException (); }
+               }
+               
+               [MonoTODO]
+               protected override DbTransaction DbTransaction {
+                       get { throw new NotImplementedException (); }
+                       set { throw new NotImplementedException (); }
+               }
+#endif
 
                #endregion
        }