SqlSharpDataAdapter.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. //
  2. // SqlSharpDataAdapter.cs - data adapter for SQL#
  3. // but uses a data reader
  4. // as the source of data
  5. //
  6. // based on
  7. // System.Data.SqlSharpClient.SqlSharpDataAdapter.cs
  8. // in Mono http://www.go-mono.com/
  9. //
  10. // Author:
  11. // Rodrigo Moya ([email protected])
  12. // Daniel Morgan ([email protected])
  13. // Tim Coleman ([email protected])
  14. //
  15. // (C) Ximian, Inc 2002
  16. // Copyright (C) 2002 Tim Coleman
  17. // Copyright (C) 2002, 2003 Daniel Morgan
  18. //
  19. using System;
  20. using System.ComponentModel;
  21. using System.Data;
  22. using System.Data.Common;
  23. namespace Mono.Data.SqlSharp
  24. {
  25. [DefaultEvent ("RowUpdated")]
  26. public sealed class SqlSharpDataAdapter : DbDataAdapter, IDbDataAdapter
  27. {
  28. #region Fields
  29. bool disposed = false;
  30. IDbCommand deleteCommand;
  31. IDbCommand insertCommand;
  32. IDbCommand selectCommand;
  33. IDbCommand updateCommand;
  34. #endregion
  35. #region Constructors
  36. public SqlSharpDataAdapter ()
  37. {
  38. }
  39. public SqlSharpDataAdapter (IDbCommand selectCommand)
  40. {
  41. DeleteCommand = null;
  42. InsertCommand = null;
  43. SelectCommand = selectCommand;
  44. UpdateCommand = null;
  45. }
  46. #endregion
  47. #region Properties
  48. // [DataCategory ("Update")]
  49. [DataSysDescription ("Used during Update for deleted rows in DataSet.")]
  50. [DefaultValue (null)]
  51. public IDbCommand DeleteCommand {
  52. get { return deleteCommand; }
  53. set { deleteCommand = value; }
  54. }
  55. // [DataCategory ("Update")]
  56. [DataSysDescription ("Used during Update for new rows in DataSet.")]
  57. [DefaultValue (null)]
  58. public IDbCommand InsertCommand {
  59. get { return insertCommand; }
  60. set { insertCommand = value; }
  61. }
  62. // [DataCategory ("Fill")]
  63. [DataSysDescription ("Used during Fill/FillSchema.")]
  64. [DefaultValue (null)]
  65. public IDbCommand SelectCommand {
  66. get { return selectCommand; }
  67. set { selectCommand = value; }
  68. }
  69. // [DataCategory ("Update")]
  70. [DataSysDescription ("Used during Update for modified rows in DataSet.")]
  71. [DefaultValue (null)]
  72. public IDbCommand UpdateCommand {
  73. get { return updateCommand; }
  74. set { updateCommand = value; }
  75. }
  76. IDbCommand IDbDataAdapter.DeleteCommand {
  77. get { return DeleteCommand; }
  78. set {
  79. DeleteCommand = value;
  80. }
  81. }
  82. IDbCommand IDbDataAdapter.InsertCommand {
  83. get { return InsertCommand; }
  84. set {
  85. InsertCommand = value;
  86. }
  87. }
  88. IDbCommand IDbDataAdapter.SelectCommand {
  89. get { return SelectCommand; }
  90. set {
  91. SelectCommand = value;
  92. }
  93. }
  94. IDbCommand IDbDataAdapter.UpdateCommand {
  95. get { return UpdateCommand; }
  96. set {
  97. UpdateCommand = value;
  98. }
  99. }
  100. ITableMappingCollection IDataAdapter.TableMappings {
  101. get { return TableMappings; }
  102. }
  103. #endregion // Properties
  104. #region Methods
  105. protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
  106. {
  107. return new SqlSharpRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
  108. }
  109. protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
  110. {
  111. return new SqlSharpRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
  112. }
  113. protected override void Dispose (bool disposing)
  114. {
  115. if (!disposed) {
  116. if (disposing) {
  117. // Release managed resources
  118. }
  119. // Release unmanaged resources
  120. disposed = true;
  121. }
  122. }
  123. protected override void OnRowUpdated (RowUpdatedEventArgs value)
  124. {
  125. if (RowUpdated != null)
  126. RowUpdated (this, (SqlSharpRowUpdatedEventArgs) value);
  127. }
  128. protected override void OnRowUpdating (RowUpdatingEventArgs value)
  129. {
  130. if (RowUpdating != null)
  131. RowUpdating (this, (SqlSharpRowUpdatingEventArgs) value);
  132. }
  133. public int FillTable (DataTable dataTable, IDataReader dataReader)
  134. {
  135. return base.Fill (dataTable, dataReader);
  136. }
  137. #endregion // Methods
  138. #region Events and Delegates
  139. // [DataCategory ("Update")]
  140. [DataSysDescription ("Event triggered before every DataRow during Update.")]
  141. public event SqlSharpRowUpdatedEventHandler RowUpdated;
  142. // [DataCategory ("Update")]
  143. [DataSysDescription ("Event triggered after every DataRow during Update.")]
  144. public event SqlSharpRowUpdatingEventHandler RowUpdating;
  145. #endregion // Events and Delegates
  146. }
  147. public sealed class SqlSharpRowUpdatedEventArgs : RowUpdatedEventArgs {
  148. #region Constructors
  149. public SqlSharpRowUpdatedEventArgs (DataRow row, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
  150. : base (row, command, statementType, tableMapping) {
  151. }
  152. #endregion // Constructors
  153. #region Properties
  154. public new IDbCommand Command {
  155. get { return base.Command; }
  156. }
  157. #endregion // Properties
  158. }
  159. public delegate void SqlSharpRowUpdatedEventHandler (object sender, SqlSharpRowUpdatedEventArgs e);
  160. public sealed class SqlSharpRowUpdatingEventArgs : RowUpdatingEventArgs {
  161. #region Constructors
  162. public SqlSharpRowUpdatingEventArgs (DataRow row, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
  163. : base (row, command, statementType, tableMapping) {
  164. }
  165. #endregion // Constructors
  166. #region Properties
  167. public new IDbCommand Command {
  168. get { return base.Command; }
  169. set { base.Command = value; }
  170. }
  171. #endregion // Properties
  172. }
  173. public delegate void SqlSharpRowUpdatingEventHandler(object sender, SqlSharpRowUpdatingEventArgs e);
  174. }