From: drh Date: Fri, 30 Jan 2015 15:40:15 +0000 (+0000) Subject: Add a few simple test cases for SQLITE_TESTCTRL_INITMODE - cases which X-Git-Tag: version-3.8.9~145^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fheads%2Finitmode-testctrl;p=thirdparty%2Fsqlite.git Add a few simple test cases for SQLITE_TESTCTRL_INITMODE - cases which also test PRAGMA integrity_check. FossilOrigin-Name: 3a6e2afe408d2b0c8166d00def2048568169d87a --- diff --git a/manifest b/manifest index 776fb5e978..83c59f47c0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sINITMODE\stest-control. -D 2015-01-29T17:54:52.194 +C Add\sa\sfew\ssimple\stest\scases\sfor\sSQLITE_TESTCTRL_INITMODE\s-\scases\swhich\nalso\stest\sPRAGMA\sintegrity_check. +D 2015-01-30T15:40:15.485 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -239,7 +239,7 @@ F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 81712116e826b0089bb221b018929536b2b5406f F src/table.c e7a09215315a978057fb42c640f890160dbcc45e F src/tclsqlite.c b8014393a96a9781bb635c8b1f52fc9b77a2bfcf -F src/test1.c 00a74fbc6604e1bcd240726a9ff8d0cc123374e7 +F src/test1.c 5dcdade99e77b7b9f7760106c80a83cf50f10e1e F src/test2.c 577961fe48961b2f2e5c8b56ee50c3f459d3359d F src/test3.c 64d2afdd68feac1bb5e2ffb8226c8c639f798622 F src/test4.c d168f83cc78d02e8d35567bb5630e40dcd85ac1e @@ -655,6 +655,7 @@ F test/index7.test 917cf1e1c7439bb155abbeabec511b28945e157b F test/indexedby.test b2f22f3e693a53813aa3f50b812eb609ba6df1ec F test/indexfault.test 31d4ab9a7d2f6e9616933eb079722362a883eb1d F test/init.test 15c823093fdabbf7b531fe22cf037134d09587a7 +F test/initmode.test 38bbaefeb47e034a162856e664a0da3b95e6999b F test/insert.test 38742b5e9601c8f8d76e9b7555f7270288c2d371 F test/insert2.test 4f3a04d168c728ed5ec2c88842e772606c7ce435 F test/insert3.test 1b7db95a03ad9c5013fdf7d6722b6cd66ee55e30 @@ -1237,10 +1238,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 85dc12625d300fe48f3c096f54ebcb8b6ef4e30a -R fe787287eb356b79eb9ba31c0e138e4f -T *branch * initmode-testctrl -T *sym-initmode-testctrl * -T -sym-trunk * +P 5940af8e7872209ce41feb958643b23f7e55d258 +R 47cbd38aaccdc229ecba207f260cbca2 U drh -Z e02e8497217bad1b69deabc72f8cd27d +Z f10513d756c3deb9c12d56e187b46090 diff --git a/manifest.uuid b/manifest.uuid index 60ead15a06..18f40e05d3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5940af8e7872209ce41feb958643b23f7e55d258 \ No newline at end of file +3a6e2afe408d2b0c8166d00def2048568169d87a \ No newline at end of file diff --git a/src/test1.c b/src/test1.c index d86ec1e84d..b9503cf394 100644 --- a/src/test1.c +++ b/src/test1.c @@ -5914,7 +5914,8 @@ static int test_test_control( int i; } aVerb[] = { { "SQLITE_TESTCTRL_LOCALTIME_FAULT", SQLITE_TESTCTRL_LOCALTIME_FAULT }, - { "SQLITE_TESTCTRL_SORTER_MMAP", SQLITE_TESTCTRL_SORTER_MMAP }, + { "SQLITE_TESTCTRL_SORTER_MMAP", SQLITE_TESTCTRL_SORTER_MMAP }, + { "SQLITE_TESTCTRL_INITMODE", SQLITE_TESTCTRL_INITMODE }, }; int iVerb; int iFlag; @@ -5955,6 +5956,21 @@ static int test_test_control( sqlite3_test_control(SQLITE_TESTCTRL_SORTER_MMAP, db, val); break; } + + case SQLITE_TESTCTRL_INITMODE: { + int fBusy, iDb, newTnum; + sqlite3 *db; + if( objc!=6 ){ + Tcl_WrongNumArgs(interp, 2, objv, "DB fBusy iDb newTnum"); + return TCL_ERROR; + } + if( getDbPointer(interp, Tcl_GetString(objv[2]), &db) ) return TCL_ERROR; + if( Tcl_GetIntFromObj(interp, objv[3], &fBusy) ) return TCL_ERROR; + if( Tcl_GetIntFromObj(interp, objv[4], &iDb) ) return TCL_ERROR; + if( Tcl_GetIntFromObj(interp, objv[5], &newTnum) ) return TCL_ERROR; + sqlite3_test_control(SQLITE_TESTCTRL_INITMODE, db, fBusy, iDb, newTnum); + break; + } } Tcl_ResetResult(interp); diff --git a/test/initmode.test b/test/initmode.test new file mode 100644 index 0000000000..ce3f675857 --- /dev/null +++ b/test/initmode.test @@ -0,0 +1,100 @@ +# 2015-01-30 +# +# 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 tests for SQLite library. +# +# The focus of this file is adding extra entries in the symbol table +# using sqlite3_test_control(SQLITE_TESTCTRL_INITMODE) and verifying that +# SQLite handles those as expected. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix initmode + +# Create a bunch of data to sort against +# +do_test initmode-1.0 { + execsql { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, d NOT NULL); + CREATE INDEX t1b ON t1(b); + CREATE UNIQUE INDEX t1c ON t1(c); + WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<30) + INSERT INTO t1(a,b,c,d) SELECT i,1000+i,2000+i,3000+i FROM c; + } + set t1_root [db one {SELECT rootpage FROM sqlite_master WHERE name='t1'}] + set t1a_root [db one {SELECT rootpage FROM sqlite_master WHERE name='t1a'}] + set t1b_root [db one {SELECT rootpage FROM sqlite_master WHERE name='t1b'}] + + # Create a shadow table that uses the same b-tree as t1 but which does + # not have the indexes + # + sqlite3_test_control SQLITE_TESTCTRL_INITMODE db 1 0 $t1_root + db eval {CREATE TABLE xt1(a,b,c,d)} + sqlite3_test_control SQLITE_TESTCTRL_INITMODE db 0 0 0 + + # Create triggers to record changes to xt1. + # + db eval { + CREATE TEMP TABLE chnglog(desc TEXT); + CREATE TEMP TRIGGER xt1_del AFTER DELETE ON xt1 BEGIN + INSERT INTO chnglog VALUES( + printf('DELETE t1: rowid=%d, a=%s, b=%s, c=%s, d=%s', + old.rowid, quote(old.a), quote(old.b), quote(old.c), + quote(old.d))); + END; + CREATE TEMP TRIGGER xt1_ins AFTER INSERT ON xt1 BEGIN + INSERT INTO chnglog VALUES( + printf('INSERT t1: rowid=%d, a=%s, b=%s, c=%s, d=%s', + new.rowid, quote(new.a), quote(new.b), quote(new.c), + quote(new.d))); + END; + } +} {} + +# The xt1 table has separate xt1.rowid and xt1.a columns. The xt1.rowid +# column corresponds to t1.rowid and t1.a, but the xt1.a column is always +# NULL +# +do_execsql_test initmode-1.1 { + SELECT rowid FROM xt1 WHERE a IS NOT NULL; +} {} +do_execsql_test initmode-1.2 { + SELECT a,b,c,d FROM t1 EXCEPT SELECT rowid,b,c,d FROM xt1; + SELECT rowid,b,c,d FROM xt1 EXCEPT SELECT a,b,c,d FROM t1; +} {} + + +# Make changes via the xt1 shadow table. This will not update the +# indexes on t1 nor check the uniqueness constraint on t1.c nor check +# the NOT NULL constraint on t1.d, resulting in a logically inconsistent +# database. +# +do_execsql_test initmode-1.3 { + DELETE FROM xt1 WHERE rowid=5; + INSERT INTO xt1(rowid,a,b,c,d) VALUES(99,'hello',1099,2022,NULL); + SELECT * FROM chnglog ORDER BY rowid; +} [list \ + {DELETE t1: rowid=5, a=NULL, b=1005, c=2005, d=3005} \ + {INSERT t1: rowid=99, a='hello', b=1099, c=2022, d=NULL} \ +] + +do_execsql_test initmode-1.4a { + PRAGMA integrity_check; +} {/NULL value in t1.d/} +do_execsql_test initmode-1.4b { + PRAGMA integrity_check; +} {/row # missing from index t1b/} +do_execsql_test initmode-1.4c { + PRAGMA integrity_check; +} {/row # missing from index t1c/} + +finish_test