Skip to content

Commit 436600a

Browse files
committed
Make only last resultset process and only generate one emptyResultSet
1 parent 63ce824 commit 436600a

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -484,29 +484,25 @@ public IRubyObject execute(final ThreadContext context, final IRubyObject sql) {
484484
boolean hasResultSet = doExecute(statement, query);
485485
int updateCount = statement.getUpdateCount();
486486

487-
IRubyObject result = newEmptyResult(context); // Default to empty result
488-
ResultSet resultSet;
489-
490487
while (hasResultSet || updateCount != -1) {
491-
492488
if (hasResultSet) {
493-
resultSet = statement.getResultSet();
494-
// For SELECT queries, return propr Result object
495-
result = mapQueryResult(context, connection, resultSet);
496-
resultSet.close();
497-
} else {
498-
// For INSERT/UPDATE/DELETE, return empty Result
499-
// Rails 8 SQLite3 adapter will convert this to [] via to_a
500-
result = newEmptyResult(context);
489+
ResultSet resultSet = statement.getResultSet();
490+
491+
// Check to see if there is another result set
492+
hasResultSet = statement.getMoreResults();
493+
// No next result so process what we have and return
494+
if (!hasResultSet) {
495+
// For SELECT queries, return propr Result object
496+
IRubyObject result = mapQueryResult(context, connection, resultSet);
497+
resultSet.close();
498+
return result;
499+
}
501500
}
502501

503-
// Check to see if there is another result set
504-
hasResultSet = statement.getMoreResults();
505502
updateCount = statement.getUpdateCount();
506503
}
507504

508-
return result;
509-
505+
return newEmptyResult(context);
510506
} catch (final SQLException e) {
511507
debugErrorSQL(context, query);
512508
throw e;

0 commit comments

Comments
 (0)