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

Add support for INSERT OR REPLACE and INSERT OR IGNORE on the zipfile

extension.

FossilOrigin-Name: 8ad35d483e4293d5571eeacc20fd26cdc4064fbee7b63d974879d507a0ee5792
This commit is contained in:
drh
2018-03-10 14:17:01 +00:00
parent 41a6f2cb6d
commit 42f3c5ff25
4 changed files with 56 additions and 10 deletions

View File

@ -268,6 +268,7 @@ typedef struct ZipfileTab ZipfileTab;
struct ZipfileTab {
sqlite3_vtab base; /* Base class - must be first */
char *zFile; /* Zip file this table accesses (may be NULL) */
sqlite3 *db; /* Host database connection */
u8 *aBuffer; /* Temporary buffer used for various tasks */
ZipfileCsr *pCsrList; /* List of cursors */
@ -360,6 +361,7 @@ static int zipfileConnect(
pNew = (ZipfileTab*)sqlite3_malloc(nByte+nFile);
if( pNew==0 ) return SQLITE_NOMEM;
memset(pNew, 0, nByte+nFile);
pNew->db = db;
pNew->aBuffer = (u8*)&pNew[1];
if( zFile ){
pNew->zFile = (char*)&pNew->aBuffer[ZIPFILE_BUFFER_SIZE];
@ -1616,8 +1618,20 @@ static int zipfileUpdate(
ZipfileEntry *p;
for(p=pTab->pFirstEntry; p; p=p->pNext){
if( zipfileComparePath(p->cds.zFile, zPath, nPath)==0 ){
zipfileTableErr(pTab, "duplicate name: \"%s\"", zPath);
rc = SQLITE_CONSTRAINT;
switch( sqlite3_vtab_on_conflict(pTab->db) ){
case SQLITE_IGNORE: {
goto zipfile_update_done;
}
case SQLITE_REPLACE: {
pOld = p;
break;
}
default: {
zipfileTableErr(pTab, "duplicate name: \"%s\"", zPath);
rc = SQLITE_CONSTRAINT;
break;
}
}
break;
}
}
@ -1661,6 +1675,7 @@ static int zipfileUpdate(
zipfileEntryFree(pOld);
}
zipfile_update_done:
sqlite3_free(pFree);
sqlite3_free(zFree);
return rc;