Skip to content

Commit a33d88e

Browse files
authored
Merge pull request #710 from nhibernate/prepare_sql
Fixes with prepare_sql
2 parents 4045925 + 5c01806 commit a33d88e

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

src/NHibernate.Test/Async/NHSpecificTest/SqlConverterAndMultiQuery/Fixture.cs

+8-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010

1111
using NHibernate.Cfg;
12-
using NHibernate.Dialect;
12+
using NHibernate.Driver;
13+
using NHibernate.Engine;
1314
using NUnit.Framework;
1415

1516
namespace NHibernate.Test.NHSpecificTest.SqlConverterAndMultiQuery
@@ -25,11 +26,13 @@ protected override void Configure(Configuration configuration)
2526
configuration.DataBaseIntegration(x => x.ExceptionConverter<SqlConverter>());
2627
}
2728

28-
protected override bool AppliesTo(Dialect.Dialect dialect)
29+
protected override bool AppliesTo(ISessionFactoryImplementor factory)
2930
{
30-
// MsSqlCe throws InvalidOperationException instead of a DbException for these tests, preventing
31-
// the test SqlConverter to do its job.
32-
return !(Dialect is MsSqlCeDialect);
31+
// Test current implementation allows to test mmostly SQL Server. Other databases
32+
// tend to (validly) send InvalidOperationException during prepare phase due to the closed
33+
// connection, which get not converted. For testing other case, maybe a failure caused by a
34+
// schema mismatch (like done in transaction tests) would be better.
35+
return factory.ConnectionProvider.Driver is SqlClientDriver;
3336
}
3437

3538
[Test]

src/NHibernate.Test/NHSpecificTest/SqlConverterAndMultiQuery/Fixture.cs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using NHibernate.Cfg;
2-
using NHibernate.Dialect;
2+
using NHibernate.Driver;
3+
using NHibernate.Engine;
34
using NUnit.Framework;
45

56
namespace NHibernate.Test.NHSpecificTest.SqlConverterAndMultiQuery
@@ -14,11 +15,13 @@ protected override void Configure(Configuration configuration)
1415
configuration.DataBaseIntegration(x => x.ExceptionConverter<SqlConverter>());
1516
}
1617

17-
protected override bool AppliesTo(Dialect.Dialect dialect)
18+
protected override bool AppliesTo(ISessionFactoryImplementor factory)
1819
{
19-
// MsSqlCe throws InvalidOperationException instead of a DbException for these tests, preventing
20-
// the test SqlConverter to do its job.
21-
return !(Dialect is MsSqlCeDialect);
20+
// Test current implementation allows to test mmostly SQL Server. Other databases
21+
// tend to (validly) send InvalidOperationException during prepare phase due to the closed
22+
// connection, which get not converted. For testing other case, maybe a failure caused by a
23+
// schema mismatch (like done in transaction tests) would be better.
24+
return factory.ConnectionProvider.Driver is SqlClientDriver;
2225
}
2326

2427
[Test]

src/NHibernate/Driver/Sql2008ClientDriver.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22
using System.Data;
33
using System.Data.Common;
44
using System.Data.SqlClient;
5-
using System.Linq;
65

76
namespace NHibernate.Driver
87
{
98
public class Sql2008ClientDriver : SqlClientDriver
109
{
10+
const byte MaxTime = 5;
11+
1112
protected override void InitializeParameter(DbParameter dbParam, string name, SqlTypes.SqlType sqlType)
1213
{
1314
base.InitializeParameter(dbParam, name, sqlType);
1415
switch (sqlType.DbType)
1516
{
1617
case DbType.Time:
1718
((SqlParameter) dbParam).SqlDbType = SqlDbType.Time;
19+
dbParam.Size = MaxTime;
1820
break;
1921
case DbType.Date:
2022
((SqlParameter) dbParam).SqlDbType = SqlDbType.Date;

src/NHibernate/Driver/SqlClientDriver.cs

-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ protected override void InitializeParameter(DbParameter dbParam, string name, Sq
100100
SetVariableLengthParameterSize(dbParam, sqlType);
101101
}
102102

103-
// Used from SqlServerCeDriver as well
104103
public static void SetVariableLengthParameterSize(DbParameter dbParam, SqlType sqlType)
105104
{
106105
SetDefaultParameterSize(dbParam, sqlType);

src/NHibernate/Driver/SqlServerCeDriver.cs

-8
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
using System.Data.Common;
55
using System.Reflection;
66
using NHibernate.SqlTypes;
7-
using NHibernate.Util;
8-
using Environment = NHibernate.Cfg.Environment;
97

108
namespace NHibernate.Driver
119
{
@@ -25,13 +23,11 @@ public SqlServerCeDriver()
2523
{
2624
}
2725

28-
private bool prepareSql;
2926
private PropertyInfo dbParamSqlDbTypeProperty;
3027

3128
public override void Configure(IDictionary<string, string> settings)
3229
{
3330
base.Configure(settings);
34-
prepareSql = PropertiesHelper.GetBoolean(Environment.PrepareSql, settings, false);
3531

3632
using (var cmd = CreateCommand())
3733
{
@@ -102,10 +98,6 @@ protected override void InitializeParameter(DbParameter dbParam, string name, Sq
10298
base.InitializeParameter(dbParam, name, AdjustSqlType(sqlType));
10399

104100
AdjustDbParamTypeForLargeObjects(dbParam, sqlType);
105-
if (prepareSql)
106-
{
107-
SqlClientDriver.SetVariableLengthParameterSize(dbParam, sqlType);
108-
}
109101
}
110102

111103
private static SqlType AdjustSqlType(SqlType sqlType)

0 commit comments

Comments
 (0)