Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UPDATE OR INSERT with existing RETURNING clause handled incorrectly for generated keys [JDBC566] #598

Closed
firebird-automations opened this issue Nov 30, 2018 · 5 comments

Comments

@firebird-automations
Copy link

firebird-automations commented Nov 30, 2018

Submitted by: @mrotteveel

The grammar for UPDATE OR INSERT has a minor bug (expecting MATCHING columnlist instead of MATCHING (columnlist)), which causes an existing RETURNING clause to not be properly identified. This results in Jaybird adding yet another RETURNING clause.

Simple reproduction:

public static void main(String[] args) throws SQLException {
    try (Connection connection = DefaultDb.createDefaultConnection();
         Statement stmt = connection.createStatement()) {
        stmt.execute("update or insert into person (id, name) values (3, 'henk') "
                + "matching (id) "
                + "returning id", Statement.RETURN_GENERATED_KEYS);

        try (ResultSet keys = stmt\.getGeneratedKeys()) {
            while (keys.next()) {
                System.out.println(keys.getInt(1));
            }
        }
    }
}

This results in error:
java.sql.SQLSyntaxErrorException: Dynamic SQL Error; SQL error code = -104; Token unknown - line 2, column 11; "ID" [SQLState:42000, ISC error code:335544634]

This bug in the grammar is also present in Jaybird 2.2, but difference between ANTLR 3.4 and 4.7 apparently cause ANTLR 3.4 to still correctly identify the RETURNING clause.

See also: https://groups.yahoo.com/neo/groups/Firebird-Java/conversations/messages/11490 (archive)

Commits: 9de9584 e1f7413

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

Consider whether to fix the grammar in Jaybird 2.2 as well.

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

Fix Version: Jaybird 3.0.6 [ 10883 ]

Fix Version: Jaybird 4 [ 10441 ]

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

Fix committed for Jaybird 3.0.6 and Jaybird 4

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

status: Resolved [ 5 ] => Closed [ 6 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment