2006-05-26 Senganal T <tsenganal@novell.com>
authorSenganal T <senga@mono-cvs.ximian.com>
Fri, 26 May 2006 08:26:47 +0000 (08:26 -0000)
committerSenganal T <senga@mono-cvs.ximian.com>
Fri, 26 May 2006 08:26:47 +0000 (08:26 -0000)
* Test/ProviderTests/System.Data.SqlClient/SqlParameterTest.cs :
Test if Parameter Type is inferred correctly
when Value is null or DBNull. Also, if Type is not explicitly set,
test if it is inferred from the value of the parameter evertime the
value is set.
* System.Data.SqlClient/SqlParameter.cs :
- InferSqlType : if value is null or DBNull.Value, retain the
current parameter type.

svn path=/trunk/mcs/; revision=61156

mcs/class/System.Data/System.Data.SqlClient/ChangeLog
mcs/class/System.Data/System.Data.SqlClient/SqlParameter.cs
mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/ChangeLog
mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlParameterTest.cs

index 4fb6230da81899a2125d3c6e734e5fde32d71ebe..4ebe12025efe9bd79e27df1772f4cc9635e0406f 100644 (file)
@@ -1,3 +1,9 @@
+2006-05-26  Senganal T  <tsenganal@novell.com>
+
+       * SqlParameter.cs :
+               - InferSqlType : if value is null or DBNull.Value, retain the
+               current parameter type.
+
 2006-04-18  Senganal T  <tsenganal@novell.com>
 
        * SqlConnection.cs :
index 940fd10d9f2501a0cdeff7a8d0437aa8ef7524b5..963e2c288025338d9cd3397ff6750543e847a4c5 100644 (file)
@@ -192,7 +192,7 @@ namespace System.Data.SqlClient {
 #if NET_2_0
                override
 #endif // NET_2_0
-        DbType DbType {
+               DbType DbType {
                        get { return dbType; }
                        set { 
                                SetDbType (value); 
@@ -427,6 +427,9 @@ namespace System.Data.SqlClient {
                // infer type information.
                private void InferSqlType (object value)
                {
+                       if (value == null || value == DBNull.Value)
+                               return;
+
                        Type type = value.GetType ();
 
                        string exception = String.Format ("The parameter data type of {0} is invalid.", type.Name);
@@ -486,10 +489,8 @@ namespace System.Data.SqlClient {
                                SetSqlDbType (SqlDbType.Money);
                                break;
                        case "System.Object":
-                       case "System.DBNull":
-                               SetSqlDbType (SqlDbType.Variant); // variant can contain numeric,
-                                                               //string,binary or data and also nul                                                                //values, so we can later resolve                                                                   // it to correct type.  
-                               break;  
+                               SetSqlDbType (SqlDbType.Variant); 
+                               break;
                        default:
                                throw new ArgumentException (exception);                                
                        }
index 541ad03c7670c608ccd4bf66a1175f6126149d77..8267a0ac13fb50f71ce4a2b4e7330add3ddfb8cb 100644 (file)
@@ -1,3 +1,10 @@
+2006-05-26  Senganal T  <tsenganal@novell.com>
+
+       * SqlParameterTest.cs : Test if Parameter Type is inferred correctly
+       when Value is null or DBNull. Also, if Type is not explicitly set,
+       test if it is inferred from the value of the parameter evertime the
+       value is set.
+       
 2006-04-18  Senganal T  <tsenganal@novell.com>
 
        * SqlConnectionTest.cs :
index 7ac6344c6f470da86118f85260264178c9aaff1c..65fa15727b332d4b69d702bdee7e173022876b90 100644 (file)
@@ -55,5 +55,37 @@ namespace MonoTests.System.Data.SqlClient
                        param.Value = DBNull.Value;
                        Assert.AreEqual (0, param.Scale, "#4");
                }
+
+               [Test]
+               public void ParameterType ()
+               {
+                       // If Type is not set, then type is inferred from the value
+                       // assigned. The Type should inferred everytime Value is assigned
+                       // If value is null/DBNull, then the current Type should retained.
+                       SqlParameter param = new SqlParameter ();
+                       Assert.AreEqual (SqlDbType.NVarChar, param.SqlDbType, "#1");
+                       param.Value = DBNull.Value;
+                       Assert.AreEqual (SqlDbType.NVarChar, param.SqlDbType, "#2");
+                       param.Value = 1;
+                       Assert.AreEqual (SqlDbType.Int, param.SqlDbType, "#3");
+                       param.Value = DBNull.Value;
+                       Assert.AreEqual (SqlDbType.Int, param.SqlDbType, "#4");
+                       param.Value = null;
+                       Assert.AreEqual (SqlDbType.Int, param.SqlDbType, "#4");
+
+                       //If Type is set, then the Type should not inferred from the value 
+                       //assigned.
+                       SqlParameter param1 = new SqlParameter ();
+                       param1.DbType = DbType.String; 
+                       Assert.AreEqual (SqlDbType.NVarChar, param1.SqlDbType, "#5");
+                       param1.Value = 1;
+                       Assert.AreEqual (SqlDbType.NVarChar, param1.SqlDbType, "#6");
+
+                       SqlParameter param2 = new SqlParameter ();
+                       param2.SqlDbType = SqlDbType.NVarChar;
+                       Assert.AreEqual (SqlDbType.NVarChar, param2.SqlDbType, "#7");
+                       param2.Value = 1;
+                       Assert.AreEqual (SqlDbType.NVarChar, param2.SqlDbType, "#8");
+               }
        }
 }