[Cleanup] Removed JavaEE csproj and sln files
[mono-project.git] / mcs / class / System.Data.OracleClient / System.Data.OracleClient.jvm / OracleCommand.cs
blob1e59ffcf3a8ed6d498fa003b99316ec822d8f028
1 //
2 // System.Data.OracleClient.OracleCommand
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.
33 using System;
34 using System.Collections;
35 using System.Text;
36 using System.Text.RegularExpressions;
37 using System.Data;
38 using System.Data.Common;
39 using System.Data.ProviderBase;
40 using System.Globalization;
42 using java.sql;
43 // Cannot use this because it makes ArrayList ambiguous reference
44 //using java.util;
45 #if !USE_DOTNET_REGEXP
46 using java.util.regex;
47 #endif
49 namespace System.Data.OracleClient {
50 public sealed class OracleCommand : AbstractDbCommand {
52 #region Fields
53 #if USE_DOTNET_REGEXP
54 internal static readonly Regex NamedParameterStoredProcedureRegExp = new Regex(@"^\s*{?\s*((?<RETVAL>\:\w+)\s*=\s*)?call\s+(?<PROCNAME>(((\[[^\]]*\])|([^\.\(])*)\s*\.\s*){0,2}(\[[^\]]*\]|((\s*[^\.\(\)\{\}\s])+)))\s*(\(\s*(?<USERPARAM>((""([^""]|(""""))*"")|('([^']|(''))*')|[^,])*)?\s*(,\s*(?<USERPARAM>((""([^""]|(""""))*"")|('([^']|(''))*')|[^,])*)\s*)*\))?\s*}?\s*$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
55 #else
56 internal static readonly Pattern NamedParameterStoredProcedureRegExp = Pattern.compile(@"^\s*\{?\s*(?:(\:\w+)\s*=\s*)?call\s+((?:(?:(?:\[[^\]]*\])|(?:[^\.\(\)\{\}\[\]])*)\s*\.\s*){0,2}(?:\[[^\]]*\]|(?:(?:\s*[^\.\(\)\{\}\[\]])+)))\s*(?:\((.*)\))?\s*\}?\s*$", Pattern.CASE_INSENSITIVE);
57 #endif
58 internal static readonly SimpleRegex NamedParameterRegExp = new OracleParamsRegex();
60 // internal static readonly int oracleTypeRefCursor = java.sql.Types.OTHER;
62 private int _currentParameterIndex = 0;
63 private ResultSet _currentRefCursor;
65 #endregion // Fields
67 #region Constructors
69 /**
70 * Initializes a new instance of the OracleCommand class.
71 * The base constructor initializes all fields to their default values.
72 * The following table shows initial property values for an instance of SqlCommand.
74 public OracleCommand() : this(null, null, null) {
77 public OracleCommand(OracleConnection connection) : this(null, connection, null) {
80 /**
81 * Initializes a new instance of the OracleCommand class with the text of the query.
82 * @param cmdText The text of the query.
84 public OracleCommand(String cmdText) : this(cmdText, null, null) {
87 /**
88 * Initializes a new instance of the OracleCommand class with the text of the query and a SqlConnection.
89 * @param cmdText The text of the query.
90 * @param connection A SqlConnection that represents the connection to an instance of SQL Server.
92 public OracleCommand(String cmdText, OracleConnection connection) : this(cmdText, connection, null) {
95 /**
96 * Initializes a new instance of the OracleCommand class with the text of the query, a SqlConnection, and the Transaction.
97 * @param cmdText The text of the query.
98 * @param connection A SqlConnection that represents the connection to an instance of SQL Server.
99 * @param transaction The SqlTransaction in which the OracleCommand executes.
101 public OracleCommand(
102 String cmdText,
103 OracleConnection connection,
104 OracleTransaction transaction)
105 : base(cmdText, connection, transaction) {
108 #endregion // Constructors
110 #region Properties
112 public new OracleConnection Connection {
113 get { return (OracleConnection)base.Connection; }
114 set { base.Connection = (AbstractDBConnection)value; }
117 public new OracleParameterCollection Parameters {
118 get {
119 return (OracleParameterCollection)base.Parameters;
123 public new OracleTransaction Transaction {
124 get { return (OracleTransaction)base.Transaction; }
125 set { base.Transaction = (DbTransaction)value; }
128 protected override bool SkipParameter(DbParameter parameter) {
129 return ((OracleParameter)parameter).OracleType == OracleType.Cursor;
132 protected sealed override ResultSet CurrentResultSet {
133 get {
134 try {
135 ResultSet resultSet = base.CurrentResultSet;
137 if (resultSet != null) {
138 return resultSet;
140 return CurrentRefCursor;
142 catch(SQLException e) {
143 throw CreateException(e);
148 private ResultSet CurrentRefCursor {
149 get {
150 if (_currentParameterIndex < 0) {
151 NextRefCursor();
153 if (_currentRefCursor == null && _currentParameterIndex < InternalParameters.Count) {
154 _currentRefCursor = (ResultSet)((CallableStatement)Statement).getObject(_currentParameterIndex + 1);
156 return _currentRefCursor;
160 #if USE_DOTNET_REGEX
161 protected override Regex StoredProcedureRegExp
162 #else
163 protected override java.util.regex.Pattern StoredProcedureRegExp {
164 #endif
165 get { return NamedParameterStoredProcedureRegExp; }
168 protected override SimpleRegex ParameterRegExp {
169 get { return NamedParameterRegExp; }
172 #endregion // Properties
174 #region Methods
176 protected override bool NextResultSet() {
177 try {
178 bool hasMoreResults = base.NextResultSet();
180 if (hasMoreResults) {
181 return true;
183 else {
184 return NextRefCursor();
187 catch (SQLException e) {
188 throw CreateException(e);
192 private bool NextRefCursor() {
193 _currentRefCursor = null;
194 for (_currentParameterIndex++;InternalParameters.Count > _currentParameterIndex;_currentParameterIndex++) {
195 OracleParameter param = (OracleParameter)InternalParameters[_currentParameterIndex];
196 if (param.OracleType == OracleType.Cursor && ((param.Direction & ParameterDirection.Output) == ParameterDirection.Output))
197 return true;
199 return false;
202 public new OracleDataReader ExecuteReader() {
203 return (OracleDataReader)ExecuteReader(CommandBehavior.Default);
206 public new OracleDataReader ExecuteReader(CommandBehavior behavior) {
207 return (OracleDataReader)base.ExecuteReader(behavior);
210 public new OracleParameter CreateParameter() {
211 return (OracleParameter)CreateParameterInternal();
214 protected sealed override void CheckParameters() {
215 //TBD
218 protected override AbstractDbParameter GetUserParameter(string parameterName, IList userParametersList, int userParametersListPosition) {
219 for(int i=0; i < userParametersList.Count; i++) {
220 OracleParameter userParameter = (OracleParameter)userParametersList[i];
221 if (String.Compare(parameterName, userParameter.InternalPlaceholder.Trim(), true, CultureInfo.InvariantCulture) == 0) {
222 return userParameter;
226 return null;
229 protected override AbstractDbParameter GetReturnParameter (IList userParametersList) {
230 for(int i=0; i < userParametersList.Count; i++) {
231 AbstractDbParameter userParameter = (AbstractDbParameter)userParametersList[i];
232 if (userParameter.Direction == ParameterDirection.ReturnValue) {
233 return userParameter;
237 return null;
240 protected sealed override DbParameter CreateParameterInternal() {
241 return new OracleParameter();
244 protected sealed override DbParameterCollection CreateParameterCollection(AbstractDbCommand parent) {
245 return new OracleParameterCollection((OracleCommand)parent);
248 public override object Clone() {
249 OracleCommand clone = (OracleCommand)base.Clone();
250 clone._currentParameterIndex = 0;
251 clone._currentRefCursor = null;
252 return clone;
255 protected override void PrepareInternalParameters() {
256 InternalParameters.Clear();
257 _currentParameterIndex = -1;
261 protected sealed override DbDataReader CreateReader() {
262 return new OracleDataReader(this);
265 protected sealed override SystemException CreateException(SQLException e) {
266 return new OracleException(e,Connection);
269 public object ExecuteOracleScalar() {
270 throw new NotImplementedException();
273 #if SUPPORT_ORACLE_TYPES
274 public int ExecuteOracleNonQuery(
275 out OracleString rowid
277 throw new NotImplementedException();
279 #endif
281 #endregion // Methods