Skip to content

Commit

Permalink
Merge pull request #710 from nhibernate/prepare_sql
Browse files Browse the repository at this point in the history
Fixes with prepare_sql
  • Loading branch information
hazzik authored Oct 10, 2017
2 parents 4045925 + 5c01806 commit a33d88e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@


using NHibernate.Cfg;
using NHibernate.Dialect;
using NHibernate.Driver;
using NHibernate.Engine;
using NUnit.Framework;

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

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

[Test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using NHibernate.Cfg;
using NHibernate.Dialect;
using NHibernate.Driver;
using NHibernate.Engine;
using NUnit.Framework;

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

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

[Test]
Expand Down
4 changes: 3 additions & 1 deletion src/NHibernate/Driver/Sql2008ClientDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;

namespace NHibernate.Driver
{
public class Sql2008ClientDriver : SqlClientDriver
{
const byte MaxTime = 5;

protected override void InitializeParameter(DbParameter dbParam, string name, SqlTypes.SqlType sqlType)
{
base.InitializeParameter(dbParam, name, sqlType);
switch (sqlType.DbType)
{
case DbType.Time:
((SqlParameter) dbParam).SqlDbType = SqlDbType.Time;
dbParam.Size = MaxTime;
break;
case DbType.Date:
((SqlParameter) dbParam).SqlDbType = SqlDbType.Date;
Expand Down
1 change: 0 additions & 1 deletion src/NHibernate/Driver/SqlClientDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ protected override void InitializeParameter(DbParameter dbParam, string name, Sq
SetVariableLengthParameterSize(dbParam, sqlType);
}

// Used from SqlServerCeDriver as well
public static void SetVariableLengthParameterSize(DbParameter dbParam, SqlType sqlType)
{
SetDefaultParameterSize(dbParam, sqlType);
Expand Down
8 changes: 0 additions & 8 deletions src/NHibernate/Driver/SqlServerCeDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using System.Data.Common;
using System.Reflection;
using NHibernate.SqlTypes;
using NHibernate.Util;
using Environment = NHibernate.Cfg.Environment;

namespace NHibernate.Driver
{
Expand All @@ -25,13 +23,11 @@ public SqlServerCeDriver()
{
}

private bool prepareSql;
private PropertyInfo dbParamSqlDbTypeProperty;

public override void Configure(IDictionary<string, string> settings)
{
base.Configure(settings);
prepareSql = PropertiesHelper.GetBoolean(Environment.PrepareSql, settings, false);

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

AdjustDbParamTypeForLargeObjects(dbParam, sqlType);
if (prepareSql)
{
SqlClientDriver.SetVariableLengthParameterSize(dbParam, sqlType);
}
}

private static SqlType AdjustSqlType(SqlType sqlType)
Expand Down

0 comments on commit a33d88e

Please sign in to comment.