SqlDataAdapter.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. //
  9. // (C) Ximian, Inc 2002
  10. // Copyright (C) 2002 Tim Coleman
  11. //
  12. // Copyright (C) 2004 Novell, Inc (http://www.novell.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. using System;
  34. using System.ComponentModel;
  35. using System.Data;
  36. using System.Data.Common;
  37. namespace System.Data.SqlClient {
  38. [DefaultEvent ("RowUpdated")]
  39. [DesignerAttribute ("Microsoft.VSDesigner.Data.VS.SqlDataAdapterDesigner, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.IDesigner")]
  40. [ToolboxItemAttribute ("Microsoft.VSDesigner.Data.VS.SqlDataAdapterToolboxItem, "+ Consts.AssemblyMicrosoft_VSDesigner)]
  41. public sealed class SqlDataAdapter : DbDataAdapter, IDbDataAdapter, IDataAdapter, ICloneable
  42. {
  43. #region Fields
  44. #if !NET_2_0
  45. bool disposed;
  46. #endif
  47. #if NET_2_0
  48. int updateBatchSize;
  49. #endif
  50. #endregion
  51. #region Constructors
  52. public SqlDataAdapter () : this ((SqlCommand) null)
  53. {
  54. }
  55. public SqlDataAdapter (SqlCommand selectCommand)
  56. {
  57. SelectCommand = selectCommand;
  58. #if NET_2_0
  59. UpdateBatchSize = 1;
  60. #endif
  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. #if !NET_2_0
  73. [DataSysDescription ("Used during Update for deleted rows in DataSet.")]
  74. #endif
  75. [DefaultValue (null)]
  76. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  77. public
  78. #if ONLY_1_1
  79. new
  80. #endif
  81. SqlCommand DeleteCommand {
  82. get { return (SqlCommand)base.DeleteCommand; }
  83. set { base.DeleteCommand = value; }
  84. }
  85. #if !NET_2_0
  86. [DataSysDescription ("Used during Update for new rows in DataSet.")]
  87. #endif
  88. [DefaultValue (null)]
  89. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  90. public
  91. #if ONLY_1_1
  92. new
  93. #endif
  94. SqlCommand InsertCommand {
  95. get { return (SqlCommand)base.InsertCommand; }
  96. set { base.InsertCommand = value; }
  97. }
  98. #if !NET_2_0
  99. [DataSysDescription ("Used during Fill/FillSchema.")]
  100. #endif
  101. [DefaultValue (null)]
  102. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  103. public
  104. #if ONLY_1_1
  105. new
  106. #endif
  107. SqlCommand SelectCommand {
  108. get { return (SqlCommand)base.SelectCommand; }
  109. set { base.SelectCommand = value; }
  110. }
  111. #if !NET_2_0
  112. [DataSysDescription ("Used during Update for modified rows in DataSet.")]
  113. #endif
  114. [DefaultValue (null)]
  115. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  116. public
  117. #if ONLY_1_1
  118. new
  119. #endif
  120. SqlCommand UpdateCommand {
  121. get { return (SqlCommand)base.UpdateCommand; }
  122. set { base.UpdateCommand = value; }
  123. }
  124. #if NET_2_0
  125. public override int UpdateBatchSize {
  126. get { return updateBatchSize; }
  127. set {
  128. if (value < 0)
  129. throw new ArgumentOutOfRangeException ("UpdateBatchSize");
  130. updateBatchSize = value;
  131. }
  132. }
  133. #endif
  134. #endregion // Properties
  135. #region Methods
  136. protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
  137. {
  138. return new SqlRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
  139. }
  140. protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
  141. {
  142. return new SqlRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
  143. }
  144. #if !NET_2_0
  145. protected override void Dispose (bool disposing)
  146. {
  147. if (!disposed) {
  148. if (disposing) {
  149. // Release managed resources
  150. }
  151. // Release unmanaged resources
  152. disposed = true;
  153. }
  154. base.Dispose (disposing);
  155. }
  156. #endif
  157. protected override void OnRowUpdated (RowUpdatedEventArgs value)
  158. {
  159. if (RowUpdated != null)
  160. RowUpdated (this, (SqlRowUpdatedEventArgs) value);
  161. }
  162. protected override void OnRowUpdating (RowUpdatingEventArgs value)
  163. {
  164. if (RowUpdating != null)
  165. RowUpdating (this, (SqlRowUpdatingEventArgs) value);
  166. }
  167. [MonoTODO]
  168. object ICloneable.Clone()
  169. {
  170. throw new NotImplementedException ();
  171. }
  172. #if NET_2_0
  173. // All the batch methods, should be implemented, if supported,
  174. // by individual providers
  175. [MonoTODO]
  176. protected override int AddToBatch (IDbCommand command)
  177. {
  178. throw new NotImplementedException ();
  179. }
  180. [MonoTODO]
  181. protected override void ClearBatch ()
  182. {
  183. throw new NotImplementedException ();
  184. }
  185. [MonoTODO]
  186. protected override int ExecuteBatch ()
  187. {
  188. throw new NotImplementedException ();
  189. }
  190. [MonoTODO]
  191. protected override IDataParameter GetBatchedParameter (int commandIdentifier, int parameterIndex)
  192. {
  193. throw new NotImplementedException ();
  194. }
  195. [MonoTODO]
  196. protected override void InitializeBatching ()
  197. {
  198. throw new NotImplementedException ();
  199. }
  200. [MonoTODO]
  201. protected override void TerminateBatching ()
  202. {
  203. throw new NotImplementedException ();
  204. }
  205. #endif
  206. #endregion // Methods
  207. #region Events and Delegates
  208. #if ONLY_1_1
  209. [DataSysDescription ("Event triggered before every DataRow during Update.")]
  210. #endif
  211. public event SqlRowUpdatedEventHandler RowUpdated;
  212. #if ONLY_1_1
  213. [DataSysDescription ("Event triggered after every DataRow during Update.")]
  214. #endif
  215. public event SqlRowUpdatingEventHandler RowUpdating;
  216. #endregion // Events and Delegates
  217. }
  218. }