Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
org.postgresql.core.Parser fails on two queries separated by semicolon #1289
I'm submitting a ...
Describe the issue
My Java WEB application creates a prepared statement using the following call:
where query looks like this:
The first query has four parameters to bind. The second query is supposed to retrieve an ID of the inserted record generated by the known sequence. The second query does not have any bound parameters.
What actually happens
java.lang.IndexOutOfBoundsException: Index -1 out-of-bounds for length 0] with root cause
I ran some investigation, and it looks like the problem is caused by calling
The source of the problem is really in the parsing of a semicolon (line 175):
The code should reset bindPositions to nulll, not just empty the collection. According to the code logic, the fact that bindPositions is null means that no question mark placeholders were found, and if it is not null, then there must be at least one placeholder in the current query. Semicolon terminates the first query and starts new one, therefore you cannot now at this point if there are any bindings in it, and the collection should be null.
As I understand it, the first query with parameter binding creates the bindPositions collection:
and then populates it with the question mark positions.
I think, the bindPositions should either be reset to null in the semicolon parsing code, or even better the code should check if the bindPositions is empty before trying to get anything from it.
While we certainly should resolve the issue, it seems a better approach to accomplish getting the primary key would be to use the jdbc functionality to define columns to be returned.