diff options
author | Veerapuram Varadhan <v.varadhan@gmail.com> | 2010-04-22 09:10:01 +0400 |
---|---|---|
committer | Veerapuram Varadhan <v.varadhan@gmail.com> | 2010-04-22 09:10:01 +0400 |
commit | 680b5eb2d695de54fe4eb3210c07722ef60e5a4b (patch) | |
tree | b27d228821abcdfdda382553ff67926d82f8a762 | |
parent | e74a474b01887eab204a7b5dd09f2310089db463 (diff) |
2010-04-21 Veerapuram Varadhan <vvaradhan@novell.com>mono-2.6.4
** Fixes #595918
* Tds70.cs (WriteParameterInfo): Write updated decimal value
* according
to specified scale value.
svn path=/branches/mono-2-6-4/mcs/; revision=155929
5 files changed, 109 insertions, 1 deletions
diff --git a/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog b/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog index 56fda9fcb2c..da081609310 100644 --- a/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog +++ b/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog @@ -1,3 +1,9 @@ +2010-04-21 Veerapuram Varadhan <vvaradhan@novell.com> + + ** Fixes #595918 + * Tds70.cs (WriteParameterInfo): Write updated decimal value according + to specified scale value. + 2009-08-17 Veerapuram Varadhan <vvaradhan@novell.com> ** Fixes #381151 NRE diff --git a/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds70.cs b/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds70.cs index a7c78a0f9e4..57fb0914645 100644 --- a/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds70.cs +++ b/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds70.cs @@ -563,6 +563,14 @@ namespace Mono.Data.Tds.Protocol if ( param.TypeName == "decimal" || param.TypeName == "numeric") { Comm.Append ((param.Precision !=0 ) ? param.Precision : (byte) 29); Comm.Append (param.Scale); + // Convert the decimal value according to Scale + if (param.Value != null && param.Value != DBNull.Value && + ((decimal)param.Value) != Decimal.MaxValue && + ((decimal)param.Value) != Decimal.MinValue) { + decimal expo = new Decimal (System.Math.Pow (10, (double)param.Scale)); + int pVal = (int)(((decimal)param.Value) * expo); + param.Value = (decimal)pVal; + } } diff --git a/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/ChangeLog b/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/ChangeLog index ef4dab6eb63..579c7219b68 100644 --- a/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/ChangeLog +++ b/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/ChangeLog @@ -1,3 +1,7 @@ +2010-04-21 Veerapuram Varadhan <vvaradhan@novell.com> + + * SqlParameterTest.cs: Add test for bug#595918. + 2009-08-01 Gert Driesen <drieseng@users.sourceforge.net> * SqlDataReaderTest.cs: Fixes for SQL Server 7.0 / TDS 7. Avoid diff --git a/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlParameterTest.cs b/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlParameterTest.cs index e0e987246cd..f521d3e369e 100644 --- a/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlParameterTest.cs +++ b/mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlParameterTest.cs @@ -402,6 +402,96 @@ namespace MonoTests.System.Data.SqlClient } } + [Test] // bug #595918 + public void DecimalDefaultScaleTest () + { + string create_tbl = "CREATE TABLE #decimalScaleCheck (decsclcheck DECIMAL (19, 5) null)"; + string create_sp = "CREATE PROCEDURE #sp_bug595918(@decsclcheck decimal(19,5) OUT)" + + "AS " + Environment.NewLine + + "BEGIN" + Environment.NewLine + + "INSERT INTO #decimalScaleCheck values (@decsclcheck)" + Environment.NewLine + + "SELECT @decsclcheck=decsclcheck from #decimalScaleCheck" + Environment.NewLine + + "END"; + + cmd = new SqlCommand (create_tbl, conn); + cmd.ExecuteNonQuery (); + + cmd.CommandText = create_sp; + cmd.ExecuteNonQuery (); + + cmd.CommandText = "[#sp_bug595918]"; + cmd.CommandType = CommandType.StoredProcedure; + SqlParameter pValue = new SqlParameter("@decsclcheck", SqlDbType.Decimal); + pValue.Value = 128.425; + pValue.Precision = 19; + pValue.Scale = 3; + pValue.Direction = ParameterDirection.InputOutput; + cmd.Parameters.Add(pValue); + cmd.ExecuteNonQuery(); + + Assert.AreEqual (128.425, pValue.Value, "Stored decimal value is incorrect - DS - Bug#595918"); + } + + [Test] // bug #595918 + public void DecimalGreaterScaleTest () + { + string create_tbl = "CREATE TABLE #decimalScaleCheck (decsclcheck DECIMAL (19, 5) null)"; + string create_sp = "CREATE PROCEDURE #sp_bug595918(@decsclcheck decimal(19,5) OUT)" + + "AS " + Environment.NewLine + + "BEGIN" + Environment.NewLine + + "INSERT INTO #decimalScaleCheck values (@decsclcheck)" + Environment.NewLine + + "SELECT @decsclcheck=decsclcheck from #decimalScaleCheck" + Environment.NewLine + + "END"; + + cmd = new SqlCommand (create_tbl, conn); + cmd.ExecuteNonQuery (); + + cmd.CommandText = create_sp; + cmd.ExecuteNonQuery (); + + cmd.CommandText = "[#sp_bug595918]"; + cmd.CommandType = CommandType.StoredProcedure; + SqlParameter pValue = new SqlParameter("@decsclcheck", SqlDbType.Decimal); + pValue.Value = 128.425; + pValue.Precision = 19; + pValue.Scale = 5; + pValue.Direction = ParameterDirection.InputOutput; + cmd.Parameters.Add(pValue); + cmd.ExecuteNonQuery(); + + Assert.AreEqual (128.42500, pValue.Value, "Stored decimal value is incorrect - GS - Bug#595918"); + } + + [Test] // bug #595918 + public void DecimalLesserScaleTest () + { + string create_tbl = "CREATE TABLE #decimalScaleCheck (decsclcheck DECIMAL (19, 5) null)"; + string create_sp = "CREATE PROCEDURE #sp_bug595918(@decsclcheck decimal(19,5) OUT)" + + "AS " + Environment.NewLine + + "BEGIN" + Environment.NewLine + + "INSERT INTO #decimalScaleCheck values (@decsclcheck)" + Environment.NewLine + + "SELECT @decsclcheck=decsclcheck from #decimalScaleCheck" + Environment.NewLine + + "END"; + + cmd = new SqlCommand (create_tbl, conn); + cmd.ExecuteNonQuery (); + + cmd.CommandText = create_sp; + cmd.ExecuteNonQuery (); + + cmd.CommandText = "[#sp_bug595918]"; + cmd.CommandType = CommandType.StoredProcedure; + SqlParameter pValue = new SqlParameter("@decsclcheck", SqlDbType.Decimal); + pValue.Value = 128.425; + pValue.Precision = 19; + pValue.Scale = 2; + pValue.Direction = ParameterDirection.InputOutput; + cmd.Parameters.Add(pValue); + cmd.ExecuteNonQuery(); + + Assert.AreEqual (128.42, pValue.Value, "Stored decimal value is incorrect - LS - Bug#595918"); + } + int ClientVersion { get { return (engine.ClientVersion); diff --git a/mcs/class/System.Data/Test/ProviderTests/app-net_2_0.config b/mcs/class/System.Data/Test/ProviderTests/app-net_2_0.config index 9553bd2ee11..a7d90214dac 100644 --- a/mcs/class/System.Data/Test/ProviderTests/app-net_2_0.config +++ b/mcs/class/System.Data/Test/ProviderTests/app-net_2_0.config @@ -73,7 +73,7 @@ <connection name="sqlserver-tds" factory="System.Data.SqlClient" - connectionString="server=164.99.99.212;database=monotest;user id=monotester;password=monotester;" + connectionString="server=164.99.116.64;database=monotest;user id=monotester;password=monotester;" engine="sqlserver2005" /> <connection name="sqlserver-odbc" |