class PGresult

Constants

BAD_RESPONSE
COMMAND_OK
COPY_IN
COPY_OUT
EMPTY_QUERY
FATAL_ERROR
NONFATAL_ERROR
TUPLES_OK

Attributes

fields[R]

TODO: status, getlength, cmdstatus

result[R]

TODO: status, getlength, cmdstatus

Public Class Methods

new(res) click to toggle source
# File lib/postgres-pr/pg-compat.rb, line 117
def initialize(res)
  @res = res
  @fields = @res.fields.map {|f| f.name}
  @result = []
  @res.rows.each do |row|
    h = {}
    @fields.zip(row){|field, value| h[field] = value}
    @result << h
  end
end

Public Instance Methods

[](index) click to toggle source
# File lib/postgres-pr/pg-compat.rb, line 113
def [](index)
  @result[index]
end
clear() click to toggle source

free the result set

# File lib/postgres-pr/pg-compat.rb, line 204
def clear
  @res = @fields = @result = nil
end
cmd_tuples()
Alias for: cmdtuples
cmdstatus() click to toggle source
# File lib/postgres-pr/pg-compat.rb, line 199
def cmdstatus
  @res.cmd_tag || ''
end
cmdtuples() click to toggle source

Returns the number of rows affected by the SQL command

# File lib/postgres-pr/pg-compat.rb, line 209
def cmdtuples
  case @res.cmd_tag
  when nil 
    return nil
  when /^INSERT\s+(\d+)\s+(\d+)$/, /^(DELETE|UPDATE|MOVE|FETCH)\s+(\d+)$/
    $2.to_i
  else
    nil
  end
end
Also aliased as: cmd_tuples, cmd_tuples
column_values(i) click to toggle source
# File lib/postgres-pr/pg-compat.rb, line 134
def column_values(i)
  raise IndexError, "no column #{i} in result"  unless i < @fields.size
  @res.rows.map{|row| row[i]}
end
each(&block) click to toggle source
# File lib/postgres-pr/pg-compat.rb, line 109
def each(&block)
  @result.each(&block)
end
field_values(field) click to toggle source
# File lib/postgres-pr/pg-compat.rb, line 139
def field_values(field)
  raise IndexError, "no such field '#{field}' in result"  unless @fields.include?(field)
  @result.map{|row| row[field]}
end
fieldname(index)
Alias for: fname
fieldnum(name)
Alias for: fnum
fname(index) click to toggle source
# File lib/postgres-pr/pg-compat.rb, line 158
def fname(index)
  @fields[index]
end
Also aliased as: fieldname
fnum(name) click to toggle source
# File lib/postgres-pr/pg-compat.rb, line 164
def fnum(name)
  @fields.index(name)
end
Also aliased as: fieldnum
ftype(index)
Alias for: type
getlength(tup_num, field_num) click to toggle source
# File lib/postgres-pr/pg-compat.rb, line 187
def getlength(tup_num, field_num)
  @res.rows[typ_num][field_num].length
end
getvalue(tup_num, field_num) click to toggle source
# File lib/postgres-pr/pg-compat.rb, line 183
def getvalue(tup_num, field_num)
  @res.rows[tup_num][field_num]
end
nfields()
Alias for: num_fields
ntuples()
Alias for: num_tuples
num_fields() click to toggle source
# File lib/postgres-pr/pg-compat.rb, line 152
def num_fields
  @fields.size
end
Also aliased as: nfields, nfields
num_tuples() click to toggle source
# File lib/postgres-pr/pg-compat.rb, line 146
def num_tuples
  @result.size
end
Also aliased as: ntuples, ntuples
size(index) click to toggle source
# File lib/postgres-pr/pg-compat.rb, line 177
def size(index)
  raise
  # TODO: correct?
  @res.fields[index].typlen
end
status() click to toggle source
# File lib/postgres-pr/pg-compat.rb, line 191
def status
  if num_tuples > 0
    TUPLES_OK
  else
    COMMAND_OK
  end
end
type(index) click to toggle source
# File lib/postgres-pr/pg-compat.rb, line 170
def type(index)
  # TODO: correct?
  @res.fields[index].type_oid
end
Also aliased as: ftype, ftype
values() click to toggle source

TODO: status, cmdstatus

# File lib/postgres-pr/pg-compat.rb, line 130
def values
  @res.rows
end