seade 2004/06/18 21:24:00 Modified: xdocs changes.xml src/java/org/apache/torque/util SqlExpression.java src/test/org/apache/torque/util CriteriaTest.java Log: Fix NOT_LIKE with no wildcard bug. Thanks to Clemens Fuchslocher for the patch which even included test cases!!! Revision Changes Path 1.124 +3 -0 db-torque/xdocs/changes.xml Index: changes.xml =================================================================== RCS file: /home/cvs/db-torque/xdocs/changes.xml,v retrieving revision 1.123 retrieving revision 1.124 diff -u -r1.123 -r1.124 --- changes.xml 6 Apr 2004 12:50:06 -0000 1.123 +++ changes.xml 19 Jun 2004 04:24:00 -0000 1.124 @@ -8,6 +8,9 @@ <body> <release version="3.2-alpha" date="in CVS"> + <action dev='seade' type='fix'> + Fix NOT_LIKE with no wildcard bug. + </action> <action dev='mpoeschl' type='fix'> TRQS97: Fix bad syntax in generated model when using primary keys of short or byte. 1.27 +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.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- SqlExpression.java 22 Feb 2004 06:16:35 -0000 1.26 +++ SqlExpression.java 19 Jun 2004 04:24:00 -0000 1.27 @@ -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()) 1.22 +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.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- CriteriaTest.java 22 Feb 2004 06:22:27 -0000 1.21 +++ CriteriaTest.java 19 Jun 2004 04:24:00 -0000 1.22 @@ -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 */ /*
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]