OdbcDataAdapter.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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
  43. {
  44. #region Fields
  45. bool disposed = false;
  46. OdbcCommand deleteCommand;
  47. OdbcCommand insertCommand;
  48. OdbcCommand selectCommand;
  49. OdbcCommand updateCommand;
  50. #endregion
  51. #region Constructors
  52. public OdbcDataAdapter ()
  53. : this (new OdbcCommand ())
  54. {
  55. }
  56. public OdbcDataAdapter (OdbcCommand selectCommand)
  57. {
  58. DeleteCommand = null;
  59. InsertCommand = null;
  60. SelectCommand = selectCommand;
  61. UpdateCommand = null;
  62. }
  63. public OdbcDataAdapter (string selectCommandText, OdbcConnection selectConnection)
  64. : this (new OdbcCommand (selectCommandText, selectConnection))
  65. {
  66. }
  67. public OdbcDataAdapter (string selectCommandText, string selectConnectionString)
  68. : this (selectCommandText, new OdbcConnection (selectConnectionString))
  69. {
  70. }
  71. #endregion
  72. #region Properties
  73. [OdbcCategory ("Update")]
  74. [OdbcDescription ("Used during Update for deleted rows in DataSet.")]
  75. [DefaultValue (null)]
  76. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  77. public OdbcCommand DeleteCommand {
  78. get { return deleteCommand; }
  79. set { deleteCommand = value; }
  80. }
  81. [OdbcCategory ("Update")]
  82. [OdbcDescription ("Used during Update for new rows in DataSet.")]
  83. [DefaultValue (null)]
  84. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  85. public OdbcCommand InsertCommand {
  86. get { return insertCommand; }
  87. set { insertCommand = value; }
  88. }
  89. [OdbcCategory ("Fill")]
  90. [OdbcDescription ("Used during Fill/FillSchema.")]
  91. [DefaultValue (null)]
  92. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  93. public OdbcCommand SelectCommand {
  94. get { return selectCommand; }
  95. set { selectCommand = value; }
  96. }
  97. [OdbcCategory ("Update")]
  98. [OdbcDescription ("Used during Update for modified rows in DataSet.")]
  99. [DefaultValue (null)]
  100. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  101. public OdbcCommand UpdateCommand {
  102. get { return updateCommand; }
  103. set { updateCommand = value; }
  104. }
  105. IDbCommand IDbDataAdapter.DeleteCommand {
  106. get { return DeleteCommand; }
  107. set {
  108. if (!(value is OdbcCommand))
  109. throw new ArgumentException ();
  110. DeleteCommand = (OdbcCommand)value;
  111. }
  112. }
  113. IDbCommand IDbDataAdapter.InsertCommand {
  114. get { return InsertCommand; }
  115. set {
  116. if (!(value is OdbcCommand))
  117. throw new ArgumentException ();
  118. InsertCommand = (OdbcCommand)value;
  119. }
  120. }
  121. IDbCommand IDbDataAdapter.SelectCommand {
  122. get { return SelectCommand; }
  123. set {
  124. if (!(value is OdbcCommand))
  125. throw new ArgumentException ();
  126. SelectCommand = (OdbcCommand)value;
  127. }
  128. }
  129. IDbCommand IDbDataAdapter.UpdateCommand {
  130. get { return UpdateCommand; }
  131. set {
  132. if (!(value is OdbcCommand))
  133. throw new ArgumentException ();
  134. UpdateCommand = (OdbcCommand)value;
  135. }
  136. }
  137. ITableMappingCollection IDataAdapter.TableMappings {
  138. get { return TableMappings; }
  139. }
  140. #endregion // Properties
  141. #region Methods
  142. protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
  143. {
  144. return new OdbcRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
  145. }
  146. protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
  147. {
  148. return new OdbcRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
  149. }
  150. protected override void Dispose (bool disposing)
  151. {
  152. if (!disposed) {
  153. if (disposing) {
  154. // Release managed resources
  155. }
  156. // Release unmanaged resources
  157. disposed = true;
  158. }
  159. }
  160. protected override void OnRowUpdated (RowUpdatedEventArgs value)
  161. {
  162. if (RowUpdated != null)
  163. RowUpdated (this, (OdbcRowUpdatedEventArgs) value);
  164. }
  165. protected override void OnRowUpdating (RowUpdatingEventArgs value)
  166. {
  167. if (RowUpdating != null)
  168. RowUpdating (this, (OdbcRowUpdatingEventArgs) value);
  169. }
  170. #endregion // Methods
  171. #region Events and Delegates
  172. public event OdbcRowUpdatedEventHandler RowUpdated;
  173. public event OdbcRowUpdatingEventHandler RowUpdating;
  174. #endregion // Events and Delegates
  175. }
  176. }