@@ -223,17 +223,29 @@ def supports_lazy_transactions?
223
223
224
224
# REFERENTIAL INTEGRITY ====================================
225
225
226
+ def execute_batch ( statements , name = nil , **kwargs )
227
+ if statements . is_a? ( Array )
228
+ # SQLite JDBC doesn't support multiple statements in one execute
229
+ # Execute each statement separately
230
+ statements . each do |sql |
231
+ raw_execute ( sql , name , **kwargs . merge ( batch : true ) )
232
+ end
233
+ else
234
+ raw_execute ( statements , name , batch : true , **kwargs )
235
+ end
236
+ end
237
+
226
238
def disable_referential_integrity # :nodoc:
227
239
old_foreign_keys = query_value ( "PRAGMA foreign_keys" )
228
240
old_defer_foreign_keys = query_value ( "PRAGMA defer_foreign_keys" )
229
241
230
242
begin
231
- execute ( "PRAGMA defer_foreign_keys = ON" )
232
- execute ( "PRAGMA foreign_keys = OFF" )
243
+ raw_execute ( "PRAGMA defer_foreign_keys = ON" , "SCHEMA" , allow_retry : false , materialize_transactions : false )
244
+ raw_execute ( "PRAGMA foreign_keys = OFF" , "SCHEMA" , allow_retry : false , materialize_transactions : false )
233
245
yield
234
246
ensure
235
- execute ( "PRAGMA defer_foreign_keys = #{ old_defer_foreign_keys } " )
236
- execute ( "PRAGMA foreign_keys = #{ old_foreign_keys } " )
247
+ raw_execute ( "PRAGMA defer_foreign_keys = #{ old_defer_foreign_keys } " , "SCHEMA" , allow_retry : false , materialize_transactions : false )
248
+ raw_execute ( "PRAGMA foreign_keys = #{ old_foreign_keys } " , "SCHEMA" , allow_retry : false , materialize_transactions : false )
237
249
end
238
250
end
239
251
@@ -809,7 +821,17 @@ def configure_connection
809
821
DEFAULT_PRAGMAS . merge ( pragmas ) . each do |pragma , value |
810
822
if ::SQLite3 ::Pragmas . respond_to? ( pragma )
811
823
stmt = ::SQLite3 ::Pragmas . public_send ( pragma , value )
812
- raw_execute ( stmt , "SCHEMA" )
824
+ # Skip pragma execution if we're inside a transaction and it's not allowed
825
+ begin
826
+ raw_execute ( stmt , "SCHEMA" )
827
+ rescue => e
828
+ if e . message . include? ( "Safety level may not be changed inside a transaction" )
829
+ # Log warning and skip this pragma
830
+ warn "Cannot set pragma '#{ pragma } ' inside a transaction, skipping"
831
+ else
832
+ raise
833
+ end
834
+ end
813
835
else
814
836
warn "Unknown SQLite pragma: #{ pragma } "
815
837
end
@@ -863,7 +885,7 @@ def jdbc_connection_class
863
885
include ArJdbc ::Abstract ::ConnectionManagement
864
886
include ArJdbc ::Abstract ::DatabaseStatements
865
887
include ArJdbc ::Abstract ::StatementCache
866
- include ArJdbc :: Abstract :: TransactionSupport
888
+ # Don't include TransactionSupport - use Rails' SQLite3::DatabaseStatements instead
867
889
868
890
869
891
##
@@ -972,7 +994,8 @@ def initialize_type_map(m)
972
994
973
995
# because the JDBC driver doesn't like multiple SQL statements in one JDBC statement
974
996
def combine_multi_statements ( total_sql )
975
- total_sql
997
+ # For Rails 8 compatibility - join multiple statements with semicolon
998
+ total_sql . is_a? ( Array ) ? total_sql . join ( ";\n " ) : total_sql
976
999
end
977
1000
978
1001
def type_map
0 commit comments