@@ -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