]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix the VACUUM command so that when the MAIN and TEMP databases have
authordrh <drh@noemail.net>
Tue, 20 Oct 2009 15:01:58 +0000 (15:01 +0000)
committerdrh <drh@noemail.net>
Tue, 20 Oct 2009 15:01:58 +0000 (15:01 +0000)
identically named tables, content from the TEMP database does not
accidently overwrite MAIN database content.
Ticket [d82e3f3721296e905d7e8c9dee718f71a826b0eb].
Note that this bug could potentially lead to database corruption.

FossilOrigin-Name: 0bbd8d72ec66cbe11c2548a04ad478202b2b69b6

manifest
manifest.uuid
src/vacuum.c
test/tkt-d82e3f3721.txt [new file with mode: 0644]

index 66d90d945a54ec816bdca794628114c98bc91c78..0d117c7fdc9f015f0fd385857a52631ddc254903 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,8 +1,8 @@
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
-C Remove\sall\smention\sof\ssqlite3_next_stmt()\sfrom\sthe\sdocumentation\sof\nsqlite3_close().
-D 2009-10-20T14:23:09
+C Fix\sthe\sVACUUM\scommand\sso\sthat\swhen\sthe\sMAIN\sand\sTEMP\sdatabases\shave\nidentically\snamed\stables,\scontent\sfrom\sthe\sTEMP\sdatabase\sdoes\snot\naccidently\soverwrite\sMAIN\sdatabase\scontent.\nTicket\s[d82e3f3721296e905d7e8c9dee718f71a826b0eb].\nNote\sthat\sthis\sbug\scould\spotentially\slead\sto\sdatabase\scorruption.
+D 2009-10-20T15:01:59
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in 4ca3f1dd6efa2075bcb27f4dc43eef749877740d
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -208,7 +208,7 @@ F src/trigger.c 2053afa9952f69cf451bc0e6ea88072701f2925e
 F src/update.c 8e8535f66c32d946199cb1caad19646a97ead3a7
 F src/utf.c 99cf927eabb104621ba889ac0dd075fc1657ad30
 F src/util.c 59d4e9456bf1fe581f415a783fa0cee6115c8f35
-F src/vacuum.c f2347520907ee4ec867c9b804d24456b0fd912a7
+F src/vacuum.c 48e1282bbd5eac4b461587c51658378658c00770
 F src/vdbe.c f0d6e7dbd4515758c188c9dd7025eb9dfcf021e0
 F src/vdbe.h 3fedb2121d026dd127350d33e875a49cf05df2e8
 F src/vdbeInt.h 8e07f4356dd5bfe03ac5991338e59b68c9b3c717
@@ -594,6 +594,7 @@ F test/tkt-2ea2425d34.test 1cf13e6f75d149b3209a0cb32927a82d3d79fb28
 F test/tkt-4a03edc4c8.test 2865e4edbc075b954daa82f8da7cc973033ec76e
 F test/tkt-5ee23731f.test 3581260f2a71e51db94e1506ba6b0f7311d002a9
 F test/tkt-94c04eaadb.test 40e6b1fce420fbecf8c2379d3ec3cb6889e49091
+F test/tkt-d82e3f3721.txt cbed12b1a1e4740382de43ef1bb45c6bc0f8f473
 F test/tkt-f777251dc7a.test 6f24c053bc5cdb7e1e19be9a72c8887cf41d5e87
 F test/tkt1435.test f8c52c41de6e5ca02f1845f3a46e18e25cadac00
 F test/tkt1443.test bacc311da5c96a227bf8c167e77a30c99f8e8368
@@ -763,14 +764,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff x
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f x
-P 3b00e769cd30aa50a75f82babb7d2cc90aeb1238
-R 55f2a2342006955cd04b73133d5e37e7
+P f494ed38a8d3fabb7a064ba4a860d5288c5a571b
+R b72a71130ae3f7d0000897032d39db86
 U drh
-Z 6bfd4182a2daf4ab874cac92413ee311
+Z 837f755ebad8093b39e326d07ae62092
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.6 (GNU/Linux)
 
-iD8DBQFK3cfQoxKgR168RlERAlcCAJ4m88U0OJHd/mnU3BP3sJcr3af/zgCcDDWl
-AvqYz6zxoYKi7SdksMjmzi4=
-=GZjz
+iD8DBQFK3dDqoxKgR168RlERAswBAKCOQaAId6gPlMqpI+c5rQCcOyOqQQCfdKm+
+rkKy+eYa2wEINnPhxXG7WQE=
+=0V8S
 -----END PGP SIGNATURE-----
