tests/sqlite-test.ss
(module sqlite-test mzscheme
  (require (lib "pretty.ss")
           "../sqlite.ss")
  
  (let ([temp-path (build-path "/tmp" "test")])
    (when (file-exists? temp-path)
      (delete-file temp-path))
    (let ([temp (open temp-path)])
      (define (exec-sql sql)
        (printf "Exec(~a) result: ~a / ~a~n"
                sql
                (exec temp sql
                      (lambda (columns values)
                        (printf "~a ~a~n" columns values)
                        0))
                (changes-count temp)))
      (exec-sql "CREATE TABLE status (guid TEXT UNIQUE, read INTEGER, followed INTEGER, flagged INTEGER, label INTEGER, deleted INTEGER)")
      ; none deferred immediate exclusive
      (transaction/lock temp exclusive fail
                        (exec-sql "INSERT INTO status VALUES ('foo', 0, 0, 0, 0, 0)")
                        (exec-sql "INSERT INTO status VALUES ('bar', 0, 1, 0, 1, 0)")
                        (fail))
      (exec-sql "SELECT * FROM status")
      (transaction temp fail
                   (exec-sql "INSERT INTO status VALUES ('foo', 0, 0, 0, 0, 0)")
                   (exec-sql "INSERT INTO status VALUES ('bar', 0, 1, 0, 1, 0)"))
      (exec-sql "SELECT * FROM status")
      (let ([insert (prepare temp "INSERT INTO status VALUES (?, ?, 0, 0, 0, 0)")])
        (run insert "zog" 1)
        (run insert "pong" 3)
        (finalize insert))
      (pretty-print (select temp "SELECT * FROM status"))
      (let ([select (prepare temp "SELECT guid FROM status WHERE read = ?")])
        (load-params select 0)
        (printf "~a~n" (step select))
        (printf "~a~n" (step select))
        (load-params select 1)
        (printf "~a~n" (step select))
        (printf "~a~n" (step select))
        (finalize select))
      (printf "Total changes: ~a~n" (total-changes-count temp))
      (close temp))))