@@ -468,6 +468,54 @@ public IRubyObject readonly_p(final ThreadContext context) throws SQLException {
468468 // note: sqlite3 cext uses this same method but we do not combine all our statements
469469 // into a single ; delimited string but leave it as an array of statements. This is
470470 // because the JDBC way of handling batches is to use addBatch().
471+ // Override execute to ensure Rails 8 compatibility
472+ // Rails 8 SQLite3 adapter expects execute to always return something that responds to to_a
473+ @ Override
474+ @ JRubyMethod (name = "execute" , required = 1 )
475+ public IRubyObject execute (final ThreadContext context , final IRubyObject sql ) {
476+ final String query = sqlString (sql );
477+ return withConnection (context , connection -> {
478+ Statement statement = null ;
479+ try {
480+ statement = createStatement (context , connection );
481+
482+ // SQLite3 can support multiple statements in one query
483+ // Process all results but return the last one for Rails compatibility
484+ boolean hasResultSet = doExecute (statement , query );
485+ int updateCount = statement .getUpdateCount ();
486+
487+ IRubyObject result = newEmptyResult (context ); // Default to empty result
488+ ResultSet resultSet ;
489+
490+ while (hasResultSet || updateCount != -1 ) {
491+
492+ 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 );
501+ }
502+
503+ // Check to see if there is another result set
504+ hasResultSet = statement .getMoreResults ();
505+ updateCount = statement .getUpdateCount ();
506+ }
507+
508+ return result ;
509+
510+ } catch (final SQLException e ) {
511+ debugErrorSQL (context , query );
512+ throw e ;
513+ } finally {
514+ close (statement );
515+ }
516+ });
517+ }
518+
471519 @ JRubyMethod (name = "execute_batch2" )
472520 public IRubyObject execute_batch2 (ThreadContext context , IRubyObject statementsArg ) {
473521 // Assume we will only call this with an array.
0 commit comments