Skip to content

Commit 46615f5

Browse files
committed
Explicitly register regproc to eliminate a lot of unknown registered type errors
1 parent 03f7552 commit 46615f5

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

lib/arjdbc/postgresql/oid_types.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,9 @@ def extensions
9191
end
9292

9393
def get_oid_type(oid, fmod, column_name, sql_type = '') # :nodoc:
94-
# This is unhappy with oid of regproc
95-
#if !type_map.key?(oid)
96-
# load_additional_types([oid])
97-
#end
94+
if !type_map.key?(oid)
95+
load_additional_types([oid])
96+
end
9897

9998
type_map.fetch(oid, fmod, sql_type) {
10099
warn "unknown OID #{oid}: failed to recognize type of '#{column_name}'. It will be treated as String."
@@ -146,7 +145,9 @@ def initialize_type_map_inner(m)
146145
m.register_type "path", OID::SpecializedString.new(:path)
147146
m.register_type "polygon", OID::SpecializedString.new(:polygon)
148147
m.register_type "circle", OID::SpecializedString.new(:circle)
149-
148+
m.register_type "regproc", OID::Enum.new
149+
# FIXME: adding this vector type leads to quoting not handlign Array data in quoting.
150+
#m.register_type "_int4", OID::Vector.new(",", m.lookup("int4"))
150151
register_class_with_precision m, "time", Type::Time
151152
register_class_with_precision m, "timestamp", OID::Timestamp
152153
register_class_with_precision m, "timestamptz", OID::TimestampWithTimeZone
@@ -206,6 +207,7 @@ def load_additional_types(oids = nil) # :nodoc:
206207
initializer = ArjdbcTypeMapInitializer.new(type_map)
207208
load_types_queries(initializer, oids) do |query|
208209
execute_and_clear(query, "SCHEMA", []) do |records|
210+
#puts "RECORDS: #{records.to_a}"
209211
initializer.run(records)
210212
end
211213
end
@@ -218,7 +220,14 @@ def load_types_queries(initializer, oids)
218220
LEFT JOIN pg_range as r ON oid = rngtypid
219221
SQL
220222
if oids
221-
yield query + "WHERE t.oid IN (%s)" % oids.join(", ")
223+
if oids.all? { |e| e.kind_of? Numeric }
224+
yield query + "WHERE t.oid IN (%s)" % oids.join(", ")
225+
else
226+
in_list = oids.map { |e| %Q{'#{e}'} }.join(", ")
227+
#puts caller[0..40]
228+
puts "IN_LIST = #{in_list}"
229+
yield query + "WHERE t.typname IN (%s)" % in_list
230+
end
222231
else
223232
yield query + initializer.query_conditions_for_known_type_names
224233
yield query + initializer.query_conditions_for_known_type_types

0 commit comments

Comments
 (0)