DataAdapter.cs 7.9 KB

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