Skip to content

Move MsSql constants from driver to dialect. #1610

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
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
10 changes: 5 additions & 5 deletions src/NHibernate.Test/DialectTest/MsSql2005DialectFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ public void NH2809()
var t = d.GetTypeName(new BinarySqlType());
Assert.That(t, Is.EqualTo("VARBINARY(MAX)"));

t = d.GetTypeName(new BinarySqlType(), SqlClientDriver.MaxSizeForLengthLimitedBinary - 1, 0, 0);
Assert.That(t, Is.EqualTo(String.Format("VARBINARY({0})", SqlClientDriver.MaxSizeForLengthLimitedBinary - 1)));
t = d.GetTypeName(new BinarySqlType(), MsSql2000Dialect.MaxSizeForLengthLimitedBinary - 1, 0, 0);
Assert.That(t, Is.EqualTo(String.Format("VARBINARY({0})", MsSql2000Dialect.MaxSizeForLengthLimitedBinary - 1)));

t = d.GetTypeName(new BinarySqlType(), SqlClientDriver.MaxSizeForLengthLimitedBinary, 0, 0);
Assert.That(t, Is.EqualTo(String.Format("VARBINARY({0})", SqlClientDriver.MaxSizeForLengthLimitedBinary)));
t = d.GetTypeName(new BinarySqlType(), MsSql2000Dialect.MaxSizeForLengthLimitedBinary, 0, 0);
Assert.That(t, Is.EqualTo(String.Format("VARBINARY({0})", MsSql2000Dialect.MaxSizeForLengthLimitedBinary)));

t = d.GetTypeName(new BinarySqlType(), SqlClientDriver.MaxSizeForLengthLimitedBinary + 1, 0, 0);
t = d.GetTypeName(new BinarySqlType(), MsSql2000Dialect.MaxSizeForLengthLimitedBinary + 1, 0, 0);
Assert.That(t, Is.EqualTo("VARBINARY(MAX)"));
}

Expand Down
27 changes: 18 additions & 9 deletions src/NHibernate/Dialect/MsSql2000Dialect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Text.RegularExpressions;
using NHibernate.Dialect.Function;
using NHibernate.Dialect.Schema;
using NHibernate.Driver;
using NHibernate.Engine;
using NHibernate.Mapping;
using NHibernate.SqlCommand;
Expand Down Expand Up @@ -42,6 +41,16 @@ namespace NHibernate.Dialect
/// </remarks>
public class MsSql2000Dialect : Dialect
{
public const int MaxSizeForAnsiClob = 2147483647; // int.MaxValue
public const int MaxSizeForClob = 1073741823; // int.MaxValue / 2
public const int MaxSizeForBlob = 2147483647; // int.MaxValue

public const int MaxSizeForLengthLimitedAnsiString = 8000;
public const int MaxSizeForLengthLimitedString = 4000;
public const int MaxSizeForLengthLimitedBinary = 8000;
public const byte MaxDateTime2 = 8;
public const byte MaxDateTimeOffset = 10;

public MsSql2000Dialect()
{
RegisterCharacterTypeMappings();
Expand Down Expand Up @@ -358,8 +367,8 @@ protected virtual void RegisterGuidTypeMapping()
protected virtual void RegisterLargeObjectTypeMappings()
{
RegisterColumnType(DbType.Binary, "VARBINARY(8000)");
RegisterColumnType(DbType.Binary, SqlClientDriver.MaxSizeForLengthLimitedBinary, "VARBINARY($l)");
RegisterColumnType(DbType.Binary, SqlClientDriver.MaxSizeForBlob, "IMAGE");
RegisterColumnType(DbType.Binary, MaxSizeForLengthLimitedBinary, "VARBINARY($l)");
RegisterColumnType(DbType.Binary, MaxSizeForBlob, "IMAGE");
}

protected virtual void RegisterDateTimeTypeMappings()
Expand Down Expand Up @@ -389,13 +398,13 @@ protected virtual void RegisterCharacterTypeMappings()
RegisterColumnType(DbType.AnsiStringFixedLength, "CHAR(255)");
RegisterColumnType(DbType.AnsiStringFixedLength, 8000, "CHAR($l)");
RegisterColumnType(DbType.AnsiString, "VARCHAR(255)");
RegisterColumnType(DbType.AnsiString, SqlClientDriver.MaxSizeForLengthLimitedAnsiString, "VARCHAR($l)");
RegisterColumnType(DbType.AnsiString, SqlClientDriver.MaxSizeForAnsiClob, "TEXT");
RegisterColumnType(DbType.AnsiString, MaxSizeForLengthLimitedAnsiString, "VARCHAR($l)");
RegisterColumnType(DbType.AnsiString, MaxSizeForAnsiClob, "TEXT");
RegisterColumnType(DbType.StringFixedLength, "NCHAR(255)");
RegisterColumnType(DbType.StringFixedLength, SqlClientDriver.MaxSizeForLengthLimitedString, "NCHAR($l)");
RegisterColumnType(DbType.StringFixedLength, MaxSizeForLengthLimitedString, "NCHAR($l)");
RegisterColumnType(DbType.String, "NVARCHAR(255)");
RegisterColumnType(DbType.String, SqlClientDriver.MaxSizeForLengthLimitedString, "NVARCHAR($l)");
RegisterColumnType(DbType.String, SqlClientDriver.MaxSizeForClob, "NTEXT");
RegisterColumnType(DbType.String, MaxSizeForLengthLimitedString, "NVARCHAR($l)");
RegisterColumnType(DbType.String, MaxSizeForClob, "NTEXT");
}

public override string AddColumnString
Expand Down Expand Up @@ -447,7 +456,7 @@ public override string GetDropTableString(string tableName)
"if exists (select * from dbo.sysobjects where id = object_id(N'{0}') and OBJECTPROPERTY(id, N'IsUserTable') = 1)" +
" drop table {0}";

return String.Format(dropTable, tableName);
return string.Format(dropTable, tableName);
}

