mirror of
https://github.com/sqlite/sqlite.git
synced 2026-01-06 08:01:16 +03:00
Improved error messages from the zipfile extension.
FossilOrigin-Name: f634a7e386918b829389f20c330d312315fdd61125cd2c5f66cf17a5d74bce49
This commit is contained in:
@@ -473,9 +473,17 @@ static int zipfileClose(sqlite3_vtab_cursor *cur){
|
||||
** Set the error message for the virtual table associated with cursor
|
||||
** pCsr to the results of vprintf(zFmt, ...).
|
||||
*/
|
||||
static void zipfileSetErrmsg(ZipfileCsr *pCsr, const char *zFmt, ...){
|
||||
static void zipfileTableErr(ZipfileTab *pTab, const char *zFmt, ...){
|
||||
va_list ap;
|
||||
va_start(ap, zFmt);
|
||||
sqlite3_free(pTab->base.zErrMsg);
|
||||
pTab->base.zErrMsg = sqlite3_vmprintf(zFmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
static void zipfileCursorErr(ZipfileCsr *pCsr, const char *zFmt, ...){
|
||||
va_list ap;
|
||||
va_start(ap, zFmt);
|
||||
sqlite3_free(pCsr->base.pVtab->zErrMsg);
|
||||
pCsr->base.pVtab->zErrMsg = sqlite3_vmprintf(zFmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
@@ -1238,7 +1246,7 @@ static int zipfileFilter(
|
||||
if( pTab->zFile ){
|
||||
zFile = pTab->zFile;
|
||||
}else if( idxNum==0 ){
|
||||
zipfileSetErrmsg(pCsr, "zipfile() function requires an argument");
|
||||
zipfileCursorErr(pCsr, "zipfile() function requires an argument");
|
||||
return SQLITE_ERROR;
|
||||
}else if( sqlite3_value_type(argv[0])==SQLITE_BLOB ){
|
||||
const u8 *aBlob = (const u8*)sqlite3_value_blob(argv[0]);
|
||||
@@ -1256,7 +1264,7 @@ static int zipfileFilter(
|
||||
if( 0==pTab->pWriteFd && 0==bInMemory ){
|
||||
pCsr->pFile = fopen(zFile, "rb");
|
||||
if( pCsr->pFile==0 ){
|
||||
zipfileSetErrmsg(pCsr, "cannot open file: %s", zFile);
|
||||
zipfileCursorErr(pCsr, "cannot open file: %s", zFile);
|
||||
rc = SQLITE_ERROR;
|
||||
}else{
|
||||
rc = zipfileReadEOCD(pTab, 0, 0, pCsr->pFile, &pCsr->eocd);
|
||||
@@ -1405,6 +1413,7 @@ static int zipfileGetMode(
|
||||
if( ((mode & S_IFDIR)==0)==bIsDir ){
|
||||
/* The "mode" attribute is a directory, but data has been specified.
|
||||
** Or vice-versa - no data but "mode" is a file or symlink. */
|
||||
*pzErr = sqlite3_mprintf("zipfile: mode does not match data");
|
||||
return SQLITE_CONSTRAINT;
|
||||
}
|
||||
*pMode = mode;
|
||||
@@ -1535,9 +1544,12 @@ static int zipfileUpdate(
|
||||
|
||||
if( nVal>1 ){
|
||||
/* Check that "sz" and "rawdata" are both NULL: */
|
||||
if( sqlite3_value_type(apVal[5])!=SQLITE_NULL
|
||||
|| sqlite3_value_type(apVal[6])!=SQLITE_NULL
|
||||
){
|
||||
if( sqlite3_value_type(apVal[5])!=SQLITE_NULL ){
|
||||
zipfileTableErr(pTab, "sz must be NULL");
|
||||
rc = SQLITE_CONSTRAINT;
|
||||
}
|
||||
if( sqlite3_value_type(apVal[6])!=SQLITE_NULL ){
|
||||
zipfileTableErr(pTab, "rawdata must be NULL");
|
||||
rc = SQLITE_CONSTRAINT;
|
||||
}
|
||||
|
||||
@@ -1557,6 +1569,7 @@ static int zipfileUpdate(
|
||||
pData = aIn;
|
||||
nData = nIn;
|
||||
if( iMethod!=0 && iMethod!=8 ){
|
||||
zipfileTableErr(pTab, "unknown compression method: %d", iMethod);
|
||||
rc = SQLITE_CONSTRAINT;
|
||||
}else{
|
||||
if( bAuto || iMethod ){
|
||||
@@ -1603,6 +1616,7 @@ 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;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user