2010-06-21 Atsushi Enomoto <atsushi@ximian.com>
[mcs.git] / class / System.Data / System.Data.SqlClient.jvm / SqlCommand.cs
blob4333ae8f3c5371748580d7fe123825bcea22e043
1 //
2 // System.Data.SqlClient.SqlCommand
3 //
4 // Authors:
5 // Konstantin Triger <kostat@mainsoft.com>
6 // Boris Kirzner <borisk@mainsoft.com>
7 //
8 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
9 //
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:
19 //
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 //
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.
32 using System;
33 using System.Collections;
34 using System.Text;
35 using System.Text.RegularExpressions;
36 using System.Data;
37 using System.Data.Common;
38 using System.Data.ProviderBase;
39 using System.Xml;
41 using java.sql;
43 namespace System.Data.SqlClient
45 public sealed class SqlCommand : AbstractDbCommand
47 #region Fields
49 #endregion // Fields
51 #region Constructors
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.
75 public SqlCommand(
76 String cmdText,
77 SqlConnection connection,
78 SqlTransaction transaction)
79 : base(cmdText, connection, transaction)
83 #endregion // Constructors
85 #region Properties
87 protected override string InternalCommandText {
88 get {
89 string commandText = CommandText;
90 if (CommandType != CommandType.StoredProcedure ||
91 string.IsNullOrEmpty (commandText) ||
92 commandText [0] == '[' ||
93 commandText.IndexOf ('.') >= 0)
94 return commandText;
96 string trimmedCommandText = commandText.TrimEnd ();
97 if (trimmedCommandText.Length > 0 && trimmedCommandText [trimmedCommandText.Length - 1] != ')')
98 commandText = String.Concat ("[", commandText, "]");
100 return commandText;
104 public new SqlConnection Connection
106 get { return (SqlConnection)base.Connection; }
107 set { base.Connection = value; }
110 public new SqlParameterCollection Parameters
112 get {
113 return (SqlParameterCollection)base.Parameters;
117 public new SqlTransaction Transaction
119 get { return (SqlTransaction)base.Transaction; }
120 set { base.Transaction = value; }
123 #if USE_DOTNET_REGEX
124 protected override Regex StoredProcedureRegExp
125 #else
126 protected override java.util.regex.Pattern StoredProcedureRegExp {
127 #endif
128 get { return SqlStatementsHelper.NamedParameterStoredProcedureRegExp; }
131 protected override SimpleRegex ParameterRegExp
133 get { return SqlStatementsHelper.NamedParameterRegExp; }
136 #endregion // Properties
138 #region Methods
140 public XmlReader ExecuteXmlReader() {
141 return SqlXmlTextReader.Create(ExecuteReader(CommandBehavior.SequentialAccess));
144 public new SqlDataReader ExecuteReader()
146 return (SqlDataReader)ExecuteReader(CommandBehavior.Default);
149 public new SqlDataReader ExecuteReader(CommandBehavior behavior)
151 return (SqlDataReader)base.ExecuteReader(behavior);
154 public new SqlParameter CreateParameter()
156 return (SqlParameter)CreateParameterInternal();
159 protected sealed override void CheckParameters()
161 // do nothing
164 protected override AbstractDbParameter GetUserParameter(string parameterName, IList userParametersList, int userParametersListPosition/*,int userParametersListStart,int userParameterListCount*/)
166 // Match match = SqlStatementsHelper.NamedParameterRegExp.Match(parameterName);
167 // parameterName = match.Result("${USERPARAM}");
168 // if (parameterName.Length == 0)
169 // return null;
171 for(int i=0; i < userParametersList.Count; i++) {
172 AbstractDbParameter userParameter = (AbstractDbParameter)userParametersList[i];
173 if (String.Compare(parameterName, userParameter.Placeholder.Trim(), true, System.Globalization.CultureInfo.InvariantCulture) == 0) {
174 return userParameter;
178 return null;
181 protected override AbstractDbParameter GetReturnParameter (IList userParametersList)
183 for(int i=0; i < userParametersList.Count; i++) {
184 AbstractDbParameter userParameter = (AbstractDbParameter)userParametersList[i];
185 if (userParameter.Direction == ParameterDirection.ReturnValue) {
186 return userParameter;
190 return null;
193 protected sealed override DbParameter CreateParameterInternal()
195 return new SqlParameter();
198 protected sealed override DbDataReader CreateReader()
200 return new SqlDataReader(this);
203 protected sealed override DbParameterCollection CreateParameterCollection(AbstractDbCommand parent)
205 return new SqlParameterCollection((SqlCommand)parent);
208 protected internal sealed override SystemException CreateException(SQLException e)
210 return new SqlException(e, Connection);
213 #region Asynchronous behavior
214 #if NET_2_0
215 [MonoNotSupported ("Asynchronous behavior not implemented")]
216 public IAsyncResult BeginExecuteReader ()
218 throw new NotImplementedException ();
221 [MonoNotSupported ("Asynchronous behavior not implemented")]
222 public IAsyncResult BeginExecuteReader (CommandBehavior behavior)
224 throw new NotImplementedException ();
227 [MonoNotSupported ("Asynchronous behavior not implemented")]
228 public IAsyncResult BeginExecuteReader (AsyncCallback callback, Object stateObject)
230 throw new NotImplementedException ();
233 [MonoNotSupported ("Asynchronous behavior not implemented")]
234 public IAsyncResult BeginExecuteReader (AsyncCallback callback, Object stateObject, CommandBehavior behavior)
236 throw new NotImplementedException ();
239 [MonoNotSupported ("Asynchronous behavior not implemented")]
240 public SqlDataReader EndExecuteReader (IAsyncResult asyncResult)
242 throw new NotImplementedException ();
245 [MonoNotSupported ("Asynchronous behavior not implemented")]
246 public IAsyncResult BeginExecuteXmlReader ()
248 throw new NotImplementedException ();
251 [MonoNotSupported ("Asynchronous behavior not implemented")]
252 public IAsyncResult BeginExecuteXmlReader (AsyncCallback callback, Object stateObject)
254 throw new NotImplementedException ();
257 [MonoNotSupported ("Asynchronous behavior not implemented")]
258 public XmlReader EndExecuteXmlReader (IAsyncResult asyncResult)
260 throw new NotImplementedException ();
263 [MonoNotSupported ("Asynchronous behavior not implemented")]
264 public IAsyncResult BeginExecuteNonQuery ()
266 throw new NotImplementedException ();
269 [MonoNotSupported ("Asynchronous behavior not implemented")]
270 public IAsyncResult BeginExecuteNonQuery (AsyncCallback callback, Object stateObject)
272 throw new NotImplementedException ();
275 [MonoNotSupported ("Asynchronous behavior not implemented")]
276 public int EndExecuteNonQuery (IAsyncResult asyncResult)
278 throw new NotImplementedException ();
280 #endif
281 #endregion
282 #endregion // Methods