public override string ForUpdateString
Expand Down
12 changes: 7 additions & 5 deletions src/NHibernate/Dialect/MsSql2005Dialect.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Data;
using NHibernate.Driver;
using NHibernate.Mapping;
using NHibernate.SqlCommand;
using NHibernate.Util;
Expand All @@ -8,6 +7,9 @@ namespace NHibernate.Dialect
{
public class MsSql2005Dialect : MsSql2000Dialect
{
///<remarks>http://stackoverflow.com/a/7264795/259946</remarks>
public const int MaxSizeForXml = 2147483647; // int.MaxValue

public MsSql2005Dialect()
{
RegisterColumnType(DbType.Xml, "XML");
Expand All @@ -16,16 +18,16 @@ public MsSql2005Dialect()
protected override void RegisterCharacterTypeMappings()
{
base.RegisterCharacterTypeMappings();
RegisterColumnType(DbType.String, SqlClientDriver.MaxSizeForClob, "NVARCHAR(MAX)");
RegisterColumnType(DbType.AnsiString, SqlClientDriver.MaxSizeForAnsiClob, "VARCHAR(MAX)");
RegisterColumnType(DbType.String, MaxSizeForClob, "NVARCHAR(MAX)");
RegisterColumnType(DbType.AnsiString, MaxSizeForAnsiClob, "VARCHAR(MAX)");
}

protected override void RegisterLargeObjectTypeMappings()
{
base.RegisterLargeObjectTypeMappings();
RegisterColumnType(DbType.Binary, "VARBINARY(MAX)");
RegisterColumnType(DbType.Binary, SqlClientDriver.MaxSizeForLengthLimitedBinary, "VARBINARY($l)");
RegisterColumnType(DbType.Binary, SqlClientDriver.MaxSizeForBlob, "VARBINARY(MAX)");
RegisterColumnType(DbType.Binary, MaxSizeForLengthLimitedBinary, "VARBINARY($l)");
RegisterColumnType(DbType.Binary, MaxSizeForBlob, "VARBINARY(MAX)");
}

protected override void RegisterKeywords()
Expand Down
4 changes: 2 additions & 2 deletions src/NHibernate/Driver/DB2400Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace NHibernate.Driver
public class DB2400Driver : ReflectionBasedDriver
{
/// <summary>
/// Initializes a new instance of the <see cref="DB2Driver"/> class.
/// Initializes a new instance of the <see cref="DB2400Driver"/> class.
/// </summary>
/// <exception cref="HibernateException">
/// Thrown when the <c>IBM.Data.DB2.iSeries</c> assembly can not be loaded.
Expand Down Expand Up @@ -40,4 +40,4 @@ public override bool SupportsMultipleOpenReaders
get { return false; }
}
}
}
}
22 changes: 6 additions & 16 deletions src/NHibernate/Driver/FirebirdClientDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public class FirebirdClientDriver : ReflectionBasedDriver
{
private const string SELECT_CLAUSE_EXP = @"(?<=\bselect|\bwhere).*";
private const string CAST_PARAMS_EXP = @"(?<![=<>]\s?|first\s?|skip\s?|between\s|between\s@\bp\w+\b\sand\s)@\bp\w+\b(?!\s?[=<>])";
private readonly Regex _statementRegEx = new Regex(SELECT_CLAUSE_EXP, RegexOptions.IgnoreCase);
private readonly Regex _castCandidateRegEx = new Regex(CAST_PARAMS_EXP, RegexOptions.IgnoreCase);
private static readonly Regex _statementRegEx = new Regex(SELECT_CLAUSE_EXP, RegexOptions.IgnoreCase);
private static readonly Regex _castCandidateRegEx = new Regex(CAST_PARAMS_EXP, RegexOptions.IgnoreCase);
private readonly FirebirdDialect _fbDialect = new FirebirdDialect();

/// <summary>
Expand All @@ -37,7 +37,6 @@ public FirebirdClientDriver()
"FirebirdSql.Data.FirebirdClient.FbConnection",
"FirebirdSql.Data.FirebirdClient.FbCommand")
{

}

