Class: PGresult
- Inherits:
-
Object
- Object
- PGresult
- Includes:
- Enumerable
- Defined in:
- lib/postgres-pr/postgres-compat.rb
Constant Summary collapse
- EMPTY_QUERY =
0
- COMMAND_OK =
1
- TUPLES_OK =
2
- COPY_OUT =
3
- COPY_IN =
4
- BAD_RESPONSE =
5
- NONFATAL_ERROR =
6
- FATAL_ERROR =
7
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
TODO: status, getlength, cmdstatus.
-
#result ⇒ Object
readonly
TODO: status, getlength, cmdstatus.
Instance Method Summary collapse
- #[](index) ⇒ Object
-
#clear ⇒ Object
free the result set.
- #cmdstatus ⇒ Object
-
#cmdtuples ⇒ Object
Returns the number of rows affected by the SQL command.
- #each(&block) ⇒ Object
- #fieldname(index) ⇒ Object
- #fieldnum(name) ⇒ Object
- #getvalue(tup_num, field_num) ⇒ Object
-
#initialize(res) ⇒ PGresult
constructor
A new instance of PGresult.
- #num_fields ⇒ Object
- #num_tuples ⇒ Object
- #size(index) ⇒ Object
- #status ⇒ Object
- #type(index) ⇒ Object
Constructor Details
#initialize(res) ⇒ PGresult
Returns a new instance of PGresult.
80 81 82 83 84 |
# File 'lib/postgres-pr/postgres-compat.rb', line 80 def initialize(res) @res = res @fields = @res.fields.map {|f| f.name} @result = @res.rows end |
Instance Attribute Details
#fields ⇒ Object (readonly)
TODO: status, getlength, cmdstatus
88 89 90 |
# File 'lib/postgres-pr/postgres-compat.rb', line 88 def fields @fields end |
#result ⇒ Object (readonly)
TODO: status, getlength, cmdstatus
88 89 90 |
# File 'lib/postgres-pr/postgres-compat.rb', line 88 def result @result end |
Instance Method Details
#[](index) ⇒ Object
76 77 78 |
# File 'lib/postgres-pr/postgres-compat.rb', line 76 def [](index) @result[index] end |
#clear ⇒ Object
free the result set
134 135 136 |
# File 'lib/postgres-pr/postgres-compat.rb', line 134 def clear @res = @fields = @result = nil end |
#cmdstatus ⇒ Object
129 130 131 |
# File 'lib/postgres-pr/postgres-compat.rb', line 129 def cmdstatus @res.cmd_tag || '' end |
#cmdtuples ⇒ Object
Returns the number of rows affected by the SQL command
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/postgres-pr/postgres-compat.rb', line 139 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 |
#each(&block) ⇒ Object
72 73 74 |
# File 'lib/postgres-pr/postgres-compat.rb', line 72 def each(&block) @result.each(&block) end |
#fieldname(index) ⇒ Object
98 99 100 |
# File 'lib/postgres-pr/postgres-compat.rb', line 98 def fieldname(index) @fields[index] end |
#fieldnum(name) ⇒ Object
102 103 104 |
# File 'lib/postgres-pr/postgres-compat.rb', line 102 def fieldnum(name) @fields.index(name) end |
#getvalue(tup_num, field_num) ⇒ Object
117 118 119 |
# File 'lib/postgres-pr/postgres-compat.rb', line 117 def getvalue(tup_num, field_num) @result[tup_num][field_num] end |
#num_fields ⇒ Object
94 95 96 |
# File 'lib/postgres-pr/postgres-compat.rb', line 94 def num_fields @fields.size end |
#num_tuples ⇒ Object
90 91 92 |
# File 'lib/postgres-pr/postgres-compat.rb', line 90 def num_tuples @result.size end |
#size(index) ⇒ Object
111 112 113 114 115 |
# File 'lib/postgres-pr/postgres-compat.rb', line 111 def size(index) raise PGError, 'size not implemented' # TODO: correct? @res.fields[index].typlen end |
#status ⇒ Object
121 122 123 124 125 126 127 |
# File 'lib/postgres-pr/postgres-compat.rb', line 121 def status if num_tuples > 0 TUPLES_OK else COMMAND_OK end end |
#type(index) ⇒ Object
106 107 108 109 |
# File 'lib/postgres-pr/postgres-compat.rb', line 106 def type(index) # TODO: correct? @res.fields[index].type_oid end |