Bug 1270882 - Enable support for SQLite custom FTS3 tokenizers at run time. r=mak

Do not require that SQLite has been built with support for custom FTS3
tokenizers enabled by default. This allows to use system SQLite in
distributions which provide SQLite configured in this way (which is SQLite
upstream's default configuration due to security concerns).

Requires exposing the sqlite3_db_config symbol in bundled SQLite.

Disable no longer needed setting of SQLITE_ENABLE_FTS3_TOKENIZER macro in
bundled SQLite build.
This commit is contained in:
Arfrever Frehtes Taifersar Arahesis 2018-11-29 23:02:10 +00:00
parent 9afe3aa0da
commit 6780dfb979
4 changed files with 20 additions and 4 deletions

View File

@ -58,10 +58,6 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'uikit':
DEFINES['SQLITE_ENABLE_LOCKING_STYLE'] = 0
# Thunderbird needs the 2-argument version of fts3_tokenizer()
if CONFIG['MOZ_THUNDERBIRD'] or CONFIG['MOZ_SUITE']:
DEFINES['SQLITE_ENABLE_FTS3_TOKENIZER'] = 1
# Turn on SQLite's assertions in debug builds.
if CONFIG['MOZ_DEBUG']:
DEFINES['SQLITE_DEBUG'] = 1

View File

@ -45,6 +45,7 @@ sqlite3_create_function
sqlite3_create_function16
sqlite3_create_module
sqlite3_data_count
sqlite3_db_config
sqlite3_db_filename
sqlite3_db_handle
sqlite3_db_mutex

View File

@ -106,6 +106,10 @@ if CONFIG['MOZ_MEMORY'] and not CONFIG['MOZ_SYSTEM_SQLITE']:
if CONFIG['OS_TARGET'] != 'Android':
DEFINES['MOZ_STORAGE_MEMORY'] = True
# Thunderbird needs the 2-argument version of fts3_tokenizer()
if CONFIG['MOZ_THUNDERBIRD'] or CONFIG['MOZ_SUITE']:
DEFINES['MOZ_SQLITE_FTS3_TOKENIZER'] = 1
# This is the default value. If we ever change it when compiling sqlite, we
# will need to change it here as well.
DEFINES['SQLITE_MAX_LIKE_PATTERN_LENGTH'] = 50000

View File

@ -602,6 +602,11 @@ nsresult Connection::initialize() {
return convertResultCode(srv);
}
#ifdef MOZ_SQLITE_FTS3_TOKENIZER
srv = ::sqlite3_db_config(mDBConn, SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, 1, 0);
MOZ_ASSERT(srv == SQLITE_OK, "SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER should be enabled");
#endif
// Do not set mDatabaseFile or mFileURL here since this is a "memory"
// database.
@ -636,6 +641,11 @@ nsresult Connection::initialize(nsIFile *aDatabaseFile) {
return convertResultCode(srv);
}
#ifdef MOZ_SQLITE_FTS3_TOKENIZER
srv = ::sqlite3_db_config(mDBConn, SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, 1, 0);
MOZ_ASSERT(srv == SQLITE_OK, "SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER should be enabled");
#endif
// Do not set mFileURL here since this is database does not have an associated
// URL.
mDatabaseFile = aDatabaseFile;
@ -665,6 +675,11 @@ nsresult Connection::initialize(nsIFileURL *aFileURL) {
return convertResultCode(srv);
}
#ifdef MOZ_SQLITE_FTS3_TOKENIZER
srv = ::sqlite3_db_config(mDBConn, SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, 1, 0);
MOZ_ASSERT(srv == SQLITE_OK, "SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER should be enabled");
#endif
// Set both mDatabaseFile and mFileURL here.
mFileURL = aFileURL;
mDatabaseFile = databaseFile;