Skip to content

Commit

Permalink
2010-04-21 Veerapuram Varadhan <[email protected]>
Browse files Browse the repository at this point in the history
        ** Fixes #595918
        * Tds70.cs (WriteParameterInfo): Write updated decimal value
        * according 
        to specified scale value.


svn path=/branches/mono-2-6-4/mcs/; revision=155929
  • Loading branch information
vvaradhan committed Apr 22, 2010
1 parent e74a474 commit 680b5eb
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 1 deletion.
6 changes: 6 additions & 0 deletions mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2010-04-21 Veerapuram Varadhan <[email protected]>

** Fixes #595918
* Tds70.cs (WriteParameterInfo): Write updated decimal value according
to specified scale value.

2009-08-17 Veerapuram Varadhan <[email protected]>

** Fixes #381151 NRE
Expand Down
8 changes: 8 additions & 0 deletions mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds70.cs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,14 @@ Ms.net send non-nullable datatypes as nullable and allows setting null values
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;
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2010-04-21 Veerapuram Varadhan <[email protected]>

* SqlParameterTest.cs: Add test for bug#595918.

2009-08-01 Gert Driesen <[email protected]>

* SqlDataReaderTest.cs: Fixes for SQL Server 7.0 / TDS 7. Avoid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,96 @@ public void ZeroLengthString ()
}
}

[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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 680b5eb

Please sign in to comment.