]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add the ".imposter" command to the command-line shell.
authordrh <drh@noemail.net>
Thu, 3 Nov 2016 13:01:38 +0000 (13:01 +0000)
committerdrh <drh@noemail.net>
Thu, 3 Nov 2016 13:01:38 +0000 (13:01 +0000)
FossilOrigin-Name: be3ec8fdcf1541017ca9375df07645db2a9a3f5a

manifest
manifest.uuid
src/shell.c

index 33edebd61fc96c14b55554dfec9d2b946e3a5fbb..e87531c36192bc2c95ff6c3284ca4667421b0f3b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\san\spossible\sNULL\spointer\sdeference\sin\sthe\scommand-line\sshell\sthat\scan\noccur\swhen\susing\simposter\smode.
-D 2016-11-03T02:25:30.134
+C Add\sthe\s".imposter"\scommand\sto\sthe\scommand-line\sshell.
+D 2016-11-03T13:01:38.992
 F Makefile.in 6fd48ffcf7c2deea7499062d1f3747f986c19678
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc e0217f2d35a0448abbe4b066132ae20136e8b408
@@ -388,7 +388,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696
 F src/resolve.c 3fac1b2737ea5a724f20b921ac7e259c9be2100b
 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
 F src/select.c ea3af83e2d0f245fef81ea4cf04cb730ce67f722
-F src/shell.c 0abcad599065d9e00b91ca4ad7d14b98ea381d91
+F src/shell.c 859c497e9f83a5326f43c1a0e078acc52952b275
 F src/sqlite.h.in 97e9b0f952306677db82b055147ed1d99cb7ba66
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
 F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae
@@ -1529,7 +1529,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 def8f598b8e33b5bab3a024cc57f4c5e300cd8cd
-R ae537ccc69c194277761110153c77ab0
+P ad08753a8bbf073ec4af9c3a5783ed664244d954
+R 4bccfcf3c4fd102e5db9ad5f3fdf53dc
 U drh
-Z c8a9d3d6f5e70005dce9f87ade1f94d9
+Z 3d1bd5abf50601149224220b1d9418d0
index 2068690c009fa1a343afc002380bbcd28ee45c70..c6fc1185b00790013eb72b032a98b960d79e86c6 100644 (file)
@@ -1 +1 @@
-ad08753a8bbf073ec4af9c3a5783ed664244d954
\ No newline at end of file
+be3ec8fdcf1541017ca9375df07645db2a9a3f5a
\ No newline at end of file
index 15bb6f273073d76058ef0272864cf65a50e76b04..374755fcc5477bb47b1ac84587ebc064fbe1f2cf 100644 (file)
@@ -2164,6 +2164,9 @@ static char zHelp[] =
   ".headers on|off        Turn display of headers on or off\n"
   ".help                  Show this message\n"
   ".import FILE TABLE     Import data from FILE into TABLE\n"
+#ifndef SQLITE_OMIT_TEST_CONTROL
+  ".imposter INDEX TABLE  Create imposter table TABLE on index INDEX\n"
+#endif
   ".indexes ?TABLE?       Show names of all indexes\n"
   "                         If TABLE specified, only show indexes for tables\n"
   "                         matching LIKE pattern TABLE.\n"
@@ -3846,6 +3849,68 @@ static int do_meta_command(char *zLine, ShellState *p){
     }
   }else
 
+#ifndef SQLITE_OMIT_BUILTIN_TEST
+  if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
+    char *zSql;
+    char *zCollist = 0;
+    sqlite3_stmt *pStmt;
+    int tnum = 0;
+    if( nArg!=3 ){
+      utf8_printf(stderr, "Usage: .imposter INDEX IMPOSTER\n");
+      rc = 1;
+      goto meta_command_exit;
+    }
+    open_db(p, 0);
+    zSql = sqlite3_mprintf("SELECT rootpage FROM sqlite_master"
+                           " WHERE name='%q' AND type='index'", azArg[1]);
+    sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
+    sqlite3_free(zSql);
+    if( sqlite3_step(pStmt)==SQLITE_ROW ){
+      tnum = sqlite3_column_int(pStmt, 0);
+    }
+    sqlite3_finalize(pStmt);
+    if( tnum==0 ){
+      utf8_printf(stderr, "no such index: \"%s\"\n", azArg[1]);
+      rc = 1;
+      goto meta_command_exit;
+    }
+    zSql = sqlite3_mprintf("PRAGMA index_xinfo='%q'", azArg[1]);
+    rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
+    sqlite3_free(zSql);
+    while( sqlite3_step(pStmt)==SQLITE_ROW ){
+      const char *zCol = (const char*)sqlite3_column_text(pStmt,2);
+      if( zCol==0 ) zCol = "_ROWID_";
+      if( zCollist==0 ){
+        zCollist = sqlite3_mprintf("\"%w\"", zCol);
+      }else{
+        zCollist = sqlite3_mprintf("%z,\"%w\"", zCollist, zCol);
+      }
+    }
+    sqlite3_finalize(pStmt);
+    zSql = sqlite3_mprintf(
+          "CREATE TABLE \"%w\"(%s,PRIMARY KEY(%s))WITHOUT ROWID",
+          azArg[2], zCollist, zCollist);
+    sqlite3_free(zCollist);
+    rc = sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 1, tnum);
+    if( rc==SQLITE_OK ){
+      rc = sqlite3_exec(p->db, zSql, 0, 0, 0);
+      sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 0);
+      if( rc ){
+        utf8_printf(stderr, "Error in [%s]: %s\n", zSql, sqlite3_errmsg(p->db));
+      }else{
+        utf8_printf(stdout, "%s;\n", zSql);
+        utf8_printf(stdout, 
+           "WARNING: writing to an imposter table will corrupt the index!\n"
+        );
+      }
+    }else{
+      utf8_printf(stderr, "SQLITE_TESTCTRL_IMPOSTER returns %d\n", rc);
+      rc = 1;
+    }
+    sqlite3_free(zSql);
+  }else
+#endif /* !defined(SQLITE_OMIT_TEST_CONTROL) */
+
 #ifdef SQLITE_ENABLE_IOTRACE
   if( c=='i' && strncmp(azArg[0], "iotrace", n)==0 ){
     SQLITE_API extern void (SQLITE_CDECL *sqlite3IoTrace)(const char*, ...);
@@ -3868,6 +3933,7 @@ static int do_meta_command(char *zLine, ShellState *p){
     }
   }else
 #endif
+
   if( c=='l' && n>=5 && strncmp(azArg[0], "limits", n)==0 ){
     static const struct {
        const char *zLimitName;   /* Name of a limit */
@@ -4708,6 +4774,7 @@ static int do_meta_command(char *zLine, ShellState *p){
     }
   }else
 
+#ifndef SQLITE_OMIT_BUILTIN_TEST
   if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 && nArg>=2 ){
     static const struct {
        const char *zCtrlName;   /* Name of a test-control option */
@@ -4883,6 +4950,7 @@ static int do_meta_command(char *zLine, ShellState *p){
     }
 #endif
   }else
+#endif /* !defined(SQLITE_OMIT_BUILTIN_TEST) */
 
 #if SQLITE_USER_AUTHENTICATION
   if( c=='u' && strncmp(azArg[0], "user", n)==0 ){