SqlDataAdapter.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. //
  13. // Copyright (C) 2004 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, ICloneable
  43. {
  44. #region Fields
  45. #if !NET_2_0
  46. bool disposed;
  47. #endif
  48. SqlCommand deleteCommand;
  49. SqlCommand insertCommand;
  50. SqlCommand selectCommand;
  51. SqlCommand updateCommand;
  52. #if NET_2_0
  53. int updateBatchSize;
  54. #endif
  55. #endregion
  56. #region Constructors
  57. public SqlDataAdapter ()
  58. : this (new SqlCommand ())
  59. {
  60. }
  61. public SqlDataAdapter (SqlCommand selectCommand)
  62. {
  63. DeleteCommand = null;
  64. InsertCommand = null;
  65. SelectCommand = selectCommand;
  66. UpdateCommand = null;
  67. #if NET_2_0
  68. UpdateBatchSize = 1;
  69. #endif
  70. }
  71. public SqlDataAdapter (string selectCommandText, SqlConnection selectConnection)
  72. : this (new SqlCommand (selectCommandText, selectConnection))
  73. {
  74. }
  75. public SqlDataAdapter (string selectCommandText, string selectConnectionString)
  76. : this (selectCommandText, new SqlConnection (selectConnectionString))
  77. {
  78. }
  79. #endregion
  80. #region Properties
  81. #if !NET_2_0
  82. [DataSysDescription ("Used during Update for deleted rows in DataSet.")]
  83. #endif
  84. [DefaultValue (null)]
  85. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  86. public new SqlCommand DeleteCommand {
  87. get { return deleteCommand; }
  88. set { deleteCommand = value; }
  89. }
  90. #if !NET_2_0
  91. [DataSysDescription ("Used during Update for new rows in DataSet.")]
  92. #endif
  93. [DefaultValue (null)]
  94. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  95. public new SqlCommand InsertCommand {
  96. get { return insertCommand; }
  97. set { insertCommand = value; }
  98. }
  99. #if !NET_2_0
  100. [DataSysDescription ("Used during Fill/FillSchema.")]
  101. #endif
  102. [DefaultValue (null)]
  103. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  104. public new SqlCommand SelectCommand {
  105. get { return selectCommand; }
  106. set { selectCommand = value; }
  107. }
  108. #if !NET_2_0
  109. [DataSysDescription ("Used during Update for modified rows in DataSet.")]
  110. #endif
  111. [DefaultValue (null)]
  112. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  113. public new SqlCommand UpdateCommand {
  114. get { return updateCommand; }
  115. set { updateCommand = value; }
  116. }
  117. IDbCommand IDbDataAdapter.DeleteCommand {
  118. get { return DeleteCommand; }
  119. set {
  120. if (!(value is SqlCommand))
  121. throw new ArgumentException ();
  122. DeleteCommand = (SqlCommand)value;
  123. }
  124. }
  125. IDbCommand IDbDataAdapter.InsertCommand {
  126. get { return InsertCommand; }
  127. set {
  128. if (!(value is SqlCommand))
  129. throw new ArgumentException ();
  130. InsertCommand = (SqlCommand)value;
  131. }
  132. }
  133. IDbCommand IDbDataAdapter.SelectCommand {
  134. get { return SelectCommand; }
  135. set {
  136. if (!(value is SqlCommand))
  137. throw new ArgumentException ();
  138. SelectCommand = (SqlCommand)value;
  139. }
  140. }
  141. IDbCommand IDbDataAdapter.UpdateCommand {
  142. get { return UpdateCommand; }
  143. set {
  144. if (!(value is SqlCommand))
  145. throw new ArgumentException ();
  146. UpdateCommand = (SqlCommand)value;
  147. }
  148. }
  149. ITableMappingCollection IDataAdapter.TableMappings {
  150. get { return TableMappings; }
  151. }
  152. #if NET_2_0
  153. public override int UpdateBatchSize {
  154. get { return updateBatchSize; }
  155. set {
  156. if (value < 0)
  157. throw new ArgumentOutOfRangeException ();
  158. updateBatchSize = value;
  159. }
  160. }
  161. #endif
  162. #endregion // Properties
  163. #region Methods
  164. protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
  165. {
  166. return new SqlRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
  167. }
  168. protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
  169. {
  170. return new SqlRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
  171. }
  172. #if !NET_2_0
  173. protected override void Dispose (bool disposing)
  174. {
  175. if (!disposed) {
  176. if (disposing) {
  177. // Release managed resources
  178. }
  179. // Release unmanaged resources
  180. disposed = true;
  181. }
  182. }
  183. #endif
  184. protected override void OnRowUpdated (RowUpdatedEventArgs value)
  185. {
  186. if (RowUpdated != null)
  187. RowUpdated (this, (SqlRowUpdatedEventArgs) value);
  188. }
  189. protected override void OnRowUpdating (RowUpdatingEventArgs value)
  190. {
  191. if (RowUpdating != null)
  192. RowUpdating (this, (SqlRowUpdatingEventArgs) value);
  193. }
  194. [MonoTODO]
  195. object ICloneable.Clone()
  196. {
  197. throw new NotImplementedException ();
  198. }
  199. #if NET_2_0
  200. // All the batch methods, should be implemented, if supported,
  201. // by individual providers
  202. [MonoTODO]
  203. protected override int AddToBatch (IDbCommand cmd)
  204. {
  205. throw new NotImplementedException ();
  206. }
  207. [MonoTODO]
  208. protected override void ClearBatch ()
  209. {
  210. throw new NotImplementedException ();
  211. }
  212. [MonoTODO]
  213. protected override int ExecuteBatch ()
  214. {
  215. throw new NotImplementedException ();
  216. }
  217. [MonoTODO]
  218. protected override IDataParameter GetBatchedParameter (int commandIdentifier, int parameterIdentifer)
  219. {
  220. throw new NotImplementedException ();
  221. }
  222. [MonoTODO]
  223. protected override void InitializeBatching ()
  224. {
  225. throw new NotImplementedException ();
  226. }
  227. [MonoTODO]
  228. protected override void TerminateBatching ()
  229. {
  230. throw new NotImplementedException ();
  231. }
  232. #endif
  233. #endregion // Methods
  234. #region Events and Delegates
  235. #if ONLY_1_1
  236. [DataSysDescription ("Event triggered before every DataRow during Update.")]
  237. #endif
  238. public event SqlRowUpdatedEventHandler RowUpdated;
  239. #if ONLY_1_1
  240. [DataSysDescription ("Event triggered after every DataRow during Update.")]
  241. #endif
  242. public event SqlRowUpdatingEventHandler RowUpdating;
  243. #endregion // Events and Delegates
  244. }
  245. }