use of com.facebook.presto.client.StatementClient in project presto by prestodb.
the class PrestoStatement method execute.
@Override
public boolean execute(String sql) throws SQLException {
clearCurrentResults();
checkOpen();
StatementClient client = null;
ResultSet resultSet = null;
try {
client = connection().startQuery(sql);
if (client.isFailed()) {
throw resultsException(client.finalResults());
}
resultSet = new PrestoResultSet(client, maxRows.get(), progressConsumer);
checkSetOrResetSession(client);
// check if this is a query
if (client.current().getUpdateType() == null) {
currentResult.set(resultSet);
return true;
}
// this is an update, not a query
while (resultSet.next()) {
// ignore rows
}
Long updateCount = client.finalResults().getUpdateCount();
currentUpdateCount.set((updateCount != null) ? updateCount : 0);
return false;
} catch (RuntimeException e) {
throw new SQLException("Error executing query", e);
} finally {
if (currentResult.get() == null) {
if (resultSet != null) {
resultSet.close();
}
if (client != null) {
client.close();
}
}
}
}
Aggregations