From: <fab...@us...> - 2010-09-01 17:17:19
|
Revision: 5174 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5174&view=rev Author: fabiomaulo Date: 2010-09-01 17:17:12 +0000 (Wed, 01 Sep 2010) Log Message: ----------- Fix NH-2302 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs trunk/nhibernate/src/NHibernate/Driver/SqlClientDriver.cs trunk/nhibernate/src/NHibernate/SqlTypes/StringClobSqlType.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj trunk/nhibernate/src/NHibernate.sln Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2302/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2302/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2302/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2302/StringLengthEntity.cs Modified: trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs 2010-09-01 17:08:11 UTC (rev 5173) +++ trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs 2010-09-01 17:17:12 UTC (rev 5174) @@ -40,6 +40,7 @@ /// </remarks> public class MsSql2000Dialect : Dialect { + public const int MaxSizeForLengthLimitedStrings = 4000; /// <summary></summary> public MsSql2000Dialect() { @@ -65,9 +66,9 @@ RegisterColumnType(DbType.Int64, "BIGINT"); RegisterColumnType(DbType.Single, "REAL"); //synonym for FLOAT(24) RegisterColumnType(DbType.StringFixedLength, "NCHAR(255)"); - RegisterColumnType(DbType.StringFixedLength, 4000, "NCHAR($l)"); + RegisterColumnType(DbType.StringFixedLength, MaxSizeForLengthLimitedStrings, "NCHAR($l)"); RegisterColumnType(DbType.String, "NVARCHAR(255)"); - RegisterColumnType(DbType.String, 4000, "NVARCHAR($l)"); + RegisterColumnType(DbType.String, MaxSizeForLengthLimitedStrings, "NVARCHAR($l)"); RegisterColumnType(DbType.String, 1073741823, "NTEXT"); RegisterColumnType(DbType.Time, "DATETIME"); Modified: trunk/nhibernate/src/NHibernate/Driver/SqlClientDriver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Driver/SqlClientDriver.cs 2010-09-01 17:08:11 UTC (rev 5173) +++ trunk/nhibernate/src/NHibernate/Driver/SqlClientDriver.cs 2010-09-01 17:17:12 UTC (rev 5174) @@ -1,6 +1,7 @@ using System.Data; using System.Data.SqlClient; using NHibernate.AdoNet; +using NHibernate.Dialect; using NHibernate.SqlCommand; using NHibernate.SqlTypes; @@ -123,14 +124,7 @@ break; case DbType.String: case DbType.StringFixedLength: - if (sqlType is StringClobSqlType) - { - dbParam.Size = MaxStringClobSize; - } - else - { - dbParam.Size = MaxStringSize; - } + dbParam.Size = IsText(dbParam, sqlType) ? MaxStringClobSize : MaxStringSize; break; case DbType.DateTime2: dbParam.Size = MaxDateTime2; @@ -141,12 +135,18 @@ } } + private static bool IsText(IDbDataParameter dbParam, SqlType sqlType) + { + return (sqlType is StringClobSqlType) || (sqlType.LengthDefined && sqlType.Length > MsSql2000Dialect.MaxSizeForLengthLimitedStrings && + (DbType.String == dbParam.DbType || DbType.StringFixedLength == dbParam.DbType)); + } + private static void SetVariableLengthParameterSize(IDbDataParameter dbParam, SqlType sqlType) { SetDefaultParameterSize(dbParam, sqlType); // Override the defaults using data from SqlType. - if (sqlType.LengthDefined) + if (sqlType.LengthDefined && !IsText(dbParam, sqlType)) { dbParam.Size = sqlType.Length; } Modified: trunk/nhibernate/src/NHibernate/SqlTypes/StringClobSqlType.cs =================================================================== --- trunk/nhibernate/src/NHibernate/SqlTypes/StringClobSqlType.cs 2010-09-01 17:08:11 UTC (rev 5173) +++ trunk/nhibernate/src/NHibernate/SqlTypes/StringClobSqlType.cs 2010-09-01 17:17:12 UTC (rev 5174) @@ -26,7 +26,8 @@ /// <summary> /// Initializes a new instance of the <see cref="StringClobSqlType"/> class. /// </summary> - public StringClobSqlType() : base() + public StringClobSqlType() + : base(int.MaxValue / 2) { } Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2302/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2302/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2302/Fixture.cs 2010-09-01 17:17:12 UTC (rev 5174) @@ -0,0 +1,176 @@ +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH2302 +{ + [TestFixture] + public class Fixture : BugTestCase + { + protected override void OnTearDown() + { + CleanUp(); + + base.OnTearDown(); + } + + [Test] + public void StringHugeLength() + { + int id; + // buildup a string the exceed the mapping + string str = GetFixedLengthString12000(); + + using (ISession sess = OpenSession()) + using (ITransaction tx = sess.BeginTransaction()) + { + // create and save the entity + StringLengthEntity entity = new StringLengthEntity(); + entity.StringHugeLength = str; + sess.Save(entity); + tx.Commit(); + id = entity.ID; + } + + using (ISession sess = OpenSession()) + using (ITransaction tx = sess.BeginTransaction()) + { + StringLengthEntity loaded = sess.Get<StringLengthEntity>(id); + Assert.IsNotNull(loaded); + Assert.AreEqual(12000, loaded.StringHugeLength.Length); + Assert.AreEqual(str, loaded.StringHugeLength); + tx.Commit(); + } + } + + [Test, Ignore("Not supported without specify the string length.")] + public void StringSqlType() + { + int id; + // buildup a string the exceed the mapping + string str = GetFixedLengthString12000(); + + using (ISession sess = OpenSession()) + using (ITransaction tx = sess.BeginTransaction()) + { + // create and save the entity + StringLengthEntity entity = new StringLengthEntity(); + entity.StringSqlType = str; + sess.Save(entity); + tx.Commit(); + id = entity.ID; + } + + using (ISession sess = OpenSession()) + using (ITransaction tx = sess.BeginTransaction()) + { + StringLengthEntity loaded = sess.Get<StringLengthEntity>(id); + Assert.IsNotNull(loaded); + Assert.AreEqual(12000, loaded.StringSqlType.Length); + Assert.AreEqual(str, loaded.StringSqlType); + tx.Commit(); + } + } + + [Test] + public void BlobSqlType() + { + int id; + // buildup a string the exceed the mapping + string str = GetFixedLengthString12000(); + + using (ISession sess = OpenSession()) + using (ITransaction tx = sess.BeginTransaction()) + { + // create and save the entity + StringLengthEntity entity = new StringLengthEntity(); + entity.BlobSqlType = str; + sess.Save(entity); + tx.Commit(); + id = entity.ID; + } + + using (ISession sess = OpenSession()) + using (ITransaction tx = sess.BeginTransaction()) + { + StringLengthEntity loaded = sess.Get<StringLengthEntity>(id); + Assert.IsNotNull(loaded); + Assert.AreEqual(12000, loaded.BlobSqlType.Length); + Assert.AreEqual(str, loaded.BlobSqlType); + tx.Commit(); + } + } + + [Test] + public void BlobWithLength() + { + int id; + // buildup a string the exceed the mapping + string str = GetFixedLengthString12000(); + + using (ISession sess = OpenSession()) + using (ITransaction tx = sess.BeginTransaction()) + { + // create and save the entity + StringLengthEntity entity = new StringLengthEntity(); + entity.BlobLength = str; + sess.Save(entity); + tx.Commit(); + id = entity.ID; + } + + using (ISession sess = OpenSession()) + using (ITransaction tx = sess.BeginTransaction()) + { + StringLengthEntity loaded = sess.Get<StringLengthEntity>(id); + Assert.IsNotNull(loaded); + Assert.AreEqual(12000, loaded.BlobLength.Length); + Assert.AreEqual(str, loaded.BlobLength); + tx.Commit(); + } + } + + [Test] + public void BlobWithoutLength() + { + int id; + // buildup a string the exceed the mapping + string str = GetFixedLengthString12000(); + + using (ISession sess = OpenSession()) + using (ITransaction tx = sess.BeginTransaction()) + { + // create and save the entity + StringLengthEntity entity = new StringLengthEntity(); + entity.Blob = str; + sess.Save(entity); + tx.Commit(); + id = entity.ID; + } + + using (ISession sess = OpenSession()) + using (ITransaction tx = sess.BeginTransaction()) + { + StringLengthEntity loaded = sess.Get<StringLengthEntity>(id); + Assert.IsNotNull(loaded); + Assert.AreEqual(12000, loaded.Blob.Length); + Assert.AreEqual(str, loaded.Blob); + tx.Commit(); + } + } + + private void CleanUp() + { + using (ISession session = OpenSession()) + using (ITransaction tx = session.BeginTransaction()) + { + session.Delete("from StringLengthEntity"); + tx.Commit(); + } + } + + private static string GetFixedLengthString12000() + { + return new string('a', 12000); + } + + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2302/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2302/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2302/Mappings.hbm.xml 2010-09-01 17:17:12 UTC (rev 5174) @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false" default-cascade="all-delete-orphan"> + <class name="NHibernate.Test.NHSpecificTest.NH2302.StringLengthEntity, NHibernate.Test" table="StringLengthEntity" + lazy="false"> + <id name="ID" access="nosetter.pascalcase-m" column="ID" type="Int32" > + <generator class="native" /> + </id> + <!-- this generates an nvarchar(255) --> + <property name="StringDefault" column="StringDefault" type="string" /> + <!-- this generates an nvarchar(50) --> + <property name="StringFixedLength" column="StringFixedLength" type="string" length="50" /> + <!-- this generates an nvarchar(max) but it operate a truncation on reading and writing, in NHib 2.1 this was --> + <property name="StringHugeLength" column="StringHugeLength" type="string" length="10000" /> + <!-- this generates an nvarchar(max) but it operate a truncation reading and writing to the default string length (4000) --> + <property name="StringSqlType" type="string"> + <column name="StringSqlType" sql-type="nvarchar(max)" /> + </property> + <!-- this generates an nvarchar(255) otherwise reading and writing seem to be ok --> + <property name="Blob" column="Blob" type="StringClob" /> + <!-- this generates an nvarchar(max) but it operate a truncation on reading and writing (same as StringHugeLength) --> + <property name="BlobLength" column="BlobLength" type="StringClob" length="15000" /> + <!-- this mapping works! for generation, writing and reading --> + <property name="BlobSqlType" type="StringClob" > + <column name="BlobSqlType" sql-type="nvarchar(max)" /> + </property> + </class> +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2302/StringLengthEntity.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2302/StringLengthEntity.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2302/StringLengthEntity.cs 2010-09-01 17:17:12 UTC (rev 5174) @@ -0,0 +1,25 @@ +namespace NHibernate.Test.NHSpecificTest.NH2302 +{ + public class StringLengthEntity + { + private int mID = 0; + public int ID + { + get { return mID; } + } + + public string StringDefault { get; set; } + + public string StringFixedLength { get; set; } + + public string StringHugeLength { get; set; } + + public string StringSqlType { get; set; } + + public string Blob { get; set; } + + public string BlobLength { get; set; } + + public string BlobSqlType { get; set; } + } +} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-09-01 17:08:11 UTC (rev 5173) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-09-01 17:17:12 UTC (rev 5174) @@ -471,6 +471,8 @@ <Compile Include="NHSpecificTest\NH2287\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2293\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2294\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2302\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2302\StringLengthEntity.cs" /> <Compile Include="NHSpecificTest\NH2303\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2303\Model.cs" /> <Compile Include="TypesTest\CharClass.cs" /> @@ -2261,6 +2263,7 @@ <EmbeddedResource Include="CollectionTest\NullableValueTypeElementMapFixture.hbm.xml" /> <EmbeddedResource Include="DriverTest\EntityForMs2008.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH2302\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2303\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2287\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2266\Mappings.hbm.xml" /> Modified: trunk/nhibernate/src/NHibernate.sln =================================================================== --- trunk/nhibernate/src/NHibernate.sln 2010-09-01 17:08:11 UTC (rev 5173) +++ trunk/nhibernate/src/NHibernate.sln 2010-09-01 17:17:12 UTC (rev 5174) @@ -23,6 +23,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NHibernate.TestDatabaseSetup", "NHibernate.TestDatabaseSetup\NHibernate.TestDatabaseSetup.csproj", "{BEEC1564-6FB6-49F7-BBE5-8EBD2F0F6E8A}" EndProject Global + GlobalSection(TestCaseManagementSettings) = postSolution + CategoryFile = NHibernate.vsmdi + EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |