Author: andreia
Date: 2007-03-16 16:24:35 -0500 (Fri, 16 Mar 2007)
New Revision: 74500
Modified:
trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds/TdsMetaParameter.cs
trunk/mcs/class/System.Data/System.Data.SqlClient/ChangeLog
trunk/mcs/class/System.Data/System.Data.SqlClient/SqlCommand.cs
trunk/mcs/class/System.Data/System.Data.SqlClient/SqlParameter.cs
trunk/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/ChangeLog
trunk/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlCommandTest.cs
Log:
2007-03-16 Andreia Gaita <[EMAIL PROTECTED]>
* SqlParameter.cs: Move isVariableSizeType flag to TdsMetaParameter
so that the TdsMetaParameter can validate itself for valid size / values.
* SqlCommand.cs (Execute): Call Validate on TdsMetaParameter.
* TdsMetaParameter.cs: Add Validate() method. For now, validate
size/value. Add isVariableSizeType.
* SqlCommandTest.cs: Add OutputParamSizeTest1-4 to test size/value
validation exception.
Modified: trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds/TdsMetaParameter.cs
===================================================================
--- trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds/TdsMetaParameter.cs
2007-03-16 21:20:38 UTC (rev 74499)
+++ trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds/TdsMetaParameter.cs
2007-03-16 21:24:35 UTC (rev 74500)
@@ -46,6 +46,7 @@
bool isSizeSet = false;
bool isNullable;
object value;
+ bool isVariableSizeType;
#endregion // Fields
@@ -126,6 +127,12 @@
}
}
+ public bool IsVariableSizeType
+ {
+ get { return isVariableSizeType; }
+ set { isVariableSizeType = value; }
+ }
+
#endregion // Properties
#region Methods
@@ -270,6 +277,20 @@
}
}
+ public void Validate (int index)
+ {
+ Console.WriteLine ("\r\n:{0}: :{1}: :{2}: :{3}:\r\n",
this.direction, this.isVariableSizeType, Value, Size);
+ if ((this.direction ==
TdsParameterDirection.InputOutput || this.direction ==
TdsParameterDirection.Output) &&
+ this.isVariableSizeType && (Value ==
DBNull.Value || Value == null) && Size == 0
+ )
+ {
+ throw new InvalidOperationException
(String.Format ("{0}[{1}]: the Size property should " +
+
"not be of size 0",
+
this.typeName,
+
index));
+ }
+ }
+
#endregion // Methods
}
}
Modified: trunk/mcs/class/System.Data/System.Data.SqlClient/ChangeLog
===================================================================
--- trunk/mcs/class/System.Data/System.Data.SqlClient/ChangeLog 2007-03-16
21:20:38 UTC (rev 74499)
+++ trunk/mcs/class/System.Data/System.Data.SqlClient/ChangeLog 2007-03-16
21:24:35 UTC (rev 74500)
@@ -1,3 +1,9 @@
+2007-03-16 Andreia Gaita <[EMAIL PROTECTED]>
+
+ * SqlParameter.cs: Move isVariableSizeType flag to TdsMetaParameter
+ so that the TdsMetaParameter can validate itself for valid size /
values.
+ * SqlCommand.cs (Execute): Call Validate on TdsMetaParameter.
+
2007-03-14 Nagappan A <[EMAIL PROTECTED]>
* SqlCommand.cs (CommandType): Exception type thrown in 2.0
Modified: trunk/mcs/class/System.Data/System.Data.SqlClient/SqlCommand.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data.SqlClient/SqlCommand.cs
2007-03-16 21:20:38 UTC (rev 74499)
+++ trunk/mcs/class/System.Data/System.Data.SqlClient/SqlCommand.cs
2007-03-16 21:24:35 UTC (rev 74500)
@@ -362,27 +362,9 @@
Connection.Tds.RecordsAffected = -1;
TdsMetaParameterCollection parms =
Parameters.MetaParameters;
foreach (TdsMetaParameter param in parms) {
- bool flag = false;
- string type = "";
- if (param.Size == 0) {
- switch (param.TypeName) {
- case "nvarchar":
- type = "String";
- flag = true;
- break;
- case "varbinary":
- type = "Byte[]";
- flag = true;
- break;
- }
- }
- if (flag == true)
- throw new InvalidOperationException
(String.Format ("{0}[{1}]: the Size property should " +
-
"not be of size 0",
-
type,
-
index));
- index++;
+ param.Validate (index++);
}
+
if (preparedStatement == null) {
bool schemaOnly = ((behavior &
CommandBehavior.SchemaOnly) > 0);
bool keyInfo = ((behavior &
CommandBehavior.KeyInfo) > 0);
Modified: trunk/mcs/class/System.Data/System.Data.SqlClient/SqlParameter.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data.SqlClient/SqlParameter.cs
2007-03-16 21:20:38 UTC (rev 74499)
+++ trunk/mcs/class/System.Data/System.Data.SqlClient/SqlParameter.cs
2007-03-16 21:24:35 UTC (rev 74500)
@@ -61,7 +61,6 @@
DbType dbType;
ParameterDirection direction = ParameterDirection.Input;
bool isNullable;
- bool isVariableSizeType = false;
bool isTypeSet = false;
int offset;
SqlDbType sqlDbType;
@@ -171,7 +170,7 @@
if (!isTypeSet)
throw new Exception ("all parameters to have an
explicity set type");
- if (isVariableSizeType) {
+ if (MetaParameter.IsVariableSizeType) {
if (SqlDbType == SqlDbType.Decimal && Precision
== 0)
throw new Exception ("Parameter of type
'Decimal' have an explicitly set Precision and Scale");
else if (Size == 0)
@@ -489,17 +488,17 @@
case DbType.AnsiString:
MetaParameter.TypeName = "varchar";
sqlDbType = SqlDbType.VarChar;
- isVariableSizeType = true;
+ MetaParameter.IsVariableSizeType = true;
break;
case DbType.AnsiStringFixedLength:
MetaParameter.TypeName = "char";
sqlDbType = SqlDbType.Char;
- isVariableSizeType = true;
+ MetaParameter.IsVariableSizeType = true;
break;
case DbType.Binary:
MetaParameter.TypeName = "varbinary";
sqlDbType = SqlDbType.VarBinary;
- isVariableSizeType = true;
+ MetaParameter.IsVariableSizeType = true;
break;
case DbType.Boolean:
MetaParameter.TypeName = "bit";
@@ -553,12 +552,12 @@
case DbType.String:
MetaParameter.TypeName = "nvarchar";
sqlDbType = SqlDbType.NVarChar;
- isVariableSizeType = true;
+ MetaParameter.IsVariableSizeType = true;
break;
case DbType.StringFixedLength:
MetaParameter.TypeName = "nchar";
sqlDbType = SqlDbType.NChar;
- isVariableSizeType = true;
+ MetaParameter.IsVariableSizeType = true;
break;
case DbType.Time:
MetaParameter.TypeName = "datetime";
@@ -664,7 +663,7 @@
case SqlDbType.Binary:
MetaParameter.TypeName = "binary";
dbType = DbType.Binary;
- isVariableSizeType = true;
+ MetaParameter.IsVariableSizeType = true;
break;
case SqlDbType.Timestamp:
MetaParameter.TypeName = "timestamp";
@@ -673,7 +672,7 @@
case SqlDbType.VarBinary:
MetaParameter.TypeName = "varbinary";
dbType = DbType.Binary;
- isVariableSizeType = true;
+ MetaParameter.IsVariableSizeType = true;
break;
case SqlDbType.Bit:
MetaParameter.TypeName = "bit";
@@ -682,7 +681,7 @@
case SqlDbType.Char:
MetaParameter.TypeName = "char";
dbType = DbType.AnsiStringFixedLength;
- isVariableSizeType = true;
+ MetaParameter.IsVariableSizeType = true;
break;
case SqlDbType.DateTime:
MetaParameter.TypeName = "datetime";
@@ -703,7 +702,7 @@
case SqlDbType.Image:
MetaParameter.TypeName = "image";
dbType = DbType.Binary;
- isVariableSizeType = true;
+ MetaParameter.IsVariableSizeType = true;
break;
case SqlDbType.Int:
MetaParameter.TypeName = "int";
@@ -720,17 +719,17 @@
case SqlDbType.NChar:
MetaParameter.TypeName = "nchar";
dbType = DbType.StringFixedLength;
- isVariableSizeType = true;
+ MetaParameter.IsVariableSizeType = true;
break;
case SqlDbType.NText:
MetaParameter.TypeName = "ntext";
dbType = DbType.String;
- isVariableSizeType = true;
+ MetaParameter.IsVariableSizeType = true;
break;
case SqlDbType.NVarChar:
MetaParameter.TypeName = "nvarchar";
dbType = DbType.String;
- isVariableSizeType = true;
+ MetaParameter.IsVariableSizeType = true;
break;
case SqlDbType.Real:
MetaParameter.TypeName = "real";
@@ -743,12 +742,12 @@
case SqlDbType.Text:
MetaParameter.TypeName = "text";
dbType = DbType.AnsiString;
- isVariableSizeType = true;
+ MetaParameter.IsVariableSizeType = true;
break;
case SqlDbType.VarChar:
MetaParameter.TypeName = "varchar";
dbType = DbType.AnsiString;
- isVariableSizeType = true;
+ MetaParameter.IsVariableSizeType = true;
break;
case SqlDbType.TinyInt:
MetaParameter.TypeName = "tinyint";
Modified:
trunk/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/ChangeLog
===================================================================
---
trunk/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/ChangeLog
2007-03-16 21:20:38 UTC (rev 74499)
+++
trunk/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/ChangeLog
2007-03-16 21:24:35 UTC (rev 74500)
@@ -1,3 +1,8 @@
+2007-03-16 Andreia Gaita <[EMAIL PROTECTED]>
+
+ * SqlCommandTest.cs: Add OutputParamSizeTest1-4 to test size/value
+ validation exception.
+
2007-03-14 Nagappan A <[EMAIL PROTECTED]>
* SqlCommandTest.cs (ExecuteScalarTest, ExecuteReaderTest)
Modified:
trunk/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlCommandTest.cs
===================================================================
---
trunk/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlCommandTest.cs
2007-03-16 21:20:38 UTC (rev 74499)
+++
trunk/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlCommandTest.cs
2007-03-16 21:24:35 UTC (rev 74500)
@@ -906,6 +906,107 @@
Assert.AreEqual(2, cmd.Parameters.Count);
}
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void OutputParamSizeTest1 ()
+ {
+ conn = (SqlConnection)
ConnectionManager.Singleton.Connection;
+ ConnectionManager.Singleton.OpenConnection ();
+ cmd = new SqlCommand ();
+ cmd.Connection = conn;
+
+ cmd.CommandText = "create procedure #testsize (@p1 as
varchar(10) output) as return";
+ cmd.CommandType = CommandType.Text;
+ cmd.ExecuteNonQuery ();
+
+ cmd.CommandText = "#testsize";
+ cmd.CommandType = CommandType.StoredProcedure;
+
+ SqlParameter p1 = new SqlParameter ();
+ p1.ParameterName = "@p1";
+ p1.Direction = ParameterDirection.InputOutput;
+ p1.DbType = DbType.String;
+ p1.IsNullable = false;
+ cmd.Parameters.Add (p1);
+ cmd.ExecuteNonQuery ();
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void OutputParamSizeTest2 ()
+ {
+ conn = (SqlConnection)
ConnectionManager.Singleton.Connection;
+ ConnectionManager.Singleton.OpenConnection ();
+ cmd = new SqlCommand ();
+ cmd.Connection = conn;
+
+ cmd.CommandText = "create procedure #testsize (@p1 as
varchar(10) output) as return";
+ cmd.CommandType = CommandType.Text;
+ cmd.ExecuteNonQuery ();
+
+ cmd.CommandText = "#testsize";
+ cmd.CommandType = CommandType.StoredProcedure;
+
+ SqlParameter p1 = new SqlParameter ();
+ p1.ParameterName = "@p1";
+ p1.Direction = ParameterDirection.Output;
+ p1.DbType = DbType.String;
+ p1.IsNullable = false;
+ cmd.Parameters.Add (p1);
+ cmd.ExecuteNonQuery ();
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void OutputParamSizeTest3 ()
+ {
+ conn = (SqlConnection)
ConnectionManager.Singleton.Connection;
+ ConnectionManager.Singleton.OpenConnection ();
+ cmd = new SqlCommand ();
+ cmd.Connection = conn;
+
+ cmd.CommandText = "create procedure #testsize (@p1 as
varchar(10) output) as return";
+ cmd.CommandType = CommandType.Text;
+ cmd.ExecuteNonQuery ();
+
+ cmd.CommandText = "#testsize";
+ cmd.CommandType = CommandType.StoredProcedure;
+
+ SqlParameter p1 = new SqlParameter ();
+ p1.ParameterName = "@p1";
+ p1.Direction = ParameterDirection.InputOutput;
+ p1.DbType = DbType.String;
+ p1.IsNullable = true;
+ cmd.Parameters.Add (p1);
+ cmd.ExecuteNonQuery ();
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void OutputParamSizeTest4 ()
+ {
+ conn = (SqlConnection)
ConnectionManager.Singleton.Connection;
+ ConnectionManager.Singleton.OpenConnection ();
+ cmd = new SqlCommand ();
+ cmd.Connection = conn;
+
+ cmd.CommandText = "create procedure #testsize (@p1 as
varchar(10) output) as return";
+ cmd.CommandType = CommandType.Text;
+ cmd.ExecuteNonQuery ();
+
+ cmd.CommandText = "#testsize";
+ cmd.CommandType = CommandType.StoredProcedure;
+
+ SqlParameter p1 = new SqlParameter ();
+ p1.ParameterName = "@p1";
+ p1.Direction = ParameterDirection.Output;
+ p1.DbType = DbType.String;
+ p1.IsNullable = true;
+ cmd.Parameters.Add (p1);
+ cmd.ExecuteNonQuery ();
+ }
+
private enum Status {
OK = 0,
Error = 3
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches