Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e519168

Browse files
committed
Improves fix for #60 Ruby 3.2 NoMethodError
Two fixes were submitted, both work. I selected the one that mirrors the call used in the PostreSQL adapter in Active Record. The first fix didn't handle DECIMAL(12,10) precision type matching.
1 parent 0e0f668 commit e519168

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

‎lib/postgresql_cursor/cursor.rb‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,14 @@ def column_types
229229
types = {}
230230
fields = @result.fields
231231
fields.each_with_index do |fname, i|
232-
ftype = @result.ftype i
233-
fmod = @result.fmod i
234-
types[fname] = @connection.get_type_map.fetch(ftype.to_s, fmod) do |oid, mod|
235-
# warn "unknown OID: #{fname}(#{oid}, #{mod}) (#{sql})"
236-
if ::ActiveRecord::VERSION::MAJOR <= 4
237-
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::Identity.new
238-
else
239-
::ActiveRecord::Type::Value.new
240-
end
241-
end
232+
ftype = @result.ftype(i)
233+
fmod = @result.fmod(i)
234+
235+
# From @netrusov 2023年01月18日. This is the same call used in the PostgreSQL Adapter
236+
types[fname] = @connection.send(:get_oid_type, ftype, fmod, fname)
237+
238+
# # From @simi 2023年01月18日 (Works as well, used old calling method)
239+
# types[fname] = @connection.get_type_map.fetch(ftype)
242240
end
243241

244242
@column_types = types

‎postgresql_cursor.gemspec‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,12 @@ Gem::Specification.new do |spec|
3030
# Remove this for jruby which should use 'activerecord-jdbcpostgresql-adapter'
3131
# spec.add_dependency 'pg'
3232

33-
spec.add_dependency "activerecord", ">= 3.1.0"
34-
# spec.add_dependency 'activerecord', '~> 3.1.0'
35-
# spec.add_dependency 'activerecord', '~> 4.1.0'
36-
# spec.add_dependency 'activerecord', '~> 5.0.0'
37-
# spec.add_dependency 'activerecord', '~> 6.0.0'
33+
# spec.add_dependency "activerecord", "~> 6.0.0"
34+
spec.add_dependency "activerecord", "~> 7.0.0"
3835

3936
spec.add_development_dependency "irb"
4037
spec.add_development_dependency "minitest"
41-
spec.add_development_dependency "pg"
38+
spec.add_development_dependency "pg"# or jruby-pg?
4239
spec.add_development_dependency "rake"
4340
spec.add_development_dependency "appraisal"
4441
end

‎test/test_postgresql_cursor.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,15 @@ def test_exception_in_failed_transaction
150150
Product.connection.execute("select kaboom")
151151
end
152152
rescue => e
153-
assert_match(/PG::InFailedSqlTransaction/, e.message)
153+
assert_match(/PG::(InFailedSqlTransaction|UndefinedColumn)/, e.message)
154154
end
155155

156156
def test_batch_exception_in_failed_transaction
157157
Product.each_row_batch_by_sql("select * from products") do |r|
158158
Product.connection.execute("select kaboom")
159159
end
160160
rescue => e
161-
assert_match(/PG::InFailedSqlTransaction/, e.message)
161+
assert_match(/PG::(InFailedSqlTransaction|UndefinedColumn)/, e.message)
162162
end
163163

164164
def test_cursor

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /