Skip to content

Result#to_a raises IndexError #9

@pilcrow

Description

@pilcrow

I believe the fix is that pg::Cursor#next_row should first return if last_row? before doing anything else.

$:» cat x.rb
#!/usr/bin/env ruby

require 'rdbi'
require 'rdbi-driver-postgresql'

puts 'ruby ' + RUBY_VERSION
Gem.loaded_specs.each do |name, gem|
  puts name + ' ' + gem.version.to_s
end
puts

conn_args = { :database => ARGV.shift,
                  :user => ARGV.shift,
              :password => ARGV.shift }

RDBI.connect(:PostgreSQL, conn_args) do |dbh|
  res = dbh.execute("SELECT true");
  puts res.to_a
end

$:» ruby  x.rb postgres me me
ruby 2.0.0
epoxy 0.3.1
typelib 0.1.0
rdbi 1.1.0
bigdecimal 1.2.0
pg 0.9.0
methlab 0.1.0
rdbi-driver-postgresql 0.9.1

/home/me/.gem/ruby/2.0.0/gems/rdbi-driver-postgresql-0.9.1/lib/rdbi/driver/postgresql.rb:148:in `[]': Index 1 is out of range (IndexError)
        from /home/me/.gem/ruby/2.0.0/gems/rdbi-driver-postgresql-0.9.1/lib/rdbi/driver/postgresql.rb:148:in `next_row'
        from /home/me/.gem/ruby/2.0.0/gems/rdbi-1.1.0/lib/rdbi/result.rb:249:in `fetch'
        from /home/me/.gem/ruby/2.0.0/gems/rdbi-1.1.0/lib/rdbi/result.rb:129:in `each'
        from x.rb:18:in `to_a'
        from x.rb:18:in `block in <main>'
        from /home/me/.gem/ruby/2.0.0/gems/rdbi-1.1.0/lib/rdbi.rb:39:in `connect'
        from x.rb:16:in `<main>'

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions