Subject Re: [Firebird-Java] Firebird 3 migration issue with Statement.RETURN_GENERATED_KEYS
Author Mark Rotteveel
On 2018-11-29 20:36, Felipe Jaekel fkjaekel@... [Firebird-Java]
wrote:
> Hi,
>
> After upgrading from Firebird 2.5.4 + Jaybird 2.2...14 to Firebird
> 3.0.4 + Jaybird 3.0.5, places that use
> Statement..RETURN_GENERATED_KEYS stopped working.
>
> On a SQL like this:
>
> update or insert into SIRES01
> (id,
> <<fields>>)
>
> values
> (:id ,
> <<parameters>>)
>
> matching (id) returning id;
>
> I get the following error:
>
> line 1:60 token recognition error at: '>'
> line 1:664 token recognition error at: '>'
> line 1:419 token recognition error at: '<'
> line 1:420 token recognition error at: '>'
> line 1:444 token recognition error at: '<'
> line 1:445 token recognition error at: '>'
> line 1:1614 token recognition error at: '>'
> line 11:29 token recognition error at: '<'
> line 11:30 token recognition error at: '>'
> line 11:54 token recognition error at: '<'
> line 11:55 token recognition error at: '>'
> line 32:62 token recognition error at: '<'
> line 32:63 token recognition error at: '>'
> line 1:213 token recognition error at: '<'
> line 1:214 token recognition error at: '>'
> line 169:26 token recognition error at: ';'

That is 'just' output of the parser. It would generally mean that the
provide query does not match the grammar, this error would then lead to
Jaybird executing the query normally. I thought I suppressed its logging
though.

On a separate note, executed queries should **not** end in a semi-colon
(;), Firebird does not need it, and although Jaybird makes some attempts
to strip it while parsing, the presence in above token recognition error
suggests that didn't work.

> GRAVE: EjbTransactionUtil.handleSystemException: Error preparing
> statement - Dynamic SQL Error; SQL error code = -104; Token unknown -
> line 170, column 11; "ID" [SQLState:42000, ISC error code:335544634]
> org.sql2o.Sql2oException: Error preparing statement - Dynamic SQL
> Error; SQL error code = -104; Token unknown - line 170, column 11;
> "ID" [SQLState:42000, ISC error code:335544634]

This error suggests your actual query is using RETURNING "ID", while
using connection dialect 1 (or the query is otherwise syntactically
invalid).

> I thought it could be related to Sql2o, but the problem happens with
> plain JDBC too. I also updated antlr-runtime from 3.4 to 4.7.
>
> Do I need additional configuration for Firebird 3?

Jaybird 2.2 and earlier ignored the connection dialect in a number of
places and then used dialect 3 anyway. The behavior suggests you use
connection property sqlDialect=1 (or one of its aliases). Try removing
it, or using sqlDialect=3.

Otherwise, could you please provide me with a reproducible (and fully
executable) case so I can test it (preferably in plain JDBC).

Mark