OracleCommand.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. //
  2. // System.Data.OracleClient.OracleCommand
  3. //
  4. // Authors:
  5. // Konstantin Triger <[email protected]>
  6. // Boris Kirzner <[email protected]>
  7. //
  8. // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
  9. //
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System;
  31. using System.Collections;
  32. using System.Text;
  33. using System.Text.RegularExpressions;
  34. using System.Data;
  35. using System.Data.Common;
  36. using System.Data.ProviderBase;
  37. using java.sql;
  38. // Cannot use this because it makes ArrayList ambiguous reference
  39. //using java.util;
  40. namespace System.Data.OracleClient {
  41. public sealed class OracleCommand : AbstractDbCommand, IDbCommand, ICloneable {
  42. #region Fields
  43. internal static readonly int oracleTypeRefCursor = java.sql.Types.OTHER;
  44. private static readonly int _oracleRefCursor = -10; // oracle.jdbc.OracleTypes.CURSOR
  45. private int _currentParameterIndex = 0;
  46. private ResultSet _currentRefCursor;
  47. #endregion // Fields
  48. #region Constructors
  49. static OracleCommand() {
  50. try {
  51. java.lang.Class OracleTypesClass = java.lang.Class.forName("oracle.jdbc.OracleTypes");
  52. _oracleRefCursor = OracleTypesClass.getField("CURSOR").getInt(null);
  53. }
  54. catch(java.lang.ClassNotFoundException e) {
  55. // oracle driver is not in classpath - just continue
  56. }
  57. }
  58. /**
  59. * Initializes a new instance of the OracleCommand class.
  60. * The base constructor initializes all fields to their default values.
  61. * The following table shows initial property values for an instance of SqlCommand.
  62. */
  63. public OracleCommand() : this(null, null, null) {
  64. }
  65. public OracleCommand(OracleConnection connection) : this(null, connection, null) {
  66. }
  67. /**
  68. * Initializes a new instance of the OracleCommand class with the text of the query.
  69. * @param cmdText The text of the query.
  70. */
  71. public OracleCommand(String cmdText) : this(cmdText, null, null) {
  72. }
  73. /**
  74. * Initializes a new instance of the OracleCommand class with the text of the query and a SqlConnection.
  75. * @param cmdText The text of the query.
  76. * @param connection A SqlConnection that represents the connection to an instance of SQL Server.
  77. */
  78. public OracleCommand(String cmdText, OracleConnection connection) : this(cmdText, connection, null) {
  79. }
  80. /**
  81. * Initializes a new instance of the OracleCommand class with the text of the query, a SqlConnection, and the Transaction.
  82. * @param cmdText The text of the query.
  83. * @param connection A SqlConnection that represents the connection to an instance of SQL Server.
  84. * @param transaction The SqlTransaction in which the OracleCommand executes.
  85. */
  86. public OracleCommand(
  87. String cmdText,
  88. OracleConnection connection,
  89. OracleTransaction transaction)
  90. : base(cmdText, connection, transaction) {
  91. }
  92. #endregion // Constructors
  93. #region Properties
  94. public new OracleConnection Connection {
  95. get { return (OracleConnection)base.Connection; }
  96. set { base.Connection = (AbstractDBConnection)value; }
  97. }
  98. public new OracleParameterCollection Parameters {
  99. get {
  100. if (_parameters == null) {
  101. _parameters = CreateParameterCollection(this);
  102. }
  103. return (OracleParameterCollection)_parameters;
  104. }
  105. }
  106. public new OracleTransaction Transaction {
  107. get { return (OracleTransaction)base.Transaction; }
  108. set { base.Transaction = (DbTransaction)value; }
  109. }
  110. #endregion // Properties
  111. #region Methods
  112. public new OracleDataReader ExecuteReader() {
  113. return (OracleDataReader)ExecuteReader(CommandBehavior.Default);
  114. }
  115. public new OracleDataReader ExecuteReader(CommandBehavior behavior) {
  116. return (OracleDataReader)base.ExecuteReader(behavior);
  117. }
  118. public new OracleParameter CreateParameter() {
  119. return (OracleParameter)CreateParameterInternal();
  120. }
  121. protected sealed override void CheckParameters() {
  122. //TBD
  123. }
  124. protected sealed override DbParameter CreateParameterInternal() {
  125. return new OracleParameter();
  126. }
  127. protected sealed override DbParameterCollection CreateParameterCollection(AbstractDbCommand parent) {
  128. return new OracleParameterCollection((OracleCommand)parent);
  129. }
  130. public object Clone() {
  131. OracleCommand clone = new OracleCommand();
  132. CopyTo(clone);
  133. return clone;
  134. }
  135. protected override void PrepareInternalParameters() {
  136. InternalParameters.Clear();
  137. _currentParameterIndex = -1;
  138. }
  139. protected sealed override DbDataReader CreateReader() {
  140. return new OracleDataReader(this);
  141. }
  142. protected sealed override SystemException CreateException(SQLException e) {
  143. return new OracleException(e,Connection);
  144. }
  145. #endregion // Methods
  146. }
  147. }