Skip to content

Commit 05a9954

Browse files
authored
Merge pull request #1127 from jruby/rails-7-sqlite-fixes
Fix some activerecord spec failures for Rails 7 support
2 parents b9d7236 + ba4fbdc commit 05a9954

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

lib/arjdbc/abstract/database_statements.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ module DatabaseStatements
1010
NO_BINDS = [].freeze
1111

1212
def exec_insert(sql, name = nil, binds = NO_BINDS, pk = nil, sequence_name = nil)
13+
sql = transform_query(sql)
14+
1315
if preventing_writes?
1416
raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
1517
end
@@ -31,6 +33,8 @@ def exec_insert(sql, name = nil, binds = NO_BINDS, pk = nil, sequence_name = nil
3133
# It appears that at this point (AR 5.0) "prepare" should only ever be true
3234
# if prepared statements are enabled
3335
def exec_query(sql, name = nil, binds = NO_BINDS, prepare: false, async: false)
36+
sql = transform_query(sql)
37+
3438
if preventing_writes? && write_query?(sql)
3539
raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
3640
end
@@ -52,6 +56,8 @@ def exec_query(sql, name = nil, binds = NO_BINDS, prepare: false, async: false)
5256
end
5357

5458
def exec_update(sql, name = nil, binds = NO_BINDS)
59+
sql = transform_query(sql)
60+
5561
if preventing_writes?
5662
raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
5763
end
@@ -70,6 +76,8 @@ def exec_update(sql, name = nil, binds = NO_BINDS)
7076
alias :exec_delete :exec_update
7177

7278
def execute(sql, name = nil, async: false)
79+
sql = transform_query(sql)
80+
7381
if preventing_writes? && write_query?(sql)
7482
raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
7583
end

lib/arjdbc/sqlite3/adapter.rb

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -756,37 +756,46 @@ def self.jdbc_connection_class
756756
# Note: This is not an override of ours but a moved line from AR Sqlite3Adapter to register ours vs our copied module (which would be their class).
757757
# ActiveSupport.run_load_hooks(:active_record_sqlite3adapter, SQLite3Adapter)
758758

759+
# DIFFERENCE: FQN
760+
class SQLite3Integer < ::ActiveRecord::Type::Integer # :nodoc:
761+
private
762+
def _limit
763+
# INTEGER storage class can be stored 8 bytes value.
764+
# See https://www.sqlite.org/datatype3.html#storage_classes_and_datatypes
765+
limit || 8
766+
end
767+
end
768+
769+
# DIFFERENCE: FQN
770+
::ActiveRecord::Type.register(:integer, SQLite3Integer, adapter: :sqlite3)
771+
772+
class << self
773+
private
774+
def initialize_type_map(m)
775+
super
776+
register_class_with_limit m, %r(int)i, SQLite3Integer
777+
end
778+
end
779+
780+
TYPE_MAP = ActiveRecord::Type::TypeMap.new.tap { |m| initialize_type_map(m) }
781+
759782
private
760783

761784
# because the JDBC driver doesn't like multiple SQL statements in one JDBC statement
762785
def combine_multi_statements(total_sql)
763786
total_sql
764787
end
765788

789+
def type_map
790+
TYPE_MAP
791+
end
792+
766793
# combine
767794
def write_query?(sql) # :nodoc:
768795
return sql.any? { |stmt| super(stmt) } if sql.kind_of? Array
769796
!READ_QUERY.match?(sql)
770797
rescue ArgumentError # Invalid encoding
771798
!READ_QUERY.match?(sql.b)
772799
end
773-
774-
def initialize_type_map(m = type_map)
775-
super
776-
register_class_with_limit m, %r(int)i, SQLite3Integer
777-
end
778-
779-
# DIFFERENCE: FQN
780-
class SQLite3Integer < ::ActiveRecord::Type::Integer # :nodoc:
781-
private
782-
def _limit
783-
# INTEGER storage class can be stored 8 bytes value.
784-
# See https://www.sqlite.org/datatype3.html#storage_classes_and_datatypes
785-
limit || 8
786-
end
787-
end
788-
789-
# DIFFERENCE: FQN
790-
::ActiveRecord::Type.register(:integer, SQLite3Integer, adapter: :sqlite3)
791800
end
792801
end

0 commit comments

Comments
 (0)