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