Hi All,

I've stumbled upon a bug using the SQLite dialect in conjunction with
multi-queries. The problem occurs with code like this:

        var firstQuery = session
                .CreateQuery("from Posts where Published between :starting
and :ending")
                .SetMaxResults(20);
        var secondQuery = session
                .CreateQuery("from Posts where Published between :starting
and :ending")
                .SetMaxResults(20);
        var testMultiQuery = session
                .CreateMultiQuery()
                .Add(firstQuery)
                .Add(secondQuery)
                .SetDateTime("starting", DateTime.UtcNow.AddDays(-3))
                .SetDateTime("ending", DateTime.UtcNow);

        // this throws exception (stack trace below)
        var testResults = testMultiQuery.List();

Here is the exception that is thrown when attempting to call
testMultiQuery.List() :

        System.InvalidCastException was unhandled
          Message="Invalid cast from 'Int32' to 'DateTime'."
          Source="mscorlib"
          StackTrace:
                   at 
System.Int32.System.IConvertible.ToDateTime(IFormatProvider
provider)
                   at System.Convert.ToDateTime(Object value, IFormatProvider
provider)
                   at System.Data.SQLite.SQLiteStatement.BindParameter(Int32 
index,
SQLiteParameter param)
                   at System.Data.SQLite.SQLiteStatement.BindParameters()
                   at System.Data.SQLite.SQLiteCommand.BuildNextCommand()
                   at System.Data.SQLite.SQLiteCommand.GetStatement(Int32 index)
                   at System.Data.SQLite.SQLiteDataReader.NextResult()
                   at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand 
cmd,
CommandBehavior behave)
                   at 
System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior
behavior)
                   at
System.Data.SQLite.SQLiteCommand.ExecuteDbDataReader(CommandBehavior
behavior)
                   at
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
                   at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand
cmd) line 242
                   at NHibernate.Impl.MultiQueryImpl.DoList() line 474
                   at NHibernate.Impl.MultiQueryImpl.ListIgnoreQueryCache() 
line 714
                   at NHibernate.Impl.MultiQueryImpl.List() line 378

I traced this issue through and found that it is due to the SQLite
dialect returning true for SupportsVariableLimit. If I extend
SQLiteDialect and override that property to return false, the query
works fine.

My understanding of the SupportsVariableLimit is, um, limited, but I
believe it is used to indicate the the limit can itself be expressed
via a parameter (perhaps improving the ability for the database to
cache the query plan). What appears to be happening is that the limits
*are* being added as parameters, but those parameters are never
referred to inside the SQL. Worse, the presence of those extra
parameters is causing the code that wires up parameter values to
choose the wrong value. In my case, it is choosing the limit value (an
Int32) rather than the starting/ending value (a DateTime).

I think the SQLite dialect is actually correct in returning true for
SupportsVariableLimit, but the code that handles that case must be
failing. Can anyone confirm my understanding / this behavior?

Best,
Kent

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to