Hello,
I am not sure if I am right, but I think that using the NOT_LIKE
comparison type in conjunction with a wildcard-less string will
result in an incorrect behavior.
When using LIKE and a string without wildcards everything works fine:
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=
Criteria criteria = new Criteria ();
criteria.add (Test.LABEL, (Object) "test", Criteria.LIKE);
System.out.println (criteria);
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=
The following output of the above source code shows that the LIKE
comparison type was optimized to EQUAL cause no wildcards were found
in the given string.
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=
Criteria:: TEST.LABEL<=>TEST.LABEL = 'test':
Current Query SQL (may not be complete or applicable):
SELECT FROM TEST WHERE TEST.LABEL = 'test'
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=
If I am doing the same with NOT_LIKE I would expect that the NOT_LIKE
comparison would be replaced through NOT_EQUAL. But that is not what
happens here. Instead the NOT_LIKE is also replaced by EQUAL. Here is
the source code:
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=
Criteria criteria = new Criteria ();
criteria.add (Test.LABEL, (Object) "test", Criteria.NOT_LIKE);
System.out.println (criteria);
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=
And the related output:
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=
Criteria:: TEST.LABEL<=>TEST.LABEL = 'test':
Current Query SQL (may not be complete or applicable):
SELECT FROM TEST WHERE TEST.LABEL = 'test'
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=
This output shows that the NOT_LIKE comparison is replaced through
EQUAL. And I think that this is wrong. NOT_LIKE should be replaced
through NOT_EQUAL (instead of EQUAL).
LIKE & wildcard-less string => EQUAL
NOT_LIKE & wildcard-less string => NOT_EQUAL
Am I right?
Here is a small patch for org.apache.torque.util.SqlExpression which
should fix the problem in the buildLike method:
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=
retrieving revision 1.24
diff -u -r1.24 SqlExpression.java
--- SqlExpression.java 27 Aug 2003 22:50:11 -0000 1.24
+++ SqlExpression.java 7 Apr 2004 18:32:54 -0000
@@ -381,6 +381,11 @@
// use = (equals). Wildcards can be escaped by prepending
// them with \ (backslash).
String equalsOrLike = " = ";
+ if (comparison.equals (Criteria.NOT_LIKE))
+ {
+ equalsOrLike = " != ";
+ }
+
int position = 0;
StringBuffer sb = new StringBuffer();
while (position < criteria.length())
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=
--
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]