Skip to content

Commit

Permalink
fix: call .next() before getting metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
olavloite committed Mar 10, 2021
1 parent b3cdced commit e591b57
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ public ResultSetMetaData getMetaData() throws SQLException {
if (StatementParser.INSTANCE.isUpdateStatement(sql)) {
// Return metadata for an empty result set as DML statements do not return any results (as a
// result set).
return new JdbcResultSetMetaData(
JdbcResultSet.of(ResultSets.forRows(Type.struct(), ImmutableList.<Struct>of())), this);
com.google.cloud.spanner.ResultSet resultSet =
ResultSets.forRows(Type.struct(), ImmutableList.<Struct>of());
resultSet.next();
return new JdbcResultSetMetaData(JdbcResultSet.of(resultSet), this);
}
try (ResultSet rs = analyzeQuery(createStatement(), QueryAnalyzeMode.PLAN)) {
return rs.getMetaData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,15 @@ public void testGetResultSetMetadata() throws SQLException {
assertEquals(Types.DOUBLE, metadata.getColumnType(3));
}
}

@Test
public void testGetResultSetMetaDataForDml() throws SQLException {
Connection connection = mock(Connection.class);
try (JdbcPreparedStatement ps =
new JdbcPreparedStatement(
createMockConnection(connection), "UPDATE FOO SET BAR=1 WHERE TRUE")) {
ResultSetMetaData metadata = ps.getMetaData();
assertEquals(0, metadata.getColumnCount());
}
}
}

0 comments on commit e591b57

Please sign in to comment.