aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/shell.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/shell.c b/src/shell.c
index 17048adb3..4912639db 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -2073,14 +2073,26 @@ static int captureOutputCallback(void *pArg, int nArg, char **azArg, char **az){
** Generate an appropriate SELFTEST table in the main database.
*/
static void createSelftestTable(ShellState *p){
+ char *zErrMsg = 0;
sqlite3_exec(p->db,
- "CREATE TABLE selftest(\n"
+ "SAVEPOINT selftest_init;\n"
+ "CREATE TABLE IF NOT EXISTS selftest(\n"
" tno INTEGER PRIMARY KEY,\n" /* Test number */
" op TEXT,\n" /* Operator: memo run */
" cmd TEXT,\n" /* Command text */
" ans TEXT\n" /* Desired answer */
");"
- "INSERT INTO selftest(op,cmd,ans)\n"
+ "CREATE TEMP TABLE [_shell$self](op,cmd,ans);\n"
+ "INSERT INTO [_shell$self](rowid,op,cmd)\n"
+ " VALUES(coalesce((SELECT (max(tno)+100)/10 FROM selftest),10),\n"
+ " 'memo','Tests generated by --init');\n"
+ "INSERT INTO [_shell$self]\n"
+ " SELECT 'run',\n"
+ " 'SELECT hex(sha3_query(''SELECT type,name,tbl_name,sql "
+ "FROM sqlite_master ORDER BY 2'',224))',\n"
+ " hex(sha3_query('SELECT type,name,tbl_name,sql "
+ "FROM sqlite_master ORDER BY 2',224));\n"
+ "INSERT INTO [_shell$self]\n"
" SELECT 'run',"
" 'SELECT hex(sha3_query(''SELECT * FROM \"' ||"
" printf('%w',name) || '\" NOT INDEXED'',224))',\n"
@@ -2092,9 +2104,17 @@ static void createSelftestTable(ShellState *p){
" AND coalesce(rootpage,0)>0\n"
" )\n"
" ORDER BY name;\n"
- "INSERT INTO selftest(op,cmd,ans)\n"
+ "INSERT INTO [_shell$self]\n"
" VALUES('run','PRAGMA integrity_check','ok');\n"
- ,0,0,0);
+ "INSERT INTO selftest(tno,op,cmd,ans)"
+ " SELECT rowid*10,op,cmd,ans FROM [_shell$self];\n"
+ "DROP TABLE [_shell$self];"
+ ,0,0,&zErrMsg);
+ if( zErrMsg ){
+ utf8_printf(stderr, "SELFTEST initialization failure: %s\n", zErrMsg);
+ sqlite3_free(zErrMsg);
+ }
+ sqlite3_exec(p->db, "RELEASE selftest_init",0,0,0);
}
@@ -5813,11 +5833,6 @@ static int do_meta_command(char *zLine, ShellState *p){
bSelftestExists = 1;
}
if( bIsInit ){
- if( bSelftestExists ){
- raw_printf(stderr, "The selftest table already exists\n");
- rc = 1;
- goto meta_command_exit;
- }
createSelftestTable(p);
bSelftestExists = 1;
}