]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Bring .import --schema enhancement in. Refine mkshellc include logic.
authorlarrybr <larrybr@noemail.net>
Mon, 17 Jan 2022 03:25:00 +0000 (03:25 +0000)
committerlarrybr <larrybr@noemail.net>
Mon, 17 Jan 2022 03:25:00 +0000 (03:25 +0000)
FossilOrigin-Name: e38f45cdc5694dc126bc6a41d3657807fc9953487f4ae26a802a00cbbd12aa61

manifest
manifest.uuid
src/shell.c.in
test/shell5.test
tool/mkshellc.tcl

index e78d1df5f58f02a2a679790c5d1e3daa8f55e4b2..0d1636c6305620b3e18aa066dd2f0ae1a20b5625 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C mkshellc.tcl\sto\sconvert\s#include\sto\sINCLUDE\sfor\sin-tree\sincludees
-D 2022-01-08T21:59:49.612
+C Bring\s.import\s--schema\senhancement\sin.\sRefine\smkshellc\sinclude\slogic.
+D 2022-01-17T03:25:00.240
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -553,7 +553,7 @@ F src/random.c 097dc8b31b8fba5a9aca1697aeb9fd82078ec91be734c16bffda620ced7ab83c
 F src/resolve.c 359bc0e445d427583d2ab6110433a5dc777f64a0ecdf8d24826d8b475233ead9
 F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
 F src/select.c 342e096c2737a3ee60753e91de6e6660c7f59cd2988b3e1ab641d38fd885003f
-F src/shell.c.in 78439a5161843de5d9b5407d2d5cd77673c6fd5d16982f38c49007319bc87fb8
+F src/shell.c.in c49f89c8c7e352f5630e47759e0371947103435d8f819fb4717001f5a35bec55
 F src/shext_linkage.h 5897e8140a06cb733d07a927994b30d41225eb93b5b8cf2ad0e3460cb4e95fd6
 F src/sqlite.h.in a5e0d6bd47e67aabf1475986d36bdcc7bfa9e06566790ebf8e3aa7fa551c9f99
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
@@ -1389,7 +1389,7 @@ F test/shell1.test a531d4f08eaca79357e3892a00b109a1a2030840a590c7bb3f18cce14932f
 F test/shell2.test de123dd6be4b774b5ebdc81b29b3515c29c4a6a81bd5d2e1c38605d2f775a25a
 F test/shell3.test cb4b835a901742c9719437a89171172ecc4a8823ad97349af8e4e841e6f82566
 F test/shell4.test 3ed6c4b42fd695efcbc25d69ef759dbb15855ca8e52ba6c5ee076f8b435f48be
-F test/shell5.test 596342db4ada597c6e021081a63f27be87eb5b1d8cf71028f3ec7dc17a8dd42e
+F test/shell5.test 84edcdd1754b8ae279329ea2bb999f3cbb9f55b1339fc27995c1cdb2cf0c9918
 F test/shell6.test 1ceb51b2678c472ba6cf1e5da96679ce8347889fe2c3bf93a0e0fa73f00b00d3
 F test/shell7.test 115132f66d0463417f408562cc2cf534f6bbc6d83a6d50f0072a9eb171bae97f
 F test/shell8.test 388471d16e4de767333107e30653983f186232c0e863f4490bb230419e830aae
@@ -1873,7 +1873,7 @@ F tool/mkopcodec.tcl 33d20791e191df43209b77d37f0ff0904620b28465cca6990cf8d60da61
 F tool/mkopcodeh.tcl 130b88697da6ec5b89b41844d955d08fb62c2552e889dec8c7bcecb28d8f50bd
 F tool/mkopts.tcl 680f785fdb09729fd9ac50632413da4eadbdf9071535e3f26d03795828ab07fa
 F tool/mkpragmatab.tcl de206c64b6e9ac8cd5e3cbd0ffe456f07d5710605ef8385d677e60ce3335ea12
-F tool/mkshellc.tcl e02ca680bec146e483394fa2f6ce9f0ba6a34e7d4e9c9aa6ee87aab50ef4b141
+F tool/mkshellc.tcl a6cbfb2bfa5bb826a6aae4a068e7636576b1d9076610a29281391df3120dbd20
 F tool/mksourceid.c 36aa8020014aed0836fd13c51d6dc9219b0df1761d6b5f58ff5b616211b079b9
 F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97
 F tool/mksqlite3c-noext.tcl 4f7cfef5152b0c91920355cbfc1d608a4ad242cb819f1aea07f6d0274f584a7f
