seade 2004/06/18 21:30:37
Modified: src/test/org/apache/torque/util Tag: TORQUE_3_1_BRANCH
CriteriaTest.java
xdocs Tag: TORQUE_3_1_BRANCH release-changes.xml
src/java/org/apache/torque/util Tag: TORQUE_3_1_BRANCH
SqlExpression.java
Log:
Fix NOT_LIKE with no wildcard bug. Thanks to Clemens Fuchslocher for the patch which even
included test cases!!!
Revision Changes Path
No revision
No revision
1.20.2.3 +54 -1 db-torque/src/test/org/apache/torque/util/CriteriaTest.java
Index: CriteriaTest.java
===================================================================
RCS file: /home/cvs/db-torque/src/test/org/apache/torque/util/CriteriaTest.java,v
retrieving revision 1.20.2.2
retrieving revision 1.20.2.3
diff -u -r1.20.2.2 -r1.20.2.3
--- CriteriaTest.java 20 May 2004 04:36:06 -0000 1.20.2.2
+++ CriteriaTest.java 19 Jun 2004 04:30:36 -0000 1.20.2.3
@@ -431,6 +431,59 @@
}
/**
+ * This test case verifies if the Criteria.LIKE comparison type will
+ * get replaced through Criteria.EQUAL if there are no SQL wildcards
+ * in the given value.
+ */
+ public void testLikeWithoutWildcards()
+ {
+ Criteria c = new Criteria();
+ c.add("TABLE.COLUMN", (Object) "no wildcards", Criteria.LIKE);
+
+ String expect = "SELECT FROM TABLE WHERE TABLE.COLUMN = 'no wildcards'";
+
+ String result = null;
+ try
+ {
+ result = BasePeer.createQueryString(c);
+ }
+ catch (TorqueException e)
+ {
+ e.printStackTrace();
+ fail("TorqueException thrown in BasePeer.createQueryString()");
+ }
+
+ assertEquals(expect, result);
+ }
+
+ /**
+ * This test case verifies if the Criteria.NOT_LIKE comparison type will
+ * get replaced through Criteria.NOT_EQUAL if there are no SQL wildcards
+ * in the given value.
+ */
+ public void testNotLikeWithoutWildcards()
+ {
+ Criteria c = new Criteria();
+ c.add("TABLE.COLUMN", (Object) "no wildcards", Criteria.NOT_LIKE);
+
+ String firstExpect = "SELECT FROM TABLE WHERE TABLE.COLUMN != 'no wildcards'";
+ String secondExpect = "SELECT FROM TABLE WHERE TABLE.COLUMN <> 'no wildcards'";
+
+ String result = null;
+ try
+ {
+ result = BasePeer.createQueryString(c);
+ }
+ catch (TorqueException e)
+ {
+ e.printStackTrace();
+ fail("TorqueException thrown in BasePeer.createQueryString()");
+ }
+
+ assertTrue(result.equals(firstExpect) || result.equals(secondExpect));
+ }
+
+ /**
* test for TRQS25
*/
/*
No revision
No revision
1.3.2.6 +3 -0 db-torque/xdocs/release-changes.xml
Index: release-changes.xml
===================================================================
RCS file: /home/cvs/db-torque/xdocs/release-changes.xml,v
retrieving revision 1.3.2.5
retrieving revision 1.3.2.6
diff -u -r1.3.2.5 -r1.3.2.6
--- release-changes.xml 6 Apr 2004 12:49:46 -0000 1.3.2.5
+++ release-changes.xml 19 Jun 2004 04:30:37 -0000 1.3.2.6
@@ -31,6 +31,9 @@
<p>
<ul>
<li>
+ Fix NOT_LIKE with no wildcard bug.
+ </li>
+ <li>
TRQS97: Fix bad syntax in generated model when using primary keys of
short or byte.
</li>
No revision
No revision
1.24.2.4 +6 -1 db-torque/src/java/org/apache/torque/util/SqlExpression.java
Index: SqlExpression.java
===================================================================
RCS file: /home/cvs/db-torque/src/java/org/apache/torque/util/SqlExpression.java,v
retrieving revision 1.24.2.3
retrieving revision 1.24.2.4
diff -u -r1.24.2.3 -r1.24.2.4
--- SqlExpression.java 20 May 2004 04:36:06 -0000 1.24.2.3
+++ SqlExpression.java 19 Jun 2004 04:30:37 -0000 1.24.2.4
@@ -381,6 +381,11 @@
// use = (equals). Wildcards can be escaped by prepending
// them with \ (backslash).
String equalsOrLike = " = ";
+ if (comparison.equals(Criteria.NOT_LIKE))
+ {
+ equalsOrLike = " " + Criteria.NOT_EQUAL + " ";
+ }
+
int position = 0;
StringBuffer sb = new StringBuffer();
while (position < criteria.length())
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org
|