SqlDataAdapter.cs 8.2 KB

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