Jan Vroonhof <vroonhof(a)math.ethz.ch> writes in xemacs-beta(a)xemacs.org:
...
3. The harlequin M-BS xanalysis common lisp SQL bindings allow
iterating over the result of a query using map- and do- like
functions. IIRC they do this not by downloading all the results but
by transparently creating a database cursor[1] for you. That would
be very cool.
No problem. I've attached a manual session illustrating cursor usage.
;; I posted the source to `pg-util-query-results' yesterday. It is
;; written in Lisp and iterates over all returned tuples and fields.
(setq P (pq-connectdb "dbname=japanese port=25432"))
#<PGconn localhost:25432 steve/japanese>
(pq-set-client-encoding P "MULE_INTERNAL")
0
(require 'pg-util)
pg-util
(let (R result)
(pq-exec P "BEGIN;")
(setq R (pq-exec P "DECLARE a_cursor CURSOR FOR SELECT * FROM kanji WHERE index
< 5 ORDER BY index;"))
(when (eq (pq-result-status R) 'pgres::command-ok)
(setq R (pq-exec P "FETCH a_cursor;"))
(while (and (eq (pq-result-status R) 'pgres::tuples-ok)
(= (pq-ntuples R) 1))
(push (pg-util-query-results R) result)
(setq R (pq-exec P "FETCH a_cursor;"))))
(pq-exec P "END;")
result)
((("kanji" "index" "nelson" "strokes"
"meaning" "mnemonic" "radical")
("円" "4" "385" "4" "round, yen"
"round coins from bank-teller's window" ""))
(("kanji" "index" "nelson" "strokes"
"meaning" "mnemonic" "radical")
("雨" "3" "6518" "8" "rain" "rain
from heavenly clouds" ""))
(("kanji" "index" "nelson" "strokes"
"meaning" "mnemonic" "radical")
("右" "2" "700" "5" "right" "right
hand to the mouth" ""))
(("kanji" "index" "nelson" "strokes"
"meaning" "mnemonic" "radical")
("一" "1" "1" "1" "one" "one
finger" "")))