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

; Test
(let ([temp-path "/tmp/test"])
  (when (file-exists? temp-path)
    (delete-file temp-path))
  (let* ([temp (new db% (path temp-path))]
         [temp-stmt% (send temp statement%)])
    (define (exec-sql sql)
      (printf "Exec(~a) result: ~a / ~a~n"
              sql
              (send temp exec sql
                    (lambda (columns values)
                      (printf "~a ~a~n" columns values)
                      0))
              (send temp changes-count)))
    (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 (new temp-stmt% (sql "INSERT INTO status VALUES (?, ?, 0, 0, 0, 0)"))])
      (send insert run "zog" "1")
      (send insert run "pong" "3"))
    (pretty-print (send temp select "SELECT * FROM status"))
    (let ([select (new temp-stmt% (sql "SELECT guid FROM status WHERE read = ?"))])
      (send select load-params "0")
      (printf "~a~n" (send select step))
      (printf "~a~n" (send select step))
      (send select load-params "1")
      (printf "~a~n" (send select step))
      (printf "~a~n" (send select step)))
    (printf "Total changes: ~a~n" (send temp total-changes-count))))