OdbcDataAdapter.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. //
  2. // System.Data.Odbc.OdbcDataAdapter.cs
  3. //
  4. // Author:
  5. // Rodrigo Moya ([email protected])
  6. // Daniel Morgan ([email protected])
  7. // Tim Coleman ([email protected])
  8. //
  9. // (C) Ximian, Inc 2002
  10. // Copyright (C) 2002 Tim Coleman
  11. //
  12. //
  13. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  14. //
  15. // Permission is hereby granted, free of charge, to any person obtaining
  16. // a copy of this software and associated documentation files (the
  17. // "Software"), to deal in the Software without restriction, including
  18. // without limitation the rights to use, copy, modify, merge, publish,
  19. // distribute, sublicense, and/or sell copies of the Software, and to
  20. // permit persons to whom the Software is furnished to do so, subject to
  21. // the following conditions:
  22. //
  23. // The above copyright notice and this permission notice shall be
  24. // included in all copies or substantial portions of the Software.
  25. //
  26. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  27. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  29. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  30. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  31. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  32. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  33. //
  34. using System;
  35. using System.ComponentModel;
  36. using System.Data;
  37. using System.Data.Common;
  38. namespace System.Data.Odbc {
  39. [DefaultEvent ("RowUpdated")]
  40. [DesignerAttribute ("Microsoft.VSDesigner.Data.VS.OdbcDataAdapterDesigner, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.IDesigner")]
  41. [ToolboxItemAttribute ("Microsoft.VSDesigner.Data.VS.OdbcDataAdapterToolboxItem, "+ Consts.AssemblyMicrosoft_VSDesigner)]
  42. public sealed class OdbcDataAdapter : DbDataAdapter, IDbDataAdapter, ICloneable
  43. {
  44. #region Fields
  45. #if ONLY_1_1
  46. bool disposed = false;
  47. #endif
  48. OdbcCommand deleteCommand;
  49. OdbcCommand insertCommand;
  50. OdbcCommand selectCommand;
  51. OdbcCommand updateCommand;
  52. #endregion
  53. #region Constructors
  54. public OdbcDataAdapter () : this (new OdbcCommand ())
  55. {
  56. }
  57. public OdbcDataAdapter (OdbcCommand selectCommand)
  58. {
  59. DeleteCommand = null;
  60. InsertCommand = null;
  61. SelectCommand = selectCommand;
  62. UpdateCommand = null;
  63. }
  64. public OdbcDataAdapter (string selectCommandText, OdbcConnection selectConnection)
  65. : this (new OdbcCommand (selectCommandText, selectConnection))
  66. {
  67. }
  68. public OdbcDataAdapter (string selectCommandText, string selectConnectionString)
  69. : this (selectCommandText, new OdbcConnection (selectConnectionString))
  70. {
  71. }
  72. #endregion
  73. #region Properties
  74. [OdbcCategory ("Update")]
  75. [OdbcDescription ("Used during Update for deleted rows in DataSet.")]
  76. [DefaultValue (null)]
  77. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  78. public new OdbcCommand DeleteCommand {
  79. get { return deleteCommand; }
  80. set { deleteCommand = value; }
  81. }
  82. [OdbcCategory ("Update")]
  83. [OdbcDescription ("Used during Update for new rows in DataSet.")]
  84. [DefaultValue (null)]
  85. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  86. public new OdbcCommand InsertCommand {
  87. get { return insertCommand; }
  88. set { insertCommand = value; }
  89. }
  90. [OdbcCategory ("Fill")]
  91. [OdbcDescription ("Used during Fill/FillSchema.")]
  92. [DefaultValue (null)]
  93. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  94. public new OdbcCommand SelectCommand {
  95. get { return selectCommand; }
  96. set { selectCommand = value; }
  97. }
  98. [OdbcCategory ("Update")]
  99. [OdbcDescription ("Used during Update for modified rows in DataSet.")]
  100. [DefaultValue (null)]
  101. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  102. public new OdbcCommand UpdateCommand {
  103. get { return updateCommand; }
  104. set { updateCommand = value; }
  105. }
  106. IDbCommand IDbDataAdapter.DeleteCommand {
  107. get { return DeleteCommand; }
  108. set {
  109. if (!(value is OdbcCommand))
  110. throw new ArgumentException ();
  111. DeleteCommand = (OdbcCommand)value;
  112. }
  113. }
  114. IDbCommand IDbDataAdapter.InsertCommand {
  115. get { return InsertCommand; }
  116. set {
  117. if (!(value is OdbcCommand))
  118. throw new ArgumentException ();
  119. InsertCommand = (OdbcCommand)value;
  120. }
  121. }
  122. IDbCommand IDbDataAdapter.SelectCommand {
  123. get { return SelectCommand; }
  124. set {
  125. if (!(value is OdbcCommand))
  126. throw new ArgumentException ();
  127. SelectCommand = (OdbcCommand)value;
  128. }
  129. }
  130. IDbCommand IDbDataAdapter.UpdateCommand {
  131. get { return UpdateCommand; }
  132. set {
  133. if (!(value is OdbcCommand))
  134. throw new ArgumentException ();
  135. UpdateCommand = (OdbcCommand)value;
  136. }
  137. }
  138. ITableMappingCollection IDataAdapter.TableMappings {
  139. get { return TableMappings; }
  140. }
  141. #endregion // Properties
  142. #region Methods
  143. protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
  144. {
  145. return new OdbcRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
  146. }
  147. protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
  148. {
  149. return new OdbcRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
  150. }
  151. #if ONLY_1_1
  152. protected override void Dispose (bool disposing)
  153. {
  154. if (!disposed) {
  155. if (disposing) {
  156. // Release managed resources
  157. }
  158. // Release unmanaged resources
  159. disposed = true;
  160. }
  161. }
  162. #endif
  163. protected override void OnRowUpdated (RowUpdatedEventArgs value)
  164. {
  165. if (RowUpdated != null)
  166. RowUpdated (this, (OdbcRowUpdatedEventArgs) value);
  167. }
  168. protected override void OnRowUpdating (RowUpdatingEventArgs value)
  169. {
  170. if (RowUpdating != null)
  171. RowUpdating (this, (OdbcRowUpdatingEventArgs) value);
  172. }
  173. [MonoTODO]
  174. object ICloneable.Clone ()
  175. {
  176. throw new NotImplementedException ();
  177. }
  178. #endregion // Methods
  179. #region Events and Delegates
  180. public event OdbcRowUpdatedEventHandler RowUpdated;
  181. public event OdbcRowUpdatingEventHandler RowUpdating;
  182. #endregion // Events and Delegates
  183. }
  184. }