DbCommandBase.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //
  2. // System.Data.ProviderBase.DbCommandBase
  3. //
  4. // Author:
  5. // Tim Coleman ([email protected])
  6. // Boris Kirzner ([email protected])
  7. //
  8. // Copyright (C) Tim Coleman, 2003
  9. //
  10. //
  11. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  12. // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
  13. //
  14. // Permission is hereby granted, free of charge, to any person obtaining
  15. // a copy of this software and associated documentation files (the
  16. // "Software"), to deal in the Software without restriction, including
  17. // without limitation the rights to use, copy, modify, merge, publish,
  18. // distribute, sublicense, and/or sell copies of the Software, and to
  19. // permit persons to whom the Software is furnished to do so, subject to
  20. // the following conditions:
  21. //
  22. // The above copyright notice and this permission notice shall be
  23. // included in all copies or substantial portions of the Software.
  24. //
  25. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  29. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  30. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  31. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  32. //
  33. #if NET_2_0 || TARGET_JVM
  34. using System.Data.Common;
  35. namespace System.Data.ProviderBase {
  36. public abstract class DbCommandBase : DbCommand
  37. {
  38. #region Fields
  39. string _commandText;
  40. int _commandTimeout;
  41. CommandType _commandType;
  42. bool _designTimeVisible;
  43. UpdateRowSource _updatedRowSource;
  44. #endregion // Fields
  45. #region Constructors
  46. protected DbCommandBase ()
  47. {
  48. _commandText = String.Empty;
  49. _commandTimeout = 30;
  50. _commandType = CommandType.Text;
  51. _designTimeVisible = true;
  52. _updatedRowSource = UpdateRowSource.Both;
  53. }
  54. protected DbCommandBase (DbCommandBase from)
  55. {
  56. _commandText = from._commandText;
  57. _commandTimeout = from._commandTimeout;
  58. _commandType = from._commandType;
  59. _updatedRowSource = from._updatedRowSource;
  60. _designTimeVisible = from._designTimeVisible;
  61. }
  62. #endregion // Constructors
  63. #region Properties
  64. public override string CommandText {
  65. get { return _commandText; }
  66. set { _commandText = value; }
  67. }
  68. public override int CommandTimeout {
  69. get { return _commandTimeout; }
  70. set { _commandTimeout = value; }
  71. }
  72. public override CommandType CommandType {
  73. get { return _commandType; }
  74. set { _commandType = value; }
  75. }
  76. public override bool DesignTimeVisible {
  77. get { return _designTimeVisible; }
  78. set { _designTimeVisible = value; }
  79. }
  80. public override UpdateRowSource UpdatedRowSource {
  81. get { return _updatedRowSource; }
  82. set { _updatedRowSource = value; }
  83. }
  84. #endregion // Properties
  85. #region Methods
  86. [MonoTODO]
  87. public override void Cancel ()
  88. {
  89. throw new NotImplementedException ();
  90. }
  91. public override int ExecuteNonQuery ()
  92. {
  93. IDataReader reader = null;
  94. try {
  95. reader = ExecuteReader ();
  96. }
  97. finally {
  98. if (reader != null)
  99. reader.Close ();
  100. }
  101. return reader.RecordsAffected;
  102. }
  103. public override object ExecuteScalar ()
  104. {
  105. IDataReader reader = ExecuteReader(CommandBehavior.SingleRow | CommandBehavior.SequentialAccess);
  106. try {
  107. do {
  108. if (reader.FieldCount > 0 && reader.Read ())
  109. return reader.GetValue (0);
  110. }
  111. while (reader.NextResult ());
  112. return null;
  113. } finally {
  114. reader.Close();
  115. }
  116. }
  117. [MonoTODO]
  118. public override void Prepare ()
  119. {
  120. throw new NotImplementedException ();
  121. }
  122. public virtual void PropertyChanging ()
  123. {
  124. }
  125. public virtual void ResetCommandTimeout ()
  126. {
  127. _commandTimeout = 30;
  128. }
  129. [MonoTODO]
  130. protected internal static void SetInputParameterValues (DbCommand command, object[] inputParameterValues)
  131. {
  132. throw new NotImplementedException ();
  133. }
  134. #endregion // Methods
  135. }
  136. }
  137. #endif