Documentation and metadata update for 0.2.1 release.
[cl-sqlite.git] / sqlite-ffi.lisp
blob09964f71fa43530414ae4f3b6d526898b8a5ceb0
1 (defpackage :sqlite-ffi
2 (:use :cl :cffi)
3 (:export :error-code
4 :p-sqlite3
5 :sqlite3-open
6 :sqlite3-close
7 :sqlite3-errmsg
8 :sqlite3-busy-timeout
9 :p-sqlite3-stmt
10 :sqlite3-prepare
11 :sqlite3-finalize
12 :sqlite3-step
13 :sqlite3-reset
14 :sqlite3-clear-bindings
15 :sqlite3-column-count
16 :sqlite3-column-type
17 :sqlite3-column-text
18 :sqlite3-column-int64
19 :sqlite3-column-double
20 :sqlite3-column-bytes
21 :sqlite3-column-blob
22 :sqlite3-column-name
23 :sqlite3-bind-parameter-count
24 :sqlite3-bind-parameter-name
25 :sqlite3-bind-parameter-index
26 :sqlite3-bind-double
27 :sqlite3-bind-int64
28 :sqlite3-bind-null
29 :sqlite3-bind-text
30 :sqlite3-bind-blob
31 :destructor-transient
32 :destructor-static
33 :sqlite3-last-insert-rowid))
35 (in-package :sqlite-ffi)
37 (define-foreign-library sqlite3-lib
38 (:darwin (:default "libsqlite3"))
39 (:unix (:or "libsqlite3.so.0" "libsqlite3.so"))
40 (t (:or (:default "libsqlite3") (:default "sqlite3"))))
42 (use-foreign-library sqlite3-lib)
44 (defcenum error-code
45 (:OK 0)
46 (:ERROR 1)
47 (:INTERNAL 2)
48 (:PERM 3)
49 (:ABORT 4)
50 (:BUSY 5)
51 (:LOCKED 6)
52 (:NOMEM 7)
53 (:READONLY 8)
54 (:INTERRUPT 9)
55 (:IOERR 10)
56 (:CORRUPT 11)
57 (:NOTFOUND 12)
58 (:FULL 13)
59 (:CANTOPEN 14)
60 (:PROTOCOL 15)
61 (:EMPTY 16)
62 (:SCHEMA 17)
63 (:TOOBIG 18)
64 (:CONSTRAINT 19)
65 (:MISMATCH 20)
66 (:MISUSE 21)
67 (:NOLFS 22)
68 (:AUTH 23)
69 (:FORMAT 24)
70 (:RANGE 25)
71 (:NOTADB 26)
72 (:ROW 100)
73 (:DONE 101))
75 (defcstruct sqlite3)
77 (defctype p-sqlite3 (:pointer sqlite3))
79 (defcfun sqlite3-open error-code
80 (filename :string)
81 (db (:pointer p-sqlite3)))
83 (defcfun sqlite3-close error-code
84 (db p-sqlite3))
86 (defcfun sqlite3-errmsg :string
87 (db p-sqlite3))
89 (defcfun sqlite3-busy-timeout :int
90 (db p-sqlite3)
91 (ms :int))
93 (defcstruct sqlite3-stmt)
95 (defctype p-sqlite3-stmt (:pointer sqlite3-stmt))
97 (defcfun (sqlite3-prepare "sqlite3_prepare_v2") error-code
98 (db p-sqlite3)
99 (sql :string)
100 (sql-length-bytes :int)
101 (stmt (:pointer p-sqlite3-stmt))
102 (tail (:pointer (:pointer :char))))
104 (defcfun sqlite3-finalize error-code
105 (statement p-sqlite3-stmt))
107 (defcfun sqlite3-step error-code
108 (statement p-sqlite3-stmt))
110 (defcfun sqlite3-reset error-code
111 (statement p-sqlite3-stmt))
113 (defcfun sqlite3-clear-bindings error-code
114 (statement p-sqlite3-stmt))
116 (defcfun sqlite3-column-count :int
117 (statement p-sqlite3-stmt))
119 (defcenum type-code
120 (:integer 1)
121 (:float 2)
122 (:text 3)
123 (:blob 4)
124 (:null 5))
126 (defcfun sqlite3-column-type type-code
127 (statement p-sqlite3-stmt)
128 (column-number :int))
130 (defcfun sqlite3-column-text :string
131 (statement p-sqlite3-stmt)
132 (column-number :int))
134 (defcfun sqlite3-column-int64 :int64
135 (statement p-sqlite3-stmt)
136 (column-number :int))
138 (defcfun sqlite3-column-double :double
139 (statement p-sqlite3-stmt)
140 (column-number :int))
142 (defcfun sqlite3-column-bytes :int
143 (statement p-sqlite3-stmt)
144 (column-number :int))
146 (defcfun sqlite3-column-blob :pointer
147 (statement p-sqlite3-stmt)
148 (column-number :int))
150 (defcfun sqlite3-column-name :string
151 (statement p-sqlite3-stmt)
152 (column-number :int))
154 (defcfun sqlite3-bind-parameter-count :int
155 (statement p-sqlite3-stmt))
157 (defcfun sqlite3-bind-parameter-name :string
158 (statement p-sqlite3-stmt)
159 (column-number :int))
161 (defcfun sqlite3-bind-parameter-index :int
162 (statement p-sqlite3-stmt)
163 (name :string))
165 (defcfun sqlite3-bind-double error-code
166 (statement p-sqlite3-stmt)
167 (parameter-index :int)
168 (value :double))
170 (defcfun sqlite3-bind-int64 error-code
171 (statement p-sqlite3-stmt)
172 (parameter-index :int)
173 (value :int64))
175 (defcfun sqlite3-bind-null error-code
176 (statement p-sqlite3-stmt)
177 (parameter-index :int))
179 (defcfun sqlite3-bind-text error-code
180 (statement p-sqlite3-stmt)
181 (parameter-index :int)
182 (value :string)
183 (octets-count :int)
184 (destructor :pointer))
186 (defcfun sqlite3-bind-blob error-code
187 (statement p-sqlite3-stmt)
188 (parameter-index :int)
189 (value :pointer)
190 (bytes-count :int)
191 (destructor :pointer))
193 (defconstant destructor-transient-address (mod -1 (expt 2 (* 8 (cffi:foreign-type-size :pointer)))))
195 (defun destructor-transient () (cffi:make-pointer destructor-transient-address))
197 (defun destructor-static () (cffi:make-pointer 0))
199 (defcfun sqlite3-last-insert-rowid :int64
200 (db p-sqlite3))