DataAdapter.cs 8.5 KB

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