Issue Details (XML | Word | Printable)

Key: JDBC-566
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Mark Rotteveel
Reporter: Mark Rotteveel
Votes: 0
Watchers: 0

If you were logged in you would be able to see more operations.
Jaybird JCA/JDBC Driver

UPDATE OR INSERT with existing RETURNING clause handled incorrectly for generated keys

Created: 30/Nov/18 02:39 PM   Updated: 25/May/19 10:03 AM
Component/s: JDBC driver
Affects Version/s: Jaybird 3.0.0, Jaybird 3.0.1, Jaybird 3.0.2, Jaybird 3.0.3, Jaybird 3.0.4, Jaybird 3.0.5
Fix Version/s: Jaybird 3.0.6, Jaybird 4

 Description  « Hide
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 ( {

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:

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Mark Rotteveel added a comment - 30/Nov/18 02:39 PM
Consider whether to fix the grammar in Jaybird 2.2 as well.

Mark Rotteveel added a comment - 30/Nov/18 03:37 PM
Fix committed for Jaybird 3.0.6 and Jaybird 4