Skip to content

Commit e96af8f

Browse files
committed
Dramatically increase OID type matching.
We were never finding some OID types in the type_map and this is at some point in 7.0 they started saving ones which can be namespace-specific in a quoted namespace way "ns"."my_type". Hacked this into our code but I am missing something. Perhaps JDBC resultset processing can do the right thing here.
1 parent cfb95e2 commit e96af8f

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

lib/arjdbc/postgresql/oid_types.rb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# frozen_string_literal: true
2-
32
require 'thread'
43

54
module ArJdbc
@@ -91,8 +90,23 @@ def extensions
9190
end
9291

9392
def get_oid_type(oid, fmod, column_name, sql_type = '') # :nodoc:
94-
if !type_map.key?(oid)
95-
load_additional_types([oid])
93+
# Note: type_map is storing a bunch of oid type prefixed with a namespace even
94+
# if they are not namespaced (e.g. ""."oidvector"). builtin types which are
95+
# common seem to not be prefixed (e.g. "varchar"). OID numbers are also keys
96+
# but JDBC never returns those. So the current scheme is to check with
97+
# what we got and that covers number and plain strings and otherwise we will
98+
# wrap with the namespace form.
99+
found = type_map.key?(oid)
100+
101+
if !found
102+
key = oid.kind_of?(String) && oid != "oid" ? "\"\".\"#{oid}\"" : oid
103+
found = type_map.key?(key)
104+
105+
if !found
106+
load_additional_types([oid])
107+
else
108+
oid = key
109+
end
96110
end
97111

98112
type_map.fetch(oid, fmod, sql_type) {
@@ -207,7 +221,6 @@ def load_additional_types(oids = nil) # :nodoc:
207221
initializer = ArjdbcTypeMapInitializer.new(type_map)
208222
load_types_queries(initializer, oids) do |query|
209223
execute_and_clear(query, "SCHEMA", []) do |records|
210-
#puts "RECORDS: #{records.to_a}"
211224
initializer.run(records)
212225
end
213226
end

0 commit comments

Comments
 (0)