2 // System.Data.SqlClient.SqlCommand
\r
5 // Konstantin Triger <kostat@mainsoft.com>
6 // Boris Kirzner <borisk@mainsoft.com>
8 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Collections;
35 using System.Text.RegularExpressions;
37 using System.Data.Common;
38 using System.Data.ProviderBase;
42 namespace System.Data.SqlClient
44 public class SqlCommand : AbstractDbCommand, IDbCommand, IDisposable, ICloneable
52 // Initializes a new instance of the SqlCommand class.
53 // The base constructor initializes all fields to their default values.
54 // The following table shows initial property values for an instance of SqlCommand.
55 public SqlCommand() : this(null, null, null)
59 public SqlCommand(SqlConnection connection) : this(null, connection, null)
63 // Initializes a new instance of the SqlCommand class with the text of the query.
64 public SqlCommand(String cmdText) : this(cmdText, null, null)
68 // Initializes a new instance of the SqlCommand class with the text of the query and a SqlConnection.
69 public SqlCommand(String cmdText, SqlConnection connection) : this(cmdText, connection, null)
73 // Initializes a new instance of the SqlCommand class with the text of the query, a SqlConnection, and the Transaction.
76 SqlConnection connection,
77 SqlTransaction transaction)
78 : base(cmdText, connection, transaction)
82 #endregion // Constructors
86 public new SqlConnection Connection
\r
88 get { return (SqlConnection)base.Connection; }
\r
89 set { base.Connection = value; }
\r
92 public new SqlParameterCollection Parameters
\r
95 if (_parameters == null) {
\r
96 _parameters = CreateParameterCollection(this);
\r
98 return (SqlParameterCollection)_parameters;
\r
102 public new SqlTransaction Transaction
\r
104 get { return (SqlTransaction)base.Transaction; }
\r
105 set { base.Transaction = value; }
\r
108 #if USE_DOTNET_REGEX
\r
109 protected override Regex StoredProcedureRegExp
\r
111 protected override java.util.regex.Pattern StoredProcedureRegExp {
\r
113 get { return SqlStatementsHelper.NamedParameterStoredProcedureRegExp; }
\r
116 protected override SimpleRegex ParameterRegExp
\r
118 get { return SqlStatementsHelper.NamedParameterRegExp; }
\r
121 #endregion // Properties
125 public new SqlDataReader ExecuteReader()
\r
127 return (SqlDataReader)ExecuteReader(CommandBehavior.Default);
\r
130 public new SqlDataReader ExecuteReader(CommandBehavior behavior)
\r
132 return (SqlDataReader)base.ExecuteReader(behavior);
\r
135 public new SqlParameter CreateParameter()
\r
137 return (SqlParameter)CreateParameterInternal();
\r
140 protected override void CheckParameters()
\r
145 protected override AbstractDbParameter GetUserParameter(string parameterName, IList userParametersList, int userParametersListPosition/*,int userParametersListStart,int userParameterListCount*/)
\r
147 // Match match = SqlStatementsHelper.NamedParameterRegExp.Match(parameterName);
148 // parameterName = match.Result("${USERPARAM}");
\r
149 // if (parameterName.Length == 0)
\r
152 for(int i=0; i < userParametersList.Count; i++) {
\r
153 AbstractDbParameter userParameter = (AbstractDbParameter)userParametersList[i];
\r
154 if (String.Compare(parameterName, userParameter.ParameterName.Trim(), true) == 0) {
\r
155 return userParameter;
\r
162 protected override DbParameter CreateParameterInternal()
\r
164 return new SqlParameter();
\r
167 protected override DbDataReader CreateReader()
\r
169 return new SqlDataReader(this);
\r
172 protected override DbParameterCollection CreateParameterCollection(AbstractDbCommand parent)
\r
174 return new SqlParameterCollection((SqlCommand)parent);
\r
177 public object Clone()
\r
179 SqlCommand clone = new SqlCommand();
\r
184 protected override SystemException CreateException(SQLException e)
186 return new SqlException(e, Connection);
\r
189 #endregion // Methods
\r