Index: third_party/sqlite/src/ext/fts3/fts3_tokenizer.c |
diff --git a/third_party/sqlite/src/ext/fts3/fts3_tokenizer.c b/third_party/sqlite/src/ext/fts3/fts3_tokenizer.c |
index 64cfe07aac38fd2aa5bec8c499b1fce4b858b4a5..bfc36af3e38bb1f5bb6a4b44fa4fd4c28abff166 100644 |
--- a/third_party/sqlite/src/ext/fts3/fts3_tokenizer.c |
+++ b/third_party/sqlite/src/ext/fts3/fts3_tokenizer.c |
@@ -30,6 +30,18 @@ |
#include <string.h> |
/* |
+** Return true if the two-argument version of fts3_tokenizer() |
+** has been activated via a prior call to sqlite3_db_config(db, |
+** SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, 1, 0); |
+*/ |
+static int fts3TokenizerEnabled(sqlite3_context *context){ |
+ sqlite3 *db = sqlite3_context_db_handle(context); |
+ int isEnabled = 0; |
+ sqlite3_db_config(db,SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER,-1,&isEnabled); |
+ return isEnabled; |
+} |
+ |
+/* |
** Implementation of the SQL scalar function for accessing the underlying |
** hash table. This function may be called as follows: |
** |
@@ -49,7 +61,7 @@ |
** is a blob containing the pointer stored as the hash data corresponding |
** to string <key-name> (after the hash-table is updated, if applicable). |
*/ |
-static void scalarFunc( |
+static void fts3TokenizerFunc( |
sqlite3_context *context, |
int argc, |
sqlite3_value **argv |
@@ -67,16 +79,20 @@ static void scalarFunc( |
nName = sqlite3_value_bytes(argv[0])+1; |
if( argc==2 ){ |
- void *pOld; |
- int n = sqlite3_value_bytes(argv[1]); |
- if( zName==0 || n!=sizeof(pPtr) ){ |
- sqlite3_result_error(context, "argument type mismatch", -1); |
- return; |
- } |
- pPtr = *(void **)sqlite3_value_blob(argv[1]); |
- pOld = sqlite3Fts3HashInsert(pHash, (void *)zName, nName, pPtr); |
- if( pOld==pPtr ){ |
- sqlite3_result_error(context, "out of memory", -1); |
+ if( fts3TokenizerEnabled(context) ){ |
+ void *pOld; |
+ int n = sqlite3_value_bytes(argv[1]); |
+ if( zName==0 || n!=sizeof(pPtr) ){ |
+ sqlite3_result_error(context, "argument type mismatch", -1); |
+ return; |
+ } |
+ pPtr = *(void **)sqlite3_value_blob(argv[1]); |
+ pOld = sqlite3Fts3HashInsert(pHash, (void *)zName, nName, pPtr); |
+ if( pOld==pPtr ){ |
+ sqlite3_result_error(context, "out of memory", -1); |
+ } |
+ }else{ |
+ sqlite3_result_error(context, "fts3tokenize disabled", -1); |
return; |
} |
}else{ |
@@ -90,7 +106,6 @@ static void scalarFunc( |
return; |
} |
} |
- |
sqlite3_result_blob(context, (void *)&pPtr, sizeof(pPtr), SQLITE_TRANSIENT); |
} |
@@ -209,7 +224,11 @@ int sqlite3Fts3InitTokenizer( |
#ifdef SQLITE_TEST |
-#include <tcl.h> |
+#if defined(INCLUDE_SQLITE_TCL_H) |
+# include "sqlite_tcl.h" |
+#else |
+# include "tcl.h" |
+#endif |
#include <string.h> |
/* |
@@ -350,6 +369,7 @@ int registerTokenizer( |
return sqlite3_finalize(pStmt); |
} |
+ |
static |
int queryTokenizer( |
sqlite3 *db, |
@@ -420,11 +440,13 @@ static void intTestFunc( |
assert( 0==strcmp(sqlite3_errmsg(db), "unknown tokenizer: nosuchtokenizer") ); |
/* Test the storage function */ |
- rc = registerTokenizer(db, "nosuchtokenizer", p1); |
- assert( rc==SQLITE_OK ); |
- rc = queryTokenizer(db, "nosuchtokenizer", &p2); |
- assert( rc==SQLITE_OK ); |
- assert( p2==p1 ); |
+ if( fts3TokenizerEnabled(context) ){ |
+ rc = registerTokenizer(db, "nosuchtokenizer", p1); |
+ assert( rc==SQLITE_OK ); |
+ rc = queryTokenizer(db, "nosuchtokenizer", &p2); |
+ assert( rc==SQLITE_OK ); |
+ assert( p2==p1 ); |
+ } |
sqlite3_result_text(context, "ok", -1, SQLITE_STATIC); |
} |
@@ -440,7 +462,7 @@ static void intTestFunc( |
** sqlite3Fts3HashInit(pHash, FTS3_HASH_STRING, 1); |
** |
** This function adds a scalar function (see header comment above |
-** scalarFunc() in this file for details) and, if ENABLE_TABLE is |
+** fts3TokenizerFunc() in this file for details) and, if ENABLE_TABLE is |
** defined at compilation time, a temporary virtual table (see header |
** comment above struct HashTableVtab) to the database schema. Both |
** provide read/write access to the contents of *pHash. |
@@ -469,10 +491,10 @@ int sqlite3Fts3InitHashTable( |
#endif |
if( SQLITE_OK==rc ){ |
- rc = sqlite3_create_function(db, zName, 1, any, p, scalarFunc, 0, 0); |
+ rc = sqlite3_create_function(db, zName, 1, any, p, fts3TokenizerFunc, 0, 0); |
} |
if( SQLITE_OK==rc ){ |
- rc = sqlite3_create_function(db, zName, 2, any, p, scalarFunc, 0, 0); |
+ rc = sqlite3_create_function(db, zName, 2, any, p, fts3TokenizerFunc, 0, 0); |
} |
#ifdef SQLITE_TEST |
if( SQLITE_OK==rc ){ |