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

Inconsistency in getUpdateCount() Return Value for CREATE Statements

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 3.3.1
    • 3.3.2
    • batch
    • None

    Description

      When CREATE statements are executed through executeBatch(), the subsequent call to getUpdateCount() returns -1, which is inconsistent with the behavior observed when executing CREATE statements using the execute() method, where getUpdateCount() returns 0. This behavior is also inconsistent with the MySQL Connector/J, which returns 0 in both scenarios.

      @Test
      public void test() throws SQLException {
          Connection con = null;
          Statement stmt = null;
          con = DriverManager.getConnection("jdbc:mariadb://localhost:3366/test5?user=user&password=password");
          stmt = con.createStatement();
          stmt.addBatch("CREATE TABLE table211_0(id VARCHAR(5) PRIMARY KEY,value BOOL);");
          stmt.addBatch("CREATE TABLE table211_0(id TINYINT PRIMARY KEY,value SMALLINT);");
          try {
              stmt.executeBatch();
          } catch (Exception e) {
              System.out.println(e);
          }
          System.out.println(stmt.getUpdateCount()); // -1
      }
      

      Attachments

        Activity

          diego dupin Diego Dupin added a comment - - edited

          Just to confirm, the example you indicate return the expected behavior (javadoc)

          the current result as an update count; -1 if the current result is a ResultSet object or there are no more results

          The problem reside in executeX when an error occur, updateCount not being reset:

          @Test
            public void getUpdateCountValue() throws SQLException {
              try (Statement st = sharedConn.createStatement()) {
                st.execute("DROP TABLE IF EXISTS getUpdateCountValue");
                try (Statement stmt = sharedConn.createStatement()) {
                  assertEquals(-1, stmt.getUpdateCount());
                  assertEquals(0, stmt.executeUpdate("CREATE TABLE getUpdateCountValue(id VARCHAR(5) PRIMARY KEY,value BOOL)"));
                  assertEquals(0, stmt.getUpdateCount());
                  try {
                    stmt.executeUpdate("CREATE TABLE getUpdateCountValue(id TINYINT PRIMARY KEY,value SMALLINT");
                  } catch (Exception e) {
                    // eat
                  }
                  assertEquals(-1, stmt.getUpdateCount());
                } finally {
                  st.execute("DROP TABLE IF EXISTS getUpdateCountValue");
                }
              }
            }
          

          (the example is the expected returns, but would return wrong result with current implementation, correction will be done)
          Are we on the same page or do i miss something ?

          diego dupin Diego Dupin added a comment - - edited Just to confirm, the example you indicate return the expected behavior ( javadoc ) the current result as an update count; -1 if the current result is a ResultSet object or there are no more results The problem reside in executeX when an error occur, updateCount not being reset: @Test public void getUpdateCountValue() throws SQLException { try (Statement st = sharedConn.createStatement()) { st.execute( "DROP TABLE IF EXISTS getUpdateCountValue" ); try (Statement stmt = sharedConn.createStatement()) { assertEquals(- 1 , stmt.getUpdateCount()); assertEquals( 0 , stmt.executeUpdate( "CREATE TABLE getUpdateCountValue(id VARCHAR(5) PRIMARY KEY,value BOOL)" )); assertEquals( 0 , stmt.getUpdateCount()); try { stmt.executeUpdate( "CREATE TABLE getUpdateCountValue(id TINYINT PRIMARY KEY,value SMALLINT" ); } catch (Exception e) { // eat } assertEquals(- 1 , stmt.getUpdateCount()); } finally { st.execute( "DROP TABLE IF EXISTS getUpdateCountValue" ); } } } (the example is the expected returns, but would return wrong result with current implementation, correction will be done) Are we on the same page or do i miss something ?
          dwenking chaos added a comment -

          Yes, your example is more reasonable than my description.

          dwenking chaos added a comment - Yes, your example is more reasonable than my description.

          People

            diego dupin Diego Dupin
            dwenking chaos
            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.