in src/main/java/com/google/cloud/spanner/pgadapter/wireprotocol/ControlMessage.java [141:192]
void sendSpannerResult(IntermediateStatement statement, QueryMode mode, long maxRows)
throws Exception {
logger.log(Level.FINER, Logging.format("Send result", Action.Starting));
try {
String command = statement.getCommandTag();
if (Strings.isNullOrEmpty(command)) {
new EmptyQueryResponse(this.outputStream).send(false);
return;
}
if (statement.getStatementResult() == null) {
return;
}
switch (statement.getStatementType()) {
case DDL:
case UNKNOWN:
CommandCompleteResponse.send(this.outputStream, command);
break;
case CLIENT_SIDE:
if (statement.getStatementResult().getResultType() != ResultType.RESULT_SET) {
CommandCompleteResponse.send(this.outputStream, command);
break;
}
// fallthrough to QUERY
case QUERY:
case UPDATE:
if (statement.getStatementResult().getResultType() == ResultType.RESULT_SET) {
SendResultSetState state = sendResultSet(statement, mode, maxRows);
statement.setHasMoreData(state.hasMoreRows());
if (state.hasMoreRows() && mode == QueryMode.EXTENDED) {
PortalSuspendedResponse.send(this.outputStream);
} else {
if (!state.hasMoreRows() && mode == QueryMode.EXTENDED) {
statement.close();
}
CommandCompleteResponse.send(this.outputStream, state.getCommandAndNumRows());
}
} else {
// For an INSERT command, the tag is INSERT oid rows, where rows is the number of rows
// inserted. oid used to be the object ID of the inserted row if rows was 1 and the
// target table had OIDs, but OIDs system columns are not supported anymore; therefore
// oid is always 0.
command += ("INSERT".equals(command) ? " 0 " : " ") + statement.getUpdateCount();
CommandCompleteResponse.send(this.outputStream, command);
}
break;
default:
throw new IllegalStateException("Unknown statement type: " + statement.getStatement());
}
} finally {
logger.log(Level.FINER, Logging.format("Send result", Action.Finished));
}
}