Skip to content

Commit

Permalink
chore: remove unused code and increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
olavloite committed Feb 21, 2024
1 parent b81af20 commit 43d9c0e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@

import com.google.cloud.spanner.Statement;
import com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement;
import com.google.cloud.spanner.connection.StatementResult;
import com.google.cloud.spanner.pgadapter.ConnectionHandler;
import com.google.cloud.spanner.pgadapter.error.PGExceptionFactory;
import com.google.cloud.spanner.pgadapter.metadata.OptionsMetadata;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.Futures;
import java.util.concurrent.Future;

public class InvalidStatement extends IntermediatePortalStatement {

Expand All @@ -47,9 +44,4 @@ public InvalidStatement(
ImmutableList.of());
setException(PGExceptionFactory.toPGException(exception));
}

@Override
public Future<StatementResult> describeAsync(BackendConnection backendConnection) {
return Futures.immediateFailedFuture(getException());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ static ShowStatement parse(String sql) {
"missing '(' for current_setting", SQLState.SyntaxError);
}
QuotedString setting = parser.readSingleQuotedString();
if (setting == null) {
throw PGExceptionFactory.newPGException(
"missing or invalid setting name", SQLState.SyntaxError);
}
boolean missingOk = false;
if (parser.eatToken(",")) {
String missingOkString = parser.readKeyword().toLowerCase(Locale.ENGLISH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4305,6 +4305,33 @@ public void testSelectCurrentSettingMissingNotOk() throws SQLException {
}
}

@Test
public void testSelectCurrentSettingMissingOk_settingIsMissing() throws SQLException {
try (Connection connection = DriverManager.getConnection(createUrl())) {
try (ResultSet resultSet =
connection
.createStatement()
.executeQuery("select current_setting('non_existing_setting', true)")) {
assertTrue(resultSet.next());
assertNull(resultSet.getString("current_setting"));
assertFalse(resultSet.next());
}
}
}

@Test
public void testSelectCurrentSettingMissingOk_settingIsPresent() throws SQLException {
try (Connection connection = DriverManager.getConnection(createUrl())) {
connection.createStatement().execute("set time zone 'IST'");
try (ResultSet resultSet =
connection.createStatement().executeQuery("select current_setting('timezone', true)")) {
assertTrue(resultSet.next());
assertEquals("Asia/Kolkata", resultSet.getString("current_setting"));
assertFalse(resultSet.next());
}
}
}

@Test
public void testSetNames() throws SQLException {
try (Connection connection = DriverManager.getConnection(createUrl())) {
Expand Down

0 comments on commit 43d9c0e

Please sign in to comment.