aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-05-20 13:55:03 -0700
committerSean Griffin <sean@thoughtbot.com>2014-05-20 13:55:03 -0700
commit9f61f31c2cbf8c1d7b6ce33f28c67f900774fd58 (patch)
tree84c352e176db99f6d195be7277f10c974240dd39 /activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
parent25c672637206a2c48fd829c58596c788b6e31c5d (diff)
downloadrails-9f61f31c2cbf8c1d7b6ce33f28c67f900774fd58.tar.gz
rails-9f61f31c2cbf8c1d7b6ce33f28c67f900774fd58.tar.bz2
rails-9f61f31c2cbf8c1d7b6ce33f28c67f900774fd58.zip
Use the generic type map for PostgreSQL OID registrations
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb23
1 files changed, 20 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index f46af35f55..ed3e884455 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -369,7 +369,7 @@ module ActiveRecord
raise "Your version of PostgreSQL (#{postgresql_version}) is too old, please upgrade!"
end
- @type_map = OID::TypeMap.new
+ @type_map = Type::HashLookupTypeMap.new
initialize_type_map(type_map)
@local_tz = execute('SHOW TIME ZONE', 'SCHEMA').first["TimeZone"]
@use_insert_returning = @config.key?(:insert_returning) ? self.class.type_cast_config_to_boolean(@config[:insert_returning]) : true
@@ -543,12 +543,29 @@ module ActiveRecord
initialize_type_map(type_map, [oid])
end
- type_map.fetch(oid, fmod) {
+ type_map.fetch(normalize_oid_type(oid, fmod)) {
warn "unknown OID #{oid}: failed to recognize type of '#{column_name}'. It will be treated as String."
- type_map[oid] = Type::Value.new
+ Type::Value.new.tap do |cast_type|
+ type_map.register_type(oid, cast_type)
+ end
}
end
+ def normalize_oid_type(ftype, fmod)
+ # The type for the numeric depends on the width of the field,
+ # so we'll do something special here.
+ #
+ # When dealing with decimal columns:
+ #
+ # places after decimal = fmod - 4 & 0xffff
+ # places before decimal = (fmod - 4) >> 16 & 0xffff
+ if ftype == 1700 && (fmod - 4 & 0xffff).zero?
+ 23
+ else
+ ftype
+ end
+ end
+
def initialize_type_map(type_map, oids = nil)
if supports_ranges?
query = <<-SQL