Class | PGresult |
In: |
postgres.c
|
Parent: | Object |
The class to represent the query result tuples (rows). An instance of this class is created as the result of every query. You may need to invoke the clear method of the instance when finished with the result for better memory performance.
EMPTY_QUERY | = | INT2FIX(PGRES_EMPTY_QUERY) |
COMMAND_OK | = | INT2FIX(PGRES_COMMAND_OK) |
TUPLES_OK | = | INT2FIX(PGRES_TUPLES_OK) |
COPY_OUT | = | INT2FIX(PGRES_COPY_OUT) |
COPY_IN | = | INT2FIX(PGRES_COPY_IN) |
BAD_RESPONSE | = | INT2FIX(PGRES_BAD_RESPONSE) |
NONFATAL_ERROR | = | INT2FIX(PGRES_NONFATAL_ERROR) |
FATAL_ERROR | = | INT2FIX(PGRES_FATAL_ERROR) |
entries | -> | result |
entries | -> | rows |
Returns the tuple (row) corresponding to n. Returns nil if n >= res.num_tuples.
Equivalent to res.result[n].
Returns the number of tuples (rows) affected by the SQL command.
If the SQL command that generated the PGresult was not one of INSERT, UPDATE, DELETE, MOVE, or FETCH, or if no tuples (rows) were affected, 0 is returned.
Returns the name of the field (column) corresponding to the index.
res=conn.exec("SELECT foo,bar AS biggles,jim,jam FROM mytable") puts res.fieldname(2) => 'jim' puts res.fieldname(1) => 'biggles'
Equivalent to res.fields[index].
Returns the index of the field specified by the string name.
res=conn.exec("SELECT foo,bar AS biggles,jim,jam FROM mytable") puts res.fieldnum('foo') => 0
Raises an ArgumentError if the specified name isn‘t one of the field names; raises a TypeError if name is not a String.
Returns an array of Strings representing the names of the fields in the result.
res=conn.exec("SELECT foo,bar AS biggles,jim,jam FROM mytable") res.fields => [ 'foo' , 'biggles' , 'jim' , 'jam' ]
Returns true if the specified value is nil; false otherwise.
Equivalent to res.value(tup_num,field_num)==nil.
Returns the (String) length of the field in bytes.
Equivalent to res.value(tup_num,field_num).length.
Returns the value in tuple number tup_num, field number field_num. (Row tup_num, column field_num.)
Equivalent to res.result[tup_num][field_num] (but faster).
Returns the value in tuple number tup_num, for the field named field_name.
Equivalent to (but faster than) either of:
res.result[<i>tup_num</i>][ res.fieldnum(<i>field_name</i>) ] res.value( <i>tup_num</i>, res.fieldnum(<i>field_name</i>) )
(This method internally calls value as like the second example above; it is slower than using the field index directly.)
Returns the number of fields (columns) in the query result.
Similar to res.result[0].length (but faster).