Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-470

Error when executing SQL contains "values" and rewriteBatchedStatements=true

    XMLWordPrintable

Details

    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 {
      

      Attachments

        Activity

          People

            diego dupin Diego Dupin
            satotatsu1973 tatsuo satoh
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.