|
From: <jul...@us...> - 2011-01-24 15:51:57
|
Revision: 5367
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5367&view=rev
Author: julian-maughan
Date: 2011-01-24 15:51:51 +0000 (Mon, 24 Jan 2011)
Log Message:
-----------
Changed SqlClientDriver to push out the parameter size to int.MaxValue/2147483647 if the IType is, 1) a BinaryType with internal SqlType Length greater than 8000, or 2) a BinaryBlobType. Blobs and Clobs are now handled similarly by the driver [ref. NH-2484]
Updated SqlClientDriverFixture dialect - so tests execute on MS SQL Server 2008.
Also performed some light refactoring of the driver: no functional changes, for readability.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs
trunk/nhibernate/src/NHibernate/Dialect/MsSql2005Dialect.cs
trunk/nhibernate/src/NHibernate/Driver/SqlClientDriver.cs
trunk/nhibernate/src/NHibernate.Test/DriverTest/SqlClientDriverFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs 2011-01-23 19:45:35 UTC (rev 5366)
+++ trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs 2011-01-24 15:51:51 UTC (rev 5367)
@@ -5,6 +5,7 @@
using System.Text.RegularExpressions;
using NHibernate.Dialect.Function;
using NHibernate.Dialect.Schema;
+using NHibernate.Driver;
using NHibernate.Engine;
using NHibernate.Mapping;
using NHibernate.SqlCommand;
@@ -40,18 +41,16 @@
/// </remarks>
public class MsSql2000Dialect : Dialect
{
- public const int MaxSizeForLengthLimitedStrings = 4000;
- /// <summary></summary>
public MsSql2000Dialect()
{
RegisterColumnType(DbType.AnsiStringFixedLength, "CHAR(255)");
RegisterColumnType(DbType.AnsiStringFixedLength, 8000, "CHAR($l)");
RegisterColumnType(DbType.AnsiString, "VARCHAR(255)");
- RegisterColumnType(DbType.AnsiString, 8000, "VARCHAR($l)");
- RegisterColumnType(DbType.AnsiString, 2147483647, "TEXT");
+ RegisterColumnType(DbType.AnsiString, SqlClientDriver.MaxSizeForLengthLimitedAnsiString, "VARCHAR($l)");
+ RegisterColumnType(DbType.AnsiString, SqlClientDriver.MaxSizeForAnsiClob, "TEXT");
RegisterColumnType(DbType.Binary, "VARBINARY(8000)");
- RegisterColumnType(DbType.Binary, 8000, "VARBINARY($l)");
- RegisterColumnType(DbType.Binary, 2147483647, "IMAGE");
+ RegisterColumnType(DbType.Binary, SqlClientDriver.MaxSizeForLengthLimitedBinary, "VARBINARY($l)");
+ RegisterColumnType(DbType.Binary, SqlClientDriver.MaxSizeForBlob, "IMAGE");
RegisterColumnType(DbType.Boolean, "BIT");
RegisterColumnType(DbType.Byte, "TINYINT");
RegisterColumnType(DbType.Currency, "MONEY");
@@ -66,10 +65,10 @@
RegisterColumnType(DbType.Int64, "BIGINT");
RegisterColumnType(DbType.Single, "REAL"); //synonym for FLOAT(24)
RegisterColumnType(DbType.StringFixedLength, "NCHAR(255)");
- RegisterColumnType(DbType.StringFixedLength, MaxSizeForLengthLimitedStrings, "NCHAR($l)");
+ RegisterColumnType(DbType.StringFixedLength, SqlClientDriver.MaxSizeForLengthLimitedString, "NCHAR($l)");
RegisterColumnType(DbType.String, "NVARCHAR(255)");
- RegisterColumnType(DbType.String, MaxSizeForLengthLimitedStrings, "NVARCHAR($l)");
- RegisterColumnType(DbType.String, 1073741823, "NTEXT");
+ RegisterColumnType(DbType.String, SqlClientDriver.MaxSizeForLengthLimitedString, "NVARCHAR($l)");
+ RegisterColumnType(DbType.String, SqlClientDriver.MaxSizeForClob, "NTEXT");
RegisterColumnType(DbType.Time, "DATETIME");
RegisterFunction("count", new CountBigQueryFunction());
Modified: trunk/nhibernate/src/NHibernate/Dialect/MsSql2005Dialect.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Dialect/MsSql2005Dialect.cs 2011-01-23 19:45:35 UTC (rev 5366)
+++ trunk/nhibernate/src/NHibernate/Dialect/MsSql2005Dialect.cs 2011-01-24 15:51:51 UTC (rev 5367)
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Data;
+using NHibernate.Driver;
using NHibernate.Mapping;
using NHibernate.SqlCommand;
using NHibernate.Util;
@@ -11,9 +12,9 @@
{
public MsSql2005Dialect()
{
- RegisterColumnType(DbType.String, 1073741823, "NVARCHAR(MAX)");
- RegisterColumnType(DbType.AnsiString, 2147483647, "VARCHAR(MAX)");
- RegisterColumnType(DbType.Binary, 2147483647, "VARBINARY(MAX)");
+ RegisterColumnType(DbType.String, SqlClientDriver.MaxSizeForClob, "NVARCHAR(MAX)");
+ RegisterColumnType(DbType.AnsiString, SqlClientDriver.MaxSizeForAnsiClob, "VARCHAR(MAX)");
+ RegisterColumnType(DbType.Binary, SqlClientDriver.MaxSizeForBlob, "VARBINARY(MAX)");
RegisterColumnType(DbType.Xml, "XML");
}
Modified: trunk/nhibernate/src/NHibernate/Driver/SqlClientDriver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Driver/SqlClientDriver.cs 2011-01-23 19:45:35 UTC (rev 5366)
+++ trunk/nhibernate/src/NHibernate/Driver/SqlClientDriver.cs 2011-01-24 15:51:51 UTC (rev 5367)
@@ -12,8 +12,19 @@
/// </summary>
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
+ public const int MaxSizeForLengthLimitedAnsiString = 8000;
+ public const int MaxSizeForLengthLimitedString = 4000;
+ public const int MaxSizeForLengthLimitedBinary = 8000;
+ public const byte MaxPrecision = 28;
+ public const byte MaxScale = 5;
+ public const byte MaxDateTime2 = 8;
+ public const byte MaxDateTimeOffset = 10;
+
/// <summary>
- /// Creates an uninitialized <see cref="IDbConnection" /> object for
+ /// Creates an uninitialized <see cref="IDbConnection" /> object for
/// the SqlClientDriver.
/// </summary>
/// <value>An unitialized <see cref="System.Data.SqlClient.SqlConnection"/> object.</value>
@@ -23,7 +34,7 @@
}
/// <summary>
- /// Creates an uninitialized <see cref="IDbCommand" /> object for
+ /// Creates an uninitialized <see cref="IDbCommand" /> object for
/// the SqlClientDriver.
/// </summary>
/// <value>An unitialized <see cref="System.Data.SqlClient.SqlCommand"/> object.</value>
@@ -33,7 +44,7 @@
}
/// <summary>
- /// MsSql requires the use of a Named Prefix in the SQL statement.
+ /// MsSql requires the use of a Named Prefix in the SQL statement.
/// </summary>
/// <remarks>
/// <see langword="true" /> because MsSql uses "<c>@</c>".
@@ -44,7 +55,7 @@
}
/// <summary>
- /// MsSql requires the use of a Named Prefix in the Parameter.
+ /// MsSql requires the use of a Named Prefix in the Parameter.
/// </summary>
/// <remarks>
/// <see langword="true" /> because MsSql uses "<c>@</c>".
@@ -55,7 +66,7 @@
}
/// <summary>
- /// The Named Prefix for parameters.
+ /// The Named Prefix for parameters.
/// </summary>
/// <value>
/// Sql Server uses <c>"@"</c>.
@@ -71,8 +82,8 @@
/// </summary>
/// <value><see langword="false" /> - it is not supported.</value>
/// <remarks>
- /// MS SQL Server 2000 (and 7) throws an exception when multiple IDataReaders are
- /// attempted to be opened. When SQL Server 2005 comes out a new driver will be
+ /// MS SQL Server 2000 (and 7) throws an exception when multiple IDataReaders are
+ /// attempted to be opened. When SQL Server 2005 comes out a new driver will be
/// created for it because SQL Server 2005 is supposed to support it.
/// </remarks>
public override bool SupportsMultipleOpenReaders
@@ -80,6 +91,20 @@
get { return false; }
}
+ public override bool SupportsMultipleQueries
+ {
+ get { return true; }
+ }
+
+ public override IDbCommand GenerateCommand(CommandType type, SqlString sqlString, SqlType[] parameterTypes)
+ {
+ IDbCommand command = base.GenerateCommand(type, sqlString, parameterTypes);
+
+ SetParameterSizes(command.Parameters, parameterTypes);
+
+ return command;
+ }
+
// Used from SqlServerCeDriver as well
public static void SetParameterSizes(IDataParameterCollection parameters, SqlType[] parameterTypes)
{
@@ -89,34 +114,33 @@
}
}
- private const int MaxAnsiStringSize = 8000;
- private const int MaxBinarySize = MaxAnsiStringSize;
- private const int MaxStringSize = MaxAnsiStringSize / 2;
- private const int MaxBinaryBlobSize = int.MaxValue;
- private const int MaxStringClobSize = MaxBinaryBlobSize / 2;
- private const byte MaxPrecision = 28;
- private const byte MaxScale = 5;
- private const byte MaxDateTime2 = 8;
- private const byte MaxDateTimeOffset = 10;
+ private static void SetVariableLengthParameterSize(IDbDataParameter dbParam, SqlType sqlType)
+ {
+ SetDefaultParameterSize(dbParam, sqlType);
+ // Override the defaults using data from SqlType - except for LOB types
+ if (sqlType.LengthDefined && !IsText(dbParam, sqlType) && !IsBlob(dbParam, sqlType))
+ {
+ dbParam.Size = sqlType.Length;
+ }
+
+ if (sqlType.PrecisionDefined)
+ {
+ dbParam.Precision = sqlType.Precision;
+ dbParam.Scale = sqlType.Scale;
+ }
+ }
+
private static void SetDefaultParameterSize(IDbDataParameter dbParam, SqlType sqlType)
{
switch (dbParam.DbType)
{
case DbType.AnsiString:
case DbType.AnsiStringFixedLength:
- dbParam.Size = MaxAnsiStringSize;
+ dbParam.Size = MaxSizeForLengthLimitedAnsiString;
break;
-
case DbType.Binary:
- if (sqlType is BinaryBlobSqlType)
- {
- dbParam.Size = MaxBinaryBlobSize;
- }
- else
- {
- dbParam.Size = MaxBinarySize;
- }
+ dbParam.Size = IsBlob(dbParam, sqlType) ? MaxSizeForBlob : MaxSizeForLengthLimitedBinary;
break;
case DbType.Decimal:
dbParam.Precision = MaxPrecision;
@@ -124,7 +148,7 @@
break;
case DbType.String:
case DbType.StringFixedLength:
- dbParam.Size = IsText(dbParam, sqlType) ? MaxStringClobSize : MaxStringSize;
+ dbParam.Size = IsText(dbParam, sqlType) ? MaxSizeForClob : MaxSizeForLengthLimitedString;
break;
case DbType.DateTime2:
dbParam.Size = MaxDateTime2;
@@ -135,44 +159,28 @@
}
}
+ /// <summary>
+ /// Interprets if a parameter is a Clob (for the purposes of setting its default size)
+ /// </summary>
+ /// <param name="dbParam">The parameter</param>
+ /// <param name="sqlType">The <see cref="SqlType" /> of the parameter</param>
+ /// <returns>True, if the parameter should be interpreted as a Clob, otherwise False</returns>
private static bool IsText(IDbDataParameter dbParam, SqlType sqlType)
{
- return (sqlType is StringClobSqlType) || (sqlType.LengthDefined && sqlType.Length > MsSql2000Dialect.MaxSizeForLengthLimitedStrings &&
- (DbType.String == dbParam.DbType || DbType.StringFixedLength == dbParam.DbType));
+ return (sqlType is StringClobSqlType) || ((DbType.String == dbParam.DbType || DbType.StringFixedLength == dbParam.DbType) && sqlType.LengthDefined && (sqlType.Length > MaxSizeForLengthLimitedString));
}
-
- private static void SetVariableLengthParameterSize(IDbDataParameter dbParam, SqlType sqlType)
+
+ /// <summary>
+ /// Interprets if a parameter is a Blob (for the purposes of setting its default size)
+ /// </summary>
+ /// <param name="dbParam">The parameter</param>
+ /// <param name="sqlType">The <see cref="SqlType" /> of the parameter</param>
+ /// <returns>True, if the parameter should be interpreted as a Blob, otherwise False</returns>
+ private static bool IsBlob(IDbDataParameter dbParam, SqlType sqlType)
{
- SetDefaultParameterSize(dbParam, sqlType);
-
- // Override the defaults using data from SqlType.
- if (sqlType.LengthDefined && !IsText(dbParam, sqlType))
- {
- dbParam.Size = sqlType.Length;
- }
-
- if (sqlType.PrecisionDefined)
- {
- dbParam.Precision = sqlType.Precision;
- dbParam.Scale = sqlType.Scale;
- }
+ return (sqlType is BinaryBlobSqlType) || ((DbType.Binary == dbParam.DbType) && sqlType.LengthDefined && (sqlType.Length > MaxSizeForLengthLimitedBinary));
}
- public override IDbCommand GenerateCommand(CommandType type, SqlString sqlString, SqlType[] parameterTypes)
- {
- IDbCommand command = base.GenerateCommand(type, sqlString, parameterTypes);
- //if (IsPrepareSqlEnabled)
- {
- SetParameterSizes(command.Parameters, parameterTypes);
- }
- return command;
- }
-
- public override bool SupportsMultipleQueries
- {
- get { return true; }
- }
-
#region IEmbeddedBatcherFactoryProvider Members
System.Type IEmbeddedBatcherFactoryProvider.BatcherFactoryClass
@@ -182,4 +190,4 @@
#endregion
}
-}
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/DriverTest/SqlClientDriverFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/DriverTest/SqlClientDriverFixture.cs 2011-01-23 19:45:35 UTC (rev 5366)
+++ trunk/nhibernate/src/NHibernate.Test/DriverTest/SqlClientDriverFixture.cs 2011-01-24 15:51:51 UTC (rev 5367)
@@ -29,10 +29,6 @@
[TestFixture]
public class SqlClientDriverFixture : TestCase
{
- protected override void Configure(Configuration configuration)
- {
- configuration.SetProperty(Environment.PrepareSql, "true");
- }
protected override string MappingsAssembly
{
get { return "NHibernate.Test"; }
@@ -45,24 +41,28 @@
protected override bool AppliesTo(Dialect.Dialect dialect)
{
- return dialect is MsSql2000Dialect;
+ return dialect is MsSql2008Dialect;
}
[Test]
public void Crud()
{
- // Should use default dimension for CRUD op and prepare_sql='true' because the mapping does not
+ // Should use default dimension for CRUD op because the mapping does not
// have dimensions specified.
object savedId;
using (ISession s = OpenSession())
using (ITransaction t = s.BeginTransaction())
{
savedId = s.Save(new MultiTypeEntity
- {
- StringProp = "a", StringClob = "a",BinaryBlob = new byte[]{1,2,3},
- Binary = new byte[] { 4, 5, 6 }, Currency = 123.4m, Double = 123.5d,
- Decimal = 789.5m
- });
+ {
+ StringProp = "a",
+ StringClob = "a",
+ BinaryBlob = new byte[]{1,2,3},
+ Binary = new byte[] { 4, 5, 6 },
+ Currency = 123.4m,
+ Double = 123.5d,
+ Decimal = 789.5m
+ });
t.Commit();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|