DataAdapter.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. using System.ComponentModel;
  12. using System.Data;
  13. namespace System.Data.Common
  14. {
  15. /// <summary>
  16. /// Represents a set of data commands and a database connection that are used to fill the DataSet and update the data source.
  17. /// </summary>
  18. public abstract class DataAdapter : Component, IDataAdapter
  19. {
  20. #region Fields
  21. private bool acceptChangesDuringFill;
  22. private bool continueUpdateOnError;
  23. private MissingMappingAction missingMappingAction;
  24. private MissingSchemaAction missingSchemaAction;
  25. private DataTableMappingCollection tableMappings;
  26. #if NET_2_0
  27. private bool acceptChangesDuringUpdate;
  28. private LoadOption fillLoadOption;
  29. private bool returnProviderSpecificTypes;
  30. #endif
  31. #endregion
  32. #region Constructors
  33. protected DataAdapter ()
  34. {
  35. acceptChangesDuringFill = true;
  36. continueUpdateOnError = false;
  37. missingMappingAction = MissingMappingAction.Passthrough;
  38. missingSchemaAction = MissingSchemaAction.Add;
  39. tableMappings = new DataTableMappingCollection ();
  40. }
  41. protected DataAdapter (DataAdapter adapter)
  42. {
  43. AcceptChangesDuringFill = adapter.AcceptChangesDuringFill;
  44. ContinueUpdateOnError = adapter.ContinueUpdateOnError;
  45. MissingMappingAction = adapter.MissingMappingAction;
  46. MissingSchemaAction = adapter.MissingSchemaAction;
  47. if (adapter.tableMappings == null || adapter.TableMappings.Count <= 0) {
  48. return;
  49. }
  50. foreach (ICloneable cloneable in adapter.TableMappings) {
  51. TableMappings.Add (cloneable.Clone ());
  52. }
  53. }
  54. #endregion
  55. #region Properties
  56. [DataCategory ("Fill")]
  57. [DataSysDescription ("Whether or not Fill will call DataRow.AcceptChanges.")]
  58. [DefaultValue (true)]
  59. public bool AcceptChangesDuringFill {
  60. get { return acceptChangesDuringFill; }
  61. set { acceptChangesDuringFill = value; }
  62. }
  63. #if NET_2_0
  64. public bool AcceptChangesDuringUpdate {
  65. get { return acceptChangesDuringUpdate; }
  66. set { acceptChangesDuringUpdate = value; }
  67. }
  68. #endif
  69. [DataCategory ("Update")]
  70. [DataSysDescription ("Whether or not to continue to the next DataRow when the Update events, RowUpdating and RowUpdated, Status is UpdateStatus.ErrorsOccurred.")]
  71. [DefaultValue (false)]
  72. public bool ContinueUpdateOnError {
  73. get { return continueUpdateOnError; }
  74. set { continueUpdateOnError = value; }
  75. }
  76. #if NET_2_0
  77. public LoadOption FillLoadOption {
  78. get { return fillLoadOption; }
  79. set { fillLoadOption = value; }
  80. }
  81. #endif
  82. ITableMappingCollection IDataAdapter.TableMappings {
  83. get { return TableMappings; }
  84. }
  85. [DataCategory ("Mapping")]
  86. [DataSysDescription ("The action taken when a table or column in the TableMappings is missing.")]
  87. [DefaultValue (MissingMappingAction.Passthrough)]
  88. public MissingMappingAction MissingMappingAction {
  89. get { return missingMappingAction; }
  90. set { missingMappingAction = value; }
  91. }
  92. [DataCategory ("Mapping")]
  93. [DataSysDescription ("The action taken when a table or column in the DataSet is missing.")]
  94. [DefaultValue (MissingSchemaAction.Add)]
  95. public MissingSchemaAction MissingSchemaAction {
  96. get { return missingSchemaAction; }
  97. set { missingSchemaAction = value; }
  98. }
  99. #if NET_2_0
  100. public virtual bool ReturnProviderSpecificTypes {
  101. get { return returnProviderSpecificTypes; }
  102. set { returnProviderSpecificTypes = value; }
  103. }
  104. #endif
  105. [DataCategory ("Mapping")]
  106. [DataSysDescription ("How to map source table to DataSet table.")]
  107. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  108. public DataTableMappingCollection TableMappings {
  109. get { return tableMappings; }
  110. }
  111. #endregion
  112. #region Events
  113. #if NET_2_0
  114. public event FillErrorEventHandler FillError;
  115. #endif
  116. #endregion
  117. #region Methods
  118. #if NET_1_1
  119. [Obsolete ("Use the protected constructor instead", false)]
  120. #endif
  121. [MonoTODO]
  122. protected virtual DataAdapter CloneInternals ()
  123. {
  124. throw new NotImplementedException ();
  125. }
  126. protected virtual DataTableMappingCollection CreateTableMappings ()
  127. {
  128. tableMappings = new DataTableMappingCollection ();
  129. return tableMappings;
  130. }
  131. [MonoTODO]
  132. protected override void Dispose (bool disposing)
  133. {
  134. throw new NotImplementedException ();
  135. }
  136. public abstract int Fill (DataSet dataSet);
  137. #if NET_2_0
  138. [MonoTODO]
  139. protected virtual int Fill (DataTable dataTable, IDataReader dataReader)
  140. {
  141. throw new NotImplementedException ();
  142. }
  143. [MonoTODO]
  144. protected virtual int Fill (DataTable[] dataTables, IDataReader dataReader, int startRecord, int maxRecords)
  145. {
  146. throw new NotImplementedException ();
  147. }
  148. [MonoTODO]
  149. protected virtual int Fill (DataSet dataSet, string srcTable, IDataReader dataReader, int startRecord, int maxRecords)
  150. {
  151. throw new NotImplementedException ();
  152. }
  153. [MonoTODO]
  154. public static int FillDataSet (IDataReader dataReader, LoadOption fillLoadOption, DataSet dataSet)
  155. {
  156. throw new NotImplementedException ();
  157. }
  158. [MonoTODO]
  159. public static int FillDataTable (IDataReader dataReader, LoadOption fillLoadOption, DataTable[] dataTables)
  160. {
  161. throw new NotImplementedException ();
  162. }
  163. #endif
  164. public abstract DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType);
  165. #if NET_2_0
  166. [MonoTODO]
  167. protected virtual DataTable FillSchema (DataTable dataTable, SchemaType schemaType, IDataReader dataReader)
  168. {
  169. throw new NotImplementedException ();
  170. }
  171. [MonoTODO]
  172. protected virtual DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType, string srcTable, IDataReader dataReader)
  173. {
  174. throw new NotImplementedException ();
  175. }
  176. #endif
  177. public abstract IDataParameter[] GetFillParameters ();
  178. #if NET_2_0
  179. [MonoTODO]
  180. protected bool HasTableMappings ()
  181. {
  182. throw new NotImplementedException ();
  183. }
  184. [MonoTODO]
  185. protected virtual void OnFillError (FillErrorEventArgs value)
  186. {
  187. throw new NotImplementedException ();
  188. }
  189. [MonoTODO]
  190. public void ResetFillLoadOption ()
  191. {
  192. throw new NotImplementedException ();
  193. }
  194. [MonoTODO]
  195. public virtual bool ShouldSerializeAcceptChangesDuringFill ()
  196. {
  197. throw new NotImplementedException ();
  198. }
  199. [MonoTODO]
  200. public virtual bool ShouldSerializeFillLoadOption ()
  201. {
  202. throw new NotImplementedException ();
  203. }
  204. #endif
  205. [MonoTODO]
  206. protected virtual bool ShouldSerializeTableMappings ()
  207. {
  208. throw new NotImplementedException ();
  209. }
  210. public abstract int Update (DataSet dataSet);
  211. #endregion
  212. }
  213. }