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

fix: comments should be sent to Spanner for PostgreSQL databases #1331

Merged
merged 12 commits into from
Sep 15, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.cloud.spanner.jdbc;

import com.google.cloud.spanner.Dialect;
import com.google.cloud.spanner.Options.QueryOption;
import com.google.cloud.spanner.ReadContext.QueryAnalyzeMode;
import com.google.cloud.spanner.ResultSets;
Expand All @@ -36,7 +37,6 @@
class JdbcPreparedStatement extends AbstractJdbcPreparedStatement {
private static final char POS_PARAM_CHAR = '?';
private final String sql;
private final String sqlWithoutComments;
private final ParametersInfo parameters;
private final ImmutableList<String> generatedKeysColumns;

Expand All @@ -46,9 +46,15 @@ class JdbcPreparedStatement extends AbstractJdbcPreparedStatement {
super(connection);
this.sql = sql;
try {
this.sqlWithoutComments = parser.removeCommentsAndTrim(this.sql);
// The PostgreSQL parser allows comments to be present in the SQL string that is used to parse
// the query parameters.
String sqlForParameterExtraction =
getConnection().getDialect() == Dialect.POSTGRESQL
? this.sql
: parser.removeCommentsAndTrim(this.sql);
this.parameters =
parser.convertPositionalParametersToNamedParameters(POS_PARAM_CHAR, sqlWithoutComments);
parser.convertPositionalParametersToNamedParameters(
POS_PARAM_CHAR, sqlForParameterExtraction);
} catch (SpannerException e) {
throw JdbcSqlExceptionFactory.of(e);
}
Expand Down