index 7bdb2970fe8aa5458b404bab7612d3a12a3a9595..a082b803d95d9c5998da022c693f2743b13396f9 100644 (file)
@@ -1 +1 @@
-f494ed38a8d3fabb7a064ba4a860d5288c5a571b
\ No newline at end of file
+0bbd8d72ec66cbe11c2548a04ad478202b2b69b6
\ No newline at end of file
index 8f9221e5cd287358abc1faa4752516ce459bab25..8373b38a80a7503b6f9c59b7c483de0f7a95b1da 100644 (file)
@@ -189,13 +189,13 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
   if( rc!=SQLITE_OK ) goto end_of_vacuum;
 
   /* Loop through the tables in the main database. For each, do
-  ** an "INSERT INTO vacuum_db.xxx SELECT * FROM xxx;" to copy
+  ** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy
   ** the contents to the temporary database.
   */
   rc = execExecSql(db, 
       "SELECT 'INSERT INTO vacuum_db.' || quote(name) "
-      "|| ' SELECT * FROM ' || quote(name) || ';'"
-      "FROM sqlite_master "
+      "|| ' SELECT * FROM main.' || quote(name) || ';'"
+      "FROM main.sqlite_master "
       "WHERE type = 'table' AND name!='sqlite_sequence' "
       "  AND rootpage>0"
 
@@ -211,7 +211,7 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
   if( rc!=SQLITE_OK ) goto end_of_vacuum;
   rc = execExecSql(db, 
       "SELECT 'INSERT INTO vacuum_db.' || quote(name) "
-      "|| ' SELECT * FROM ' || quote(name) || ';' "
+      "|| ' SELECT * FROM main.' || quote(name) || ';' "
       "FROM vacuum_db.sqlite_master WHERE name=='sqlite_sequence';"
   );
   if( rc!=SQLITE_OK ) goto end_of_vacuum;
@@ -225,7 +225,7 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
   rc = execSql(db,
       "INSERT INTO vacuum_db.sqlite_master "
       "  SELECT type, name, tbl_name, rootpage, sql"
-      "    FROM sqlite_master"
+      "    FROM main.sqlite_master"
       "   WHERE type='view' OR type='trigger'"
       "      OR (type='table' AND rootpage=0)"
   );
diff --git a/test/tkt-d82e3f3721.txt b/test/tkt-d82e3f3721.txt
new file mode 100644 (file)
index 0000000..db0007b
--- /dev/null
@@ -0,0 +1,79 @@
+# 2009 September 2
+#
+# The author disclaims copyright to this source code.  In place of
+# a legal notice, here is a blessing:
+#
+#    May you do good and not evil.
+#    May you find forgiveness for yourself and forgive others.
+#    May you share freely, never taking more than you give.
+#
+#***********************************************************************
+# This file implements regression tests for SQLite library.
+#
+# This file implements tests to verify that ticket [d82e3f3721] has been
+# fixed.  
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+do_test tkt-d82e3-1.1 {
+  db eval {
+    CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b);
+    INSERT INTO t1 VALUES(null,'abc');
+    INSERT INTO t1 VALUES(null,'def');
+    DELETE FROM t1;
+    INSERT INTO t1 VALUES(null,'ghi');
+    SELECT * FROM t1;
+  }
+} {3 ghi}
+do_test tkt-d82e3-1.2 {
+  db eval {
+    CREATE TEMP TABLE t2(a INTEGER PRIMARY KEY AUTOINCREMENT, b);
+    INSERT INTO t2 VALUES(null,'jkl');
+    INSERT INTO t2 VALUES(null,'mno');
+    DELETE FROM t2;
+    INSERT INTO t2 VALUES(null,'pqr');
+    SELECT * FROM t2;
+  }
+} {3 pqr}
+do_test tkt-d82e3-1.3 {
+  db eval {
+    SELECT 'main', * FROM main.sqlite_sequence
+    UNION ALL
+    SELECT 'temp', * FROM temp.sqlite_sequence
+    ORDER BY 2
+  }
+} {main t1 3 temp t2 3}
+do_test tkt-d82e3-1.4 {
+  db eval {
+    VACUUM;
+    SELECT 'main', * FROM main.sqlite_sequence
+    UNION ALL
+    SELECT 'temp', * FROM temp.sqlite_sequence
+    ORDER BY 2
+  }
+} {main t1 3 temp t2 3}
+
+sqlite3 db2 test.db
+do_test tkt-d82e3-2.1 {
+  db eval {
+    CREATE TEMP TABLE t3(x);
+    INSERT INTO t3 VALUES(1);
+  }
+  db2 eval {
+    CREATE TABLE t3(y,z);
+    INSERT INTO t3 VALUES(8,9);
+  }
+  db eval {
+    SELECT * FROM temp.t3 JOIN main.t3;
+  }
+} {1 8 9}
+do_test tkt-d82e3-2.2 {
+  db eval {
+    VACUUM;
+    SELECT * FROM temp.t3 JOIN main.t3;
+  }
+} {1 8 9}
+
+finish_test