chickadee » dbi » get-one

get-one db query #!rest paramsprocedure

Like get-one-row, except it returns only the first field of the first row in the set (or #f if the set is empty).

NOTE: This will still retrieve the entire result set, despite only returning the one row. So it's still up to you to add LIMIT 1 or FETCH FIRST ROW ONLY to your query!

Example:

(define mydb (open 'sqlite3 '((dbname . "/tmp/db"))))
(let ((tuple (get-one-row
               mydb
               "SELECT name, year FROM films WHERE name = ?"
               "The Godfather")))
  (print (vector-ref tuple 0) " -- " (vector-ref tuple 1)))
;; This will print something like:
;; The Godfather -- 1972