Details
-
Bug
-
Status: Closed (View Workflow)
-
Minor
-
Resolution: Fixed
-
1.1.8
-
None
-
Windows 7, 64 bit
Description
I can reproduce the error I am submitting here with this code block:
|
public static void main(String[] args) throws SQLException { |
MariaDB db = new MariaDB(); |
Connection conn = db.getConnection();
|
PreparedStatement sqlInsert = conn.prepareStatement("insert into prep (text) values (?)"); |
sqlInsert.setString(1, "aa"); |
sqlInsert.addBatch();
|
sqlInsert.setString(1, "b;b"); |
sqlInsert.addBatch();
|
sqlInsert.executeBatch();
|
conn.commit();
|
}
|
|
The connection uses "rewriteBatchedStatements=true"
As soon as I use a semicolon in the string, I get an "String index out of range: -1"
- if I switch back to connector 1.1.7, I get no error
- if I set rewriteBatchedStatements to false, I get no error
- the MariaDB query.log is empty, i.e. the statement does not reach the database. Which is to be expected since the error is an java.lang.StringIndexOutOfBoundsException
- Tested on MariaDB 10.0.15, connector 1.1.8
If you need any more infos, let me know.
The following issues that fixes part has been resolved.
org.mariadb.jdbc.MySQLPreparedStatement.java
/**
* <p>
* CONJ-142 bugs
* </p>
* Using a semicolon in a string with "rewriteBatchedStatements=true" fails
*/
@Override
String sqlUpper = sql.toUpperCase();
}
}
}
}
/**
* If the batch array contains only rewriteable sql strings, returns the
* rewritten statement.
*
* @return the rewritten statement
*/
result.append(firstRewrite);
String query = mySQLPS.dQuery.toSQLForBatchInsert(firstRewrite);
result.append(query);
}
}
}
org.mariadb.jdbc.internal.common.query.MySQLParameterizedQuery.java
/**
* <p>
* CONJ-142 bug
* </p>
* Using a semicolon in a string with "rewriteBatchedStatements=true" fails
*/
}
}
/**
* <p>
* CONJ-142 bug
* </p>
* Using a semicolon in a string with "rewriteBatchedStatements=true" fails
*/
QueryException {
}
- index);
}
os.write(queryPartsArray[i]);
}
}