Skip to content

Commit 48e7c01

Browse files
committed
Added MaxNumberOfParameters to Dialect
1 parent eb10f86 commit 48e7c01

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/NHibernate/AdoNet/GenericBatchingBatcher.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace NHibernate.AdoNet
1919
/// </summary>
2020
public partial class GenericBatchingBatcher : AbstractBatcher
2121
{
22-
private readonly int _maxNumberOfParameters = int.MaxValue;
22+
private readonly int? _maxNumberOfParameters;
2323
private readonly BatchingCommandSet _currentBatch;
2424
private int _totalExpectedRowsAffected;
2525
private StringBuilder _currentBatchCommandsLog;
@@ -30,14 +30,8 @@ public GenericBatchingBatcher(ConnectionManager connectionManager, IInterceptor
3030
BatchSize = Factory.Settings.AdoBatchSize;
3131
StatementTerminator = statementTerminator;
3232
_currentBatch = new BatchingCommandSet(this);
33-
// On Sql Server there is a limit of 2100 parameters, but 2 are reserved for sp_executesql, so
34-
// we are able to use up to 2098 parameters. When sp_prepexec is used for preparing and executing
35-
// statements then one more parameter is used. Set the max number of parameters to 2097 in order
36-
// to ensure that we will never exceed the limit.
37-
if (Factory.Dialect is MsSql2000Dialect)
38-
{
39-
_maxNumberOfParameters = 2097;
40-
}
33+
_maxNumberOfParameters = Factory.Dialect.MaxNumberOfParameters;
34+
4135
// We always create this, because we need to deal with a scenario in which
4236
// the user change the logging configuration at runtime. Trying to put this
4337
// behind an if(log.IsDebugEnabled) will cause a null reference exception
@@ -54,7 +48,8 @@ public GenericBatchingBatcher(ConnectionManager connectionManager, IInterceptor
5448
public override void AddToBatch(IExpectation expectation)
5549
{
5650
var batchUpdate = CurrentCommand;
57-
if (_currentBatch.CountOfParameters + CurrentCommand.Parameters.Count > _maxNumberOfParameters)
51+
if (_maxNumberOfParameters.HasValue &&
52+
_currentBatch.CountOfParameters + CurrentCommand.Parameters.Count > _maxNumberOfParameters)
5853
{
5954
ExecuteBatchWithTiming(batchUpdate);
6055
}

src/NHibernate/Dialect/Dialect.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,6 +2446,11 @@ public virtual string LowercaseFunction
24462446
/// </summary>
24472447
public virtual int MaxAliasLength => 18;
24482448

2449+
/// <summary>
2450+
/// The maximum number of parameters allowed in a query.
2451+
/// </summary>
2452+
public virtual int? MaxNumberOfParameters { get; } = null;
2453+
24492454
/// <summary>
24502455
/// The syntax used to add a column to a table. Note this is deprecated
24512456
/// </summary>

src/NHibernate/Dialect/MsSql2000Dialect.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,13 @@ public override bool SupportsSqlBatches
716716
/// <inheritdoc />
717717
public override int MaxAliasLength => 30;
718718

719+
/// <summary>
720+
/// On SQL Server there is a limit of 2100 parameters, but two are reserved for sp_executesql
721+
/// and three for sp_prepexec (used when preparing is enabled). Set the number to 2097
722+
/// as the worst case scenario.
723+
/// </summary>
724+
public override int? MaxNumberOfParameters => 2097;
725+
719726
#region Overridden informational metadata
720727

721728
public override bool SupportsEmptyInList => false;

0 commit comments

Comments
 (0)