Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lsqlite3.c File Reference
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "civetweb_lua.h"
#include "sqlite3.h"

Go to the source code of this file.

Data Structures

struct  sdb_func
 
struct  sdb
 
struct  sdb_vm
 
struct  lcontext
 
struct  scc
 
struct  sdb_bu
 

Macros

#define SQLITE_OMIT_PROGRESS_CALLBACK   0
 
#define LSQLITE_OMIT_UPDATE_HOOK   0
 
#define SQLITE3_OPEN(L, filename, flags)   sqlite3_open_v2(L,filename,flags,NULL)
 
#define PUSH_INT64(L, i64in, fallback)
 
#define LSQLITE_VERSION   "unknown"
 
#define SC(s)   { #s, SQLITE_ ## s },
 
#define LSC(s)   { #s, LSQLITE_ ## s },
 

Typedefs

typedef struct sdb sdb
 
typedef struct sdb_vm sdb_vm
 
typedef struct sdb_bu sdb_bu
 
typedef struct sdb_func sdb_func
 

Functions

static void vm_push_column (lua_State *L, sqlite3_stmt *vm, int idx)
 
static sdb_vmnewvm (lua_State *L, sdb *db)
 
static int cleanupvm (lua_State *L, sdb_vm *svm)
 
static int stepvm (lua_State *L, sdb_vm *svm)
 
static sdb_vmlsqlite_getvm (lua_State *L, int index)
 
static sdb_vmlsqlite_checkvm (lua_State *L, int index)
 
static int dbvm_isopen (lua_State *L)
 
static int dbvm_tostring (lua_State *L)
 
static int dbvm_gc (lua_State *L)
 
static int dbvm_step (lua_State *L)
 
static int dbvm_finalize (lua_State *L)
 
static int dbvm_reset (lua_State *L)
 
static void dbvm_check_contents (lua_State *L, sdb_vm *svm)
 
static void dbvm_check_index (lua_State *L, sdb_vm *svm, int index)
 
static void dbvm_check_bind_index (lua_State *L, sdb_vm *svm, int index)
 
static int dbvm_last_insert_rowid (lua_State *L)
 
static int dbvm_columns (lua_State *L)
 
static int dbvm_get_value (lua_State *L)
 
static int dbvm_get_name (lua_State *L)
 
static int dbvm_get_type (lua_State *L)
 
static int dbvm_get_values (lua_State *L)
 
static int dbvm_get_names (lua_State *L)
 
static int dbvm_get_types (lua_State *L)
 
static int dbvm_get_uvalues (lua_State *L)
 
static int dbvm_get_unames (lua_State *L)
 
static int dbvm_get_utypes (lua_State *L)
 
static int dbvm_get_named_values (lua_State *L)
 
static int dbvm_get_named_types (lua_State *L)
 
static int dbvm_bind_index (lua_State *L, sqlite3_stmt *vm, int index, int lindex)
 
static int dbvm_bind_parameter_count (lua_State *L)
 
static int dbvm_bind_parameter_name (lua_State *L)
 
static int dbvm_bind (lua_State *L)
 
static int dbvm_bind_blob (lua_State *L)
 
static int dbvm_bind_values (lua_State *L)
 
static int dbvm_bind_names (lua_State *L)
 
static sdbnewdb (lua_State *L)
 
static int cleanupdb (lua_State *L, sdb *db)
 
static sdblsqlite_getdb (lua_State *L, int index)
 
static sdblsqlite_checkdb (lua_State *L, int index)
 
static lcontextlsqlite_make_context (lua_State *L)
 
static lcontextlsqlite_getcontext (lua_State *L, int index)
 
static lcontextlsqlite_checkcontext (lua_State *L, int index)
 
static int lcontext_tostring (lua_State *L)
 
static void lcontext_check_aggregate (lua_State *L, lcontext *ctx)
 
static int lcontext_user_data (lua_State *L)
 
static int lcontext_get_aggregate_context (lua_State *L)
 
static int lcontext_set_aggregate_context (lua_State *L)
 
static int lcontext_aggregate_count (lua_State *L)
 
static int lcontext_result (lua_State *L)
 
static int lcontext_result_blob (lua_State *L)
 
static int lcontext_result_double (lua_State *L)
 
static int lcontext_result_error (lua_State *L)
 
static int lcontext_result_int (lua_State *L)
 
static int lcontext_result_null (lua_State *L)
 
static int lcontext_result_text (lua_State *L)
 
static int db_isopen (lua_State *L)
 
static int db_last_insert_rowid (lua_State *L)
 
static int db_changes (lua_State *L)
 
static int db_total_changes (lua_State *L)
 
static int db_errcode (lua_State *L)
 
static int db_errmsg (lua_State *L)
 
static int db_interrupt (lua_State *L)
 
static int db_db_filename (lua_State *L)
 
static void db_push_value (lua_State *L, sqlite3_value *value)
 
static void db_sql_normal_function (sqlite3_context *context, int argc, sqlite3_value **argv)
 
static void db_sql_finalize_function (sqlite3_context *context)
 
static int db_register_function (lua_State *L, int aggregate)
 
static int db_create_function (lua_State *L)
 
static int db_create_aggregate (lua_State *L)
 
static int collwrapper (scc *co, int l1, const void *p1, int l2, const void *p2)
 
static void collfree (scc *co)
 
static int db_create_collation (lua_State *L)
 
static int db_load_extension (lua_State *L)
 
static void db_trace_callback (void *user, const char *sql)
 
static int db_trace (lua_State *L)
 
static void db_update_hook_callback (void *user, int op, char const *dbname, char const *tblname, sqlite3_int64 rowid)
 
static int db_update_hook (lua_State *L)
 
static int db_commit_hook_callback (void *user)
 
static int db_commit_hook (lua_State *L)
 
static void db_rollback_hook_callback (void *user)
 
static int db_rollback_hook (lua_State *L)
 
static int db_progress_callback (void *user)
 
static int db_progress_handler (lua_State *L)
 
static int cleanupbu (lua_State *L, sdb_bu *sbu)
 
static int lsqlite_backup_init (lua_State *L)
 
static sdb_bulsqlite_getbu (lua_State *L, int index)
 
static sdb_bulsqlite_checkbu (lua_State *L, int index)
 
static int dbbu_gc (lua_State *L)
 
static int dbbu_step (lua_State *L)
 
static int dbbu_remaining (lua_State *L)
 
static int dbbu_pagecount (lua_State *L)
 
static int dbbu_finish (lua_State *L)
 
static int db_busy_callback (void *user, int tries)
 
static int db_busy_handler (lua_State *L)
 
static int db_busy_timeout (lua_State *L)
 
static int db_exec_callback (void *user, int columns, char **data, char **names)
 
static int db_exec (lua_State *L)
 
static int db_prepare (lua_State *L)
 
static int db_do_next_row (lua_State *L, int packed)
 
static int db_next_row (lua_State *L)
 
static int db_next_packed_row (lua_State *L)
 
static int db_next_named_row (lua_State *L)
 
static int dbvm_do_rows (lua_State *L, int(*f)(lua_State *))
 
static int dbvm_rows (lua_State *L)
 
static int dbvm_nrows (lua_State *L)
 
static int dbvm_urows (lua_State *L)
 
static int db_do_rows (lua_State *L, int(*f)(lua_State *))
 
static int db_rows (lua_State *L)
 
static int db_nrows (lua_State *L)
 
static int db_urows (lua_State *L)
 
static int db_tostring (lua_State *L)
 
static int db_close (lua_State *L)
 
static int db_close_vm (lua_State *L)
 
static int db_get_ptr (lua_State *L)
 
static int db_gc (lua_State *L)
 
static int lsqlite_version (lua_State *L)
 
static int lsqlite_complete (lua_State *L)
 
static int lsqlite_temp_directory (lua_State *L)
 
static int lsqlite_do_open (lua_State *L, const char *filename, int flags)
 
static int lsqlite_open (lua_State *L)
 
static int lsqlite_open_memory (lua_State *L)
 
static int lsqlite_open_ptr (lua_State *L)
 
static int lsqlite_newindex (lua_State *L)
 
static int lsqlite_lversion (lua_State *L)
 
static void create_meta (lua_State *L, const char *name, const luaL_Reg *lib)
 
static int luaopen_sqlitelib (lua_State *L)
 
LUALIB_API int luaopen_lsqlite3 (lua_State *L)
 

Variables

static const char * sqlite_meta = ":sqlite3"
 
static const char * sqlite_vm_meta = ":sqlite3:vm"
 
static const char * sqlite_bu_meta = ":sqlite3:bu"
 
static const char * sqlite_ctx_meta = ":sqlite3:ctx"
 
static int sqlite_ctx_meta_ref
 
struct { 
 
   const char *   name 
 
   int   value 
 
sqlite_constants [] 
 
static const luaL_Reg dblib []
 
static const luaL_Reg vmlib []
 
static const luaL_Reg ctxlib []
 
static const luaL_Reg dbbulib []
 
static const luaL_Reg sqlitelib []
 

Macro Definition Documentation

◆ LSC

#define LSC ( s)    { #s, LSQLITE_ ## s },

Definition at line 2151 of file lsqlite3.c.

◆ LSQLITE_OMIT_UPDATE_HOOK

#define LSQLITE_OMIT_UPDATE_HOOK   0

Definition at line 64 of file lsqlite3.c.

◆ LSQLITE_VERSION

#define LSQLITE_VERSION   "unknown"

Definition at line 2134 of file lsqlite3.c.

Referenced by lsqlite_lversion().

◆ PUSH_INT64

#define PUSH_INT64 ( L,
i64in,
fallback )
Value:
do { \
sqlite_int64 i64 = i64in; \
if (n == i64) lua_pushnumber(L, n); \
else fallback; \
} while (0)
LUA_API void lua_pushnumber(lua_State *L, lua_Number n)
LUA_NUMBER lua_Number
sqlite_int64 i64
Definition sqlite3.c:14329
long long int sqlite_int64
Definition sqlite3.c:1326

Definition at line 147 of file lsqlite3.c.

147#define PUSH_INT64(L,i64in,fallback) \
148 do { \
149 sqlite_int64 i64 = i64in; \
150 lua_Number n = (lua_Number)i64; \
151 if (n == i64) lua_pushnumber(L, n); \
152 else fallback; \
153 } while (0)

Referenced by db_last_insert_rowid(), db_push_value(), db_update_hook_callback(), dbvm_last_insert_rowid(), and vm_push_column().

◆ SC

#define SC ( s)    { #s, SQLITE_ ## s },

Definition at line 2150 of file lsqlite3.c.

◆ SQLITE3_OPEN

#define SQLITE3_OPEN ( L,
filename,
flags )   sqlite3_open_v2(L,filename,flags,NULL)

Definition at line 69 of file lsqlite3.c.

Referenced by lsqlite_do_open().

◆ SQLITE_OMIT_PROGRESS_CALLBACK

#define SQLITE_OMIT_PROGRESS_CALLBACK   0

Definition at line 61 of file lsqlite3.c.

Typedef Documentation

◆ sdb

typedef struct sdb sdb

Definition at line 72 of file lsqlite3.c.

◆ sdb_bu

typedef struct sdb_bu sdb_bu

Definition at line 74 of file lsqlite3.c.

◆ sdb_func

typedef struct sdb_func sdb_func

Definition at line 75 of file lsqlite3.c.

◆ sdb_vm

typedef struct sdb_vm sdb_vm

Definition at line 73 of file lsqlite3.c.

Function Documentation

◆ cleanupbu()

static int cleanupbu ( lua_State * L,
sdb_bu * sbu )
static

Definition at line 1572 of file lsqlite3.c.

1572 {
1573
1574 if (!sbu->bu) return 0; /* already finished */
1575
1576 /* remove table from registry */
1577 lua_pushlightuserdata(L, sbu->bu);
1578 lua_pushnil(L);
1580
1582 sbu->bu = NULL;
1583
1584 return 1;
1585}
#define NULL
Definition gmacros.h:924
LUA_API void lua_pushnil(lua_State *L)
LUA_API void lua_pushlightuserdata(lua_State *L, void *p)
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
LUA_API void lua_rawset(lua_State *L, int idx)
#define LUA_REGISTRYINDEX
SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p)
Definition sqlite3.c:75625
sqlite3_backup * bu
Definition lsqlite3.c:1569

References sdb_bu::bu, lua_pushinteger(), lua_pushlightuserdata(), lua_pushnil(), lua_rawset(), LUA_REGISTRYINDEX, NULL, and sqlite3_backup_finish().

Referenced by dbbu_finish(), and dbbu_gc().

◆ cleanupdb()

static int cleanupdb ( lua_State * L,
sdb * db )
static

Definition at line 654 of file lsqlite3.c.

654 {
655 sdb_func *func;
656 sdb_func *func_next;
657 int top;
658 int result;
659
660 /* free associated virtual machines */
663
664 /* close all used handles */
665 top = lua_gettop(L);
666 lua_pushnil(L);
667 while (lua_next(L, -2)) {
668 sdb_vm *svm = lua_touserdata(L, -2); /* key: vm; val: sql text */
669 cleanupvm(L, svm);
670
671 lua_settop(L, top);
672 lua_pushnil(L);
673 }
674
675 lua_pop(L, 1); /* pop vm table */
676
677 /* remove entry in lua registry table */
679 lua_pushnil(L);
681
682 /* 'free' all references */
689#if !defined(LSQLITE_OMIT_UPDATE_HOOK) || !LSQLITE_OMIT_UPDATE_HOOK
696#endif
697
698 /* close database */
699 result = sqlite3_close(db->db);
700 db->db = NULL;
701
702 /* free associated memory with created functions */
703 func = db->func;
704 while (func) {
705 func_next = func->next;
709 free(func);
710 func = func_next;
711 }
712 db->func = NULL;
713 return result;
714}
#define free
Definition civetweb.c:1542
static int cleanupvm(lua_State *L, sdb_vm *svm)
Definition lsqlite3.c:223
LUA_API void lua_rawget(lua_State *L, int idx)
LUA_API int lua_next(lua_State *L, int idx)
LUA_API void * lua_touserdata(lua_State *L, int idx)
LUA_API void lua_settop(lua_State *L, int idx)
LUA_API int lua_gettop(lua_State *L)
LUALIB_API void luaL_unref(lua_State *L, int t, int ref)
#define lua_pop(L, n)
SQLITE_API int sqlite3_close(sqlite3 *)
Definition sqlite3.c:162246
sdb_func * next
Definition lsqlite3.c:87
int fn_step
Definition lsqlite3.c:80
int udata
Definition lsqlite3.c:82
int fn_finalize
Definition lsqlite3.c:81
int update_hook_cb
Definition lsqlite3.c:112
sqlite3 * db
Definition lsqlite3.c:95
int rollback_hook_cb
Definition lsqlite3.c:118
int update_hook_udata
Definition lsqlite3.c:113
int commit_hook_cb
Definition lsqlite3.c:115
int trace_cb
Definition lsqlite3.c:107
int commit_hook_udata
Definition lsqlite3.c:116
int trace_udata
Definition lsqlite3.c:108
int progress_udata
Definition lsqlite3.c:105
int busy_udata
Definition lsqlite3.c:102
int busy_cb
Definition lsqlite3.c:101
sdb_func * func
Definition lsqlite3.c:98
int rollback_hook_udata
Definition lsqlite3.c:119
int progress_cb
Definition lsqlite3.c:104

References sdb::busy_cb, sdb::busy_udata, cleanupvm(), sdb::commit_hook_cb, sdb::commit_hook_udata, sdb::db, sdb_func::fn_finalize, sdb_func::fn_step, free, sdb::func, lua_gettop(), lua_next(), lua_pop, lua_pushlightuserdata(), lua_pushnil(), lua_rawget(), lua_rawset(), LUA_REGISTRYINDEX, lua_settop(), lua_touserdata(), luaL_unref(), sdb_func::next, NULL, sdb::progress_cb, sdb::progress_udata, sdb::rollback_hook_cb, sdb::rollback_hook_udata, sqlite3_close(), sdb::trace_cb, sdb::trace_udata, sdb_func::udata, sdb::update_hook_cb, and sdb::update_hook_udata.

Referenced by db_close(), db_gc(), and lsqlite_do_open().

◆ cleanupvm()

static int cleanupvm ( lua_State * L,
sdb_vm * svm )
static

Definition at line 223 of file lsqlite3.c.

223 {
224
225 /* remove entry in database table - no harm if not present in the table */
226 lua_pushlightuserdata(L, svm->db);
228 lua_pushlightuserdata(L, svm);
229 lua_pushnil(L);
230 lua_rawset(L, -3);
231 lua_pop(L, 1);
232
233 svm->columns = 0;
234 svm->has_values = 0;
235
236 if (!svm->vm) return 0;
237
239 svm->vm = NULL;
240 return 1;
241}
SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt)
Definition sqlite3.c:83080
sqlite3_stmt * vm
Definition lsqlite3.c:190
int columns
Definition lsqlite3.c:193
char has_values
Definition lsqlite3.c:194
sdb * db
Definition lsqlite3.c:189

References sdb_vm::columns, sdb_vm::db, sdb_vm::has_values, lua_pop, lua_pushinteger(), lua_pushlightuserdata(), lua_pushnil(), lua_rawget(), lua_rawset(), LUA_REGISTRYINDEX, NULL, sqlite3_finalize(), and sdb_vm::vm.

Referenced by cleanupdb(), db_do_next_row(), db_do_rows(), db_prepare(), dbvm_finalize(), and dbvm_gc().

◆ collfree()

static void collfree ( scc * co)
static

Definition at line 1187 of file lsqlite3.c.

1187 {
1188 if (co) {
1190 free(co);
1191 }
1192}
int ref
Definition lsqlite3.c:1172
lua_State * L
Definition lsqlite3.c:1171

