Bug #8005 Driver generates corrupt SQL on "updateRow" when the PK is VARCHAR BINARY
Submitted: 19 Jan 2005 11:14 Modified: 19 Jan 2005 14:08
Reporter: Szymon Smyka Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:mysql-connector-java-3.0.16-ga OS:Windows (WinXP)
Assigned to: CPU Architecture:Any

[19 Jan 2005 11:14] Szymon Smyka
Description:
When calling "updateRow" on any table which primary key is of type VARCHAR BINARYthe driver produces corrupt select statement which leads to  exception pasted below.
If the PK is  of type VARCHAR (not binary)it works.

The testcase works with an older version of the JDBC Driver correcly.

java.sql.SQLException: Syntax error or access violation message from server: "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 '1''' at line 1"
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278)
	at com.mysql.jdbc.Connection.execSQL(Connection.java:2251)
	at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1586)
	at com.mysql.jdbc.UpdatableResultSet.refreshRow(UpdatableResultSet.java:706)
	at com.mysql.jdbc.UpdatableResultSet.updateRow(UpdatableResultSet.java:1569)
	at com.verdisoft.cdm.Test.main(Test.java:43)

The SQL produced by the driver during update row:
 36 Query       SHOW KEYS FROM `test` FROM `vcls`
 36 Query       UPDATE `vcls`.`test` SET `PK`=_binary'1',`DUMMY`=2 WHERE `PK`='1'
 36 Query       SELECT `PK`,`DUMMY` FROM `vcls`.`test` WHERE `PK`='_binary'1''

How to repeat:
Create table:
CREATE TABLE TEST
(
    PK			VARCHAR(64) BINARY NOT NULL,
    DUMMY			INT,
    PRIMARY KEY PK (PK)
)

Insert Row:
INSERT INTO TEST (PK,DUMMY) VALUES (1,1);

Run this main method:
public static void main(String[] args) throws Exception{
		Class.forName("com.mysql.jdbc.Driver");
		Connection con = DriverManager.getConnection("jdbc:mysql://localhost/vcls", "szymon", "szymon");
		Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
		ResultSet rs = stmt.executeQuery("SELECT PK, DUMMY FROM TEST WHERE PK = '1'");
		while(rs.next()){
			System.out.println("Next");
			rs.updateInt(2, 2);
			rs.updateRow();
		}
	}
[19 Jan 2005 14:08] Mark Matthews
This is a duplicate of BUG#7686, which is already fixed for 3.0.17 and available in the nightly snapshots.