SqlDataAdapter.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. //
  2. // System.Data.SqlClient.SqlDataAdapter.cs
  3. //
  4. // Author:
  5. // Rodrigo Moya ([email protected])
  6. // Daniel Morgan ([email protected])
  7. // Tim Coleman ([email protected])
  8. // Veerapuram Varadhan ([email protected])
  9. //
  10. // (C) Ximian, Inc 2002
  11. // Copyright (C) 2002 Tim Coleman
  12. //
  13. // Copyright (C) 2004, 2009 Novell, Inc (http://www.novell.com)
  14. //
  15. // Permission is hereby granted, free of charge, to any person obtaining
  16. // a copy of this software and associated documentation files (the
  17. // "Software"), to deal in the Software without restriction, including
  18. // without limitation the rights to use, copy, modify, merge, publish,
  19. // distribute, sublicense, and/or sell copies of the Software, and to
  20. // permit persons to whom the Software is furnished to do so, subject to
  21. // the following conditions:
  22. //
  23. // The above copyright notice and this permission notice shall be
  24. // included in all copies or substantial portions of the Software.
  25. //
  26. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  27. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  29. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  30. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  31. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  32. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  33. //
  34. using System;
  35. using System.ComponentModel;
  36. using System.Data;
  37. using System.Data.Common;
  38. namespace System.Data.SqlClient {
  39. [DefaultEvent ("RowUpdated")]
  40. [DesignerAttribute ("Microsoft.VSDesigner.Data.VS.SqlDataAdapterDesigner, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.IDesigner")]
  41. [ToolboxItemAttribute ("Microsoft.VSDesigner.Data.VS.SqlDataAdapterToolboxItem, "+ Consts.AssemblyMicrosoft_VSDesigner)]
  42. public sealed class SqlDataAdapter : DbDataAdapter, IDbDataAdapter, IDataAdapter, ICloneable
  43. {
  44. #region Fields
  45. #if ONLY_1_0 || ONLY_1_1
  46. SqlCommand _selectCommand;
  47. SqlCommand _insertCommand;
  48. SqlCommand _updateCommand;
  49. SqlCommand _deleteCommand;
  50. #endif
  51. int updateBatchSize;
  52. #endregion
  53. #region Constructors
  54. public SqlDataAdapter () : this ((SqlCommand) null)
  55. {
  56. }
  57. public SqlDataAdapter (SqlCommand selectCommand)
  58. {
  59. SelectCommand = selectCommand;
  60. UpdateBatchSize = 1;
  61. }
  62. public SqlDataAdapter (string selectCommandText, SqlConnection selectConnection)
  63. : this (new SqlCommand (selectCommandText, selectConnection))
  64. {
  65. }
  66. public SqlDataAdapter (string selectCommandText, string selectConnectionString)
  67. : this (selectCommandText, new SqlConnection (selectConnectionString))
  68. {
  69. }
  70. #endregion
  71. #region Properties
  72. [DefaultValue (null)]
  73. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  74. public new SqlCommand DeleteCommand {
  75. get {
  76. return (SqlCommand)base.DeleteCommand;
  77. }
  78. set {
  79. base.DeleteCommand = value;
  80. }
  81. }
  82. [DefaultValue (null)]
  83. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  84. public new SqlCommand InsertCommand {
  85. get {
  86. return (SqlCommand)base.InsertCommand;
  87. }
  88. set {
  89. base.InsertCommand = value;
  90. }
  91. }
  92. [DefaultValue (null)]
  93. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  94. public new SqlCommand SelectCommand {
  95. get {
  96. return (SqlCommand)base.SelectCommand;
  97. }
  98. set {
  99. base.SelectCommand = value;
  100. }
  101. }
  102. [DefaultValue (null)]
  103. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  104. public new SqlCommand UpdateCommand {
  105. get {
  106. return (SqlCommand)base.UpdateCommand;
  107. }
  108. set {
  109. base.UpdateCommand = value;
  110. }
  111. }
  112. IDbCommand IDbDataAdapter.SelectCommand {
  113. get { return SelectCommand; }
  114. set { SelectCommand = (SqlCommand) value; }
  115. }
  116. IDbCommand IDbDataAdapter.InsertCommand {
  117. get { return InsertCommand; }
  118. set { InsertCommand = (SqlCommand) value; }
  119. }
  120. IDbCommand IDbDataAdapter.UpdateCommand {
  121. get { return UpdateCommand; }
  122. set { UpdateCommand = (SqlCommand) value; }
  123. }
  124. IDbCommand IDbDataAdapter.DeleteCommand {
  125. get { return DeleteCommand; }
  126. set { DeleteCommand = (SqlCommand) value; }
  127. }
  128. public override int UpdateBatchSize {
  129. get { return updateBatchSize; }
  130. set {
  131. if (value < 0)
  132. throw new ArgumentOutOfRangeException ("UpdateBatchSize");
  133. updateBatchSize = value;
  134. }
  135. }
  136. #endregion // Properties
  137. #region Methods
  138. protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
  139. {
  140. return new SqlRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
  141. }
  142. protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
  143. {
  144. return new SqlRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
  145. }
  146. protected override void OnRowUpdated (RowUpdatedEventArgs value)
  147. {
  148. if (RowUpdated != null)
  149. RowUpdated (this, (SqlRowUpdatedEventArgs) value);
  150. }
  151. protected override void OnRowUpdating (RowUpdatingEventArgs value)
  152. {
  153. if (RowUpdating != null)
  154. RowUpdating (this, (SqlRowUpdatingEventArgs) value);
  155. }
  156. [MonoTODO]
  157. object ICloneable.Clone()
  158. {
  159. throw new NotImplementedException ();
  160. }
  161. // All the batch methods, should be implemented, if supported,
  162. // by individual providers
  163. [MonoTODO]
  164. protected override int AddToBatch (IDbCommand command)
  165. {
  166. throw new NotImplementedException ();
  167. }
  168. [MonoTODO]
  169. protected override void ClearBatch ()
  170. {
  171. throw new NotImplementedException ();
  172. }
  173. [MonoTODO]
  174. protected override int ExecuteBatch ()
  175. {
  176. throw new NotImplementedException ();
  177. }
  178. [MonoTODO]
  179. protected override IDataParameter GetBatchedParameter (int commandIdentifier, int parameterIndex)
  180. {
  181. throw new NotImplementedException ();
  182. }
  183. [MonoTODO]
  184. protected override void InitializeBatching ()
  185. {
  186. throw new NotImplementedException ();
  187. }
  188. [MonoTODO]
  189. protected override void TerminateBatching ()
  190. {
  191. throw new NotImplementedException ();
  192. }
  193. #endregion // Methods
  194. #region Events and Delegates
  195. public event SqlRowUpdatedEventHandler RowUpdated;
  196. public event SqlRowUpdatingEventHandler RowUpdating;
  197. #endregion // Events and Delegates
  198. }
  199. }