Fix for bug in Dialect class when "use_sql_comments" is true.

292 views
Skip to first unread message

cbp

unread,
Dec 12, 2011, 10:52:44 PM12/12/11
to nhusers
I have discovered a bug in the Dialect class which occurs when
"use_sql_comments" is set to true.

I have confirmed the bug in NH 2.1 but looking at NH 3.2's code, the
bug appears to still exist.

The problem occurs when all the following conditions are met in an
ICriteria:
* You try to do a paged query (i.e. one using SetMaxResults and
SetFirstResult), and the first result is greater than 0
* You use projections, rather than selecting all columns
* You use an ORDER BY statement


The result is an "invalid syntax" SQL exception because the generated
SQL looks something like this:

SELECT TOP 10 y0_, y1_ FROM (/* criteria query */ SELECT this.Foo as
y0_, this.Bar as y1_, ROW_NUMBER() OVER(ORDER BY /* criteria query */
SELECT) as __hibernate_sort_row FROM FooBar this_) as query WHERE
query.__hibernate_sort_row > 10 ORDER BY query.__hibernate_sort_row

Notice the invalid syntax near the OVER(ORDER BY clause.

To fix the bug, the following code needs to be added to the
ExtractColumnOrAliasNames method of the Dialect class, above the line
that reads "handle composite expressions like "2 * 4 as foo":

if ("/*" == token)
{
while (index < tokens.Count)
{
token = tokens[index];
index += 1;

if ("*/" == token)
break;
}
continue;
}

Oskar Berggren

unread,
Dec 13, 2011, 8:11:01 AM12/13/11
to nhu...@googlegroups.com
Please file a bug at https://nhibernate.jira.com/.

Even better if you could attach a unit test
http://nhforge.org/blogs/nhibernate/archive/2008/10/04/the-best-way-to-solve-nhibernate-bugs-submit-good-unit-test.aspx

Patches can be attached to the issue, or submitted via a pull request in github.

/Oskar


2011/12/13 cbp <centri...@gmail.com>:

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

Reply all
Reply to author
Forward
0 new messages