|
From: <fab...@us...> - 2009-06-15 21:59:02
|
Revision: 4481
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4481&view=rev
Author: fabiomaulo
Date: 2009-06-15 21:59:01 +0000 (Mon, 15 Jun 2009)
Log Message:
-----------
Prevent fooly usage of prepared queries using MsSQL.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Driver/SqlClientDriver.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/DriverTest/MultiTypeEntity.hbm.xml
trunk/nhibernate/src/NHibernate.Test/DriverTest/SqlClientDriverFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Driver/SqlClientDriver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Driver/SqlClientDriver.cs 2009-06-15 20:50:43 UTC (rev 4480)
+++ trunk/nhibernate/src/NHibernate/Driver/SqlClientDriver.cs 2009-06-15 21:59:01 UTC (rev 4481)
@@ -93,6 +93,8 @@
private const int MaxStringSize = MaxAnsiStringSize / 2;
private const int MaxBinaryBlobSize = int.MaxValue;
private const int MaxStringClobSize = MaxBinaryBlobSize / 2;
+ private const byte MaxPrecision = 28;
+ private const byte MaxScale = 5;
private static void SetDefaultParameterSize(IDbDataParameter dbParam, SqlType sqlType)
{
@@ -113,7 +115,10 @@
dbParam.Size = MaxBinarySize;
}
break;
-
+ case DbType.Decimal:
+ dbParam.Precision = MaxPrecision;
+ dbParam.Scale = MaxScale;
+ break;
case DbType.String:
case DbType.StringFixedLength:
if (sqlType is StringClobSqlType)
Added: trunk/nhibernate/src/NHibernate.Test/DriverTest/MultiTypeEntity.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/DriverTest/MultiTypeEntity.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/DriverTest/MultiTypeEntity.hbm.xml 2009-06-15 21:59:01 UTC (rev 4481)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Test.DriverTest"
+ assembly="NHibernate.Test">
+
+ <class name="MultiTypeEntity">
+ <id name="Id">
+ <generator class="native" />
+ </id>
+ <property name="StringProp"/>
+ <property name="AnsiStringProp" type="AnsiString"/>
+ <property name="Decimal" type="decimal"/>
+ <property name="Currency" type="Currency"/>
+ <property name="Double" column="`Double`" type="Double"/>
+ <property name="Float" type="Single"/>
+ <property name="BinaryBlob" type="BinaryBlob"/>
+ <property name="Binary" type="Byte[]"/>
+ <property name="StringClob" type="StringClob"/>
+ </class>
+</hibernate-mapping>
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/DriverTest/SqlClientDriverFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/DriverTest/SqlClientDriverFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/DriverTest/SqlClientDriverFixture.cs 2009-06-15 21:59:01 UTC (rev 4481)
@@ -0,0 +1,85 @@
+using System.Collections;
+using NHibernate.Cfg;
+using NHibernate.Dialect;
+using NUnit.Framework;
+using Environment=NHibernate.Cfg.Environment;
+
+namespace NHibernate.Test.DriverTest
+{
+ public class MultiTypeEntity
+ {
+ public virtual int Id { get; set; }
+ public virtual string StringProp { get; set; }
+ public virtual string AnsiStringProp { get; set; }
+ public virtual decimal Decimal { get; set; }
+ public virtual decimal Currency { get; set; }
+ public virtual double Double { get; set; }
+ public virtual float Float { get; set; }
+ public virtual byte[] BinaryBlob { get; set; }
+ public virtual byte[] Binary { get; set; }
+ public virtual string StringClob { get; set; }
+ }
+
+ [TestFixture]
+ public class SqlClientDriverFixture : TestCase
+ {
+ protected override void Configure(Configuration configuration)
+ {
+ configuration.SetProperty(Environment.PrepareSql, "true");
+ }
+ protected override string MappingsAssembly
+ {
+ get { return "NHibernate.Test"; }
+ }
+
+ protected override IList Mappings
+ {
+ get { return new[] { "DriverTest.MultiTypeEntity.hbm.xml" }; }
+ }
+
+ protected override bool AppliesTo(Dialect.Dialect dialect)
+ {
+ return dialect is MsSql2000Dialect;
+ }
+
+ [Test]
+ public void Crud()
+ {
+ // Should use default dimension for CRUD op and prepare_sql='true' because the mapping does not
+ // have dimensions specified.
+ object savedId;
+ using (ISession s = OpenSession())
+ using (ITransaction t = s.BeginTransaction())
+ {
+ savedId = s.Save(new MultiTypeEntity
+ {
+ StringProp = "a", StringClob = "a",BinaryBlob = new byte[]{1,2,3},
+ Binary = new byte[] { 4, 5, 6 }, Currency = 123.4m, Double = 123.5d,
+ Decimal = 789.5m
+ });
+ t.Commit();
+ }
+
+ using (ISession s = OpenSession())
+ using (ITransaction t = s.BeginTransaction())
+ {
+ var m = s.Get<MultiTypeEntity>(savedId);
+ m.StringProp = "b";
+ m.StringClob = "b";
+ m.BinaryBlob = new byte[] {4,5,6};
+ m.Binary = new byte[] {7,8,9};
+ m.Currency = 456.78m;
+ m.Double = 987.6d;
+ m.Decimal = 1323456.45m;
+ t.Commit();
+ }
+
+ using (ISession s = OpenSession())
+ using (ITransaction t = s.BeginTransaction())
+ {
+ s.CreateQuery("delete from MultiTypeEntity").ExecuteUpdate();
+ t.Commit();
+ }
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-06-15 20:50:43 UTC (rev 4480)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-06-15 21:59:01 UTC (rev 4481)
@@ -147,6 +147,7 @@
<Compile Include="Criteria\MaterialResource.cs" />
<Compile Include="Criteria\ProjectionsTest.cs" />
<Compile Include="Criteria\Reptile.cs" />
+ <Compile Include="DriverTest\SqlClientDriverFixture.cs" />
<Compile Include="ExpressionTest\RestrictionsFixture.cs" />
<Compile Include="Criteria\Student.cs" />
<Compile Include="Criteria\StudentDTO.cs" />
@@ -1911,6 +1912,7 @@
<EmbeddedResource Include="CacheTest\EntityWithFilters.xml" />
<EmbeddedResource Include="Classic\EntityWithLifecycle.hbm.xml" />
<EmbeddedResource Include="Bytecode\Lightweight\ProductLine.hbm.xml" />
+ <EmbeddedResource Include="DriverTest\MultiTypeEntity.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
<EmbeddedResource Include="NHSpecificTest\NH1837\Mappings.hbm.xml" />
<EmbeddedResource Include="TypesTest\MultiTypeEntity_WithSqlType.hbm.xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|