References free, scc::L, LUA_REGISTRYINDEX, luaL_unref(), and scc::ref.

Referenced by db_create_collation().

◆ collwrapper()

static int collwrapper ( scc * co,
int l1,
const void * p1,
int l2,
const void * p2 )
static

Definition at line 1175 of file lsqlite3.c.

1176 {
1177 int res=0;
1178 lua_State *L=co->L;
1180 lua_pushlstring(L,p1,l1);
1181 lua_pushlstring(L,p2,l2);
1182 if (lua_pcall(L,2,1,0)==0) res=(int)lua_tonumber(L,-1);
1183 lua_pop(L,1);
1184 return res;
1185}
LUA_API void lua_pushlstring(lua_State *L, const char *s, size_t len)
LUA_API void lua_rawgeti(lua_State *L, int idx, int n)
#define lua_tonumber(L, i)
#define lua_pcall(L, n, r, f)

References scc::L, lua_pcall, lua_pop, lua_pushlstring(), lua_rawgeti(), LUA_REGISTRYINDEX, lua_tonumber, and scc::ref.

Referenced by db_create_collation().

◆ create_meta()

static void create_meta ( lua_State * L,
const char * name,
const luaL_Reg * lib )
static

Definition at line 2365 of file lsqlite3.c.

2365 {
2367 lua_pushstring(L, "__index");
2368 lua_pushvalue(L, -2); /* push metatable */
2369 lua_rawset(L, -3); /* metatable.__index = metatable */
2370
2371 /* register metatable functions */
2372 luaL_openlib(L, NULL, lib, 0);
2373
2374 /* remove metatable from stack */
2375 lua_pop(L, 1);
2376}
const char * name
Definition lsqlite3.c:2154
LUA_API void lua_pushstring(lua_State *L, const char *s)
LUA_API void lua_pushvalue(lua_State *L, int idx)
LUALIB_API int luaL_newmetatable(lua_State *L, const char *tname)

References lua_pop, lua_pushstring(), lua_pushvalue(), lua_rawset(), luaL_newmetatable(), name, and NULL.

Referenced by luaopen_lsqlite3().

◆ db_busy_callback()

static int db_busy_callback ( void * user,
int tries )
static

Definition at line 1678 of file lsqlite3.c.

1678 {
1679 int retry = 0; /* abort by default */
1680 sdb *db = (sdb*)user;
1681 lua_State *L = db->L;
1682 int top = lua_gettop(L);
1683
1686 lua_pushinteger(L, tries);
1687
1688 /* call lua function */
1689 if (!lua_pcall(L, 2, 1, 0))
1690 retry = lua_toboolean(L, -1);
1691
1692 lua_settop(L, top);
1693 return retry;
1694}
LUA_API int lua_toboolean(lua_State *L, int idx)
Definition lsqlite3.c:91
lua_State * L
Definition lsqlite3.c:93

References sdb::busy_cb, sdb::busy_udata, sdb::L, lua_gettop(), lua_pcall, lua_pushinteger(), lua_rawgeti(), LUA_REGISTRYINDEX, lua_settop(), and lua_toboolean().

Referenced by db_busy_handler().

◆ db_busy_handler()

static int db_busy_handler ( lua_State * L)
static

Definition at line 1696 of file lsqlite3.c.

1696 {
1697 sdb *db = lsqlite_checkdb(L, 1);
1698
1699 if (lua_gettop(L) < 2 || lua_isnil(L, 2)) {
1702
1703 db->busy_cb =
1704 db->busy_udata = LUA_NOREF;
1705
1706 /* clear busy handler */
1708 }
1709 else {
1711 /* make sure we have an userdata field (even if nil) */
1712 lua_settop(L, 3);
1713
1716
1719
1720 /* set busy handler */
1722 }
1723
1724 return 0;
1725}
static int db_busy_callback(void *user, int tries)
Definition lsqlite3.c:1678
static sdb * lsqlite_checkdb(lua_State *L, int index)
Definition lsqlite3.c:722
LUALIB_API int luaL_ref(lua_State *L, int t)
LUALIB_API void luaL_checktype(lua_State *L, int narg, int t)
#define LUA_NOREF
#define lua_isnil(L, n)
#define LUA_TFUNCTION
SQLITE_API int sqlite3_busy_handler(sqlite3 *, int(*)(void *, int), void *)
Definition sqlite3.c:162677

References sdb::busy_cb, sdb::busy_udata, sdb::db, db_busy_callback(), lsqlite_checkdb(), lua_gettop(), lua_isnil, LUA_NOREF, LUA_REGISTRYINDEX, lua_settop(), LUA_TFUNCTION, luaL_checktype(), luaL_ref(), luaL_unref(), NULL, and sqlite3_busy_handler().

◆ db_busy_timeout()

static int db_busy_timeout ( lua_State * L)
static

Definition at line 1727 of file lsqlite3.c.

1727 {
1728 sdb *db = lsqlite_checkdb(L, 1);
1729 int timeout = luaL_checkint(L, 2);
1730 sqlite3_busy_timeout(db->db, timeout);
1731
1732 /* if there was a timeout callback registered, it is now
1733 ** invalid/useless. free any references we may have */
1736 db->busy_cb =
1737 db->busy_udata = LUA_NOREF;
1738
1739 return 0;
1740}
#define luaL_checkint(L, n)
SQLITE_API int sqlite3_busy_timeout(sqlite3 *, int ms)
Definition sqlite3.c:162731

References sdb::busy_cb, sdb::busy_udata, sdb::db, lsqlite_checkdb(), LUA_NOREF, LUA_REGISTRYINDEX, luaL_checkint, luaL_unref(), and sqlite3_busy_timeout().

◆ db_changes()

static int db_changes ( lua_State * L)
static

Definition at line 903 of file lsqlite3.c.

903 {
904 sdb *db = lsqlite_checkdb(L, 1);
906 return 1;
907}
SQLITE_API int sqlite3_changes(sqlite3 *)
Definition sqlite3.c:162082

References sdb::db, lsqlite_checkdb(), lua_pushinteger(), and sqlite3_changes().

◆ db_close()

static int db_close ( lua_State * L)
static

Definition at line 1984 of file lsqlite3.c.

1984 {
1985 sdb *db = lsqlite_checkdb(L, 1);
1986 lua_pushinteger(L, cleanupdb(L, db));
1987 return 1;
1988}
static int cleanupdb(lua_State *L, sdb *db)
Definition lsqlite3.c:654

References cleanupdb(), lsqlite_checkdb(), and lua_pushinteger().

◆ db_close_vm()

static int db_close_vm ( lua_State * L)
static

Definition at line 1990 of file lsqlite3.c.

1990 {
1991 sdb *db = lsqlite_checkdb(L, 1);
1992 /* cleanup temporary only tables? */
1993 int temp = lua_toboolean(L, 2);
1994
1995 /* free associated virtual machines */
1996 lua_pushlightuserdata(L, db);
1998
1999 /* close all used handles */
2000 lua_pushnil(L);
2001 while (lua_next(L, -2)) {
2002 sdb_vm *svm = lua_touserdata(L, -2); /* key: vm; val: sql text */
2003
2004 if ((!temp || svm->temp) && svm->vm)
2005 {
2006 sqlite3_finalize(svm->vm);
2007 svm->vm = NULL;
2008 }
2009
2010 /* leave key in the stack */
2011 lua_pop(L, 1);
2012 }
2013 return 0;
2014}
char temp
Definition lsqlite3.c:196

References lsqlite_checkdb(), lua_next(), lua_pop, lua_pushlightuserdata(), lua_pushnil(), lua_rawget(), LUA_REGISTRYINDEX, lua_toboolean(), lua_touserdata(), NULL, sqlite3_finalize(), sdb_vm::temp, and sdb_vm::vm.

◆ db_commit_hook()

static int db_commit_hook ( lua_State * L)
static

Definition at line 1395 of file lsqlite3.c.

1395 {
1396 sdb *db = lsqlite_checkdb(L, 1);
1397
1398 if (lua_gettop(L) < 2 || lua_isnil(L, 2)) {
1401
1402 db->commit_hook_cb =
1404
1405 /* clear commit_hook handler */
1407 }
1408 else {
1410
1411 /* make sure we have an userdata field (even if nil) */
1412 lua_settop(L, 3);
1413
1416
1419
1420 /* set commit_hook handler */
1422 }
1423
1424 return 0;
1425}
static int db_commit_hook_callback(void *user)
Definition lsqlite3.c:1377
SQLITE_API void * sqlite3_commit_hook(sqlite3 *, int(*)(void *), void *)
Definition sqlite3.c:163156

References sdb::commit_hook_cb, sdb::commit_hook_udata, sdb::db, db_commit_hook_callback(), lsqlite_checkdb(), lua_gettop(), lua_isnil, LUA_NOREF, LUA_REGISTRYINDEX, lua_settop(), LUA_TFUNCTION, luaL_checktype(), luaL_ref(), luaL_unref(), NULL, and sqlite3_commit_hook().

◆ db_commit_hook_callback()

static int db_commit_hook_callback ( void * user)
static

Definition at line 1377 of file lsqlite3.c.

1377 {
1378 sdb *db = (sdb*)user;
1379 lua_State *L = db->L;
1380 int top = lua_gettop(L);
1381 int rollback = 0;
1382
1383 /* setup lua callback call */
1384 lua_rawgeti(L, LUA_REGISTRYINDEX, db->commit_hook_cb); /* get callback */
1385 lua_rawgeti(L, LUA_REGISTRYINDEX, db->commit_hook_udata); /* get callback user data */
1386
1387 /* call lua function */
1388 if (!lua_pcall(L, 1, 1, 0))
1389 rollback = lua_toboolean(L, -1); /* use result if there was no error */
1390
1391 lua_settop(L, top);
1392 return rollback;
1393}

References sdb::commit_hook_cb, sdb::commit_hook_udata, sdb::L, lua_gettop(), lua_pcall, lua_rawgeti(), LUA_REGISTRYINDEX, lua_settop(), and lua_toboolean().

Referenced by db_commit_hook().

◆ db_create_aggregate()

static int db_create_aggregate ( lua_State * L)
static

Definition at line 1163 of file lsqlite3.c.

1163 {
1164 return db_register_function(L, 1);
1165}
static int db_register_function(lua_State *L, int aggregate)
Definition lsqlite3.c:1098

References db_register_function().

◆ db_create_collation()

static int db_create_collation ( lua_State * L)
static

Definition at line 1194 of file lsqlite3.c.

1194 {
1195 sdb *db=lsqlite_checkdb(L,1);
1196 const char *collname=luaL_checkstring(L,2);
1197 scc *co=NULL;
1198 int (*collfunc)(scc *,int,const void *,int,const void *)=NULL;
1199 lua_settop(L,3); /* default args to nil, and exclude extras */
1200 if (lua_isfunction(L,3)) collfunc=collwrapper;
1201 else if (!lua_isnil(L,3))
1202 luaL_error(L,"create_collation: function or nil expected");
1203 if (collfunc != NULL) {
1204 co=(scc *)malloc(sizeof(scc)); /* userdata is a no-no as it
1205 will be garbage-collected */
1206 if (co) {
1207 co->L=L;
1208 /* lua_settop(L,3) above means we don't need: lua_pushvalue(L,3); */
1210 }
1211 else luaL_error(L,"create_collation: could not allocate callback");
1212 }
1214 (void *)co,
1215 (int(*)(void*,int,const void*,int,const void*))collfunc,
1216 (void(*)(void*))collfree);
1217 return 0;
1218}
#define malloc
Definition civetweb.c:1539
static void collfree(scc *co)
Definition lsqlite3.c:1187
static int collwrapper(scc *co, int l1, const void *p1, int l2, const void *p2)
Definition lsqlite3.c:1175
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
#define luaL_checkstring(L, n)
#define lua_isfunction(L, n)
#define SQLITE_UTF8
Definition sqlite3.c:6252
SQLITE_API int sqlite3_create_collation_v2(sqlite3 *, const char *zName, int eTextRep, void *pArg, int(*xCompare)(void *, int, const void *, int, const void *), void(*xDestroy)(void *))
Definition sqlite3.c:164452

References collfree(), collwrapper(), sdb::db, scc::L, lsqlite_checkdb(), lua_isfunction, lua_isnil, LUA_REGISTRYINDEX, lua_settop(), luaL_checkstring, luaL_error(), luaL_ref(), malloc, NULL, scc::ref, sqlite3_create_collation_v2(), and SQLITE_UTF8.

◆ db_create_function()

static int db_create_function ( lua_State * L)
static

Definition at line 1159 of file lsqlite3.c.

1159 {
1160 return db_register_function(L, 0);
1161}

References db_register_function().

◆ db_db_filename()

static int db_db_filename ( lua_State * L)
static

Definition at line 933 of file lsqlite3.c.

933 {
934 sdb *db = lsqlite_checkdb(L, 1);
935 const char *db_name = luaL_checkstring(L, 2);
936 // sqlite3_db_filename may return NULL, in that case Lua pushes nil...
937 lua_pushstring(L, sqlite3_db_filename(db->db, db_name));
938 return 1;
939}
SQLITE_API const char * sqlite3_db_filename(sqlite3 *db, const char *zDbName)
Definition sqlite3.c:165384

References sdb::db, lsqlite_checkdb(), lua_pushstring(), luaL_checkstring, and sqlite3_db_filename().

◆ db_do_next_row()

static int db_do_next_row ( lua_State * L,
int packed )
static

Definition at line 1851 of file lsqlite3.c.

1851 {
1852 int result;
1853 sdb_vm *svm = lsqlite_checkvm(L, 1);
1854 sqlite3_stmt *vm;
1855 int columns;
1856 int i;
1857
1858 result = stepvm(L, svm);
1859 vm = svm->vm; /* stepvm may change svm->vm if re-prepare is needed */
1860 svm->has_values = result == SQLITE_ROW ? 1 : 0;
1861 svm->columns = columns = sqlite3_data_count(vm);
1862
1863 if (result == SQLITE_ROW) {
1864 if (packed) {
1865 if (packed == 1) {
1866 lua_createtable(L, columns, 0);
1867 for (i = 0; i < columns;) {
1868 vm_push_column(L, vm, i);
1869 lua_rawseti(L, -2, ++i);
1870 }
1871 }
1872 else {
1873 lua_createtable(L, 0, columns);
1874 for (i = 0; i < columns; ++i) {
1876 vm_push_column(L, vm, i);
1877 lua_rawset(L, -3);
1878 }
1879 }
1880 return 1;
1881 }
1882 else {
1883 lua_checkstack(L, columns);
1884 for (i = 0; i < columns; ++i)
1885 vm_push_column(L, vm, i);
1886 return svm->columns;
1887 }
1888 }
1889
1890 if (svm->temp) {
1891 /* finalize and check for errors */
1892 result = sqlite3_finalize(vm);
1893 svm->vm = NULL;
1894 cleanupvm(L, svm);
1895 }
1896 else if (result == SQLITE_DONE) {
1897 result = sqlite3_reset(vm);
1898 }
1899
1900 if (result != SQLITE_OK) {
1902 lua_error(L);
1903 }
1904 return 0;
1905}
static void vm_push_column(lua_State *L, sqlite3_stmt *vm, int idx)
Definition lsqlite3.c:162
static int stepvm(lua_State *L, sdb_vm *svm)
Definition lsqlite3.c:243
static sdb_vm * lsqlite_checkvm(lua_State *L, int index)
Definition lsqlite3.c:253
LUA_API int lua_error(lua_State *L)
LUA_API void lua_createtable(lua_State *L, int narray, int nrec)
LUA_API void lua_rawseti(lua_State *L, int idx, int n)
LUA_API int lua_checkstack(lua_State *L, int size)
#define SQLITE_ROW
Definition sqlite3.c:1499
#define SQLITE_OK
Definition sqlite3.c:1469
SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt)
Definition sqlite3.c:83107
SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt)
Definition sqlite3.c:83987
SQLITE_API const char * sqlite3_column_name(sqlite3_stmt *, int N)
Definition sqlite3.c:84218
SQLITE_API const char * sqlite3_errmsg(sqlite3 *)
Definition sqlite3.c:163483
struct sqlite3_stmt sqlite3_stmt
Definition sqlite3.c:4844
#define SQLITE_DONE
Definition sqlite3.c:1500

References cleanupvm(), sdb_vm::columns, sdb::db, sdb_vm::db, sdb_vm::has_values, lsqlite_checkvm(), lua_checkstack(), lua_createtable(), lua_error(), lua_pushstring(), lua_rawset(), lua_rawseti(), NULL, sqlite3_column_name(), sqlite3_data_count(), sqlite3_errmsg(), sqlite3_finalize(), sqlite3_reset(), SQLITE_DONE, SQLITE_OK, SQLITE_ROW, stepvm(), sdb_vm::temp, sdb_vm::vm, and vm_push_column().

Referenced by db_next_named_row(), db_next_packed_row(), and db_next_row().

◆ db_do_rows()

static int db_do_rows ( lua_State * L,
int(*)(lua_State *) f )
static

Definition at line 1940 of file lsqlite3.c.

1940 {
1941 sdb *db = lsqlite_checkdb(L, 1);
1942 const char *sql = luaL_checkstring(L, 2);
1943 sdb_vm *svm;
1944 lua_settop(L,2); /* db,sql is on top of stack for call to newvm */
1945 svm = newvm(L, db);
1946 svm->temp = 1;
1947
1948 if (sqlite3_prepare_v2(db->db, sql, -1, &svm->vm, NULL) != SQLITE_OK) {
1950 if (cleanupvm(L, svm) == 1)
1951 lua_pop(L, 1); /* this should not happen since sqlite3_prepare_v2 will not set ->vm on error */
1952 lua_error(L);
1953 }
1954
1955 lua_pushcfunction(L, f);
1956 lua_insert(L, -2);
1957 return 2;
1958}
static sdb_vm * newvm(lua_State *L, sdb *db)
Definition lsqlite3.c:200
#define lua_pushcfunction(L, f)
#define lua_insert(L, idx)
SQLITE_API int sqlite3_prepare_v2(sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt **ppStmt, const char **pzTail)
Definition sqlite3.c:129146

