SqlDataAdapter.cs 7.5 KB

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