1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-05 15:55:57 +03:00

Add code to test8.c to check that the correct idxNum value is passed to the xFilter method. (CVS 3241)

FossilOrigin-Name: 77bcaf99b3aba0f482e0504a5409c8f79cc441b4
This commit is contained in:
danielk1977
2006-06-14 10:55:52 +00:00
parent a8ed652f8f
commit 98331538bf
3 changed files with 28 additions and 8 deletions

View File

@@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test8.c,v 1.15 2006/06/14 10:47:04 danielk1977 Exp $
** $Id: test8.c,v 1.16 2006/06/14 10:55:53 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -322,6 +322,24 @@ static int echoRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
return SQLITE_OK;
}
/*
** Compute a simple hash of the null terminated string zString.
**
** This module uses only sqlite3_index_info.idxStr, not
** sqlite3_index_info.idxNum. So to test idxNum, when idxStr is set
** in echoBestIndex(), idxNum is set to the corresponding hash value.
** In echoFilter(), code assert()s that the supplied idxNum value is
** indeed the hash of the supplied idxStr.
*/
static int hashString(const char *zString){
int val = 0;
int ii;
for(ii=0; zString[ii]; ii++){
val = (val << 3) + (int)zString[ii];
}
return val;
}
static int echoFilter(
sqlite3_vtab_cursor *pVtabCursor,
@@ -335,6 +353,7 @@ static int echoFilter(
echo_vtab *pVtab = (echo_vtab *)pVtabCursor->pVtab;
sqlite3 *db = pVtab->db;
assert( idxNum==hashString(idxStr) );
sqlite3_finalize(pCur->pStmt);
pCur->pStmt = 0;
rc = sqlite3_prepare(db, idxStr, -1, &pCur->pStmt, 0);
@@ -448,6 +467,7 @@ static int echoBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
appendToEchoModule(pVtab->interp, "xBestIndex");;
appendToEchoModule(pVtab->interp, zQuery);
pIdxInfo->idxNum = hashString(zQuery);
pIdxInfo->idxStr = zQuery;
pIdxInfo->needToFreeIdxStr = 1;
pIdxInfo->estimatedCost = 1.0;