- (progn
- (setq R (pq-exec P "SELECT * FROM xemacs_test;"))
- (pq-clear R)
- R)
- => #<PGresult DEAD>
-
- The following set of functions are accessors to various data in the
-PGresult object.
-
- - Function: pq-result-status result
- Return status of a query result. RESULT is a PGresult object.
- The return value is one of the symbols in the following table.
- `pgres::empty-query'
- A query contained no text. This is usually the result of a
- recoverable error, or a minor programming error.
-
- `pgres::command-ok'
- A query command that doesn't return anything was executed
- properly by the backend.
-
- `pgres::tuples-ok'
- A query command that returns tuples was executed properly by
- the backend.
-
- `pgres::copy-out'
- Copy Out data transfer is in progress.
-
- `pgres::copy-in'
- Copy In data transfer is in progress.
-
- `pgres::bad-response'
- An unexpected response was received from the backend.
-
- `pgres::nonfatal-error'
- Undocumented. This value is returned when the libpq function
- `PQresultStatus' is called with a NULL pointer.
-
- `pgres::fatal-error'
- Undocumented. An error has occurred in processing the query
- and the operation was not completed.
-
- - Function: pq-res-status result
- Return the query result status as a string, not a symbol. RESULT
- is a PGresult object.
-
- (setq R (pq-exec P "SELECT * FROM xemacs_test;"))
- => #<PGresult PGRES_TUPLES_OK[5] - SELECT>
- (pq-res-status R)
- => "PGRES_TUPLES_OK"
-
- - Function: pq-result-error-message result
- Return an error message generated by the query, if any. RESULT is
- a PGresult object.
-
- (setq R (pq-exec P "SELECT * FROM xemacs-test;"))
- => <A fatal error is signaled in the echo area>
- (pq-result-error-message R)
- => "ERROR: parser: parse error at or near \"-\"
- "
-
- - Function: pq-ntuples result
- Return the number of tuples in the query result. RESULT is a
- PGresult object.
-
- (setq R (pq-exec P "SELECT * FROM xemacs_test;"))
- => #<PGresult PGRES_TUPLES_OK[5] - SELECT>
- (pq-ntuples R)
- => 5
-
- - Function: pq-nfields result
- Return the number of fields in each tuple of the query result.
- RESULT is a PGresult object.
-
- (setq R (pq-exec P "SELECT * FROM xemacs_test;"))
- => #<PGresult PGRES_TUPLES_OK[5] - SELECT>
- (pq-nfields R)
- => 3
-
- - Function: pq-binary-tuples result
- Returns t if binary tuples are present in the results, nil
- otherwise. RESULT is a PGresult object.
-
- (setq R (pq-exec P "SELECT * FROM xemacs_test;"))
- => #<PGresult PGRES_TUPLES_OK[5] - SELECT>
- (pq-binary-tuples R)
- => nil
-
- - Function: pq-fname result field-index
- Returns the name of a specific field. RESULT is a PGresult object.
- FIELD-INDEX is the number of the column to select from. The first
- column is number zero.
-
- (let (i l)
- (setq R (pq-exec P "SELECT * FROM xemacs_test;"))
- (setq i (pq-nfields R))
- (while (>= (decf i) 0)
- (push (pq-fname R i) l))
- l)
- => ("id" "shikona" "rank")
-
- - Function: pq-fnumber result field-name
- Return the field number corresponding to the given field name. -1
- is returned on a bad field name. RESULT is a PGresult object.
- FIELD-NAME is a string representing the field name to find.
- (setq R (pq-exec P "SELECT * FROM xemacs_test;"))
- => #<PGresult PGRES_TUPLES_OK[5] - SELECT>
- (pq-fnumber R "id")
- => 0
- (pq-fnumber R "Not a field")
- => -1
-
- - Function: pq-ftype result field-num
- Return an integer code representing the data type of the specified
- column. RESULT is a PGresult object. FIELD-NUM is the field
- number.
-
- The return value of this function is the Object ID (Oid) in the
- database of the type. Further queries need to be made to various
- system tables in order to convert this value into something useful.
-
- - Function: pq-fmod result field-num
- Return the type modifier code associated with a field. Field
- numbers start at zero. RESULT is a PGresult object. FIELD-INDEX
- selects which field to use.
-
- - Function: pq-fsize result field-index
- Return size of the given field. RESULT is a PGresult object.
- FIELD-INDEX selects which field to use.
-
- (let (i l)
- (setq R (pq-exec P "SELECT * FROM xemacs_test;"))
- (setq i (pq-nfields R))
- (while (>= (decf i) 0)
- (push (list (pq-ftype R i) (pq-fsize R i)) l))
- l)
- => ((23 23) (25 25) (25 25))
-
- - Function: pq-get-value result tup-num field-num
- Retrieve a return value. RESULT is a PGresult object. TUP-NUM
- selects which tuple to fetch from. FIELD-NUM selects which field
- to fetch from.
-
- Both tuples and fields are numbered from zero.
-
- (setq R (pq-exec P "SELECT * FROM xemacs_test;"))
- => #<PGresult PGRES_TUPLES_OK[5] - SELECT>
- (pq-get-value R 0 1)
- => "Musashimaru"
- (pq-get-value R 1 1)
- => "Dejima"
- (pq-get-value R 2 1)
- => "Musoyama"
-
- - Function: pq-get-length result tup-num field-num
- Return the length of a specific value. RESULT is a PGresult
- object. TUP-NUM selects which tuple to fetch from. FIELD-NUM
- selects which field to fetch from.
-
- (setq R (pq-exec P "SELECT * FROM xemacs_test;"))
- => #<PGresult PGRES_TUPLES_OK[5] - SELECT>
- (pq-get-length R 0 1)
- => 11
- (pq-get-length R 1 1)
- => 6
- (pq-get-length R 2 1)
- => 8
-
- - Function: pq-get-is-null result tup-num field-num
- Return t if the specific value is the SQL NULL. RESULT is a
- PGresult object. TUP-NUM selects which tuple to fetch from.
- FIELD-NUM selects which field to fetch from.
-
- - Function: pq-cmd-status result
- Return a summary string from the query. RESULT is a PGresult
- object.
- (pq-exec P "INSERT INTO xemacs_test
- VALUES (6, 'Wakanohana', 'Yokozuna');")
- => #<PGresult PGRES_COMMAND_OK[1] - INSERT 542086 1>
- (pq-cmd-status R)
- => "INSERT 542086 1"
- (setq R (pq-exec P "UPDATE xemacs_test SET rank='retired'
- WHERE shikona='Wakanohana';"))
- => #<PGresult PGRES_COMMAND_OK[1] - UPDATE 1>
- (pq-cmd-status R)
- => "UPDATE 1"
-
- Note that the first number returned from an insertion, like in the
- example, is an object ID number and will almost certainly vary from
- system to system since object ID numbers in Postgres must be unique
- across all databases.
-
- - Function: pq-cmd-tuples result
- Return the number of tuples if the last command was an
- INSERT/UPDATE/DELETE. If the last command was something else, the
- empty string is returned. RESULT is a PGresult object.
-
- (setq R (pq-exec P "INSERT INTO xemacs_test VALUES
- (7, 'Takanohana', 'Yokuzuna');"))
- => #<PGresult PGRES_COMMAND_OK[1] - INSERT 38688 1>
- (pq-cmd-tuples R)
- => "1"
- (setq R (pq-exec P "SELECT * from xemacs_test;"))
- => #<PGresult PGRES_TUPLES_OK[7] - SELECT>
- (pq-cmd-tuples R)
- => ""
- (setq R (pq-exec P "DELETE FROM xemacs_test
- WHERE shikona LIKE '%hana';"))
- => #<PGresult PGRES_COMMAND_OK[2] - DELETE 2>
- (pq-cmd-tuples R)
- => "2"
-
- - Function: pq-oid-value result
- Return the object id of the insertion if the last command was an
- INSERT. 0 is returned if the last command was not an insertion.
- RESULT is a PGresult object.
-
- In the first example, the numbers you will see on your local
- system will almost certainly be different, however the second
- number from the right in the unprintable PGresult object and the
- number returned by `pq-oid-value' should match.
- (setq R (pq-exec P "INSERT INTO xemacs_test VALUES
- (8, 'Terao', 'Maegashira');"))
- => #<PGresult PGRES_COMMAND_OK[1] - INSERT 542089 1>
- (pq-oid-value R)
- => 542089
- (setq R (pq-exec P "SELECT shikona FROM xemacs_test
- WHERE rank='Maegashira';"))
- => #<PGresult PGRES_TUPLES_OK[2] - SELECT>
- (pq-oid-value R)
- => 0
-
- - Function: pq-make-empty-pgresult conn status
- Create an empty pgresult with the given status. CONN a database
- connection object STATUS a value that can be returned by
- `pq-result-status'.
-
- The caller is responsible for making sure the return value gets
- properly freed.