@@ -483,29 +483,25 @@ public IRubyObject execute(final ThreadContext context, final IRubyObject sql) {
483483 // Process all results but return the last one for Rails compatibility
484484 boolean hasResultSet = doExecute (statement , query );
485485 int updateCount = statement .getUpdateCount ();
486-
487- IRubyObject result = newEmptyResult (context ); // Default to empty result
488- ResultSet resultSet ;
486+ IRubyObject result = null ;
489487
490488 while (hasResultSet || updateCount != -1 ) {
491-
489+ // Query has results to process (insert/update/delete) we move on to next
492490 if (hasResultSet ) {
493- resultSet = statement .getResultSet ();
491+ ResultSet resultSet = statement .getResultSet ();
494492 // For SELECT queries, return propr Result object
495493 result = mapQueryResult (context , connection , resultSet );
496494 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 );
501495 }
502496
503497 // Check to see if there is another result set
504498 hasResultSet = statement .getMoreResults ();
505499 updateCount = statement .getUpdateCount ();
506500 }
507501
508- return result ;
502+ return result == null ?
503+ newEmptyResult (context ) :
504+ result ;
509505
510506 } catch (final SQLException e ) {
511507 debugErrorSQL (context , query );
0 commit comments