implement sqlite logging, disable broken ffi.gc
This commit is contained in:
parent
64312e57fa
commit
5914e83437
|
@ -5,6 +5,8 @@ return {
|
|||
SQLITE_TRANSIENT = ffi.cast('void(*)(void*)', -1);
|
||||
SQLITE_STATIC = ffi.cast('void(*)(void*)', 0);
|
||||
|
||||
log_callback_type = 'void(*)(void*,int,const char*)';
|
||||
|
||||
-- error codes
|
||||
SQLITE_EMPTY = 16;
|
||||
SQLITE_CANTOPEN = 14;
|
||||
|
|
|
@ -4,16 +4,18 @@
|
|||
(local sqlffi (require :diet-sqlite.sqlite3_ffi))
|
||||
(local ffi (require :diet-sqlite.ffi))
|
||||
(local util (require :lib.util))
|
||||
(local {: SQLITE_OK : SQLITE_INTEGER : SQLITE_FLOAT : SQLITE_NULL : SQLITE_BLOB : SQLITE_TEXT : SQLITE_TRANSIENT} (require :diet-sqlite.codes))
|
||||
(local {: SQLITE_OK : SQLITE_INTEGER : SQLITE_FLOAT : SQLITE_NULL : SQLITE_BLOB : SQLITE_TEXT : SQLITE_TRANSIENT
|
||||
: SQLITE_CONFIG_LOG : log_callback_type} (require :diet-sqlite.codes))
|
||||
|
||||
(local sql {:step sqlffi.sqlite3_step
|
||||
:reset sqlffi.sqlite3_reset})
|
||||
:reset sqlffi.sqlite3_reset
|
||||
:shutdown sqlffi.sqlite3_shutdown})
|
||||
|
||||
(fn sql.open [dbname]
|
||||
(let [lpdb (ffi.new "sqlite3*[1]")
|
||||
rc (sqlffi.sqlite3_open dbname lpdb)
|
||||
db (. lpdb 0)]
|
||||
(when (not= db nil) (ffi.gc db sqlffi.sqlite3_close_v2))
|
||||
; (when (not= db nil) (ffi.gc db sqlffi.sqlite3_close_v2))
|
||||
(values rc (. lpdb 0))))
|
||||
|
||||
(fn sql.close [db]
|
||||
|
@ -58,4 +60,8 @@
|
|||
(if (= rc-expect rc) ... (error (.. "Expected " rc-expect ", got " rc))))
|
||||
(fn sql.assert [...] (sql.assert-rc SQLITE_OK ...))
|
||||
|
||||
(fn sql.register-logger [logfn]
|
||||
(let [callback (ffi.cast log_callback_type (fn [pArg iErrCode zMsg] (logfn (ffi.string zMsg) iErrCode)))]
|
||||
(sql.assert (sqlffi.sqlite3_config SQLITE_CONFIG_LOG callback (ffi.cast "void *" nil)))))
|
||||
|
||||
sql
|
||||
|
|
|
@ -862,8 +862,5 @@ struct sqlite3_rtree_geometry {
|
|||
|
||||
local Lib = ffi.load(ffi.os == "Windows" and "bin/sqlite3" or "sqlite3")
|
||||
|
||||
-- initialize the library
|
||||
Lib.sqlite3_initialize();
|
||||
|
||||
return Lib;
|
||||
|
||||
|
|
Loading…
Reference in a new issue