tests/sqlite-test.ss
(require (lib "pretty.ss")
         (lib "sqlite.ss" "sqlite"))

; Test
(let ([temp-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"))
    (printf "Total changes: ~a~n" (total-changes-count temp))
    (close temp)))