Skip to content

Fix NH-3252 #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3252/Fixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using NHibernate.Linq;

namespace NHibernate.Test.NHSpecificTest.NH3252
{
[TestFixture]
public class Fixture : TestCase
{
protected override string MappingsAssembly
{
get { return "NHibernate.Test"; }
}

protected override IList Mappings
{
get { return new string[] { "NHSpecificTest.NH3252.Mappings.hbm.xml" }; }
}

[Test]
public void VerifyThatWeCanSaveAndLoad()
{
using (ISession session = OpenSession())
using (ITransaction transaction = session.BeginTransaction())
{

session.Save(new Note { Text = new String('0', 9000) });
transaction.Commit();
}

using (ISession session = OpenSession())
using (ITransaction transaction = session.BeginTransaction())
{

var note = session.Query<Note>().First();
Assert.AreEqual(9000, note.Text.Length);
}
}

protected override void OnTearDown()
{
using (ISession session = OpenSession())
using (ITransaction transaction = session.BeginTransaction())
{
session.Delete("from System.Object");

session.Flush();
transaction.Commit();
}
}
}
}
9 changes: 9 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3252/Mappings.hbm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernate.Test.NHSpecificTest.NH3252" assembly="NHibernate.Test">
<class name="Note">
<id name="Id" type="Int32">
<generator class="identity" />
</id>
<property name="Text" type="AnsiString" length="10000" />
</class>
</hibernate-mapping>
14 changes: 14 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3252/Note.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NHibernate.Test.NHSpecificTest.NH3252
{
class Note
{
public virtual int Id { get; protected set; }

public virtual string Text { get; set; }
}
}
3 changes: 3 additions & 0 deletions src/NHibernate.Test/NHibernate.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,8 @@
<Compile Include="NHSpecificTest\BagWithLazyExtraAndFilter\Domain.cs" />
<Compile Include="NHSpecificTest\BagWithLazyExtraAndFilter\Fixture.cs" />
<Compile Include="Component\Basic\ComponentWithUniqueConstraintTests.cs" />
<Compile Include="NHSpecificTest\NH3252\Fixture.cs" />
<Compile Include="NHSpecificTest\NH3252\Note.cs" />
<Compile Include="NHSpecificTest\NH3408\Fixture.cs" />
<Compile Include="NHSpecificTest\NH3408\Model.cs" />
<Compile Include="NHSpecificTest\NH2297\CustomCompositeUserType.cs" />
Expand Down Expand Up @@ -2882,6 +2884,7 @@
<EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="NHSpecificTest\NH3252\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH3408\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2408\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2297\MappingsNames.hbm.xml" />
Expand Down
17 changes: 14 additions & 3 deletions src/NHibernate/Driver/SqlClientDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ protected static void SetDefaultParameterSize(IDbDataParameter dbParam, SqlType
switch (dbParam.DbType)
{
case DbType.AnsiString:
case DbType.AnsiStringFixedLength:
dbParam.Size = MaxSizeForLengthLimitedAnsiString;
case DbType.AnsiStringFixedLength:
dbParam.Size = IsAnsiText(dbParam, sqlType) ? MaxSizeForAnsiClob : MaxSizeForLengthLimitedAnsiString;
break;
case DbType.Binary:
dbParam.Size = IsBlob(dbParam, sqlType) ? MaxSizeForBlob : MaxSizeForLengthLimitedBinary;
Expand All @@ -154,7 +154,18 @@ protected static void SetDefaultParameterSize(IDbDataParameter dbParam, SqlType
dbParam.Size = MaxDateTimeOffset;
break;
}
}
}

/// <summary>
/// Interprets if a parameter is a Clob (for the purposes of setting its default size)
/// </summary>
/// <param name="dbParam">The parameter</param>
/// <param name="sqlType">The <see cref="SqlType" /> of the parameter</param>
/// <returns>True, if the parameter should be interpreted as a Clob, otherwise False</returns>
protected static bool IsAnsiText(IDbDataParameter dbParam, SqlType sqlType)
{
return ((DbType.AnsiString == dbParam.DbType || DbType.AnsiStringFixedLength == dbParam.DbType) && sqlType.LengthDefined && (sqlType.Length > MaxSizeForLengthLimitedAnsiString));
}

/// <summary>
/// Interprets if a parameter is a Clob (for the purposes of setting its default size)
Expand Down