Author: toshok
Date: 2006-02-22 14:14:04 -0500 (Wed, 22 Feb 2006)
New Revision: 57169
Modified:
trunk/mcs/class/System.Web/System.Web.UI.WebControls/AccessDataSource.cs
trunk/mcs/class/System.Web/System.Web.UI.WebControls/AccessDataSourceView.cs
trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSource.cs
trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSourceFilteringEventArgs.cs
trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSourceSelectingEventArgs.cs
trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSourceView.cs
Log:
2006-02-22 Chris Toshok <[EMAIL PROTECTED]>
* SqlDataSourceFilteringEventArgs.cs: formatting.
* SqlDataSourceSelectingEventArgs.cs: remove ExecutingSelectCount,
both the property and ctor arg.
* AccessDataSourceView.cs (ExecuteSelect): use SelectingEventArgs,
not CommandEventArgs. Also, cast the return value of
oleCommand.ExecuteReader.
* AccessDataSource.cs (.ctor): fix the ctors and remove FIXME
comments.
(GetDbProviderFactory): implement naively, and leave a MonoTODO.
(GetPhysicalDataFilePath): implement, again naively. this is
where the NRE is generated when we access ConnectionString in a
testcase on .net.
(ConnectionString): dynamically generate this based on our
DataFile attribute.
(DataFile): clear the ConnectionString in the setter so we'll
regenerate it.
(ProviderName): use base.ProviderName in the getter, not
this.ProviderName, so we don't recurse infinitely.
* SqlDataSourceView.cs: start reworking this class.
* SqlDataSource.cs (GetDbProviderFactory): implement this,
following the MS docs on the matter (if ProviderName is null/"",
return SqlClientFactory.Instance.)
(GetDbProviderFactoryInternal): add an internal method for use by
SqlDataSourceView.
(TrackViewState): don't invoke View.TrackViewState unless we have
one.
(Selecting): change event handler type to match MS.
(Filtering): add missing event.
(View): call CreateDataSourceView, don't just create an
SqlDataSourceView.
Modified:
trunk/mcs/class/System.Web/System.Web.UI.WebControls/AccessDataSource.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/AccessDataSource.cs
2006-02-22 19:11:17 UTC (rev 57168)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/AccessDataSource.cs
2006-02-22 19:14:04 UTC (rev 57169)
@@ -44,21 +44,22 @@
[ToolboxBitmap ("")]
public class AccessDataSource : SqlDataSource {
+ const string PROVIDER_NAME = "System.Data.OleDb";
+ const string PROVIDER_STRING = "Microsoft.Jet.OLEDB.4.0";
+
string dataFile;
-
+ string connectionString;
+
public AccessDataSource () : base ()
{
- this.ProviderName = "System.Data.OleDb";
+ base.ProviderName = PROVIDER_NAME;
}
public AccessDataSource (string dataFile, string selectCommand)
:
base (String.Empty, selectCommand)
{
this.dataFile = dataFile;
- //After setting dataFile, connectionString gets
recreated
- //On accessing ConnectionString, MS.Net throws
NullReferenceException
- //Need to dig more on this.
- this.ProviderName = "System.Data.OleDb";
+ this.ProviderName = PROVIDER_NAME;
}
protected override SqlDataSourceView CreateDataSourceView
(string viewName)
@@ -83,19 +84,36 @@
set { throw new NotSupportedException
("AccessDataSource does not supports SQL Cache Dependencies."); }
}
- [MonoTODO]
+ [MonoTODO ("why override? maybe it doesn't call
DbProviderFactories.GetFactory?")]
protected override DbProviderFactory GetDbProviderFactory ()
{
- throw new NotImplementedException ();
+ return DbProviderFactories.GetFactory (PROVIDER_NAME);
}
+ string GetPhysicalDataFilePath ()
+ {
+ if (DataFile == null || DataFile == "")
+ return "";
+
+ // more here? how do we handle |DataDirectory|?
+ return HttpContext.Current.Request.MapPath (DataFile);
+ }
+
[BrowsableAttribute (false),
DesignerSerializationVisibilityAttribute
(DesignerSerializationVisibility.Hidden)]
public override string ConnectionString {
- get { return this.ConnectionString; }
- set { throw new InvalidOperationException
- ("The ConnectionString is automatically
generated for AccessDataSource and hence cannot be set.");
+ get {
+ if (connectionString == null) {
+ connectionString = String.Format
("Provider={0}; Data Source={1}",
+
PROVIDER_STRING, GetPhysicalDataFilePath ());
+ }
+
+ return connectionString;
}
+ set {
+ throw new InvalidOperationException
+ ("The ConnectionString is automatically
generated for AccessDataSource and hence cannot be set.");
+ }
}
[UrlPropertyAttribute]
@@ -104,17 +122,17 @@
[WebSysDescriptionAttribute ("MS Office Access database file
name")]
[EditorAttribute ("System.Web.UI.Design.MdbDataFileEditor, " +
Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " +
Consts.AssemblySystem_Drawing)]
public string DataFile {
- get { return dataFile; }
- set { dataFile = value; }
- //After setting dataFile, connectionString gets
recreated
- //On accessing ConnectionString, MS.Net throws
NullReferenceException
- //Need to dig more on this.
+ get { return ViewState.GetString ("DataFile", ""); }
+ set {
+ ViewState ["DataFile"] = value;
+ connectionString = null;
+ }
}
[BrowsableAttribute (false),
DesignerSerializationVisibilityAttribute
(DesignerSerializationVisibility.Hidden)]
public override string ProviderName {
- get { return this.ProviderName; }
+ get { return base.ProviderName; }
set { throw new InvalidOperationException
("Setting ProviderName on an AccessDataSource
is not allowed");
}
Modified:
trunk/mcs/class/System.Web/System.Web.UI.WebControls/AccessDataSourceView.cs
===================================================================
---
trunk/mcs/class/System.Web/System.Web.UI.WebControls/AccessDataSourceView.cs
2006-02-22 19:11:17 UTC (rev 57168)
+++
trunk/mcs/class/System.Web/System.Web.UI.WebControls/AccessDataSourceView.cs
2006-02-22 19:14:04 UTC (rev 57169)
@@ -57,7 +57,7 @@
DataSourceSelectArguments
arguments)
{
oleCommand = new OleDbCommand (this.SelectCommand,
oleConnection);
- SqlDataSourceCommandEventArgs cmdEventArgs = new
SqlDataSourceCommandEventArgs (oleCommand);
+ SqlDataSourceSelectingEventArgs cmdEventArgs = new
SqlDataSourceSelectingEventArgs (oleCommand, arguments);
OnSelecting (cmdEventArgs);
IEnumerable enums = null;
Exception exception = null;
@@ -65,7 +65,7 @@
try {
System.IO.File.OpenRead
(dataSource.DataFile).Close ();
oleConnection.Open ();
- reader = oleCommand.ExecuteReader ();
+ reader =
(OleDbDataReader)oleCommand.ExecuteReader ();
//enums = reader.GetEnumerator ();
throw new
NotImplementedException("OleDbDataReader doesnt implements GetEnumerator method
yet");
Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
2006-02-22 19:11:17 UTC (rev 57168)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
2006-02-22 19:14:04 UTC (rev 57169)
@@ -1,3 +1,41 @@
+2006-02-22 Chris Toshok <[EMAIL PROTECTED]>
+
+ * SqlDataSourceFilteringEventArgs.cs: formatting.
+
+ * SqlDataSourceSelectingEventArgs.cs: remove ExecutingSelectCount,
+ both the property and ctor arg.
+
+ * AccessDataSourceView.cs (ExecuteSelect): use SelectingEventArgs,
+ not CommandEventArgs. Also, cast the return value of
+ oleCommand.ExecuteReader.
+
+ * AccessDataSource.cs (.ctor): fix the ctors and remove FIXME
+ comments.
+ (GetDbProviderFactory): implement naively, and leave a MonoTODO.
+ (GetPhysicalDataFilePath): implement, again naively. this is
+ where the NRE is generated when we access ConnectionString in a
+ testcase on .net.
+ (ConnectionString): dynamically generate this based on our
+ DataFile attribute.
+ (DataFile): clear the ConnectionString in the setter so we'll
+ regenerate it.
+ (ProviderName): use base.ProviderName in the getter, not
+ this.ProviderName, so we don't recurse infinitely.
+
+ * SqlDataSourceView.cs: start reworking this class.
+
+ * SqlDataSource.cs (GetDbProviderFactory): implement this,
+ following the MS docs on the matter (if ProviderName is null/"",
+ return SqlClientFactory.Instance.)
+ (GetDbProviderFactoryInternal): add an internal method for use by
+ SqlDataSourceView.
+ (TrackViewState): don't invoke View.TrackViewState unless we have
+ one.
+ (Selecting): change event handler type to match MS.
+ (Filtering): add missing event.
+ (View): call CreateDataSourceView, don't just create an
+ SqlDataSourceView.
+
2006-02-21 Chris Toshok <[EMAIL PROTECTED]>
* BoundField.cs: ues the ViewState.Get* pattern with default
Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSource.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSource.cs
2006-02-22 19:11:17 UTC (rev 57168)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSource.cs
2006-02-22 19:14:04 UTC (rev 57169)
@@ -4,9 +4,10 @@
// Authors:
// Ben Maurer ([EMAIL PROTECTED])
// Sanjay Gupta ([EMAIL PROTECTED])
+// Chris Toshok ([EMAIL PROTECTED])
//
// (C) 2003 Ben Maurer
-// (C) 2004 Novell, Inc. (http://www.novell.com)
+// (C) 2004-2006 Novell, Inc. (http://www.novell.com)
//
//
@@ -33,7 +34,11 @@
#if NET_2_0
using System.Collections;
using System.Collections.Specialized;
+using System.Configuration;
+using System.Drawing;
+using System.Web.Configuration;
using System.Data.Common;
+using System.Data.SqlClient;
using System.Text;
using System.ComponentModel;
@@ -45,11 +50,11 @@
[DesignerAttribute
("System.Web.UI.Design.WebControls.SqlDataSourceDesigner, " +
Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
[DefaultEventAttribute ("Selecting")]
public class SqlDataSource : DataSourceControl {
-
+
public SqlDataSource ()
{
}
-
+
public SqlDataSource (string connectionString, string
selectCommand)
{
ConnectionString = connectionString;
@@ -80,12 +85,27 @@
return view;
}
- [MonoTODO]
protected virtual DbProviderFactory GetDbProviderFactory ()
{
- throw new NotImplementedException ();
+ DbProviderFactory f = null;
+
+ if (ProviderName != null && ProviderName != "") {
+ try {
+ f =
DbProviderFactories.GetFactory(ProviderName);
+ }
+ catch { /* nada */ }
+ if (f != null)
+ return f;
+ }
+
+ return SqlClientFactory.Instance;
}
+ internal DbProviderFactory GetDbProviderFactoryInternal ()
+ {
+ return GetDbProviderFactory ();
+ }
+
protected override ICollection GetViewNames ()
{
return new string [] { "DefaultView" };
@@ -132,58 +152,123 @@
protected override void TrackViewState ()
{
base.TrackViewState ();
- ((IStateManager) View).TrackViewState ();
+ if (view != null)
+ ((IStateManager) view).TrackViewState ();
}
-
- //protected virtual DataSourceCache Cache { get; }
- //public virtual int CacheDuration { get; set; }
- //public virtual DataSourceCacheExpiry CacheExpirationPolicy {
get; set; }
- //public virtual string CacheKeyDependency { get; set; }
+#region TODO
+ [MonoTODO]
[DefaultValue ("")]
+ public virtual string CacheKeyDependency {
+ get { return ViewState.GetString ("CacheKeyDependency",
""); }
+ set { ViewState ["CacheKeyDependency"] = value; }
+ }
+
[MonoTODO]
+ [DefaultValue (true)]
+ public virtual bool CancelSelectOnNullParameter {
+ get { return ViewState.GetBool
("CancelSelectOnNullParameter", true); }
+ set { ViewState["CancelSelectOnNullParameter"] = value;
}
+ }
+
+ [MonoTODO]
+ [DefaultValue (ConflictOptions.OverwriteChanges)]
+ public ConflictOptions ConflictDetection {
+ get { return (ConflictOptions) ViewState.GetInt
("ConflictDetection", (int)ConflictOptions.OverwriteChanges); }
+ set { ViewState ["ConflictDetection"] = value; }
+ }
+
+ [MonoTODO]
+ [DefaultValue (SqlDataSourceCommandType.Text)]
+ public SqlDataSourceCommandType DeleteCommandType {
+ get { return (SqlDataSourceCommandType)
ViewState.GetInt ("DeleteCommandType",
(int)SqlDataSourceCommandType.StoredProcedure); }
+ set { ViewState ["DeleteCommandType"] = value; }
+ }
+
+ [MonoTODO]
+ [DefaultValue (SqlDataSourceCommandType.Text)]
+ public SqlDataSourceCommandType InsertCommandType {
+ get { return (SqlDataSourceCommandType)
ViewState.GetInt ("InsertCommandType",
(int)SqlDataSourceCommandType.StoredProcedure); }
+ set { ViewState ["InsertCommandType"] = value; }
+ }
+
+ [MonoTODO]
+ [DefaultValue (SqlDataSourceCommandType.Text)]
+ public SqlDataSourceCommandType SelectCommandType {
+ get { return (SqlDataSourceCommandType)
ViewState.GetInt ("SelectCommandType",
(int)SqlDataSourceCommandType.StoredProcedure); }
+ set { ViewState ["SelectCommandType"] = value; }
+ }
+
+ [MonoTODO]
+ [DefaultValue (SqlDataSourceCommandType.Text)]
+ public SqlDataSourceCommandType UpdateCommandType {
+ get { return (SqlDataSourceCommandType)
ViewState.GetInt ("UpdateCommandType",
(int)SqlDataSourceCommandType.StoredProcedure); }
+ set { ViewState ["UpdateCommandType"] = value; }
+ }
+
+ [MonoTODO]
+ [DefaultValue ("{0}")]
+ public string OldValuesParameterFormatString {
+ get { return ViewState.GetString
("OldValuesParameterFormatString", "{0}"); }
+ set { ViewState ["OldValuesParameterFormatString"] =
value; }
+ }
+
+ [DefaultValue ("")]
+ [MonoTODO]
public virtual string SqlCacheDependency {
- get {
- throw new NotImplementedException ();
- }
- set {
- throw new NotImplementedException ();
- }
+ get { return ViewState.GetString ("SqlCacheDependency",
""); }
+ set { ViewState ["SqlCacheDependency"] = value; }
}
- //public virtual bool EnableCaching { get; set; }
-
+ [MonoTODO]
+ [DefaultValue ("")]
+ public string SortParameterName {
+ get { return ViewState.GetString ("SortParameterName",
""); }
+ set { ViewState ["SortParameterName"] = value; }
+ }
+
+ [DefaultValue (0)]
+ // [TypeConverter (typeof
(DataSourceCacheDurationConverter))]
+ public virtual int CacheDuration {
+ get { return ViewState.GetInt ("CacheDuration", 0); }
+ set { ViewState ["CacheDuration"] = value; }
+ }
+
+ [DefaultValue (DataSourceCacheExpiry.Absolute)]
+ public virtual DataSourceCacheExpiry CacheExpirationPolicy {
+ get { return (DataSourceCacheExpiry) ViewState.GetInt
("CacheExpirationPolicy", (int)DataSourceCacheExpiry.Absolute); }
+ set { ViewState ["CacheExpirationPolicy"] = value; }
+ }
+
+ [DefaultValue (false)]
+ public virtual bool EnableCaching {
+ get { return ViewState.GetBool ("EnableCaching",
false); }
+ set { ViewState ["EnableCaching"] = value; }
+ }
+#endregion
+
[DefaultValueAttribute ("")]
-// [TypeConverterAttribute (typeof
(System.Web.UI.Design.WebControls.DataProviderNameConverter)]
+ [TypeConverterAttribute
("System.Web.UI.Design.WebControls.DataProviderNameConverter, " +
Consts.AssemblySystem_Design)]
public virtual string ProviderName {
- get {
- string val = ViewState ["ProviderName"] as
string;
- return val == null ? "System.Data.SqlClient" :
val;
- }
+ get { return ViewState.GetString ("ProviderName", ""); }
set { ViewState ["ProviderName"] = value; }
}
- [EditorAttribute ("System.Web.UI.Design.ConnectionStringEditor,
" + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " +
Consts.AssemblySystem_Drawing)]
+ [EditorAttribute
("System.Web.UI.Design.WebControls.SqlDataSourceConnectionStringEditor, " +
Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " +
Consts.AssemblySystem_Drawing)]
[DefaultValueAttribute ("")]
public virtual string ConnectionString {
- get {
- string val = ViewState ["ConnectionString"] as
string;
- return val == null ? "" : val;
- }
+ get { return ViewState.GetString ("ConnectionString",
""); }
set { ViewState ["ConnectionString"] = value; }
}
- [DefaultValueAttribute (SqlDataSourceMode.DataSet)]
+ [DefaultValueAttribute (SqlDataSourceMode.DataSet)]
public SqlDataSourceMode DataSourceMode {
- get {
- object val = ViewState ["DataSourceMode"];
- return val == null ? SqlDataSourceMode.DataSet
: (SqlDataSourceMode) val;
- }
+ get { return (SqlDataSourceMode) ViewState.GetInt
("DataSourceMode", (int)SqlDataSourceMode.DataSet); }
set { ViewState ["DataSourceMode"] = value; }
}
- [DefaultValueAttribute ("")]
+ [DefaultValueAttribute ("")]
public string DeleteCommand {
get { return View.DeleteCommand; }
set { View.DeleteCommand = value; }
@@ -205,7 +290,7 @@
get { return View.FilterParameters; }
}
- [DefaultValueAttribute ("")]
+ [DefaultValueAttribute ("")]
public string InsertCommand {
get { return View.InsertCommand; }
set { View.InsertCommand = value; }
@@ -233,7 +318,7 @@
get { return View.SelectParameters; }
}
- [DefaultValueAttribute ("")]
+ [DefaultValueAttribute ("")]
public string UpdateCommand {
get { return View.UpdateCommand; }
set { View.UpdateCommand = value; }
@@ -247,7 +332,7 @@
get { return View.UpdateParameters; }
}
- [DefaultValueAttribute ("")]
+ [DefaultValueAttribute ("")]
public string FilterExpression {
get { return View.FilterExpression; }
set { View.FilterExpression = value; }
@@ -268,6 +353,11 @@
remove { View.Inserted -= value; }
}
+ public event SqlDataSourceFilteringEventHandler Filtering {
+ add { View.Filtering += value; }
+ remove { View.Filtering -= value; }
+ }
+
public event SqlDataSourceCommandEventHandler Inserting {
add { View.Inserting += value; }
remove { View.Inserting -= value; }
@@ -278,7 +368,7 @@
remove { View.Selected -= value; }
}
- public event SqlDataSourceCommandEventHandler Selecting {
+ public event SqlDataSourceSelectingEventHandler Selecting {
add { View.Selecting += value; }
remove { View.Selecting -= value; }
}
@@ -297,7 +387,7 @@
SqlDataSourceView View {
get {
if (view == null) {
- view = new SqlDataSourceView (this,
"DefaultView", this.Context);
+ view = CreateDataSourceView
("DefaultView");
view.DataSourceViewChanged += new
EventHandler (ViewChanged);
if (IsTrackingViewState)
((IStateManager)
view).TrackViewState ();
Modified:
trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSourceFilteringEventArgs.cs
===================================================================
---
trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSourceFilteringEventArgs.cs
2006-02-22 19:11:17 UTC (rev 57168)
+++
trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSourceFilteringEventArgs.cs
2006-02-22 19:14:04 UTC (rev 57169)
@@ -42,9 +42,7 @@
public IOrderedDictionary ParameterValues
{
- get {
- return param_values;
- }
+ get { return param_values; }
}
IOrderedDictionary param_values;
Modified:
trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSourceSelectingEventArgs.cs
===================================================================
---
trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSourceSelectingEventArgs.cs
2006-02-22 19:11:17 UTC (rev 57168)
+++
trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSourceSelectingEventArgs.cs
2006-02-22 19:14:04 UTC (rev 57169)
@@ -34,22 +34,16 @@
namespace System.Web.UI.WebControls {
public class SqlDataSourceSelectingEventArgs :
SqlDataSourceCommandEventArgs {
DataSourceSelectArguments arguments;
- bool executeSelect;
- public SqlDataSourceSelectingEventArgs (DbCommand command,
DataSourceSelectArguments argument,
- bool executeSelect) : base (command)
+ public SqlDataSourceSelectingEventArgs (DbCommand command,
DataSourceSelectArguments argument)
+ : base (command)
{
this.arguments = argument;
- this.executeSelect = executeSelect;
}
public DataSourceSelectArguments Arguments {
get { return arguments; }
}
-
- public bool ExecutingSelectCount {
- get { return executeSelect; }
- }
}
}
#endif
Modified:
trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSourceView.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSourceView.cs
2006-02-22 19:11:17 UTC (rev 57168)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSourceView.cs
2006-02-22 19:14:04 UTC (rev 57169)
@@ -36,39 +36,53 @@
using System.Text;
using System.Data;
using System.ComponentModel;
-using System.Data.SqlClient;
+using System.Data.Common;
namespace System.Web.UI.WebControls {
public class SqlDataSourceView : DataSourceView, IStateManager {
- SqlCommand command;
- SqlConnection connection;
HttpContext context;
+ DbProviderFactory factory;
+ DbConnection connection;
public SqlDataSourceView (SqlDataSource owner, string name,
HttpContext context)
- : base (owner, name)
+ : base (owner, name)
{
this.owner = owner;
this.name = name;
this.context = context;
- connection = new SqlConnection (owner.ConnectionString);
}
+ void InitConnection ()
+ {
+ if (connection == null) {
+ factory = owner.GetDbProviderFactoryInternal ();
+ connection = factory.CreateConnection ();
+ connection.ConnectionString =
owner.ConnectionString;
+ }
+ }
+
public int Delete (IDictionary keys, IDictionary oldValues)
{
return ExecuteDelete (keys, oldValues);
}
[MonoTODO ("Handle keys, oldValues, parameters and check for
path for AccessDBFile")]
- protected override int ExecuteDelete(IDictionary keys,
IDictionary oldValues)
+ protected override int ExecuteDelete (IDictionary keys,
IDictionary oldValues)
{
if (!CanDelete)
throw new NotSupportedException("Delete
operation is not supported");
if (oldValues == null && conflictOptions ==
ConflictOptions.CompareAllValues)
throw new InvalidOperationException ("oldValues
parameters should be specified when ConflictOptions is set to
CompareAllValues");
- command = new SqlCommand (this.DeleteCommand,
connection);
- SqlDataSourceCommandEventArgs cmdEventArgs = new
SqlDataSourceCommandEventArgs (command);
- OnDeleting (cmdEventArgs);
+
+ InitConnection ();
+
+ DbCommand command = factory.CreateCommand ();
+ command.CommandText = DeleteCommand;
+ command.Connection = connection;
+
+ OnDeleting (new SqlDataSourceCommandEventArgs
(command));
+
connection.Open ();
Exception exception = null;
int result = -1;;
@@ -77,8 +91,9 @@
} catch (Exception e) {
exception = e;
}
- SqlDataSourceStatusEventArgs statusEventArgs = new
SqlDataSourceStatusEventArgs (command, result, exception);
- OnDeleted (statusEventArgs);
+
+ OnDeleted (new SqlDataSourceStatusEventArgs (command,
result, exception));
+
if (exception != null)
throw exception;
return result;
@@ -94,9 +109,15 @@
{
if (!CanInsert)
throw new NotSupportedException ("Insert
operation is not supported");
- command = new SqlCommand (this.InsertCommand,
connection);
- SqlDataSourceCommandEventArgs cmdEventArgs = new
SqlDataSourceCommandEventArgs (command);
- OnInserting (cmdEventArgs);
+
+ InitConnection ();
+
+ DbCommand command = factory.CreateCommand ();
+ command.CommandText = InsertCommand;
+ command.Connection = connection;
+
+ OnInserting (new SqlDataSourceCommandEventArgs
(command));
+
connection.Open();
Exception exception = null;
int result = -1;
@@ -105,8 +126,9 @@
}catch (Exception e) {
exception = e;
}
- SqlDataSourceStatusEventArgs statusEventArgs = new
SqlDataSourceStatusEventArgs (command, result, exception);
- OnInserted (statusEventArgs);
+
+ OnInserted (new SqlDataSourceStatusEventArgs (command,
result, exception));
+
if (exception != null)
throw exception;
return result;
@@ -114,54 +136,67 @@
public IEnumerable Select (DataSourceSelectArguments arguments)
{
-
return ExecuteSelect (arguments);
}
- [MonoTODO ("Handle arguments")]
- protected internal override IEnumerable ExecuteSelect (
- DataSourceSelectArguments
arguments)
+ [MonoTODO ("Handle @arguments, do replacement of command
parameters")]
+ protected internal override IEnumerable ExecuteSelect
(DataSourceSelectArguments arguments)
{
- command = new SqlCommand (this.SelectCommand,
connection);
- SqlDataSourceCommandEventArgs cmdEventArgs = new
SqlDataSourceCommandEventArgs (command);
- OnSelecting (cmdEventArgs);
- connection.Open ();
- SqlDataReader reader = command.ExecuteReader ();
+ DbProviderFactory f =
owner.GetDbProviderFactoryInternal ();
+ DbConnection c = f.CreateConnection ();
- IEnumerable enums = null;
- Exception exception = null;
- try {
- //enums = reader.GetEnumerator();
- throw new NotImplementedException
("SqlDataReader doesnt implements GetEnumerator method yet");
- } catch (Exception e) {
- exception = e;
+ c.ConnectionString = owner.ConnectionString;
+
+ DbCommand command = f.CreateCommand ();
+
+ command.CommandText = SelectCommand;
+ command.Connection = c;
+ command.CommandType = CommandType.Text;
+
+ /* XXX do replacement of command parameters */
+
+ OnSelecting (new SqlDataSourceSelectingEventArgs
(command, arguments));
+
+ if (owner.DataSourceMode == SqlDataSourceMode.DataSet) {
+ DbDataAdapter adapter = f.CreateDataAdapter ();
+
+ adapter.SelectCommand = command;
+
+ DataSet dataset = new DataSet ();
+
+ /* XXX MS calls Fill (DataSet dataset, string
srcTable) - find out what the source table is */
+ adapter.Fill (dataset, name);
+
+ dataset.WriteXml (Console.Out);
+
+ return dataset.CreateDataReader ();
}
- SqlDataSourceStatusEventArgs statusEventArgs =
- new SqlDataSourceStatusEventArgs (command,
reader.RecordsAffected, exception);
- OnSelected (statusEventArgs);
- if (exception !=null)
- throw exception;
- return enums;
-
+ else {
+ throw new NotImplementedException ();
+ }
}
- public int Update(IDictionary keys, IDictionary values,
- IDictionary oldValues)
+ public int Update (IDictionary keys, IDictionary values,
IDictionary oldValues)
{
return ExecuteUpdate (keys, values, oldValues);
}
[MonoTODO ("Handle keys, values and oldValues")]
- protected override int ExecuteUpdate (IDictionary keys,
- IDictionary values, IDictionary
oldValues)
+ protected override int ExecuteUpdate (IDictionary keys,
IDictionary values, IDictionary oldValues)
{
if (!CanUpdate)
throw new NotSupportedException ("Update
operation is not supported");
if (oldValues == null && conflictOptions ==
ConflictOptions.CompareAllValues)
throw new InvalidOperationException ("oldValues
parameters should be specified when ConflictOptions is set to
CompareAllValues");
- command = new SqlCommand(this.UpdateCommand,
connection);
- SqlDataSourceCommandEventArgs cmdEventArgs = new
SqlDataSourceCommandEventArgs (command);
- OnUpdating (cmdEventArgs);
+
+ InitConnection ();
+
+ DbCommand command = factory.CreateCommand ();
+ command.CommandText = UpdateCommand;
+ command.Connection = connection;
+
+ OnUpdating (new SqlDataSourceCommandEventArgs
(command));
+
connection.Open ();
Exception exception = null;
int result = -1;
@@ -170,8 +205,9 @@
}catch (Exception e) {
exception = e;
}
- SqlDataSourceStatusEventArgs statusEventArgs = new
SqlDataSourceStatusEventArgs (command, result, exception);
- OnUpdated (statusEventArgs);
+
+ OnUpdated (new SqlDataSourceStatusEventArgs (command,
result, exception));
+
if (exception != null)
throw exception;
return result;
@@ -203,7 +239,7 @@
if (vs [2] != null) ((IStateManager)
insertParameters).LoadViewState (vs [2]);
if (vs [3] != null) ((IStateManager)
selectParameters).LoadViewState (vs [3]);
if (vs [4] != null) ((IStateManager)
updateParameters).LoadViewState (vs [4]);
- if (vs [5] != null) ((IStateManager)
viewState).LoadViewState (vs [5]);
+ if (vs [5] != null) ((IStateManager)
ViewState).LoadViewState (vs [5]);
}
protected virtual object SaveViewState ()
@@ -234,76 +270,46 @@
if (viewState != null) ((IStateManager)
viewState).TrackViewState ();
}
- protected bool IsTrackingViewState {
- get { return tracking; }
- }
-
bool IStateManager.IsTrackingViewState {
get { return IsTrackingViewState; }
}
-
- public string DeleteCommand {
- get {
- string val = ViewState ["DeleteCommand"] as
string;
- return val == null ? "" : val;
- }
- set { ViewState ["DeleteCommand"] = value; }
+
+ bool cancelSelectOnNullParameter = true;
+ public bool CancelSelectOnNullParameter {
+ get { return cancelSelectOnNullParameter; }
+ set { cancelSelectOnNullParameter = value; }
}
-
- public string FilterExpression {
- get {
- string val = ViewState ["FilterExpression"] as
string;
- return val == null ? "" : val;
- }
- set { ViewState ["FilterExpression"] = value; }
+
+ public override bool CanDelete {
+ get { return DeleteCommand != null && DeleteCommand !=
""; }
}
-
- public string InsertCommand {
- get {
- string val = ViewState ["InsertCommand"] as
string;
- return val == null ? "" : val;
- }
- set { ViewState ["InsertCommand"] = value; }
+
+ public override bool CanInsert {
+ get { return InsertCommand != null && InsertCommand !=
""; }
}
- public string SelectCommand {
- get {
- string val = ViewState ["SelectCommand"] as
string;
- return val == null ? "" : val;
- }
- set { ViewState ["SelectCommand"] = value; }
+ public override bool CanPage {
+ /* according to MS, this is false in all cases */
+ get { return false; }
}
-
- public string UpdateCommand {
- get {
- string val = ViewState ["UpdateCommand"] as
string;
- return val == null ? "" : val;
- }
- set { ViewState ["UpdateCommand"] = value; }
+
+ public override bool CanRetrieveTotalRowCount {
+ /* according to MS, this is false in all cases */
+ get { return false; }
}
-
- public string SortExpression {
+
+ public override bool CanSort {
get {
- string val = ViewState ["SortExpression"] as
string;
- return val == null ? "" : val;
+ /* we can sort if we're a DataSet, regardless
of sort parameter name.
+ we can sort if we're a DataReader, if the
sort parameter name is not null/"".
+ */
+ return (owner.DataSourceMode ==
SqlDataSourceMode.DataSet
+ || (SortParameterName != null &&
SortParameterName != ""));
}
- set { ViewState ["SortExpression"] = value; }
}
- public override bool CanDelete {
- get { return DeleteCommand != ""; }
- }
-
- public override bool CanInsert {
- get { return UpdateCommand != ""; }
- }
-
- public override bool CanSort {
- get { return owner.DataSourceMode ==
SqlDataSourceMode.DataSet; }
- }
-
public override bool CanUpdate {
- get { return UpdateCommand != ""; }
+ get { return UpdateCommand != null && UpdateCommand !=
""; }
}
ConflictOptions conflictOptions =
ConflictOptions.OverwriteChanges;
@@ -312,25 +318,17 @@
set { conflictOptions = value; }
}
- void ParametersChanged (object source, EventArgs args)
- {
- OnDataSourceViewChanged (EventArgs.Empty);
+ public string DeleteCommand {
+ get { return ViewState.GetString ("DeleteCommand", "");
}
+ set { ViewState ["DeleteCommand"] = value; }
}
-
- ParameterCollection GetParameterCollection (ref
ParameterCollection output)
- {
- if (output != null)
- return output;
-
- output = new ParameterCollection ();
- output.ParametersChanged += new EventHandler
(ParametersChanged);
-
- if (IsTrackingViewState)
- ((IStateManager) output).TrackViewState ();
-
- return output;
+
+ [MonoTODO]
+ public SqlDataSourceCommandType DeleteCommandType {
+ get { return (SqlDataSourceCommandType)
ViewState.GetInt ("DeleteCommandType",
(int)SqlDataSourceCommandType.StoredProcedure); }
+ set { ViewState ["DeleteCommandType"] = value; }
}
-
+
[DefaultValueAttribute (null)]
[PersistenceModeAttribute (PersistenceMode.InnerProperty)]
[EditorAttribute
("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " +
Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " +
Consts.AssemblySystem_Drawing)]
@@ -338,6 +336,11 @@
get { return GetParameterCollection (ref
deleteParameters); }
}
+ public string FilterExpression {
+ get { return ViewState.GetString ("FilterExpression",
""); }
+ set { ViewState ["FilterExpression"] = value; }
+ }
+
[EditorAttribute
("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " +
Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " +
Consts.AssemblySystem_Drawing)]
[PersistenceModeAttribute (PersistenceMode.InnerProperty)]
[DefaultValueAttribute (null)]
@@ -345,17 +348,67 @@
get { return GetParameterCollection (ref
filterParameters); }
}
+ public string InsertCommand {
+ get { return ViewState.GetString ("InsertCommand", "");
}
+ set { ViewState ["InsertCommand"] = value; }
+ }
+
+ [MonoTODO]
+ public SqlDataSourceCommandType InsertCommandType {
+ get { return (SqlDataSourceCommandType)
ViewState.GetInt ("InsertCommandType",
(int)SqlDataSourceCommandType.StoredProcedure); }
+ set { ViewState ["InsertCommandType"] = value; }
+ }
+
[EditorAttribute
("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " +
Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " +
Consts.AssemblySystem_Drawing)]
[PersistenceModeAttribute (PersistenceMode.InnerProperty)]
[DefaultValueAttribute (null)]
public ParameterCollection InsertParameters {
get { return GetParameterCollection (ref
insertParameters); }
}
+
+ protected bool IsTrackingViewState {
+ get { return tracking; }
+ }
+
+ [MonoTODO]
+ [DefaultValue ("{0}")]
+ public string OldValuesParameterFormatString {
+ get { return ViewState.GetString
("OldValuesParameterFormatString", "{0}"); }
+ set { ViewState ["OldValuesParameterFormatString"] =
value; }
+ }
+ public string SelectCommand {
+ get { return ViewState.GetString ("SelectCommand", "");
}
+ set { ViewState ["SelectCommand"] = value; }
+ }
+
+ [MonoTODO]
+ public SqlDataSourceCommandType SelectCommandType {
+ get { return (SqlDataSourceCommandType)
ViewState.GetInt ("SelectCommandType",
(int)SqlDataSourceCommandType.StoredProcedure); }
+ set { ViewState ["SelectCommandType"] = value; }
+ }
+
public ParameterCollection SelectParameters {
get { return GetParameterCollection (ref
selectParameters); }
}
-
+
+ [MonoTODO]
+ public string SortParameterName {
+ get { return ViewState.GetString ("SortParameterName",
""); }
+ set { ViewState ["SortParameterName"] = value; }
+ }
+
+ public string UpdateCommand {
+ get { return ViewState.GetString ("UpdateCommand", "");
}
+ set { ViewState ["UpdateCommand"] = value; }
+ }
+
+ [MonoTODO]
+ public SqlDataSourceCommandType UpdateCommandType {
+ get { return (SqlDataSourceCommandType)
ViewState.GetInt ("UpdateCommandType",
(int)SqlDataSourceCommandType.StoredProcedure); }
+ set { ViewState ["UpdateCommandType"] = value; }
+ }
+
[EditorAttribute
("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " +
Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " +
Consts.AssemblySystem_Drawing)]
[PersistenceModeAttribute (PersistenceMode.InnerProperty)]
[DefaultValueAttribute (null)]
@@ -363,9 +416,23 @@
get { return GetParameterCollection (ref
updateParameters); }
}
+ void ParametersChanged (object source, EventArgs args)
+ {
+ OnDataSourceViewChanged (EventArgs.Empty);
+ }
- public override string Name {
- get { return name; }
+ ParameterCollection GetParameterCollection (ref
ParameterCollection output)
+ {
+ if (output != null)
+ return output;
+
+ output = new ParameterCollection ();
+ output.ParametersChanged += new EventHandler
(ParametersChanged);
+
+ if (IsTrackingViewState)
+ ((IStateManager) output).TrackViewState ();
+
+ return output;
}
protected virtual string ParameterPrefix {
@@ -373,19 +440,19 @@
}
StateBag viewState;
- protected StateBag ViewState {
+ private StateBag ViewState {
get {
if (viewState != null)
return viewState;
-
+
viewState = new StateBag ();
if (IsTrackingViewState)
viewState.TrackViewState ();
-
+
return viewState;
}
}
-
+
ParameterCollection deleteParameters;
ParameterCollection filterParameters;
ParameterCollection insertParameters;
@@ -425,6 +492,21 @@
remove { Events.RemoveHandler (EventDeleting, value); }
}
#endregion
+
+ #region OnFiltering
+ static readonly object EventFiltering = new object ();
+ protected virtual void OnFiltering
(SqlDataSourceFilteringEventArgs e)
+ {
+ if (!HasEvents ()) return;
+ SqlDataSourceFilteringEventHandler h = Events
[EventFiltering] as SqlDataSourceFilteringEventHandler;
+ if (h != null)
+ h (this, e);
+ }
+ public event SqlDataSourceFilteringEventHandler Filtering {
+ add { Events.AddHandler (EventFiltering, value); }
+ remove { Events.RemoveHandler (EventFiltering, value); }
+ }
+ #endregion
#region OnInsert
static readonly object EventInserted = new object ();
@@ -471,14 +553,14 @@
}
static readonly object EventSelecting = new object ();
- protected virtual void OnSelecting
(SqlDataSourceCommandEventArgs e)
+ protected virtual void OnSelecting
(SqlDataSourceSelectingEventArgs e)
{
if (!HasEvents ()) return;
- SqlDataSourceCommandEventHandler h = Events
[EventSelecting] as SqlDataSourceCommandEventHandler;
+ SqlDataSourceSelectingEventHandler h = Events
[EventSelecting] as SqlDataSourceSelectingEventHandler;
if (h != null)
h (this, e);
}
- public event SqlDataSourceCommandEventHandler Selecting {
+ public event SqlDataSourceSelectingEventHandler Selecting {
add { Events.AddHandler (EventSelecting, value); }
remove { Events.RemoveHandler (EventSelecting, value); }
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches