diff options
Diffstat (limited to '3rdparty/lsqlite3')
-rw-r--r-- | 3rdparty/lsqlite3/HISTORY | 15 | ||||
-rw-r--r-- | 3rdparty/lsqlite3/README | 12 | ||||
-rw-r--r-- | 3rdparty/lsqlite3/doc/lsqlite3.wiki | 64 | ||||
-rw-r--r-- | 3rdparty/lsqlite3/lsqlite3-0.9.5-1.rockspec (renamed from 3rdparty/lsqlite3/lsqlite3-0.9.4-0.rockspec) | 24 | ||||
-rw-r--r-- | 3rdparty/lsqlite3/lsqlite3.c | 88 | ||||
-rw-r--r-- | 3rdparty/lsqlite3/lsqlite3complete-0.9.5-1.rockspec | 40 | ||||
-rw-r--r-- | 3rdparty/lsqlite3/test/test.lua | 2 | ||||
-rw-r--r-- | 3rdparty/lsqlite3/test/tests-sqlite3.lua | 40 |
8 files changed, 235 insertions, 50 deletions
diff --git a/3rdparty/lsqlite3/HISTORY b/3rdparty/lsqlite3/HISTORY index 0fa8e7bdc92..bd9103955dc 100644 --- a/3rdparty/lsqlite3/HISTORY +++ b/3rdparty/lsqlite3/HISTORY @@ -1,9 +1,22 @@ -2016-November-?? +2018-June-30 + +Version "0.9.5" + +Since the "0.9.4-devel" release of this Lua library... + +Lua 5.4 compatibility (backward compatible with Lua 5.3, 5.2, and Lua 5.1.5). + +2016-November-13 Version "0.9.4" Since the "0.9.3-devel" release of this Lua library... +Add functions db:get_ptr() and sqlite3.open_ptr(db_ptr) to pass a db connection between threads. +Add function db:db_filename(name). +Update sqlite3_open to sqlite3_open_v2 and add open flags constants. +Thanks to Wolfgang Oertl! + Added second module 'lsqlite3complete' that statically links sqlite.c. Continue to use 'lsqlite3' for dynamic linking to 'sqlite3.so' or 'sqlite3.dll'. diff --git a/3rdparty/lsqlite3/README b/3rdparty/lsqlite3/README index 92c27b2770b..a7751bce130 100644 --- a/3rdparty/lsqlite3/README +++ b/3rdparty/lsqlite3/README @@ -1,8 +1,16 @@ -LuaSQLite 3 provides a means to manipulate SQLite3 +LuaSQLite3 provides a means to manipulate SQLite3 databases directly from lua using Lua 5. -To use this library you need SQLite3 library. +There are two modules, identical except that one links +SQLite3 dynamically, the other statically. + +The module lsqlite3 links SQLite3 dynamically. +To use this module you need the SQLite3 library. You can get it from http://www.sqlite.org/ +The module lsqlite3complete links SQLite3 statically. +The SQLite3 amalgamation source code is included in +the LuaSQLite3 distribution. + Lua 5 is available from http://www.lua.org/ diff --git a/3rdparty/lsqlite3/doc/lsqlite3.wiki b/3rdparty/lsqlite3/doc/lsqlite3.wiki index 083959f152f..baa2bed76e1 100644 --- a/3rdparty/lsqlite3/doc/lsqlite3.wiki +++ b/3rdparty/lsqlite3/doc/lsqlite3.wiki @@ -18,6 +18,7 @@ <li><a href="#sqlite3_lversion">sqlite3.lversion</a></li> <li><a href="#sqlite3_open">sqlite3.open</a></li> <li><a href="#sqlite3_open_memory">sqlite3.open_memory</a></li> + <li><a href="#sqlite3_open_ptr">sqlite3.open_ptr</a></li> <li><a href="#sqlite3_backup_init">sqlite3.backup_init</a></li> <li><a href="#sqlite3_temp_directory">sqlite3.temp_directory</a></li> <li><a href="#sqlite3_version">sqlite3.version</a></li> @@ -31,6 +32,7 @@ <li><a href="#db_changes">db:changes</a></li> <li><a href="#db_close">db:close</a></li> <li><a href="#db_close_vm">db:close_vm</a></li> + <li><a href="#db_get_ptr">db:get_ptr</a></li> <li><a href="#db_commit_hook">db:commit_hook</a></li> <li><a href="#db_create_aggregate">db:create_aggregate</a></li> <li><a href="#db_create_collation">db:create_collation</a></li> @@ -38,7 +40,8 @@ <li><a href="#db_errcode">db:errcode</a></li> <li><a href="#db_errmsg">db:errmsg</a></li> <li><a href="#db_exec">db:exec</a></li> - <li><a href="#db_interrupt">db:interrupt</a></li> + <li><a href="#db_interrupt">db:interrupt</a></li> + <li><a href="#db_db_filename">db:db_filename</a></li> <li><a href="#db_isopen">db:isopen</a></li> <li><a href="#db_last_insert_rowid">db:last_insert_rowid</a></li> <li><a href="#db_load_extension">db:load_extension</a></li> @@ -129,8 +132,18 @@ <h1><a name="overview">OVERVIEW</a></h1> <p><strong>LuaSQLite 3</strong> is a thin wrapper around the public domain SQLite3 database engine.</p> -<p>The <code>lsqlite3</code> module supports the creation and manipulation of -SQLite3 databases. After a <code>sqlite3 = require('lsqlite3')</code> the exported +<p>There are two modules, identical except that one links SQLite3 dynamically, the other +statically.</p> +<p>The module <code>lsqlite3</code> links SQLite3 dynamically. +To use this module you need the SQLite3 library (DLL or .so). +You can get it from <a href="http://www.sqlite.org/">http://www.sqlite.org/</a> +</p> +<p>The module <code>lsqlite3complete</code> links SQLite3 statically. +The SQLite3 amalgamation source code is included in +the LuaSQLite 3 distribution.</p> +<p>Both modules support the creation and manipulation of +SQLite3 databases. After a <code>sqlite3 = require('lsqlite3')</code> +(or <code>sqlite3 = require('lsqlite3complete')</code>) the exported functions are called with prefix <code>sqlite3</code>. However, most sqlite3 functions are called via an object-oriented interface to either database or SQL statement objects; see below for details.</p> @@ -138,7 +151,9 @@ database or SQL statement objects; see below for details.</p> works, it just describes the Lua binding and the available functions. For more information about the SQL features supported by SQLite3 and details about the syntax of SQL statements and queries, please see the -<strong>SQLite3 documentation</strong> <a href="http://www.sqlite.org/">http://www.sqlite.org/</a>. Using some of the +<strong>SQLite3 documentation</strong> +<a href="http://www.sqlite.org/">http://www.sqlite.org/</a>. +Using some of the advanced features (how to use callbacks, for instance) will require some familiarity with the SQLite3 API.</p> <p> @@ -147,15 +162,18 @@ some familiarity with the SQLite3 API.</p> <h1><a name="download">DOWNLOAD</a></h1> <p><strong>LuaSQLite 3</strong> source code can be downloaded from its Fossil (<a href="http://lua.sqlite.org/">http://lua.sqlite.org/</a>) page.</p> -<p>You will also need to build or obtain an SQLite3 loadable library -(DLL or .so). See <a href="http://www.sqlite.org/">http://www.sqlite.org/</a> for obtaining SQLite3 +<p>For <code>lsqlite3</code> (but not for <code>lsqlite3complete</code>) you will also need to +build or obtain an SQLite3 loadable library (DLL or .so). +See <a href="http://www.sqlite.org/">http://www.sqlite.org/</a> for obtaining SQLite3 source code or downloading a binary SQLite3 library.</p> <p> </p> <hr /> <h1><a name="installation">INSTALLATION</a></h1> <p>Luarocks (<a href="http://luarocks.org/">http://luarocks.org/</a>) is the preferred mechanism -to build and install <code>lsqlite3</code>; it assumes an SQLite3 library is already installed.</p> +to build and install <code>lsqlite3</code> or <code>lsqlite3complete</code>; for +<code>lsqlite3</code> it assumes an SQLite3 library is already installed. For +<code>lsqlite3complete</code> no SQLite3 library is needed.</p> <p> </p> <hr /> @@ -171,7 +189,7 @@ an enhanced version of Michael Roth's <code>lunit</code> called <code>lunitx</co tests were also derived from Michael's <strong>lua-sqlite3</strong> module, and more unit tests added by Doug Currie. Get <code>lunitx</code> using Luarocks.</p> <p>The distribution also contains some functional tests by Tiago.</p> -<p>This version of <code>lsqlite3</code> was tested with SQLite 3.11.0 and 3.15.0.</p> +<p>This version of <code>lsqlite3</code> was tested with SQLite 3.11.0 and 3.15.1.</p> <p> </p> <hr /> @@ -225,7 +243,14 @@ and an error message. (In-memory databases are volatile as they are never stored on disk.)</p> <p> </p> - +<h2><a name="sqlite3_open_ptr">sqlite3.open_ptr</a></h2> +<pre> + sqlite3.open_ptr(db_ptr)</pre> +<p>Opens the SQLite database corresponding to the light userdata <code>db_ptr</code> and returns +its handle as userdata. Use <a href="#db_get_ptr"><code>db:get_ptr</code></a> to get +a <code>db_ptr</code> for an open database.</p> +<p> +</p> <h2><a name="sqlite3_backup_init">sqlite3.backup_init</a></h2> <pre> sqlite3.backup_init(target_db, target_name, source_db, source_name)</pre> @@ -325,6 +350,16 @@ have been finalized before this function is called. The function returns This function returns nothing.</p> <p> </p> +<h2><a name="db_get_ptr">db:get_ptr</a></h2> +<pre> + db:get_ptr()</pre> +<p>Returns a lightuserdata corresponding to the open <code>db</code>. Use with +<a href="#sqlite3_open_ptr"><code>sqlite3.open_ptr</code></a> to pass a database connection +between threads. (When using lsqlite3 in a multithreaded environment, each thread has a separate +Lua environment; full userdata structures can't be passed from one thread to another, but this +is possible with lightuserdata.)</p> +<p> +</p> <h2><a name="db_commit_hook">db:commit_hook</a></h2> <pre> db:commit_hook(func,udata)</pre> @@ -499,6 +534,17 @@ all subsequent SQL statements are skipped and <code>db:exec()</code> returns at the next opportunity. This function returns nothing.</p> <p> </p> +<h2><a name="db_db_filename">db:db_filename</a></h2> +<pre> + db:db_filename(name)</pre> +<p>This function returns the filename associated with database <code>name</code> of connection +<code>db</code>. The <code>name</code> may be "main" for the main database file, or +the name specified after the AS keyword in an ATTACH statement for an attached database. +If there is no attached database <code>name</code> on the database connection <code>db</code>, +then no value is returned; if database <code>name</code> is a temporary or in-memory database, +then an empty string is returned.</p> +<p> +</p> <h2><a name="db_isopen">db:isopen</a></h2> <pre> db:isopen()</pre> diff --git a/3rdparty/lsqlite3/lsqlite3-0.9.4-0.rockspec b/3rdparty/lsqlite3/lsqlite3-0.9.5-1.rockspec index 4d7a2dabb70..b5d2c85df04 100644 --- a/3rdparty/lsqlite3/lsqlite3-0.9.4-0.rockspec +++ b/3rdparty/lsqlite3/lsqlite3-0.9.5-1.rockspec @@ -1,23 +1,23 @@ package = "lsqlite3" -version = "0.9.4-0" +version = "0.9.5-1" source = { - url = "http://lua.sqlite.org/index.cgi/zip/lsqlite3_fsl09x.zip?uuid=fsl_9x", - file = "lsqlite3_fsl09x.zip" + url = "http://lua.sqlite.org/index.cgi/zip/lsqlite3_fsl09y.zip?uuid=fsl_9y", + file = "lsqlite3_fsl09y.zip" } description = { summary = "A binding for Lua to the SQLite3 database library", detailed = [[ - lsqlite3 is a thin wrapper around the public domain SQLite3 database engine. + lsqlite3 is a thin wrapper around the public domain SQLite3 database engine. SQLite3 is + dynamically linked to lsqlite3. The statically linked alternative is lsqlite3complete. The lsqlite3 module supports the creation and manipulation of SQLite3 databases. - After a require('lsqlite3') the exported functions are called with prefix sqlite3. - However, most sqlite3 functions are called via an object-oriented interface to - either database or SQL statement objects. + Most sqlite3 functions are called via an object-oriented interface to either + database or SQL statement objects. ]], - license = "MIT/X11", + license = "MIT", homepage = "http://lua.sqlite.org/" } dependencies = { - "lua >= 5.1, < 5.4" + "lua >= 5.1, < 5.5" } external_dependencies = { SQLITE = { @@ -29,15 +29,11 @@ build = { modules = { lsqlite3 = { sources = { "lsqlite3.c" }, - defines = {'LSQLITE_VERSION="0.9.4"'}, + defines = {'LSQLITE_VERSION="0.9.5"'}, libraries = { "sqlite3" }, incdirs = { "$(SQLITE_INCDIR)" }, libdirs = { "$(SQLITE_LIBDIR)" } }, - lsqlite3complete = { - sources = { "lsqlite3.c", "sqlite3.c" }, - defines = {'LSQLITE_VERSION="0.9.4"', 'luaopen_lsqlite3=luaopen_lsqlite3complete'} - } }, copy_directories = { 'doc', 'examples' } } diff --git a/3rdparty/lsqlite3/lsqlite3.c b/3rdparty/lsqlite3/lsqlite3.c index 483bbf8deae..2b8959573de 100644 --- a/3rdparty/lsqlite3/lsqlite3.c +++ b/3rdparty/lsqlite3/lsqlite3.c @@ -31,18 +31,20 @@ #include <assert.h> #define LUA_LIB -#include <lua.h> -#include <lauxlib.h> +#include "lua.h" +#include "lauxlib.h" #if LUA_VERSION_NUM > 501 /* ** Lua 5.2 */ -//#define lua_strlen lua_rawlen +#ifndef lua_strlen +#define lua_strlen lua_rawlen +#endif /* luaL_typerror always used with arg at ndx == NULL */ #define luaL_typerror(L,ndx,str) luaL_error(L,"bad argument %d (%s expected, got nil)",ndx,str) /* luaL_register used once, so below expansion is OK for this case */ -//#define luaL_register(L,name,reg) lua_newtable(L);luaL_setfuncs(L,reg,0) +#define luaL_register(L,name,reg) lua_newtable(L);luaL_setfuncs(L,reg,0) /* luaL_openlib always used with name == NULL */ #define luaL_openlib(L,name,reg,nup) luaL_setfuncs(L,reg,nup) @@ -54,7 +56,7 @@ #endif #endif -#include <sqlite3.h> +#include "sqlite3.h" /* compile time features */ #if !defined(SQLITE_OMIT_PROGRESS_CALLBACK) @@ -173,7 +175,7 @@ static void vm_push_column(lua_State *L, sqlite3_stmt *vm, int idx) { lua_pushlstring(L, (const char*)sqlite3_column_text(vm, idx), sqlite3_column_bytes(vm, idx)); break; case SQLITE_BLOB: - lua_pushlstring(L, sqlite3_column_blob(vm, idx), sqlite3_column_bytes(vm, idx)); + lua_pushlstring(L, (const char*)sqlite3_column_blob(vm, idx), sqlite3_column_bytes(vm, idx)); break; case SQLITE_NULL: lua_pushnil(L); @@ -665,7 +667,7 @@ static int cleanupdb(lua_State *L, sdb *db) { top = lua_gettop(L); lua_pushnil(L); while (lua_next(L, -2)) { - sdb_vm *svm = lua_touserdata(L, -2); /* key: vm; val: sql text */ + sdb_vm *svm = (sdb_vm*)lua_touserdata(L, -2); /* key: vm; val: sql text */ cleanupvm(L, svm); lua_settop(L, top); @@ -930,6 +932,14 @@ static int db_interrupt(lua_State *L) { return 0; } +static int db_db_filename(lua_State *L) { + sdb *db = lsqlite_checkdb(L, 1); + const char *db_name = luaL_checkstring(L, 2); + // sqlite3_db_filename may return NULL, in that case Lua pushes nil... + lua_pushstring(L, sqlite3_db_filename(db->db, db_name)); + return 1; +} + /* ** Registering SQL functions: */ @@ -951,7 +961,7 @@ static void db_push_value(lua_State *L, sqlite3_value *value) { break; case SQLITE_BLOB: - lua_pushlstring(L, sqlite3_value_blob(value), sqlite3_value_bytes(value)); + lua_pushlstring(L, (const char*)sqlite3_value_blob(value), sqlite3_value_bytes(value)); break; case SQLITE_NULL: @@ -1169,9 +1179,9 @@ static int collwrapper(scc *co,int l1,const void *p1, int res=0; lua_State *L=co->L; lua_rawgeti(L,LUA_REGISTRYINDEX,co->ref); - lua_pushlstring(L,p1,l1); - lua_pushlstring(L,p2,l2); - if (lua_pcall(L,2,1,0)==0) res=lua_tonumber(L,-1); + lua_pushlstring(L,(const char*)p1,l1); + lua_pushlstring(L,(const char*)p2,l2); + if (lua_pcall(L,2,1,0)==0) res=(int)lua_tonumber(L,-1); lua_pop(L,1); return res; } @@ -1307,7 +1317,7 @@ static void db_update_hook_callback(void *user, int op, char const *dbname, char sdb *db = (sdb*)user; lua_State *L = db->L; int top = lua_gettop(L); - //lua_Number n; + lua_Number n; /* setup lua callback call */ lua_rawgeti(L, LUA_REGISTRYINDEX, db->update_hook_cb); /* get callback */ @@ -1991,7 +2001,7 @@ static int db_close_vm(lua_State *L) { /* close all used handles */ lua_pushnil(L); while (lua_next(L, -2)) { - sdb_vm *svm = lua_touserdata(L, -2); /* key: vm; val: sql text */ + sdb_vm *svm = (sdb_vm*)lua_touserdata(L, -2); /* key: vm; val: sql text */ if ((!temp || svm->temp) && svm->vm) { @@ -2005,6 +2015,17 @@ static int db_close_vm(lua_State *L) { return 0; } +/* From: Wolfgang Oertl +When using lsqlite3 in a multithreaded environment, each thread has a separate Lua +environment, but full userdata structures can't be passed from one thread to another. +This is possible with lightuserdata, however. See: lsqlite_open_ptr(). +*/ +static int db_get_ptr(lua_State *L) { + sdb *db = lsqlite_checkdb(L, 1); + lua_pushlightuserdata(L, db->db); + return 1; +} + static int db_gc(lua_State *L) { sdb *db = lsqlite_getdb(L, 1); if (db->db != NULL) /* ignore closed databases */ @@ -2029,7 +2050,7 @@ static int lsqlite_complete(lua_State *L) { return 1; } -#ifndef WIN32 +#ifndef _WIN32 static int lsqlite_temp_directory(lua_State *L) { const char *oldtemp = sqlite3_temp_directory; @@ -2080,6 +2101,30 @@ static int lsqlite_open_memory(lua_State *L) { return lsqlite_do_open(L, ":memory:", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE); } +/* From: Wolfgang Oertl +When using lsqlite3 in a multithreaded environment, each thread has a separate Lua +environment, but full userdata structures can't be passed from one thread to another. +This is possible with lightuserdata, however. See: db_get_ptr(). +*/ +static int lsqlite_open_ptr(lua_State *L) { + sqlite3 *db_ptr; + sdb *db; + int rc; + + luaL_checktype(L, 1, LUA_TLIGHTUSERDATA); + db_ptr = (sqlite3*)lua_touserdata(L, 1); + /* This is the only API function that runs sqlite3SafetyCheck regardless of + * SQLITE_ENABLE_API_ARMOR and does almost nothing (without an SQL + * statement) */ + rc = sqlite3_exec(db_ptr, NULL, NULL, NULL, NULL); + if (rc != SQLITE_OK) + luaL_argerror(L, 1, "not a valid SQLite3 pointer"); + + db = newdb(L); /* create and leave in stack */ + db->db = db_ptr; + return 1; +} + static int lsqlite_newindex(lua_State *L) { lua_pushliteral(L, "attempt to change readonly table"); lua_error(L); @@ -2188,6 +2233,7 @@ static const luaL_Reg dblib[] = { {"errmsg", db_errmsg }, {"error_message", db_errmsg }, {"interrupt", db_interrupt }, + {"db_filename", db_db_filename }, {"create_function", db_create_function }, {"create_aggregate", db_create_aggregate }, @@ -2213,6 +2259,7 @@ static const luaL_Reg dblib[] = { {"execute", db_exec }, {"close", db_close }, {"close_vm", db_close_vm }, + {"get_ptr", db_get_ptr }, {"__tostring", db_tostring }, {"__gc", db_gc }, @@ -2304,11 +2351,12 @@ static const luaL_Reg sqlitelib[] = { {"lversion", lsqlite_lversion }, {"version", lsqlite_version }, {"complete", lsqlite_complete }, -#ifndef WIN32 +#ifndef _WIN32 {"temp_directory", lsqlite_temp_directory }, #endif {"open", lsqlite_open }, {"open_memory", lsqlite_open_memory }, + {"open_ptr", lsqlite_open_ptr }, {"backup_init", lsqlite_backup_init }, @@ -2329,12 +2377,6 @@ static void create_meta(lua_State *L, const char *name, const luaL_Reg *lib) { lua_pop(L, 1); } -static int luaopen_sqlite3 ( lua_State * L ) -{ - luaL_newlib(L, sqlitelib); - return 1; -} - LUALIB_API int luaopen_lsqlite3(lua_State *L) { create_meta(L, sqlite_meta, dblib); create_meta(L, sqlite_vm_meta, vmlib); @@ -2345,8 +2387,8 @@ LUALIB_API int luaopen_lsqlite3(lua_State *L) { sqlite_ctx_meta_ref = luaL_ref(L, LUA_REGISTRYINDEX); /* register (local) sqlite metatable */ - //luaL_register(L, "sqlite3", sqlitelib); - luaL_requiref(L, "sqlite3", luaopen_sqlite3, 1); + luaL_register(L, "sqlite3", sqlitelib); + { int i = 0; /* add constants to global table */ diff --git a/3rdparty/lsqlite3/lsqlite3complete-0.9.5-1.rockspec b/3rdparty/lsqlite3/lsqlite3complete-0.9.5-1.rockspec new file mode 100644 index 00000000000..c71c6365c11 --- /dev/null +++ b/3rdparty/lsqlite3/lsqlite3complete-0.9.5-1.rockspec @@ -0,0 +1,40 @@ +package = "lsqlite3complete" +version = "0.9.5-1" +source = { + url = "http://lua.sqlite.org/index.cgi/zip/lsqlite3_fsl09y.zip?uuid=fsl_9y", + file = "lsqlite3_fsl09y.zip" +} +description = { + summary = "A binding for Lua to the SQLite3 database library", + detailed = [[ + lsqlite3complete is a thin wrapper around the public domain SQLite3 database engine. + SQLite3 is included and statically linked. (The dynamically linked alternative is lsqlite3). + The lsqlite3complete module supports the creation and manipulation of SQLite3 databases. + Most sqlite3 functions are called via an object-oriented interface to either database + or SQL statement objects. + ]], + license = "MIT", + homepage = "http://lua.sqlite.org/" +} +dependencies = { + "lua >= 5.1, < 5.5" +} +build = { + type = "builtin", + modules = { + lsqlite3complete = { + sources = { "lsqlite3.c", "sqlite3.c" }, + defines = {'LSQLITE_VERSION="0.9.5"', 'luaopen_lsqlite3=luaopen_lsqlite3complete'} + }, + }, + platforms = { + unix = { + modules = { + lsqlite3complete = { + libraries = { "pthread", "m", "dl" } + } + } + } + }, + copy_directories = { 'doc', 'examples' } +} diff --git a/3rdparty/lsqlite3/test/test.lua b/3rdparty/lsqlite3/test/test.lua index e5e3bfa35f2..e94b957a89c 100644 --- a/3rdparty/lsqlite3/test/test.lua +++ b/3rdparty/lsqlite3/test/test.lua @@ -44,7 +44,7 @@ line("select * from t", 'db:exec') assert(db:exec('select * from t', function (ud, ncols, values, names) --table.setn(values, 2) - print(table.unpack(values)) + print((unpack or table.unpack)(values)) return sqlite3.OK end) == sqlite3.OK) diff --git a/3rdparty/lsqlite3/test/tests-sqlite3.lua b/3rdparty/lsqlite3/test/tests-sqlite3.lua index 4a276b0bc29..125ec22b3f6 100644 --- a/3rdparty/lsqlite3/test/tests-sqlite3.lua +++ b/3rdparty/lsqlite3/test/tests-sqlite3.lua @@ -1204,5 +1204,45 @@ function db_bu_null.test() end +-------------------------------------- +-- Functions added 2016-11-xx 0.9.4 -- +-------------------------------------- + +r094 = lunit_TestCase("Functions added 0.9.4") + +function r094.setup() + r094.db = assert( sqlite3.open_memory() ) + r094.filename = "/tmp/__lua-sqlite3-20161112163049." .. os.time() + r094.db_fn = assert_userdata( sqlite3.open(r094.filename) ) +end + +function r094.teardown() + assert_number( r094.db:close() ) + assert_number( r094.db_fn:close() ) +end + +function r094.test_db_filename() + + assert_nil( r094.db:db_filename("frob") ) + assert_equal( '', r094.db:db_filename("main") ) + + assert_nil( r094.db_fn:db_filename("frob") ) + assert_equal( r094.filename, r094.db_fn:db_filename("main") ) + + -- from Wolfgang Oertl + local db_ptr = assert_userdata( r094.db:get_ptr() ) + local db2 = assert_userdata( sqlite3.open_ptr(db_ptr) ) + -- do something via connection 1 + r094.db:exec("CREATE TABLE test1(a, b)") + r094.db:exec("INSERT INTO test1 VALUES(1, 2)") + -- see result via connection 2 + for a, b in db2:urows("SELECT * FROM test1 ORDER BY a") do + assert_equal(a, 1) + assert_equal(b, 2) + end + assert_number( db2:close() ) + +end + lunit.main() |