Uploaded image for project: 'Derby'
  1. Derby
  2. DERBY-6952

Regression on Statement.getGeneratedKeys() on UPDATE statements

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 10.13.1.1
    • Fix Version/s: None
    • Component/s: JDBC
    • Labels:
      None

      Description

      Consider this program:

      import java.sql.Connection;
      import java.sql.PreparedStatement;
      import java.sql.ResultSet;
      import java.sql.Statement;
      import java.util.Properties;
      
      import org.apache.derby.jdbc.EmbeddedDriver;
      
      public class Derby {
          public static void main(String[] args) throws Exception {
              try (Connection c1 = new EmbeddedDriver().connect("jdbc:derby:memory:test;create=true", new Properties());
                   Statement s = c1.createStatement()) {
      
                  s.execute(
                      "CREATE TABLE test ("
                          + "id INT PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY,"
                          + "val INT)");
      
                  try {
                      s.executeUpdate("INSERT INTO test (val) VALUES (1)");
      
                      try (PreparedStatement p = c1.prepareStatement("UPDATE test SET val = 2 WHERE id = 1", Statement.RETURN_GENERATED_KEYS)) {
                          p.executeUpdate();
      
                          try (ResultSet rs = p.getGeneratedKeys()) {
                              while (rs.next())
                                  System.out.println(rs.getString(1));
                          }
                      }
                  }
                  finally {
                      s.execute("DROP TABLE test");
                  }
              }
          }
      }
      

      Running this with Derby version 10.12.1.1 yields

      1

      With 10.13.1.1, it yields:

      0

      I'm not sure if this is (supposed to be) working at all, but the change is certainly a bit confusing.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                lukas.eder Lukas Eder
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated: