1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Add tests and fixes for "PRAGMA ota_mode".

FossilOrigin-Name: 39df35c4ac65ffba76ba2c6f6727cf5e843e7517
This commit is contained in:
dan
2014-09-17 15:20:24 +00:00
parent 1b95de09bc
commit abc0788663
6 changed files with 140 additions and 26 deletions

View File

@ -14,7 +14,7 @@ set testdir [file join [file dirname $argv0] .. .. test]
source $testdir/tester.tcl source $testdir/tester.tcl
set ::testprefix ota2 set ::testprefix ota2
forcedelete test.db-oal forcedelete test.db-oal test.db-bak
do_execsql_test 1.0 { do_execsql_test 1.0 {
CREATE TABLE t1(a, b); CREATE TABLE t1(a, b);

View File

@ -9,13 +9,17 @@
# #
#*********************************************************************** #***********************************************************************
# #
# Test some properties of the pager_ota_mode pragma. # Test some properties of the pager_ota_mode and ota_mode pragmas.
# #
set testdir [file join [file dirname $argv0] .. .. test] set testdir [file join [file dirname $argv0] .. .. test]
source $testdir/tester.tcl source $testdir/tester.tcl
set ::testprefix ota4 set ::testprefix ota4
#-------------------------------------------------------------------------
# The following tests aim to verify some properties of the pager_ota_mode
# pragma:
#
# 1. Cannot set the pager_ota_mode flag on a WAL mode database. # 1. Cannot set the pager_ota_mode flag on a WAL mode database.
# #
# 2. Or if there is an open read transaction. # 2. Or if there is an open read transaction.
@ -30,34 +34,34 @@ set ::testprefix ota4
# file was started. # file was started.
# #
do_execsql_test 1.1 { do_execsql_test 1.1.1 {
PRAGMA journal_mode = wal; PRAGMA journal_mode = wal;
SELECT * FROM sqlite_master; SELECT * FROM sqlite_master;
} {wal} } {wal}
do_catchsql_test 1.2 { do_catchsql_test 1.1.2 {
PRAGMA pager_ota_mode = 1 PRAGMA pager_ota_mode = 1
} {1 {cannot set pager_ota_mode in wal mode}} } {1 {cannot set pager_ota_mode in wal mode}}
do_execsql_test 2.1 { do_execsql_test 1.2.1 {
PRAGMA journal_mode = delete; PRAGMA journal_mode = delete;
BEGIN; BEGIN;
SELECT * FROM sqlite_master; SELECT * FROM sqlite_master;
} {delete} } {delete}
do_catchsql_test 2.2 { do_catchsql_test 1.2.2 {
PRAGMA pager_ota_mode = 1 PRAGMA pager_ota_mode = 1
} {1 {cannot set pager_ota_mode with open transaction}} } {1 {cannot set pager_ota_mode with open transaction}}
do_execsql_test 2.3 { do_execsql_test 1.2.3 {
COMMIT; COMMIT;
} {} } {}
do_execsql_test 3.1 { do_execsql_test 1.3.1 {
PRAGMA journal_mode = wal; PRAGMA journal_mode = wal;
CREATE TABLE t1(a, b); CREATE TABLE t1(a, b);
INSERT INTO t1 VALUES(1, 2); INSERT INTO t1 VALUES(1, 2);
} {wal} } {wal}
do_test 3.2 { do_test 1.3.2 {
forcecopy test.db-wal test.db-bak forcecopy test.db-wal test.db-bak
execsql { execsql {
PRAGMA journal_mode = delete; PRAGMA journal_mode = delete;
@ -69,7 +73,7 @@ do_test 3.2 {
} }
} {1 {unable to open database file}} } {1 {unable to open database file}}
do_test 4.1 { do_test 1.4.1 {
db close db close
forcedelete test.db-wal test.db-oal forcedelete test.db-wal test.db-oal
sqlite3 db test.db sqlite3 db test.db
@ -82,7 +86,7 @@ do_test 4.1 {
} }
} {1 {unable to open database file}} } {1 {unable to open database file}}
do_test 5.1 { do_test 1.5.1 {
forcedelete test.db-oal forcedelete test.db-oal
reset_db reset_db
execsql { execsql {
@ -100,7 +104,7 @@ do_test 5.1 {
SELECT * FROM t1; SELECT * FROM t1;
} }
} {1 2} } {1 2}
do_execsql_test 5.2 { do_execsql_test 1.5.2 {
PRAGMA pager_ota_mode = 1; PRAGMA pager_ota_mode = 1;
SELECT * FROM t1; SELECT * FROM t1;
INSERT INTO t1 VALUES(5, 6); INSERT INTO t1 VALUES(5, 6);
@ -113,9 +117,115 @@ do_test 5.3 {
SELECT * FROM t1; SELECT * FROM t1;
} }
} {1 2 7 8} } {1 2 7 8}
do_catchsql_test 5.4 { do_catchsql_test 1.5.4 {
PRAGMA pager_ota_mode = 1; PRAGMA pager_ota_mode = 1;
SELECT * FROM t1; SELECT * FROM t1;
} {1 {database is locked}} } {1 {database is locked}}
#-------------------------------------------------------------------------
# These tests - ota4-2.* - aim to verify some properties of the ota_mode
# pragma.
#
# 1. Check that UNIQUE constraints are not tested in ota_mode.
# 2. Except for (real) PRIMARY KEY constraints.
# 3. Check that all non-temporary triggers are ignored.
#
reset_db
do_execsql_test 2.1.1 {
CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
CREATE UNIQUE INDEX i1 ON t1(b);
INSERT INTO t1 VALUES(1, 2, 3);
INSERT INTO t1 VALUES(2, 4, 6);
}
do_execsql_test 2.1.2 {
PRAGMA ota_mode = 1;
INSERT INTO t1 VALUES(3, 2, 6);
UPDATE t1 SET b=2 WHERE a=2;
SELECT * FROM t1;
} {
1 2 3
2 2 6
3 2 6
}
reset_db
do_execsql_test 2.2.1 {
CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
CREATE TABLE t2(x, y, z, PRIMARY KEY(y, z)) WITHOUT ROWID;
INSERT INTO t1 VALUES(1, 2, 3);
INSERT INTO t2 VALUES(4, 5, 6);
PRAGMA ota_mode = 1;
}
do_catchsql_test 2.2.2 {
INSERT INTO t1 VALUES(1, 'two', 'three');
} {1 {UNIQUE constraint failed: t1.a}}
do_catchsql_test 2.2.3 {
INSERT INTO t2 VALUES('four', 5, 6);
} {1 {UNIQUE constraint failed: t2.y, t2.z}}
reset_db
do_execsql_test 2.3.1 {
CREATE TABLE t1(a, b, c);
CREATE TABLE log(x);
INSERT INTO t1 VALUES(1, 2, 3);
CREATE TRIGGER tr1 BEFORE INSERT ON t1 BEGIN
INSERT INTO log VALUES('permanent');
END;
CREATE TRIGGER tr2 AFTER INSERT ON t1 BEGIN
INSERT INTO log VALUES('permanent');
END;
CREATE TRIGGER tr3 BEFORE DELETE ON t1 BEGIN
INSERT INTO log VALUES('permanent');
END;
CREATE TRIGGER tr4 AFTER DELETE ON t1 BEGIN
INSERT INTO log VALUES('permanent');
END;
CREATE TRIGGER tr5 BEFORE UPDATE ON t1 BEGIN
INSERT INTO log VALUES('permanent');
END;
CREATE TRIGGER tr6 AFTER UPDATE ON t1 BEGIN
INSERT INTO log VALUES('permanent');
END;
CREATE TEMP TRIGGER ttr1 BEFORE INSERT ON t1 BEGIN
INSERT INTO log VALUES('temp');
END;
CREATE TEMP TRIGGER ttr2 AFTER INSERT ON t1 BEGIN
INSERT INTO log VALUES('temp');
END;
CREATE TEMP TRIGGER ttr3 BEFORE DELETE ON t1 BEGIN
INSERT INTO log VALUES('temp');
END;
CREATE TEMP TRIGGER ttr4 AFTER DELETE ON t1 BEGIN
INSERT INTO log VALUES('temp');
END;
CREATE TEMP TRIGGER ttr5 BEFORE UPDATE ON t1 BEGIN
INSERT INTO log VALUES('temp');
END;
CREATE TEMP TRIGGER ttr6 AFTER UPDATE ON t1 BEGIN
INSERT INTO log VALUES('temp');
END;
}
do_execsql_test 2.3.2 {
INSERT INTO t1 VALUES(4, 5, 6);
DELETE FROM t1 WHERE a = 4;
UPDATE t1 SET c = 6;
SELECT x FROM log;
} {
temp permanent temp permanent temp permanent
temp permanent temp permanent temp permanent
}
do_execsql_test 2.3.3 {
DELETE FROM log;
PRAGMA ota_mode = 1;
INSERT INTO t1 VALUES(4, 5, 6);
DELETE FROM t1 WHERE a = 4;
UPDATE t1 SET c = 6;
SELECT x FROM log;
} {temp temp temp temp temp temp}
finish_test finish_test

View File

@ -1,5 +1,5 @@
C Clarify\sthe\seffects\sof\sthe\spager_ota_mode\spragma.\sAdd\stests\sand\sfixes\sfor\sthe\ssame. C Add\stests\sand\sfixes\sfor\s"PRAGMA\sota_mode".
D 2014-09-16T20:02:41.756 D 2014-09-17T15:20:24.516
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in cf57f673d77606ab0f2d9627ca52a9ba1464146a F Makefile.in cf57f673d77606ab0f2d9627ca52a9ba1464146a
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -123,9 +123,9 @@ F ext/misc/vtshim.c babb0dc2bf116029e3e7c9a618b8a1377045303e
F ext/misc/wholenumber.c 784b12543d60702ebdd47da936e278aa03076212 F ext/misc/wholenumber.c 784b12543d60702ebdd47da936e278aa03076212
F ext/ota/ota.c d37097e92a005d3915883adefbb93019ea6f8841 F ext/ota/ota.c d37097e92a005d3915883adefbb93019ea6f8841
F ext/ota/ota1.test 7cbf37a9f6cd29320f47b041cfeb0cc1d7eaa916 F ext/ota/ota1.test 7cbf37a9f6cd29320f47b041cfeb0cc1d7eaa916
F ext/ota/ota2.test 13f76922446c62ed96192e938b8e625ebf0142fa F ext/ota/ota2.test 716f9c66e8bf8b0ad2fe3a5d8323e6cf460a2e27
F ext/ota/ota3.test 1c48b7476af1c5920db9a43e7b1476d421a463b5 F ext/ota/ota3.test 1c48b7476af1c5920db9a43e7b1476d421a463b5
F ext/ota/ota4.test ec01b0d69ad2989559a65fde74560c1cfcca8202 F ext/ota/ota4.test baf23b47748a5056c713871959cc70fc623c90e9
F ext/ota/sqlite3ota.c 668ed08dd81ff8ae1e8524b2d4bf0f2609cbf907 F ext/ota/sqlite3ota.c 668ed08dd81ff8ae1e8524b2d4bf0f2609cbf907
F ext/ota/sqlite3ota.h 39ce4dffbfcf4ade9e4526369fe2243709345c8e F ext/ota/sqlite3ota.h 39ce4dffbfcf4ade9e4526369fe2243709345c8e
F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761
@ -195,7 +195,7 @@ F src/global.c 5110fa12e09729b84eee0191c984ec4008e21937
F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5
F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094 F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094
F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08
F src/insert.c 25e63641927530eee0487c5a8bbf6e5414c4c753 F src/insert.c 887551441b3a46d964733b16a86c614d0152778d
F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d
F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e
F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770
@ -290,7 +290,7 @@ F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698
F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9
F src/threads.c 22dded4283dc4b25422f6444cdcb8d6b1ea0b5ff F src/threads.c 22dded4283dc4b25422f6444cdcb8d6b1ea0b5ff
F src/tokenize.c 3df63041994f55afeb168b463ec836e8f1c50e7c F src/tokenize.c 3df63041994f55afeb168b463ec836e8f1c50e7c
F src/trigger.c 25571661fdeae8c7f975ff40ffec205520a3f92f F src/trigger.c eb921d1292aca83d515bde5881df71df91d962d6
F src/update.c 729f6f18fc27740591d085e1172cebe311144bf0 F src/update.c 729f6f18fc27740591d085e1172cebe311144bf0
F src/utf.c 77abb5e6d27f3d236e50f7c8fff1d00e15262359 F src/utf.c 77abb5e6d27f3d236e50f7c8fff1d00e15262359
F src/util.c 4006c01772bd8d8ac4306d523bbcee41d3e392d8 F src/util.c 4006c01772bd8d8ac4306d523bbcee41d3e392d8
@ -1205,7 +1205,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P 48d201cd8b68c0377cf8a2cc6439b893f9462fe2 P decaccc37cbdcd2a663233469efdf4982a810513
R de185427497b23c6bf5f7a43a97cdd26 R d8d51626052024a717c822f3b6627467
U dan U dan
Z de73fdb4c4401b74adf143cdfee4f7e2 Z 65720a0642c813fef614e2d54b0a69b7

View File

@ -1 +1 @@
decaccc37cbdcd2a663233469efdf4982a810513 39df35c4ac65ffba76ba2c6f6727cf5e843e7517

View File

@ -1564,7 +1564,7 @@ void sqlite3CompleteInsertion(
/* If the "ota_mode" flag is set, ignore all indexes except the PK /* If the "ota_mode" flag is set, ignore all indexes except the PK
** index of WITHOUT ROWID tables. */ ** index of WITHOUT ROWID tables. */
if( (pParse->db->flags & SQLITE_OtaMode) if( (pParse->db->flags & SQLITE_OtaMode)
&& (pTab->iPKey>=0 || pIdx->idxType!=SQLITE_IDXTYPE_PRIMARYKEY) && (HasRowid(pTab) || pIdx->idxType!=SQLITE_IDXTYPE_PRIMARYKEY)
){ ){
continue; continue;
} }

View File

@ -43,10 +43,14 @@ void sqlite3DeleteTriggerStep(sqlite3 *db, TriggerStep *pTriggerStep){
** To state it another way: This routine returns a list of all triggers ** To state it another way: This routine returns a list of all triggers
** that fire off of pTab. The list will include any TEMP triggers on ** that fire off of pTab. The list will include any TEMP triggers on
** pTab as well as the triggers lised in pTab->pTrigger. ** pTab as well as the triggers lised in pTab->pTrigger.
**
** If the SQLITE_OtaMode flag is set, do not include any non-temporary
** triggers in the returned list.
*/ */
Trigger *sqlite3TriggerList(Parse *pParse, Table *pTab){ Trigger *sqlite3TriggerList(Parse *pParse, Table *pTab){
Schema * const pTmpSchema = pParse->db->aDb[1].pSchema; Schema * const pTmpSchema = pParse->db->aDb[1].pSchema;
Trigger *pList = 0; /* List of triggers to return */ Trigger *pList = 0; /* List of triggers to return */
int bOta = !!(pParse->db->flags & SQLITE_OtaMode);
if( pParse->disableTriggers ){ if( pParse->disableTriggers ){
return 0; return 0;
@ -60,13 +64,13 @@ Trigger *sqlite3TriggerList(Parse *pParse, Table *pTab){
if( pTrig->pTabSchema==pTab->pSchema if( pTrig->pTabSchema==pTab->pSchema
&& 0==sqlite3StrICmp(pTrig->table, pTab->zName) && 0==sqlite3StrICmp(pTrig->table, pTab->zName)
){ ){
pTrig->pNext = (pList ? pList : pTab->pTrigger); pTrig->pNext = ((pList || bOta) ? pList : pTab->pTrigger);
pList = pTrig; pList = pTrig;
} }
} }
} }
return (pList ? pList : pTab->pTrigger); return ((pList || bOta) ? pList : pTab->pTrigger);
} }
/* /*