SqlCommand.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. //
  2. // System.Data.SqlClient.SqlCommand
  3. //
  4. // Author:
  5. // Boris Kirzner ([email protected])
  6. // Konstantin Triger ([email protected])
  7. //
  8. using System;
  9. using System.Collections;
  10. using System.Text;
  11. using System.Text.RegularExpressions;
  12. using System.Data;
  13. using System.Data.Common;
  14. using System.Data.ProviderBase;
  15. using java.sql;
  16. namespace System.Data.SqlClient
  17. {
  18. public class SqlCommand : AbstractDbCommand, IDbCommand, IDisposable, ICloneable
  19. {
  20. #region Fields
  21. #endregion // Fields
  22. #region Constructors
  23. // Initializes a new instance of the SqlCommand class.
  24. // The base constructor initializes all fields to their default values.
  25. // The following table shows initial property values for an instance of SqlCommand.
  26. public SqlCommand() : this(null, null, null)
  27. {
  28. }
  29. public SqlCommand(SqlConnection connection) : this(null, connection, null)
  30. {
  31. }
  32. // Initializes a new instance of the SqlCommand class with the text of the query.
  33. public SqlCommand(String cmdText) : this(cmdText, null, null)
  34. {
  35. }
  36. // Initializes a new instance of the SqlCommand class with the text of the query and a SqlConnection.
  37. public SqlCommand(String cmdText, SqlConnection connection) : this(cmdText, connection, null)
  38. {
  39. }
  40. // Initializes a new instance of the SqlCommand class with the text of the query, a SqlConnection, and the Transaction.
  41. public SqlCommand(
  42. String cmdText,
  43. SqlConnection connection,
  44. SqlTransaction transaction)
  45. : base(cmdText, connection, transaction)
  46. {
  47. }
  48. #endregion // Constructors
  49. #region Properties
  50. public new SqlConnection Connection
  51. {
  52. get { return (SqlConnection)base.Connection; }
  53. set { base.Connection = value; }
  54. }
  55. public new SqlParameterCollection Parameters
  56. {
  57. get {
  58. if (_parameters == null) {
  59. _parameters = CreateParameterCollection(this);
  60. }
  61. return (SqlParameterCollection)_parameters;
  62. }
  63. }
  64. public new SqlTransaction Transaction
  65. {
  66. get { return (SqlTransaction)base.Transaction; }
  67. set { base.Transaction = value; }
  68. }
  69. #if USE_DOTNET_REGEX
  70. protected override Regex StoredProcedureRegExp
  71. #else
  72. protected override java.util.regex.Pattern StoredProcedureRegExp {
  73. #endif
  74. get { return SqlStatementsHelper.NamedParameterStoredProcedureRegExp; }
  75. }
  76. protected override SimpleRegex ParameterRegExp
  77. {
  78. get { return SqlStatementsHelper.NamedParameterRegExp; }
  79. }
  80. #endregion // Properties
  81. #region Methods
  82. public new SqlDataReader ExecuteReader()
  83. {
  84. return (SqlDataReader)ExecuteReader(CommandBehavior.Default);
  85. }
  86. public new SqlDataReader ExecuteReader(CommandBehavior behavior)
  87. {
  88. return (SqlDataReader)base.ExecuteReader(behavior);
  89. }
  90. public new SqlParameter CreateParameter()
  91. {
  92. return (SqlParameter)CreateParameterInternal();
  93. }
  94. protected override void CheckParameters()
  95. {
  96. // do nothing
  97. }
  98. protected override AbstractDbParameter GetUserParameter(string parameterName, IList userParametersList, int userParametersListPosition/*,int userParametersListStart,int userParameterListCount*/)
  99. {
  100. // Match match = SqlStatementsHelper.NamedParameterRegExp.Match(parameterName);
  101. // parameterName = match.Result("${USERPARAM}");
  102. // if (parameterName.Length == 0)
  103. // return null;
  104. for(int i=0; i < userParametersList.Count; i++) {
  105. AbstractDbParameter userParameter = (AbstractDbParameter)userParametersList[i];
  106. if (String.Compare(parameterName, userParameter.ParameterName.Trim(), true) == 0) {
  107. return userParameter;
  108. }
  109. }
  110. return null;
  111. }
  112. protected override DbParameter CreateParameterInternal()
  113. {
  114. return new SqlParameter();
  115. }
  116. protected override DbDataReader CreateReader()
  117. {
  118. return new SqlDataReader(this);
  119. }
  120. protected override DbParameterCollection CreateParameterCollection(AbstractDbCommand parent)
  121. {
  122. return new SqlParameterCollection((SqlCommand)parent);
  123. }
  124. public object Clone()
  125. {
  126. SqlCommand clone = new SqlCommand();
  127. CopyTo(clone);
  128. return clone;
  129. }
  130. protected override SystemException CreateException(SQLException e)
  131. {
  132. return new SqlException(e, Connection);
  133. }
  134. #endregion // Methods
  135. }
  136. }