References cleanupvm(), sdb::db, sdb_vm::db, lsqlite_checkdb(), lua_error(), lua_insert, lua_pop, lua_pushcfunction, lua_pushstring(), lua_settop(), luaL_checkstring, newvm(), NULL, sqlite3_errmsg(), sqlite3_prepare_v2(), SQLITE_OK, sdb_vm::temp, and sdb_vm::vm.

Referenced by db_nrows(), db_rows(), and db_urows().

◆ db_errcode()

static int db_errcode ( lua_State * L)
static

Definition at line 915 of file lsqlite3.c.

915 {
916 sdb *db = lsqlite_checkdb(L, 1);
918 return 1;
919}
SQLITE_API int sqlite3_errcode(sqlite3 *db)
Definition sqlite3.c:163553

References sdb::db, lsqlite_checkdb(), lua_pushinteger(), and sqlite3_errcode().

◆ db_errmsg()

static int db_errmsg ( lua_State * L)
static

Definition at line 921 of file lsqlite3.c.

921 {
922 sdb *db = lsqlite_checkdb(L, 1);
924 return 1;
925}

References sdb::db, lsqlite_checkdb(), lua_pushstring(), and sqlite3_errmsg().

◆ db_exec()

static int db_exec ( lua_State * L)
static

Definition at line 1797 of file lsqlite3.c.

1797 {
1798 sdb *db = lsqlite_checkdb(L, 1);
1799 const char *sql = luaL_checkstring(L, 2);
1800 int result;
1801
1802 if (!lua_isnoneornil(L, 3)) {
1803 /* stack:
1804 ** 3: callback function
1805 ** 4: userdata
1806 ** 5: column names
1807 ** 6: reusable column values
1808 */
1810 lua_settop(L, 4); /* 'trap' userdata - nil extra parameters */
1811 lua_pushnil(L); /* column names not known at this point */
1812 lua_newtable(L); /* column values table */
1813
1814 result = sqlite3_exec(db->db, sql, db_exec_callback, L, NULL);
1815 }
1816 else {
1817 /* no callbacks */
1818 result = sqlite3_exec(db->db, sql, NULL, NULL, NULL);
1819 }
1820
1821 lua_pushinteger(L, result);
1822 return 1;
1823}
static int db_exec_callback(void *user, int columns, char **data, char **names)
Definition lsqlite3.c:1750
#define lua_newtable(L)
#define lua_isnoneornil(L, n)
SQLITE_API int sqlite3_exec(sqlite3 *, const char *sql, int(*callback)(void *, int, char **, char **), void *, char **errmsg)
Definition sqlite3.c:123455

References sdb::db, db_exec_callback(), lsqlite_checkdb(), lua_isnoneornil, lua_newtable, lua_pushinteger(), lua_pushnil(), lua_settop(), LUA_TFUNCTION, luaL_checkstring, luaL_checktype(), NULL, and sqlite3_exec().

◆ db_exec_callback()

static int db_exec_callback ( void * user,
int columns,
char ** data,
char ** names )
static

Definition at line 1750 of file lsqlite3.c.

1750 {
1751 int result = SQLITE_ABORT; /* abort by default */
1752 lua_State *L = (lua_State*)user;
1753 int n;
1754
1755 int top = lua_gettop(L);
1756
1757 lua_pushvalue(L, 3); /* function to call */
1758 lua_pushvalue(L, 4); /* user data */
1759 lua_pushinteger(L, columns); /* total number of rows in result */
1760
1761 /* column values */
1762 lua_pushvalue(L, 6);
1763 for (n = 0; n < columns;) {
1764 lua_pushstring(L, data[n++]);
1765 lua_rawseti(L, -2, n);
1766 }
1767
1768 /* columns names */
1769 lua_pushvalue(L, 5);
1770 if (lua_isnil(L, -1)) {
1771 lua_pop(L, 1);
1772 lua_createtable(L, columns, 0);
1773 lua_pushvalue(L, -1);
1774 lua_replace(L, 5);
1775 for (n = 0; n < columns;) {
1776 lua_pushstring(L, names[n++]);
1777 lua_rawseti(L, -2, n);
1778 }
1779 }
1780
1781 /* call lua function */
1782 if (!lua_pcall(L, 4, 1, 0)) {
1783
1784#if LUA_VERSION_NUM > 502
1785 if (lua_isinteger(L, -1))
1786 result = lua_tointeger(L, -1);
1787 else
1788#endif
1789 if (lua_isnumber(L, -1))
1790 result = (int)lua_tonumber(L, -1);
1791 }
1792
1793 lua_settop(L, top);
1794 return result;
1795}
LUA_API int lua_isnumber(lua_State *L, int idx)
#define lua_tointeger(L, i)
LUA_API int lua_isinteger(lua_State *L, int idx)
#define lua_replace(L, idx)
#define SQLITE_ABORT
Definition sqlite3.c:1474

References lua_createtable(), lua_gettop(), lua_isinteger(), lua_isnil, lua_isnumber(), lua_pcall, lua_pop, lua_pushinteger(), lua_pushstring(), lua_pushvalue(), lua_rawseti(), lua_replace, lua_settop(), lua_tointeger, lua_tonumber, and SQLITE_ABORT.

Referenced by db_exec().

◆ db_gc()

static int db_gc ( lua_State * L)
static

Definition at line 2027 of file lsqlite3.c.

2027 {
2028 sdb *db = lsqlite_getdb(L, 1);
2029 if (db->db != NULL) /* ignore closed databases */
2030 cleanupdb(L, db);
2031 return 0;
2032}
static sdb * lsqlite_getdb(lua_State *L, int index)
Definition lsqlite3.c:716

References cleanupdb(), sdb::db, lsqlite_getdb(), and NULL.

◆ db_get_ptr()

static int db_get_ptr ( lua_State * L)
static

Definition at line 2021 of file lsqlite3.c.

2021 {
2022 sdb *db = lsqlite_checkdb(L, 1);
2023 lua_pushlightuserdata(L, db->db);
2024 return 1;
2025}

References sdb::db, lsqlite_checkdb(), and lua_pushlightuserdata().

◆ db_interrupt()

static int db_interrupt ( lua_State * L)
static

Definition at line 927 of file lsqlite3.c.

927 {
928 sdb *db = lsqlite_checkdb(L, 1);
930 return 0;
931}
SQLITE_API void sqlite3_interrupt(sqlite3 *)
Definition sqlite3.c:162748

References sdb::db, lsqlite_checkdb(), and sqlite3_interrupt().

◆ db_isopen()

static int db_isopen ( lua_State * L)
static

Definition at line 889 of file lsqlite3.c.

889 {
890 sdb *db = lsqlite_getdb(L, 1);
891 lua_pushboolean(L, db->db != NULL ? 1 : 0);
892 return 1;
893}
LUA_API void lua_pushboolean(lua_State *L, int b)

References sdb::db, lsqlite_getdb(), lua_pushboolean(), and NULL.

◆ db_last_insert_rowid()

static int db_last_insert_rowid ( lua_State * L)
static

Definition at line 895 of file lsqlite3.c.

895 {
896 sdb *db = lsqlite_checkdb(L, 1);
897 /* conversion warning: int64 -> luaNumber */
899 PUSH_INT64(L, rowid, lua_pushfstring(L, "%ll", rowid));
900 return 1;
901}
#define PUSH_INT64(L, i64in, fallback)
Definition lsqlite3.c:147
LUA_API const char * lua_pushfstring(lua_State *L, const char *fmt,...)
SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3 *)
Definition sqlite3.c:162054

References sdb::db, lsqlite_checkdb(), lua_pushfstring(), PUSH_INT64, and sqlite3_last_insert_rowid().

◆ db_load_extension()

static int db_load_extension ( lua_State * L)
static

Definition at line 1222 of file lsqlite3.c.

1222 {
1223 sdb *db=lsqlite_checkdb(L,1);
1224 const char *extname=luaL_optstring(L,2,NULL);
1225 const char *entrypoint=luaL_optstring(L,3,NULL);
1226 int result;
1227 char *errmsg = NULL;
1228
1229 if (extname == NULL) {
1230 result = sqlite3_enable_load_extension(db->db,0); /* disable extension loading */
1231 }
1232 else {
1233 sqlite3_enable_load_extension(db->db,1); /* enable extension loading */
1234 result = sqlite3_load_extension(db->db,extname,entrypoint,&errmsg);
1235 }
1236
1237 if (result == SQLITE_OK) {
1238 lua_pushboolean(L,1);
1239 return 1;
1240 }
1241
1242 lua_pushboolean(L,0); /* so, assert(load_extension(...)) works */
1243 lua_pushstring(L,errmsg);
1244 sqlite3_free(errmsg);
1245 return 2;
1246}
#define luaL_optstring(L, n, d)
SQLITE_API void sqlite3_free(void *)
Definition sqlite3.c:27692
SQLITE_API int sqlite3_load_extension(sqlite3 *db, const char *zFile, const char *zProc, char **pzErrMsg)
Definition sqlite3.c:124876
SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff)
Definition sqlite3.c:124907

References sdb::db, lsqlite_checkdb(), lua_pushboolean(), lua_pushstring(), luaL_optstring, NULL, sqlite3_enable_load_extension(), sqlite3_free(), sqlite3_load_extension(), and SQLITE_OK.

◆ db_next_named_row()

static int db_next_named_row ( lua_State * L)
static

Definition at line 1915 of file lsqlite3.c.

1915 {
1916 return db_do_next_row(L, 2);
1917}
static int db_do_next_row(lua_State *L, int packed)
Definition lsqlite3.c:1851

References db_do_next_row().

Referenced by db_nrows(), and dbvm_nrows().

◆ db_next_packed_row()

static int db_next_packed_row ( lua_State * L)
static

Definition at line 1911 of file lsqlite3.c.

1911 {
1912 return db_do_next_row(L, 1);
1913}

References db_do_next_row().

Referenced by db_rows(), and dbvm_rows().

◆ db_next_row()

static int db_next_row ( lua_State * L)
static

Definition at line 1907 of file lsqlite3.c.

1907 {
1908 return db_do_next_row(L, 0);
1909}

References db_do_next_row().

Referenced by db_urows(), and dbvm_urows().

◆ db_nrows()

static int db_nrows ( lua_State * L)
static

Definition at line 1964 of file lsqlite3.c.

1964 {
1965 return db_do_rows(L, db_next_named_row);
1966}
static int db_next_named_row(lua_State *L)
Definition lsqlite3.c:1915
static int db_do_rows(lua_State *L, int(*f)(lua_State *))
Definition lsqlite3.c:1940

References db_do_rows(), and db_next_named_row().

◆ db_prepare()

static int db_prepare ( lua_State * L)
static

Definition at line 1829 of file lsqlite3.c.

1829 {
1830 sdb *db = lsqlite_checkdb(L, 1);
1831 const char *sql = luaL_checkstring(L, 2);
1832 int sql_len = lua_strlen(L, 2);
1833 const char *sqltail;
1834 sdb_vm *svm;
1835 lua_settop(L,2); /* db,sql is on top of stack for call to newvm */
1836 svm = newvm(L, db);
1837
1838 if (sqlite3_prepare_v2(db->db, sql, sql_len, &svm->vm, &sqltail) != SQLITE_OK) {
1839 lua_pushnil(L);
1841 if (cleanupvm(L, svm) == 1)
1842 lua_pop(L, 1); /* this should not happen since sqlite3_prepare_v2 will not set ->vm on error */
1843 return 2;
1844 }
1845
1846 /* vm already in the stack */
1847 lua_pushstring(L, sqltail);
1848 return 2;
1849}
#define lua_strlen(L, i)

References cleanupvm(), sdb::db, lsqlite_checkdb(), lua_pop, lua_pushinteger(), lua_pushnil(), lua_pushstring(), lua_settop(), lua_strlen, luaL_checkstring, newvm(), sqlite3_errcode(), sqlite3_prepare_v2(), SQLITE_OK, and sdb_vm::vm.

◆ db_progress_callback()

static int db_progress_callback ( void * user)
static

Definition at line 1494 of file lsqlite3.c.

1494 {
1495 int result = 1; /* abort by default */
1496 sdb *db = (sdb*)user;
1497 lua_State *L = db->L;
1498 int top = lua_gettop(L);
1499
1502
1503 /* call lua function */
1504 if (!lua_pcall(L, 1, 1, 0))
1505 result = lua_toboolean(L, -1);
1506
1507 lua_settop(L, top);
1508 return result;
1509}

References sdb::L, lua_gettop(), lua_pcall, lua_rawgeti(), LUA_REGISTRYINDEX, lua_settop(), lua_toboolean(), sdb::progress_cb, and sdb::progress_udata.

Referenced by db_progress_handler().

◆ db_progress_handler()

static int db_progress_handler ( lua_State * L)
static

Definition at line 1511 of file lsqlite3.c.

1511 {
1512 sdb *db = lsqlite_checkdb(L, 1);
1513
1514 if (lua_gettop(L) < 2 || lua_isnil(L, 2)) {
1517
1518 db->progress_cb =
1520
1521 /* clear busy handler */
1523 }
1524 else {
1525 int nop = luaL_checkint(L, 2); /* number of opcodes */
1527
1528 /* make sure we have an userdata field (even if nil) */
1529 lua_settop(L, 4);
1530
1533
1536
1537 /* set progress callback */
1539 }
1540
1541 return 0;
1542}
static int db_progress_callback(void *user)
Definition lsqlite3.c:1494
SQLITE_API void sqlite3_progress_handler(sqlite3 *, int, int(*)(void *), void *)
Definition sqlite3.c:162700

References sdb::db, db_progress_callback(), lsqlite_checkdb(), lua_gettop(), lua_isnil, LUA_NOREF, LUA_REGISTRYINDEX, lua_settop(), LUA_TFUNCTION, luaL_checkint, luaL_checktype(), luaL_ref(), luaL_unref(), NULL, sdb::progress_cb, sdb::progress_udata, and sqlite3_progress_handler().

◆ db_push_value()

static void db_push_value ( lua_State * L,
sqlite3_value * value )
static

Definition at line 945 of file lsqlite3.c.

945 {
946 switch (sqlite3_value_type(value)) {
947 case SQLITE_TEXT:
949 break;
950
951 case SQLITE_INTEGER:
953 , lua_pushlstring(L, (const char*)sqlite3_value_text(value)
955 break;
956
957 case SQLITE_FLOAT:
959 break;
960
961 case SQLITE_BLOB:
963 break;
964
965 case SQLITE_NULL:
966 lua_pushnil(L);
967 break;
968
969 default:
970 /* things done properly (SQLite + Lua SQLite)
971 ** this should never happen */
972 lua_pushnil(L);
973 break;
974 }
975}
int value
Definition lsqlite3.c:2155
#define SQLITE_FLOAT
Definition sqlite3.c:5792
#define SQLITE_BLOB
Definition sqlite3.c:5793
SQLITE_API double sqlite3_value_double(sqlite3_value *)
Definition sqlite3.c:83172
#define SQLITE_INTEGER
Definition sqlite3.c:5791
SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value *)
Definition sqlite3.c:83178
SQLITE_API int sqlite3_value_type(sqlite3_value *)
Definition sqlite3.c:83216
#define SQLITE_TEXT
Definition sqlite3.c:5798
SQLITE_API int sqlite3_value_bytes(sqlite3_value *)
Definition sqlite3.c:83166
SQLITE_API const unsigned char * sqlite3_value_text(sqlite3_value *)
Definition sqlite3.c:83198
SQLITE_API const void * sqlite3_value_blob(sqlite3_value *)
Definition sqlite3.c:83153
#define SQLITE_NULL
Definition sqlite3.c:5794

References lua_pushlstring(), lua_pushnil(), lua_pushnumber(), PUSH_INT64, sqlite3_value_blob(), sqlite3_value_bytes(), sqlite3_value_double(), sqlite3_value_int64(), sqlite3_value_text(), sqlite3_value_type(), SQLITE_BLOB, SQLITE_FLOAT, SQLITE_INTEGER, SQLITE_NULL, SQLITE_TEXT, and value.

Referenced by db_sql_normal_function().

◆ db_register_function()

static int db_register_function ( lua_State * L,
int aggregate )
static

Definition at line 1098 of file lsqlite3.c.

