Skip to content

Commit bea9bc9

Browse files
committed
Merge branch 'darrenkopp-NH-3252'
2 parents 7c8a0ff + fcc3076 commit bea9bc9

File tree

5 files changed

+94
-1
lines changed

5 files changed

+94
-1
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using NUnit.Framework;
7+
using NHibernate.Linq;
8+
9+
namespace NHibernate.Test.NHSpecificTest.NH3252
10+
{
11+
[TestFixture]
12+
public class Fixture : TestCase
13+
{
14+
protected override string MappingsAssembly
15+
{
16+
get { return "NHibernate.Test"; }
17+
}
18+
19+
protected override IList Mappings
20+
{
21+
get { return new string[] { "NHSpecificTest.NH3252.Mappings.hbm.xml" }; }
22+
}
23+
24+
[Test]
25+
public void VerifyThatWeCanSaveAndLoad()
26+
{
27+
using (ISession session = OpenSession())
28+
using (ITransaction transaction = session.BeginTransaction())
29+
{
30+
31+
session.Save(new Note { Text = new String('0', 9000) });
32+
transaction.Commit();
33+
}
34+
35+
using (ISession session = OpenSession())
36+
using (ITransaction transaction = session.BeginTransaction())
37+
{
38+
39+
var note = session.Query<Note>().First();
40+
Assert.AreEqual(9000, note.Text.Length);
41+
}
42+
}
43+
44+
protected override void OnTearDown()
45+
{
46+
using (ISession session = OpenSession())
47+
using (ITransaction transaction = session.BeginTransaction())
48+
{
49+
session.Delete("from System.Object");
50+
51+
session.Flush();
52+
transaction.Commit();
53+
}
54+
}
55+
}
56+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernate.Test.NHSpecificTest.NH3252" assembly="NHibernate.Test">
3+
<class name="Note">
4+
<id name="Id" type="Int32">
5+
<generator class="identity" />
6+
</id>
7+
<property name="Text" type="AnsiString" length="10000" />
8+
</class>
9+
</hibernate-mapping>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace NHibernate.Test.NHSpecificTest.NH3252
7+
{
8+
class Note
9+
{
10+
public virtual int Id { get; protected set; }
11+
12+
public virtual string Text { get; set; }
13+
}
14+
}

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,8 @@
801801
<Compile Include="NHSpecificTest\NH3428\Fixture.cs" />
802802
<Compile Include="NHSpecificTest\NH3316\ByCodeFixture.cs" />
803803
<Compile Include="NHSpecificTest\NH3316\Entity.cs" />
804+
<Compile Include="NHSpecificTest\NH3252\Fixture.cs" />
805+
<Compile Include="NHSpecificTest\NH3252\Note.cs" />
804806
<Compile Include="NHSpecificTest\NH3408\Fixture.cs" />
805807
<Compile Include="NHSpecificTest\NH3408\Model.cs" />
806808
<Compile Include="NHSpecificTest\NH2297\CustomCompositeUserType.cs" />
@@ -3163,6 +3165,7 @@
31633165
<EmbeddedResource Include="NHSpecificTest\NH3505\Mappings.hbm.xml" />
31643166
<EmbeddedResource Include="NHSpecificTest\NH3428\Mappings.hbm.xml" />
31653167
<EmbeddedResource Include="NHSpecificTest\NH3641\Mappings.hbm.xml" />
3168+
<EmbeddedResource Include="NHSpecificTest\NH3252\Mappings.hbm.xml" />
31663169
<EmbeddedResource Include="NHSpecificTest\NH3408\Mappings.hbm.xml" />
31673170
<EmbeddedResource Include="NHSpecificTest\NH2408\Mappings.hbm.xml" />
31683171
<EmbeddedResource Include="NHSpecificTest\NH2297\MappingsNames.hbm.xml" />

src/NHibernate/Driver/SqlClientDriver.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ protected static void SetDefaultParameterSize(IDbDataParameter dbParam, SqlType
122122
{
123123
case DbType.AnsiString:
124124
case DbType.AnsiStringFixedLength:
125-
dbParam.Size = MaxSizeForLengthLimitedAnsiString;
125+
dbParam.Size = IsAnsiText(dbParam, sqlType) ? MaxSizeForAnsiClob : MaxSizeForLengthLimitedAnsiString;
126126
break;
127127
case DbType.Binary:
128128
dbParam.Size = IsBlob(dbParam, sqlType) ? MaxSizeForBlob : MaxSizeForLengthLimitedBinary;
@@ -144,6 +144,17 @@ protected static void SetDefaultParameterSize(IDbDataParameter dbParam, SqlType
144144
}
145145
}
146146

147+
/// <summary>
148+
/// Interprets if a parameter is a Clob (for the purposes of setting its default size)
149+
/// </summary>
150+
/// <param name="dbParam">The parameter</param>
151+
/// <param name="sqlType">The <see cref="SqlType" /> of the parameter</param>
152+
/// <returns>True, if the parameter should be interpreted as a Clob, otherwise False</returns>
153+
protected static bool IsAnsiText(IDbDataParameter dbParam, SqlType sqlType)
154+
{
155+
return ((DbType.AnsiString == dbParam.DbType || DbType.AnsiStringFixedLength == dbParam.DbType) && sqlType.LengthDefined && (sqlType.Length > MaxSizeForLengthLimitedAnsiString));
156+
}
157+
147158
/// <summary>
148159
/// Interprets if a parameter is a Clob (for the purposes of setting its default size)
149160
/// </summary>

0 commit comments

Comments
 (0)