Class: PGresult

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/postgres-pr/postgres-compat.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(res) ⇒ PGresult

Returns a new instance of PGresult.



51
52
53
54
55
# File 'lib/postgres-pr/postgres-compat.rb', line 51

def initialize(res)
  @res = res
  @fields = @res.fields.map {|f| f.name}
  @result = @res.rows
end

Instance Attribute Details

#fieldsObject (readonly)

TODO: status, getlength, cmdstatus



59
60
61
# File 'lib/postgres-pr/postgres-compat.rb', line 59

def fields
  @fields
end

#resultObject (readonly)

TODO: status, getlength, cmdstatus



59
60
61
# File 'lib/postgres-pr/postgres-compat.rb', line 59

def result
  @result
end

Instance Method Details

#[](index) ⇒ Object



47
48
49
# File 'lib/postgres-pr/postgres-compat.rb', line 47

def [](index)
  @result[index]
end

#clearObject

free the result set



94
95
96
# File 'lib/postgres-pr/postgres-compat.rb', line 94

def clear
  @res = @fields = @result = nil
end

#each(&block) ⇒ Object



43
44
45
# File 'lib/postgres-pr/postgres-compat.rb', line 43

def each(&block)
  @result.each(&block)
end

#fieldname(index) ⇒ Object



69
70
71
# File 'lib/postgres-pr/postgres-compat.rb', line 69

def fieldname(index)
  @fields[index]
end

#fieldnum(name) ⇒ Object



73
74
75
# File 'lib/postgres-pr/postgres-compat.rb', line 73

def fieldnum(name)
  @fields.index(name)
end

#getvalue(tup_num, field_num) ⇒ Object



89
90
91
# File 'lib/postgres-pr/postgres-compat.rb', line 89

def getvalue(tup_num, field_num)
  @result[tup_num][field_num]
end

#num_fieldsObject



65
66
67
# File 'lib/postgres-pr/postgres-compat.rb', line 65

def num_fields
  @fields.size
end

#num_tuplesObject



61
62
63
# File 'lib/postgres-pr/postgres-compat.rb', line 61

def num_tuples
  @result.size
end

#size(index) ⇒ Object



83
84
85
86
87
# File 'lib/postgres-pr/postgres-compat.rb', line 83

def size(index)
  raise
  # TODO: correct?
  @res.fields[index].typlen
end

#type(index) ⇒ Object



77
78
79
80
81
# File 'lib/postgres-pr/postgres-compat.rb', line 77

def type(index)
  raise
  # TODO: correct?
  @res.fields[index].type_oid
end