From b08a1efae52f0252fcde355fffaad4aa4cf3cdfd Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 15 Apr 2011 19:18:57 +0000 Subject: [PATCH] Improve coverage of session module. FossilOrigin-Name: 3dfd1d63bddfa9bd9018eb00bee1d496379630b5 --- ext/session/session5.test | 51 ++++++++++++++++++++++++++++++++++++ ext/session/sqlite3session.c | 29 +++++++++++--------- manifest | 14 +++++----- manifest.uuid | 2 +- 4 files changed, 76 insertions(+), 20 deletions(-) diff --git a/ext/session/session5.test b/ext/session/session5.test index 9cce67dcc1..1e67e1d325 100644 --- a/ext/session/session5.test +++ b/ext/session/session5.test @@ -183,6 +183,13 @@ do_concat_test 2.1 { } { SELECT indirect(0); UPDATE abc SET a='one point six' WHERE c = 'three'; +} { + CREATE TABLE x1(a, b, PRIMARY KEY(a)); + SELECT indirect(1); + INSERT INTO x1 VALUES(1, 2); +} { + SELECT indirect(1); + UPDATE x1 SET b = 3 WHERE a = 1; } catch {db close} @@ -204,6 +211,50 @@ do_concat_test 2.2 { INSERT INTO t2 VALUES('x', 'y'); } +do_test 2.3.0 { + catch {db close} + forcedelete test.db + sqlite3 db test.db + + set sql1 "" + set sql2 "" + for {set i 1} {$i < 120} {incr i} { + append sql1 "INSERT INTO x1 VALUES($i*4, $i);" + } + for {set i 1} {$i < 120} {incr i} { + append sql2 "DELETE FROM x1 WHERE a = $i*4;" + } + + set {} {} +} {} +do_concat_test 2.3 { + CREATE TABLE x1(a PRIMARY KEY, b) +} $sql1 $sql2 $sql1 $sql2 + +do_concat_test 2.4 { + CREATE TABLE x2(a PRIMARY KEY, b); + CREATE TABLE x3(a PRIMARY KEY, b); + + INSERT INTO x2 VALUES('a', 'b'); + INSERT INTO x2 VALUES('x', 'y'); + INSERT INTO x3 VALUES('a', 'b'); +} { + INSERT INTO x2 VALUES('c', 'd'); + INSERT INTO x3 VALUES('e', 'f'); + INSERT INTO x3 VALUES('x', 'y'); +} + +do_concat_test 2.5 { + UPDATE x3 SET b = 'Y' WHERE a = 'x' +} { + DELETE FROM x3 WHERE a = 'x' +} { + DELETE FROM x2 WHERE a = 'a' +} { + INSERT INTO x2 VALUES('a', 'B'); +} + + #------------------------------------------------------------------------- # Test that schema incompatibilities are detected correctly. # diff --git a/ext/session/sqlite3session.c b/ext/session/sqlite3session.c index 41665ce9e9..bad6240a1f 100644 --- a/ext/session/sqlite3session.c +++ b/ext/session/sqlite3session.c @@ -2793,13 +2793,21 @@ static int sessionChangeMerge( pNew->bIndirect = (bIndirect && pExist->bIndirect); aCsr = pNew->aRecord = (u8 *)&pNew[1]; - if( op1==SQLITE_INSERT && op2==SQLITE_UPDATE ){ + if( op1==SQLITE_INSERT ){ /* INSERT + UPDATE */ u8 *a1 = aRec; + assert( op2==SQLITE_UPDATE ); pNew->bInsert = SQLITE_INSERT; sessionReadRecord(&a1, pTab->nCol, 0); sessionMergeRecord(&aCsr, pTab, pExist->aRecord, a1); - } - else if( op1==SQLITE_UPDATE && op2==SQLITE_UPDATE ){ + }else if( op1==SQLITE_DELETE ){ /* DELETE + INSERT */ + assert( op2==SQLITE_INSERT ); + pNew->bInsert = SQLITE_UPDATE; + if( 0==sessionMergeUpdate(&aCsr, pTab, pExist->aRecord, 0, aRec, 0) ){ + sqlite3_free(pNew); + pNew = 0; + } + }else if( op2==SQLITE_UPDATE ){ /* UPDATE + UPDATE */ + assert( op1==SQLITE_UPDATE ); u8 *a1 = pExist->aRecord; u8 *a2 = aRec; sessionReadRecord(&a1, pTab->nCol, 0); @@ -2809,18 +2817,11 @@ static int sessionChangeMerge( sqlite3_free(pNew); pNew = 0; } - } - else if( op1==SQLITE_UPDATE && op2==SQLITE_DELETE ){ + }else{ /* UPDATE + DELETE */ + assert( op1==SQLITE_UPDATE && op2==SQLITE_DELETE ); pNew->bInsert = SQLITE_DELETE; sessionMergeRecord(&aCsr, pTab, aRec, pExist->aRecord); } - else if( op1==SQLITE_DELETE && op2==SQLITE_INSERT ){ - pNew->bInsert = SQLITE_UPDATE; - if( 0==sessionMergeUpdate(&aCsr, pTab, pExist->aRecord, 0, aRec, 0) ){ - sqlite3_free(pNew); - pNew = 0; - } - } if( pNew ){ pNew->nRecord = (aCsr - pNew->aRecord); @@ -2860,6 +2861,10 @@ int sessionConcatChangeset( assert( pIter->apValue==0 ); sqlite3changeset_op(pIter, &zNew, &nCol, &op, &bIndirect); + assert( zNew>=(char *)pChangeset && zNew-nChangeset<((char *)pChangeset) ); + assert( !pTab || pTab->zName-nChangeset<(char *)pChangeset ); + assert( !pTab || zNew>=pTab->zName ); + if( !pTab || zNew!=pTab->zName ){ /* Search the list for a matching table */ int nNew = strlen(zNew); diff --git a/manifest b/manifest index b165b9433c..bc49322d17 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stests\sand\sfixes\sfor\sOOM\shandling\sin\ssqlite3changeset_concat(). -D 2011-04-15T16:03:32.057 +C Improve\scoverage\sof\ssession\smodule. +D 2011-04-15T19:18:57.799 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 7a4d9524721d40ef9ee26f93f9bd6a51dba106f2 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -103,10 +103,10 @@ F ext/session/session1.test 7a92a2a6f531aef1e9764ffb7f983fb8b315376d F ext/session/session2.test c3e5f78d5eb988e35cc2ba9ce3678f706283cfdb F ext/session/session3.test bfa2376db7cbb2ac69496f84d93a8d81b13110d3 F ext/session/session4.test a6ed685da7a5293c5d6f99855bcf41dbc352ca84 -F ext/session/session5.test 940d77c748808769cac50fb62bb674aa84e472f2 +F ext/session/session5.test 525503799d56124a31bedbd7895c1e668d18420d F ext/session/session_common.tcl 1539d8973b2aea0025c133eb0cc4c89fcef541a5 F ext/session/sessionfault.test 2766cd620f1793f0e54f1e3859a184bcea55bad4 -F ext/session/sqlite3session.c 08573805932a9db4158f36663e01747d0ff69342 +F ext/session/sqlite3session.c 4c44da92750d4b31bcbed25428be7167cddccf84 F ext/session/sqlite3session.h 665f5591562e3c71eb3d0da26f1a1efae26f7bcf F ext/session/test_session.c f4d1dca94db71ec2177ee61eab51e718e58476d7 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x @@ -938,7 +938,7 @@ F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 343b64517d244b75097e38342dc273eb5a52915b -R c818789c65113df118a04c3a29f3e5ba +P df0b2d21dcd81679e55b24866f97568019932983 +R b4d7dfa6bf40d53e75863a5a6b9fd8ce U dan -Z 7081c2709375635b8446c7ef8a86300e +Z 2d321dbf5ee44d87c34feecb146a5235 diff --git a/manifest.uuid b/manifest.uuid index 72289d19b5..8ae1676306 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -df0b2d21dcd81679e55b24866f97568019932983 \ No newline at end of file +3dfd1d63bddfa9bd9018eb00bee1d496379630b5 \ No newline at end of file