Bug #25047 Bug in StringUtils.indexOfIgnoreCaseRespectQuotes breaks RewriteBatchedStatement
Submitted: 13 Dec 2006 18:18 Modified: 22 Feb 2007 11:39
Reporter: Martin Ross Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:5.0.x OS:
Assigned to: CPU Architecture:Any
Tags: executeBatch, REWRITEBATCHEDSTATEMENTS, StringUtils

[13 Dec 2006 18:18] Martin Ross
Description:
Symptom is that rewritebactchstatements fails where case of the values() clause is lower case.

Method indexOfIgnoreCaseRespectQuotes in StringUtils() is called by PreparedStatements.extractValuesClause().  indexOfIgnoreCaseRespectQuotes() has a bug in it that causes it to fail when the src string has the desired target string, but the first character of the target and substring in the src that matches the target string differ in case.

<SNIP>
} else if (c == target.charAt(0) && !escaped
&& contextMarker == Character.MIN_VALUE) {
    if (startsWithIgnoreCase(src, i, target))
        return i;
}
</SNIP>

The offending statement is c == target.charAt(0).  If the cases differ then the startsWithIgnoreCase() method will not be called.  The should check should be case insensitive.

Please note that this bug fixes breaks other methods including
CallableStatement.generateParameterMap()
Connection.canHandleAsServerPreparedStatementNoCache()
DatabaseMetaData.extractForeignKeyForTable(ArrayList, ResultSet, String) (5 matches)
DatabaseMetaData.getCallStmtParameterTypes(String, String, String, List) (7 matches)
DatabaseMetaData.parseTableStatusIntoLocalAndReferencedColumns(String) (6 matches)

How to repeat:
insert into Test (TestID) values (?)
insert into Test (TestID) values (?)

Suggested fix:
c == target.charAt(0) check should not be case sensitive.
[2 Jan 2007 19:12] Tonci Grgin
Martin, once again I have to agree with you. Thanks for your report.
[5 Jan 2007 5:50] Martin Ross
Can we get this fix committed?  It is literally a one line fix :)  Hibernate batching is broken until this is done.

Thanks.
[10 Jan 2007 21:29] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/17890
[10 Jan 2007 21:35] Mark Matthews
Fixes are never one-liners (if you count the testcase, and the fact that we had to take into account locales that are "tricky" to compare characters case-insensitively...Why there isn't a method to do so on java.lang.Character() is beyond me, unless I'm missing something obvious).
[22 Feb 2007 11:39] MC Brown
A note has been added to the 5.0.5 changelog.