2 // System.Data.OracleClient.OracleCommand
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
;
36 using System
.Text
.RegularExpressions
;
38 using System
.Data
.Common
;
39 using System
.Data
.ProviderBase
;
40 using System
.Globalization
;
43 // Cannot use this because it makes ArrayList ambiguous reference
45 #if !USE_DOTNET_REGEXP
46 using java
.util
.regex
;
49 namespace System
.Data
.OracleClient
{
50 public sealed class OracleCommand
: AbstractDbCommand
{
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
);
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
);
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
;
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) {
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) {
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) {
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(
103 OracleConnection connection
,
104 OracleTransaction transaction
)
105 : base(cmdText
, connection
, transaction
) {
108 #endregion // Constructors
112 public new OracleConnection Connection
{
113 get { return (OracleConnection)base.Connection; }
114 set { base.Connection = (AbstractDBConnection)value; }
117 public new OracleParameterCollection Parameters
{
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
{
135 ResultSet resultSet
= base.CurrentResultSet
;
137 if (resultSet
!= null) {
140 return CurrentRefCursor
;
142 catch(SQLException e
) {
143 throw CreateException(e
);
148 private ResultSet CurrentRefCursor
{
150 if (_currentParameterIndex
< 0) {
153 if (_currentRefCursor
== null && _currentParameterIndex
< InternalParameters
.Count
) {
154 _currentRefCursor
= (ResultSet
)((CallableStatement
)Statement
).getObject(_currentParameterIndex
+ 1);
156 return _currentRefCursor
;
161 protected override Regex StoredProcedureRegExp
163 protected override java
.util
.regex
.Pattern StoredProcedureRegExp
{
165 get { return NamedParameterStoredProcedureRegExp; }
168 protected override SimpleRegex ParameterRegExp
{
169 get { return NamedParameterRegExp; }
172 #endregion // Properties
176 protected override bool NextResultSet() {
178 bool hasMoreResults
= base.NextResultSet();
180 if (hasMoreResults
) {
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
))
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() {
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
;
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
;
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;
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();
281 #endregion // Methods