1098 {
1099 sdb *db = lsqlite_checkdb(L, 1);
1100 const char *name;
1101 int args;
1102 int result;
1103 sdb_func *func;
1104
1105 /* safety measure */
1106 if (aggregate) aggregate = 1;
1107
1108 name = luaL_checkstring(L, 2);
1109 args = luaL_checkint(L, 3);
1111 if (aggregate) luaL_checktype(L, 5, LUA_TFUNCTION);
1112
1113 /* maybe an alternative way to allocate memory should be used/avoided */
1114 func = (sdb_func*)malloc(sizeof(sdb_func));
1115 if (func == NULL) {
1116 luaL_error(L, "out of memory");
1117 }
1118
1119 result = sqlite3_create_function(
1120 db->db, name, args, SQLITE_UTF8, func,
1121 aggregate ? NULL : db_sql_normal_function,
1122 aggregate ? db_sql_normal_function : NULL,
1123 aggregate ? db_sql_finalize_function : NULL
1124 );
1125
1126 if (result == SQLITE_OK) {
1127 /* safety measures for userdata field to be present in the stack */
1128 lua_settop(L, 5 + aggregate);
1129
1130 /* save registered function in db function list */
1131 func->db = db;
1132 func->aggregate = aggregate;
1133 func->next = db->func;
1134 db->func = func;
1135
1136 /* save the setp/normal function callback */
1137 lua_pushvalue(L, 4);
1139 /* save user data */
1140 lua_pushvalue(L, 5+aggregate);
1141 func->udata = luaL_ref(L, LUA_REGISTRYINDEX);
1142
1143 if (aggregate) {
1144 lua_pushvalue(L, 5);
1146 }
1147 else
1148 func->fn_finalize = LUA_NOREF;
1149 }
1150 else {
1151 /* free allocated memory */
1152 free(func);
1153 }
1154
1155 lua_pushboolean(L, result == SQLITE_OK ? 1 : 0);
1156 return 1;
1157}
static void db_sql_normal_function(sqlite3_context *context, int argc, sqlite3_value **argv)
Definition lsqlite3.c:983
static void db_sql_finalize_function(sqlite3_context *context)
Definition lsqlite3.c:1042
SQLITE_API int sqlite3_create_function(sqlite3 *db, const char *zFunctionName, int nArg, int eTextRep, void *pApp, void(*xFunc)(sqlite3_context *, int, sqlite3_value **), void(*xStep)(sqlite3_context *, int, sqlite3_value **), void(*xFinal)(sqlite3_context *))
Definition sqlite3.c:162936
sdb * db
Definition lsqlite3.c:84
char aggregate
Definition lsqlite3.c:85

References sdb_func::aggregate, sdb_func::db, sdb::db, db_sql_finalize_function(), db_sql_normal_function(), sdb_func::fn_finalize, sdb_func::fn_step, free, sdb::func, lsqlite_checkdb(), LUA_NOREF, lua_pushboolean(), lua_pushvalue(), LUA_REGISTRYINDEX, lua_settop(), LUA_TFUNCTION, luaL_checkint, luaL_checkstring, luaL_checktype(), luaL_error(), luaL_ref(), malloc, name, sdb_func::next, NULL, sqlite3_create_function(), SQLITE_OK, SQLITE_UTF8, and sdb_func::udata.

Referenced by db_create_aggregate(), and db_create_function().

◆ db_rollback_hook()

static int db_rollback_hook ( lua_State * L)
static

Definition at line 1450 of file lsqlite3.c.

1450 {
1451 sdb *db = lsqlite_checkdb(L, 1);
1452
1453 if (lua_gettop(L) < 2 || lua_isnil(L, 2)) {
1456
1457 db->rollback_hook_cb =
1459
1460 /* clear rollback_hook handler */
1462 }
1463 else {
1465
1466 /* make sure we have an userdata field (even if nil) */
1467 lua_settop(L, 3);
1468
1471
1474
1475 /* set rollback_hook handler */
1477 }
1478
1479 return 0;
1480}
static void db_rollback_hook_callback(void *user)
Definition lsqlite3.c:1434
SQLITE_API void * sqlite3_rollback_hook(sqlite3 *, void(*)(void *), void *)
Definition sqlite3.c:163206

References sdb::db, db_rollback_hook_callback(), lsqlite_checkdb(), lua_gettop(), lua_isnil, LUA_NOREF, LUA_REGISTRYINDEX, lua_settop(), LUA_TFUNCTION, luaL_checktype(), luaL_ref(), luaL_unref(), NULL, sdb::rollback_hook_cb, sdb::rollback_hook_udata, and sqlite3_rollback_hook().

◆ db_rollback_hook_callback()

static void db_rollback_hook_callback ( void * user)
static

Definition at line 1434 of file lsqlite3.c.

1434 {
1435 sdb *db = (sdb*)user;
1436 lua_State *L = db->L;
1437 int top = lua_gettop(L);
1438
1439 /* setup lua callback call */
1440 lua_rawgeti(L, LUA_REGISTRYINDEX, db->rollback_hook_cb); /* get callback */
1441 lua_rawgeti(L, LUA_REGISTRYINDEX, db->rollback_hook_udata); /* get callback user data */
1442
1443 /* call lua function */
1444 lua_pcall(L, 1, 0, 0);
1445 /* ignore any error generated by this function */
1446
1447 lua_settop(L, top);
1448}

References sdb::L, lua_gettop(), lua_pcall, lua_rawgeti(), LUA_REGISTRYINDEX, lua_settop(), sdb::rollback_hook_cb, and sdb::rollback_hook_udata.

Referenced by db_rollback_hook().

◆ db_rows()

static int db_rows ( lua_State * L)
static

Definition at line 1960 of file lsqlite3.c.

1960 {
1961 return db_do_rows(L, db_next_packed_row);
1962}
static int db_next_packed_row(lua_State *L)
Definition lsqlite3.c:1911

References db_do_rows(), and db_next_packed_row().

◆ db_sql_finalize_function()

static void db_sql_finalize_function ( sqlite3_context * context)
static

Definition at line 1042 of file lsqlite3.c.

1042 {
1043 sdb_func *func = (sdb_func*)sqlite3_user_data(context);
1044 lua_State *L = func->db->L;
1045 void *p = sqlite3_aggregate_context(context, 1); /* minimal mem usage */
1046 lcontext *ctx;
1047 int top = lua_gettop(L);
1048
1049 lua_rawgeti(L, LUA_REGISTRYINDEX, func->fn_finalize); /* function to call */
1050
1051 /* i think it is OK to use assume that using a light user data
1052 ** as an entry on LUA REGISTRY table will be unique */
1054 lua_rawget(L, LUA_REGISTRYINDEX); /* context table */
1055
1056 if (lua_isnil(L, -1)) { /* not yet created? - shouldn't happen in finalize function */
1057 lua_pop(L, 1);
1058 ctx = lsqlite_make_context(L);
1060 lua_pushvalue(L, -2);
1062 }
1063 else
1064 ctx = lsqlite_getcontext(L, -1);
1065
1066 /* set context */
1067 ctx->ctx = context;
1068
1069 if (lua_pcall(L, 1, 0, 0)) {
1070 sqlite3_result_error(context, lua_tostring(L, -1), -1);
1071 }
1072
1073 /* invalidate context */
1074 ctx->ctx = NULL;
1075
1076 /* cleanup context */
1078 /* remove it from registry */
1080 lua_pushnil(L);
1082
1083 lua_settop(L, top);
1084}
static lcontext * lsqlite_make_context(lua_State *L)
Definition lsqlite3.c:739
static lcontext * lsqlite_getcontext(lua_State *L, int index)
Definition lsqlite3.c:748
#define lua_tostring(L, i)
SQLITE_API void sqlite3_result_error(sqlite3_context *, const char *, int)
Definition sqlite3.c:83407
SQLITE_API void * sqlite3_aggregate_context(sqlite3_context *, int nBytes)
Definition sqlite3.c:83867
SQLITE_API void * sqlite3_user_data(sqlite3_context *)
Definition sqlite3.c:83779
sqlite3_context * ctx
Definition lsqlite3.c:735

References lcontext::ctx, sdb_func::db, sdb_func::fn_finalize, sdb::L, lsqlite_getcontext(), lsqlite_make_context(), lua_gettop(), lua_isnil, lua_pcall, lua_pop, lua_pushlightuserdata(), lua_pushnil(), lua_pushvalue(), lua_rawget(), lua_rawgeti(), lua_rawset(), LUA_REGISTRYINDEX, lua_settop(), lua_tostring, luaL_unref(), NULL, sqlite3_aggregate_context(), sqlite3_result_error(), sqlite3_user_data(), and lcontext::ud.

Referenced by db_register_function().

◆ db_sql_normal_function()

static void db_sql_normal_function ( sqlite3_context * context,
int argc,
sqlite3_value ** argv )
static

Definition at line 983 of file lsqlite3.c.

983 {
984 sdb_func *func = (sdb_func*)sqlite3_user_data(context);
985 lua_State *L = func->db->L;
986 int n;
987 lcontext *ctx;
988
989 int top = lua_gettop(L);
990
991 /* ensure there is enough space in the stack */
992 lua_checkstack(L, argc + 3);
993
994 lua_rawgeti(L, LUA_REGISTRYINDEX, func->fn_step); /* function to call */
995
996 if (!func->aggregate) {
997 ctx = lsqlite_make_context(L); /* push context - used to set results */
998 }
999 else {
1000 /* reuse context userdata value */
1001 void *p = sqlite3_aggregate_context(context, 1);
1002 /* i think it is OK to use assume that using a light user data
1003 ** as an entry on LUA REGISTRY table will be unique */
1005 lua_rawget(L, LUA_REGISTRYINDEX); /* context table */
1006
1007 if (lua_isnil(L, -1)) { /* not yet created? */
1008 lua_pop(L, 1);
1009 ctx = lsqlite_make_context(L);
1011 lua_pushvalue(L, -2);
1013 }
1014 else
1015 ctx = lsqlite_getcontext(L, -1);
1016 }
1017
1018 /* push params */
1019 for (n = 0; n < argc; ++n) {
1020 db_push_value(L, argv[n]);
1021 }
1022
1023 /* set context */
1024 ctx->ctx = context;
1025
1026 if (lua_pcall(L, argc + 1, 0, 0)) {
1027 const char *errmsg = lua_tostring(L, -1);
1028 int size = lua_strlen(L, -1);
1029 sqlite3_result_error(context, errmsg, size);
1030 }
1031
1032 /* invalidate context */
1033 ctx->ctx = NULL;
1034
1035 if (!func->aggregate) {
1037 }
1038
1039 lua_settop(L, top);
1040}
static void db_push_value(lua_State *L, sqlite3_value *value)
Definition lsqlite3.c:945

References sdb_func::aggregate, lcontext::ctx, sdb_func::db, db_push_value(), sdb_func::fn_step, sdb::L, lsqlite_getcontext(), lsqlite_make_context(), lua_checkstack(), lua_gettop(), lua_isnil, lua_pcall, lua_pop, lua_pushlightuserdata(), lua_pushvalue(), lua_rawget(), lua_rawgeti(), lua_rawset(), LUA_REGISTRYINDEX, lua_settop(), lua_strlen, lua_tostring, luaL_unref(), NULL, sqlite3_aggregate_context(), sqlite3_result_error(), sqlite3_user_data(), and lcontext::ud.

Referenced by db_register_function().

◆ db_tostring()

static int db_tostring ( lua_State * L)
static

Definition at line 1973 of file lsqlite3.c.

1973 {
1974 char buff[32];
1975 sdb *db = lsqlite_getdb(L, 1);
1976 if (db->db == NULL)
1977 strcpy(buff, "closed");
1978 else
1979 sprintf(buff, "%p", lua_touserdata(L, 1));
1980 lua_pushfstring(L, "sqlite database (%s)", buff);
1981 return 1;
1982}

References sdb::db, lsqlite_getdb(), lua_pushfstring(), lua_touserdata(), and NULL.

◆ db_total_changes()

static int db_total_changes ( lua_State * L)
static

Definition at line 909 of file lsqlite3.c.

909 {
910 sdb *db = lsqlite_checkdb(L, 1);
912 return 1;
913}
SQLITE_API int sqlite3_total_changes(sqlite3 *)
Definition sqlite3.c:162095

References sdb::db, lsqlite_checkdb(), lua_pushinteger(), and sqlite3_total_changes().

◆ db_trace()

static int db_trace ( lua_State * L)
static

Definition at line 1272 of file lsqlite3.c.

1272 {
1273 sdb *db = lsqlite_checkdb(L, 1);
1274
1275 if (lua_gettop(L) < 2 || lua_isnil(L, 2)) {
1278
1279 db->trace_cb =
1280 db->trace_udata = LUA_NOREF;
1281
1282 /* clear trace handler */
1283 sqlite3_trace(db->db, NULL, NULL);
1284 }
1285 else {
1287
1288 /* make sure we have an userdata field (even if nil) */
1289 lua_settop(L, 3);
1290
1293
1296
1297 /* set trace handler */
1299 }
1300
1301 return 0;
1302}
static void db_trace_callback(void *user, const char *sql)
Definition lsqlite3.c:1255
SQLITE_API SQLITE_DEPRECATED void * sqlite3_trace(sqlite3 *, void(*xTrace)(void *, const char *), void *)
Definition sqlite3.c:163075

References sdb::db, db_trace_callback(), lsqlite_checkdb(), lua_gettop(), lua_isnil, LUA_NOREF, LUA_REGISTRYINDEX, lua_settop(), LUA_TFUNCTION, luaL_checktype(), luaL_ref(), luaL_unref(), NULL, sqlite3_trace(), sdb::trace_cb, and sdb::trace_udata.

◆ db_trace_callback()

static void db_trace_callback ( void * user,
const char * sql )
static

Definition at line 1255 of file lsqlite3.c.

1255 {
1256 sdb *db = (sdb*)user;
1257 lua_State *L = db->L;
1258 int top = lua_gettop(L);
1259
1260 /* setup lua callback call */
1261 lua_rawgeti(L, LUA_REGISTRYINDEX, db->trace_cb); /* get callback */
1262 lua_rawgeti(L, LUA_REGISTRYINDEX, db->trace_udata); /* get callback user data */
1263 lua_pushstring(L, sql); /* traced sql statement */
1264
1265 /* call lua function */
1266 lua_pcall(L, 2, 0, 0);
1267 /* ignore any error generated by this function */
1268
1269 lua_settop(L, top);
1270}

References sdb::L, lua_gettop(), lua_pcall, lua_pushstring(), lua_rawgeti(), LUA_REGISTRYINDEX, lua_settop(), sdb::trace_cb, and sdb::trace_udata.

Referenced by db_trace().

◆ db_update_hook()

static int db_update_hook ( lua_State * L)
static

Definition at line 1336 of file lsqlite3.c.

1336 {
1337 sdb *db = lsqlite_checkdb(L, 1);
1338
1339 if (lua_gettop(L) < 2 || lua_isnil(L, 2)) {
1342
1343 db->update_hook_cb =
1345
1346 /* clear update_hook handler */
1348 }
1349 else {
1351
1352 /* make sure we have an userdata field (even if nil) */
1353 lua_settop(L, 3);
1354
1357
1360
1361 /* set update_hook handler */
1363 }
1364
1365 return 0;
1366}
static void db_update_hook_callback(void *user, int op, char const *dbname, char const *tblname, sqlite3_int64 rowid)
Definition lsqlite3.c:1314
SQLITE_API void * sqlite3_update_hook(sqlite3 *, void(*)(void *, int, char const *, char const *, sqlite3_int64), void *)
Definition sqlite3.c:163181

References sdb::db, db_update_hook_callback(), lsqlite_checkdb(), lua_gettop(), lua_isnil, LUA_NOREF, LUA_REGISTRYINDEX, lua_settop(), LUA_TFUNCTION, luaL_checktype(), luaL_ref(), luaL_unref(), NULL, sqlite3_update_hook(), sdb::update_hook_cb, and sdb::update_hook_udata.

◆ db_update_hook_callback()

static void db_update_hook_callback ( void * user,
int op,
char const * dbname,
char const * tblname,
sqlite3_int64 rowid )
static

Definition at line 1314 of file lsqlite3.c.

1314 {
1315 sdb *db = (sdb*)user;
1316 lua_State *L = db->L;
1317 int top = lua_gettop(L);
1318 lua_Number n;
1319
1320 /* setup lua callback call */
1321 lua_rawgeti(L, LUA_REGISTRYINDEX, db->update_hook_cb); /* get callback */
1322 lua_rawgeti(L, LUA_REGISTRYINDEX, db->update_hook_udata); /* get callback user data */
1323 lua_pushinteger(L, op);
1324 lua_pushstring(L, dbname); /* update_hook database name */
1325 lua_pushstring(L, tblname); /* update_hook database name */
1326
1327 PUSH_INT64(L, rowid, lua_pushfstring(L, "%ll", rowid));
1328
1329 /* call lua function */
1330 lua_pcall(L, 5, 0, 0);
1331 /* ignore any error generated by this function */
1332
1333 lua_settop(L, top);
1334}

References sdb::L, lua_gettop(), lua_pcall, lua_pushfstring(), lua_pushinteger(), lua_pushstring(), lua_rawgeti(), LUA_REGISTRYINDEX, lua_settop(), PUSH_INT64, sdb::update_hook_cb, and sdb::update_hook_udata.

Referenced by db_update_hook().

◆ db_urows()

static int db_urows ( lua_State * L)
static

Definition at line 1969 of file lsqlite3.c.

1969 {
1970 return db_do_rows(L, db_next_row);
1971}
static int db_next_row(lua_State *L)
Definition lsqlite3.c:1907

References db_do_rows(), and db_next_row().

◆ dbbu_finish()

static int dbbu_finish ( lua_State * L)
static

Definition at line 1663 of file lsqlite3.c.

1663 {
1664 sdb_bu *sbu = lsqlite_checkbu(L, 1);
1665 return cleanupbu(L, sbu);
1666}
static int cleanupbu(lua_State *L, sdb_bu *sbu)
Definition lsqlite3.c:1572
static sdb_bu * lsqlite_checkbu(lua_State *L, int index)
Definition lsqlite3.c:1628

References cleanupbu(), and lsqlite_checkbu().

◆ dbbu_gc()

static int dbbu_gc ( lua_State * L)
static

Definition at line 1634 of file lsqlite3.c.

1634 {
1635 sdb_bu *sbu = lsqlite_getbu(L, 1);
1636 if (sbu->bu != NULL) {
1637 cleanupbu(L, sbu);
1638 lua_pop(L, 1);
1639 }
1640 /* else ignore if already finished */
1641 return 0;
1642}
static sdb_bu * lsqlite_getbu(lua_State *L, int index)
Definition lsqlite3.c:1622

