SqlCommand.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. //
  2. // System.Data.SqlClient.SqlCommand
  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. namespace System.Data.SqlClient
  39. {
  40. public class SqlCommand : AbstractDbCommand
  41. {
  42. #region Fields
  43. #endregion // Fields
  44. #region Constructors
  45. // Initializes a new instance of the SqlCommand class.
  46. // The base constructor initializes all fields to their default values.
  47. // The following table shows initial property values for an instance of SqlCommand.
  48. public SqlCommand() : this(null, null, null)
  49. {
  50. }
  51. public SqlCommand(SqlConnection connection) : this(null, connection, null)
  52. {
  53. }
  54. // Initializes a new instance of the SqlCommand class with the text of the query.
  55. public SqlCommand(String cmdText) : this(cmdText, null, null)
  56. {
  57. }
  58. // Initializes a new instance of the SqlCommand class with the text of the query and a SqlConnection.
  59. public SqlCommand(String cmdText, SqlConnection connection) : this(cmdText, connection, null)
  60. {
  61. }
  62. // Initializes a new instance of the SqlCommand class with the text of the query, a SqlConnection, and the Transaction.
  63. public SqlCommand(
  64. String cmdText,
  65. SqlConnection connection,
  66. SqlTransaction transaction)
  67. : base(cmdText, connection, transaction)
  68. {
  69. }
  70. #endregion // Constructors
  71. #region Properties
  72. public new SqlConnection Connection
  73. {
  74. get { return (SqlConnection)base.Connection; }
  75. set { base.Connection = value; }
  76. }
  77. public new SqlParameterCollection Parameters
  78. {
  79. get {
  80. return (SqlParameterCollection)base.Parameters;
  81. }
  82. }
  83. public new SqlTransaction Transaction
  84. {
  85. get { return (SqlTransaction)base.Transaction; }
  86. set { base.Transaction = value; }
  87. }
  88. #if USE_DOTNET_REGEX
  89. protected override Regex StoredProcedureRegExp
  90. #else
  91. protected override java.util.regex.Pattern StoredProcedureRegExp {
  92. #endif
  93. get { return SqlStatementsHelper.NamedParameterStoredProcedureRegExp; }
  94. }
  95. protected override SimpleRegex ParameterRegExp
  96. {
  97. get { return SqlStatementsHelper.NamedParameterRegExp; }
  98. }
  99. #endregion // Properties
  100. #region Methods
  101. public new SqlDataReader ExecuteReader()
  102. {
  103. return (SqlDataReader)ExecuteReader(CommandBehavior.Default);
  104. }
  105. public new SqlDataReader ExecuteReader(CommandBehavior behavior)
  106. {
  107. return (SqlDataReader)base.ExecuteReader(behavior);
  108. }
  109. public new SqlParameter CreateParameter()
  110. {
  111. return (SqlParameter)CreateParameterInternal();
  112. }
  113. protected sealed override void CheckParameters()
  114. {
  115. // do nothing
  116. }
  117. protected override AbstractDbParameter GetUserParameter(string parameterName, IList userParametersList, int userParametersListPosition/*,int userParametersListStart,int userParameterListCount*/)
  118. {
  119. // Match match = SqlStatementsHelper.NamedParameterRegExp.Match(parameterName);
  120. // parameterName = match.Result("${USERPARAM}");
  121. // if (parameterName.Length == 0)
  122. // return null;
  123. for(int i=0; i < userParametersList.Count; i++) {
  124. AbstractDbParameter userParameter = (AbstractDbParameter)userParametersList[i];
  125. if (String.Compare(parameterName, userParameter.ParameterName.Trim(), true) == 0) {
  126. return userParameter;
  127. }
  128. }
  129. return null;
  130. }
  131. protected override AbstractDbParameter GetReturnParameter (IList userParametersList)
  132. {
  133. for(int i=0; i < userParametersList.Count; i++) {
  134. AbstractDbParameter userParameter = (AbstractDbParameter)userParametersList[i];
  135. if (userParameter.Direction == ParameterDirection.ReturnValue) {
  136. return userParameter;
  137. }
  138. }
  139. return null;
  140. }
  141. protected sealed override DbParameter CreateParameterInternal()
  142. {
  143. return new SqlParameter();
  144. }
  145. protected sealed override DbDataReader CreateReader()
  146. {
  147. return new SqlDataReader(this);
  148. }
  149. protected sealed override DbParameterCollection CreateParameterCollection(AbstractDbCommand parent)
  150. {
  151. return new SqlParameterCollection((SqlCommand)parent);
  152. }
  153. protected internal sealed override SystemException CreateException(SQLException e)
  154. {
  155. return new SqlException(e, Connection);
  156. }
  157. #endregion // Methods
  158. }
  159. }