persistence@glassfish.java.net

Code review for Issue 2646 - MySQL: Left/Right Trim function is translated into invalid SQL

From: Wonseok Kim <guruwons_at_gmail.com>
Date: Mon, 19 Mar 2007 23:19:30 +0900

Hi Tom,

Here is the fix for following issues, please review the attached fix.

* MySQL: Left/Right Trim function is translated into invalid SQL
https://glassfish.dev.java.net/issues/show_bug.cgi?id=2646
* Entity-Persistence-Tests must not check for existence of optional
LeftTrim2 function
https://glassfish.dev.java.net/issues/show_bug.cgi?id=1898

The summary of this fix:
* Added MySQL-specific LeftTrim2 and RightTrim2 ExpressionOperator
implementation
* Added more tests: leftTrim without character and rightTrim with/without
character
* Fix for 1898 - More precise DB platforms check for trim tests after
investigating each platform documentation

* Fixed DatabaseException log formatting like below - See Error code line

[From]
Internal Exception: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You
have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near ' 'M') = 'anotick')' at
line 1Error Code: 1064
Call:SELECT CUST_ID, NAME, CUST_VERSION, CITY FROM CMP3_CUSTOMER WHERE
(LTRIM(CITY, ?) = ?)
    bind => [M, anotick]
Query:ReadAllQuery(
oracle.toplink.essentials.testing.models.cmp3.relationships.Customer))

[To]
Internal Exception: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You
have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near ' 'M') = 'anotick')'
at line 1
Error Code: 1064
Call: SELECT CUST_ID, NAME, CUST_VERSION, CITY FROM CMP3_CUSTOMER WHERE
(LTRIM(CITY, ?) = ?)
    bind => [M, anotick]
Query: ReadAllQuery(
oracle.toplink.essentials.testing.models.cmp3.relationships.Customer))

I tested this fix on MySQL, Derby and Oracle. MySQL still has failures which
I have mentioned earlier, but the failures regarding trim functions is now
gone away.

Thanks,
-Wonseok