1 /********************************************************
\r
2 * ADO.NET 2.0 Data Provider for SQLite Version 3.X
\r
3 * Written by Robert Simpson (robert@blackcastlesoft.com)
\r
5 * Released to the public domain, use at your own risk!
\r
6 ********************************************************/
\r
8 namespace Mono.Data.Sqlite
\r
12 using System.Data.Common;
\r
13 using System.ComponentModel;
\r
16 /// SQLite implementation of DbDataAdapter.
\r
18 #if !PLATFORM_COMPACTFRAMEWORK
\r
19 [DefaultEvent("RowUpdated")]
\r
20 [ToolboxItem("SQLite.Designer.SqliteDataAdapterToolboxItem, SQLite.Designer, Version=1.0.36.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139")]
\r
21 [Designer("Microsoft.VSDesigner.Data.VS.SqlDataAdapterDesigner, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
\r
23 public sealed class SqliteDataAdapter : DbDataAdapter
\r
25 private static object _updatingEventPH = new object();
\r
26 private static object _updatedEventPH = new object();
\r
29 /// This class is just a shell around the DbDataAdapter. Nothing from DbDataAdapter is overridden here, just a few constructors are defined.
\r
32 /// Default constructor.
\r
34 public SqliteDataAdapter()
\r
39 /// Constructs a data adapter using the specified select command.
\r
41 /// <param name="cmd">The select command to associate with the adapter.</param>
\r
42 public SqliteDataAdapter(SqliteCommand cmd)
\r
44 SelectCommand = cmd;
\r
48 /// Constructs a data adapter with the supplied select command text and associated with the specified connection.
\r
50 /// <param name="commandText">The select command text to associate with the data adapter.</param>
\r
51 /// <param name="connection">The connection to associate with the select command.</param>
\r
52 public SqliteDataAdapter(string commandText, SqliteConnection connection)
\r
54 SelectCommand = new SqliteCommand(commandText, connection);
\r
58 /// Constructs a data adapter with the specified select command text, and using the specified database connection string.
\r
60 /// <param name="commandText">The select command text to use to construct a select command.</param>
\r
61 /// <param name="connectionString">A connection string suitable for passing to a new SqliteConnection, which is associated with the select command.</param>
\r
62 public SqliteDataAdapter(string commandText, string connectionString)
\r
64 SqliteConnection cnn = new SqliteConnection(connectionString);
\r
65 SelectCommand = new SqliteCommand(commandText, cnn);
\r
69 /// Row updating event handler
\r
71 public event EventHandler<RowUpdatingEventArgs> RowUpdating
\r
75 #if !PLATFORM_COMPACTFRAMEWORK
\r
76 EventHandler<RowUpdatingEventArgs> previous = (EventHandler<RowUpdatingEventArgs>)base.Events[_updatingEventPH];
\r
77 if ((previous != null) && (value.Target is DbCommandBuilder))
\r
79 EventHandler<RowUpdatingEventArgs> handler = (EventHandler<RowUpdatingEventArgs>)FindBuilder(previous);
\r
80 if (handler != null)
\r
82 base.Events.RemoveHandler(_updatingEventPH, handler);
\r
86 base.Events.AddHandler(_updatingEventPH, value);
\r
88 remove { base.Events.RemoveHandler(_updatingEventPH, value); }
\r
91 #if !PLATFORM_COMPACTFRAMEWORK
\r
92 internal static Delegate FindBuilder(MulticastDelegate mcd)
\r
96 Delegate[] invocationList = mcd.GetInvocationList();
\r
97 for (int i = 0; i < invocationList.Length; i++)
\r
99 if (invocationList[i].Target is DbCommandBuilder)
\r
101 return invocationList[i];
\r
110 /// Row updated event handler
\r
112 public event EventHandler<RowUpdatedEventArgs> RowUpdated
\r
114 add { base.Events.AddHandler(_updatedEventPH, value); }
\r
115 remove { base.Events.RemoveHandler(_updatedEventPH, value); }
\r
119 /// Raised by the underlying DbDataAdapter when a row is being updated
\r
121 /// <param name="value">The event's specifics</param>
\r
122 protected override void OnRowUpdating(RowUpdatingEventArgs value)
\r
124 EventHandler<RowUpdatingEventArgs> handler = base.Events[_updatingEventPH] as EventHandler<RowUpdatingEventArgs>;
\r
126 if (handler != null)
\r
127 handler(this, value);
\r
131 /// Raised by DbDataAdapter after a row is updated
\r
133 /// <param name="value">The event's specifics</param>
\r
134 protected override void OnRowUpdated(RowUpdatedEventArgs value)
\r
136 EventHandler<RowUpdatedEventArgs> handler = base.Events[_updatedEventPH] as EventHandler<RowUpdatedEventArgs>;
\r
138 if (handler != null)
\r
139 handler(this, value);
\r
143 /// Gets/sets the select command for this DataAdapter
\r
145 #if !PLATFORM_COMPACTFRAMEWORK
\r
146 [DefaultValue((string)null), Editor("Microsoft.VSDesigner.Data.Design.DBCommandEditor, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
\r
148 public new SqliteCommand SelectCommand
\r
150 get { return (SqliteCommand)base.SelectCommand; }
\r
151 set { base.SelectCommand = value; }
\r
155 /// Gets/sets the insert command for this DataAdapter
\r
157 #if !PLATFORM_COMPACTFRAMEWORK
\r
158 [DefaultValue((string)null), Editor("Microsoft.VSDesigner.Data.Design.DBCommandEditor, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
\r
160 public new SqliteCommand InsertCommand
\r
162 get { return (SqliteCommand)base.InsertCommand; }
\r
163 set { base.InsertCommand = value; }
\r
167 /// Gets/sets the update command for this DataAdapter
\r
169 #if !PLATFORM_COMPACTFRAMEWORK
\r
170 [DefaultValue((string)null), Editor("Microsoft.VSDesigner.Data.Design.DBCommandEditor, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
\r
172 public new SqliteCommand UpdateCommand
\r
174 get { return (SqliteCommand)base.UpdateCommand; }
\r
175 set { base.UpdateCommand = value; }
\r
179 /// Gets/sets the delete command for this DataAdapter
\r
181 #if !PLATFORM_COMPACTFRAMEWORK
\r
182 [DefaultValue((string)null), Editor("Microsoft.VSDesigner.Data.Design.DBCommandEditor, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
\r
184 public new SqliteCommand DeleteCommand
\r
186 get { return (SqliteCommand)base.DeleteCommand; }
\r
187 set { base.DeleteCommand = value; }
\r