DataAdapter.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. //
  2. // System.Data.Common.DataAdapter
  3. //
  4. // Author:
  5. // Rodrigo Moya ([email protected])
  6. // Tim Coleman ([email protected])
  7. //
  8. // (C) Ximian, Inc
  9. // Copyright (C) Tim Coleman, 2002-2003
  10. //
  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.ComponentModel;
  34. using System.Data;
  35. namespace System.Data.Common
  36. {
  37. /// <summary>
  38. /// Represents a set of data commands and a database connection that are used to fill the DataSet and update the data source.
  39. /// </summary>
  40. public
  41. #if !NET_2_0
  42. abstract
  43. #endif
  44. class DataAdapter : Component, IDataAdapter
  45. {
  46. #region Fields
  47. private bool acceptChangesDuringFill;
  48. private bool continueUpdateOnError;
  49. private MissingMappingAction missingMappingAction;
  50. private MissingSchemaAction missingSchemaAction;
  51. private DataTableMappingCollection tableMappings;
  52. #if NET_2_0
  53. private bool acceptChangesDuringUpdate;
  54. private LoadOption fillLoadOption;
  55. private bool returnProviderSpecificTypes;
  56. #endif
  57. #endregion
  58. #region Constructors
  59. protected DataAdapter ()
  60. {
  61. acceptChangesDuringFill = true;
  62. continueUpdateOnError = false;
  63. missingMappingAction = MissingMappingAction.Passthrough;
  64. missingSchemaAction = MissingSchemaAction.Add;
  65. tableMappings = new DataTableMappingCollection ();
  66. }
  67. protected DataAdapter (DataAdapter adapter)
  68. {
  69. AcceptChangesDuringFill = adapter.AcceptChangesDuringFill;
  70. ContinueUpdateOnError = adapter.ContinueUpdateOnError;
  71. MissingMappingAction = adapter.MissingMappingAction;
  72. MissingSchemaAction = adapter.MissingSchemaAction;
  73. if (adapter.tableMappings == null || adapter.TableMappings.Count <= 0) {
  74. return;
  75. }
  76. foreach (ICloneable cloneable in adapter.TableMappings) {
  77. TableMappings.Add (cloneable.Clone ());
  78. }
  79. }
  80. #endregion
  81. #region Properties
  82. [DataCategory ("Fill")]
  83. #if !NET_2_0
  84. [DataSysDescription ("Whether or not Fill will call DataRow.AcceptChanges.")]
  85. #endif
  86. [DefaultValue (true)]
  87. public bool AcceptChangesDuringFill {
  88. get { return acceptChangesDuringFill; }
  89. set { acceptChangesDuringFill = value; }
  90. }
  91. #if NET_2_0
  92. [DefaultValue (true)]
  93. public bool AcceptChangesDuringUpdate {
  94. get { return acceptChangesDuringUpdate; }
  95. set { acceptChangesDuringUpdate = value; }
  96. }
  97. #endif
  98. [DataCategory ("Update")]
  99. #if !NET_2_0
  100. [DataSysDescription ("Whether or not to continue to the next DataRow when the Update events, RowUpdating and RowUpdated, Status is UpdateStatus.ErrorsOccurred.")]
  101. #endif
  102. [DefaultValue (false)]
  103. public bool ContinueUpdateOnError {
  104. get { return continueUpdateOnError; }
  105. set { continueUpdateOnError = value; }
  106. }
  107. #if NET_2_0
  108. [RefreshProperties (RefreshProperties.All)]
  109. public LoadOption FillLoadOption {
  110. get { return fillLoadOption; }
  111. set { fillLoadOption = value; }
  112. }
  113. #endif
  114. ITableMappingCollection IDataAdapter.TableMappings {
  115. get { return TableMappings; }
  116. }
  117. [DataCategory ("Mapping")]
  118. #if !NET_2_0
  119. [DataSysDescription ("The action taken when a table or column in the TableMappings is missing.")]
  120. #endif
  121. [DefaultValue (MissingMappingAction.Passthrough)]
  122. public MissingMappingAction MissingMappingAction {
  123. get { return missingMappingAction; }
  124. set {
  125. if (!Enum.IsDefined (typeof (MissingMappingAction), value))
  126. throw ExceptionHelper.InvalidEnumValueException ("MissingMappingAction", value);
  127. missingMappingAction = value;
  128. }
  129. }
  130. [DataCategory ("Mapping")]
  131. #if !NET_2_0
  132. [DataSysDescription ("The action taken when a table or column in the DataSet is missing.")]
  133. #endif
  134. [DefaultValue (MissingSchemaAction.Add)]
  135. public MissingSchemaAction MissingSchemaAction {
  136. get { return missingSchemaAction; }
  137. set {
  138. if (!Enum.IsDefined (typeof (MissingSchemaAction), value))
  139. throw ExceptionHelper.InvalidEnumValueException ("MissingSchemaAction", value);
  140. missingSchemaAction = value;
  141. }
  142. }
  143. #if NET_2_0
  144. [DefaultValue (false)]
  145. public virtual bool ReturnProviderSpecificTypes {
  146. get { return returnProviderSpecificTypes; }
  147. set { returnProviderSpecificTypes = value; }
  148. }
  149. #endif
  150. [DataCategory ("Mapping")]
  151. #if !NET_2_0
  152. [DataSysDescription ("How to map source table to DataSet table.")]
  153. #endif
  154. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  155. public DataTableMappingCollection TableMappings {
  156. get { return tableMappings; }
  157. }
  158. #endregion
  159. #region Events
  160. #if NET_2_0
  161. public event FillErrorEventHandler FillError;
  162. #endif
  163. #endregion
  164. #region Methods
  165. #if NET_1_1
  166. [Obsolete ("Use the protected constructor instead", false)]
  167. #endif
  168. [MonoTODO]
  169. protected virtual DataAdapter CloneInternals ()
  170. {
  171. throw new NotImplementedException ();
  172. }
  173. protected virtual DataTableMappingCollection CreateTableMappings ()
  174. {
  175. tableMappings = new DataTableMappingCollection ();
  176. return tableMappings;
  177. }
  178. [MonoTODO]
  179. protected override void Dispose (bool disposing)
  180. {
  181. throw new NotImplementedException ();
  182. }
  183. [MonoTODO]
  184. protected virtual bool ShouldSerializeTableMappings ()
  185. {
  186. throw new NotImplementedException ();
  187. }
  188. #if NET_2_0
  189. [MonoTODO]
  190. public virtual int Fill (DataSet dataSet)
  191. {
  192. throw new NotImplementedException ();
  193. }
  194. [MonoTODO]
  195. protected virtual int Fill (DataTable dataTable, IDataReader dataReader)
  196. {
  197. throw new NotImplementedException ();
  198. }
  199. [MonoTODO]
  200. protected virtual int Fill (DataTable[] dataTables, IDataReader dataReader, int startRecord, int maxRecords)
  201. {
  202. throw new NotImplementedException ();
  203. }
  204. [MonoTODO]
  205. protected virtual int Fill (DataSet dataSet, string srcTable, IDataReader dataReader, int startRecord, int maxRecords)
  206. {
  207. throw new NotImplementedException ();
  208. }
  209. [MonoTODO]
  210. protected virtual DataTable FillSchema (DataTable dataTable, SchemaType schemaType, IDataReader dataReader)
  211. {
  212. throw new NotImplementedException ();
  213. }
  214. [MonoTODO]
  215. protected virtual DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType, string srcTable, IDataReader dataReader)
  216. {
  217. throw new NotImplementedException ();
  218. }
  219. [MonoTODO]
  220. public virtual DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType)
  221. {
  222. throw new NotImplementedException ();
  223. }
  224. [MonoTODO]
  225. [EditorBrowsable (EditorBrowsableState.Advanced)]
  226. public virtual IDataParameter[] GetFillParameters ()
  227. {
  228. throw new NotImplementedException ();
  229. }
  230. [MonoTODO]
  231. protected bool HasTableMappings ()
  232. {
  233. throw new NotImplementedException ();
  234. }
  235. protected virtual void OnFillError (FillErrorEventArgs value)
  236. {
  237. if (FillError != null)
  238. FillError (this, value);
  239. }
  240. [MonoTODO]
  241. [EditorBrowsable (EditorBrowsableState.Never)]
  242. public void ResetFillLoadOption ()
  243. {
  244. throw new NotImplementedException ();
  245. }
  246. [MonoTODO]
  247. [EditorBrowsable (EditorBrowsableState.Never)]
  248. public virtual bool ShouldSerializeAcceptChangesDuringFill ()
  249. {
  250. throw new NotImplementedException ();
  251. }
  252. [MonoTODO]
  253. [EditorBrowsable (EditorBrowsableState.Never)]
  254. public virtual bool ShouldSerializeFillLoadOption ()
  255. {
  256. throw new NotImplementedException ();
  257. }
  258. [MonoTODO]
  259. public virtual int Update (DataSet dataSet)
  260. {
  261. throw new NotImplementedException ();
  262. }
  263. #else
  264. public abstract int Fill (DataSet dataSet);
  265. public abstract DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType);
  266. public abstract IDataParameter[] GetFillParameters ();
  267. public abstract int Update (DataSet dataSet);
  268. #endif
  269. #endregion
  270. }
  271. }