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

PostgreSQL statement parsing fails on string literals with newline characters #1730

Closed
olavloite opened this issue Mar 7, 2022 · 0 comments · Fixed by #1731
Closed

PostgreSQL statement parsing fails on string literals with newline characters #1730

olavloite opened this issue Mar 7, 2022 · 0 comments · Fixed by #1731
Assignees
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@olavloite
Copy link
Collaborator

The PostgreSQL statement parser that removes comments and determines how many query parameters are in a query fails if the statement contains one or more string literals or quoted identifiers that contain a newline character.

So the following statements fail with an INVALID_ARGUMENT: SQL statement contains an unclosed literal error:

select 'test1
test2';

select "foo
bar" from some_table;
@olavloite olavloite self-assigned this Mar 7, 2022
@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/java-spanner API. label Mar 7, 2022
@olavloite olavloite added priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed api: spanner Issues related to the googleapis/java-spanner API. labels Mar 7, 2022
olavloite added a commit that referenced this issue Mar 7, 2022
PostgreSQL supports newline characters in string literals and quoted
identifiers. Trying to execute a statement with a string literal or
quoted identifier that contained a newline character would cause an
'Unclosed string literal' error.

Fixes #1730
olavloite added a commit that referenced this issue Mar 8, 2022
…1731)

* fix: PostgreSQL supports newline in quoted literals and identifiers

PostgreSQL supports newline characters in string literals and quoted
identifiers. Trying to execute a statement with a string literal or
quoted identifier that contained a newline character would cause an
'Unclosed string literal' error.

Fixes #1730

* fix: typo
olavloite added a commit that referenced this issue Mar 8, 2022
* fix: PostgreSQL supports newline in quoted literals and identifiers

PostgreSQL supports newline characters in string literals and quoted
identifiers. Trying to execute a statement with a string literal or
quoted identifier that contained a newline character would cause an
'Unclosed string literal' error.

Fixes #1730

* feat: parse query parameters in PostgreSQL query

Adds a helper method to get the parameters from a PostgreSQL query. This
is needed for DESCRIBE statement messages in PGAdapter, as it must
return the data types of all query parameters in a query string. Even
though this parser is not able to determine the parameter types, it is
able to determine the number of parameters. This again makes it possible
to PGAdapter to return Oid.UNSPECIFIED for each parameter in the query
string, which is enough for most clients.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant