[CONJ-470] Error when executing SQL contains "values" and rewriteBatchedStatements=true Created: 2017-05-15  Updated: 2017-06-04  Resolved: 2017-06-04

Status: Closed
Project: MariaDB Connector/J
Component/s: JDBC 4.2 compatibility
Affects Version/s: 2.0.1
Fix Version/s: 1.6.1, 2.0.2

Type: Bug Priority: Major
Reporter: tatsuo satoh Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None


 Description   

I can reproduce the error I am submitting here with this code block:

 
public class MariaDbJdbcTest {
 
	private static final String URL = "jdbc:mariadb://localhost:3306/test?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true";
	private static final String USERNAME = "root";
	private static final String PASSWORD = "password";
 
	private static final String CREATE_TABLE = "CREATE table test_partitioning(created_at datetime primary key)";
 
	private static final String ALTER_TABLE = "ALTER table test_partitioning PARTITION BY RANGE COLUMNS( created_at ) (PARTITION test_p201605 VALUES LESS THAN ('2016-06-01'))";
 
	private static final String DROP_TABLE = "DROP table test_partitioning";
 
	@Test
	public void test() throws SQLException {
		try (Connection conn = DriverManager.getConnection(URL, USERNAME, PASSWORD)) {
			executeSql(conn, CREATE_TABLE);
			executeSql(conn, ALTER_TABLE);// Success
			executeSql(conn, DROP_TABLE);
		}
	}
 
	@Test
	public void testPrepared() throws SQLException {
		try (Connection conn = DriverManager.getConnection(URL, USERNAME, PASSWORD)) {
			executePreparedSql(conn, CREATE_TABLE);
			executePreparedSql(conn, ALTER_TABLE);// fail
			executePreparedSql(conn, DROP_TABLE);
		}
	}
 
	private void executePreparedSql(Connection conn, String sql) throws SQLException {
		try (PreparedStatement stmt = conn.prepareStatement(sql)) {
			stmt.execute();
			System.out.println(sql);
		}
	}
 
	private void executeSql(Connection conn, String sql) throws SQLException {
		try (Statement stmt = conn.createStatement();) {
			stmt.execute(sql);
			System.out.println(sql);
		}
	}
}

The following code correction no longer causes an error, but I do not know if we should fix rewite batch processing.

org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.java

Before correction

	public void executeQuery(boolean mustExecuteOnMaster, Results results,
			final ClientPrepareResult clientPrepareResult, ParameterHolder[] parameters) throws SQLException {
		cmdPrologue();
		try {
			if (clientPrepareResult.getParamCount() == 0	&& !clientPrepareResult.isQueryMultiValuesRewritable()) {
				ComQuery.sendDirect(writer, clientPrepareResult.getQueryParts().get(0));
			} else {

After correction

	public void executeQuery(boolean mustExecuteOnMaster, Results results,
			final ClientPrepareResult clientPrepareResult, ParameterHolder[] parameters) throws SQLException {
		cmdPrologue();
		try {
			if (clientPrepareResult.getParamCount() == 0 && clientPrepareResult.getQueryParts().size() == 1
					&& !clientPrepareResult.isQueryMultiValuesRewritable()) {
				ComQuery.sendDirect(writer, clientPrepareResult.getQueryParts().get(0));
			} else {



 Comments   
Comment by Diego Dupin [ 2017-05-15 ]

Hi satotatsu1973, thanks for sharing this with a good test case !
issue is reproduced.

This can occur when the "rewriteBatchedStatements" option is enabled, and executing a query that contain keyword "values" without any parameter "?".
This will be corrected in next corrective version.

Generated at Thu Feb 08 03:15:54 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.