private void processSQL (Connection conn, PrintWriter writer,
OutputType outputType, CommitMode commitMode,
ProcessStatement stmt) throws SQLException {
boolean useSubArrays = (outputType == OutputType.OBJECT);
AkibanAppender appender = AkibanAppender.of(writer);
int nresults = 0;
commitMode.begin(conn);
outputType.begin(appender);
Statement s = stmt.processStatement(nresults);
while (s != null) {
if(useSubArrays) {
beginResultSetArray(appender, nresults == 0, nresults);
}
JDBCResultSet results = (JDBCResultSet) s.getResultSet();
int updateCount = s.getUpdateCount();
if (results != null && !results.isClosed()) {
collectResults(results, appender, options);
// Force close the result set here because if you execute "SELECT...;INSERT..."
// the call to s.getResultSet() returns the (now empty) SELECT result set
// giving bad results
results.close();
} else {
appender.append("\n{\"update_count\":");
appender.append(updateCount);
results = (JDBCResultSet) s.getGeneratedKeys();
if (results != null) {
appender.append(",\n\"returning\":[");
collectResults(results, appender, options);
appender.append("]\n");
}
appender.append("}\n");
}
if(useSubArrays) {
endResultSetArray(appender);
}
++nresults;