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

Statement.getGeneratedKeys() returns a non-empty ResultSet if AUTO_INCREMENT was unaffected

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.1.7
    • Fix Version/s: 1.1.8
    • Component/s: None
    • Labels:
      None
    • Environment:
      I used Windows 8 with MariaDB server 5.5.33a and Java 7.

      Description

      How to reproduce:
      Run test case GeneratedKeysTest.testGeneratedKeysInsertOnDuplicateUpdate() in the attached file GeneratedKeysTest.java. Psedo code:
      1. Create a table with an AUTO_INCREMENT column.
      2. Insert one row
      3. Try to insert another row with the ON DUPLICATE KEY UPDATE syntax that updates the previous inserted row.

      Actual:
      This assert fails:
      assertTrue(resultSet.next());

      That is: the ResultSet is not empty, it contains one row with the value 0 for the first column. The value 0 is just a dummy value and does not reflect any value of the key.

      Expected:
      The Javadoc for Statement.getGeneratedKeys() says: “If this Statement object did not generate any keys, an empty ResultSet object is returned.”

      Discussion:
      I’m guessing that the INSERT ON DUPLICATE-feature is a Mysql specific extension to SQL. It is my option that the feature does not mix very with the Javadoc for Statement.getGeneratedKeys(). My recommendation to others would be to not write code that use this feature.

      On the code I’m working on this feature is however used. We previously used Mysql JDBC driver and are now switching to MariaDB. My attached test case passes with Mysql JDBC driver (the ResultSet is empty). It would be good for me if MariaDB behaves the same.

        Attachments

          Activity

            People

            Assignee:
            massimo.siani Massimo Siani (Inactive)
            Reporter:
            lennartschedin Lennart Schedin
            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.