2 // System.Data.Odbc.OdbcCommand
5 // Brian Ritchie (brianlritchie@hotmail.com)
7 // Copyright (C) Brian Ritchie, 2002
10 using System.ComponentModel;
12 using System.Data.Common;
13 using System.Collections;
14 using System.Runtime.InteropServices;
16 namespace System.Data.Odbc
19 /// Represents an SQL statement or stored procedure to execute against a data source.
21 public sealed class OdbcCommand : Component, ICloneable, IDbCommand
27 CommandType commandType;
28 OdbcConnection connection;
29 OdbcParameterCollection parameters;
30 //OdbcTransaction transaction;
31 bool designTimeVisible;
33 OdbcDataReader dataReader;
34 CommandBehavior behavior;
43 commandText = String.Empty;
44 timeout = 30; // default timeout
45 commandType = CommandType.Text;
47 parameters = new OdbcParameterCollection ();
49 designTimeVisible = false;
51 behavior = CommandBehavior.Default;
54 public OdbcCommand (string cmdText) : this ()
56 CommandText = cmdText;
59 public OdbcCommand (string cmdText, OdbcConnection connection)
62 Connection = connection;
65 // public OdbcCommand (string cmdText,
66 // OdbcConnection connection,
67 // OdbcTransaction transaction) : this (cmdText, connection)
69 // this.transaction = transaction;
72 #endregion // Constructors
81 public string CommandText
92 public int CommandTimeout {
101 public CommandType CommandType {
110 public OdbcConnection Connection {
119 public bool DesignTimeVisible {
121 return designTimeVisible;
124 designTimeVisible = value;
128 public OdbcParameterCollection Parameters {
137 // public OdbcTransaction Transaction {
139 // return transaction;
142 // transaction = value;
146 public UpdateRowSource UpdatedRowSource {
149 throw new NotImplementedException ();
153 throw new NotImplementedException ();
157 IDbConnection IDbCommand.Connection {
162 Connection = (OdbcConnection) value;
166 IDataParameterCollection IDbCommand.Parameters {
168 throw new NotImplementedException ();
173 IDbTransaction IDbCommand.Transaction {
175 throw new NotImplementedException ();
176 //return Transaction;
179 throw new NotImplementedException ();
183 #endregion // Properties
188 public void Cancel ()
190 throw new NotImplementedException ();
193 public OdbcParameter CreateParameter ()
195 return new OdbcParameter ();
198 IDbDataParameter IDbCommand.CreateParameter ()
200 return CreateParameter ();
204 protected override void Dispose (bool disposing)
206 throw new NotImplementedException ();
209 protected void ExecSQL(string sql)
216 if (Parameters.Count>0)
217 Parameters.Bind(hstmt);
222 ret=libodbc.SQLExecute(hstmt);
223 libodbc.DisplayError("SQLExecute",ret);
227 ret=libodbc.SQLAllocHandle((ushort) OdbcHandleType.Stmt,
228 Connection.hDbc, ref hstmt);
229 libodbc.DisplayError("SQLAllocHandle(hstmt)",ret);
230 ret=libodbc.SQLExecDirect(hstmt, sql, sql.Length);
231 libodbc.DisplayError("SQLExecDirect",ret);
235 public int ExecuteNonQuery ()
237 if (connection == null)
238 throw new InvalidOperationException ();
239 if (connection.State == ConnectionState.Closed)
240 throw new InvalidOperationException ();
241 // FIXME: a third check is mentioned in .NET docs
242 if (connection.DataReader != null)
243 throw new InvalidOperationException ();
245 ExecSQL(CommandText);
248 libodbc.SQLFreeHandle( (ushort) OdbcHandleType.Stmt, hstmt);
252 public void Prepare()
255 ret=libodbc.SQLAllocHandle((ushort) OdbcHandleType.Stmt, Connection.hDbc,
257 libodbc.DisplayError("SQLAlloc(Prepare)",ret);
258 ret=libodbc.SQLPrepare(hstmt, CommandText, CommandText.Length);
259 libodbc.DisplayError("SQLPrepare",ret);
263 public OdbcDataReader ExecuteReader ()
265 return ExecuteReader (CommandBehavior.Default);
268 IDataReader IDbCommand.ExecuteReader ()
270 return ExecuteReader ();
273 public OdbcDataReader ExecuteReader (CommandBehavior behavior)
276 dataReader=new OdbcDataReader(this);
280 IDataReader IDbCommand.ExecuteReader (CommandBehavior behavior)
282 return ExecuteReader (behavior);
285 public object ExecuteScalar ()
287 throw new NotImplementedException ();
288 // if (connection.DataReader != null)
289 // throw new InvalidOperationException ();
294 object ICloneable.Clone ()
296 throw new NotImplementedException ();
299 public void ResetCommandTimeout ()