References sdb_bu::bu, cleanupbu(), lsqlite_getbu(), lua_pop, and NULL.

◆ dbbu_pagecount()

static int dbbu_pagecount ( lua_State * L)
static

Definition at line 1657 of file lsqlite3.c.

1657 {
1658 sdb_bu *sbu = lsqlite_checkbu(L, 1);
1660 return 1;
1661}
SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p)
Definition sqlite3.c:75693

References sdb_bu::bu, lsqlite_checkbu(), lua_pushinteger(), and sqlite3_backup_pagecount().

◆ dbbu_remaining()

static int dbbu_remaining ( lua_State * L)
static

Definition at line 1651 of file lsqlite3.c.

1651 {
1652 sdb_bu *sbu = lsqlite_checkbu(L, 1);
1654 return 1;
1655}
SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p)
Definition sqlite3.c:75679

References sdb_bu::bu, lsqlite_checkbu(), lua_pushinteger(), and sqlite3_backup_remaining().

◆ dbbu_step()

static int dbbu_step ( lua_State * L)
static

Definition at line 1644 of file lsqlite3.c.

1644 {
1645 sdb_bu *sbu = lsqlite_checkbu(L, 1);
1646 int nPage = luaL_checkint(L, 2);
1647 lua_pushinteger(L, sqlite3_backup_step(sbu->bu, nPage));
1648 return 1;
1649}
SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage)
Definition sqlite3.c:75371

References sdb_bu::bu, lsqlite_checkbu(), lua_pushinteger(), luaL_checkint, and sqlite3_backup_step().

◆ dbvm_bind()

static int dbvm_bind ( lua_State * L)
static

Definition at line 528 of file lsqlite3.c.

528 {
529 sdb_vm *svm = lsqlite_checkvm(L, 1);
530 sqlite3_stmt *vm = svm->vm;
531 int index = luaL_checkint(L, 2);
532 int result;
533
535 result = dbvm_bind_index(L, vm, index, 3);
536
537 lua_pushinteger(L, result);
538 return 1;
539}
guint index
static int dbvm_bind_index(lua_State *L, sqlite3_stmt *vm, int index, int lindex)
Definition lsqlite3.c:492
static void dbvm_check_bind_index(lua_State *L, sdb_vm *svm, int index)
Definition lsqlite3.c:319

References dbvm_bind_index(), dbvm_check_bind_index(), index, lsqlite_checkvm(), lua_pushinteger(), luaL_checkint, and sdb_vm::vm.

◆ dbvm_bind_blob()

static int dbvm_bind_blob ( lua_State * L)
static

Definition at line 541 of file lsqlite3.c.

541 {
542 sdb_vm *svm = lsqlite_checkvm(L, 1);
543 int index = luaL_checkint(L, 2);
544 const char *value = luaL_checkstring(L, 3);
545 int len = lua_strlen(L, 3);
546
548 return 1;
549}
SQLITE_API int sqlite3_bind_blob(sqlite3_stmt *, int, const void *, int n, void(*)(void *))
Definition sqlite3.c:84390
#define SQLITE_TRANSIENT
Definition sqlite3.c:6671

References index, lsqlite_checkvm(), lua_pushinteger(), lua_strlen, luaL_checkint, luaL_checkstring, sqlite3_bind_blob(), SQLITE_TRANSIENT, value, and sdb_vm::vm.

◆ dbvm_bind_index()

static int dbvm_bind_index ( lua_State * L,
sqlite3_stmt * vm,
int index,
int lindex )
static

Definition at line 492 of file lsqlite3.c.

492 {
493 switch (lua_type(L, lindex)) {
494 case LUA_TSTRING:
495 return sqlite3_bind_text(vm, index, lua_tostring(L, lindex), lua_strlen(L, lindex), SQLITE_TRANSIENT);
496 case LUA_TNUMBER:
497#if LUA_VERSION_NUM > 502
498 if (lua_isinteger(L, lindex))
499 return sqlite3_bind_int64(vm, index, lua_tointeger(L, lindex));
500#endif
501 return sqlite3_bind_double(vm, index, lua_tonumber(L, lindex));
502 case LUA_TBOOLEAN:
503 return sqlite3_bind_int(vm, index, lua_toboolean(L, lindex) ? 1 : 0);
504 case LUA_TNONE:
505 case LUA_TNIL:
506 return sqlite3_bind_null(vm, index);
507 default:
508 luaL_error(L, "index (%d) - invalid data type for bind (%s)", index, lua_typename(L, lua_type(L, lindex)));
509 return SQLITE_MISUSE; /*!*/
510 }
511}
LUA_API int lua_type(lua_State *L, int idx)
LUA_API const char * lua_typename(lua_State *L, int t)
#define LUA_TNONE
#define LUA_TSTRING
#define LUA_TBOOLEAN
#define LUA_TNUMBER
#define LUA_TNIL
#define SQLITE_MISUSE
Definition sqlite3.c:1491
SQLITE_API int sqlite3_bind_null(sqlite3_stmt *, int)
Definition sqlite3.c:84439
SQLITE_API int sqlite3_bind_text(sqlite3_stmt *, int, const char *, int, void(*)(void *))
Definition sqlite3.c:84466
SQLITE_API int sqlite3_bind_double(sqlite3_stmt *, int, double)
Definition sqlite3.c:84416
SQLITE_API int sqlite3_bind_int(sqlite3_stmt *, int, int)
Definition sqlite3.c:84426
SQLITE_API int sqlite3_bind_int64(sqlite3_stmt *, int, sqlite3_int64)
Definition sqlite3.c:84429

References index, lua_isinteger(), lua_strlen, LUA_TBOOLEAN, LUA_TNIL, LUA_TNONE, LUA_TNUMBER, lua_toboolean(), lua_tointeger, lua_tonumber, lua_tostring, LUA_TSTRING, lua_type(), lua_typename(), luaL_error(), sqlite3_bind_double(), sqlite3_bind_int(), sqlite3_bind_int64(), sqlite3_bind_null(), sqlite3_bind_text(), SQLITE_MISUSE, and SQLITE_TRANSIENT.

Referenced by dbvm_bind(), dbvm_bind_names(), and dbvm_bind_values().

◆ dbvm_bind_names()

static int dbvm_bind_names ( lua_State * L)
static

Definition at line 575 of file lsqlite3.c.

575 {
576 sdb_vm *svm = lsqlite_checkvm(L, 1);
577 sqlite3_stmt *vm = svm->vm;
578 int count = sqlite3_bind_parameter_count(vm);
579 const char *name;
580 int result, n;
582
583 for (n = 1; n <= count; ++n) {
585 if (name && (name[0] == ':' || name[0] == '$')) {
586 lua_pushstring(L, ++name);
587 lua_gettable(L, 2);
588 result = dbvm_bind_index(L, vm, n, -1);
589 lua_pop(L, 1);
590 }
591 else {
592 lua_pushinteger(L, n);
593 lua_gettable(L, 2);
594 result = dbvm_bind_index(L, vm, n, -1);
595 lua_pop(L, 1);
596 }
597
598 if (result != SQLITE_OK) {
599 lua_pushinteger(L, result);
600 return 1;
601 }
602 }
603
605 return 1;
606}
LUA_API void lua_gettable(lua_State *L, int idx)
#define LUA_TTABLE
SQLITE_API const char * sqlite3_bind_parameter_name(sqlite3_stmt *, int)
Definition sqlite3.c:84573
SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt *)
Definition sqlite3.c:84562

References dbvm_bind_index(), lsqlite_checkvm(), lua_gettable(), lua_pop, lua_pushinteger(), lua_pushstring(), LUA_TTABLE, luaL_checktype(), name, sqlite3_bind_parameter_count(), sqlite3_bind_parameter_name(), SQLITE_OK, and sdb_vm::vm.

◆ dbvm_bind_parameter_count()

static int dbvm_bind_parameter_count ( lua_State * L)
static

Definition at line 514 of file lsqlite3.c.

514 {
515 sdb_vm *svm = lsqlite_checkvm(L, 1);
517 return 1;
518}

References lsqlite_checkvm(), lua_pushinteger(), sqlite3_bind_parameter_count(), and sdb_vm::vm.

◆ dbvm_bind_parameter_name()

static int dbvm_bind_parameter_name ( lua_State * L)
static

Definition at line 520 of file lsqlite3.c.

520 {
521 sdb_vm *svm = lsqlite_checkvm(L, 1);
522 int index = luaL_checknumber(L, 2);
525 return 1;
526}
LUALIB_API lua_Number luaL_checknumber(lua_State *L, int narg)

References dbvm_check_bind_index(), index, lsqlite_checkvm(), lua_pushstring(), luaL_checknumber(), sqlite3_bind_parameter_name(), and sdb_vm::vm.

◆ dbvm_bind_values()

static int dbvm_bind_values ( lua_State * L)
static

Definition at line 551 of file lsqlite3.c.

551 {
552 sdb_vm *svm = lsqlite_checkvm(L, 1);
553 sqlite3_stmt *vm = svm->vm;
554 int top = lua_gettop(L);
555 int result, n;
556
557 if (top - 1 != sqlite3_bind_parameter_count(vm))
558 luaL_error(L,
559 "incorrect number of parameters to bind (%d given, %d to bind)",
560 top - 1,
562 );
563
564 for (n = 2; n <= top; ++n) {
565 if ((result = dbvm_bind_index(L, vm, n - 1, n)) != SQLITE_OK) {
566 lua_pushinteger(L, result);
567 return 1;
568 }
569 }
570
572 return 1;
573}

References dbvm_bind_index(), lsqlite_checkvm(), lua_gettop(), lua_pushinteger(), luaL_error(), sqlite3_bind_parameter_count(), SQLITE_OK, and sdb_vm::vm.

◆ dbvm_check_bind_index()

static void dbvm_check_bind_index ( lua_State * L,
sdb_vm * svm,
int index )
static

Definition at line 319 of file lsqlite3.c.

319 {
320 if (index < 1 || index > sqlite3_bind_parameter_count(svm->vm)) {
321 luaL_error(L, "bind index out of range [1..%d]", sqlite3_bind_parameter_count(svm->vm));
322 }
323}

References luaL_error(), sqlite3_bind_parameter_count(), and sdb_vm::vm.

Referenced by dbvm_bind(), and dbvm_bind_parameter_name().

◆ dbvm_check_contents()

static void dbvm_check_contents ( lua_State * L,
sdb_vm * svm )
static

Definition at line 307 of file lsqlite3.c.

307 {
308 if (!svm->has_values) {
309 luaL_error(L, "misuse of function");
310 }
311}

References sdb_vm::has_values, and luaL_error().

Referenced by dbvm_get_named_values(), dbvm_get_uvalues(), dbvm_get_value(), and dbvm_get_values().

◆ dbvm_check_index()

static void dbvm_check_index ( lua_State * L,
sdb_vm * svm,
int index )
static

Definition at line 313 of file lsqlite3.c.

313 {
314 if (index < 0 || index >= svm->columns) {
315 luaL_error(L, "index out of range [0..%d]", svm->columns - 1);
316 }
317}

References sdb_vm::columns, and luaL_error().

Referenced by dbvm_get_name(), dbvm_get_type(), and dbvm_get_value().

◆ dbvm_columns()

static int dbvm_columns ( lua_State * L)
static

Definition at line 338 of file lsqlite3.c.

338 {
339 sdb_vm *svm = lsqlite_checkvm(L, 1);
341 return 1;
342}
SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt)
Definition sqlite3.c:83978

References lsqlite_checkvm(), lua_pushinteger(), sqlite3_column_count(), and sdb_vm::vm.

◆ dbvm_do_rows()

static int dbvm_do_rows ( lua_State * L,
int(*)(lua_State *) f )
static

Definition at line 1919 of file lsqlite3.c.

1919 {
1920 /* sdb_vm *svm = */
1921 lsqlite_checkvm(L, 1);
1922 lua_pushvalue(L,1);
1923 lua_pushcfunction(L, f);
1924 lua_insert(L, -2);
1925 return 2;
1926}

References lsqlite_checkvm(), lua_insert, lua_pushcfunction, and lua_pushvalue().

Referenced by dbvm_nrows(), dbvm_rows(), and dbvm_urows().

◆ dbvm_finalize()

static int dbvm_finalize ( lua_State * L)
static

Definition at line 295 of file lsqlite3.c.

295 {
296 sdb_vm *svm = lsqlite_checkvm(L, 1);
297 return cleanupvm(L, svm);
298}

References cleanupvm(), and lsqlite_checkvm().

◆ dbvm_gc()

static int dbvm_gc ( lua_State * L)
static

Definition at line 276 of file lsqlite3.c.

276 {
277 sdb_vm *svm = lsqlite_getvm(L, 1);
278 if (svm->vm != NULL) /* ignore closed vms */
279 cleanupvm(L, svm);
280 return 0;
281}
static sdb_vm * lsqlite_getvm(lua_State *L, int index)
Definition lsqlite3.c:247

References cleanupvm(), lsqlite_getvm(), NULL, and sdb_vm::vm.

◆ dbvm_get_name()

static int dbvm_get_name ( lua_State * L)
static

Definition at line 359 of file lsqlite3.c.

359 {
360 sdb_vm *svm = lsqlite_checkvm(L, 1);
361 int index = luaL_checknumber(L, 2);
362 dbvm_check_index(L, svm, index);
364 return 1;
365}
static void dbvm_check_index(lua_State *L, sdb_vm *svm, int index)
Definition lsqlite3.c:313

References dbvm_check_index(), index, lsqlite_checkvm(), lua_pushstring(), luaL_checknumber(), sqlite3_column_name(), and sdb_vm::vm.

◆ dbvm_get_named_types()

static int dbvm_get_named_types ( lua_State * L)
static

Definition at line 471 of file lsqlite3.c.

471 {
472 sdb_vm *svm = lsqlite_checkvm(L, 1);
473 sqlite3_stmt *vm = svm->vm;
474 int columns = sqlite3_column_count(vm);
475 int n;
476
477 lua_createtable(L, 0, columns);
478 for (n = 0; n < columns; ++n) {
481 lua_rawset(L, -3);
482 }
483 return 1;
484}
SQLITE_API const char * sqlite3_column_decltype(sqlite3_stmt *, int)
Definition sqlite3.c:84241

References lsqlite_checkvm(), lua_createtable(), lua_pushstring(), lua_rawset(), sqlite3_column_count(), sqlite3_column_decltype(), sqlite3_column_name(), and sdb_vm::vm.

◆ dbvm_get_named_values()

static int dbvm_get_named_values ( lua_State * L)
static

Definition at line 455 of file lsqlite3.c.

455 {
456 sdb_vm *svm = lsqlite_checkvm(L, 1);
457 sqlite3_stmt *vm = svm->vm;
458 int columns = svm->columns;
459 int n;
460 dbvm_check_contents(L, svm);
461
462 lua_createtable(L, 0, columns);
463 for (n = 0; n < columns; ++n) {
465 vm_push_column(L, vm, n);
466 lua_rawset(L, -3);
467 }
468 return 1;
469}
static void dbvm_check_contents(lua_State *L, sdb_vm *svm)
Definition lsqlite3.c:307

References sdb_vm::columns, dbvm_check_contents(), lsqlite_checkvm(), lua_createtable(), lua_pushstring(), lua_rawset(), sqlite3_column_name(), sdb_vm::vm, and vm_push_column().

◆ dbvm_get_names()

static int dbvm_get_names ( lua_State * L)
static

Definition at line 390 of file lsqlite3.c.

390 {
391 sdb_vm *svm = lsqlite_checkvm(L, 1);
392 sqlite3_stmt *vm = svm->vm;
393 int columns = sqlite3_column_count(vm); /* valid as soon as statement prepared */
394 int n;
395
396 lua_createtable(L, columns, 0);
397 for (n = 0; n < columns;) {
399 lua_rawseti(L, -2, n);
400 }
401 return 1;
402}

References lsqlite_checkvm(), lua_createtable(), lua_pushstring(), lua_rawseti(), sqlite3_column_count(), sqlite3_column_name(), and sdb_vm::vm.

◆ dbvm_get_type()

static int dbvm_get_type ( lua_State * L)
static

Definition at line 367 of file lsqlite3.c.

367 {
368 sdb_vm *svm = lsqlite_checkvm(L, 1);
369 int index = luaL_checknumber(L, 2);
370 dbvm_check_index(L, svm, index);
372 return 1;
373}

References dbvm_check_index(), index, lsqlite_checkvm(), lua_pushstring(), luaL_checknumber(), sqlite3_column_decltype(), and sdb_vm::vm.

◆ dbvm_get_types()

static int dbvm_get_types ( lua_State * L)
static

Definition at line 404 of file lsqlite3.c.

404 {
405 sdb_vm *svm = lsqlite_checkvm(L, 1);
406 sqlite3_stmt *vm = svm->vm;
407 int columns = sqlite3_column_count(vm); /* valid as soon as statement prepared */
408 int n;
409
410 lua_createtable(L, columns, 0);
411 for (n = 0; n < columns;) {
413 lua_rawseti(L, -2, n);
414 }
415 return 1;
416}

References lsqlite_checkvm(), lua_createtable(), lua_pushstring(), lua_rawseti(), sqlite3_column_count(), sqlite3_column_decltype(), and sdb_vm::vm.

◆ dbvm_get_unames()

static int dbvm_get_unames ( lua_State * L)
static

Definition at line 431 of file lsqlite3.c.

431 {
432 sdb_vm *svm = lsqlite_checkvm(L, 1);
433 sqlite3_stmt *vm = svm->vm;
434 int columns = sqlite3_column_count(vm); /* valid as soon as statement prepared */
435 int n;
436
437 lua_checkstack(L, columns);
438 for (n = 0; n < columns; ++n)
440 return columns;
441}

