Skip to content

NH-3518 - Set default parameter size for DbType.Xml in SqlClientDriver #449

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

Merged
merged 1 commit into from
Dec 30, 2015
Merged
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
23 changes: 23 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3518/ClassWithXmlMember.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Xml;

namespace NHibernate.Test.NHSpecificTest.NH3518
{
public class ClassWithXmlMember
{
private int _id;

public ClassWithXmlMember(string name, XmlDocument xml)
{
Xml = xml;
this.Name = name;
}

private ClassWithXmlMember()
{
}

public string Name { get; private set; }

public XmlDocument Xml { get; private set; }
}
}
14 changes: 14 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3518/Mappings.hbm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="NHibernate.Test"
namespace="NHibernate.Test.NHSpecificTest.NH3518">

<class name="ClassWithXmlMember" lazy="false">
<id name="_id" access="field">
<generator class="native"/>
</id>
<property name="Name" />
<property name="Xml" />
</class>

</hibernate-mapping>
48 changes: 48 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3518/XmlColumnTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Xml;
using NHibernate.Cfg;
using NHibernate.Driver;
using NHibernate.Engine;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.NH3518
{
[TestFixture]
public class XmlColumnTest : BugTestCase
{
protected override void OnTearDown()
{
using (var session = sessions.OpenSession())
using (var t = session.BeginTransaction())
{
session.Delete("from ClassWithXmlMember");
t.Commit();
}
}

protected override bool AppliesTo(ISessionFactoryImplementor factory)
{
return factory.ConnectionProvider.Driver is SqlClientDriver;
}

protected override void Configure(Configuration configuration)
{
configuration.SetProperty(Environment.PrepareSql, "true");
}

[Test]
public void FilteredQuery()
{
var xmlDocument = new XmlDocument();
var xmlElement = xmlDocument.CreateElement("testXml");
xmlDocument.AppendChild(xmlElement);
var parentA = new ClassWithXmlMember("A", xmlDocument);

using (var s = sessions.OpenSession())
using (var t = s.BeginTransaction())
{
s.Save(parentA);
t.Commit();
}
}
}
}
3 changes: 3 additions & 0 deletions src/NHibernate.Test/NHibernate.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,8 @@
<Compile Include="NHSpecificTest\BagWithLazyExtraAndFilter\Fixture.cs" />
<Compile Include="Linq\ByMethod\DistinctTests.cs" />
<Compile Include="Component\Basic\ComponentWithUniqueConstraintTests.cs" />
<Compile Include="NHSpecificTest\NH3518\ClassWithXmlMember.cs" />
<Compile Include="NHSpecificTest\NH3518\XmlColumnTest.cs" />
<Compile Include="NHSpecificTest\NH3609\MappingEntity.cs" />
<Compile Include="NHSpecificTest\NH3609\Entity.cs" />
<Compile Include="NHSpecificTest\NH3609\Fixture.cs" />
Expand Down Expand Up @@ -3153,6 +3155,7 @@
<EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="NHSpecificTest\NH3518\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH3609\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH3818\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH3666\Mappings.hbm.xml">
Expand Down
5 changes: 5 additions & 0 deletions src/NHibernate/Driver/SqlClientDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class SqlClientDriver : DriverBase, IEmbeddedBatcherFactoryProvider
public const int MaxSizeForAnsiClob = 2147483647; // int.MaxValue
public const int MaxSizeForClob = 1073741823; // int.MaxValue / 2
public const int MaxSizeForBlob = 2147483647; // int.MaxValue
//http://stackoverflow.com/a/7264795/259946
public const int MaxSizeForXml = 2147483647; // int.MaxValue
public const int MaxSizeForLengthLimitedAnsiString = 8000;
public const int MaxSizeForLengthLimitedString = 4000;
public const int MaxSizeForLengthLimitedBinary = 8000;
Expand Down Expand Up @@ -141,6 +143,9 @@ protected static void SetDefaultParameterSize(IDbDataParameter dbParam, SqlType
case DbType.DateTimeOffset:
dbParam.Size = MaxDateTimeOffset;
break;
case DbType.Xml:
dbParam.Size = MaxSizeForXml;
break;
}
}

Expand Down