DataAdapter.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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 { missingMappingAction = value; }
  113. }
  114. [DataCategory ("Mapping")]
  115. [DataSysDescription ("The action taken when a table or column in the DataSet is missing.")]
  116. [DefaultValue (MissingSchemaAction.Add)]
  117. public MissingSchemaAction MissingSchemaAction {
  118. get { return missingSchemaAction; }
  119. set { missingSchemaAction = value; }
  120. }
  121. #if NET_2_0
  122. public virtual bool ReturnProviderSpecificTypes {
  123. get { return returnProviderSpecificTypes; }
  124. set { returnProviderSpecificTypes = value; }
  125. }
  126. #endif
  127. [DataCategory ("Mapping")]
  128. [DataSysDescription ("How to map source table to DataSet table.")]
  129. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  130. public DataTableMappingCollection TableMappings {
  131. get { return tableMappings; }
  132. }
  133. #endregion
  134. #region Events
  135. #if NET_2_0
  136. public event FillErrorEventHandler FillError;
  137. #endif
  138. #endregion
  139. #region Methods
  140. #if NET_1_1
  141. [Obsolete ("Use the protected constructor instead", false)]
  142. #endif
  143. [MonoTODO]
  144. protected virtual DataAdapter CloneInternals ()
  145. {
  146. throw new NotImplementedException ();
  147. }
  148. protected virtual DataTableMappingCollection CreateTableMappings ()
  149. {
  150. tableMappings = new DataTableMappingCollection ();
  151. return tableMappings;
  152. }
  153. [MonoTODO]
  154. protected override void Dispose (bool disposing)
  155. {
  156. throw new NotImplementedException ();
  157. }
  158. public abstract int Fill (DataSet dataSet);
  159. #if NET_2_0
  160. [MonoTODO]
  161. protected virtual int Fill (DataTable dataTable, IDataReader dataReader)
  162. {
  163. throw new NotImplementedException ();
  164. }
  165. [MonoTODO]
  166. protected virtual int Fill (DataTable[] dataTables, IDataReader dataReader, int startRecord, int maxRecords)
  167. {
  168. throw new NotImplementedException ();
  169. }
  170. [MonoTODO]
  171. protected virtual int Fill (DataSet dataSet, string srcTable, IDataReader dataReader, int startRecord, int maxRecords)
  172. {
  173. throw new NotImplementedException ();
  174. }
  175. [MonoTODO]
  176. public static int FillDataSet (IDataReader dataReader, LoadOption fillLoadOption, DataSet dataSet)
  177. {
  178. throw new NotImplementedException ();
  179. }
  180. [MonoTODO]
  181. public static int FillDataTable (IDataReader dataReader, LoadOption fillLoadOption, DataTable[] dataTables)
  182. {
  183. throw new NotImplementedException ();
  184. }
  185. #endif
  186. public abstract DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType);
  187. #if NET_2_0
  188. [MonoTODO]
  189. protected virtual DataTable FillSchema (DataTable dataTable, SchemaType schemaType, IDataReader dataReader)
  190. {
  191. throw new NotImplementedException ();
  192. }
  193. [MonoTODO]
  194. protected virtual DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType, string srcTable, IDataReader dataReader)
  195. {
  196. throw new NotImplementedException ();
  197. }
  198. #endif
  199. public abstract IDataParameter[] GetFillParameters ();
  200. #if NET_2_0
  201. [MonoTODO]
  202. protected bool HasTableMappings ()
  203. {
  204. throw new NotImplementedException ();
  205. }
  206. [MonoTODO]
  207. protected virtual void OnFillError (FillErrorEventArgs value)
  208. {
  209. throw new NotImplementedException ();
  210. }
  211. [MonoTODO]
  212. public void ResetFillLoadOption ()
  213. {
  214. throw new NotImplementedException ();
  215. }
  216. [MonoTODO]
  217. public virtual bool ShouldSerializeAcceptChangesDuringFill ()
  218. {
  219. throw new NotImplementedException ();
  220. }
  221. [MonoTODO]
  222. public virtual bool ShouldSerializeFillLoadOption ()
  223. {
  224. throw new NotImplementedException ();
  225. }
  226. #endif
  227. [MonoTODO]
  228. protected virtual bool ShouldSerializeTableMappings ()
  229. {
  230. throw new NotImplementedException ();
  231. }
  232. public abstract int Update (DataSet dataSet);
  233. #endregion
  234. }
  235. }