MCPcopy Create free account
hub / github.com/audacity/audacity / zipfileFilter

Function zipfileFilter

lib-src/sqlite/shell.c:7120–7174  ·  view source on GitHub ↗

** xFilter callback. */

Source from the content-addressed store, hash-verified

7118** xFilter callback.
7119*/
7120static int zipfileFilter(
7121 sqlite3_vtab_cursor *cur,
7122 int idxNum, const char *idxStr,
7123 int argc, sqlite3_value **argv
7124){
7125 ZipfileTab *pTab = (ZipfileTab*)cur->pVtab;
7126 ZipfileCsr *pCsr = (ZipfileCsr*)cur;
7127 const char *zFile = 0; /* Zip file to scan */
7128 int rc = SQLITE_OK; /* Return Code */
7129 int bInMemory = 0; /* True for an in-memory zipfile */
7130
7131 zipfileResetCursor(pCsr);
7132
7133 if( pTab->zFile ){
7134 zFile = pTab->zFile;
7135 }else if( idxNum==0 ){
7136 zipfileCursorErr(pCsr, "zipfile() function requires an argument");
7137 return SQLITE_ERROR;
7138 }else if( sqlite3_value_type(argv[0])==SQLITE_BLOB ){
7139 const u8 *aBlob = (const u8*)sqlite3_value_blob(argv[0]);
7140 int nBlob = sqlite3_value_bytes(argv[0]);
7141 assert( pTab->pFirstEntry==0 );
7142 rc = zipfileLoadDirectory(pTab, aBlob, nBlob);
7143 pCsr->pFreeEntry = pTab->pFirstEntry;
7144 pTab->pFirstEntry = pTab->pLastEntry = 0;
7145 if( rc!=SQLITE_OK ) return rc;
7146 bInMemory = 1;
7147 }else{
7148 zFile = (const char*)sqlite3_value_text(argv[0]);
7149 }
7150
7151 if( 0==pTab->pWriteFd && 0==bInMemory ){
7152 pCsr->pFile = fopen(zFile, "rb");
7153 if( pCsr->pFile==0 ){
7154 zipfileCursorErr(pCsr, "cannot open file: %s", zFile);
7155 rc = SQLITE_ERROR;
7156 }else{
7157 rc = zipfileReadEOCD(pTab, 0, 0, pCsr->pFile, &pCsr->eocd);
7158 if( rc==SQLITE_OK ){
7159 if( pCsr->eocd.nEntry==0 ){
7160 pCsr->bEof = 1;
7161 }else{
7162 pCsr->iNextOff = pCsr->eocd.iOffset;
7163 rc = zipfileNext(cur);
7164 }
7165 }
7166 }
7167 }else{
7168 pCsr->bNoop = 1;
7169 pCsr->pCurrent = pCsr->pFreeEntry ? pCsr->pFreeEntry : pTab->pFirstEntry;
7170 rc = zipfileNext(cur);
7171 }
7172
7173 return rc;
7174}
7175
7176/*
7177** xBestIndex callback.

Callers

nothing calls this directly

Calls 5

zipfileResetCursorFunction · 0.85
zipfileCursorErrFunction · 0.85
zipfileLoadDirectoryFunction · 0.85
zipfileReadEOCDFunction · 0.85
zipfileNextFunction · 0.85

Tested by

no test coverage detected