From 5b5c884d36d40b7aac62bc03bbb1db08795b6297 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Thu, 15 Aug 2019 08:10:06 -0700 Subject: [PATCH] Convert all database array types to Ruby arrays in the jdbc adapter This is done if convert_types is true for the Database, which is the default (it can be set to false for better performance). Remove the related code in the jdbc/postgresql adapter as it is no longer needed. --- CHANGELOG | 2 ++ lib/sequel/adapters/jdbc.rb | 8 +++++++- lib/sequel/adapters/jdbc/postgresql.rb | 14 +------------- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 67d501edcc..278189868c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ === master +* Convert all database array types to Ruby arrays in the jdbc adapter (jeremyevans) + * Add static_cache_cache plugin for caching rows for static_cache models to a file to avoid database queries during model initialization (jeremyevans) * Add :cache_file plugin option to pg_auto_constraint_validations plugin, for caching metadata to a file for faster initialization (jeremyevans) diff --git a/lib/sequel/adapters/jdbc.rb b/lib/sequel/adapters/jdbc.rb index da876b2e8f..43c6dac67e 100644 --- a/lib/sequel/adapters/jdbc.rb +++ b/lib/sequel/adapters/jdbc.rb @@ -102,12 +102,17 @@ def x.call(r, i) v.getSubString(1, v.length) end end + x = convertors[:RubyArray] = Object.new + def x.call(r, i) + if v = r.getArray(i) + v.array.to_ary + end + end MAP = Hash.new(convertors[:Object]) types = Java::JavaSQL::Types { - :ARRAY => :Array, :BOOLEAN => :Boolean, :CHAR => :String, :DOUBLE => :Double, @@ -126,6 +131,7 @@ def x.call(r, i) BASIC_MAP = MAP.dup { + :ARRAY => :Array, :BINARY => :Blob, :BLOB => :Blob, :CLOB => :Clob, diff --git a/lib/sequel/adapters/jdbc/postgresql.rb b/lib/sequel/adapters/jdbc/postgresql.rb index bbbfe74f84..5ad286fec2 100644 --- a/lib/sequel/adapters/jdbc/postgresql.rb +++ b/lib/sequel/adapters/jdbc/postgresql.rb @@ -195,17 +195,7 @@ def literal_sqltime(v) STRING_TYPE = Java::JavaSQL::Types::VARCHAR ARRAY_TYPE = Java::JavaSQL::Types::ARRAY - PG_SPECIFIC_TYPES = [ARRAY_TYPE, Java::JavaSQL::Types::OTHER, Java::JavaSQL::Types::STRUCT, Java::JavaSQL::Types::TIME_WITH_TIMEZONE, Java::JavaSQL::Types::TIME].freeze - - # Return PostgreSQL array types as ruby Arrays instead of - # JDBC PostgreSQL driver-specific array type. Only used if the - # database does not have a conversion proc for the type. - ARRAY_METHOD = Object.new - def ARRAY_METHOD.call(r, i) - if v = r.getArray(i) - v.array.to_ary - end - end + PG_SPECIFIC_TYPES = [Java::JavaSQL::Types::ARRAY, Java::JavaSQL::Types::OTHER, Java::JavaSQL::Types::STRUCT, Java::JavaSQL::Types::TIME_WITH_TIMEZONE, Java::JavaSQL::Types::TIME].freeze # Return PostgreSQL hstore types as ruby Hashes instead of # Java HashMaps. Only used if the database does not have a @@ -223,8 +213,6 @@ def type_convertor(map, meta, type, i) oid = meta.getField(i).getOID if pr = db.oid_convertor_proc(oid) pr - elsif type == ARRAY_TYPE - ARRAY_METHOD elsif oid == 2950 # UUID map[STRING_TYPE] elsif meta.getPGType(i) == 'hstore'