References lsqlite_checkvm(), lua_checkstack(), lua_pushstring(), sqlite3_column_count(), sqlite3_column_name(), and sdb_vm::vm.

◆ dbvm_get_utypes()

static int dbvm_get_utypes ( lua_State * L)
static

Definition at line 443 of file lsqlite3.c.

443 {
444 sdb_vm *svm = lsqlite_checkvm(L, 1);
445 sqlite3_stmt *vm = svm->vm;
446 int columns = sqlite3_column_count(vm); /* valid as soon as statement prepared */
447 int n;
448
449 lua_checkstack(L, columns);
450 for (n = 0; n < columns; ++n)
452 return columns;
453}

References lsqlite_checkvm(), lua_checkstack(), lua_pushstring(), sqlite3_column_count(), sqlite3_column_decltype(), and sdb_vm::vm.

◆ dbvm_get_uvalues()

static int dbvm_get_uvalues ( lua_State * L)
static

Definition at line 418 of file lsqlite3.c.

418 {
419 sdb_vm *svm = lsqlite_checkvm(L, 1);
420 sqlite3_stmt *vm = svm->vm;
421 int columns = svm->columns;
422 int n;
423 dbvm_check_contents(L, svm);
424
425 lua_checkstack(L, columns);
426 for (n = 0; n < columns; ++n)
427 vm_push_column(L, vm, n);
428 return columns;
429}

References sdb_vm::columns, dbvm_check_contents(), lsqlite_checkvm(), lua_checkstack(), sdb_vm::vm, and vm_push_column().

◆ dbvm_get_value()

static int dbvm_get_value ( lua_State * L)
static

Definition at line 350 of file lsqlite3.c.

350 {
351 sdb_vm *svm = lsqlite_checkvm(L, 1);
352 int index = luaL_checkint(L, 2);
353 dbvm_check_contents(L, svm);
354 dbvm_check_index(L, svm, index);
355 vm_push_column(L, svm->vm, index);
356 return 1;
357}

References dbvm_check_contents(), dbvm_check_index(), index, lsqlite_checkvm(), luaL_checkint, sdb_vm::vm, and vm_push_column().

◆ dbvm_get_values()

static int dbvm_get_values ( lua_State * L)
static

Definition at line 375 of file lsqlite3.c.

375 {
376 sdb_vm *svm = lsqlite_checkvm(L, 1);
377 sqlite3_stmt *vm = svm->vm;
378 int columns = svm->columns;
379 int n;
380 dbvm_check_contents(L, svm);
381
382 lua_createtable(L, columns, 0);
383 for (n = 0; n < columns;) {
384 vm_push_column(L, vm, n++);
385 lua_rawseti(L, -2, n);
386 }
387 return 1;
388}

References sdb_vm::columns, dbvm_check_contents(), lsqlite_checkvm(), lua_createtable(), lua_rawseti(), sdb_vm::vm, and vm_push_column().

◆ dbvm_isopen()

static int dbvm_isopen ( lua_State * L)
static

Definition at line 259 of file lsqlite3.c.

259 {
260 sdb_vm *svm = lsqlite_getvm(L, 1);
261 lua_pushboolean(L, svm->vm != NULL ? 1 : 0);
262 return 1;
263}

References lsqlite_getvm(), lua_pushboolean(), NULL, and sdb_vm::vm.

◆ dbvm_last_insert_rowid()

static int dbvm_last_insert_rowid ( lua_State * L)
static

Definition at line 325 of file lsqlite3.c.

325 {
326 sdb_vm *svm = lsqlite_checkvm(L, 1);
327 /* conversion warning: int64 -> luaNumber */
329 PUSH_INT64(L, rowid, lua_pushfstring(L, "%ll", rowid));
330 return 1;
331}

References sdb::db, sdb_vm::db, lsqlite_checkvm(), lua_pushfstring(), PUSH_INT64, and sqlite3_last_insert_rowid().

◆ dbvm_nrows()

static int dbvm_nrows ( lua_State * L)
static

Definition at line 1932 of file lsqlite3.c.

1932 {
1934}
static int dbvm_do_rows(lua_State *L, int(*f)(lua_State *))
Definition lsqlite3.c:1919

References db_next_named_row(), and dbvm_do_rows().

◆ dbvm_reset()

static int dbvm_reset ( lua_State * L)
static

Definition at line 300 of file lsqlite3.c.

300 {
301 sdb_vm *svm = lsqlite_checkvm(L, 1);
302 sqlite3_reset(svm->vm);
304 return 1;
305}

References sdb::db, sdb_vm::db, lsqlite_checkvm(), lua_pushinteger(), sqlite3_errcode(), sqlite3_reset(), and sdb_vm::vm.

◆ dbvm_rows()

static int dbvm_rows ( lua_State * L)
static

Definition at line 1928 of file lsqlite3.c.

1928 {
1930}

References db_next_packed_row(), and dbvm_do_rows().

◆ dbvm_step()

static int dbvm_step ( lua_State * L)
static

Definition at line 283 of file lsqlite3.c.

283 {
284 int result;
285 sdb_vm *svm = lsqlite_checkvm(L, 1);
286
287 result = stepvm(L, svm);
288 svm->has_values = result == SQLITE_ROW ? 1 : 0;
289 svm->columns = sqlite3_data_count(svm->vm);
290
291 lua_pushinteger(L, result);
292 return 1;
293}

References sdb_vm::columns, sdb_vm::has_values, lsqlite_checkvm(), lua_pushinteger(), sqlite3_data_count(), SQLITE_ROW, stepvm(), and sdb_vm::vm.

◆ dbvm_tostring()

static int dbvm_tostring ( lua_State * L)
static

Definition at line 265 of file lsqlite3.c.

265 {
266 char buff[39];
267 sdb_vm *svm = lsqlite_getvm(L, 1);
268 if (svm->vm == NULL)
269 strcpy(buff, "closed");
270 else
271 sprintf(buff, "%p", svm);
272 lua_pushfstring(L, "sqlite virtual machine (%s)", buff);
273 return 1;
274}

References lsqlite_getvm(), lua_pushfstring(), NULL, and sdb_vm::vm.

◆ dbvm_urows()

static int dbvm_urows ( lua_State * L)
static

Definition at line 1936 of file lsqlite3.c.

1936 {
1937 return dbvm_do_rows(L, db_next_row);
1938}

References db_next_row(), and dbvm_do_rows().

◆ lcontext_aggregate_count()

static int lcontext_aggregate_count ( lua_State * L)
static

Definition at line 801 of file lsqlite3.c.

801 {
802 lcontext *ctx = lsqlite_checkcontext(L, 1);
805 return 1;
806}
static void lcontext_check_aggregate(lua_State *L, lcontext *ctx)
Definition lsqlite3.c:771
static lcontext * lsqlite_checkcontext(lua_State *L, int index)
Definition lsqlite3.c:754
SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context *)
Definition sqlite3.c:83969

References lcontext::ctx, lcontext_check_aggregate(), lsqlite_checkcontext(), lua_pushinteger(), and sqlite3_aggregate_count().

◆ lcontext_check_aggregate()

static void lcontext_check_aggregate ( lua_State * L,
lcontext * ctx )
static

Definition at line 771 of file lsqlite3.c.

771 {
772 sdb_func *func = (sdb_func*)sqlite3_user_data(ctx->ctx);
773 if (!func->aggregate) {
774 luaL_error(L, "attempt to call aggregate method from scalar function");
775 }
776}

References sdb_func::aggregate, lcontext::ctx, luaL_error(), and sqlite3_user_data().

Referenced by lcontext_aggregate_count(), lcontext_get_aggregate_context(), and lcontext_set_aggregate_context().

◆ lcontext_get_aggregate_context()

static int lcontext_get_aggregate_context ( lua_State * L)
static

Definition at line 785 of file lsqlite3.c.

785 {
786 lcontext *ctx = lsqlite_checkcontext(L, 1);
789 return 1;
790}

References lcontext_check_aggregate(), lsqlite_checkcontext(), lua_rawgeti(), LUA_REGISTRYINDEX, and lcontext::ud.

◆ lcontext_result()

static int lcontext_result ( lua_State * L)
static

Definition at line 813 of file lsqlite3.c.

813 {
814 lcontext *ctx = lsqlite_checkcontext(L, 1);
815 switch (lua_type(L, 2)) {
816 case LUA_TNUMBER:
817#if LUA_VERSION_NUM > 502
818 if (lua_isinteger(L, 2))
820 else
821#endif
823 break;
824 case LUA_TSTRING:
826 break;
827 case LUA_TNIL:
828 case LUA_TNONE:
830 break;
831 default:
832 luaL_error(L, "invalid result type %s", lua_typename(L, 2));
833 break;
834 }
835
836 return 0;
837}
LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int narg)
SQLITE_API void sqlite3_result_text(sqlite3_context *, const char *, int, void(*)(void *))
Definition sqlite3.c:83449
SQLITE_API void sqlite3_result_double(sqlite3_context *, double)
Definition sqlite3.c:83403
SQLITE_API void sqlite3_result_int64(sqlite3_context *, sqlite3_int64)
Definition sqlite3.c:83423
SQLITE_API void sqlite3_result_null(sqlite3_context *)
Definition sqlite3.c:83427

References lcontext::ctx, lsqlite_checkcontext(), lua_isinteger(), lua_strlen, LUA_TNIL, LUA_TNONE, LUA_TNUMBER, LUA_TSTRING, lua_type(), lua_typename(), luaL_checkinteger(), luaL_checknumber(), luaL_checkstring, luaL_error(), sqlite3_result_double(), sqlite3_result_int64(), sqlite3_result_null(), sqlite3_result_text(), and SQLITE_TRANSIENT.

◆ lcontext_result_blob()

static int lcontext_result_blob ( lua_State * L)
static

Definition at line 839 of file lsqlite3.c.

839 {
840 lcontext *ctx = lsqlite_checkcontext(L, 1);
841 const char *blob = luaL_checkstring(L, 2);
842 int size = lua_strlen(L, 2);
843 sqlite3_result_blob(ctx->ctx, (const void*)blob, size, SQLITE_TRANSIENT);
844 return 0;
845}
SQLITE_API void sqlite3_result_blob(sqlite3_context *, const void *, int, void(*)(void *))
Definition sqlite3.c:83379

References lcontext::ctx, lsqlite_checkcontext(), lua_strlen, luaL_checkstring, sqlite3_result_blob(), and SQLITE_TRANSIENT.

◆ lcontext_result_double()

static int lcontext_result_double ( lua_State * L)
static

Definition at line 847 of file lsqlite3.c.

847 {
848 lcontext *ctx = lsqlite_checkcontext(L, 1);
849 double d = luaL_checknumber(L, 2);
850 sqlite3_result_double(ctx->ctx, d);
851 return 0;
852}

References lcontext::ctx, lsqlite_checkcontext(), luaL_checknumber(), and sqlite3_result_double().

◆ lcontext_result_error()

static int lcontext_result_error ( lua_State * L)
static

Definition at line 854 of file lsqlite3.c.

854 {
855 lcontext *ctx = lsqlite_checkcontext(L, 1);
856 const char *err = luaL_checkstring(L, 2);
857 int size = lua_strlen(L, 2);
858 sqlite3_result_error(ctx->ctx, err, size);
859 return 0;
860}

References lcontext::ctx, lsqlite_checkcontext(), lua_strlen, luaL_checkstring, and sqlite3_result_error().

◆ lcontext_result_int()

static int lcontext_result_int ( lua_State * L)
static

Definition at line 862 of file lsqlite3.c.

862 {
863 lcontext *ctx = lsqlite_checkcontext(L, 1);
864 int i = luaL_checkint(L, 2);
865 sqlite3_result_int(ctx->ctx, i);
866 return 0;
867}
SQLITE_API void sqlite3_result_int(sqlite3_context *, int)
Definition sqlite3.c:83419

References lcontext::ctx, lsqlite_checkcontext(), luaL_checkint, and sqlite3_result_int().

◆ lcontext_result_null()

static int lcontext_result_null ( lua_State * L)
static

Definition at line 869 of file lsqlite3.c.

869 {
870 lcontext *ctx = lsqlite_checkcontext(L, 1);
872 return 0;
873}

References lcontext::ctx, lsqlite_checkcontext(), and sqlite3_result_null().

◆ lcontext_result_text()

static int lcontext_result_text ( lua_State * L)
static

Definition at line 875 of file lsqlite3.c.

875 {
876 lcontext *ctx = lsqlite_checkcontext(L, 1);
877 const char *text = luaL_checkstring(L, 2);
878 int size = lua_strlen(L, 2);
879 sqlite3_result_text(ctx->ctx, text, size, SQLITE_TRANSIENT);
880 return 0;
881}

References lcontext::ctx, lsqlite_checkcontext(), lua_strlen, luaL_checkstring, sqlite3_result_text(), and SQLITE_TRANSIENT.

◆ lcontext_set_aggregate_context()

static int lcontext_set_aggregate_context ( lua_State * L)
static

Definition at line 792 of file lsqlite3.c.

792 {
793 lcontext *ctx = lsqlite_checkcontext(L, 1);
795 lua_settop(L, 2);
797 ctx->ud = luaL_ref(L, LUA_REGISTRYINDEX);
798 return 0;
799}

References lcontext_check_aggregate(), lsqlite_checkcontext(), LUA_REGISTRYINDEX, lua_settop(), luaL_ref(), luaL_unref(), and lcontext::ud.

◆ lcontext_tostring()

static int lcontext_tostring ( lua_State * L)
static

Definition at line 760 of file lsqlite3.c.

760 {
761 char buff[39];
762 lcontext *ctx = lsqlite_getcontext(L, 1);
763 if (ctx->ctx == NULL)
764 strcpy(buff, "closed");
765 else
766 sprintf(buff, "%p", ctx->ctx);
767 lua_pushfstring(L, "sqlite function context (%s)", buff);
768 return 1;
769}

References lcontext::ctx, lsqlite_getcontext(), lua_pushfstring(), and NULL.

◆ lcontext_user_data()

static int lcontext_user_data ( lua_State * L)
static

Definition at line 778 of file lsqlite3.c.

778 {
779 lcontext *ctx = lsqlite_checkcontext(L, 1);
780 sdb_func *func = (sdb_func*)sqlite3_user_data(ctx->ctx);
782 return 1;
783}

References lcontext::ctx, lsqlite_checkcontext(), lua_rawgeti(), LUA_REGISTRYINDEX, sqlite3_user_data(), and sdb_func::udata.

◆ lsqlite_backup_init()

static int lsqlite_backup_init ( lua_State * L)
static

Definition at line 1587 of file lsqlite3.c.

1587 {
1588
1589 sdb *target_db = lsqlite_checkdb(L, 1);
1590 const char *target_nm = luaL_checkstring(L, 2);
1591 sdb *source_db = lsqlite_checkdb(L, 3);
1592 const char *source_nm = luaL_checkstring(L, 4);
1593
1594 sqlite3_backup *bu = sqlite3_backup_init(target_db->db, target_nm, source_db->db, source_nm);
1595
1596 if (NULL != bu) {
1597 sdb_bu *sbu = (sdb_bu*)lua_newuserdata(L, sizeof(sdb_bu));
1598
1600 lua_setmetatable(L, -2); /* set metatable */
1601 sbu->bu = bu;
1602
1603 /* create table from registry */
1604 /* to prevent referenced databases from being garbage collected while bu is live */
1605 lua_pushlightuserdata(L, bu);
1606 lua_createtable(L, 2, 0);
1607 /* add source and target dbs to table at indices 1 and 2 */
1608 lua_pushvalue(L, 1); /* target db */
1609 lua_rawseti(L, -2, 1);
1610 lua_pushvalue(L, 3); /* source db */
1611 lua_rawseti(L, -2, 2);
1612 /* put table in registry with key lightuserdata bu */
1614
1615 return 1;
1616 }
1617 else {
1618 return 0;
1619 }
1620}
static const char * sqlite_bu_meta
Definition lsqlite3.c:126
LUA_API int lua_setmetatable(lua_State *L, int objindex)
#define luaL_getmetatable(L, n)
#define lua_newuserdata(L, s)
SQLITE_API sqlite3_backup * sqlite3_backup_init(sqlite3 *pDest, const char *zDestName, sqlite3 *pSource, const char *zSourceName)
Definition sqlite3.c:75191

References sdb_bu::bu, sdb::db, lsqlite_checkdb(), lua_createtable(), lua_newuserdata, lua_pushlightuserdata(), lua_pushvalue(), lua_rawset(), lua_rawseti(), LUA_REGISTRYINDEX, lua_setmetatable(), luaL_checkstring, luaL_getmetatable, NULL, sqlite3_backup_init(), and sqlite_bu_meta.

◆ lsqlite_checkbu()

static sdb_bu * lsqlite_checkbu ( lua_State * L,
int index )
static

Definition at line 1628 of file lsqlite3.c.

1628 {
1629 sdb_bu *sbu = lsqlite_getbu(L, index);
1630 if (sbu->bu == NULL) luaL_argerror(L, index, "attempt to use closed sqlite database backup");
1631 return sbu;
1632}
LUALIB_API int luaL_argerror(lua_State *L, int narg, const char *extramsg)

References sdb_bu::bu, index, lsqlite_getbu(), luaL_argerror(), and NULL.

Referenced by dbbu_finish(), dbbu_pagecount(), dbbu_remaining(), and dbbu_step().

◆ lsqlite_checkcontext()

◆ lsqlite_checkdb()

◆ lsqlite_checkvm()

◆ lsqlite_complete()

