Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Springs's KeyHolder, oracle jdbс and insert-query with line breaks lead to ORA-00931: missing identifier

I store sql-queries in resource files with pretty human-readable formatting(with line breaks and indents). Suddenly I faced with issue: simple query, like below, works fine without fetching generated code-column value via keyholder,

insert into 
my_table
(
  code
)
values
(
  my_table_seq.nextval
)

but return ORA-00931: missing identifier\n when keyholder used:

...
var keyHolder = new GeneratedKeyHolder();
jdbcTemplate.update(
        "MY INSERT QUERY",
        new MapSqlParameterSource(),
        keyHolder,
        new String[]{"code"}
);
...

I debugged oracle jdbc driver(ojdbc8/ojdbc10 19.24) and noticed that whitespace after into-keyword cause this behaviour: AutoKeyInfo.getTableName return "\n" instead of "MY_TABLE"(see image below)! Removing whitespace solved the issue.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is it bug(and is it possible to submit it to ojdbc developers)?
keyHolder fail

>Solution :

Is it a bug?

Yes… The code looks for INSERT then INTO and then skips space characters and assumes that the next non-space character is the start of the identifier for the table name. When it finds a new-line character, it assumes that is the start of the identifier and returns a single new-line character instead of the actual identifier.

What it should do is skip whitespace characters rather than just spaces.

However… The work-around is simple, don’t use non-space whitespace characters in INSERT INTO my_table, just use spaces between the keywords and the identifier.


So, yes, you could report it but, in the meanwhile, you should be able to easily fix your code so it doesn’t trigger the issue.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading