]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fixes to the dump logic. All appears to be working in preliminary tests.
authordrh <drh@noemail.net>
Mon, 13 Mar 2017 21:49:48 +0000 (21:49 +0000)
committerdrh <drh@noemail.net>
Mon, 13 Mar 2017 21:49:48 +0000 (21:49 +0000)
FossilOrigin-Name: 007b11e301d444361c8eff8734dc2fb968a64343c177ff30cec74a0cf76099e8

ext/misc/dbdump.c
manifest
manifest.uuid

index ce51eba0a05950cc627f086ff16bcddf8e5b00ca..db581a8325e5e04fc560bd991d1405f86ca465e9 100644 (file)
@@ -224,7 +224,6 @@ static char **tableColumnList(DState *p, const char *zTab){
   rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
   sqlite3_free(zSql);
   if( rc ) return 0;
-  azCol[0] = 0;
   while( sqlite3_step(pStmt)==SQLITE_ROW ){
     if( nCol>=nAlloc-2 ){
       char **azNew;
@@ -232,6 +231,7 @@ static char **tableColumnList(DState *p, const char *zTab){
       azNew = sqlite3_realloc(azCol, nAlloc*sizeof(azCol[0]));
       if( azNew==0 ) goto col_oom;
       azCol = azNew;
+      azCol[0] = 0;
     }
     azCol[++nCol] = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 1));
     if( azCol[nCol]==0 ) goto col_oom;
@@ -317,7 +317,7 @@ static void output_formatted(DState *p, const char *zFormat, ...){
   va_list ap;
   char *z;
   va_start(ap, zFormat);
-  z = sqlite3_mprintf(zFormat, ap);
+  z = sqlite3_vmprintf(zFormat, ap);
   va_end(ap);
   p->xCallback(z, p->pArg);
   sqlite3_free(z);
@@ -430,10 +430,13 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
     azCol = tableColumnList(p, zTable);
     if( azCol==0 ) return 0;
 
+    initText(&sTable);
+    appendText(&sTable, "INSERT INTO ", 0);
+
     /* Always quote the table name, even if it appears to be pure ascii,
     ** in case it is a keyword. Ex:  INSERT INTO "table" ... */
-    initText(&sTable);
     appendText(&sTable, zTable, quoteChar(zTable));
+
     /* If preserving the rowid, add a column list after the table name.
     ** In other words:  "INSERT INTO tab(rowid,a,b,c,...) VALUES(...)"
     ** instead of the usual "INSERT INTO tab VALUES(...)".
@@ -462,7 +465,8 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
         appendText(&sSelect, ",", 0);
       }
     }
-    nCol = i-1;
+    nCol = i;
+    if( azCol[0]==0 ) nCol--;
     freeColumnList(azCol);
     appendText(&sSelect, " FROM ", 0);
     appendText(&sSelect, zTable, quoteChar(zTable));
@@ -545,7 +549,7 @@ static void output_sql_from_query(
   char *zSql;
   va_list ap;
   va_start(ap, zSelect);
-  zSql = sqlite3_mprintf(zSelect, ap);
+  zSql = sqlite3_vmprintf(zSelect, ap);
   va_end(ap);
   if( zSql==0 ){
     p->rc = SQLITE_NOMEM;
@@ -602,7 +606,7 @@ static void run_schema_dump_query(
   char *z;
   va_list ap;
   va_start(ap, zQuery);
-  z = sqlite3_mprintf(zQuery, ap);
+  z = sqlite3_vmprintf(zQuery, ap);
   va_end(ap); 
   sqlite3_exec(p->db, z, dump_callback, p, &zErr);
   sqlite3_free(z);
index dfbee1c83e5a046d57756ed42b4357c82c2e29f8..57159e7a5ce11bfad9abdc160a5410339595cc4b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C First\sdraft\sof\sthe\scomplete\sdbdump.c\slibrary.
-D 2017-03-13T21:26:41.643
+C Fixes\sto\sthe\sdump\slogic.\s\sAll\sappears\sto\sbe\sworking\sin\spreliminary\stests.
+D 2017-03-13T21:49:48.351
 F Makefile.in 9605f4c49eace601d5c12c85dd6e037cc613a6d823e857614ba26b42f1285db0
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc 9020fa41eb91f657ae0cc44145d0a2f3af520860
@@ -211,7 +211,7 @@ F ext/misc/carray.c 40c27641010a4dc67e3690bdb7c9d36ca58b3c2d
 F ext/misc/closure.c 0d2a038df8fbae7f19de42e7c7d71f2e4dc88704
 F ext/misc/compress.c 122faa92d25033d6c3f07c39231de074ab3d2e83
 F ext/misc/csv.c 531a46cbad789fca0aa9db69a0e6c8ac9e68767d
-F ext/misc/dbdump.c 819eb33f6ff788a466525557f7ea3742078853cc794b2eb0799a254dd6da81e2
+F ext/misc/dbdump.c 34174d537318027b159e3341105866c05a4149376ede59988c82280bed144e6d
 F ext/misc/eval.c f971962e92ebb8b0a4e6b62949463ee454d88fa2
 F ext/misc/fileio.c d4171c815d6543a9edef8308aab2951413cd8d0f
 F ext/misc/fuzzer.c 7c64b8197bb77b7d64eff7cac7848870235d4c25
@@ -1564,7 +1564,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 74c5ace498f72d7f5495203678bedd0bc540211131a4e4db7b62115d5322a288
-R dcbc2252d3d150af6e3faa70158994bd
+P 84ea4fcc52d0af02648c52989c2e69f4961071e1620382555ec59a39161a7a7d
+R de364a9f85fa4899d644a897efb72e80
 U drh
-Z 9a73382dae2ea2eb6bda6a3d74fd54dd
+Z 55e9f45d2725daddcac9a1569ce24da7
index 0597c414ba895bc7ca5dfc24d3562ae097c562f9..db7f312b5025d2c69f955348f04c61f34906a8d6 100644 (file)
@@ -1 +1 @@
-84ea4fcc52d0af02648c52989c2e69f4961071e1620382555ec59a39161a7a7d
\ No newline at end of file
+007b11e301d444361c8eff8734dc2fb968a64343c177ff30cec74a0cf76099e8
\ No newline at end of file