diff options
author | drh <drh@noemail.net> | 2018-10-30 13:19:49 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2018-10-30 13:19:49 +0000 |
commit | 60f34ae09128bfe2ccd9574d1663102933ab1f1e (patch) | |
tree | 0fae58fd8f46f1ee4ab0ef3cff9e8877eed2a5b1 /src | |
parent | f4452cfbed0627f3eb09b59a5cf8ecc03509ff4f (diff) | |
download | sqlite-60f34ae09128bfe2ccd9574d1663102933ab1f1e.tar.gz sqlite-60f34ae09128bfe2ccd9574d1663102933ab1f1e.zip |
Enable sqlite3_deserialize() in the CLI. The --deserialize option associated
with opening a new database cause the database file to be read into memory
and accessed using the sqlite3_deserialize() API. This simplifies running
tests on a database without risk of modifying the file on disk.
FossilOrigin-Name: 5e0129ee9afa7c2d707f8ac9e29ef3583c49bb1d0965085c067d58f828ac8cdf
Diffstat (limited to 'src')
-rw-r--r-- | src/shell.c.in | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/src/shell.c.in b/src/shell.c.in index e70e2939b..73a649410 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -1059,11 +1059,12 @@ struct ShellState { /* Allowed values for ShellState.openMode */ -#define SHELL_OPEN_UNSPEC 0 /* No open-mode specified */ -#define SHELL_OPEN_NORMAL 1 /* Normal database file */ -#define SHELL_OPEN_APPENDVFS 2 /* Use appendvfs */ -#define SHELL_OPEN_ZIPFILE 3 /* Use the zipfile virtual table */ -#define SHELL_OPEN_READONLY 4 /* Open a normal database read-only */ +#define SHELL_OPEN_UNSPEC 0 /* No open-mode specified */ +#define SHELL_OPEN_NORMAL 1 /* Normal database file */ +#define SHELL_OPEN_APPENDVFS 2 /* Use appendvfs */ +#define SHELL_OPEN_ZIPFILE 3 /* Use the zipfile virtual table */ +#define SHELL_OPEN_READONLY 4 /* Open a normal database read-only */ +#define SHELL_OPEN_DESERIALIZE 5 /* Open using sqlite3_deserialize() */ /* ** These are the allowed shellFlgs values @@ -3432,10 +3433,11 @@ static const char *(azHelp[]) = { " -x Open in a spreadsheet", ".open ?OPTIONS? ?FILE? Close existing database and reopen FILE", " Options:", - " --append Use appendvfs to append database to the end of FILE", - " --new Initialize FILE to an empty database", - " --readonly Open FILE readonly", - " --zip FILE is a ZIP archive", + " --append Use appendvfs to append database to the end of FILE", + " --deserialize Load into memory useing sqlite3_deserialize()", + " --new Initialize FILE to an empty database", + " --readonly Open FILE readonly", + " --zip FILE is a ZIP archive", ".output ?FILE? Send output to FILE or stdout if FILE is omitted", " If FILE begins with '|' then open it as a pipe.", ".print STRING... Print literal STRING", @@ -3724,6 +3726,10 @@ static void open_db(ShellState *p, int openFlags){ SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, "apndvfs"); break; } + case SHELL_OPEN_DESERIALIZE: { + sqlite3_open(0, &p->db); + break; + } case SHELL_OPEN_ZIPFILE: { sqlite3_open(":memory:", &p->db); break; @@ -3772,6 +3778,15 @@ static void open_db(ShellState *p, int openFlags){ "CREATE VIRTUAL TABLE zip USING zipfile(%Q);", p->zDbFilename); sqlite3_exec(p->db, zSql, 0, 0, 0); sqlite3_free(zSql); + }else if( p->openMode==SHELL_OPEN_DESERIALIZE ){ + int nData = 0; + unsigned char *aData = (unsigned char*)readFile(p->zDbFilename, &nData); + int rc = sqlite3_deserialize(p->db, "main", aData, nData, nData, + SQLITE_DESERIALIZE_RESIZEABLE | + SQLITE_DESERIALIZE_FREEONCLOSE); + if( rc ){ + utf8_printf(stderr, "Error: sqlite3_deserialize() returns %d\n", rc); + } } } } @@ -6653,6 +6668,8 @@ static int do_meta_command(char *zLine, ShellState *p){ p->openMode = SHELL_OPEN_APPENDVFS; }else if( optionMatch(z, "readonly") ){ p->openMode = SHELL_OPEN_READONLY; + }else if( optionMatch(z, "deserialize") ){ + p->openMode = SHELL_OPEN_DESERIALIZE; }else if( z[0]=='-' ){ utf8_printf(stderr, "unknown option: %s\n", z); rc = 1; @@ -8621,6 +8638,8 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ #endif }else if( strcmp(z,"-append")==0 ){ data.openMode = SHELL_OPEN_APPENDVFS; + }else if( strcmp(z,"-deserialize")==0 ){ + data.openMode = SHELL_OPEN_DESERIALIZE; }else if( strcmp(z,"-readonly")==0 ){ data.openMode = SHELL_OPEN_READONLY; #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) @@ -8716,6 +8735,8 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ #endif }else if( strcmp(z,"-append")==0 ){ data.openMode = SHELL_OPEN_APPENDVFS; + }else if( strcmp(z,"-deserialize")==0 ){ + data.openMode = SHELL_OPEN_DESERIALIZE; }else if( strcmp(z,"-readonly")==0 ){ data.openMode = SHELL_OPEN_READONLY; }else if( strcmp(z,"-ascii")==0 ){ |