-
Notifications
You must be signed in to change notification settings - Fork 9
Home
The constant SQLITE_ can be accessed as lsqlite3.<VAL>
(remove the SQLITE_ prefix)
Most functions throw errors on non-SQLITE_OK return codes unless otherwise specified.
Basic functions:
-
local db, msg, code = lsqlite3.open(filename[, mode])
: Opens a database and returns a handle object.mode
is optional and can be either "read" for read-only, "write" for read-write, or "create" (the default) for read-write+create if the db doesn't exist. If opening fails, returns nil, an error message, and error code. -
db:close()
: Closes the database. -
db:exec(sql)
: Executes a string of SQL, ignoring the results. -
local stmt = db:prepare(sql)
: Prepares a statement and returns the object. -
stmt:bind(index, value)
: Binds a value to a statement. Valid types are number (double), boolean (int true=1, false=0), nil (null), and 64-bit integers from FFI. -
stmt:bind_blob(index, value[, len])
: Binds a blob to a statement. Valid types are Lua strings (in which case the len field may be omitted), cdata objects, or nil (which stores a zero blob). -
local has_row = stmt:step()
: Steps the statement. Returns true if the statement has a row available or false if the statement is completed. Ex.while stmt:step() do ... end
-
local val = stmt:get_value(col)
: Returns a value in a column. 64bit-integers are truncated into Lua doubles, and blob values are returned as-is, with no copying done. Strings are converted into Lua strings. -
stmt:finalize()
: Finalizes a statement -
stmt:reset()
: Resets a statement
Blob IO and other functions are also implemented; see the code.
If you set lsqlite3.DEBUG = true
, then a traceback will be taken when a statement is prepared or blob is opened. This information can be printed via db:dump_unfinalized_statements
and db:dump_unclosed_blobs