1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Add simple tests for the xColumnText() extension api.

FossilOrigin-Name: 1e9053abdaf5e128d44504ee00dfd909dc25f378
This commit is contained in:
dan
2014-07-19 20:27:54 +00:00
parent 4a165c0af4
commit e1c77bcfcd
8 changed files with 71 additions and 14 deletions

View File

@ -657,8 +657,8 @@ static int fts5ApiColumnText(
Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
int rc = fts5SeekCursor(pCsr);
if( rc==SQLITE_OK ){
*pz = (const char*)sqlite3_column_text(pCsr->pStmt, iCol);
*pn = sqlite3_column_bytes(pCsr->pStmt, iCol);
*pz = (const char*)sqlite3_column_text(pCsr->pStmt, iCol+1);
*pn = sqlite3_column_bytes(pCsr->pStmt, iCol+1);
}
return rc;
}

View File

@ -53,6 +53,9 @@ typedef void (*fts5_extension_function)(
** xColumnSize:
** Reports the size in tokens of a column value from the current row.
**
** xColumnText:
** Reports the size in tokens of a column value from the current row.
**
** xPhraseCount:
** Returns the number of phrases in the current query expression.
**

View File

@ -89,6 +89,7 @@ void sqlite3Fts5BufferFree(Fts5Buffer*);
void sqlite3Fts5BufferZero(Fts5Buffer*);
void sqlite3Fts5BufferSet(int*, Fts5Buffer*, int, const u8*);
void sqlite3Fts5BufferAppendPrintf(int *, Fts5Buffer*, char *zFmt, ...);
void sqlite3Fts5BufferAppendListElem(int*, Fts5Buffer*, const char*, int);
#define fts5BufferZero(x) sqlite3Fts5BufferZero(x)
#define fts5BufferGrow(a,b,c) sqlite3Fts5BufferGrow(a,b,c)

View File

@ -65,6 +65,19 @@ static void fts5TestFunction(
if( zReq==0 && nCol>1 ) sqlite3Fts5BufferAppendPrintf(&rc, &s, "}");
}
if( zReq==0 ){
sqlite3Fts5BufferAppendPrintf(&rc, &s, "columntext ");
}
if( 0==zReq || 0==sqlite3_stricmp(zReq, "columntext") ){
for(i=0; rc==SQLITE_OK && i<nCol; i++){
const char *z;
int n;
rc = pApi->xColumnText(pFts, i, &z, &n);
if( i!=0 ) sqlite3Fts5BufferAppendPrintf(&rc, &s, " ");
sqlite3Fts5BufferAppendListElem(&rc, &s, z, n);
}
}
if( zReq==0 ){
sqlite3Fts5BufferAppendPrintf(&rc, &s, " phrasecount ");
}

View File

@ -232,4 +232,35 @@ int sqlite3Fts5PoslistNext(
return 0;
}
void sqlite3Fts5BufferAppendListElem(
int *pRc, /* IN/OUT: Error code */
Fts5Buffer *pBuf, /* Buffer to append to */
const char *z, int n /* Value to append to buffer */
){
int bParen = (n==0);
int nMax = n*2 + 2 + 1;
u8 *pOut;
int i;
/* Ensure the buffer has space for the new list element */
if( sqlite3Fts5BufferGrow(pRc, pBuf, nMax) ) return;
pOut = &pBuf->p[pBuf->n];
/* Figure out if we need the enclosing {} */
for(i=0; i<n && bParen==0; i++){
if( z[i]=='"' || z[i]==' ' ){
bParen = 1;
}
}
if( bParen ) *pOut++ = '{';
for(i=0; i<n; i++){
*pOut++ = z[i];
}
if( bParen ) *pOut++ = '}';
pBuf->n = pOut - pBuf->p;
*pOut = '\0';
}