namespace System.Data.Odbc
{
- /// <summary>
+ /// <summary>
/// Represents an SQL statement or stored procedure to execute against a data source.
/// </summary>
[DesignerAttribute ("Microsoft.VSDesigner.Data.VS.OdbcCommandDesigner, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.IDesigner")]
- [ToolboxItemAttribute ("System.Drawing.Design.ToolboxItem, "+ Consts.AssemblySystem_Drawing)]
+ [ToolboxItemAttribute ("System.Drawing.Design.ToolboxItem, "+ Consts.AssemblySystem_Drawing)]
#if NET_2_0
+ [DefaultEvent ("RecordsAffected")]
public sealed class OdbcCommand : DbCommand, ICloneable
#else
public sealed class OdbcCommand : Component, ICloneable, IDbCommand
{
#region Fields
+ const int DEFAULT_COMMAND_TIMEOUT = 30;
+
string commandText;
int timeout;
CommandType commandType;
- UpdateRowSource updateRowSource = UpdateRowSource.Both;
+ UpdateRowSource updateRowSource;
OdbcConnection connection;
OdbcTransaction transaction;
OdbcParameterCollection _parameters;
bool designTimeVisible;
- bool prepared=false;
+ bool prepared;
IntPtr hstmt = IntPtr.Zero;
- bool disposed = false;
+ bool disposed;
#endregion // Fields
public OdbcCommand ()
{
- this.CommandText = String.Empty;
- this.CommandTimeout = 30; // default timeout
- this.CommandType = CommandType.Text;
- Connection = null;
+ timeout = DEFAULT_COMMAND_TIMEOUT;
+ commandType = CommandType.Text;
_parameters = new OdbcParameterCollection ();
- Transaction = null;
- designTimeVisible = false;
-#if ONLY_1_1
+ designTimeVisible = true;
updateRowSource = UpdateRowSource.Both;
-#endif // ONLY_1_1
}
public OdbcCommand (string cmdText) : this ()
{
- CommandText = cmdText;
+ commandText = cmdText;
}
public OdbcCommand (string cmdText, OdbcConnection connection)
Connection = connection;
}
- public OdbcCommand (string cmdText,
- OdbcConnection connection,
+ public OdbcCommand (string cmdText, OdbcConnection connection,
OdbcTransaction transaction) : this (cmdText, connection)
{
this.Transaction = transaction;
#region Properties
- internal IntPtr hStmt
- {
+ internal IntPtr hStmt {
get { return hstmt; }
}
- [OdbcCategory ("Data")]
- [DefaultValue ("")]
- [OdbcDescriptionAttribute ("Command text to execute")]
- [EditorAttribute ("Microsoft.VSDesigner.Data.Odbc.Design.OdbcCommandTextEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
- [RefreshPropertiesAttribute (RefreshProperties.All)]
- public
+ [OdbcCategory ("Data")]
+ [DefaultValue ("")]
+ [OdbcDescriptionAttribute ("Command text to execute")]
+ [EditorAttribute ("Microsoft.VSDesigner.Data.Odbc.Design.OdbcCommandTextEditor, "+ 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; }
- set {
- prepared=false;
+ string CommandText {
+ get {
+ if (commandText == null)
+ return string.Empty;
+ return commandText;
+ }
+ set {
+ prepared = false;
commandText = value;
}
}
[OdbcDescriptionAttribute ("Time to wait for command to execute")]
#if NET_1_0 || ONLY_1_1
- [DefaultValue (30)]
+ [DefaultValue (DEFAULT_COMMAND_TIMEOUT)]
#endif
- public
+ public
#if NET_2_0
override
#endif
}
[OdbcCategory ("Data")]
- [DefaultValue ("Text")]
- [OdbcDescriptionAttribute ("How to interpret the CommandText")]
- [RefreshPropertiesAttribute (RefreshProperties.All)]
+ [DefaultValue ("Text")]
+ [OdbcDescriptionAttribute ("How to interpret the CommandText")]
+ [RefreshPropertiesAttribute (RefreshProperties.All)]
public
#if NET_2_0
override
#endif
- CommandType CommandType {
+ CommandType CommandType {
get { return commandType; }
set { commandType = value; }
}
#if ONLY_1_1
[OdbcCategory ("Behavior")]
- [OdbcDescriptionAttribute ("Connection used by the command")]
- [DefaultValue (null)]
- [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DbConnectionEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
- public OdbcConnection Connection {
+ [OdbcDescriptionAttribute ("Connection used by the command")]
+ [DefaultValue (null)]
+ [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DbConnectionEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
+ public OdbcConnection Connection {
get {
return connection;
}
#endif // ONLY_1_1
#if NET_2_0
- [DefaultValue (null)]
- [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DbConnectionEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
- public new OdbcConnection Connection
- {
- get { return DbConnection as OdbcConnection; }
- set { DbConnection = value; }
- }
-
+ [DefaultValue (null)]
+ [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DbConnectionEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
+ public new OdbcConnection Connection {
+ get { return DbConnection as OdbcConnection; }
+ set { DbConnection = value; }
+ }
#endif // NET_2_0
[BrowsableAttribute (false)]
- [DesignOnlyAttribute (true)]
- [DefaultValue (true)]
- [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DbConnectionEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
- public
+ [DesignOnlyAttribute (true)]
+ [DefaultValue (true)]
+#if NET_2_0
+ [EditorBrowsable (EditorBrowsableState.Never)]
+#endif
+ public
#if NET_2_0
override
#endif
- bool DesignTimeVisible {
+ bool DesignTimeVisible {
get {
return designTimeVisible;
}
[OdbcCategory ("Data")]
- [OdbcDescriptionAttribute ("The parameters collection")]
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
+ [OdbcDescriptionAttribute ("The parameters collection")]
+ [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
public
#if NET_2_0
- new
+ new
#endif // NET_2_0
- OdbcParameterCollection Parameters {
+ OdbcParameterCollection Parameters {
get {
#if ONLY_1_1
return _parameters;
- #else
- return base.Parameters as OdbcParameterCollection;
+#else
+ return base.Parameters as OdbcParameterCollection;
#endif // ONLY_1_1
-
}
}
[BrowsableAttribute (false)]
- [OdbcDescriptionAttribute ("The transaction used by the command")]
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
+ [OdbcDescriptionAttribute ("The transaction used by the command")]
+ [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
public
#if NET_2_0
- new
+ new
#endif // NET_2_0
- OdbcTransaction Transaction {
+ OdbcTransaction Transaction {
get {
return transaction;
}
}
[OdbcCategory ("Behavior")]
- [DefaultValue (UpdateRowSource.Both)]
- [OdbcDescriptionAttribute ("When used by a DataAdapter.Update, how command results are applied to the current DataRow")]
- public
+ [DefaultValue (UpdateRowSource.Both)]
+ [OdbcDescriptionAttribute ("When used by a DataAdapter.Update, how command results are applied to the current DataRow")]
+ public
#if NET_2_0
override
#endif
- UpdateRowSource UpdatedRowSource {
+ UpdateRowSource UpdatedRowSource {
get {
return updateRowSource;
}
}
#if NET_2_0
- protected override DbConnection DbConnection
- {
- get { return connection; }
- set {
- connection = (OdbcConnection) value;
- }
- }
+ protected override DbConnection DbConnection {
+ get { return connection; }
+ set { connection = (OdbcConnection) value;}
+ }
#endif // NET_2_0
#if ONLY_1_1
-
IDbConnection IDbCommand.Connection {
get {
return Connection;
}
}
- IDataParameterCollection IDbCommand.Parameters {
+ IDataParameterCollection IDbCommand.Parameters {
get {
return Parameters;
}
}
- #else
- protected override DbParameterCollection DbParameterCollection
- {
- get { return _parameters as DbParameterCollection;}
- }
-
+#else
+ protected override DbParameterCollection DbParameterCollection {
+ get { return _parameters as DbParameterCollection;}
+ }
#endif // NET_2_0
#if ONLY_1_1
- IDbTransaction IDbCommand.Transaction {
+ IDbTransaction IDbCommand.Transaction {
get {
return (IDbTransaction) Transaction;
}
set {
- if (value is OdbcTransaction)
- {
- Transaction = (OdbcTransaction)value;
- }
- else
- {
- throw new ArgumentException ();
- }
+ if (value is OdbcTransaction) {
+ Transaction = (OdbcTransaction) value;
+ } else {
+ throw new ArgumentException ();
+ }
}
}
#else
- protected override DbTransaction DbTransaction
- {
+ protected override DbTransaction DbTransaction {
get { return transaction; }
- set {
- transaction = (OdbcTransaction)value;
- }
+ set { transaction = (OdbcTransaction) value; }
}
#endif // ONLY_1_1
-
-
#endregion // Properties
#region Methods
public
#if NET_2_0
- override
+ override
#endif // NET_2_0
- void Cancel ()
+ void Cancel ()
{
if (hstmt!=IntPtr.Zero)
{
}
#else
- protected override DbParameter CreateDbParameter ()
- {
- return CreateParameter ();
- }
-
+ protected override DbParameter CreateDbParameter ()
+ {
+ return CreateParameter ();
+ }
#endif // ONLY_1_1
public new OdbcParameter CreateParameter ()
hstmt = IntPtr.Zero;
}
- private void ExecSQL(string sql)
+ private void ExecSQL (string sql)
{
OdbcReturn ret;
if (! prepared && Parameters.Count <= 0) {
public
#if NET_2_0
- override
+ override
#endif // NET_2_0
- int ExecuteNonQuery ()
+ int ExecuteNonQuery ()
{
return ExecuteNonQuery (true);
}
ExecSQL(CommandText);
// .NET documentation says that except for INSERT, UPDATE and
- // DELETE where the return value is the number of rows affected
- // for the rest of the commands the return value is -1.
- if ((CommandText.ToUpper().IndexOf("UPDATE")!=-1) ||
+ // DELETE where the return value is the number of rows affected
+ // for the rest of the commands the return value is -1.
+ if ((CommandText.ToUpper().IndexOf("UPDATE")!=-1) ||
(CommandText.ToUpper().IndexOf("INSERT")!=-1) ||
(CommandText.ToUpper().IndexOf("DELETE")!=-1)) {
-
int numrows = 0;
OdbcReturn ret = libodbc.SQLRowCount(hstmt,ref numrows);
records = numrows;
- }
- else
+ } else
records = -1;
if (freeHandle && !prepared)
public
#if NET_2_0
- override
+ override
#endif // NET_2_0
- void Prepare()
+ void Prepare()
{
ReAllocStatment ();
}
}
-
public
#if NET_2_0
- new
+ new
#endif // NET_2_0
- OdbcDataReader ExecuteReader ()
+ OdbcDataReader ExecuteReader ()
{
return ExecuteReader (CommandBehavior.Default);
}
{
return ExecuteReader ();
}
- #else
- protected override DbDataReader ExecuteDbDataReader (CommandBehavior behavior)
- {
- return ExecuteReader (behavior);
- }
-
+#else
+ protected override DbDataReader ExecuteDbDataReader (CommandBehavior behavior)
+ {
+ return ExecuteReader (behavior);
+ }
#endif // ONLY_1_1
public
#if NET_2_0
- new
+ new
#endif // NET_2_0
- OdbcDataReader ExecuteReader (CommandBehavior behavior)
+ OdbcDataReader ExecuteReader (CommandBehavior behavior)
{
int recordsAffected = ExecuteNonQuery(false);
OdbcDataReader dataReader=new OdbcDataReader(this, behavior, recordsAffected);
}
#if ONLY_1_1
- IDataReader IDbCommand.ExecuteReader (CommandBehavior behavior)
+ IDataReader IDbCommand.ExecuteReader (CommandBehavior behavior)
{
return ExecuteReader (behavior);
}
#endif // ONLY_1_1
- public
+ public
#if NET_2_0
override
#endif
{
object val = null;
OdbcDataReader reader=ExecuteReader();
- try
- {
+ try {
if (reader.Read ())
val=reader[0];
- }
- finally
- {
+ } finally {
reader.Close();
}
return val;
}
- [MonoTODO]
object ICloneable.Clone ()
{
- throw new NotImplementedException ();
+ OdbcCommand command = new OdbcCommand ();
+ command.CommandText = this.CommandText;
+ command.CommandTimeout = this.CommandTimeout;
+ command.CommandType = this.CommandType;
+ command.Connection = this.Connection;
+ command.DesignTimeVisible = this.DesignTimeVisible;
+ foreach (OdbcParameter parameter in this.Parameters)
+ command.Parameters.Add (parameter);
+ command.Transaction = this.Transaction;
+ return command;
}
public void ResetCommandTimeout ()
{
- CommandTimeout = 30;
+ CommandTimeout = DEFAULT_COMMAND_TIMEOUT;
}
#endregion