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.
73 74 75 76 77 |
# File 'lib/postgres-pr/postgres-compat.rb', line 73 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
81 82 83 |
# File 'lib/postgres-pr/postgres-compat.rb', line 81 def fields @fields end |
#result ⇒ Object (readonly)
TODO: status, getlength, cmdstatus
81 82 83 |
# File 'lib/postgres-pr/postgres-compat.rb', line 81 def result @result end |
Instance Method Details
#[](index) ⇒ Object
69 70 71 |
# File 'lib/postgres-pr/postgres-compat.rb', line 69 def [](index) @result[index] end |
#clear ⇒ Object
free the result set
127 128 129 |
# File 'lib/postgres-pr/postgres-compat.rb', line 127 def clear @res = @fields = @result = nil end |
#cmdstatus ⇒ Object
122 123 124 |
# File 'lib/postgres-pr/postgres-compat.rb', line 122 def cmdstatus @res.cmd_tag || '' end |
#cmdtuples ⇒ Object
Returns the number of rows affected by the SQL command
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/postgres-pr/postgres-compat.rb', line 132 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
65 66 67 |
# File 'lib/postgres-pr/postgres-compat.rb', line 65 def each(&block) @result.each(&block) end |
#fieldname(index) ⇒ Object
91 92 93 |
# File 'lib/postgres-pr/postgres-compat.rb', line 91 def fieldname(index) @fields[index] end |
#fieldnum(name) ⇒ Object
95 96 97 |
# File 'lib/postgres-pr/postgres-compat.rb', line 95 def fieldnum(name) @fields.index(name) end |
#getvalue(tup_num, field_num) ⇒ Object
110 111 112 |
# File 'lib/postgres-pr/postgres-compat.rb', line 110 def getvalue(tup_num, field_num) @result[tup_num][field_num] end |
#num_fields ⇒ Object
87 88 89 |
# File 'lib/postgres-pr/postgres-compat.rb', line 87 def num_fields @fields.size end |
#num_tuples ⇒ Object
83 84 85 |
# File 'lib/postgres-pr/postgres-compat.rb', line 83 def num_tuples @result.size end |
#size(index) ⇒ Object
104 105 106 107 108 |
# File 'lib/postgres-pr/postgres-compat.rb', line 104 def size(index) raise # TODO: correct? @res.fields[index].typlen end |
#status ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/postgres-pr/postgres-compat.rb', line 114 def status if num_tuples > 0 TUPLES_OK else COMMAND_OK end end |
#type(index) ⇒ Object
99 100 101 102 |
# File 'lib/postgres-pr/postgres-compat.rb', line 99 def type(index) # TODO: correct? @res.fields[index].type_oid end |