From: drh Date: Wed, 1 Jul 2020 16:19:14 +0000 (+0000) Subject: Ensure that the "PRAGMA schema_version" command causes the schema to be X-Git-Tag: version-3.33.0~80 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e3863b5176ae43740f1722ec93e698afd122bd16;p=thirdparty%2Fsqlite.git Ensure that the "PRAGMA schema_version" command causes the schema to be reparsed and reloaded. FossilOrigin-Name: 27d4a9a7b530c77a5b2593d1a5232b10746da9906f8d12890de7a8fbd7270256 --- diff --git a/manifest b/manifest index 8481a71001..2bfc0d9967 100644 --- a/manifest +++ b/manifest @@ -1,6 +1,6 @@ B 7a876209a678a34c198b54ceef9e3c041f128a14dc73357f6a57cadadaa6cf7b -C Fix\sa\sproblem\swith\sVM\scode\sgenerated\sfor\ssome\saggregate\sSELECT\sstatements\sthat\sfeature\smin()/max()\saggregates\sboth\swith\sand\swithout\sFILTER\sclauses. -D 2020-07-01T14:07:45.398 +C Ensure\sthat\sthe\s"PRAGMA\sschema_version"\scommand\scauses\sthe\sschema\sto\sbe\nreparsed\sand\sreloaded. +D 2020-07-01T16:19:14.139 F Makefile.in 19374a5db06c3199ec1bab71ab74a103d8abf21053c05e9389255dc58083f806 F Makefile.msc 48f5a3fc32672c09ad73795749f6253e406a31526935fbbffd8f021108d54574 F autoconf/Makefile.am a8d1d24affe52ebf8d7ddcf91aa973fa0316618ab95bb68c87cabf8faf527dc8 @@ -14,13 +14,15 @@ F src/btree.c e8e4a7e4727f0ead6433fdafeff347bf078fec39bee55a24441c3481e5b85164 F src/btreeInt.h 19267385aa3bc00067d48e0e4ba83ae82dc08b0c15a3b3df20ea653cb462b5bf F src/build.c ba1bbe563a3dc02d5fed20537603181e5289c13ea30ae5e775f552e7557adbfa F src/expr.c a3ab84399b3415f66d2d0c25f5bcd98ef465c0c07ea1f19bf2a418b1c8fcad74 +F src/pragma.c 9085fc43b56497cbd88752cd7a9bca2c36ed52af5b56b1b089f8ddedc6b9b7ba F src/resolve.c 79cee37182fea66703f90365b8b0a646ed7e9bfa9238b91fa90dfc74258b940e F src/select.c 860daa05592ed1b38f6266f067fa020b539548ab929aa60fa59e7681e7f3f8cb F src/shell.c.in d663152487d4bfddea0f6d21ebc2ed51575d22657a02c6828afd344bbd4651af F src/test1.c fe56c4bcaa2685ca9aa25d817a0ee9345e189aff4a5a71a3d8ba946c7776feb8 F src/update.c 6a0484134635f167594d597a33d186051125d3ef41803a90b246cea6cf7f11f9 -F src/vdbe.c b9ff68008f3d9d1f38525414bdcf8f62a73f458079245c17a63b2b4763d645fd +F src/vdbe.c 1208cbeecb7a6293d97819c1308630421bd461ff4006785746b07467cc8ebd26 F src/vdbeapi.c c1a9004ac554d8d48794d2ce5f80397f8e419fd28643a543cc1e004c7713c3ef +F test/altertab.test b8b2104212e8ea87c75c3cbe3cb78ed7236a6c828ee2e59ed09d3dbe9812d002 F test/busy2.test 415364312743992641f9bf679c84918327296067f85a5d00012b339dc35acbd7 F test/decimal.test 12739a01bdba4c4d79f95b323e6b67b9fad1ab6ffb56116bd2b9c81a5b19e1d9 F test/filter1.test 6c483ecf7886c8843a8612c021aa23f33c581f584151f251842b3a3592c95ac8 @@ -34,7 +36,7 @@ F tool/mksqlite3c.tcl f4ef476510eca4124c874a72029f1e01bc54a896b1724e8f9eef0d8bfa F tool/mksqlite3h.tcl 1f5e4a1dbbbc43c83cc6e74fe32c6c620502240b66c7c0f33a51378e78fc4edf F tool/showlocks.c 9cc5e66d4ebbf2d194f39db2527ece92077e86ae627ddd233ee48e16e8142564 F tool/speed-check.sh 615cbdf50f1409ef3bbf9f682e396df80f49d97ed93ed3e61c8e91fae6afde58 -P f068fb116286b1dbdee9c168900348cfcab84e6d8413f3456e4e492f650d11b0 -R 8b21ceb686d4d5f9c6580e467d4cb411 -U dan -Z 46b832ad1b2fc184b95c974e9f57ad71 +P 2094da753feb847254473b148d11e535c44dbae9b17454f1a4f8f7e90aefba3f +R f173a87f0b525ecb55db36f097804790 +U drh +Z af55a7b0f1c3b906e0bbd996c22a7eb2 diff --git a/manifest.uuid b/manifest.uuid index fe8f62e77f..278e50023b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2094da753feb847254473b148d11e535c44dbae9b17454f1a4f8f7e90aefba3f \ No newline at end of file +27d4a9a7b530c77a5b2593d1a5232b10746da9906f8d12890de7a8fbd7270256 \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 161a241efe..c553fb32d8 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1890,6 +1890,7 @@ void sqlite3Pragma( aOp[1].p1 = iDb; aOp[1].p2 = iCookie; aOp[1].p3 = sqlite3Atoi(zRight); + aOp[1].p5 = 1; }else{ /* Read the specified cookie value */ static const VdbeOpList readCookie[] = { diff --git a/src/vdbe.c b/src/vdbe.c index 98897d3f72..51b48aa5a3 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -3629,7 +3629,7 @@ case OP_ReadCookie: { /* out2 */ break; } -/* Opcode: SetCookie P1 P2 P3 * * +/* Opcode: SetCookie P1 P2 P3 * P5 ** ** Write the integer value P3 into cookie number P2 of database P1. ** P2==1 is the schema version. P2==2 is the database format. @@ -3638,6 +3638,11 @@ case OP_ReadCookie: { /* out2 */ ** database file used to store temporary tables. ** ** A transaction must be started before executing this opcode. +** +** If P2 is the SCHEMA_VERSION cookie (cookie number 1) then the internal +** schema version is set to P3-P5. The "PRAGMA schema_version=N" statement +** has P5 set to 1, so that the internal schema version will be different +** from the database schema version, resulting in a schema reset. */ case OP_SetCookie: { Db *pDb; @@ -3654,7 +3659,7 @@ case OP_SetCookie: { rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, pOp->p3); if( pOp->p2==BTREE_SCHEMA_VERSION ){ /* When the schema cookie changes, record the new cookie internally */ - pDb->pSchema->schema_cookie = pOp->p3; + pDb->pSchema->schema_cookie = pOp->p3 - pOp->p5; db->mDbFlags |= DBFLAG_SchemaChange; }else if( pOp->p2==BTREE_FILE_FORMAT ){ /* Record changes in the file format */ diff --git a/test/altertab.test b/test/altertab.test index c99010d29d..435620d1ee 100644 --- a/test/altertab.test +++ b/test/altertab.test @@ -658,5 +658,23 @@ do_catchsql_test 21.3 { ALTER TABLE a RENAME TO e; } {1 {error in view c: 1st ORDER BY term does not match any column in the result set}} +# After forum thread https://sqlite.org/forum/forumpost/ddbe1c7efa +# Ensure that PRAGMA schema_version=N causes a full schema reload. +# +reset_db +do_execsql_test 22.0 { + CREATE TABLE t1(a INT, b TEXT NOT NULL); + INSERT INTO t1 VALUES(1,2),('a','b'); + BEGIN; + PRAGMA writable_schema=ON; + UPDATE sqlite_schema SET sql='CREATE TABLE t1(a INT, b TEXT)' WHERE name LIKE 't1'; + PRAGMA schema_version=1234; + COMMIT; + PRAGMA integrity_check; +} {ok} +do_execsql_test 22.1 { + ALTER TABLE t1 ADD COLUMN c INT DEFAULT 78; + SELECT * FROM t1; +} {1 2 78 a b 78} finish_test