sqlite-ffi-test.ss
(module sqlite-ffi-test mzscheme
  (require "sqlite-ffi.ss")
  
  ; Helpers
  (define (sqlite-ok? s)
    (= s SQLITE_OK))
  
  ; Test
  (define (quickstart-example db-path sql)
    (define exec-callback
      (lambda (arg_pointer column-count_int column-values_pointer column-names_pointer)
        (printf "~a ~a ~a ~a~n" arg_pointer column-count_int 
                (cvector->list (make-cvector* column-values_pointer _string column-count_int))
                (cvector->list (make-cvector* column-names_pointer _string column-count_int)))
        0))
    
    (define db (malloc _pointer))
    (define callback-arg (malloc _pointer))
    (define errMsg (malloc _pointer))
    
    (ptr-set! callback-arg _int 0)
    (if (sqlite-ok? (sqlite3_open db-path db))      (begin
                                                      (printf "Exec result: ~a.~n"
                                                              (sqlite3_exec (ptr-ref db _pointer) 
                                                                            sql
                                                                            exec-callback
                                                                            callback-arg
                                                                            errMsg))
                                                      (printf "Changes result: ~a.~n"
                                                              (sqlite3_changes (ptr-ref db _pointer))))
        (printf "Error opening database.~n"))
    
    (sqlite3_close (ptr-ref db _pointer))
    
    (free db)
    (free callback-arg)
    (free errMsg))
  
  (when (file-exists? "/tmp/test")
    (delete-file "/tmp/test"))
  (quickstart-example "/tmp/test" "CREATE TABLE status (guid TEXT UNIQUE, read INTEGER, followed INTEGER, flagged INTEGER, label INTEGER, deleted INTEGER)" )
  (quickstart-example "/tmp/test" "INSERT INTO status VALUES ('foo', 0, 0, 0, 0, 0)")
  (quickstart-example "/tmp/test" "INSERT INTO status VALUES ('bar', 0, 1, 0, 1, 0)")
  (quickstart-example "/tmp/test" "SELECT * FROM status"))