2 // System.Data.OleDb.OleDbCommand
5 // Rodrigo Moya (rodrigo@ximian.com)
6 // Tim Coleman (tim@timcoleman.com)
8 // Copyright (C) Rodrigo Moya, 2002
9 // Copyright (C) Tim Coleman, 2002
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System.ComponentModel;
37 using System.Data.Common;
38 using System.Collections;
39 using System.Runtime.InteropServices;
41 namespace System.Data.OleDb
44 /// Represents an SQL statement or stored procedure to execute against a data source.
46 [DesignerAttribute ("Microsoft.VSDesigner.Data.VS.OleDbCommandDesigner, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.IDesigner")]
47 [ToolboxItemAttribute ("System.Drawing.Design.ToolboxItem, "+ Consts.AssemblySystem_Drawing)]
48 public sealed class OleDbCommand :
54 , ICloneable, IDbCommand
60 CommandType commandType;
61 OleDbConnection connection;
62 OleDbParameterCollection parameters;
63 OleDbTransaction transaction;
64 bool designTimeVisible;
65 OleDbDataReader dataReader;
66 CommandBehavior behavior;
73 public OleDbCommand ()
75 commandText = String.Empty;
76 timeout = 30; // default timeout per .NET
77 commandType = CommandType.Text;
79 parameters = new OleDbParameterCollection ();
83 behavior = CommandBehavior.Default;
84 gdaCommand = IntPtr.Zero;
87 public OleDbCommand (string cmdText) : this ()
89 CommandText = cmdText;
92 public OleDbCommand (string cmdText, OleDbConnection connection)
95 Connection = connection;
98 public OleDbCommand (string cmdText,
99 OleDbConnection connection,
100 OleDbTransaction transaction) : this (cmdText, connection)
102 this.transaction = transaction;
105 #endregion // Constructors
109 [DataCategory ("Data")]
112 [DataSysDescriptionAttribute ("Command text to execute.")]
114 [EditorAttribute ("Microsoft.VSDesigner.Data.ADO.Design.OleDbCommandTextEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing)]
115 [RefreshPropertiesAttribute (RefreshProperties.All)]
131 [DataSysDescriptionAttribute ("Time to wait for command to execute.")]
147 [DataCategory ("Data")]
148 [DefaultValue ("Text")]
150 [DataSysDescriptionAttribute ("How to interpret the CommandText.")]
152 [RefreshPropertiesAttribute (RefreshProperties.All)]
157 CommandType CommandType {
166 [DataCategory ("Behavior")]
168 [DataSysDescriptionAttribute ("Connection used by the command.")]
170 [DefaultValue (null)]
171 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DbConnectionEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
172 public new OleDbConnection Connection {
181 [BrowsableAttribute (false)]
182 [DesignOnlyAttribute (true)]
183 [DefaultValue (true)]
188 bool DesignTimeVisible {
190 return designTimeVisible;
193 designTimeVisible = value;
197 [DataCategory ("Data")]
199 [DataSysDescriptionAttribute ("The parameters collection.")]
201 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
202 public new OleDbParameterCollection Parameters {
208 [BrowsableAttribute (false)]
210 [DataSysDescriptionAttribute ("The transaction used by the command.")]
212 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
213 public new OleDbTransaction Transaction {
222 [DataCategory ("Behavior")]
223 [DefaultValue (UpdateRowSource.Both)]
225 [DataSysDescriptionAttribute ("When used by a DataAdapter.Update, how command results are applied to the current DataRow.")]
231 UpdateRowSource UpdatedRowSource {
234 throw new NotImplementedException ();
238 throw new NotImplementedException ();
242 IDbConnection IDbCommand.Connection {
247 Connection = (OleDbConnection) value;
251 IDataParameterCollection IDbCommand.Parameters {
257 IDbTransaction IDbCommand.Transaction {
262 Transaction = (OleDbTransaction) value;
266 #endregion // Properties
277 throw new NotImplementedException ();
280 public new OleDbParameter CreateParameter ()
282 return new OleDbParameter ();
285 IDbDataParameter IDbCommand.CreateParameter ()
287 return CreateParameter ();
291 protected override void Dispose (bool disposing)
293 throw new NotImplementedException ();
296 private void SetupGdaCommand ()
300 switch (commandType) {
301 case CommandType.TableDirect :
302 type = GdaCommandType.Table;
304 case CommandType.StoredProcedure :
305 type = GdaCommandType.Procedure;
307 case CommandType.Text :
309 type = GdaCommandType.Sql;
313 if (gdaCommand != IntPtr.Zero) {
314 libgda.gda_command_set_text (gdaCommand, commandText);
315 libgda.gda_command_set_command_type (gdaCommand, type);
317 gdaCommand = libgda.gda_command_new (commandText, type, 0);
320 //libgda.gda_command_set_transaction
327 int ExecuteNonQuery ()
329 if (connection == null)
330 throw new InvalidOperationException ("connection == null");
331 if (connection.State == ConnectionState.Closed)
332 throw new InvalidOperationException ("State == Closed");
333 // FIXME: a third check is mentioned in .NET docs
335 IntPtr gdaConnection = connection.GdaConnection;
336 IntPtr gdaParameterList = parameters.GdaParameterList;
339 return libgda.gda_connection_execute_non_query (gdaConnection,
344 public new OleDbDataReader ExecuteReader ()
346 return ExecuteReader (behavior);
349 IDataReader IDbCommand.ExecuteReader ()
351 return ExecuteReader ();
354 public new OleDbDataReader ExecuteReader (CommandBehavior behavior)
356 ArrayList results = new ArrayList ();
360 if (connection.State != ConnectionState.Open)
361 throw new InvalidOperationException ("State != Open");
363 this.behavior = behavior;
365 IntPtr gdaConnection = connection.GdaConnection;
366 IntPtr gdaParameterList = parameters.GdaParameterList;
368 /* execute the command */
370 rs_list = libgda.gda_connection_execute_command (
374 if (rs_list != IntPtr.Zero) {
375 glist_node = (GdaList) Marshal.PtrToStructure (rs_list, typeof (GdaList));
377 while (glist_node != null) {
378 results.Add (glist_node.data);
379 if (glist_node.next == IntPtr.Zero)
382 glist_node = (GdaList) Marshal.PtrToStructure (glist_node.next,
385 dataReader = new OleDbDataReader (this, results);
386 dataReader.NextResult ();
392 IDataReader IDbCommand.ExecuteReader (CommandBehavior behavior)
394 return ExecuteReader (behavior);
401 object ExecuteScalar ()
404 OleDbDataReader reader = ExecuteReader ();
405 if (reader == null) {
408 if (!reader.Read ()) {
412 object o = reader.GetValue (0);
418 object ICloneable.Clone ()
420 throw new NotImplementedException ();
430 throw new NotImplementedException ();
433 public void ResetCommandTimeout ()
440 protected override DbParameter CreateDbParameter ()
442 throw new NotImplementedException ();
446 protected override DbDataReader ExecuteDbDataReader (CommandBehavior behavior)
448 throw new NotImplementedException ();
452 protected override DbConnection DbConnection {
453 get { throw new NotImplementedException (); }
454 set { throw new NotImplementedException (); }
458 protected override DbParameterCollection DbParameterCollection {
459 get { throw new NotImplementedException (); }
463 protected override DbTransaction DbTransaction {
464 get { throw new NotImplementedException (); }
465 set { throw new NotImplementedException (); }