chickadee » dbi » for-each-row

for-each-row proc db query #!rest paramsprocedure

Execute the query on the database connection db and invoke the procedure proc for every row. params should be rest arguments which replace the corresponding "?" placeholders in query.

The procedure should accept one argument, which will be a vector containing the tuple's fields.

Example:

(define mydb (open 'sqlite3 '((dbname . "/tmp/db"))))
(for-each-row (lambda (tuple)
	        (print (vector-ref tuple 0) " -- " (vector-ref tuple 1)))
              mydb
              "SELECT name, year FROM films WHERE name = ? OR name = ?"
              "The Godfather" "Alien")

;; This will print something like:
;; The Godfather -- 1972
;; Alien -- 1979