Class: PGresult
- Inherits:
-
Object
- Object
- PGresult
- Includes:
- Enumerable
- Defined in:
- lib/postgres-pr/pg-compat.rb,
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
(also: #cmd_tuples)
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 (also: #nfields)
- #num_tuples ⇒ Object (also: #ntuples)
- #size(index) ⇒ Object
- #status ⇒ Object
- #type(index) ⇒ Object (also: #ftype)
Constructor Details
#initialize(res) ⇒ PGresult
Returns a new instance of PGresult.
90 91 92 93 94 95 96 97 |
# File 'lib/postgres-pr/pg-compat.rb', line 90 def initialize(res) @res = res @fields = @res.fields.map {|f| f.name} @result = [] @res.rows.each do |row| @result << REXML::SyncEnumerator.new(fields, row).map {|name, value| [name, value]} end end |
Instance Attribute Details
#fields ⇒ Object (readonly)
TODO: status, getlength, cmdstatus
101 102 103 |
# File 'lib/postgres-pr/pg-compat.rb', line 101 def fields @fields end |
#result ⇒ Object (readonly)
TODO: status, getlength, cmdstatus
101 102 103 |
# File 'lib/postgres-pr/pg-compat.rb', line 101 def result @result end |
Instance Method Details
#[](index) ⇒ Object
86 87 88 |
# File 'lib/postgres-pr/pg-compat.rb', line 86 def [](index) @result[index] end |
#clear ⇒ Object
free the result set
153 154 155 |
# File 'lib/postgres-pr/pg-compat.rb', line 153 def clear @res = @fields = @result = nil end |
#cmdstatus ⇒ Object
148 149 150 |
# File 'lib/postgres-pr/pg-compat.rb', line 148 def cmdstatus @res.cmd_tag || '' end |
#cmdtuples ⇒ Object Also known as: cmd_tuples
Returns the number of rows affected by the SQL command
158 159 160 161 162 163 164 165 166 167 |
# File 'lib/postgres-pr/pg-compat.rb', line 158 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
82 83 84 |
# File 'lib/postgres-pr/pg-compat.rb', line 82 def each(&block) @result.each(&block) end |
#fieldname(index) ⇒ Object
115 116 117 |
# File 'lib/postgres-pr/pg-compat.rb', line 115 def fieldname(index) @fields[index] end |
#fieldnum(name) ⇒ Object
119 120 121 |
# File 'lib/postgres-pr/pg-compat.rb', line 119 def fieldnum(name) @fields.index(name) end |
#getvalue(tup_num, field_num) ⇒ Object
136 137 138 |
# File 'lib/postgres-pr/pg-compat.rb', line 136 def getvalue(tup_num, field_num) @result[tup_num][field_num] end |
#num_fields ⇒ Object Also known as: nfields
109 110 111 |
# File 'lib/postgres-pr/pg-compat.rb', line 109 def num_fields @fields.size end |
#num_tuples ⇒ Object Also known as: ntuples
103 104 105 |
# File 'lib/postgres-pr/pg-compat.rb', line 103 def num_tuples @result.size end |
#size(index) ⇒ Object
130 131 132 133 134 |
# File 'lib/postgres-pr/pg-compat.rb', line 130 def size(index) raise # TODO: correct? @res.fields[index].typlen end |
#status ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/postgres-pr/pg-compat.rb', line 140 def status if num_tuples > 0 TUPLES_OK else COMMAND_OK end end |
#type(index) ⇒ Object Also known as: ftype
123 124 125 126 |
# File 'lib/postgres-pr/pg-compat.rb', line 123 def type(index) # TODO: correct? @res.fields[index].type_oid end |