Author: krasnov
Date: 2006-10-17 09:20:40 -0400 (Tue, 17 Oct 2006)
New Revision: 66745
Added:
trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/SqlDataSourceDerbyTest.cs
Modified:
trunk/mcs/class/System.Web/ChangeLog
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/SqlDataSourceView.cs
trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog
trunk/mcs/class/System.Web/Test/TestMonoWeb20.vmwcsproj
trunk/mcs/class/System.Web/run-mono-tests.bat
Log:
* SqlDataSource.cs, SqlDataSourceView.cs: redesign and bug fixes
* added SqlDataSourceDerbyTest.cs
* run-mono-tests.bat: added Derby to tests class path
Modified: trunk/mcs/class/System.Web/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/ChangeLog 2006-10-17 13:11:41 UTC (rev
66744)
+++ trunk/mcs/class/System.Web/ChangeLog 2006-10-17 13:20:40 UTC (rev
66745)
@@ -1,3 +1,7 @@
+2006-10-17 Vladimir Krasnov <[EMAIL PROTECTED]>
+
+ * run-mono-tests.bat: added Derby to tests classpath
+
2006-10-11 Merav Sudri <[EMAIL PROTECTED]>
The following new tests were added:
* System.Web.UI.WebControls.SessionParameterTest.cs
Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
2006-10-17 13:11:41 UTC (rev 66744)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
2006-10-17 13:20:40 UTC (rev 66745)
@@ -1,3 +1,7 @@
+2006-10-17 Vladimir Krasnov <[EMAIL PROTECTED]>
+
+ * SqlDataSource.cs, SqlDataSourceView.cs: redesign and bug fixes
+
2006-10-17 Igor Zelmanovich <[EMAIL PROTECTED]>
* DetailsView.cs: fixed: CreateDataSourceSelectArguments method.
Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSource.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSource.cs
2006-10-17 13:11:41 UTC (rev 66744)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSource.cs
2006-10-17 13:20:40 UTC (rev 66745)
@@ -156,116 +156,94 @@
((IStateManager) view).TrackViewState ();
}
-#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;
}
+ get { return View.CancelSelectOnNullParameter; }
+ set { View.CancelSelectOnNullParameter = value; }
}
- [MonoTODO]
[DefaultValue (ConflictOptions.OverwriteChanges)]
public ConflictOptions ConflictDetection {
- get { return (ConflictOptions) ViewState.GetInt
("ConflictDetection", (int)ConflictOptions.OverwriteChanges); }
- set { ViewState ["ConflictDetection"] = value; }
+ get { return View.ConflictDetection; }
+ set { View.ConflictDetection = value; }
}
- [MonoTODO]
[DefaultValue (SqlDataSourceCommandType.Text)]
public SqlDataSourceCommandType DeleteCommandType {
- get { return (SqlDataSourceCommandType)
ViewState.GetInt ("DeleteCommandType",
(int)SqlDataSourceCommandType.StoredProcedure); }
- set { ViewState ["DeleteCommandType"] = value; }
+ get { return View.DeleteCommandType; }
+ set { View.DeleteCommandType = value; }
}
- [MonoTODO]
[DefaultValue (SqlDataSourceCommandType.Text)]
public SqlDataSourceCommandType InsertCommandType {
- get { return (SqlDataSourceCommandType)
ViewState.GetInt ("InsertCommandType",
(int)SqlDataSourceCommandType.StoredProcedure); }
- set { ViewState ["InsertCommandType"] = value; }
+ get { return View.InsertCommandType; }
+ set { View.InsertCommandType = value; }
}
- [MonoTODO]
[DefaultValue (SqlDataSourceCommandType.Text)]
public SqlDataSourceCommandType SelectCommandType {
- get { return (SqlDataSourceCommandType)
ViewState.GetInt ("SelectCommandType",
(int)SqlDataSourceCommandType.StoredProcedure); }
- set { ViewState ["SelectCommandType"] = value; }
+ get { return View.SelectCommandType; }
+ set { View.SelectCommandType = value; }
}
- [MonoTODO]
[DefaultValue (SqlDataSourceCommandType.Text)]
public SqlDataSourceCommandType UpdateCommandType {
- get { return (SqlDataSourceCommandType)
ViewState.GetInt ("UpdateCommandType",
(int)SqlDataSourceCommandType.StoredProcedure); }
- set { ViewState ["UpdateCommandType"] = value; }
+ get { return View.UpdateCommandType; }
+ set { View.UpdateCommandType = value; }
}
- [MonoTODO]
[DefaultValue ("{0}")]
public string OldValuesParameterFormatString {
- get { return ViewState.GetString
("OldValuesParameterFormatString", "{0}"); }
- set { ViewState ["OldValuesParameterFormatString"] =
value; }
+ get { return View.OldValuesParameterFormatString; }
+ set { View.OldValuesParameterFormatString = value; }
}
-
- [DefaultValue ("")]
- [MonoTODO]
- public virtual string SqlCacheDependency {
- get { return ViewState.GetString ("SqlCacheDependency",
""); }
- set { ViewState ["SqlCacheDependency"] = value; }
- }
- [MonoTODO]
[DefaultValue ("")]
- public string SortParameterName {
- get { return ViewState.GetString ("SortParameterName",
""); }
- set { ViewState ["SortParameterName"] = value; }
+ public string SortParameterName
+ {
+ get { return View.SortParameterName; }
+ set { View.SortParameterName = value; }
}
- [DefaultValue (0)]
- // [TypeConverter (typeof
(DataSourceCacheDurationConverter))]
- public virtual int CacheDuration {
- get { return ViewState.GetInt ("CacheDuration", 0); }
- set { ViewState ["CacheDuration"] = value; }
+ [DefaultValueAttribute ("")]
+ public string FilterExpression
+ {
+ get { return View.FilterExpression; }
+ set { View.FilterExpression = 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
("System.Web.UI.Design.WebControls.DataProviderNameConverter, " +
Consts.AssemblySystem_Design)]
public virtual string ProviderName {
get { return ViewState.GetString ("ProviderName", ""); }
- set { ViewState ["ProviderName"] = value; }
+ set
+ {
+ ViewState ["ProviderName"] = value;
+ RaiseDataSourceChangedEvent (EventArgs.Empty);
+ }
}
-
-
+
[EditorAttribute
("System.Web.UI.Design.WebControls.SqlDataSourceConnectionStringEditor, " +
Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " +
Consts.AssemblySystem_Drawing)]
[DefaultValueAttribute ("")]
public virtual string ConnectionString {
get { return ViewState.GetString ("ConnectionString",
""); }
- set { ViewState ["ConnectionString"] = value; }
+ set
+ {
+
+ ViewState ["ConnectionString"] = value;
+ RaiseDataSourceChangedEvent (EventArgs.Empty);
+ }
}
[DefaultValueAttribute (SqlDataSourceMode.DataSet)]
public SqlDataSourceMode DataSourceMode {
get { return (SqlDataSourceMode) ViewState.GetInt
("DataSourceMode", (int)SqlDataSourceMode.DataSet); }
- set { ViewState ["DataSourceMode"] = value; }
+ set
+ {
+ ViewState ["DataSourceMode"] = value;
+ RaiseDataSourceChangedEvent (EventArgs.Empty);
+ }
}
[DefaultValueAttribute ("")]
@@ -332,11 +310,43 @@
get { return View.UpdateParameters; }
}
- [DefaultValueAttribute ("")]
- public string FilterExpression {
- get { return View.FilterExpression; }
- set { View.FilterExpression = value; }
+#region TODO
+ [MonoTODO]
+ [DefaultValue ("")]
+ public virtual string CacheKeyDependency
+ {
+ get { return ViewState.GetString ("CacheKeyDependency",
""); }
+ set { ViewState ["CacheKeyDependency"] = value; }
}
+
+ [MonoTODO]
+ [DefaultValue ("")]
+ public virtual string SqlCacheDependency {
+ get { return ViewState.GetString ("SqlCacheDependency",
""); }
+ set { ViewState ["SqlCacheDependency"] = value; }
+ }
+
+ [MonoTODO]
+ [DefaultValue (0)]
+ public virtual int CacheDuration {
+ get { return ViewState.GetInt ("CacheDuration", 0); }
+ set { ViewState ["CacheDuration"] = value; }
+ }
+
+ [MonoTODO]
+ [DefaultValue (DataSourceCacheExpiry.Absolute)]
+ public virtual DataSourceCacheExpiry CacheExpirationPolicy {
+ get { return (DataSourceCacheExpiry) ViewState.GetInt
("CacheExpirationPolicy", (int)DataSourceCacheExpiry.Absolute); }
+ set { ViewState ["CacheExpirationPolicy"] = value; }
+ }
+
+ [MonoTODO]
+ [DefaultValue (false)]
+ public virtual bool EnableCaching {
+ get { return ViewState.GetBool ("EnableCaching",
false); }
+ set { ViewState ["EnableCaching"] = value; }
+ }
+#endregion
public event SqlDataSourceStatusEventHandler Deleted {
add { View.Deleted += value; }
Modified:
trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSourceView.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSourceView.cs
2006-10-17 13:11:41 UTC (rev 66744)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/SqlDataSourceView.cs
2006-10-17 13:20:40 UTC (rev 66745)
@@ -55,9 +55,9 @@
void InitConnection ()
{
- if (factory == null) factory =
owner.GetDbProviderFactoryInternal ();
- if (connection == null) {
- connection = factory.CreateConnection();
+ if (factory == null) factory =
owner.GetDbProviderFactoryInternal ();
+ if (connection == null) {
+ connection = factory.CreateConnection ();
connection.ConnectionString =
owner.ConnectionString;
}
}
@@ -67,7 +67,6 @@
return ExecuteDelete (keys, oldValues);
}
- [MonoTODO ("Handle keys, oldValues, parameters and check for
path for AccessDBFile")]
protected override int ExecuteDelete (IDictionary keys,
IDictionary oldValues)
{
if (!CanDelete)
@@ -80,10 +79,23 @@
DbCommand command = factory.CreateCommand ();
command.CommandText = DeleteCommand;
command.Connection = connection;
- command.CommandType = CommandType.Text;
+ if (DeleteCommandType == SqlDataSourceCommandType.Text)
+ command.CommandType = CommandType.Text;
+ else
+ command.CommandType =
CommandType.StoredProcedure;
- if (DeleteParameters.Count > 0)
- InitializeParameters (command,
DeleteParameters, null);
+ IDictionary oldDataValues;
+ if (ConflictDetection ==
ConflictOptions.CompareAllValues) {
+ oldDataValues = new Hashtable ();
+ foreach (DictionaryEntry de in keys)
+ oldDataValues [de.Key] = de.Value;
+ foreach (DictionaryEntry de in oldValues)
+ oldDataValues [de.Key] = de.Value;
+ }
+ else
+ oldDataValues = keys;
+
+ InitializeParameters (command, DeleteParameters, null,
oldDataValues, null, false);
OnDeleting (new SqlDataSourceCommandEventArgs
(command));
@@ -111,10 +123,9 @@
public int Insert (IDictionary values)
{
- return Insert (values);
+ return ExecuteInsert (values);
}
-
- [MonoTODO ("Handle values and parameters")]
+
protected override int ExecuteInsert (IDictionary values)
{
if (!CanInsert)
@@ -125,22 +136,24 @@
DbCommand command = factory.CreateCommand ();
command.CommandText = InsertCommand;
command.Connection = connection;
- command.CommandType = CommandType.Text;
+ if (InsertCommandType == SqlDataSourceCommandType.Text)
+ command.CommandType = CommandType.Text;
+ else
+ command.CommandType =
CommandType.StoredProcedure;
- if (InsertParameters.Count > 0)
- InitializeParameters (command,
InsertParameters, null);
+ InitializeParameters (command, InsertParameters,
values, null, null, true);
OnInserting (new SqlDataSourceCommandEventArgs
(command));
bool closed = connection.State ==
ConnectionState.Closed;
-
if (closed)
- connection.Open();
+ connection.Open ();
Exception exception = null;
int result = -1;
try {
- result = command.ExecuteNonQuery();
- } catch (Exception e) {
+ result = command.ExecuteNonQuery ();
+ }
+ catch (Exception e) {
exception = e;
}
@@ -159,42 +172,98 @@
return ExecuteSelect (arguments);
}
- [MonoTODO ("Handle @arguments")]
protected internal override IEnumerable ExecuteSelect
(DataSourceSelectArguments arguments)
{
+ if (SortParameterName.Length > 0 && SelectCommandType
== SqlDataSourceCommandType.Text)
+ throw new NotSupportedException ("The
SortParameterName property is only supported with stored procedure commands in
SqlDataSource");
+
+ if (arguments.SortExpression.Length > 0 &&
owner.DataSourceMode == SqlDataSourceMode.DataReader)
+ throw new NotSupportedException ("SqlDataSource
cannot sort. Set DataSourceMode to DataSet to enable sorting.");
+
+ if (arguments.StartRowIndex > 0 ||
arguments.MaximumRows > 0)
+ throw new NotSupportedException ("SqlDataSource
does not have paging enabled. Set the DataSourceMode to DataSet to enable
paging.");
+
+ if (FilterExpression.Length > 0 && owner.DataSourceMode
== SqlDataSourceMode.DataReader)
+ throw new NotSupportedException ("SqlDataSource
only supports filtering when the data source's DataSourceMode is set to
DataSet.");
+
InitConnection ();
DbCommand command = factory.CreateCommand ();
command.CommandText = SelectCommand;
command.Connection = connection;
- command.CommandType = CommandType.Text;
+ if (SelectCommandType == SqlDataSourceCommandType.Text)
+ command.CommandType = CommandType.Text;
+ else {
+ command.CommandType =
CommandType.StoredProcedure;
+ if (SortParameterName.Length > 0 &&
arguments.SortExpression.Length > 0)
+ command.Parameters.Add
(CreateDbParameter (ParameterPrefix + SortParameterName,
arguments.SortExpression));
+ }
- if (SelectParameters.Count > 0)
- InitializeParameters (command,
SelectParameters, null);
+ if (SelectParameters.Count > 0)
+ InitializeParameters (command,
SelectParameters, null, null, null, false);
OnSelecting (new SqlDataSourceSelectingEventArgs
(command, arguments));
+ Exception exception = null;
if (owner.DataSourceMode == SqlDataSourceMode.DataSet) {
- DbDataAdapter adapter =
factory.CreateDataAdapter ();
+ DataView dataView = null;
- adapter.SelectCommand = command;
+ try {
+ DbDataAdapter adapter =
factory.CreateDataAdapter ();
+ DataSet dataset = new DataSet ();
- DataSet dataset = new DataSet ();
+ adapter.SelectCommand = command;
+ adapter.Fill (dataset, name);
- adapter.Fill (dataset, name);
+ dataView = dataset.Tables
[0].DefaultView;
+ if (dataView == null)
+ throw new
InvalidOperationException ();
+ }
+ catch (Exception e) {
+ exception = e;
+ }
+ int rowsAffected = (dataView == null) ? 0 :
dataView.Count;
+ OnSelected (new SqlDataSourceStatusEventArgs
(command, rowsAffected, exception));
- if (dataset.Tables.Count >= 1)
- return dataset.Tables[0].DefaultView;
- else
- return dataset.CreateDataReader ();
+ if (exception != null)
+ throw exception;
+
+ if (SortParameterName.Length == 0 ||
SelectCommandType == SqlDataSourceCommandType.Text)
+ dataView.Sort =
arguments.SortExpression;
+
+ if (FilterExpression.Length > 0) {
+ IOrderedDictionary fparams =
FilterParameters.GetValues (context, owner);
+ SqlDataSourceFilteringEventArgs fargs =
new SqlDataSourceFilteringEventArgs (fparams);
+ OnFiltering (fargs);
+ if (!fargs.Cancel) {
+ object [] formatValues = new
object [fparams.Count];
+ for (int n = 0; n <
formatValues.Length; n++) {
+ formatValues [n] =
fparams [n];
+ if (formatValues [n] ==
null) return dataView;
+ }
+ dataView.RowFilter =
string.Format (FilterExpression, formatValues);
+ }
+ }
+
+ return dataView;
}
else {
+ DbDataReader reader = null;
bool closed = connection.State ==
ConnectionState.Closed;
- if (closed)
- connection.Open ();
+ if (closed)
+ connection.Open ();
+ try {
+ reader = command.ExecuteReader (closed
? CommandBehavior.CloseConnection : CommandBehavior.Default);
+ }
+ catch (Exception e) {
+ exception = e;
+ }
+ OnSelected (new SqlDataSourceStatusEventArgs
(command, reader.RecordsAffected, exception));
+ if (exception != null)
+ throw exception;
- return command.ExecuteReader (closed ?
CommandBehavior.CloseConnection : CommandBehavior.Default);
+ return reader;
}
}
@@ -203,7 +272,6 @@
return ExecuteUpdate (keys, values, oldValues);
}
- [MonoTODO ("Handle keys, values and oldValues")]
protected override int ExecuteUpdate (IDictionary keys,
IDictionary values, IDictionary oldValues)
{
if (!CanUpdate)
@@ -216,22 +284,39 @@
DbCommand command = factory.CreateCommand ();
command.CommandText = UpdateCommand;
command.Connection = connection;
- command.CommandType = CommandType.Text;
+ if (UpdateCommandType == SqlDataSourceCommandType.Text)
+ command.CommandType = CommandType.Text;
+ else
+ command.CommandType =
CommandType.StoredProcedure;
- if (UpdateParameters.Count > 0)
- InitializeParameters (command,
UpdateParameters, null);
+ IDictionary dataValues;
+ IDictionary oldDataValues;
+ if (ConflictDetection ==
ConflictOptions.CompareAllValues) {
+ oldDataValues = new OrderedDictionary ();
+ dataValues = values;
+ foreach (DictionaryEntry de in keys)
+ oldDataValues [de.Key] = de.Value;
+ foreach (DictionaryEntry de in oldValues)
+ oldDataValues [de.Key] = de.Value;
+ }
+ else {
+ oldDataValues = keys;
+ dataValues = values;
+ }
+ InitializeParameters (command, UpdateParameters,
dataValues, oldDataValues, null, false);
+
OnUpdating (new SqlDataSourceCommandEventArgs
(command));
bool closed = connection.State ==
ConnectionState.Closed;
-
if (closed)
- connection.Open();
+ connection.Open ();
Exception exception = null;
int result = -1;
try {
- result = command.ExecuteNonQuery ();
- }catch (Exception e) {
+ result = command.ExecuteNonQuery ();
+ }
+ catch (Exception e) {
exception = e;
}
@@ -245,21 +330,73 @@
return result;
}
- void InitializeParameters (DbCommand command,
ParameterCollection parameters, IDictionary exclusionList)
- {
- IOrderedDictionary values = parameters.GetValues
(HttpContext.Current, owner);
+ string FormatOldParameter (string name)
+ {
+ string f = OldValuesParameterFormatString;
+ if (f.Length > 0)
+ return String.Format (f, name);
+ else
+ return name;
+ }
+
+ void InitializeParameters (DbCommand command,
ParameterCollection parameters, IDictionary values, IDictionary oldValues,
IDictionary exclusionList, bool allwaysAddNewValues)
+ {
+ foreach (Parameter p in parameters) {
+ bool oldAdded = false;
+ if (oldValues != null && oldValues.Contains
(p.Name)) {
+ object val = Convert.ChangeType
(oldValues [p.Name], p.Type);
+ command.Parameters.Add
(CreateDbParameter (FormatOldParameter (p.Name), val, p.Direction, p.Size));
+ oldAdded = true;
+ }
+ else if (oldValues != null) {
+ string ufName = p.Name.Replace
(FormatOldParameter (string.Empty), string.Empty);
+ if (oldValues != null &&
oldValues.Contains (ufName) && !command.Parameters.Contains (p.Name)) {
+ object val = Convert.ChangeType
(oldValues [ufName], p.Type);
+ command.Parameters.Add
(CreateDbParameter (p.Name, val, p.Direction, p.Size));
+ oldAdded = true;
+ }
+ }
- foreach (Parameter p in parameters) {
- DbParameter dbp = factory.CreateParameter ();
+ if (values != null && values.Contains (p.Name))
{
+ object val = Convert.ChangeType (values
[p.Name], p.Type);
+ command.Parameters.Add
(CreateDbParameter (p.Name, val, p.Direction, p.Size));
+ }
+ else if (!oldAdded || allwaysAddNewValues) {
+ object val = p.GetValue (context,
owner);
+ if (!command.Parameters.Contains
(p.Name))
+ command.Parameters.Add
(CreateDbParameter (p.Name, val, p.Direction, p.Size));
+ }
+ }
+ if (values != null) {
+ foreach (DictionaryEntry de in values)
+ if (!command.Parameters.Contains
((string) de.Key))
+ command.Parameters.Add
(CreateDbParameter ((string) de.Key, de.Value));
+ }
- dbp.ParameterName = p.Name;
- dbp.Value = values[p.Name];
- dbp.Direction = p.Direction;
- dbp.Size = p.Size;
- command.Parameters.Add (dbp);
- }
- }
+ if (oldValues != null) {
+ foreach (DictionaryEntry de in oldValues)
+ if (!command.Parameters.Contains
(FormatOldParameter ((string) de.Key)))
+ command.Parameters.Add
(CreateDbParameter (FormatOldParameter ((string) de.Key), de.Value));
+ }
+ }
+ private DbParameter CreateDbParameter (string name, object
value)
+ {
+ return CreateDbParameter (name, value,
ParameterDirection.Input, -1);
+ }
+
+ private DbParameter CreateDbParameter (string name, object
value, ParameterDirection dir, int size)
+ {
+ DbParameter dbp = factory.CreateParameter ();
+ dbp.ParameterName = name;
+ dbp.Value = value;
+ dbp.Direction = dir;
+ if (size != -1)
+ dbp.Size = size;
+
+ return dbp;
+ }
+
void IStateManager.LoadViewState (object savedState)
{
LoadViewState (savedState);
@@ -321,6 +458,7 @@
get { return IsTrackingViewState; }
}
+ [MonoTODO]
bool cancelSelectOnNullParameter = true;
public bool CancelSelectOnNullParameter {
get { return cancelSelectOnNullParameter; }
@@ -370,9 +508,8 @@
set { ViewState ["DeleteCommand"] = value; }
}
- [MonoTODO]
public SqlDataSourceCommandType DeleteCommandType {
- get { return (SqlDataSourceCommandType)
ViewState.GetInt ("DeleteCommandType",
(int)SqlDataSourceCommandType.StoredProcedure); }
+ get { return (SqlDataSourceCommandType)
ViewState.GetInt ("DeleteCommandType", (int)SqlDataSourceCommandType.Text); }
set { ViewState ["DeleteCommandType"] = value; }
}
@@ -400,9 +537,8 @@
set { ViewState ["InsertCommand"] = value; }
}
- [MonoTODO]
public SqlDataSourceCommandType InsertCommandType {
- get { return (SqlDataSourceCommandType)
ViewState.GetInt ("InsertCommandType",
(int)SqlDataSourceCommandType.StoredProcedure); }
+ get { return (SqlDataSourceCommandType)
ViewState.GetInt ("InsertCommandType", (int) SqlDataSourceCommandType.Text); }
set { ViewState ["InsertCommandType"] = value; }
}
@@ -417,7 +553,6 @@
get { return tracking; }
}
- [MonoTODO]
[DefaultValue ("{0}")]
public string OldValuesParameterFormatString {
get { return ViewState.GetString
("OldValuesParameterFormatString", "{0}"); }
@@ -429,9 +564,8 @@
set { ViewState ["SelectCommand"] = value; }
}
- [MonoTODO]
public SqlDataSourceCommandType SelectCommandType {
- get { return (SqlDataSourceCommandType)
ViewState.GetInt ("SelectCommandType",
(int)SqlDataSourceCommandType.StoredProcedure); }
+ get { return (SqlDataSourceCommandType)
ViewState.GetInt ("SelectCommandType", (int) SqlDataSourceCommandType.Text); }
set { ViewState ["SelectCommandType"] = value; }
}
@@ -439,7 +573,6 @@
get { return GetParameterCollection (ref
selectParameters); }
}
- [MonoTODO]
public string SortParameterName {
get { return ViewState.GetString ("SortParameterName",
""); }
set { ViewState ["SortParameterName"] = value; }
@@ -450,9 +583,8 @@
set { ViewState ["UpdateCommand"] = value; }
}
- [MonoTODO]
public SqlDataSourceCommandType UpdateCommandType {
- get { return (SqlDataSourceCommandType)
ViewState.GetInt ("UpdateCommandType",
(int)SqlDataSourceCommandType.StoredProcedure); }
+ get { return (SqlDataSourceCommandType)
ViewState.GetInt ("UpdateCommandType", (int) SqlDataSourceCommandType.Text); }
set { ViewState ["UpdateCommandType"] = value; }
}
Modified: trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog
2006-10-17 13:11:41 UTC (rev 66744)
+++ trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog
2006-10-17 13:20:40 UTC (rev 66745)
@@ -1,3 +1,7 @@
+2006-10-17 Vladimir Krasnov <[EMAIL PROTECTED]>
+
+ * added: SqlDataSourceDerbyTest.cs
+
2006-10-17 Igor Zelmanovich <[EMAIL PROTECTED]>
* DetailsViewTest.cs: added tests
Added:
trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/SqlDataSourceDerbyTest.cs
===================================================================
---
trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/SqlDataSourceDerbyTest.cs
2006-10-17 13:11:41 UTC (rev 66744)
+++
trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/SqlDataSourceDerbyTest.cs
2006-10-17 13:20:40 UTC (rev 66745)
@@ -0,0 +1,271 @@
+//
+// Tests for System.Web.UI.WebControls.SqlDataSource
+// This test uses Derby, java embedded database.
+//
+// Author:
+// Vladimir Krasnov ([EMAIL PROTECTED])
+//
+
+//
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+//#if NET_2_0 && TARGET_JVM
+
+using NUnit.Framework;
+using System;
+using System.Configuration;
+using System.Data;
+using System.Data.OleDb;
+using System.Data.Common;
+using System.IO;
+using System.Globalization;
+using System.Web;
+using System.Web.UI;
+using System.Web.UI.WebControls;
+using System.Collections.Specialized;
+
+namespace MonoTests.System.Web.UI.WebControls
+{
+ [TestFixture]
+ public class SqlDataSourceDerbyTest {
+ [TestFixtureSetUp]
+ public void setup ()
+ {
+ if (Directory.Exists (_dataDir))
+ Directory.Delete (_dataDir, true);
+
+ string initSql = @"CREATE TABLE Table1 (
+ UserId int
NOT NULL PRIMARY KEY,
+ UserName
varchar(256) NOT NULL,
+ Description
varchar(256)
+ )";
+
+ OleDbConnection connection = new OleDbConnection
(_connectionString);
+ try {
+ connection.Open ();
+ DbCommand cmd = connection.CreateCommand ();
+ cmd.CommandText = initSql;
+ cmd.CommandType = CommandType.Text;
+ cmd.ExecuteNonQuery ();
+ }
+ catch (Exception) {
+ }
+ finally {
+ connection.Close ();
+ }
+ RestoreData ();
+ }
+
+ [Test]
+ public void SelectTest1 ()
+ {
+ SqlDataSource ds = CreateDataSource ();
+ ds.SelectCommand = "SELECT * FROM Table1";
+ DataView dataView = (DataView) ds.Select (new
DataSourceSelectArguments ());
+
+ Assert.AreEqual (10, dataView.Count);
+ }
+
+ [Test]
+ public void SelectTest2 ()
+ {
+ SqlDataSource ds = CreateDataSource ();
+ ds.SelectCommand = "SELECT * FROM Table1";
+ ds.FilterExpression = "UserId > 5";
+
+ DataView dataView = (DataView) ds.Select (new
DataSourceSelectArguments ());
+ Assert.AreEqual (4, dataView.Count);
+ }
+
+ [Test]
+ public void SelectTest3 ()
+ {
+ SqlDataSource ds = CreateDataSource ();
+ ds.SelectCommand = "SELECT * FROM Table1";
+
+ DataView dataView = (DataView) ds.Select (new
DataSourceSelectArguments ("Description"));
+ Assert.AreEqual ("Description", dataView.Sort);
+ }
+
+ [Test]
+ public void SelectTest4 ()
+ {
+ SqlDataSource ds = CreateDataSource ();
+ ds.SelectCommand = "SELECT * FROM Table1";
+ try {
+ DataView dataView = (DataView) ds.Select (new
DataSourceSelectArguments (1, 2));
+ }
+ catch (NotSupportedException) {
+ Assert.AreEqual (true, true);
+ }
+ }
+
+ [Test]
+ public void SelectTest5 ()
+ {
+ SqlDataSource ds = CreateDataSource ();
+ ds.SelectCommand = "SELECT * FROM Table1 WHERE UserId =
?";
+ ds.SelectParameters.Add (new Parameter ("UserId",
TypeCode.Int32, "5"));
+
+ DataView dataView = (DataView) ds.Select (new
DataSourceSelectArguments ());
+ Assert.AreEqual (1, dataView.Count);
+ }
+
+ [Test]
+ public void UpdateTest1 ()
+ {
+ SqlDataSource ds = CreateDataSource ();
+ ds.SelectCommand = "SELECT * FROM Table1 WHERE UserName
= ?";
+ ds.SelectParameters.Add (new Parameter ("UserName",
TypeCode.String, "superuser"));
+
+ ds.UpdateCommand = "UPDATE Table1 SET UserName = ?
WHERE UserId = ?";
+ ds.UpdateParameters.Add (new Parameter ("UserName",
TypeCode.String, "superuser"));
+ ds.UpdateParameters.Add (new Parameter ("UserId",
TypeCode.Int32, "5"));
+
+ int records = ds.Update ();
+ DataView dataView = (DataView) ds.Select (new
DataSourceSelectArguments ());
+ Assert.AreEqual (1, dataView.Count);
+ Assert.AreEqual (1, records);
+
+ RestoreData ();
+ }
+
+ [Test]
+ public void UpdateTest2 ()
+ {
+ SqlDataSource ds = CreateDataSource ();
+ ds.SelectCommand = "SELECT * FROM Table1 WHERE UserName
= ?";
+ ds.SelectParameters.Add (new Parameter ("UserName",
TypeCode.String, "SimpleUser"));
+
+ ds.UpdateCommand = "UPDATE Table1 SET UserName = ?
WHERE UserId = ?";
+ ds.UpdateParameters.Add (new Parameter ("UserName",
TypeCode.String, "superuser"));
+ ds.UpdateParameters.Add (new Parameter ("UserId",
TypeCode.Int32, "5"));
+ ds.OldValuesParameterFormatString = "original_{0}";
+
+ SqlDataSourceView view = (SqlDataSourceView)
((IDataSource) ds).GetView ("");
+
+ OrderedDictionary keys = new OrderedDictionary ();
+ keys.Add ("UserId", 7);
+
+ OrderedDictionary values = new OrderedDictionary ();
+ values.Add ("UserName", "SimpleUser");
+
+ OrderedDictionary oldvalues = new OrderedDictionary ();
+ oldvalues.Add ("UserName", "user7");
+
+ int records = view.Update (keys, values, oldvalues);
+ DataView dataView = (DataView) ds.Select (new
DataSourceSelectArguments ());
+ Assert.AreEqual (1, dataView.Count);
+ Assert.AreEqual (1, records);
+
+ RestoreData ();
+ }
+
+ [Test]
+ public void InsertTest1 ()
+ {
+ SqlDataSource ds = CreateDataSource ();
+ ds.SelectCommand = "SELECT * FROM Table1 WHERE UserName
= ?";
+ ds.SelectParameters.Add (new Parameter ("UserName",
TypeCode.String, "newuser"));
+
+ ds.InsertCommand = "INSERT INTO Table1 (UserId,
UserName, Description) VALUES (?, ?, ?)";
+ ds.InsertParameters.Add (new Parameter ("UserId",
TypeCode.Int32, "15"));
+ ds.InsertParameters.Add (new Parameter ("UserName",
TypeCode.String, "newuser"));
+ ds.InsertParameters.Add (new Parameter ("Description",
TypeCode.String, "newuser"));
+
+ int records = ds.Insert ();
+ DataView dataView = (DataView) ds.Select (new
DataSourceSelectArguments ());
+ Assert.AreEqual (1, dataView.Count);
+ Assert.AreEqual (1, records);
+
+ RestoreData ();
+ }
+
+ [Test]
+ public void InsertTest2 ()
+ {
+ SqlDataSource ds = CreateDataSource ();
+ ds.SelectCommand = "SELECT * FROM Table1 WHERE UserName
= ?";
+ ds.SelectParameters.Add (new Parameter ("UserName",
TypeCode.String, "newuser2"));
+
+ ds.InsertCommand = "INSERT INTO Table1 (UserId,
UserName, Description) VALUES (?, ?, ?)";
+ ds.InsertParameters.Add (new Parameter ("UserId",
TypeCode.Int32, "5"));
+ ds.InsertParameters.Add (new Parameter ("UserName",
TypeCode.String, "newuser"));
+ ds.InsertParameters.Add (new Parameter ("Description",
TypeCode.String, "newuser"));
+
+ SqlDataSourceView view = (SqlDataSourceView)
((IDataSource) ds).GetView ("");
+
+ OrderedDictionary values = new OrderedDictionary ();
+ values.Add ("UserId", "17");
+ values.Add ("UserName", "newuser2");
+ values.Add ("Description", "newuser2");
+
+ int records = view.Insert (values);
+ DataView dataView = (DataView) ds.Select (new
DataSourceSelectArguments ());
+ Assert.AreEqual (1, dataView.Count);
+ Assert.AreEqual (1, records);
+
+ RestoreData ();
+ }
+
+
+ const string _dataDir = "DataDir";
+ const string _connectionString =
"JdbcDriverClassName=org.apache.derby.jdbc.EmbeddedDriver;JdbcURL=jdbc:derby:"
+ _dataDir + ";create=true";
+ private SqlDataSource CreateDataSource ()
+ {
+ SqlDataSource ds = new SqlDataSource ();
+ ds.ConnectionString = _connectionString;
+ ds.ProviderName = "System.Data.OleDb";
+ ds.DataSourceMode = SqlDataSourceMode.DataSet;
+ return ds;
+ }
+
+ private void RestoreData ()
+ {
+ string insertSql = @"INSERT INTO Table1 VALUES ({0},
'{1}', '{2}')";
+ string deleteSql = @"DELETE FROM Table1";
+
+ OleDbConnection connection = new OleDbConnection
(_connectionString);
+ try {
+ DbCommand dc = connection.CreateCommand ();
+ dc.CommandText = deleteSql;
+ dc.CommandType = CommandType.Text;
+ dc.ExecuteNonQuery ();
+
+ for (int i = 0; i < 10; i++) {
+ DbCommand ic = connection.CreateCommand
();
+ ic.CommandText = string.Format
(insertSql, i.ToString (), "user" + i.ToString (), (9 - i).ToString ());
+ ic.CommandType = CommandType.Text;
+ ic.ExecuteNonQuery ();
+ }
+ }
+ catch (Exception) {
+ }
+ finally {
+ connection.Close ();
+ }
+ }
+ }
+
+}
+
+//#endif
Modified: trunk/mcs/class/System.Web/Test/TestMonoWeb20.vmwcsproj
===================================================================
--- trunk/mcs/class/System.Web/Test/TestMonoWeb20.vmwcsproj 2006-10-17
13:11:41 UTC (rev 66744)
+++ trunk/mcs/class/System.Web/Test/TestMonoWeb20.vmwcsproj 2006-10-17
13:20:40 UTC (rev 66745)
@@ -292,6 +292,7 @@
<Compile
Include="System.Web.UI.WebControls\SelectedDatesCollectionTest.cs" />
<Compile Include="System.Web.UI.WebControls\SiteMapDataSourceTest.cs" />
<Compile Include="System.Web.UI.WebControls\SiteMapPathTest.cs" />
+ <Compile Include="System.Web.UI.WebControls\SqlDataSourceDerbyTest.cs" />
<Compile Include="System.Web.UI.WebControls\SqlDataSourceTest.cs" />
<Compile Include="System.Web.UI.WebControls\SqlDataSourceViewTest.cs" />
<Compile Include="System.Web.UI.WebControls\StyleTest.cs">
Modified: trunk/mcs/class/System.Web/run-mono-tests.bat
===================================================================
--- trunk/mcs/class/System.Web/run-mono-tests.bat 2006-10-17 13:11:41 UTC
(rev 66744)
+++ trunk/mcs/class/System.Web/run-mono-tests.bat 2006-10-17 13:20:40 UTC
(rev 66745)
@@ -54,6 +54,8 @@
rem set RUNTIME_CLASSPATH=%RUNTIME_CLASSPATH%;%JGAC_PATH%System.Drawing.jar
set RUNTIME_CLASSPATH=%RUNTIME_CLASSPATH%;%JGAC_PATH%J2SE.Helpers.jar
+set RUNTIME_CLASSPATH=%RUNTIME_CLASSPATH%;%VMW_HOME%\jgac\jdbc\derby.jar
+
set
RUNTIME_CLASSPATH=%RUNTIME_CLASSPATH%;Test\mainsoft\NunitWeb\NunitWeb\bin\Debug_Java20\NunitWeb.jar
set
RUNTIME_CLASSPATH=%RUNTIME_CLASSPATH%;Test\mainsoft\NunitWeb\NunitWeb\bin\Debug_Java20\HtmlCompare.jar
set NUNIT_OPTIONS=/exclude=NotWorking
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches