From: drh Date: Tue, 13 Dec 2016 23:22:39 +0000 (+0000) Subject: In the command-line shell, in the output of the ".dump", ".schema", and X-Git-Tag: version-3.16.0~46 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=79f20e96dc72f054f29155c7212563271da439e0;p=thirdparty%2Fsqlite.git In the command-line shell, in the output of the ".dump", ".schema", and ".fullschema" commands, convert CREATE TABLE statements that appear to come from shadow tables into CREATE TABLE IF NOT EXISTS statements. FossilOrigin-Name: c7021960f5c070fb5c9db9e41b4000d3dc065f42 --- diff --git a/manifest b/manifest index 254f17d042..e64156d9ec 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\scompiler\swarnings. -D 2016-12-13T20:30:29.436 +C In\sthe\scommand-line\sshell,\sin\sthe\soutput\sof\sthe\s".dump",\s".schema",\sand\n".fullschema"\scommands,\sconvert\sCREATE\sTABLE\sstatements\sthat\sappear\sto\scome\nfrom\sshadow\stables\sinto\sCREATE\sTABLE\sIF\sNOT\sEXISTS\sstatements. +D 2016-12-13T23:22:39.714 F Makefile.in 7639c6a09da11a9c7c6f2630fc981ee588d1072d F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc b8ca53350ae545e3562403d5da2a69cec79308da @@ -389,7 +389,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c bb070cf5f23611c44ab7e4788803684e385fc3fb F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c b4bd43e1233c87e8a7cf66150421997b0396417e -F src/shell.c 9597efa50a4a27bc6440ad99cbcd7fff6957f514 +F src/shell.c f1c7fde7a83421e6ed620df41d200674a2327e65 F src/sqlite.h.in e8e2d108d82647f0a812fdb74accf91c1ec08ddc F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae @@ -1536,7 +1536,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7f88bb44129a0cd36e27e00dc7c37e87cf3c90f7 -R f2e66ee6668f0716a35acfaa4809f04b +P ed2c9f3738c96d8e3dbece7ccb721cb1a8ae8fac +R 064921518747d6f1187652c989ffbe09 U drh -Z 404271946c196a116af17aa555379b02 +Z 06643ca029a5c5cdb028f91458ca4784 diff --git a/manifest.uuid b/manifest.uuid index 99dfe7c001..136940b880 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ed2c9f3738c96d8e3dbece7ccb721cb1a8ae8fac \ No newline at end of file +c7021960f5c070fb5c9db9e41b4000d3dc065f42 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 756c389761..d0b743cb5b 100644 --- a/src/shell.c +++ b/src/shell.c @@ -946,6 +946,25 @@ static int shellAuth( } #endif +/* +** Print a schema statement. Part of MODE_Semi and MODE_Pretty output. +** +** This routine converts some CREATE TABLE statements for shadow tables +** in FTS3/4/5 into CREATE TABLE IF NOT EXISTS statements. +*/ +static void printSchemaLine(FILE *out, const char *z, const char *zTail){ + if( sqlite3_strglob("CREATE TABLE ['\"]*", z)==0 ){ + utf8_printf(out, "CREATE TABLE IF NOT EXISTS %s%s", z+13, zTail); + }else{ + utf8_printf(out, "%s%s", z, zTail); + } +} +static void printSchemaLineN(FILE *out, char *z, int n, const char *zTail){ + char c = z[n]; + z[n] = 0; + printSchemaLine(out, z, zTail); + z[n] = c; +} /* ** This is the callback routine that the shell @@ -1064,7 +1083,7 @@ static int shell_callback( break; } case MODE_Semi: { /* .schema and .fullschema output */ - utf8_printf(p->out, "%s;\n", azArg[0]); + printSchemaLine(p->out, azArg[0], ";\n"); break; } case MODE_Pretty: { /* .schema and .fullschema with --indent */ @@ -1108,14 +1127,14 @@ static int shell_callback( }else if( c==')' ){ nParen--; if( nLine>0 && nParen==0 && j>0 ){ - utf8_printf(p->out, "%.*s\n", j, z); + printSchemaLineN(p->out, z, j, "\n"); j = 0; } } z[j++] = c; if( nParen==1 && (c=='(' || c==',' || c=='\n') ){ if( c=='\n' ) j--; - utf8_printf(p->out, "%.*s\n ", j, z); + printSchemaLineN(p->out, z, j, "\n "); j = 0; nLine++; while( IsSpace(z[i+1]) ){ i++; } @@ -1123,7 +1142,7 @@ static int shell_callback( } z[j] = 0; } - utf8_printf(p->out, "%s;\n", z); + printSchemaLine(p->out, z, ";\n"); sqlite3_free(z); break; } @@ -2046,7 +2065,7 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){ sqlite3_free(zIns); return 0; }else{ - utf8_printf(p->out, "%s;\n", zSql); + printSchemaLine(p->out, zSql, ";\n"); } if( strcmp(zType, "table")==0 ){