LuaSQLite3

Check-in [fe6dfc96f6]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add function db:db_filename(name)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: fe6dfc96f60b0adc730891d378fff6ae0e4aafcd
User & Date: e 2016-11-12 21:33:37
References
2016-11-12
21:35 Closed ticket [aca99b99ec]: add the db_filename API function plus 5 other changes artifact: 24121366c8 user: e
Context
2016-11-12
21:42
Update sqlite3 to 3.15.1 check-in: 9a9a8e3156 user: e tags: trunk
21:33
Add function db:db_filename(name) check-in: fe6dfc96f6 user: e tags: trunk
2016-11-05
19:21
Remove older rockspec check-in: 3cf19187bf user: e tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to HISTORY.

1
2
3
4
5
6




7
8
9
10
11
12
13
2016-November-??

Version "0.9.4"

Since the "0.9.3-devel" release of this Lua library...





Added second module 'lsqlite3complete' that statically links sqlite.c. Continue to use 
'lsqlite3' for dynamic linking to 'sqlite3.so' or 'sqlite3.dll'.

Added Online Backup API

Added unit tests for NULs in BLOBs and TEXT columns. (Refute defect report.)







>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2016-November-??

Version "0.9.4"

Since the "0.9.3-devel" release of this Lua library...

Add function db:db_filename(name)

Update sqlite3_open to sqlite3_open_v2 and add open flags constants.

Added second module 'lsqlite3complete' that statically links sqlite.c. Continue to use 
'lsqlite3' for dynamic linking to 'sqlite3.so' or 'sqlite3.dll'.

Added Online Backup API

Added unit tests for NULs in BLOBs and TEXT columns. (Refute defect report.)

Changes to doc/lsqlite3.wiki.

34
35
36
37
38
39
40
41

42
43
44
45
46
47
48
...
494
495
496
497
498
499
500











501
502
503
504
505
506
507
        <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>
		<li><a href="#db_create_function">db:create_function</a></li>
		<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_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>
		<li><a href="#db_nrows">db:nrows</a></li>
		<li><a href="#db_prepare">db:prepare</a></li>
		<li><a href="#db_progress_handler">db:progress_handler</a></li>
        <li><a href="#db_rollback_hook">db:rollback_hook</a></li>
................................................................................
</p>
<h2><a name="db_interrupt">db:interrupt</a></h2>
<pre>
        db:interrupt()</pre>
<p>This function causes any pending database operation to abort and return
at the next opportunity. This function returns nothing.</p>
<p>











</p>
<h2><a name="db_isopen">db:isopen</a></h2>
<pre>
        db:isopen()</pre>
<p>Returns true if database db is open, false otherwise.</p>
<p>
</p>







|
>







 







>
>
>
>
>
>
>
>
>
>
>







34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
...
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
        <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>
		<li><a href="#db_create_function">db:create_function</a></li>
		<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_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>
		<li><a href="#db_nrows">db:nrows</a></li>
		<li><a href="#db_prepare">db:prepare</a></li>
		<li><a href="#db_progress_handler">db:progress_handler</a></li>
        <li><a href="#db_rollback_hook">db:rollback_hook</a></li>
................................................................................
</p>
<h2><a name="db_interrupt">db:interrupt</a></h2>
<pre>
        db:interrupt()</pre>
<p>This function causes any pending database operation to abort and return
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>
<p>Returns true if database db is open, false otherwise.</p>
<p>
</p>

Changes to lsqlite3.c.

925
926
927
928
929
930
931













932
933
934
935
936
937
938
....
2184
2185
2186
2187
2188
2189
2190

2191
2192
2193
2194
2195
2196
2197
}

static int db_interrupt(lua_State *L) {
    sdb *db = lsqlite_checkdb(L, 1);
    sqlite3_interrupt(db->db);
    return 0;
}














/*
** Registering SQL functions:
*/

static void db_push_value(lua_State *L, sqlite3_value *value) {
    switch (sqlite3_value_type(value)) {
................................................................................
    {"changes",             db_changes              },
    {"total_changes",       db_total_changes        },
    {"errcode",             db_errcode              },
    {"error_code",          db_errcode              },
    {"errmsg",              db_errmsg               },
    {"error_message",       db_errmsg               },
    {"interrupt",           db_interrupt            },


    {"create_function",     db_create_function      },
    {"create_aggregate",    db_create_aggregate     },
    {"create_collation",    db_create_collation     },
    {"load_extension",      db_load_extension       },

    {"trace",               db_trace                },







>
>
>
>
>
>
>
>
>
>
>
>
>







 







>







925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
....
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
}

static int db_interrupt(lua_State *L) {
    sdb *db = lsqlite_checkdb(L, 1);
    sqlite3_interrupt(db->db);
    return 0;
}

static int db_db_filename(lua_State *L) {
    sdb *db = lsqlite_checkdb(L, 1);
    const char *db_name = luaL_checkstring(L, 2);
    const char *filename = sqlite3_db_filename(db->db, db_name);
    if (NULL == filename) {
        return 0;
    }
    else {
        lua_pushstring(L, filename);
        return 1;
    }
}

/*
** Registering SQL functions:
*/

static void db_push_value(lua_State *L, sqlite3_value *value) {
    switch (sqlite3_value_type(value)) {
................................................................................
    {"changes",             db_changes              },
    {"total_changes",       db_total_changes        },
    {"errcode",             db_errcode              },
    {"error_code",          db_errcode              },
    {"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     },
    {"create_collation",    db_create_collation     },
    {"load_extension",      db_load_extension       },

    {"trace",               db_trace                },

Changes to test/tests-sqlite3.lua.

1199
1200
1201
1202
1203
1204
1205
1206




























1207
1208
end

function db_bu_null.test()

  local bu = assert_nil( sqlite3.backup_init(db_bu_null.db, 'main', db_bu_null.db, 'main') )

end





























lunit.main()









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
end

function db_bu_null.test()

  local bu = assert_nil( sqlite3.backup_init(db_bu_null.db, 'main', db_bu_null.db, 'main') )

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") )

end


lunit.main()