From 8d1e8e07bca631bd04cee08a05d6944bc6fd7fcd Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 5 Jun 2019 17:55:20 +0900 Subject: [PATCH] AR connection adapter may not yet be loaded here And, we'd better not define a toplevel constant for this fixes #41 --- lib/postgresql_cursor/cursor.rb | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/postgresql_cursor/cursor.rb b/lib/postgresql_cursor/cursor.rb index a8f17e9..3389799 100644 --- a/lib/postgresql_cursor/cursor.rb +++ b/lib/postgresql_cursor/cursor.rb @@ -1,5 +1,3 @@ -require 'active_record/connection_adapters/postgresql/oid' - ################################################################################ # PostgreSQLCursor: library class provides postgresql cursor for large result # set processing. Requires ActiveRecord, but can be adapted to other DBI/ORM libraries. @@ -20,13 +18,6 @@ # ActiveRecordModel.each_instance_by_sql("select ...") { |model| ... } # - -if ::ActiveRecord::VERSION::MAJOR <= 4 - OID = ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID -else - OID = ActiveRecord::ConnectionAdapters::PostgreSQL::OID -end - module PostgreSQLCursor class Cursor include Enumerable @@ -240,7 +231,11 @@ def column_types fmod = @result.fmod i types[fname] = @connection.get_type_map.fetch(ftype, fmod) { |oid, mod| warn "unknown OID: #{fname}(#{oid}) (#{sql})" - OID::Identity.new + if ::ActiveRecord::VERSION::MAJOR <= 4 + ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::Identity.new + else + ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Identity.new + end } end