@@ -1939,8 +1939,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P f628c3afd0a0527b1db7e3e117afc33a6cb929a507d1e32670e5fd5933fc4833
-R 59637fb955c3322a47f3cc2a0fb0721f
+P b1f3b317c08f467fa8d4cbafdf08ef859b8f84ce371d19c13f87f7a1f2313b98
+Q +38d9dbca166078013a44214c88805fc7cca578976ceed9fc62f5159a38ec96a7
+Q +bff9153ceedcc7be77f2daf5139fee29c2fab742ff1fce49877965423a7d4be3
+R 174a8be2eb19d15c0a189ca59e03dfc3
 U larrybr
-Z 3a2f0529fc6b670cc5387b026b5b1a8a
+Z f12762a64bd7b7363f72a3839c277d50
 # Remove this line to create a well-formed Fossil manifest.
index c6ead6c2846716e205eb552de30e5037d99ecbc5..2522229a5667a465cc1077376a21ad16d2b8833e 100644 (file)
@@ -1 +1 @@
-b1f3b317c08f467fa8d4cbafdf08ef859b8f84ce371d19c13f87f7a1f2313b98
\ No newline at end of file
+e38f45cdc5694dc126bc6a41d3657807fc9953487f4ae26a802a00cbbd12aa61
\ No newline at end of file
index d0b95ad3ce1cc2e2a0d27387eb203602ee57f86c..d3966751b46eb84c9d642fe6c2e2f80cc15a7aa3 100644 (file)
@@ -8157,6 +8157,7 @@ COLLECT_HELP_TEXT[
   "     --ascii               Use \\037 and \\036 as column and row separators",
   "     --csv                 Use , and \\n as column and row separators",
   "     --skip N              Skip the first N rows of input",
+  "     --schema S            Target table to be S.TABLE",
   "     -v                    \"Verbose\" - increase auxiliary output",
   "   Notes:",
   "     *  If TABLE does not exist, it is created.  The first row of input",
@@ -8168,6 +8169,7 @@ COLLECT_HELP_TEXT[
 ];
 DISPATCHABLE_COMMAND( import ? 3 7 ){
   char *zTable = 0;           /* Insert data into this table */
+  char *zSchema = "main";     /* within this schema */
   char *zFile = 0;            /* Name of file to extra content from */
   sqlite3_stmt *pStmt = NULL; /* A statement */
   int nCol;                   /* Number of columns in the table */
@@ -8208,6 +8210,8 @@ DISPATCHABLE_COMMAND( import ? 3 7 ){
       }
     }else if( strcmp(z,"-v")==0 ){
       eVerbose++;
+    }else if( strcmp(z,"-schema")==0 && i<nArg-1 ){
+      zSchema = azArg[++i];
     }else if( strcmp(z,"-skip")==0 && i<nArg-1 ){
       nSkip = integerValue(azArg[++i]);
     }else if( strcmp(z,"-ascii")==0 ){
@@ -8288,6 +8292,7 @@ DISPATCHABLE_COMMAND( import ? 3 7 ){
     import_cleanup(&sCtx);
     return 1;
   }
+  /* Below, resources must be freed before exit. */
   if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){
     char zSep[2];
     zSep[1] = 0;
@@ -8302,7 +8307,7 @@ DISPATCHABLE_COMMAND( import ? 3 7 ){
   while( (nSkip--)>0 ){
     while( xRead(&sCtx) && sCtx.cTerm==sCtx.cColSep ){}
   }
-  zSql = sqlite3_mprintf("SELECT * FROM \"%w\"", zTable);
+  zSql = sqlite3_mprintf("SELECT * FROM \"%w\".\"%w\"", zSchema, zTable);
   if( zSql==0 ){
     import_cleanup(&sCtx);
     shell_out_of_memory();
@@ -8311,7 +8316,8 @@ DISPATCHABLE_COMMAND( import ? 3 7 ){
   rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
   import_append_char(&sCtx, 0);    /* To ensure sCtx.z is allocated */
   if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(p->db))==0 ){
-    char *zCreate = sqlite3_mprintf("CREATE TABLE \"%w\"", zTable);
+    char *zCreate = sqlite3_mprintf("CREATE TABLE \"%w\".\"%w\"",
+                                    zSchema, zTable);
     char cSep = '(';
     while( xRead(&sCtx) ){
       zCreate = sqlite3_mprintf("%z%c\n  \"%w\" TEXT", zCreate, cSep, sCtx.z);
@@ -8329,13 +8335,13 @@ DISPATCHABLE_COMMAND( import ? 3 7 ){
       utf8_printf(p->out, "%s\n", zCreate);
     }
     rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
-    sqlite3_free(zCreate);
     if( rc ){
-      *pzErr = shellMPrintf(0,"CREATE TABLE \"%s\"(...) failed: %s\n",
-                               zTable, sqlite3_errmsg(p->db));
+      utf8_printf(stderr, "%s failed:\n%s\n", zCreate, sqlite3_errmsg(p->db));
+      sqlite3_free(zCreate);
       import_cleanup(&sCtx);
       return 1;
     }
+    sqlite3_free(zCreate);
     rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
   }
   sqlite3_free(zSql);
@@ -8354,7 +8360,8 @@ DISPATCHABLE_COMMAND( import ? 3 7 ){
     import_cleanup(&sCtx);
     shell_out_of_memory();
   }
-  sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\" VALUES(?", zTable);
+  sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\".\"%w\" VALUES(?",
+                   zSchema, zTable);
   j = strlen30(zSql);
   for(i=1; i<nCol; i++){
     zSql[j++] = ',';
index f1384fbf786a0ca6046ef4bb089ab634b63f1073..a20b070386dbed012c0a7e9138e48f2a1eba8796 100644 (file)
@@ -88,8 +88,9 @@ do_test shell5-1.4.2 {
   forcedelete shell5.csv
   set in [open shell5.csv w]
   close $in
-  set res [catchcmd "test.db" {.import shell5.csv t1
-SELECT COUNT(*) FROM t1;}]
+  set res [catchcmd ":memory:" {ATTACH 'test.db' AS test;
+.import -schema test shell5.csv t1
+SELECT COUNT(*) FROM test.t1;}]
 } {0 0}
 
 # import file with 1 row, 1 column (expecting 2 cols)
@@ -97,7 +98,8 @@ do_test shell5-1.4.3 {
   set in [open shell5.csv w]
   puts $in "1"
   close $in
-  set res [catchcmd "test.db" {.import shell5.csv t1}]
+  set res [catchcmd ":memory:" {ATTACH 'test.db' AS test;
+.import -schema test shell5.csv t1}]
 } {1 {shell5.csv:1: expected 2 columns but found 1 - filling the rest with NULL}}
 
 # import file with 1 row, 3 columns (expecting 2 cols)
@@ -105,7 +107,8 @@ do_test shell5-1.4.4 {
   set in [open shell5.csv w]
   puts $in "1|2|3"
   close $in
-  set res [catchcmd "test.db" {.import shell5.csv t1}]
+  set res [catchcmd ":memory:" {ATTACH 'test.db' AS test;
+.import --schema test shell5.csv t1}]
 } {1 {shell5.csv:1: expected 2 columns but found 3 - extras ignored}}
 
 # import file with 1 row, 2 columns
@@ -126,8 +129,9 @@ do_test shell5-1.4.6 {
   puts $in "2|3"
   puts $in "3|4"
   close $in
-  set res [catchcmd "test.db" {.import shell5.csv t1
-SELECT COUNT(*) FROM t1;}]
+  set res [catchcmd ":memory:" {ATTACH 'test.db' AS test;
+.import -schema test shell5.csv t1
+SELECT COUNT(*) FROM test.t1;}]
 } {0 3}
 
 # import file with 1 row, 2 columns, using a comma
@@ -135,9 +139,10 @@ do_test shell5-1.4.7 {
   set in [open shell5.csv w]
   puts $in "4,5"
   close $in
-  set res [catchcmd "test.db" {.separator ,
-.import shell5.csv t1
-SELECT COUNT(*) FROM t1;}]
+  set res [catchcmd ":memory:" {ATTACH 'test.db' AS test;
+.separator ,
+.import --schema test shell5.csv t1
+SELECT COUNT(*) FROM test.t1;}]
 } {0 4}
 
 # import file with 1 row, 2 columns, text data
index b14e517a00c3ab4a61d1d819fd1fb4efbe1b1051..b8c69382ddc2bc70f9af1fe9998135c5104a12e8 100644 (file)
@@ -622,6 +622,7 @@ proc do_macro {inSrc lx ostrm} {
 }
 
 array set ::typedefsSeen {}
+array set ::includesDone {}
 
 # Filter redundant typedefs and certain includes and qualifiers, in place.
 # Return 1 if line can be emitted as-is, 0 if to be processed further.
@@ -648,8 +649,14 @@ proc transform_line {lineVar nesting} {
     set incPath [file join [file dirname $fromPath] $incRelPath]
     set inTree [file exists $incPath]
     if {$inTree} {
-      set line "INCLUDE $incRelPath"
-      return 0
+      if {[info exists ::includesDone($incPath)]} {
+        set line "/* $line */"
+        return 1
+      } else {
+        set line "INCLUDE $incRelPath"
+        set ::includesDone($incPath) 1
+        return 0
+      }
     }
   }
   if {[string first "__declspec(dllexport)" $line] >= 0} {