#18155: Fixing scale for Decimal parameters

Work Item: 18155

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2011-12-16 15:50:53 -08:00
parent 330808fe3c
commit 4e27c20635
2 changed files with 28 additions and 0 deletions

View File

@@ -224,5 +224,22 @@ namespace Orchard.Tests.DataMigration {
.AlterColumn("Data", column => column.WithLength(2048)));
}
[Test]
public void PrecisionAndScaleAreApplied() {
_schemaBuilder
.CreateTable("Product", table => table
.Column("Price", DbType.Decimal, column => column.WithPrecision(6).WithScale(9))
);
_schemaBuilder
.ExecuteSql(String.Format("INSERT INTO TEST_Product (Price) VALUES ({0})", "123456.123456789"));
var command = _session.Connection.CreateCommand();
command.CommandText = "SELECT MAX(Price) FROM TEST_Product";
Assert.That(command.ExecuteScalar(), Is.EqualTo(123456.123456789m));
}
}
}

View File

@@ -278,6 +278,17 @@ namespace Orchard.Data.Migration.Interpreters {
}
private string GetTypeName(DbType dbType, int? length, byte precision, byte scale) {
// NHibernate has a bug in MsSqlCeDialect, as it's declaring the decimal type as this:
// NUMERIC(19, $1), where $1 is the Length parameter, and it's wrong. It should be
// NUMERIC(19, $s) in order to use the Scale parameter, as it's done for SQL Server dialects
// https://nhibernate.jira.com/browse/NH-2979
if (_dialect is NHibernate.Dialect.MsSqlCeDialect
&& dbType == DbType.Decimal
&& scale != 0) {
return _dialect.GetTypeName(new SqlType(dbType), scale, precision, scale);
}
return precision > 0
? _dialect.GetTypeName(new SqlType(dbType, precision, scale))
: length.HasValue