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;
43 namespace System.Data.SqlClient
45 public class SqlCommand : AbstractDbCommand
53 // Initializes a new instance of the SqlCommand class.
54 // The base constructor initializes all fields to their default values.
55 // The following table shows initial property values for an instance of SqlCommand.
56 public SqlCommand() : this(null, null, null)
60 public SqlCommand(SqlConnection connection) : this(null, connection, null)
64 // Initializes a new instance of the SqlCommand class with the text of the query.
65 public SqlCommand(String cmdText) : this(cmdText, null, null)
69 // Initializes a new instance of the SqlCommand class with the text of the query and a SqlConnection.
70 public SqlCommand(String cmdText, SqlConnection connection) : this(cmdText, connection, null)
74 // Initializes a new instance of the SqlCommand class with the text of the query, a SqlConnection, and the Transaction.
77 SqlConnection connection,
78 SqlTransaction transaction)
79 : base(cmdText, connection, transaction)
83 #endregion // Constructors
87 public override string CommandText {
89 string commandText = base.CommandText;
90 if (CommandType != CommandType.StoredProcedure || string.IsNullOrEmpty (commandText))
93 string trimmedCommandText = commandText.TrimEnd ();
94 if (commandText [0] != '[' && trimmedCommandText.Length > 0 && trimmedCommandText [trimmedCommandText.Length - 1] != ')')
95 commandText = String.Concat ("[", commandText, "]");
100 base.CommandText = value;
104 public new SqlConnection Connection
\r
106 get { return (SqlConnection)base.Connection; }
\r
107 set { base.Connection = value; }
\r
110 public new SqlParameterCollection Parameters
\r
113 return (SqlParameterCollection)base.Parameters;
\r
117 public new SqlTransaction Transaction
\r
119 get { return (SqlTransaction)base.Transaction; }
\r
120 set { base.Transaction = value; }
\r
123 #if USE_DOTNET_REGEX
\r
124 protected override Regex StoredProcedureRegExp
\r
126 protected override java.util.regex.Pattern StoredProcedureRegExp {
\r
128 get { return SqlStatementsHelper.NamedParameterStoredProcedureRegExp; }
\r
131 protected override SimpleRegex ParameterRegExp
\r
133 get { return SqlStatementsHelper.NamedParameterRegExp; }
\r
136 #endregion // Properties
140 public XmlReader ExecuteXmlReader() {
141 return SqlXmlTextReader.Create(ExecuteReader(CommandBehavior.SequentialAccess));
144 public new SqlDataReader ExecuteReader()
\r
146 return (SqlDataReader)ExecuteReader(CommandBehavior.Default);
\r
149 public new SqlDataReader ExecuteReader(CommandBehavior behavior)
\r
151 return (SqlDataReader)base.ExecuteReader(behavior);
\r
154 public new SqlParameter CreateParameter()
\r
156 return (SqlParameter)CreateParameterInternal();
\r
159 protected sealed override void CheckParameters()
\r
164 protected override AbstractDbParameter GetUserParameter(string parameterName, IList userParametersList, int userParametersListPosition/*,int userParametersListStart,int userParameterListCount*/)
\r
166 // Match match = SqlStatementsHelper.NamedParameterRegExp.Match(parameterName);
167 // parameterName = match.Result("${USERPARAM}");
\r
168 // if (parameterName.Length == 0)
\r
171 for(int i=0; i < userParametersList.Count; i++) {
\r
172 AbstractDbParameter userParameter = (AbstractDbParameter)userParametersList[i];
\r
173 if (String.Compare(parameterName, userParameter.Placeholder.Trim(), true, System.Globalization.CultureInfo.InvariantCulture) == 0) {
\r
174 return userParameter;
\r
181 protected override AbstractDbParameter GetReturnParameter (IList userParametersList)
\r
183 for(int i=0; i < userParametersList.Count; i++) {
\r
184 AbstractDbParameter userParameter = (AbstractDbParameter)userParametersList[i];
\r
185 if (userParameter.Direction == ParameterDirection.ReturnValue) {
\r
186 return userParameter;
\r
193 protected sealed override DbParameter CreateParameterInternal()
\r
195 return new SqlParameter();
\r
198 protected sealed override DbDataReader CreateReader()
\r
200 return new SqlDataReader(this);
\r
203 protected sealed override DbParameterCollection CreateParameterCollection(AbstractDbCommand parent)
\r
205 return new SqlParameterCollection((SqlCommand)parent);
\r
208 protected internal sealed override SystemException CreateException(SQLException e)
210 return new SqlException(e, Connection);
\r
213 #endregion // Methods
\r