Index: ext/misc/zipfile.c ================================================================== --- ext/misc/zipfile.c +++ ext/misc/zipfile.c @@ -1522,11 +1522,11 @@ int nData = 0; /* Size of pData buffer in bytes */ int iMethod = 0; /* Compression method for new entry */ u8 *pFree = 0; /* Free this */ char *zFree = 0; /* Also free this */ ZipfileEntry *pOld = 0; - int bUpdate = 0; + int bUpdate = 0; /* True for an update that modifies "name" */ int bIsDir = 0; u32 iCrc32 = 0; if( pTab->pWriteFd==0 ){ rc = zipfileBegin(pVtab); Index: test/zipfile2.test ================================================================== --- test/zipfile2.test +++ test/zipfile2.test @@ -207,9 +207,33 @@ set hex [string map {6e6f7461646972 6e6f746164692f} $hex] set blob2 [binary decode hex $hex] execsql { SELECT name, data IS NULL FROM zipfile($blob2) } } {notadi/ 1} + +#------------------------------------------------------------------------- +# Test that duplicate entries may not be created using UPDATE +# statements. +# +forcedelete test.zip +do_execsql_test 6.0 { + CREATE VIRTUAL TABLE temp.zip USING zipfile('test.zip'); + INSERT INTO temp.zip (name,data) VALUES ('test1','test'); + INSERT INTO temp.zip (name,data) VALUES ('test2','test'); +} +do_catchsql_test 6.1 { + UPDATE temp.zip SET name='test1' WHERE name='test2' +} {1 {duplicate name: "test1"}} + +forcedelete test.zip +do_catchsql_test 6.2 { + DROP TABLE zip; + CREATE VIRTUAL TABLE temp.zip USING zipfile('test.zip'); + INSERT INTO temp.zip (name,data) VALUES ('test','test'); + UPDATE temp.zip set name=name||'new' where name='test'; + INSERT INTO temp.zip (name,data) VALUES ('test','test'); + UPDATE temp.zip set name=name||'new' where name='test'; +} {1 {duplicate name: "testnew"}} finish_test