Skip to content

Commit 23516e2

Browse files
committed
NH-3518 - Set default parameter size for DbType.Xml in SqlClientDriver
1 parent ddeb12f commit 23516e2

File tree

5 files changed

+93
-0
lines changed

5 files changed

+93
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Xml;
2+
3+
namespace NHibernate.Test.NHSpecificTest.NH3518
4+
{
5+
public class ClassWithXmlMember
6+
{
7+
private int _id;
8+
9+
public ClassWithXmlMember(string name, XmlDocument xml)
10+
{
11+
Xml = xml;
12+
this.Name = name;
13+
}
14+
15+
private ClassWithXmlMember()
16+
{
17+
}
18+
19+
public string Name { get; private set; }
20+
21+
public XmlDocument Xml { get; private set; }
22+
}
23+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
3+
assembly="NHibernate.Test"
4+
namespace="NHibernate.Test.NHSpecificTest.NH3518">
5+
6+
<class name="ClassWithXmlMember" lazy="false">
7+
<id name="_id" access="field">
8+
<generator class="native"/>
9+
</id>
10+
<property name="Name" />
11+
<property name="Xml" />
12+
</class>
13+
14+
</hibernate-mapping>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System.Xml;
2+
using NHibernate.Cfg;
3+
using NHibernate.Driver;
4+
using NHibernate.Engine;
5+
using NUnit.Framework;
6+
7+
namespace NHibernate.Test.NHSpecificTest.NH3518
8+
{
9+
[TestFixture]
10+
public class XmlColumnTest : BugTestCase
11+
{
12+
protected override void OnTearDown()
13+
{
14+
using (var session = sessions.OpenSession())
15+
using (var t = session.BeginTransaction())
16+
{
17+
session.Delete("from ClassWithXmlMember");
18+
t.Commit();
19+
}
20+
}
21+
22+
protected override bool AppliesTo(ISessionFactoryImplementor factory)
23+
{
24+
return factory.ConnectionProvider.Driver is SqlClientDriver;
25+
}
26+
27+
protected override void Configure(Configuration configuration)
28+
{
29+
configuration.SetProperty(Environment.PrepareSql, "true");
30+
}
31+
32+
[Test]
33+
public void FilteredQuery()
34+
{
35+
var xmlDocument = new XmlDocument();
36+
var xmlElement = xmlDocument.CreateElement("testXml");
37+
xmlDocument.AppendChild(xmlElement);
38+
var parentA = new ClassWithXmlMember("A", xmlDocument);
39+
40+
using (var s = sessions.OpenSession())
41+
using (var t = s.BeginTransaction())
42+
{
43+
s.Save(parentA);
44+
t.Commit();
45+
}
46+
}
47+
}
48+
}

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,8 @@
718718
<Compile Include="NHSpecificTest\BagWithLazyExtraAndFilter\Fixture.cs" />
719719
<Compile Include="Linq\ByMethod\DistinctTests.cs" />
720720
<Compile Include="Component\Basic\ComponentWithUniqueConstraintTests.cs" />
721+
<Compile Include="NHSpecificTest\NH3518\ClassWithXmlMember.cs" />
722+
<Compile Include="NHSpecificTest\NH3518\XmlColumnTest.cs" />
721723
<Compile Include="NHSpecificTest\NH3609\MappingEntity.cs" />
722724
<Compile Include="NHSpecificTest\NH3609\Entity.cs" />
723725
<Compile Include="NHSpecificTest\NH3609\Fixture.cs" />
@@ -3153,6 +3155,7 @@
31533155
<EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" />
31543156
</ItemGroup>
31553157
<ItemGroup>
3158+
<EmbeddedResource Include="NHSpecificTest\NH3518\Mappings.hbm.xml" />
31563159
<EmbeddedResource Include="NHSpecificTest\NH3609\Mappings.hbm.xml" />
31573160
<EmbeddedResource Include="NHSpecificTest\NH3818\Mappings.hbm.xml" />
31583161
<EmbeddedResource Include="NHSpecificTest\NH3666\Mappings.hbm.xml">

src/NHibernate/Driver/SqlClientDriver.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class SqlClientDriver : DriverBase, IEmbeddedBatcherFactoryProvider
1515
public const int MaxSizeForAnsiClob = 2147483647; // int.MaxValue
1616
public const int MaxSizeForClob = 1073741823; // int.MaxValue / 2
1717
public const int MaxSizeForBlob = 2147483647; // int.MaxValue
18+
//http://stackoverflow.com/a/7264795/259946
19+
public const int MaxSizeForXml = 2147483647; // int.MaxValue
1820
public const int MaxSizeForLengthLimitedAnsiString = 8000;
1921
public const int MaxSizeForLengthLimitedString = 4000;
2022
public const int MaxSizeForLengthLimitedBinary = 8000;
@@ -141,6 +143,9 @@ protected static void SetDefaultParameterSize(IDbDataParameter dbParam, SqlType
141143
case DbType.DateTimeOffset:
142144
dbParam.Size = MaxDateTimeOffset;
143145
break;
146+
case DbType.Xml:
147+
dbParam.Size = MaxSizeForXml;
148+
break;
144149
}
145150
}
146151

0 commit comments

Comments
 (0)