Permalink
Browse files

NH-1160 - Parameter compatibility problem in cached batch SQL command.

SVN: branches/1.2.x@3111
  • Loading branch information...
1 parent 0be34cb commit bfaf3e485fd56878c2225d67ac832e8d2894ae0b Sergey Koshcheyev committed Nov 18, 2007
Showing with 30 additions and 6 deletions.
  1. +12 −6 src/NHibernate/Impl/BatcherImpl.cs
  2. +18 −0 src/NHibernate/Util/ArrayHelper.cs
@@ -9,6 +9,7 @@
using NHibernate.Exceptions;
using NHibernate.SqlCommand;
using NHibernate.SqlTypes;
+using NHibernate.Util;
namespace NHibernate.Impl
{
@@ -31,6 +32,7 @@ public abstract class BatcherImpl : IBatcher
// just update. However I haven't seen this being used with read statements...
private IDbCommand batchCommand;
private SqlString batchCommandSql;
+ private SqlType[] batchCommandParameterTypes;
private ISet commandsToClose = new HashedSet();
private ISet readersToClose = new HashedSet();
@@ -114,18 +116,20 @@ protected void Prepare(IDbCommand cmd)
public IDbCommand PrepareBatchCommand(CommandType type, SqlString sql, SqlType[] parameterTypes)
{
- if (!sql.Equals(batchCommandSql))
- {
- batchCommand = PrepareCommand(type, sql, parameterTypes); // calls ExecuteBatch()
- batchCommandSql = sql;
- }
- else
+ if (sql.Equals(batchCommandSql) &&
+ ArrayHelper.ArrayEquals(parameterTypes, batchCommandParameterTypes))
{
if (log.IsDebugEnabled)
{
log.Debug("reusing command " + batchCommand.CommandText);
}
}
+ else
+ {
+ batchCommand = PrepareCommand(type, sql, parameterTypes); // calls ExecuteBatch()
+ batchCommandSql = sql;
+ batchCommandParameterTypes = parameterTypes;
+ }
return batchCommand;
}
@@ -159,6 +163,7 @@ public void AbortBatch(Exception e)
IDbCommand cmd = batchCommand;
batchCommand = null;
batchCommandSql = null;
+ batchCommandParameterTypes = null;
// close the statement closeStatement(cmd)
if (cmd != null)
{
@@ -307,6 +312,7 @@ public void ExecuteBatch()
IDbCommand ps = batchCommand;
batchCommand = null;
batchCommandSql = null;
+ batchCommandParameterTypes = null;
try
{
DoExecuteBatch(ps);
@@ -257,5 +257,23 @@ public static int CountTrue(bool[] array)
}
return result;
}
+
+ public static bool ArrayEquals(SqlType[] a, SqlType[] b)
+ {
+ if (a.Length != b.Length)
+ {
+ return false;
+ }
+
+ for(int i = 0; i < a.Length; i++)
+ {
+ if (!Equals(a[i], b[i]))
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
}
}

0 comments on commit bfaf3e4

Please sign in to comment.