imported everything from my branch (which is slightly harmless).
[mono.git] / mcs / class / System.Data / System.Data.SqlClient.jvm / SqlCommand.cs
1 //\r
2 // System.Data.SqlClient.SqlCommand\r
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 //
10
11 //
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.
30 //
31
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
40 using java.sql;
41
42 namespace System.Data.SqlClient
43 {
44         public class SqlCommand : AbstractDbCommand, IDbCommand, IDisposable, ICloneable
45         {
46                 #region Fields
47
48                 #endregion // Fields
49
50                 #region Constructors
51
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)
56                 {
57                 }
58
59                 public SqlCommand(SqlConnection connection) : this(null, connection, null)
60                 {
61                 }
62
63                 // Initializes a new instance of the SqlCommand class with the text of the query.
64                 public SqlCommand(String cmdText) : this(cmdText, null, null)
65                 {
66                 }
67
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)
70                 {
71                 }
72
73                 // Initializes a new instance of the SqlCommand class with the text of the query, a SqlConnection, and the Transaction.
74                 public SqlCommand(
75                         String cmdText,
76                         SqlConnection connection,
77                         SqlTransaction transaction)
78                         : base(cmdText, connection, transaction)
79                 {
80                 }
81
82                 #endregion // Constructors
83
84                 #region Properties
85
86                 public new SqlConnection Connection\r
87                 {\r
88                         get { return (SqlConnection)base.Connection; }\r
89                         set { base.Connection = value; }\r
90                 }
91         
92                 public new SqlParameterCollection Parameters\r
93                 {\r
94                         get { \r
95                                 if (_parameters == null) {\r
96                                         _parameters = CreateParameterCollection(this);\r
97                                 }\r
98                                 return (SqlParameterCollection)_parameters; \r
99                         }\r
100                 }
101
102                 public new SqlTransaction Transaction\r
103                 {\r
104                         get { return (SqlTransaction)base.Transaction; }\r
105                         set { base.Transaction = value; }\r
106                 }
107
108 #if USE_DOTNET_REGEX\r
109                 protected override Regex StoredProcedureRegExp\r
110 #else\r
111                 protected override java.util.regex.Pattern StoredProcedureRegExp {\r
112 #endif\r
113                         get { return SqlStatementsHelper.NamedParameterStoredProcedureRegExp; }\r
114                 }\r
115 \r
116                 protected override SimpleRegex ParameterRegExp\r
117                 {\r
118                         get { return SqlStatementsHelper.NamedParameterRegExp; }\r
119                 }
120
121                 #endregion // Properties
122
123                 #region Methods
124
125                 public new SqlDataReader ExecuteReader()\r
126                 {\r
127                         return (SqlDataReader)ExecuteReader(CommandBehavior.Default);\r
128                 }
129
130                 public new SqlDataReader ExecuteReader(CommandBehavior behavior)\r
131                 {\r
132                         return (SqlDataReader)base.ExecuteReader(behavior);\r
133                 }
134 \r
135                 public new SqlParameter CreateParameter()\r
136                 {\r
137                         return (SqlParameter)CreateParameterInternal();\r
138                 }\r
139 \r
140                 protected override void CheckParameters()\r
141                 {\r
142                         // do nothing\r
143                 }\r
144 \r
145                 protected override AbstractDbParameter GetUserParameter(string parameterName, IList userParametersList, int userParametersListPosition/*,int userParametersListStart,int userParameterListCount*/)\r
146                 {\r
147 //                      Match match = SqlStatementsHelper.NamedParameterRegExp.Match(parameterName);
148 //                      parameterName = match.Result("${USERPARAM}");\r
149 //                      if (parameterName.Length == 0)\r
150 //                              return null;\r
151 \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
156                                 }\r
157                         }\r
158 \r
159                         return null;\r
160                 }\r
161 \r
162                 protected override DbParameter CreateParameterInternal()\r
163                 {\r
164                         return new SqlParameter();\r
165                 }\r
166 \r
167                 protected override DbDataReader CreateReader()\r
168                 {\r
169                         return new SqlDataReader(this);\r
170                 }\r
171 \r
172                 protected override DbParameterCollection CreateParameterCollection(AbstractDbCommand parent)\r
173                 {\r
174                         return new SqlParameterCollection((SqlCommand)parent);\r
175                 }\r
176 \r
177                 public object Clone()\r
178                 {\r
179                         SqlCommand clone = new SqlCommand();\r
180                         CopyTo(clone);\r
181                         return clone;\r
182                 }\r
183 \r
184                 protected override SystemException CreateException(SQLException e)
185                 {\r
186                         return new SqlException(e, Connection);         \r
187                 }
188
189                 #endregion // Methods\r
190         }
191 }