The FTS3 amalgamation can now be appended to the SQLite amalgamation to

generate a single source file that contains both components. (CVS 4558)

FossilOrigin-Name: 0fc61f99b54bd269fcc011f448b9b971e902cb01
This commit is contained in:
drh 2007-11-24 00:41:52 +00:00
parent 0f31c45c10
commit 8255feca02
5 changed files with 120 additions and 123 deletions

View File

@ -287,7 +287,6 @@
#include "fts3.h"
#include "fts3_hash.h"
#include "fts3_tokenizer.h"
#include "sqlite3.h"
#ifndef SQLITE_CORE
#include "sqlite3ext.h"
SQLITE_EXTENSION_INIT1
@ -308,9 +307,9 @@
*/
#if 0
# define TRACE(A) printf A; fflush(stdout)
# define FTSTRACE(A) printf A; fflush(stdout)
#else
# define TRACE(A)
# define FTSTRACE(A)
#endif
/*
@ -391,7 +390,7 @@ enum {
/* Write a 64-bit variable-length integer to memory starting at p[0].
* The length of data written will be between 1 and VARINT_MAX bytes.
* The number of bytes written is returned. */
static int putVarint(char *p, sqlite_int64 v){
static int fts3PutVarint(char *p, sqlite_int64 v){
unsigned char *q = (unsigned char *) p;
sqlite_uint64 vu = v;
do{
@ -406,7 +405,7 @@ static int putVarint(char *p, sqlite_int64 v){
/* Read a 64-bit variable-length integer from memory starting at p[0].
* Return the number of bytes read, or 0 on error.
* The value is stored in *v. */
static int getVarint(const char *p, sqlite_int64 *v){
static int fts3GetVarint(const char *p, sqlite_int64 *v){
const unsigned char *q = (const unsigned char *) p;
sqlite_uint64 x = 0, y = 1;
while( (*q & 0x80) == 0x80 ){
@ -422,9 +421,9 @@ static int getVarint(const char *p, sqlite_int64 *v){
return (int) (q - (unsigned char *)p);
}
static int getVarint32(const char *p, int *pi){
static int fts3GetVarint32(const char *p, int *pi){
sqlite_int64 i;
int ret = getVarint(p, &i);
int ret = fts3GetVarint(p, &i);
*pi = (int) i;
assert( *pi==i );
return ret;
@ -616,13 +615,13 @@ static int dlrAllDataBytes(DLReader *pReader){
*/
static const char *dlrPosData(DLReader *pReader){
sqlite_int64 iDummy;
int n = getVarint(pReader->pData, &iDummy);
int n = fts3GetVarint(pReader->pData, &iDummy);
assert( !dlrAtEnd(pReader) );
return pReader->pData+n;
}
static int dlrPosDataLen(DLReader *pReader){
sqlite_int64 iDummy;
int n = getVarint(pReader->pData, &iDummy);
int n = fts3GetVarint(pReader->pData, &iDummy);
assert( !dlrAtEnd(pReader) );
return pReader->nElement-n;
}
@ -637,20 +636,20 @@ static void dlrStep(DLReader *pReader){
/* If there is more data, read the next doclist element. */
if( pReader->nData!=0 ){
sqlite_int64 iDocidDelta;
int iDummy, n = getVarint(pReader->pData, &iDocidDelta);
int iDummy, n = fts3GetVarint(pReader->pData, &iDocidDelta);
pReader->iDocid += iDocidDelta;
if( pReader->iType>=DL_POSITIONS ){
assert( n<pReader->nData );
while( 1 ){
n += getVarint32(pReader->pData+n, &iDummy);
n += fts3GetVarint32(pReader->pData+n, &iDummy);
assert( n<=pReader->nData );
if( iDummy==POS_END ) break;
if( iDummy==POS_COLUMN ){
n += getVarint32(pReader->pData+n, &iDummy);
n += fts3GetVarint32(pReader->pData+n, &iDummy);
assert( n<pReader->nData );
}else if( pReader->iType==DL_POSITIONS_OFFSETS ){
n += getVarint32(pReader->pData+n, &iDummy);
n += getVarint32(pReader->pData+n, &iDummy);
n += fts3GetVarint32(pReader->pData+n, &iDummy);
n += fts3GetVarint32(pReader->pData+n, &iDummy);
assert( n<pReader->nData );
}
}
@ -688,18 +687,18 @@ static void docListValidate(DocListType iType, const char *pData, int nData,
assert( pData+nData>pData );
while( nData!=0 ){
sqlite_int64 iDocidDelta;
int n = getVarint(pData, &iDocidDelta);
int n = fts3GetVarint(pData, &iDocidDelta);
iPrevDocid += iDocidDelta;
if( iType>DL_DOCIDS ){
int iDummy;
while( 1 ){
n += getVarint32(pData+n, &iDummy);
n += fts3GetVarint32(pData+n, &iDummy);
if( iDummy==POS_END ) break;
if( iDummy==POS_COLUMN ){
n += getVarint32(pData+n, &iDummy);
n += fts3GetVarint32(pData+n, &iDummy);
}else if( iType>DL_POSITIONS ){
n += getVarint32(pData+n, &iDummy);
n += getVarint32(pData+n, &iDummy);
n += fts3GetVarint32(pData+n, &iDummy);
n += fts3GetVarint32(pData+n, &iDummy);
}
assert( n<=nData );
}
@ -770,9 +769,9 @@ static void dlwAppend(DLWriter *pWriter,
#endif
/* Recode the initial docid as delta from iPrevDocid. */
nFirstOld = getVarint(pData, &iDocid);
nFirstOld = fts3GetVarint(pData, &iDocid);
assert( nFirstOld<nData || (nFirstOld==nData && pWriter->iType==DL_DOCIDS) );
nFirstNew = putVarint(c, iFirstDocid-pWriter->iPrevDocid);
nFirstNew = fts3PutVarint(c, iFirstDocid-pWriter->iPrevDocid);
/* Verify that the incoming doclist is valid AND that it ends with
** the expected docid. This is essential because we'll trust this
@ -798,7 +797,7 @@ static void dlwCopy(DLWriter *pWriter, DLReader *pReader){
}
static void dlwAdd(DLWriter *pWriter, sqlite_int64 iDocid){
char c[VARINT_MAX];
int n = putVarint(c, iDocid-pWriter->iPrevDocid);
int n = fts3PutVarint(c, iDocid-pWriter->iPrevDocid);
/* Docids must ascend. */
assert( !pWriter->has_iPrevDocid || iDocid>pWriter->iPrevDocid );
@ -865,12 +864,12 @@ static void plrStep(PLReader *pReader){
return;
}
n = getVarint32(pReader->pData, &i);
n = fts3GetVarint32(pReader->pData, &i);
if( i==POS_COLUMN ){
n += getVarint32(pReader->pData+n, &pReader->iColumn);
n += fts3GetVarint32(pReader->pData+n, &pReader->iColumn);
pReader->iPosition = 0;
pReader->iStartOffset = 0;
n += getVarint32(pReader->pData+n, &i);
n += fts3GetVarint32(pReader->pData+n, &i);
}
/* Should never see adjacent column changes. */
assert( i!=POS_COLUMN );
@ -883,9 +882,9 @@ static void plrStep(PLReader *pReader){
pReader->iPosition += i-POS_BASE;
if( pReader->iType==DL_POSITIONS_OFFSETS ){
n += getVarint32(pReader->pData+n, &i);
n += fts3GetVarint32(pReader->pData+n, &i);
pReader->iStartOffset += i;
n += getVarint32(pReader->pData+n, &i);
n += fts3GetVarint32(pReader->pData+n, &i);
pReader->iEndOffset = pReader->iStartOffset+i;
}
assert( n<=pReader->nData );
@ -957,21 +956,21 @@ static void plwAdd(PLWriter *pWriter, int iColumn, int iPos,
if( pWriter->dlw->iType==DL_DOCIDS ) return;
if( iColumn!=pWriter->iColumn ){
n += putVarint(c+n, POS_COLUMN);
n += putVarint(c+n, iColumn);
n += fts3PutVarint(c+n, POS_COLUMN);
n += fts3PutVarint(c+n, iColumn);
pWriter->iColumn = iColumn;
pWriter->iPos = 0;
pWriter->iOffset = 0;
}
assert( iPos>=pWriter->iPos );
n += putVarint(c+n, POS_BASE+(iPos-pWriter->iPos));
n += fts3PutVarint(c+n, POS_BASE+(iPos-pWriter->iPos));
pWriter->iPos = iPos;
if( pWriter->dlw->iType==DL_POSITIONS_OFFSETS ){
assert( iStartOffset>=pWriter->iOffset );
n += putVarint(c+n, iStartOffset-pWriter->iOffset);
n += fts3PutVarint(c+n, iStartOffset-pWriter->iOffset);
pWriter->iOffset = iStartOffset;
assert( iEndOffset>=iStartOffset );
n += putVarint(c+n, iEndOffset-iStartOffset);
n += fts3PutVarint(c+n, iEndOffset-iStartOffset);
}
dataBufferAppend(pWriter->dlw->b, c, n);
}
@ -987,7 +986,7 @@ static void plwInit(PLWriter *pWriter, DLWriter *dlw, sqlite_int64 iDocid){
/* Docids must ascend. */
assert( !pWriter->dlw->has_iPrevDocid || iDocid>pWriter->dlw->iPrevDocid );
n = putVarint(c, iDocid-pWriter->dlw->iPrevDocid);
n = fts3PutVarint(c, iDocid-pWriter->dlw->iPrevDocid);
dataBufferAppend(pWriter->dlw->b, c, n);
pWriter->dlw->iPrevDocid = iDocid;
#ifndef NDEBUG
@ -1009,7 +1008,7 @@ static void plwInit(PLWriter *pWriter, DLWriter *dlw, sqlite_int64 iDocid){
static void plwTerminate(PLWriter *pWriter){
if( pWriter->dlw->iType>DL_DOCIDS ){
char c[VARINT_MAX];
int n = putVarint(c, POS_END);
int n = fts3PutVarint(c, POS_END);
dataBufferAppend(pWriter->dlw->b, c, n);
}
#ifndef NDEBUG
@ -1048,7 +1047,7 @@ typedef struct DLCollector {
static void dlcAddDoclist(DLCollector *pCollector, DataBuffer *b){
if( pCollector->dlw.iType>DL_DOCIDS ){
char c[VARINT_MAX];
int n = putVarint(c, POS_END);
int n = fts3PutVarint(c, POS_END);
dataBufferAppend2(b, pCollector->b.pData, pCollector->b.nData, c, n);
}else{
dataBufferAppend(b, pCollector->b.pData, pCollector->b.nData);
@ -1762,7 +1761,7 @@ static int sql_exec(sqlite3 *db, const char *zDb, const char *zName,
const char *zFormat){
char *zCommand = string_format(zFormat, zDb, zName);
int rc;
TRACE(("FTS3 sql: %s\n", zCommand));
FTSTRACE(("FTS3 sql: %s\n", zCommand));
rc = sqlite3_exec(db, zCommand, NULL, 0, NULL);
sqlite3_free(zCommand);
return rc;
@ -1772,7 +1771,7 @@ static int sql_prepare(sqlite3 *db, const char *zDb, const char *zName,
sqlite3_stmt **ppStmt, const char *zFormat){
char *zCommand = string_format(zFormat, zDb, zName);
int rc;
TRACE(("FTS3 prepare: %s\n", zCommand));
FTSTRACE(("FTS3 prepare: %s\n", zCommand));
rc = sqlite3_prepare_v2(db, zCommand, -1, ppStmt, NULL);
sqlite3_free(zCommand);
return rc;
@ -2423,7 +2422,7 @@ static int clearPendingTerms(fulltext_vtab *v);
static void fulltext_vtab_destroy(fulltext_vtab *v){
int iStmt, i;
TRACE(("FTS3 Destroy %p\n", v));
FTSTRACE(("FTS3 Destroy %p\n", v));
for( iStmt=0; iStmt<MAX_STMT; iStmt++ ){
if( v->pFulltextStatements[iStmt]!=NULL ){
sqlite3_finalize(v->pFulltextStatements[iStmt]);
@ -2464,18 +2463,18 @@ static void fulltext_vtab_destroy(fulltext_vtab *v){
/*
** If X is a character that can be used in an identifier then
** IdChar(X) will be true. Otherwise it is false.
** ftsIdChar(X) will be true. Otherwise it is false.
**
** For ASCII, any character with the high-order bit set is
** allowed in an identifier. For 7-bit characters,
** sqlite3IsIdChar[X] must be 1.
** isFtsIdChar[X] must be 1.
**
** Ticket #1066. the SQL standard does not allow '$' in the
** middle of identfiers. But many SQL implementations do.
** SQLite will allow '$' in identifiers for compatibility.
** But the feature is undocumented.
*/
static const char isIdChar[] = {
static const char isFtsIdChar[] = {
/* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2x */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 3x */
@ -2484,14 +2483,14 @@ static const char isIdChar[] = {
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6x */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 7x */
};
#define IdChar(C) (((c=C)&0x80)!=0 || (c>0x1f && isIdChar[c-0x20]))
#define ftsIdChar(C) (((c=C)&0x80)!=0 || (c>0x1f && isFtsIdChar[c-0x20]))
/*
** Return the length of the token that begins at z[0].
** Store the token type in *tokenType before returning.
*/
static int getToken(const char *z, int *tokenType){
static int ftsGetToken(const char *z, int *tokenType){
int i, c;
switch( *z ){
case 0: {
@ -2525,10 +2524,10 @@ static int getToken(const char *z, int *tokenType){
return i;
}
default: {
if( !IdChar(*z) ){
if( !ftsIdChar(*z) ){
break;
}
for(i=1; IdChar(z[i]); i++){}
for(i=1; ftsIdChar(z[i]); i++){}
*tokenType = TOKEN_ID;
return i;
}
@ -2541,10 +2540,10 @@ static int getToken(const char *z, int *tokenType){
** A token extracted from a string is an instance of the following
** structure.
*/
typedef struct Token {
typedef struct FtsToken {
const char *z; /* Pointer to token text. Not '\000' terminated */
short int n; /* Length of the token text in bytes. */
} Token;
} FtsToken;
/*
** Given a input string (which is really one of the argv[] parameters
@ -2561,14 +2560,14 @@ typedef struct Token {
*/
static char **tokenizeString(const char *z, int *pnToken){
int nToken = 0;
Token *aToken = sqlite3_malloc( strlen(z) * sizeof(aToken[0]) );
FtsToken *aToken = sqlite3_malloc( strlen(z) * sizeof(aToken[0]) );
int n = 1;
int e, i;
int totalSize = 0;
char **azToken;
char *zCopy;
while( n>0 ){
n = getToken(z, &e);
n = ftsGetToken(z, &e);
if( e!=TOKEN_SPACE ){
aToken[nToken].z = z;
aToken[nToken].n = n;
@ -2673,7 +2672,7 @@ static void tokenListToIdList(char **azIn){
static char *firstToken(char *zIn, char **pzTail){
int n, ttype;
while(1){
n = getToken(zIn, &ttype);
n = ftsGetToken(zIn, &ttype);
if( ttype==TOKEN_SPACE ){
zIn += n;
}else if( ttype==TOKEN_EOF ){
@ -2934,7 +2933,7 @@ static int constructVtab(
v->nPendingData = -1;
*ppVTab = &v->base;
TRACE(("FTS3 Connect %p\n", v));
FTSTRACE(("FTS3 Connect %p\n", v));
return rc;
@ -2971,7 +2970,7 @@ static int fulltextCreate(sqlite3 *db, void *pAux,
int rc;
TableSpec spec;
StringBuffer schema;
TRACE(("FTS3 Create\n"));
FTSTRACE(("FTS3 Create\n"));
rc = parseSpec(&spec, argc, argv, pzErr);
if( rc!=SQLITE_OK ) return rc;
@ -3016,7 +3015,7 @@ out:
static int fulltextBestIndex(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
fulltext_vtab *v = (fulltext_vtab *)pVTab;
int i;
TRACE(("FTS3 BestIndex\n"));
FTSTRACE(("FTS3 BestIndex\n"));
for(i=0; i<pInfo->nConstraint; ++i){
const struct sqlite3_index_constraint *pConstraint;
@ -3025,12 +3024,12 @@ static int fulltextBestIndex(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
if( (pConstraint->iColumn==-1 || pConstraint->iColumn==v->nColumn+1) &&
pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ ){
pInfo->idxNum = QUERY_DOCID; /* lookup by docid */
TRACE(("FTS3 QUERY_DOCID\n"));
FTSTRACE(("FTS3 QUERY_DOCID\n"));
} else if( pConstraint->iColumn>=0 && pConstraint->iColumn<=v->nColumn &&
pConstraint->op==SQLITE_INDEX_CONSTRAINT_MATCH ){
/* full-text search */
pInfo->idxNum = QUERY_FULLTEXT + pConstraint->iColumn;
TRACE(("FTS3 QUERY_FULLTEXT %d\n", pConstraint->iColumn));
FTSTRACE(("FTS3 QUERY_FULLTEXT %d\n", pConstraint->iColumn));
} else continue;
pInfo->aConstraintUsage[i].argvIndex = 1;
@ -3049,7 +3048,7 @@ static int fulltextBestIndex(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
}
static int fulltextDisconnect(sqlite3_vtab *pVTab){
TRACE(("FTS3 Disconnect %p\n", pVTab));
FTSTRACE(("FTS3 Disconnect %p\n", pVTab));
fulltext_vtab_destroy((fulltext_vtab *)pVTab);
return SQLITE_OK;
}
@ -3058,7 +3057,7 @@ static int fulltextDestroy(sqlite3_vtab *pVTab){
fulltext_vtab *v = (fulltext_vtab *)pVTab;
int rc;
TRACE(("FTS3 Destroy %p\n", pVTab));
FTSTRACE(("FTS3 Destroy %p\n", pVTab));
rc = sql_exec(v->db, v->zDb, v->zName,
"drop table if exists %_content;"
"drop table if exists %_segments;"
@ -3078,7 +3077,7 @@ static int fulltextOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
memset(c, 0, sizeof(fulltext_cursor));
/* sqlite will initialize c->base */
*ppCursor = &c->base;
TRACE(("FTS3 Open %p: %p\n", pVTab, c));
FTSTRACE(("FTS3 Open %p: %p\n", pVTab, c));
return SQLITE_OK;
}else{
return SQLITE_NOMEM;
@ -3550,7 +3549,7 @@ static void snippetText(
*/
static int fulltextClose(sqlite3_vtab_cursor *pCursor){
fulltext_cursor *c = (fulltext_cursor *) pCursor;
TRACE(("FTS3 Close %p\n", c));
FTSTRACE(("FTS3 Close %p\n", c));
sqlite3_finalize(c->pStmt);
queryClear(&c->q);
snippetClear(&c->snippet);
@ -3564,7 +3563,7 @@ static int fulltextNext(sqlite3_vtab_cursor *pCursor){
fulltext_cursor *c = (fulltext_cursor *) pCursor;
int rc;
TRACE(("FTS3 Next %p\n", pCursor));
FTSTRACE(("FTS3 Next %p\n", pCursor));
snippetClear(&c->snippet);
if( c->iCursorType < QUERY_FULLTEXT ){
/* TODO(shess) Handle SQLITE_SCHEMA AND SQLITE_BUSY. */
@ -4012,7 +4011,7 @@ static int fulltextFilter(
int rc;
StringBuffer sb;
TRACE(("FTS3 Filter %p\n",pCursor));
FTSTRACE(("FTS3 Filter %p\n",pCursor));
initStringBuffer(&sb);
append(&sb, "SELECT docid, ");
@ -4309,8 +4308,8 @@ static InteriorBlock *interiorBlockNew(int iHeight, sqlite_int64 iChildBlock,
dataBufferInit(&block->term, 0);
dataBufferReplace(&block->term, pTerm, nTerm);
n = putVarint(c, iHeight);
n += putVarint(c+n, iChildBlock);
n = fts3PutVarint(c, iHeight);
n += fts3PutVarint(c+n, iChildBlock);
dataBufferInit(&block->data, INTERIOR_MAX);
dataBufferReplace(&block->data, c, n);
}
@ -4330,7 +4329,7 @@ static void interiorBlockValidate(InteriorBlock *pBlock){
assert( pData+nData>pData );
/* Must lead with height of node as a varint(n), n>0 */
n = getVarint32(pData, &iDummy);
n = fts3GetVarint32(pData, &iDummy);
assert( n>0 );
assert( iDummy>0 );
assert( n<nData );
@ -4338,7 +4337,7 @@ static void interiorBlockValidate(InteriorBlock *pBlock){
nData -= n;
/* Must contain iBlockid. */
n = getVarint(pData, &iBlockid);
n = fts3GetVarint(pData, &iBlockid);
assert( n>0 );
assert( n<=nData );
pData += n;
@ -4347,7 +4346,7 @@ static void interiorBlockValidate(InteriorBlock *pBlock){
/* Zero or more terms of positive length */
if( nData!=0 ){
/* First term is not delta-encoded. */
n = getVarint32(pData, &iDummy);
n = fts3GetVarint32(pData, &iDummy);
assert( n>0 );
assert( iDummy>0 );
assert( n+iDummy>0);
@ -4358,7 +4357,7 @@ static void interiorBlockValidate(InteriorBlock *pBlock){
/* Following terms delta-encoded. */
while( nData!=0 ){
/* Length of shared prefix. */
n = getVarint32(pData, &iDummy);
n = fts3GetVarint32(pData, &iDummy);
assert( n>0 );
assert( iDummy>=0 );
assert( n<nData );
@ -4366,7 +4365,7 @@ static void interiorBlockValidate(InteriorBlock *pBlock){
nData -= n;
/* Length and data of distinct suffix. */
n = getVarint32(pData, &iDummy);
n = fts3GetVarint32(pData, &iDummy);
assert( n>0 );
assert( iDummy>0 );
assert( n+iDummy>0);
@ -4433,15 +4432,15 @@ static void interiorWriterAppend(InteriorWriter *pWriter,
** at 0.
*/
if( pWriter->term.nData==0 ){
n = putVarint(c, nTerm);
n = fts3PutVarint(c, nTerm);
}else{
while( nPrefix<pWriter->term.nData &&
pTerm[nPrefix]==pWriter->term.pData[nPrefix] ){
nPrefix++;
}
n = putVarint(c, nPrefix);
n += putVarint(c+n, nTerm-nPrefix);
n = fts3PutVarint(c, nPrefix);
n += fts3PutVarint(c+n, nTerm-nPrefix);
}
#ifndef NDEBUG
@ -4571,7 +4570,7 @@ static void interiorReaderInit(const char *pData, int nData,
CLEAR(pReader);
/* Decode the base blockid, and set the cursor to the first term. */
n = getVarint(pData+1, &pReader->iBlockid);
n = fts3GetVarint(pData+1, &pReader->iBlockid);
assert( 1+n<=nData );
pReader->pData = pData+1+n;
pReader->nData = nData-(1+n);
@ -4583,7 +4582,7 @@ static void interiorReaderInit(const char *pData, int nData,
if( pReader->nData==0 ){
dataBufferInit(&pReader->term, 0);
}else{
n = getVarint32(pReader->pData, &nTerm);
n = fts3GetVarint32(pReader->pData, &nTerm);
dataBufferInit(&pReader->term, nTerm);
dataBufferReplace(&pReader->term, pReader->pData+n, nTerm);
assert( n+nTerm<=pReader->nData );
@ -4621,8 +4620,8 @@ static void interiorReaderStep(InteriorReader *pReader){
}else{
int n, nPrefix, nSuffix;
n = getVarint32(pReader->pData, &nPrefix);
n += getVarint32(pReader->pData+n, &nSuffix);
n = fts3GetVarint32(pReader->pData, &nPrefix);
n += fts3GetVarint32(pReader->pData+n, &nSuffix);
/* Truncate the current term and append suffix data. */
pReader->term.nData = nPrefix;
@ -4727,7 +4726,7 @@ static void leafNodeValidate(const char *pData, int nData){
assert( pData+nData>pData );
/* Must lead with a varint(0) */
n = getVarint32(pData, &iDummy);
n = fts3GetVarint32(pData, &iDummy);
assert( iDummy==0 );
assert( n>0 );
assert( n<nData );
@ -4735,7 +4734,7 @@ static void leafNodeValidate(const char *pData, int nData){
nData -= n;
/* Leading term length and data must fit in buffer. */
n = getVarint32(pData, &iDummy);
n = fts3GetVarint32(pData, &iDummy);
assert( n>0 );
assert( iDummy>0 );
assert( n+iDummy>0 );
@ -4744,7 +4743,7 @@ static void leafNodeValidate(const char *pData, int nData){
nData -= n+iDummy;
/* Leading term's doclist length and data must fit. */
n = getVarint32(pData, &iDummy);
n = fts3GetVarint32(pData, &iDummy);
assert( n>0 );
assert( iDummy>0 );
assert( n+iDummy>0 );
@ -4755,13 +4754,13 @@ static void leafNodeValidate(const char *pData, int nData){
/* Verify that trailing terms and doclists also are readable. */
while( nData!=0 ){
n = getVarint32(pData, &iDummy);
n = fts3GetVarint32(pData, &iDummy);
assert( n>0 );
assert( iDummy>=0 );
assert( n<nData );
pData += n;
nData -= n;
n = getVarint32(pData, &iDummy);
n = fts3GetVarint32(pData, &iDummy);
assert( n>0 );
assert( iDummy>0 );
assert( n+iDummy>0 );
@ -4769,7 +4768,7 @@ static void leafNodeValidate(const char *pData, int nData){
pData += n+iDummy;
nData -= n+iDummy;
n = getVarint32(pData, &iDummy);
n = fts3GetVarint32(pData, &iDummy);
assert( n>0 );
assert( iDummy>0 );
assert( n+iDummy>0 );
@ -4809,7 +4808,7 @@ static int leafWriterInternalFlush(fulltext_vtab *v, LeafWriter *pWriter,
/* Reconstruct the first term in the leaf for purposes of building
** the interior node.
*/
n = getVarint32(pWriter->data.pData+iData+1, &nStartingTerm);
n = fts3GetVarint32(pWriter->data.pData+iData+1, &nStartingTerm);
pStartingTerm = pWriter->data.pData+iData+1+n;
assert( pWriter->data.nData>iData+1+n+nStartingTerm );
assert( pWriter->nTermDistinct>0 );
@ -4933,8 +4932,8 @@ static int leafWriterEncodeTerm(LeafWriter *pWriter,
** varint(nTerm)
** char pTerm[nTerm]
*/
n = putVarint(c, '\0');
n += putVarint(c+n, nTerm);
n = fts3PutVarint(c, '\0');
n += fts3PutVarint(c+n, nTerm);
dataBufferAppend2(&pWriter->data, c, n, pTerm, nTerm);
}else{
/* Delta-encode the term as:
@ -4942,8 +4941,8 @@ static int leafWriterEncodeTerm(LeafWriter *pWriter,
** varint(nSuffix)
** char pTermSuffix[nSuffix]
*/
n = putVarint(c, nPrefix);
n += putVarint(c+n, nTerm-nPrefix);
n = fts3PutVarint(c, nPrefix);
n += fts3PutVarint(c+n, nTerm-nPrefix);
dataBufferAppend2(&pWriter->data, c, n, pTerm+nPrefix, nTerm-nPrefix);
}
dataBufferReplace(&pWriter->term, pTerm, nTerm);
@ -4960,8 +4959,8 @@ static int leafWriterInlineFlush(fulltext_vtab *v, LeafWriter *pWriter,
const char *pTerm, int nTerm,
int iDoclistData){
char c[VARINT_MAX+VARINT_MAX];
int iData, n = putVarint(c, 0);
n += putVarint(c+n, nTerm);
int iData, n = fts3PutVarint(c, 0);
n += fts3PutVarint(c+n, nTerm);
/* There should always be room for the header. Even if pTerm shared
** a substantial prefix with the previous term, the entire prefix
@ -5001,7 +5000,7 @@ static int leafWriterStepMerge(fulltext_vtab *v, LeafWriter *pWriter,
for(i=0, nData=0; i<nReaders; i++){
nData += dlrAllDataBytes(&pReaders[i]);
}
n = putVarint(c, nData);
n = fts3PutVarint(c, nData);
dataBufferAppend(&pWriter->data, c, n);
docListMerge(&pWriter->data, pReaders, nReaders);
@ -5015,7 +5014,7 @@ static int leafWriterStepMerge(fulltext_vtab *v, LeafWriter *pWriter,
** not a big deal, we can just use memmove() to adjust things.
*/
nActualData = pWriter->data.nData-(iDoclistData+n);
nActual = putVarint(c, nActualData);
nActual = fts3PutVarint(c, nActualData);
assert( nActualData<=nData );
assert( nActual<=n );
@ -5078,8 +5077,8 @@ static int leafWriterStepMerge(fulltext_vtab *v, LeafWriter *pWriter,
pWriter->nTermDistinct = nTermDistinct;
/* Rebuild header using the current term */
n = putVarint(pWriter->data.pData, 0);
n += putVarint(pWriter->data.pData+n, nTerm);
n = fts3PutVarint(pWriter->data.pData, 0);
n += fts3PutVarint(pWriter->data.pData+n, nTerm);
memcpy(pWriter->data.pData+n, pTerm, nTerm);
n += nTerm;
@ -5153,13 +5152,13 @@ static const char *leafReaderTerm(LeafReader *pReader){
static int leafReaderDataBytes(LeafReader *pReader){
int nData;
assert( pReader->term.nData>0 );
getVarint32(pReader->pData, &nData);
fts3GetVarint32(pReader->pData, &nData);
return nData;
}
static const char *leafReaderData(LeafReader *pReader){
int n, nData;
assert( pReader->term.nData>0 );
n = getVarint32(pReader->pData, &nData);
n = fts3GetVarint32(pReader->pData, &nData);
return pReader->pData+n;
}
@ -5173,7 +5172,7 @@ static void leafReaderInit(const char *pData, int nData,
CLEAR(pReader);
/* Read the first term, skipping the header byte. */
n = getVarint32(pData+1, &nTerm);
n = fts3GetVarint32(pData+1, &nTerm);
dataBufferInit(&pReader->term, nTerm);
dataBufferReplace(&pReader->term, pData+1+n, nTerm);
@ -5189,7 +5188,7 @@ static void leafReaderStep(LeafReader *pReader){
assert( !leafReaderAtEnd(pReader) );
/* Skip previous entry's data block. */
n = getVarint32(pReader->pData, &nData);
n = fts3GetVarint32(pReader->pData, &nData);
assert( n+nData<=pReader->nData );
pReader->pData += n+nData;
pReader->nData -= n+nData;
@ -5198,8 +5197,8 @@ static void leafReaderStep(LeafReader *pReader){
/* Construct the new term using a prefix from the old term plus a
** suffix from the leaf data.
*/
n = getVarint32(pReader->pData, &nPrefix);
n += getVarint32(pReader->pData+n, &nSuffix);
n = fts3GetVarint32(pReader->pData, &nPrefix);
n += fts3GetVarint32(pReader->pData+n, &nSuffix);
assert( n+nSuffix<pReader->nData );
pReader->term.nData = nPrefix;
dataBufferAppend(&pReader->term, pReader->pData+n, nSuffix);
@ -5996,7 +5995,7 @@ static int fulltextUpdate(sqlite3_vtab *pVtab, int nArg, sqlite3_value **ppArg,
fulltext_vtab *v = (fulltext_vtab *) pVtab;
int rc;
TRACE(("FTS3 Update %p\n", pVtab));
FTSTRACE(("FTS3 Update %p\n", pVtab));
if( nArg<2 ){
rc = index_delete(v, sqlite3_value_int64(ppArg[0]));
@ -6050,13 +6049,13 @@ static int fulltextUpdate(sqlite3_vtab *pVtab, int nArg, sqlite3_value **ppArg,
}
static int fulltextSync(sqlite3_vtab *pVtab){
TRACE(("FTS3 xSync()\n"));
FTSTRACE(("FTS3 xSync()\n"));
return flushPendingTerms((fulltext_vtab *)pVtab);
}
static int fulltextBegin(sqlite3_vtab *pVtab){
fulltext_vtab *v = (fulltext_vtab *) pVtab;
TRACE(("FTS3 xBegin()\n"));
FTSTRACE(("FTS3 xBegin()\n"));
/* Any buffered updates should have been cleared by the previous
** transaction.
@ -6067,7 +6066,7 @@ static int fulltextBegin(sqlite3_vtab *pVtab){
static int fulltextCommit(sqlite3_vtab *pVtab){
fulltext_vtab *v = (fulltext_vtab *) pVtab;
TRACE(("FTS3 xCommit()\n"));
FTSTRACE(("FTS3 xCommit()\n"));
/* Buffered updates should have been cleared by fulltextSync(). */
assert( v->nPendingData<0 );
@ -6075,7 +6074,7 @@ static int fulltextCommit(sqlite3_vtab *pVtab){
}
static int fulltextRollback(sqlite3_vtab *pVtab){
TRACE(("FTS3 xRollback()\n"));
FTSTRACE(("FTS3 xRollback()\n"));
return clearPendingTerms((fulltext_vtab *)pVtab);
}

View File

@ -131,13 +131,13 @@ static int fts3BinCompare(const void *pKey1, int n1, const void *pKey2, int n2){
** The C syntax in this function definition may be unfamilar to some
** programmers, so we provide the following additional explanation:
**
** The name of the function is "hashFunction". The function takes a
** single parameter "keyClass". The return value of hashFunction()
** The name of the function is "ftsHashFunction". The function takes a
** single parameter "keyClass". The return value of ftsHashFunction()
** is a pointer to another function. Specifically, the return value
** of hashFunction() is a pointer to a function that takes two parameters
** of ftsHashFunction() is a pointer to a function that takes two parameters
** with types "const void*" and "int" and returns an "int".
*/
static int (*hashFunction(int keyClass))(const void*,int){
static int (*ftsHashFunction(int keyClass))(const void*,int){
if( keyClass==FTS3_HASH_STRING ){
return &fts3StrHash;
}else{
@ -152,7 +152,7 @@ static int (*hashFunction(int keyClass))(const void*,int){
** For help in interpreted the obscure C code in the function definition,
** see the header comment on the previous function.
*/
static int (*compareFunction(int keyClass))(const void*,int,const void*,int){
static int (*ftsCompareFunction(int keyClass))(const void*,int,const void*,int){
if( keyClass==FTS3_HASH_STRING ){
return &fts3StrCompare;
}else{
@ -202,7 +202,7 @@ static void fts3Rehash(fts3Hash *pH, int new_size){
fts3HashFree(pH->ht);
pH->ht = new_ht;
pH->htsize = new_size;
xHash = hashFunction(pH->keyClass);
xHash = ftsHashFunction(pH->keyClass);
for(elem=pH->first, pH->first=0; elem; elem = next_elem){
int h = (*xHash)(elem->pKey, elem->nKey) & (new_size-1);
next_elem = elem->next;
@ -228,7 +228,7 @@ static fts3HashElem *fts3FindElementByHash(
struct _fts3ht *pEntry = &pH->ht[h];
elem = pEntry->chain;
count = pEntry->count;
xCompare = compareFunction(pH->keyClass);
xCompare = ftsCompareFunction(pH->keyClass);
while( count-- && elem ){
if( (*xCompare)(elem->pKey,elem->nKey,pKey,nKey)==0 ){
return elem;
@ -286,7 +286,7 @@ void *sqlite3Fts3HashFind(const fts3Hash *pH, const void *pKey, int nKey){
int (*xHash)(const void*,int); /* The hash function */
if( pH==0 || pH->ht==0 ) return 0;
xHash = hashFunction(pH->keyClass);
xHash = ftsHashFunction(pH->keyClass);
assert( xHash!=0 );
h = (*xHash)(pKey,nKey);
assert( (pH->htsize & (pH->htsize-1))==0 );
@ -322,7 +322,7 @@ void *sqlite3Fts3HashInsert(
int (*xHash)(const void*,int); /* The hash function */
assert( pH!=0 );
xHash = hashFunction(pH->keyClass);
xHash = ftsHashFunction(pH->keyClass);
assert( xHash!=0 );
hraw = (*xHash)(pKey, nKey);
assert( (pH->htsize & (pH->htsize-1))==0 );

View File

@ -25,8 +25,6 @@
*/
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
#include "sqlite3.h"
#include "sqlite3ext.h"
SQLITE_EXTENSION_INIT1

View File

@ -1,5 +1,5 @@
C Fix\sa\stypo\sin\sa\schange\sto\sall.test\sfrom\searlier\stoday.\s(CVS\s4557)
D 2007-11-23T18:19:22
C The\sFTS3\samalgamation\scan\snow\sbe\sappended\sto\sthe\sSQLite\samalgamation\sto\ngenerate\sa\ssingle\ssource\sfile\sthat\scontains\sboth\scomponents.\s(CVS\s4558)
D 2007-11-24T00:41:52
F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
F Makefile.in 35396fd58890420b29edcf27b6c0e2d054862a6b
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -50,13 +50,13 @@ F ext/fts2/fts2_tokenizer1.c 8a545c232bdffafd117c4eeaf59789691909f26a
F ext/fts2/mkfts2amal.tcl 974d5d438cb3f7c4a652639262f82418c1e4cff0
F ext/fts3/README.tokenizers a97c9a55b3422f6cb04af9de9296fe2447ea4a78
F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d
F ext/fts3/fts3.c 2ea2aead0d342a9844f522d9b51e24d47614b06b
F ext/fts3/fts3.c b95b4b62211335cf74d2485a7c17925a9f8338f8
F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe
F ext/fts3/fts3_hash.c 76506de426f8df5527254f5e0bc1abf05e83a2b8
F ext/fts3/fts3_hash.c 83e7bb4042106b32811681dd2859b4577a7a6b35
F ext/fts3/fts3_hash.h 004b759e1602ff16dfa02fea3ca1c77336ad6798
F ext/fts3/fts3_icu.c e676f8f0c472cfbb3194febf0eadc1cea6ff0d0c
F ext/fts3/fts3_porter.c 3063da945fb0a935781c135f7575f39166173eca
F ext/fts3/fts3_tokenizer.c 81e7604555b24dce6bc487d8169ca4ef51c71e4c
F ext/fts3/fts3_tokenizer.c d777c079eaa76996e8493596b1124898d5692271
F ext/fts3/fts3_tokenizer.h 7eb79de4f991a77f43c517e209e5fae95dfa7369
F ext/fts3/fts3_tokenizer1.c 0a5bcc579f35de5d24a9345d7908dc25ae403ee7
F ext/fts3/mkfts3amal.tcl 8282b56f11d008b9fa1f09ad3f7eca513949575e
@ -590,7 +590,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P f94cdcfd1171fd110ed9cd4c47f1fb5fa7e99ca9
R cf810e1e41ea0c1ce9c3cdeb8ac44a5e
P 8c0b2157f2a2f8ecfa641a041279faf21aedd4e0
R cdfb152187a9296f913494eaf2c01ee9
U drh
Z b72934b154618065708efb065dded2b6
Z eba6c82b1c5d7dceb4b3e7cae88033fd

View File

@ -1 +1 @@
8c0b2157f2a2f8ecfa641a041279faf21aedd4e0
0fc61f99b54bd269fcc011f448b9b971e902cb01