static int lsqlite_complete ( lua_State * L)
static

Definition at line 2045 of file lsqlite3.c.

2045 {
2046 const char *sql = luaL_checkstring(L, 1);
2048 return 1;
2049}
SQLITE_API int sqlite3_complete(const char *sql)
Definition sqlite3.c:160710

References lua_pushboolean(), luaL_checkstring, and sqlite3_complete().

◆ lsqlite_do_open()

static int lsqlite_do_open ( lua_State * L,
const char * filename,
int flags )
static

Definition at line 2072 of file lsqlite3.c.

2072 {
2073 sdb *db = newdb(L); /* create and leave in stack */
2074
2075 if (SQLITE3_OPEN(filename, &db->db, flags) == SQLITE_OK) {
2076 /* database handle already in the stack - return it */
2077 return 1;
2078 }
2079
2080 /* failed to open database */
2081 lua_pushnil(L); /* push nil */
2083 lua_pushstring(L, sqlite3_errmsg(db->db)); /* push error message */
2084
2085 /* clean things up */
2086 cleanupdb(L, db);
2087
2088 /* return */
2089 return 3;
2090}
#define SQLITE3_OPEN(L, filename, flags)
Definition lsqlite3.c:69
static sdb * newdb(lua_State *L)
Definition lsqlite3.c:621

References cleanupdb(), sdb::db, lua_pushinteger(), lua_pushnil(), lua_pushstring(), newdb(), sqlite3_errcode(), sqlite3_errmsg(), SQLITE3_OPEN, and SQLITE_OK.

Referenced by lsqlite_open(), and lsqlite_open_memory().

◆ lsqlite_getbu()

static sdb_bu * lsqlite_getbu ( lua_State * L,
int index )
static

Definition at line 1622 of file lsqlite3.c.

1622 {
1624 if (sbu == NULL) luaL_typerror(L, index, "sqlite database backup");
1625 return sbu;
1626}
LUALIB_API int luaL_typerror(lua_State *L, int narg, const char *tname)
LUALIB_API void * luaL_checkudata(lua_State *L, int ud, const char *tname)

References index, luaL_checkudata(), luaL_typerror(), NULL, and sqlite_bu_meta.

Referenced by dbbu_gc(), and lsqlite_checkbu().

◆ lsqlite_getcontext()

static lcontext * lsqlite_getcontext ( lua_State * L,
int index )
static

Definition at line 748 of file lsqlite3.c.

748 {
750 if (ctx == NULL) luaL_typerror(L, index, "sqlite context");
751 return ctx;
752}
static const char * sqlite_ctx_meta
Definition lsqlite3.c:127

References index, luaL_checkudata(), luaL_typerror(), NULL, and sqlite_ctx_meta.

Referenced by db_sql_finalize_function(), db_sql_normal_function(), lcontext_tostring(), and lsqlite_checkcontext().

◆ lsqlite_getdb()

static sdb * lsqlite_getdb ( lua_State * L,
int index )
static

Definition at line 716 of file lsqlite3.c.

716 {
718 if (db == NULL) luaL_typerror(L, index, "sqlite database");
719 return db;
720}
static const char * sqlite_meta
Definition lsqlite3.c:124

References index, luaL_checkudata(), luaL_typerror(), NULL, and sqlite_meta.

Referenced by db_gc(), db_isopen(), db_tostring(), and lsqlite_checkdb().

◆ lsqlite_getvm()

static sdb_vm * lsqlite_getvm ( lua_State * L,
int index )
static

Definition at line 247 of file lsqlite3.c.

247 {
249 if (svm == NULL) luaL_argerror(L, index, "bad sqlite virtual machine");
250 return svm;
251}
static const char * sqlite_vm_meta
Definition lsqlite3.c:125

References index, luaL_argerror(), luaL_checkudata(), NULL, and sqlite_vm_meta.

Referenced by dbvm_gc(), dbvm_isopen(), dbvm_tostring(), and lsqlite_checkvm().

◆ lsqlite_lversion()

static int lsqlite_lversion ( lua_State * L)
static

Definition at line 2139 of file lsqlite3.c.

2139 {
2141 return 1;
2142}
#define LSQLITE_VERSION
Definition lsqlite3.c:2134

References LSQLITE_VERSION, and lua_pushstring().

◆ lsqlite_make_context()

static lcontext * lsqlite_make_context ( lua_State * L)
static

Definition at line 739 of file lsqlite3.c.

739 {
740 lcontext *ctx = (lcontext*)lua_newuserdata(L, sizeof(lcontext));
742 lua_setmetatable(L, -2);
743 ctx->ctx = NULL;
744 ctx->ud = LUA_NOREF;
745 return ctx;
746}
static int sqlite_ctx_meta_ref
Definition lsqlite3.c:128

References lcontext::ctx, lua_newuserdata, LUA_NOREF, lua_rawgeti(), LUA_REGISTRYINDEX, lua_setmetatable(), NULL, sqlite_ctx_meta_ref, and lcontext::ud.

Referenced by db_sql_finalize_function(), and db_sql_normal_function().

◆ lsqlite_newindex()

static int lsqlite_newindex ( lua_State * L)
static

Definition at line 2126 of file lsqlite3.c.

2126 {
2127 lua_pushliteral(L, "attempt to change readonly table");
2128 lua_error(L);
2129 return 0;
2130}
#define lua_pushliteral(L, s)

References lua_error(), and lua_pushliteral.

◆ lsqlite_open()

static int lsqlite_open ( lua_State * L)
static

Definition at line 2092 of file lsqlite3.c.

2092 {
2093 const char *filename = luaL_checkstring(L, 1);
2095 return lsqlite_do_open(L, filename, flags);
2096}
static int lsqlite_do_open(lua_State *L, const char *filename, int flags)
Definition lsqlite3.c:2072
LUALIB_API lua_Integer luaL_optinteger(lua_State *L, int narg, lua_Integer def)
#define SQLITE_OPEN_CREATE
Definition sqlite3.c:1603
#define SQLITE_OPEN_READWRITE
Definition sqlite3.c:1602

References lsqlite_do_open(), luaL_checkstring, luaL_optinteger(), SQLITE_OPEN_CREATE, and SQLITE_OPEN_READWRITE.

◆ lsqlite_open_memory()

static int lsqlite_open_memory ( lua_State * L)
static

Definition at line 2098 of file lsqlite3.c.

2098 {
2100}

References lsqlite_do_open(), SQLITE_OPEN_CREATE, and SQLITE_OPEN_READWRITE.

◆ lsqlite_open_ptr()

static int lsqlite_open_ptr ( lua_State * L)
static

Definition at line 2107 of file lsqlite3.c.

2107 {
2108 sqlite3 *db_ptr;
2109 sdb *db;
2110 int rc;
2111
2113 db_ptr = lua_touserdata(L, 1);
2114 /* This is the only API function that runs sqlite3SafetyCheck regardless of
2115 * SQLITE_ENABLE_API_ARMOR and does almost nothing (without an SQL
2116 * statement) */
2117 rc = sqlite3_exec(db_ptr, NULL, NULL, NULL, NULL);
2118 if (rc != SQLITE_OK)
2119 luaL_argerror(L, 1, "not a valid SQLite3 pointer");
2120
2121 db = newdb(L); /* create and leave in stack */
2122 db->db = db_ptr;
2123 return 1;
2124}
#define LUA_TLIGHTUSERDATA

References sdb::db, LUA_TLIGHTUSERDATA, lua_touserdata(), luaL_argerror(), luaL_checktype(), newdb(), NULL, sqlite3_exec(), and SQLITE_OK.

◆ lsqlite_temp_directory()

static int lsqlite_temp_directory ( lua_State * L)
static

Definition at line 2052 of file lsqlite3.c.

2052 {
2053 const char *oldtemp = sqlite3_temp_directory;
2054
2055 if (!lua_isnone(L, 1)) {
2056 const char *temp = luaL_optstring(L, 1, NULL);
2059 }
2060 if (temp) {
2062 }
2063 else {
2065 }
2066 }
2067 lua_pushstring(L, oldtemp);
2068 return 1;
2069}
#define lua_isnone(L, n)
SQLITE_API char * sqlite3_mprintf(const char *,...)
Definition sqlite3.c:29323
SQLITE_API char * sqlite3_temp_directory
Definition sqlite3.c:7084

References lua_isnone, lua_pushstring(), luaL_optstring, NULL, sqlite3_free(), sqlite3_mprintf(), and sqlite3_temp_directory.

◆ lsqlite_version()

static int lsqlite_version ( lua_State * L)
static

Definition at line 2040 of file lsqlite3.c.

2040 {
2042 return 1;
2043}
SQLITE_API const char * sqlite3_libversion(void)
Definition sqlite3.c:161104

References lua_pushstring(), and sqlite3_libversion().

◆ luaopen_lsqlite3()

LUALIB_API int luaopen_lsqlite3 ( lua_State * L)

Definition at line 2384 of file lsqlite3.c.

2384 {
2389
2392
2393 /* register global sqlite3 library */
2394 luaL_requiref(L, "sqlite3", luaopen_sqlitelib, 1);
2395
2396 {
2397 int i = 0;
2398 /* add constants to global table */
2399 while (sqlite_constants[i].name) {
2402 lua_rawset(L, -3);
2403 ++i;
2404 }
2405 }
2406
2407 /* set sqlite's metatable to itself - set as readonly (__newindex) */
2408 lua_pushvalue(L, -1);
2409 lua_setmetatable(L, -2);
2410
2411 return 1;
2412}
static const luaL_Reg vmlib[]
Definition lsqlite3.c:2268
static const struct @45 sqlite_constants[]
static const luaL_Reg ctxlib[]
Definition lsqlite3.c:2316
static void create_meta(lua_State *L, const char *name, const luaL_Reg *lib)
Definition lsqlite3.c:2365
static const luaL_Reg dblib[]
Definition lsqlite3.c:2224
static int luaopen_sqlitelib(lua_State *L)
Definition lsqlite3.c:2378
static const luaL_Reg dbbulib[]
Definition lsqlite3.c:2336
LUALIB_API void luaL_requiref(lua_State *L, const char *modname, lua_CFunction openf, int glb)

References create_meta(), ctxlib, dbbulib, dblib, lua_pushinteger(), lua_pushstring(), lua_pushvalue(), lua_rawset(), LUA_REGISTRYINDEX, lua_setmetatable(), luaL_getmetatable, luaL_ref(), luaL_requiref(), luaopen_sqlitelib(), name, sqlite_bu_meta, sqlite_constants, sqlite_ctx_meta, sqlite_ctx_meta_ref, sqlite_meta, sqlite_vm_meta, value, and vmlib.

◆ luaopen_sqlitelib()

static int luaopen_sqlitelib ( lua_State * L)
static

Definition at line 2378 of file lsqlite3.c.

2378 {
2380 luaL_setfuncs(L, sqlitelib, 0);
2381 return 1;
2382}
static const luaL_Reg sqlitelib[]
Definition lsqlite3.c:2348
LUALIB_API void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup)
#define luaL_newlibtable(L, l)

References luaL_newlibtable, luaL_setfuncs(), and sqlitelib.

Referenced by luaopen_lsqlite3().

◆ newdb()

static sdb * newdb ( lua_State * L)
static

Definition at line 621 of file lsqlite3.c.

621 {
622 sdb *db = (sdb*)lua_newuserdata(L, sizeof(sdb));
623 db->L = L;
624 db->db = NULL; /* database handle is currently `closed' */
625 db->func = NULL;
626
627 db->busy_cb =
628 db->busy_udata =
629 db->progress_cb =
630 db->progress_udata =
631 db->trace_cb =
632 db->trace_udata =
633#if !defined(LSQLITE_OMIT_UPDATE_HOOK) || !LSQLITE_OMIT_UPDATE_HOOK
634 db->update_hook_cb =
636 db->commit_hook_cb =
638 db->rollback_hook_cb =
640#endif
641 LUA_NOREF;
642
644 lua_setmetatable(L, -2); /* set metatable */
645
646 /* to keep track of 'open' virtual machines */
648 lua_newtable(L);
650
651 return db;
652}

References sdb::busy_cb, sdb::busy_udata, sdb::commit_hook_cb, sdb::commit_hook_udata, sdb::db, sdb::func, sdb::L, lua_newtable, lua_newuserdata, LUA_NOREF, lua_pushlightuserdata(), lua_rawset(), LUA_REGISTRYINDEX, lua_setmetatable(), luaL_getmetatable, NULL, sdb::progress_cb, sdb::progress_udata, sdb::rollback_hook_cb, sdb::rollback_hook_udata, sqlite_meta, sdb::trace_cb, sdb::trace_udata, sdb::update_hook_cb, and sdb::update_hook_udata.

Referenced by lsqlite_do_open(), and lsqlite_open_ptr().

◆ newvm()

static sdb_vm * newvm ( lua_State * L,
sdb * db )
static

Definition at line 200 of file lsqlite3.c.

200 {
201 sdb_vm *svm = (sdb_vm*)lua_newuserdata(L, sizeof(sdb_vm)); /* db sql svm_ud -- */
202
204 lua_setmetatable(L, -2); /* set metatable */
205
206 svm->db = db;
207 svm->columns = 0;
208 svm->has_values = 0;
209 svm->vm = NULL;
210 svm->temp = 0;
211
212 /* add an entry on the database table: svm -> db to keep db live while svm is live */
213 lua_pushlightuserdata(L, db); /* db sql svm_ud db_lud -- */
214 lua_rawget(L, LUA_REGISTRYINDEX); /* db sql svm_ud reg[db_lud] -- */
215 lua_pushlightuserdata(L, svm); /* db sql svm_ud reg[db_lud] svm_lud -- */
216 lua_pushvalue(L, -5); /* db sql svm_ud reg[db_lud] svm_lud db -- */
217 lua_rawset(L, -3); /* (reg[db_lud])[svm_lud] = db ; set the db for this vm */
218 lua_pop(L, 1); /* db sql svm_ud -- */
219
220 return svm;
221}

References sdb_vm::columns, sdb_vm::db, sdb_vm::has_values, lua_newuserdata, lua_pop, lua_pushlightuserdata(), lua_pushvalue(), lua_rawget(), lua_rawset(), LUA_REGISTRYINDEX, lua_setmetatable(), luaL_getmetatable, NULL, sqlite_vm_meta, sdb_vm::temp, and sdb_vm::vm.

Referenced by db_do_rows(), and db_prepare().

◆ stepvm()

static int stepvm ( lua_State * L,
sdb_vm * svm )
static

Definition at line 243 of file lsqlite3.c.

243 {
244 return sqlite3_step(svm->vm);
245}
SQLITE_API int sqlite3_step(sqlite3_stmt *)
Definition sqlite3.c:83730

References sqlite3_step(), and sdb_vm::vm.

Referenced by db_do_next_row(), and dbvm_step().

◆ vm_push_column()

static void vm_push_column ( lua_State * L,
sqlite3_stmt * vm,
int idx )
static

Definition at line 162 of file lsqlite3.c.

162 {
163 switch (sqlite3_column_type(vm, idx)) {
164 case SQLITE_INTEGER:
166 , lua_pushlstring(L, (const char*)sqlite3_column_text(vm, idx)
167 , sqlite3_column_bytes(vm, idx)));
168 break;
169 case SQLITE_FLOAT:
171 break;
172 case SQLITE_TEXT:
173 lua_pushlstring(L, (const char*)sqlite3_column_text(vm, idx), sqlite3_column_bytes(vm, idx));
174 break;
175 case SQLITE_BLOB:
177 break;
178 case SQLITE_NULL:
179 lua_pushnil(L);
180 break;
181 default:
182 lua_pushnil(L);
183 break;
184 }
185}
SQLITE_API int sqlite3_column_bytes(sqlite3_stmt *, int iCol)
Definition sqlite3.c:84101
SQLITE_API double sqlite3_column_double(sqlite3_stmt *, int iCol)
Definition sqlite3.c:84111
SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt *, int iCol)
Definition sqlite3.c:84121
SQLITE_API int sqlite3_column_type(sqlite3_stmt *, int iCol)
Definition sqlite3.c:84147
SQLITE_API const void * sqlite3_column_blob(sqlite3_stmt *, int iCol)
Definition sqlite3.c:84091
SQLITE_API const unsigned char * sqlite3_column_text(sqlite3_stmt *, int iCol)
Definition sqlite3.c:84126

References lua_pushlstring(), lua_pushnil(), lua_pushnumber(), PUSH_INT64, sqlite3_column_blob(), sqlite3_column_bytes(), sqlite3_column_double(), sqlite3_column_int64(), sqlite3_column_text(), sqlite3_column_type(), SQLITE_BLOB, SQLITE_FLOAT, SQLITE_INTEGER, SQLITE_NULL, and SQLITE_TEXT.

Referenced by db_do_next_row(), dbvm_get_named_values(), dbvm_get_uvalues(), dbvm_get_value(), and dbvm_get_values().

Variable Documentation

◆ ctxlib

