#lang racket/base
(require ffi/unsafe
ffi/unsafe/define)
(require "ffi-constants.rkt")
(provide (all-from-out "ffi-constants.rkt")
(protect-out (all-defined-out)))
(define-ffi-definer define-sqlite
(case (system-type)
((windows) (ffi-lib "sqlite3.dll"))
(else (ffi-lib "libsqlite3" '("0" #f)))))
(define-cpointer-type _sqlite3_database)
(define-cpointer-type _sqlite3_statement)
(define-sqlite sqlite3_libversion_number
(_fun -> _int))
(define-sqlite sqlite3_open_v2
(_fun (filename flags) ::
(filename : _bytes)
(db : (_ptr o _sqlite3_database))
(flags : _int)
(vfs : _pointer = #f)
-> (result : _int)
-> (values db result)))
(define-sqlite sqlite3_close
(_fun _sqlite3_database
-> _int))
(define-sqlite sqlite3_prepare_v2
(_fun (db zsql) ::
(db : _sqlite3_database) (zsql : _string) ((string-utf-8-length zsql) : _int)
(statement : (_ptr o _sqlite3_statement/null)) (tail : (_ptr o _string))
-> (result : _int)
-> (values result statement tail)))
(define-sqlite sqlite3_finalize
(_fun _sqlite3_statement
-> _int))
(define-sqlite sqlite3_bind_parameter_count
(_fun _sqlite3_statement
-> _int))
(define-sqlite sqlite3_column_count
(_fun _sqlite3_statement
-> _int))
(define-sqlite sqlite3_column_name
(_fun _sqlite3_statement _int
-> _string))
(define-sqlite sqlite3_column_decltype
(_fun _sqlite3_statement _int
-> _string))
(define-sqlite sqlite3_errcode
(_fun _sqlite3_database -> _int))
(define-sqlite sqlite3_errmsg
(_fun _sqlite3_database -> _string))
(define-sqlite sqlite3_bind_int
(_fun _sqlite3_statement _int _int -> _int))
(define-sqlite sqlite3_bind_int64
(_fun _sqlite3_statement _int _int64 -> _int))
(define-sqlite sqlite3_bind_double
(_fun _sqlite3_statement _int _double -> _int))
(define-sqlite sqlite3_bind_text
(_fun (stmt col the-string) ::
(stmt : _sqlite3_statement)
(col : _int)
(string-ptr : _string = the-string)
(string-len : _int = (string-utf-8-length the-string))
(destructor : _intptr = SQLITE_TRANSIENT)
-> _int))
(define-sqlite sqlite3_bind_blob
(_fun (stmt col the-bytes) ::
(stmt : _sqlite3_statement)
(col : _int)
(byte-ptr : _bytes = the-bytes)
(byte-len : _int = (bytes-length the-bytes))
(destructor : _intptr = SQLITE_TRANSIENT)
-> _int))
(define-sqlite sqlite3_bind_null
(_fun _sqlite3_statement _int -> _int))
(define-sqlite sqlite3_reset
(_fun _sqlite3_statement -> _int))
(define-sqlite sqlite3_clear_bindings
(_fun _sqlite3_statement -> _int))
(define-sqlite sqlite3_step
(_fun _sqlite3_statement -> _int))
(define-sqlite sqlite3_column_type
(_fun _sqlite3_statement _int -> _int))
(define-sqlite sqlite3_column_int
(_fun _sqlite3_statement _int -> _int))
(define-sqlite sqlite3_column_int64
(_fun _sqlite3_statement _int -> _int64))
(define-sqlite sqlite3_column_double
(_fun _sqlite3_statement _int -> _double))
(define-sqlite sqlite3_column_text
(_fun _sqlite3_statement _int -> _string))
(define-sqlite sqlite3_column_bytes
(_fun _sqlite3_statement _int -> _int))
(define-sqlite sqlite3_column_blob
(_fun (stmt : _sqlite3_statement)
(col : _int)
-> (blob : _bytes)
-> (let ([len (sqlite3_column_bytes stmt col)])
(bytes-copy (make-sized-byte-string blob len)))))
(define-sqlite sqlite3_get_autocommit
(_fun _sqlite3_database
-> _bool))