mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
SQLite3 valid integer value should be 8 bytes (64-bit signed integer) (#28379)
This is a regression since Rails 4.2. SQLite3 integer is stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value. Assuming default valid value as 4 bytes caused that actual valid value in INTEGER storage class cannot be stored and existing value cannot be found. https://www.sqlite.org/datatype3.html We should allow valid value in INTEGER storage class in SQLite3 to fix the regression. Fixes #22594.
This commit is contained in:
parent
70fa9e9ab7
commit
9b823c02b6
2 changed files with 18 additions and 5 deletions
|
@ -374,6 +374,10 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
private
|
||||
def initialize_type_map(m = type_map)
|
||||
super
|
||||
register_class_with_limit m, %r(int)i, SQLite3Integer
|
||||
end
|
||||
|
||||
def table_structure(table_name)
|
||||
structure = exec_query("PRAGMA table_info(#{quote_table_name(table_name)})", "SCHEMA")
|
||||
|
@ -529,6 +533,17 @@ module ActiveRecord
|
|||
def configure_connection
|
||||
execute("PRAGMA foreign_keys = ON", "SCHEMA")
|
||||
end
|
||||
|
||||
class SQLite3Integer < Type::Integer # :nodoc:
|
||||
private
|
||||
def _limit
|
||||
# INTEGER storage class can be stored 8 bytes value.
|
||||
# See https://www.sqlite.org/datatype3.html#storage_classes_and_datatypes
|
||||
limit || 8
|
||||
end
|
||||
end
|
||||
|
||||
ActiveRecord::Type.register(:integer, SQLite3Integer, adapter: :sqlite3)
|
||||
end
|
||||
ActiveSupport.run_load_hooks(:active_record_sqlite3adapter, SQLite3Adapter)
|
||||
end
|
||||
|
|
|
@ -891,11 +891,9 @@ class BasicsTest < ActiveRecord::TestCase
|
|||
assert_equal 2147483648, company.rating
|
||||
end
|
||||
|
||||
unless current_adapter?(:SQLite3Adapter)
|
||||
def test_bignum_pk
|
||||
company = Company.create!(id: 2147483648, name: "foo")
|
||||
assert_equal company, Company.find(company.id)
|
||||
end
|
||||
def test_bignum_pk
|
||||
company = Company.create!(id: 2147483648, name: "foo")
|
||||
assert_equal company, Company.find(company.id)
|
||||
end
|
||||
|
||||
# TODO: extend defaults tests to other databases!
|
||||
|
|
Loading…
Reference in a new issue