From: dan Date: Tue, 20 Mar 2018 13:26:01 +0000 (+0000) Subject: Fix handling of "UPDATE OR REPLACE" statements run on zipfile virtual tables. X-Git-Tag: version-3.23.0~45^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fheads%2FtestFixes;p=thirdparty%2Fsqlite.git Fix handling of "UPDATE OR REPLACE" statements run on zipfile virtual tables. FossilOrigin-Name: 9a5ef341de2bd2fc4657a510f48159f7876f58d340b457b4272a71d389f88da3 --- diff --git a/ext/misc/zipfile.c b/ext/misc/zipfile.c index b3c4903758..50270593eb 100644 --- a/ext/misc/zipfile.c +++ b/ext/misc/zipfile.c @@ -1500,6 +1500,19 @@ static u32 zipfileGetTime(sqlite3_value *pVal){ return (u32)sqlite3_value_int64(pVal); } +/* +** Unless it is NULL, entry pOld is currently part of the pTab->pFirstEntry +** linked list. Remove it from the list and free the object. +*/ +static void zipfileRemoveEntryFromList(ZipfileTab *pTab, ZipfileEntry *pOld){ + if( pOld ){ + ZipfileEntry **pp; + for(pp=&pTab->pFirstEntry; (*pp)!=pOld; pp=&((*pp)->pNext)); + *pp = (*pp)->pNext; + zipfileEntryFree(pOld); + } +} + /* ** xUpdate method. */ @@ -1524,6 +1537,7 @@ static int zipfileUpdate( u8 *pFree = 0; /* Free this */ char *zFree = 0; /* Also free this */ ZipfileEntry *pOld = 0; + ZipfileEntry *pOld2 = 0; int bUpdate = 0; /* True for an update that modifies "name" */ int bIsDir = 0; u32 iCrc32 = 0; @@ -1631,7 +1645,7 @@ static int zipfileUpdate( goto zipfile_update_done; } case SQLITE_REPLACE: { - pOld = p; + pOld2 = p; break; } default: { @@ -1669,18 +1683,17 @@ static int zipfileUpdate( } } - if( rc==SQLITE_OK && pOld ){ - ZipfileEntry **pp; + if( rc==SQLITE_OK && (pOld || pOld2) ){ ZipfileCsr *pCsr; for(pCsr=pTab->pCsrList; pCsr; pCsr=pCsr->pCsrNext){ - if( pCsr->pCurrent==pOld ){ - pCsr->pCurrent = pOld->pNext; + if( pCsr->pCurrent && (pCsr->pCurrent==pOld || pCsr->pCurrent==pOld2) ){ + pCsr->pCurrent = pCsr->pCurrent->pNext; pCsr->bNoop = 1; } } - for(pp=&pTab->pFirstEntry; (*pp)!=pOld; pp=&((*pp)->pNext)); - *pp = (*pp)->pNext; - zipfileEntryFree(pOld); + + zipfileRemoveEntryFromList(pTab, pOld); + zipfileRemoveEntryFromList(pTab, pOld2); } zipfile_update_done: diff --git a/manifest b/manifest index ba15cbcb41..2f317cd34d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\stest\scase\sfor\sthe\sfix\son\sthis\sbranch. -D 2018-03-20T12:12:06.326 +C Fix\shandling\sof\s"UPDATE\sOR\sREPLACE"\sstatements\srun\son\szipfile\svirtual\stables. +D 2018-03-20T13:26:01.034 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -304,7 +304,7 @@ F ext/misc/vfsstat.c bf10ef0bc51e1ad6756629e1edb142f7a8db1178 F ext/misc/vtablog.c 31d0d8f4406795679dcd3a67917c213d3a2a5fb3ea5de35f6e773491ed7e13c9 F ext/misc/vtshim.c 1976e6dd68dd0d64508c91a6dfab8e75f8aaf6cd F ext/misc/wholenumber.c 784b12543d60702ebdd47da936e278aa03076212 -F ext/misc/zipfile.c e8c31e8be9f7a0216b4838343363e90e38ab9886f1ace1fb3dd85a92b1f2ac8b +F ext/misc/zipfile.c 316c771140fe54c17729138f139c7d94b13674b375ccfbb1e6e30202d835e8c8 F ext/misc/zorder.c b0ff58fa643afa1d846786d51ea8d5c4b6b35aa0254ab5a82617db92f3adda64 F ext/rbu/rbu.c ea7d1b7eb44c123a2a619332e19fe5313500705c4a58aaa1887905c0d83ffc2e F ext/rbu/rbu1.test 43836fac8c7179a358eaf38a8a1ef3d6e6285842 @@ -1612,7 +1612,7 @@ F test/writecrash.test f1da7f7adfe8d7f09ea79b42e5ca6dcc41102f27f8e334ad71539501d F test/zeroblob.test 3857870fe681b8185654414a9bccfde80b62a0fa F test/zerodamage.test 9c41628db7e8d9e8a0181e59ea5f189df311a9f6ce99cc376dc461f66db6f8dc F test/zipfile.test 2a923f6ead6a0f9b61d936881f3ee2aeaabe15fc65c196456f58ea9b4b450f9b -F test/zipfile2.test f611e537dbbc41d1a372fe8b27675d8edce57e1fd4d7c98bd5a636f4e9ad22ca +F test/zipfile2.test fc2f08d5ec19c18c83289fbed32e378dc5116519972166e57a244da7bf2e5805 F test/zipfilefault.test 44d4d7a7f7cca7521d569d7f71026b241d65a6b1757aa409c1a168827edbbc2c F tool/GetFile.cs a15e08acb5dd7539b75ba23501581d7c2b462cb5 F tool/GetTclKit.bat 8995df40c4209808b31f24de0b58f90930239a234f7591e3675d45bfbb990c5d @@ -1712,7 +1712,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P cf78a882799424610209e9ac5e76771db3f5e6704ffa181f9598eb0986d93eb8 -R 958eea6484ac8b1f82316e81b3fed621 +P 7834cf6c28c63f6ca0e29a508c0f6e3ec9c5c48715344c2db99a9866e92ef205 +R 0676d2c36dd5dc602d3c6343c630c1e9 U dan -Z 23959e9d81ae20f5afbec072c04d2b8a +Z 67bd751f2f713e6278cdb7ebdf4ff3a3 diff --git a/manifest.uuid b/manifest.uuid index 9177bec341..a74146b095 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7834cf6c28c63f6ca0e29a508c0f6e3ec9c5c48715344c2db99a9866e92ef205 \ No newline at end of file +9a5ef341de2bd2fc4657a510f48159f7876f58d340b457b4272a71d389f88da3 \ No newline at end of file diff --git a/test/zipfile2.test b/test/zipfile2.test index 7c400646f7..73ec333b0b 100644 --- a/test/zipfile2.test +++ b/test/zipfile2.test @@ -234,6 +234,13 @@ do_catchsql_test 6.2 { UPDATE temp.zip set name=name||'new' where name='test'; } {1 {duplicate name: "testnew"}} +forcedelete test.zip +do_execsql_test 6.3 { + INSERT INTO temp.zip (name,data) VALUES ('test1','test'); + INSERT INTO temp.zip (name,data) VALUES ('test2','test'); + UPDATE OR REPLACE zip SET name='test2' WHERE name='test1'; + SELECT name FROM zip; +} {test2} finish_test