public override void Configure(IDictionary<string, string> settings)
Expand All @@ -46,20 +45,11 @@ public override void Configure(IDictionary<string, string> settings)
_fbDialect.Configure(settings);
}

public override bool UseNamedPrefixInSql
{
get { return true; }
}
public override bool UseNamedPrefixInSql => true;

public override bool UseNamedPrefixInParameter
{
get { return true; }
}
public override bool UseNamedPrefixInParameter => true;

public override string NamedPrefix
{
get { return "@"; }
}
public override string NamedPrefix => "@";

protected override void InitializeParameter(DbParameter dbParam, string name, SqlType sqlType)
{
Expand Down Expand Up @@ -96,7 +86,7 @@ private string GetStatementsWithCastCandidates(string commandText)
return _statementRegEx.Match(commandText).Value;
}

private HashSet<string> GetCastCandidates(string statement)
private static HashSet<string> GetCastCandidates(string statement)
{
var candidates =
_castCandidateRegEx
Expand Down
30 changes: 6 additions & 24 deletions src/NHibernate/Driver/MySqlDataDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,23 @@ public MySqlDataDriver() : base(
/// MySql.Data uses named parameters in the sql.
/// </summary>
/// <value><see langword="true" /> - MySql uses <c>?</c> in the sql.</value>
public override bool UseNamedPrefixInSql
{
get { return true; }
}
public override bool UseNamedPrefixInSql => true;

/// <summary></summary>
public override bool UseNamedPrefixInParameter
{
get { return true; }
}
public override bool UseNamedPrefixInParameter => true;

/// <summary>
/// MySql.Data use the <c>?</c> to locate parameters in sql.
/// </summary>
/// <value><c>?</c> is used to locate parameters in sql.</value>
public override string NamedPrefix
{
get { return "?"; }
}
public override string NamedPrefix => "?";

/// <summary>
/// The MySql.Data driver does NOT support more than 1 open DbDataReader
/// with only 1 DbConnection.
/// </summary>
/// <value><see langword="false" /> - it is not supported.</value>
public override bool SupportsMultipleOpenReaders
{
get { return false; }
}
public override bool SupportsMultipleOpenReaders => false;

/// <summary>
/// MySql.Data does not support preparing of commands.
Expand All @@ -75,20 +63,14 @@ public override bool SupportsMultipleOpenReaders
/// With the Gamma MySql.Data provider it is throwing an exception with the
/// message "Expected End of data packet" when a select command is prepared.
/// </remarks>
protected override bool SupportsPreparingCommands
{
get { return false; }
}
protected override bool SupportsPreparingCommands => false;

public override IResultSetsCommand GetResultSetsCommand(Engine.ISessionImplementor session)
{
return new BasicResultSetsCommand(session);
}

public override bool SupportsMultipleQueries
{
get { return true; }
}
public override bool SupportsMultipleQueries => true;

public override bool RequiresTimeSpanForTime => true;

Expand Down
34 changes: 9 additions & 25 deletions src/NHibernate/Driver/NpgsqlDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,18 @@ public NpgsqlDriver() : base(
{
}

public override bool UseNamedPrefixInSql
{
get { return true; }
}
public override bool UseNamedPrefixInSql => true;

public override bool UseNamedPrefixInParameter
{
get { return true; }
}
public override bool UseNamedPrefixInParameter => true;

public override string NamedPrefix
{
get { return ":"; }
}
public override string NamedPrefix => ":";

public override bool SupportsMultipleOpenReaders
{
get { return false; }
}
public override bool SupportsMultipleOpenReaders => false;

protected override bool SupportsPreparingCommands
{
// NH-2267 Patrick Earl
get { return true; }
}
/// <remarks>
/// NH-2267 Patrick Earl
/// </remarks>
protected override bool SupportsPreparingCommands => true;

public override bool SupportsNullEnlistment => false;

Expand All @@ -74,10 +61,7 @@ public override IResultSetsCommand GetResultSetsCommand(Engine.ISessionImplement
return new BasicResultSetsCommand(session);
}

public override bool SupportsMultipleQueries
{
get { return true; }
}
public override bool SupportsMultipleQueries => true;

protected override void InitializeParameter(DbParameter dbParam, string name, SqlTypes.SqlType sqlType)
{
Expand Down
1 change: 0 additions & 1 deletion src/NHibernate/Driver/OracleDataClientDriverBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Reflection;
using NHibernate.AdoNet;
using NHibernate.Engine.Query;
using NHibernate.SqlTypes;
Expand Down
67 changes: 26 additions & 41 deletions src/NHibernate/Driver/SQLite20Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,58 +35,43 @@ public SQLite20Driver() : base(
{
}

public override DbConnection CreateConnection()
{
var connection = base.CreateConnection();
connection.StateChange += Connection_StateChange;
return connection;
}

private static void Connection_StateChange(object sender, StateChangeEventArgs e)
{
if ((e.OriginalState == ConnectionState.Broken || e.OriginalState == ConnectionState.Closed || e.OriginalState == ConnectionState.Connecting) &&
e.CurrentState == ConnectionState.Open)
{
var connection = (DbConnection)sender;
using (var command = connection.CreateCommand())
{
// Activated foreign keys if supported by SQLite. Unknown pragmas are ignored.
command.CommandText = "PRAGMA foreign_keys = ON";
command.ExecuteNonQuery();
}
}
}

public override bool UseNamedPrefixInSql
{
get { return true; }
}

public override bool UseNamedPrefixInParameter
{
get { return true; }
}

public override string NamedPrefix
public override DbConnection CreateConnection()
{
get { return "@"; }
var connection = base.CreateConnection();
connection.StateChange += Connection_StateChange;
return connection;
}

public override bool SupportsMultipleOpenReaders
private static void Connection_StateChange(object sender, StateChangeEventArgs e)
{
get { return false; }
if ((e.OriginalState == ConnectionState.Broken || e.OriginalState == ConnectionState.Closed || e.OriginalState == ConnectionState.Connecting) &&
e.CurrentState == ConnectionState.Open)
{
var connection = (DbConnection)sender;
using (var command = connection.CreateCommand())
{
// Activated foreign keys if supported by SQLite. Unknown pragmas are ignored.
command.CommandText = "PRAGMA foreign_keys = ON";
command.ExecuteNonQuery();
}
}
}

public override IResultSetsCommand GetResultSetsCommand(Engine.ISessionImplementor session)
{
return new BasicResultSetsCommand(session);
}

public override bool SupportsMultipleQueries
{
get { return true; }
}

public override bool UseNamedPrefixInSql => true;

public override bool UseNamedPrefixInParameter => true;

public override string NamedPrefix => "@";

public override bool SupportsMultipleOpenReaders => false;

public override bool SupportsMultipleQueries => true;

public override bool SupportsNullEnlistment => false;

public override bool HasDelayedDistributedTransactionCompletion => true;
Expand Down
Loading