const luaL_Reg ctxlib[]
static
Initial value:
= {
{"user_data", lcontext_user_data },
{"get_aggregate_data", lcontext_get_aggregate_context },
{"set_aggregate_data", lcontext_set_aggregate_context },
{"aggregate_count", lcontext_aggregate_count },
{"result", lcontext_result },
{"result_null", lcontext_result_null },
{"result_number", lcontext_result_double },
{"result_double", lcontext_result_double },
{"result_int", lcontext_result_int },
{"result_text", lcontext_result_text },
{"result_blob", lcontext_result_blob },
{"result_error", lcontext_result_error },
{"__tostring", lcontext_tostring },
}
static int lcontext_tostring(lua_State *L)
Definition lsqlite3.c:760
static int lcontext_user_data(lua_State *L)
Definition lsqlite3.c:778
static int lcontext_result_text(lua_State *L)
Definition lsqlite3.c:875
static int lcontext_aggregate_count(lua_State *L)
Definition lsqlite3.c:801
static int lcontext_get_aggregate_context(lua_State *L)
Definition lsqlite3.c:785
static int lcontext_result_blob(lua_State *L)
Definition lsqlite3.c:839
static int lcontext_result_double(lua_State *L)
Definition lsqlite3.c:847
static int lcontext_result(lua_State *L)
Definition lsqlite3.c:813
static int lcontext_set_aggregate_context(lua_State *L)
Definition lsqlite3.c:792
static int lcontext_result_null(lua_State *L)
Definition lsqlite3.c:869
static int lcontext_result_error(lua_State *L)
Definition lsqlite3.c:854
static int lcontext_result_int(lua_State *L)
Definition lsqlite3.c:862

Definition at line 2316 of file lsqlite3.c.

2316 {
2317 {"user_data", lcontext_user_data },
2318
2319 {"get_aggregate_data", lcontext_get_aggregate_context },
2320 {"set_aggregate_data", lcontext_set_aggregate_context },
2321 {"aggregate_count", lcontext_aggregate_count },
2322
2323 {"result", lcontext_result },
2324 {"result_null", lcontext_result_null },
2325 {"result_number", lcontext_result_double },
2326 {"result_double", lcontext_result_double },
2327 {"result_int", lcontext_result_int },
2328 {"result_text", lcontext_result_text },
2329 {"result_blob", lcontext_result_blob },
2330 {"result_error", lcontext_result_error },
2331
2332 {"__tostring", lcontext_tostring },
2333 {NULL, NULL}
2334};

Referenced by luaopen_lsqlite3().

◆ dbbulib

const luaL_Reg dbbulib[]
static
Initial value:
= {
{"step", dbbu_step },
{"remaining", dbbu_remaining },
{"pagecount", dbbu_pagecount },
{"finish", dbbu_finish },
{"__gc", dbbu_gc },
}
static int dbbu_step(lua_State *L)
Definition lsqlite3.c:1644
static int dbbu_gc(lua_State *L)
Definition lsqlite3.c:1634
static int dbbu_finish(lua_State *L)
Definition lsqlite3.c:1663
static int dbbu_remaining(lua_State *L)
Definition lsqlite3.c:1651
static int dbbu_pagecount(lua_State *L)
Definition lsqlite3.c:1657

Definition at line 2336 of file lsqlite3.c.

2336 {
2337
2338 {"step", dbbu_step },
2339 {"remaining", dbbu_remaining },
2340 {"pagecount", dbbu_pagecount },
2341 {"finish", dbbu_finish },
2342
2343// {"__tostring", dbbu_tostring },
2344 {"__gc", dbbu_gc },
2345 {NULL, NULL}
2346};

Referenced by luaopen_lsqlite3().

◆ dblib

const luaL_Reg dblib[]
static

Definition at line 2224 of file lsqlite3.c.

2224 {
2225 {"isopen", db_isopen },
2226 {"last_insert_rowid", db_last_insert_rowid },
2227 {"changes", db_changes },
2228 {"total_changes", db_total_changes },
2229 {"errcode", db_errcode },
2230 {"error_code", db_errcode },
2231 {"errmsg", db_errmsg },
2232 {"error_message", db_errmsg },
2233 {"interrupt", db_interrupt },
2234 {"db_filename", db_db_filename },
2235
2236 {"create_function", db_create_function },
2237 {"create_aggregate", db_create_aggregate },
2238 {"create_collation", db_create_collation },
2239 {"load_extension", db_load_extension },
2240
2241 {"trace", db_trace },
2242 {"progress_handler", db_progress_handler },
2243 {"busy_timeout", db_busy_timeout },
2244 {"busy_handler", db_busy_handler },
2245#if !defined(LSQLITE_OMIT_UPDATE_HOOK) || !LSQLITE_OMIT_UPDATE_HOOK
2246 {"update_hook", db_update_hook },
2247 {"commit_hook", db_commit_hook },
2248 {"rollback_hook", db_rollback_hook },
2249#endif
2250
2251 {"prepare", db_prepare },
2252 {"rows", db_rows },
2253 {"urows", db_urows },
2254 {"nrows", db_nrows },
2255
2256 {"exec", db_exec },
2257 {"execute", db_exec },
2258 {"close", db_close },
2259 {"close_vm", db_close_vm },
2260 {"get_ptr", db_get_ptr },
2261
2262 {"__tostring", db_tostring },
2263 {"__gc", db_gc },
2264
2265 {NULL, NULL}
2266};
static int db_db_filename(lua_State *L)
Definition lsqlite3.c:933
static int db_rows(lua_State *L)
Definition lsqlite3.c:1960
static int db_busy_timeout(lua_State *L)
Definition lsqlite3.c:1727
static int db_prepare(lua_State *L)
Definition lsqlite3.c:1829
static int db_rollback_hook(lua_State *L)
Definition lsqlite3.c:1450
static int db_create_aggregate(lua_State *L)
Definition lsqlite3.c:1163
static int db_nrows(lua_State *L)
Definition lsqlite3.c:1964
static int db_close(lua_State *L)
Definition lsqlite3.c:1984
static int db_trace(lua_State *L)
Definition lsqlite3.c:1272
static int db_progress_handler(lua_State *L)
Definition lsqlite3.c:1511
static int db_errcode(lua_State *L)
Definition lsqlite3.c:915
static int db_interrupt(lua_State *L)
Definition lsqlite3.c:927
static int db_gc(lua_State *L)
Definition lsqlite3.c:2027
static int db_urows(lua_State *L)
Definition lsqlite3.c:1969
static int db_get_ptr(lua_State *L)
Definition lsqlite3.c:2021
static int db_create_collation(lua_State *L)
Definition lsqlite3.c:1194
static int db_total_changes(lua_State *L)
Definition lsqlite3.c:909
static int db_changes(lua_State *L)
Definition lsqlite3.c:903
static int db_commit_hook(lua_State *L)
Definition lsqlite3.c:1395
static int db_load_extension(lua_State *L)
Definition lsqlite3.c:1222
static int db_close_vm(lua_State *L)
Definition lsqlite3.c:1990
static int db_isopen(lua_State *L)
Definition lsqlite3.c:889
static int db_update_hook(lua_State *L)
Definition lsqlite3.c:1336
static int db_create_function(lua_State *L)
Definition lsqlite3.c:1159
static int db_exec(lua_State *L)
Definition lsqlite3.c:1797
static int db_last_insert_rowid(lua_State *L)
Definition lsqlite3.c:895
static int db_tostring(lua_State *L)
Definition lsqlite3.c:1973
static int db_busy_handler(lua_State *L)
Definition lsqlite3.c:1696
static int db_errmsg(lua_State *L)
Definition lsqlite3.c:921

Referenced by luaopen_lsqlite3().

◆ name

const char* name

Definition at line 2154 of file lsqlite3.c.

Referenced by _file_info_(), aux_upvalue(), aux_upvalue(), aux_upvalue(), auxopen(), auxupvalue(), auxupvalue(), auxupvalue(), auxupvalue(), checkrepeated(), create_meta(), createlabel(), db_getlocal(), db_getlocal(), db_getlocal(), db_getlocal(), db_register_function(), db_setlocal(), db_setlocal(), dbvm_bind_names(), dofile(), dofile(), dofile(), dofile(), dolibrary(), dolibrary(), dolibrary(), dolibrary(), dostring(), dostring(), dostring(), dostring(), duk__declvar_helper(), duk__delvar_helper(), duk__get_identifier_reference(), duk__getid_activation_regs(), duk__getid_open_decl_env_regs(), duk__getvar_helper(), duk__js_execute_bytecode_inner(), duk__putvar_helper(), duk_js_declvar_activation(), duk_js_delvar_activation(), duk_js_getvar_activation(), duk_js_getvar_envrec(), duk_js_putvar_activation(), duk_js_putvar_envrec(), fetch_github_user(), findfile(), findfile(), findfile(), findfile(), findlabel(), findloader(), findloader(), findloader(), findlocal(), findlocal(), findlocal(), funcnamefromcode(), funcnamefromcode(), get_header(), get_option_index(), get_req_headers(), get_system_name(), getfuncname(), getfuncname(), getfuncname(), getfuncname(), getnextfilename(), getobjname(), getobjname(), getobjname(), getobjname(), getupvalname(), getupvalname(), getupvalname(), gotostat(), gxf(), handle_luainit(), handle_luainit(), handle_luainit(), indexupvalue(), init_ssl_ctx(), kname(), kname(), kname(), labelstat(), ll_require(), ll_require(), ll_require(), ll_require(), loader_C(), loader_Croot(), loader_Lua(), loader_preload(), lua_getglobal(), lua_getlocal(), lua_getupvalue(), lua_setglobal(), lua_setlocal(), lua_setupvalue(), luaD_protectedparser(), luaD_protectedparser(), luaG_callerror(), luaG_findlocal(), luaG_typeerror(), luaL_checkoption(), luaL_checkoption(), luaL_loadbuffer(), luaL_loadbufferx(), luaopen_lsqlite3(), luaT_objtypename(), luaU_undump(), luaU_undump(), luaY_parser(), luaY_parser(), mg_get_header(), mg_get_option(), mg_get_system_info(), mg_get_var(), mg_get_var2(), mg_init_library(), mg_set_thread_name(), mg_split_form_urlencoded(), mg_start2(), mg_start_domain2(), new_localvar(), new_localvar(), new_localvar(), new_localvar(), new_localvarliteral_(), new_localvarliteral_(), newgotoentry(), newlabelentry(), newlabelentry(), newlabelentry(), newupvalue(), newupvalue(), newupvalue(), open_auth_file(), parse_auth_header(), print_props(), pushglobalfuncname(), pushglobalfuncname(), doctest::registerReporter(), rkname(), rname(), searcher_C(), searcher_C(), searcher_C(), searcher_Croot(), searcher_Croot(), searcher_Croot(), searcher_Lua(), searcher_Lua(), searcher_Lua(), searcher_preload(), searcher_preload(), searcher_preload(), searchpath(), searchpath(), searchpath(), searchupvalue(), searchupvalue(), searchupvalue(), set_option(), set_ports_option(), show_usage_and_exit(), varinfo(), and varinfo().

◆ sqlite_bu_meta

const char* sqlite_bu_meta = ":sqlite3:bu"
static

Definition at line 126 of file lsqlite3.c.

Referenced by lsqlite_backup_init(), lsqlite_getbu(), and luaopen_lsqlite3().

◆ [struct]

const struct { ... } sqlite_constants[]

Referenced by luaopen_lsqlite3().

◆ sqlite_ctx_meta

const char* sqlite_ctx_meta = ":sqlite3:ctx"
static

Definition at line 127 of file lsqlite3.c.

Referenced by lsqlite_getcontext(), and luaopen_lsqlite3().

◆ sqlite_ctx_meta_ref

int sqlite_ctx_meta_ref
static

Definition at line 128 of file lsqlite3.c.

Referenced by lsqlite_make_context(), and luaopen_lsqlite3().

◆ sqlite_meta

const char* sqlite_meta = ":sqlite3"
static

Definition at line 124 of file lsqlite3.c.

Referenced by lsqlite_getdb(), luaopen_lsqlite3(), and newdb().

◆ sqlite_vm_meta

const char* sqlite_vm_meta = ":sqlite3:vm"
static

Definition at line 125 of file lsqlite3.c.

Referenced by lsqlite_getvm(), luaopen_lsqlite3(), and newvm().

◆ sqlitelib

const luaL_Reg sqlitelib[]
static
Initial value:
= {
{"lversion", lsqlite_lversion },
{"version", lsqlite_version },
{"complete", lsqlite_complete },
{"temp_directory", lsqlite_temp_directory },
{"open", lsqlite_open },
{"open_memory", lsqlite_open_memory },
{"open_ptr", lsqlite_open_ptr },
{"backup_init", lsqlite_backup_init },
{"__newindex", lsqlite_newindex },
}
static int lsqlite_open(lua_State *L)
Definition lsqlite3.c:2092
static int lsqlite_version(lua_State *L)
Definition lsqlite3.c:2040
static int lsqlite_temp_directory(lua_State *L)
Definition lsqlite3.c:2052
static int lsqlite_open_ptr(lua_State *L)
Definition lsqlite3.c:2107
static int lsqlite_backup_init(lua_State *L)
Definition lsqlite3.c:1587
static int lsqlite_newindex(lua_State *L)
Definition lsqlite3.c:2126
static int lsqlite_lversion(lua_State *L)
Definition lsqlite3.c:2139
static int lsqlite_complete(lua_State *L)
Definition lsqlite3.c:2045
static int lsqlite_open_memory(lua_State *L)
Definition lsqlite3.c:2098

Definition at line 2348 of file lsqlite3.c.

2348 {
2349 {"lversion", lsqlite_lversion },
2350 {"version", lsqlite_version },
2351 {"complete", lsqlite_complete },
2352#ifndef _WIN32
2353 {"temp_directory", lsqlite_temp_directory },
2354#endif
2355 {"open", lsqlite_open },
2356 {"open_memory", lsqlite_open_memory },
2357 {"open_ptr", lsqlite_open_ptr },
2358
2359 {"backup_init", lsqlite_backup_init },
2360
2361 {"__newindex", lsqlite_newindex },
2362 {NULL, NULL}
2363};

Referenced by luaopen_sqlitelib().

◆ value

◆ vmlib

const luaL_Reg vmlib[]
static

Definition at line 2268 of file lsqlite3.c.

2268 {
2269 {"isopen", dbvm_isopen },
2270
2271 {"step", dbvm_step },
2272 {"reset", dbvm_reset },
2273 {"finalize", dbvm_finalize },
2274
2275 {"columns", dbvm_columns },
2276
2277 {"bind", dbvm_bind },
2278 {"bind_values", dbvm_bind_values },
2279 {"bind_names", dbvm_bind_names },
2280 {"bind_blob", dbvm_bind_blob },
2281 {"bind_parameter_count",dbvm_bind_parameter_count},
2282 {"bind_parameter_name", dbvm_bind_parameter_name},
2283
2284 {"get_value", dbvm_get_value },
2285 {"get_values", dbvm_get_values },
2286 {"get_name", dbvm_get_name },
2287 {"get_names", dbvm_get_names },
2288 {"get_type", dbvm_get_type },
2289 {"get_types", dbvm_get_types },
2290 {"get_uvalues", dbvm_get_uvalues },
2291 {"get_unames", dbvm_get_unames },
2292 {"get_utypes", dbvm_get_utypes },
2293
2294 {"get_named_values", dbvm_get_named_values },
2295 {"get_named_types", dbvm_get_named_types },
2296
2297 {"rows", dbvm_rows },
2298 {"urows", dbvm_urows },
2299 {"nrows", dbvm_nrows },
2300
2301 {"last_insert_rowid", dbvm_last_insert_rowid },
2302
2303 /* compatibility names (added by request) */
2304 {"idata", dbvm_get_values },
2305 {"inames", dbvm_get_names },
2306 {"itypes", dbvm_get_types },
2307 {"data", dbvm_get_named_values },
2308 {"type", dbvm_get_named_types },
2309
2310 {"__tostring", dbvm_tostring },
2311 {"__gc", dbvm_gc },
2312
2313 { NULL, NULL }
2314};
static int dbvm_bind_values(lua_State *L)
Definition lsqlite3.c:551
static int dbvm_gc(lua_State *L)
Definition lsqlite3.c:276
static int dbvm_bind_blob(lua_State *L)
Definition lsqlite3.c:541
static int dbvm_get_type(lua_State *L)
Definition lsqlite3.c:367
static int dbvm_tostring(lua_State *L)
Definition lsqlite3.c:265
static int dbvm_last_insert_rowid(lua_State *L)
Definition lsqlite3.c:325
static int dbvm_get_types(lua_State *L)
Definition lsqlite3.c:404
static int dbvm_get_named_values(lua_State *L)
Definition lsqlite3.c:455
static int dbvm_get_uvalues(lua_State *L)
Definition lsqlite3.c:418
static int dbvm_step(lua_State *L)
Definition lsqlite3.c:283
static int dbvm_bind_parameter_count(lua_State *L)
Definition lsqlite3.c:514
static int dbvm_get_values(lua_State *L)
Definition lsqlite3.c:375
static int dbvm_finalize(lua_State *L)
Definition lsqlite3.c:295
static int dbvm_get_names(lua_State *L)
Definition lsqlite3.c:390
static int dbvm_columns(lua_State *L)
Definition lsqlite3.c:338
static int dbvm_bind(lua_State *L)
Definition lsqlite3.c:528
static int dbvm_reset(lua_State *L)
Definition lsqlite3.c:300
static int dbvm_nrows(lua_State *L)
Definition lsqlite3.c:1932
static int dbvm_get_named_types(lua_State *L)
Definition lsqlite3.c:471
static int dbvm_rows(lua_State *L)
Definition lsqlite3.c:1928
static int dbvm_get_utypes(lua_State *L)
Definition lsqlite3.c:443
static int dbvm_isopen(lua_State *L)
Definition lsqlite3.c:259
static int dbvm_get_value(lua_State *L)
Definition lsqlite3.c:350
static int dbvm_get_unames(lua_State *L)
Definition lsqlite3.c:431
static int dbvm_bind_names(lua_State *L)
Definition lsqlite3.c:575
static int dbvm_bind_parameter_name(lua_State *L)
Definition lsqlite3.c:520
static int dbvm_get_name(lua_State *L)
Definition lsqlite3.c:359
static int dbvm_urows(lua_State *L)
Definition lsqlite3.c:1936

Referenced by luaopen_lsqlite3().