[jira] [Commented] (DERBY-6952) Regression on Statement.getGeneratedKeys() on UPDATE statements

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[jira] [Commented] (DERBY-6952) Regression on Statement.getGeneratedKeys() on UPDATE statements

JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/DERBY-6952?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16095985#comment-16095985 ]

Lukas Eder commented on DERBY-6952:
-----------------------------------

Thanks for linking. Of course, the soundest solution that would make using getGeneratedKeys() obsolete would be to support the SQL standard OLD TABLE () / NEW TABLE () / FINAL TABLE () syntaxes as currently supported by DB2 (or, alternatively, the RETURNING clause as currently implemented by Oracle PL/SQL, PostgreSQL, Firebird):

{code}
SELECT *
FROM FINAL TABLE (
  UPDATE test SET val = 2 WHERE id = 1
)
{code}

I've created a separate feature request for the <data change delta table> feature: https://issues.apache.org/jira/browse/DERBY-6953

> Regression on Statement.getGeneratedKeys() on UPDATE statements
> ---------------------------------------------------------------
>
>                 Key: DERBY-6952
>                 URL: https://issues.apache.org/jira/browse/DERBY-6952
>             Project: Derby
>          Issue Type: Bug
>          Components: JDBC
>    Affects Versions: 10.13.1.1
>            Reporter: Lukas Eder
>
> Consider this program:
> {code}
> 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");
>             }
>         }
>     }
> }
> {code}
> 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.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)
Loading...