Navigation
API > API/Plugins > API/Plugins/SQLiteCore > API/Plugins/SQLiteCore/sqlite
References
| Module | SQLiteCore |
| Header | /Engine/Plugins/Runtime/Database/SQLiteCore/Source/SQLiteCore/Public/sqlite/sqlite3.h |
| Include | #include "sqlite/sqlite3.h" |
Syntax
struct Fts5ExtensionApi
Remarks
EXTENSION API FUNCTIONS
xUserData(pFts): Return a copy of the context pointer the extension function was registered with.
xColumnTotalSize(pFts, iCol, pnToken): If parameter iCol is less than zero, set output variable *pnToken to the total number of tokens in the FTS5 table. Or, if iCol is non-negative but less than the number of columns in the table, return the total number of tokens in column iCol, considering all rows in the FTS5 table.
If parameter iCol is greater than or equal to the number of columns in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g. an OOM condition or IO error), an appropriate SQLite error code is returned.
xColumnCount(pFts): Return the number of columns in the table.
xColumnSize(pFts, iCol, pnToken): If parameter iCol is less than zero, set output variable *pnToken to the total number of tokens in the current row. Or, if iCol is non-negative but less than the number of columns in the table, set *pnToken to the number of tokens in column iCol of the current row.
If parameter iCol is greater than or equal to the number of columns in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g. an OOM condition or IO error), an appropriate SQLite error code is returned.
This function may be quite inefficient if used with an FTS5 table created with the "columnsize=0" option.
xColumnText: This function attempts to retrieve the text of column iCol of the current document. If successful, (*pz) is set to point to a buffer containing the text in utf-8 encoding, (*pn) is set to the size in bytes (not characters) of the buffer and SQLITE_OK is returned. Otherwise, if an error occurs, an SQLite error code is returned and the final values of (*pz) and (*pn) are undefined.
xPhraseCount: Returns the number of phrases in the current query expression.
xPhraseSize: Returns the number of tokens in phrase iPhrase of the query. Phrases are numbered starting from zero.
xInstCount: Set *pnInst to the total number of occurrences of all phrases within the query within the current row. Return SQLITE_OK if successful, or an error code (i.e. SQLITE_NOMEM) if an error occurs.
This API can be quite slow if used with an FTS5 table created with the "detail=none" or "detail=column" option. If the FTS5 table is created with either "detail=none" or "detail=column" and "content=" option (i.e. if it is a contentless table), then this API always returns 0.
xInst: Query for the details of phrase match iIdx within the current row. Phrase matches are numbered starting from zero, so the iIdx argument should be greater than or equal to zero and smaller than the value output by xInstCount().
Usually, output parameter *piPhrase is set to the phrase number, *piCol to the column in which it occurs and *piOff the token offset of the first token of the phrase. Returns SQLITE_OK if successful, or an error code (i.e. SQLITE_NOMEM) if an error occurs.
This API can be quite slow if used with an FTS5 table created with the "detail=none" or "detail=column" option.
xRowid: Returns the rowid of the current row.
xTokenize: Tokenize text using the tokenizer belonging to the FTS5 table.
xQueryPhrase(pFts5, iPhrase, pUserData, xCallback): This API function is used to query the FTS table for phrase iPhrase of the current query. Specifically, a query equivalent to: ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid
with $p set to a phrase equivalent to the phrase iPhrase of the current query is executed. Any column filter that applies to phrase iPhrase of the current query is included in $p. For each row visited, the callback function passed as the fourth argument is invoked. The context and API objects passed to the callback function may be used to access the properties of each matched row. Invoking Api.xUserData() returns a copy of the pointer passed as the third argument to pUserData.
If the callback function returns any value other than SQLITE_OK, the query is abandoned and the xQueryPhrase function returns immediately. If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK. Otherwise, the error code is propagated upwards.
If the query runs to completion without incident, SQLITE_OK is returned. Or, if some error occurs before the query completes or is aborted by the callback, an SQLite error code is returned.
xSetAuxdata(pFts5, pAux, xDelete)
Save the pointer passed as the second argument as the extension function's "auxiliary data". The pointer may then be retrieved by the current or any future invocation of the same fts5 extension function made as part of the same MATCH query using the xGetAuxdata() API.
Each extension function is allocated a single auxiliary data slot for each FTS query (MATCH expression). If the extension function is invoked more than once for a single FTS query, then all invocations share a single auxiliary data context.
If there is already an auxiliary data pointer when this function is invoked, then it is replaced by the new pointer. If an xDelete callback was specified along with the original pointer, it is invoked at this point.
The xDelete callback, if one is specified, is also invoked on the auxiliary data pointer after the FTS5 query has finished.
If an error (e.g. an OOM condition) occurs within this function, the auxiliary data is set to NULL and an error code returned. If the xDelete parameter was not NULL, it is invoked on the auxiliary data pointer before returning.
Returns the current auxiliary data pointer for the fts5 extension function. See the xSetAuxdata() method for details.
If the bClear argument is non-zero, then the auxiliary data is cleared (set to NULL) before this function returns. In this case the xDelete, if any, is not invoked.
This function is used to retrieve the total number of rows in the table. In other words, the same value that would be returned by: SELECT count(*) FROM ftstable;
xPhraseFirst() This function is used, along with type Fts5PhraseIter and the xPhraseNext method, to iterate through all instances of a single query phrase within the current row. This is the same information as is accessible via the xInstCount/xInst APIs. While the xInstCount/xInst APIs are more convenient to use, this API may be faster under some circumstances. To iterate through instances of phrase iPhrase, use the following code: Fts5PhraseIter iter; int iCol, iOff; for(pApi->xPhraseFirst(pFts, iPhrase, &iter, &iCol, &iOff); iCol>=0; pApi->xPhraseNext(pFts, &iter, &iCol, &iOff) ){ // An instance of phrase iPhrase at offset iOff of column iCol }
The Fts5PhraseIter structure is defined above. Applications should not modify this structure directly - it should only be used as shown above with the xPhraseFirst() and xPhraseNext() API methods (and by xPhraseFirstColumn() and xPhraseNextColumn() as illustrated below).
This API can be quite slow if used with an FTS5 table created with the "detail=none" or "detail=column" option. If the FTS5 table is created with either "detail=none" or "detail=column" and "content=" option (i.e. if it is a contentless table), then this API always iterates through an empty set (all calls to xPhraseFirst() set iCol to -1).
xPhraseNext() See xPhraseFirst above.
xPhraseFirstColumn() This function and xPhraseNextColumn() are similar to the xPhraseFirst() and xPhraseNext() APIs described above. The difference is that instead of iterating through all instances of a phrase in the current row, these APIs are used to iterate through the set of columns in the current row that contain one or more instances of a specified phrase. For example: Fts5PhraseIter iter; int iCol; for(pApi->xPhraseFirstColumn(pFts, iPhrase, &iter, &iCol); iCol>=0; pApi->xPhraseNextColumn(pFts, &iter, &iCol) ){ // Column iCol contains at least one instance of phrase iPhrase }
This API can be quite slow if used with an FTS5 table created with the "detail=none" option. If the FTS5 table is created with either "detail=none" "content=" option (i.e. if it is a contentless table), then this API always iterates through an empty set (all calls to xPhraseFirstColumn() set iCol to -1).
The information accessed using this API and its companion xPhraseFirstColumn() may also be obtained using xPhraseFirst/xPhraseNext (or xInst/xInstCount). The chief advantage of this API is that it is significantly more efficient than those alternatives when used with "detail=column" tables.
xPhraseNextColumn() See xPhraseFirstColumn above.
Variables
| Type | Name | Description | |
|---|---|---|---|
| int | iVersion | ||
| int(*)(Fts5Context *) | xColumnCount | ||
| int(*)(Fts5Context *, int iCol, int *pnToken) | xColumnSize | ||
| int(*)(Fts5Context *, int iCol, const char **pz, int *pn) | xColumnText | ||
| int(*)(Fts5Context *, int iCol, sqlite3_int64 *pnToken) | xColumnTotalSize | ||
| void *(*)(Fts5Context *, int bClear) | xGetAuxdata | ||
| int(*)(Fts5Context *, int iIdx, int *piPhrase, int *piCol, int *piOff) | xInst | ||
| int(*)(Fts5Context *, int *pnInst) | xInstCount | ||
| int(*)(Fts5Context *) | xPhraseCount | ||
| int(*)(Fts5Context *, int iPhrase, Fts5PhraseIter *, int *, int *) | xPhraseFirst | ||
| int(*)(Fts5Context *, int iPhrase, Fts5PhraseIter *, int *) | xPhraseFirstColumn | ||
| void(*)(Fts5Context *, Fts5PhraseIter *, int *piCol, int *piOff) | xPhraseNext | ||
| void(*)(Fts5Context *, Fts5PhraseIter *, int *piCol) | xPhraseNextColumn | ||
| int(*)(Fts5Context *, int iPhrase) | xPhraseSize | ||
| int(*)(Fts5Context *, int iPhrase, void *pUserData, int(*)(const Fts5ExtensionApi &#... | xQueryPhrase | ||
| int(*)(Fts5Context *, sqlite3_int64 *pnRow) | xRowCount | ||
| sqlite3_int64(*)(Fts5Context *) | xRowid | ||
| int(*)(Fts5Context *, void *pAux, void(*xDelete)(void *)) | xSetAuxdata | ||
| int(*)(Fts5Context *, const char *pText, int nText, void *pCtx, int(*xToken)(voi... | xTokenize | ||
| void *(*)(Fts5Context *) | xUserData |