diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-05-20 16:39:25 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-05-20 16:39:25 +0200 |
commit | d17b05657153f4305e4112532c485239d49b77b8 (patch) | |
tree | 89890683aa8ec5f81298415b60cc890c958b2da2 /activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb | |
parent | f9860fcbe2973025df6ccf4bba0431492af09575 (diff) | |
parent | 36fde2b704164ac02380518350f01a17d3e0208e (diff) | |
download | rails-d17b05657153f4305e4112532c485239d49b77b8.tar.gz rails-d17b05657153f4305e4112532c485239d49b77b8.tar.bz2 rails-d17b05657153f4305e4112532c485239d49b77b8.zip |
Merge pull request #15197 from sgrif/sg-delegate-type-cast-sqlite3
Delegate `#type_cast` to injected type objects on SQLite3
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index 03ff0d4ead..7f83891043 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -42,13 +42,21 @@ module ActiveRecord module ConnectionAdapters #:nodoc: class SQLite3Column < Column #:nodoc: - class << self - def binary_to_string(value) - if value.encoding != Encoding::ASCII_8BIT - value = value.force_encoding(Encoding::ASCII_8BIT) - end - value + def type_cast(value) + if encoded? + super + else + cast_type.type_cast(value) + end + end + end + + class SQLite3Binary < Type::Binary # :nodoc: + def cast_value(value) + if value.encoding != Encoding::ASCII_8BIT + value = value.force_encoding(Encoding::ASCII_8BIT) end + value end end @@ -502,6 +510,12 @@ module ActiveRecord end protected + + def initialize_type_map(m) + super + m.register_type(/binary/i, SQLite3Binary.new) + end + def select(sql, name = nil, binds = []) #:nodoc: exec_query(sql, name, binds) end |