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.
68 69 70 71 72 |
# File 'lib/postgres-pr/postgres-compat.rb', line 68 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
76 77 78 |
# File 'lib/postgres-pr/postgres-compat.rb', line 76 def fields @fields end |
#result ⇒ Object (readonly)
TODO: status, getlength, cmdstatus
76 77 78 |
# File 'lib/postgres-pr/postgres-compat.rb', line 76 def result @result end |
Instance Method Details
#[](index) ⇒ Object
64 65 66 |
# File 'lib/postgres-pr/postgres-compat.rb', line 64 def [](index) @result[index] end |
#clear ⇒ Object
free the result set
122 123 124 |
# File 'lib/postgres-pr/postgres-compat.rb', line 122 def clear @res = @fields = @result = nil end |
#cmdstatus ⇒ Object
117 118 119 |
# File 'lib/postgres-pr/postgres-compat.rb', line 117 def cmdstatus @res.cmd_tag || '' end |
#cmdtuples ⇒ Object
Returns the number of rows affected by the SQL command
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/postgres-pr/postgres-compat.rb', line 127 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
60 61 62 |
# File 'lib/postgres-pr/postgres-compat.rb', line 60 def each(&block) @result.each(&block) end |
#fieldname(index) ⇒ Object
86 87 88 |
# File 'lib/postgres-pr/postgres-compat.rb', line 86 def fieldname(index) @fields[index] end |
#fieldnum(name) ⇒ Object
90 91 92 |
# File 'lib/postgres-pr/postgres-compat.rb', line 90 def fieldnum(name) @fields.index(name) end |
#getvalue(tup_num, field_num) ⇒ Object
105 106 107 |
# File 'lib/postgres-pr/postgres-compat.rb', line 105 def getvalue(tup_num, field_num) @result[tup_num][field_num] end |
#num_fields ⇒ Object
82 83 84 |
# File 'lib/postgres-pr/postgres-compat.rb', line 82 def num_fields @fields.size end |
#num_tuples ⇒ Object
78 79 80 |
# File 'lib/postgres-pr/postgres-compat.rb', line 78 def num_tuples @result.size end |
#size(index) ⇒ Object
99 100 101 102 103 |
# File 'lib/postgres-pr/postgres-compat.rb', line 99 def size(index) raise # TODO: correct? @res.fields[index].typlen end |
#status ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/postgres-pr/postgres-compat.rb', line 109 def status if num_tuples > 0 TUPLES_OK else COMMAND_OK end end |
#type(index) ⇒ Object
94 95 96 97 |
# File 'lib/postgres-pr/postgres-compat.rb', line 94 def type(index) # TODO: correct? @res.fields[index].type_oid end |