Skip to content

Commit

Permalink
Modify the sqltclsh startup script to look for a properly formatted
Browse files Browse the repository at this point in the history
SQLAR at the end of the executable.  Fix the CLI so that it automatically
links against appendvfs and so that the --append command-line option works.
  • Loading branch information
D. Richard Hipp committed Jan 7, 2018
1 parent 1f0c90d commit 20e2e07
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@ keywordhash.h: $(TOP)/tool/mkkeywordhash.c
# Source files that go into making shell.c
SHELL_SRC = \
$(TOP)/src/shell.c.in \
$(TOP)/ext/misc/appendvfs.c \
$(TOP)/ext/misc/shathree.c \
$(TOP)/ext/misc/fileio.c \
$(TOP)/ext/misc/completion.c \
Expand Down
1 change: 1 addition & 0 deletions Makefile.msc
Original file line number Diff line number Diff line change
Expand Up @@ -2083,6 +2083,7 @@ keywordhash.h: $(TOP)\tool\mkkeywordhash.c mkkeywordhash.exe
# Source files that go into making shell.c
SHELL_SRC = \
$(TOP)\src\shell.c.in \
$(TOP)\ext\misc\appendvfs.c \
$(TOP)\ext\misc\shathree.c \
$(TOP)\ext\misc\fileio.c \
$(TOP)\ext\misc\completion.c \
Expand Down
4 changes: 1 addition & 3 deletions ext/misc/appendvfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@
** If the file being opened is not an appended database, then this shim is
** a pass-through into the default underlying VFS.
**/
#if !defined(SQLITEINT_H)
#include <sqlite3ext.h>
#endif
#include "sqlite3ext.h"
SQLITE_EXTENSION_INIT1
#include <string.h>
#include <assert.h>
Expand Down
1 change: 1 addition & 0 deletions main.mk
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ keywordhash.h: $(TOP)/tool/mkkeywordhash.c
# Source files that go into making shell.c
SHELL_SRC = \
$(TOP)/src/shell.c.in \
$(TOP)/ext/misc/appendvfs.c \
$(TOP)/ext/misc/shathree.c \
$(TOP)/ext/misc/fileio.c \
$(TOP)/ext/misc/completion.c \
Expand Down
8 changes: 8 additions & 0 deletions src/shell.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@ INCLUDE test_windirent.c
INCLUDE ../ext/misc/shathree.c
INCLUDE ../ext/misc/fileio.c
INCLUDE ../ext/misc/completion.c
INCLUDE ../ext/misc/appendvfs.c
#ifdef SQLITE_HAVE_ZLIB
INCLUDE ../ext/misc/zipfile.c
INCLUDE ../ext/misc/sqlar.c
Expand Down Expand Up @@ -7952,6 +7953,12 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
utf8_printf(stderr, "no such VFS: \"%s\"\n", argv[i]);
exit(1);
}
#ifdef SQLITE_HAVE_ZIP
}else if( strcmp(z,"-zip")==0 ){
data.openMode = SHELL_OPEN_ZIPFILE;
#endif
}else if( strcmp(z,"-append")==0 ){
data.openMode = SHELL_OPEN_APPENDVFS;
}
}
if( data.zDbFilename==0 ){
Expand All @@ -7964,6 +7971,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
#endif
}
data.out = stdout;
sqlite3_appendvfs_init(0,0,0);

/* Go ahead and open the database file if it already exists. If the
** file does not exist, delay opening it. This prevents empty database
Expand Down
5 changes: 5 additions & 0 deletions tool/sqltclsh.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@
#define SQLITE_MAX_EXPR_DEPTH 0
INCLUDE sqlite3.c
INCLUDE $ROOT/ext/misc/appendvfs.c
INCLUDE $ROOT/ext/misc/zipfile.c
INCLUDE $ROOT/ext/misc/sqlar.c
INCLUDE $ROOT/src/tclsqlite.c

const char *sqlite3_tclapp_init_proc(Tcl_Interp *interp){
(void)interp;
sqlite3_appendvfs_init(0,0,0);
sqlite3_auto_extension((void(*)(void))sqlite3_sqlar_init);
sqlite3_auto_extension((void(*)(void))sqlite3_zipfile_init);

return
BEGIN_STRING
INCLUDE $ROOT/tool/sqltclsh.tcl
Expand Down
4 changes: 3 additions & 1 deletion tool/sqltclsh.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ catch {
append argv0 .exe
}
sqlite3 db $argv0 -vfs apndvfs -create 0
set mainscript [db one {SELECT data FROM scripts WHERE name='main.tcl'}]
set mainscript [db one {
SELECT sqlar_uncompress(data,sz) FROM sqlar WHERE name='main.tcl'
}]
}
if {[info exists mainscript]} {
eval $mainscript
Expand Down

0 comments on commit 20e2e07

Please sign in to comment.