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

Change zipfile to be a WITHOUT ROWID virtual table and table-valued function.

FossilOrigin-Name: 931201f64e04247ed613a0301fcc86c3a337c2ed162c6370a80c67a1dd919e7c
This commit is contained in:
dan
2018-01-11 17:33:48 +00:00
parent 5e9bbe1924
commit 66a3a91aa6
4 changed files with 19 additions and 22 deletions

View File

@ -57,7 +57,7 @@ typedef unsigned long u32;
static const char ZIPFILE_SCHEMA[] =
"CREATE TABLE y("
"name," /* 0: Name of file in zip archive */
"name PRIMARY KEY," /* 0: Name of file in zip archive */
"mode," /* 1: POSIX mode for file */
"mtime," /* 2: Last modification time (secs since 1970)*/
"sz," /* 3: Size of object */
@ -65,7 +65,7 @@ static const char ZIPFILE_SCHEMA[] =
"data," /* 5: Uncompressed data */
"method," /* 6: Compression method (integer) */
"file HIDDEN" /* 7: Name of zip file */
");";
") WITHOUT ROWID;";
#define ZIPFILE_F_COLUMN_IDX 7 /* Index of column "file" in the above */
#define ZIPFILE_BUFFER_SIZE (64*1024)
@ -223,7 +223,6 @@ struct ZipfileLFH {
typedef struct ZipfileEntry ZipfileEntry;
struct ZipfileEntry {
char *zPath; /* Path of zipfile entry */
i64 iRowid; /* Rowid for this value if queried */
u8 *aCdsEntry; /* Buffer containing entire CDS entry */
int nCdsEntry; /* Size of buffer aCdsEntry[] in bytes */
int bDeleted; /* True if entry has been deleted */
@ -830,12 +829,7 @@ static int zipfileColumn(
** Return the rowid for the current row.
*/
static int zipfileRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
ZipfileCsr *pCsr = (ZipfileCsr*)cur;
if( pCsr->pCurrent ){
*pRowid = pCsr->pCurrent->iRowid;
}else{
*pRowid = pCsr->cds.iOffset;
}
assert( 0 );
return SQLITE_OK;
}
@ -999,11 +993,9 @@ static void zipfileAddEntry(ZipfileTab *pTab, ZipfileEntry *pNew){
assert( (pTab->pFirstEntry==0)==(pTab->pLastEntry==0) );
assert( pNew->pNext==0 );
if( pTab->pFirstEntry==0 ){
pNew->iRowid = 1;
pTab->pFirstEntry = pTab->pLastEntry = pNew;
}else{
assert( pTab->pLastEntry->pNext==0 );
pNew->iRowid = pTab->pLastEntry->iRowid+1;
pTab->pLastEntry->pNext = pNew;
pTab->pLastEntry = pNew;
}
@ -1251,10 +1243,11 @@ static int zipfileUpdate(
if( nVal>1 ){
return SQLITE_CONSTRAINT;
}else{
i64 iDelete = sqlite3_value_int64(apVal[0]);
const char *zDelete = (const char*)sqlite3_value_text(apVal[0]);
int nDelete = strlen(zDelete);
ZipfileEntry *p;
for(p=pTab->pFirstEntry; p; p=p->pNext){
if( p->iRowid==iDelete ){
if( zipfileComparePath(p->zPath, zDelete, nDelete)==0 ){
p->bDeleted = 1;
break;
}