IgnoreCase not working

8 views
Skip to first unread message

Joe

unread,
Aug 19, 2009, 7:15:05 PM8/19/09
to nhusers
I use QueryByExample in my application and set IgnoreCase which was
working fine.

But, it seems to have broken when I upgraded from NH 1.2.1 to NH 2.1.

The SQL generated appears to be the same, however, the parameters are
not.

Under NH 1.2.1, if I were to search for a string property with "A",
the parameter sent to the database was actually "a%".
Under NH 2.1, if I search for a string property with "A", the
parameter sent to the database is "A".


Am I missing something. Did this behavior change on purpose?

This is against an Oracle database, using the "Oracle9iDialect" from
2.1

Thanks for any help / pointers!

Fabio Maulo

unread,
Aug 20, 2009, 9:34:36 AM8/20/09
to nhu...@googlegroups.com
Test case in JIRA please.
I mean... before create a JIRA please be sure of your issue proving it in a failing test.
Thanks

2009/8/19 Joe <junkma...@gmail.com>



--
Fabio Maulo

Joe

unread,
Aug 20, 2009, 11:10:53 AM8/20/09
to nhusers

That's my next step -- just wanted to see if anyone already ran into
this and might know what I'm doing wrong. I'm assuming the problem is
with me and not NH.


For the test case, does it have to fit into the NHibernate.Tests
solution or can I just write a quick console app test that shows the
problem?

--Brian


On Aug 20, 6:34 am, Fabio Maulo <fabioma...@gmail.com> wrote:
> Test case in JIRA please.I mean... before create a JIRA please be sure of
> your issue proving it in a failing test.
> Thanks
>
> 2009/8/19 Joe <junkmail....@gmail.com>

Fabio Maulo

unread,
Aug 20, 2009, 1:37:45 PM8/20/09
to nhu...@googlegroups.com
Have a look to the "Welcome" message of our JIRA (top left)

2009/8/20 Joe <junkma...@gmail.com>



--
Fabio Maulo

Saijado

unread,
Aug 21, 2009, 7:02:18 AM8/21/09
to nhusers
This Bug should be fixed in Version 2.1.1 I've send a patch to JIRA
some weeks ago. Search in JIRA for "Example" and you should find my
post.

-- Armin

Armin Landscheidt

unread,
Aug 21, 2009, 7:15:28 AM8/21/09
to nhusers

Joe

unread,
Aug 21, 2009, 1:26:49 PM8/21/09
to nhusers
Thanks you guys, I was pulling my hair out!

Joe

unread,
Aug 21, 2009, 2:52:09 PM8/21/09
to nhusers
Oops, I celebrated too soon!
I grabbed the latest build from NH TeamCity and at first it seemed
fixed.


But, there is a problem still with case.

If I set a string property to "C", the parameter generated is "C%",
but it should be "c%" because the where clause is: "WHERE (lower
(this_.description) like ?)"

"C%" is not going to match anything returned by a lower() function.


Armin, did you have this problem??

Joe

unread,
Aug 21, 2009, 3:49:33 PM8/21/09
to nhusers
Based on your tests for NH-1902, then this test should pass, too.


I can't seem to get NHibernate to build and test on my machine. Is
this something you can run??

[Test]
public void TestEnableLikeAndCaseInsensitiveWithMatchmodeAnywhere()
{
using (ISession s = OpenSession())
using (ITransaction t = s.BeginTransaction()) {
Componentizable master = GetMaster("BERN", null, null);
ICriteria crit = s.CreateCriteria(typeof(Componentizable));
Example ex = Example.Create(master).EnableLike
(MatchMode.Anywhere).IgnoreCase();
crit.Add(ex);
IList result = crit.List();
Assert.IsNotNull(result);
Assert.AreEqual(3, result.Count);
t.Commit();

armin-landscheidt

unread,
Aug 21, 2009, 5:31:42 PM8/21/09
to nhu...@googlegroups.com
If I remember right, it doesn't matter if you write 'C%' or 'c%' but I will check it.

Joe

unread,
Aug 21, 2009, 5:39:32 PM8/21/09
to nhusers

It matters on Oracle database:

select 'X' from dual where lower('ABCDE') like 'A%'

Does not return a row, the like comparison fails.

armin-landscheidt

unread,
Aug 21, 2009, 5:43:16 PM8/21/09
to nhu...@googlegroups.com
Ok I've tested it on MySQL and MS-SQL and there it doesn't matter. Your Test wokrs on my machine.
It seems, this is an Oracle sepcific thing. Mybe I know how to fix it. Give me a second :-D

armin-landscheidt

unread,
Aug 21, 2009, 6:19:18 PM8/21/09
to nhu...@googlegroups.com
Puhhh some minutes more then i thought ^^. I think I've found it. Ther ist no lower call for Parameter.
I hope sending fils on groups works.
Here is the Patch for the LikeExpression. But I don't know if it was intended that ther is no lower call.
I will try to send the patch in a short time to JIRA.
lowercaseMissingOnParameters.patch

armin-landscheidt

unread,
Aug 21, 2009, 6:37:54 PM8/21/09
to nhu...@googlegroups.com
Now I'm really confused. There is an InsensitiveLikeExpression which allways calls lower.
But it calls 'ilike' for Postgres. But in LikeExpression there is no special call for postgresql.
And the lowercase call for paramters are missing too.

Is this a Bug too?

Joe

unread,
Aug 21, 2009, 6:38:47 PM8/21/09
to nhusers

Thank you for all your work and help on this.
> [lowercaseMissingOnParameters.patch1K ]Index: LikeExpression.cs
> ===================================================================
> --- LikeExpression.cs   (revision 4656)
> +++ LikeExpression.cs   (working copy)
> @@ -69,12 +69,21 @@
>                                         .Add(StringHelper.OpenParen)
>                                         .Add(columns[0])
>                                         .Add(StringHelper.ClosedParen);
> +
> +
> +                               lhs.Add(" like ").Add(dialect.LowercaseFunction)
> +                                       .Add(StringHelper.OpenParen)
> +                                       .AddParameter()
> +                                       .Add(StringHelper.ClosedParen);
> +
>                         }
> -                       else
> +                       else {
>                                 lhs.Add(columns[0]);
> +                               lhs.Add(" like ").AddParameter();
> +                              
> +                       }
>
>                         criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery));
> -                       lhs.Add(" like ").AddParameter();
>                         if (escapeChar.HasValue)
>                                 lhs.Add(" escape '" + escapeChar + "'");
>                         return lhs.ToSqlString();
Reply all
Reply to author
Forward
0 new messages