mirror of
https://github.com/darlinghq/fmdb.git
synced 2025-02-20 13:53:44 +00:00
Don't force custom tokenizer module name
This commit is contained in:
parent
6c20e62a0a
commit
a8df75e87c
@ -1,11 +1,11 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'FMDB'
|
||||
s.version = '2.4'
|
||||
s.version = '2.4.1'
|
||||
s.summary = 'A Cocoa / Objective-C wrapper around SQLite.'
|
||||
s.homepage = 'https://github.com/ccgus/fmdb'
|
||||
s.license = 'MIT'
|
||||
s.author = { 'August Mueller' => 'gus@flyingmeat.com' }
|
||||
s.source = { :git => 'https://github.com/ccgus/fmdb.git', :tag => 'v2.4' }
|
||||
s.source = { :git => 'https://github.com/ccgus/fmdb.git', :tag => 'v2.4.1' }
|
||||
s.requires_arc = true
|
||||
|
||||
s.default_subspec = 'standard'
|
||||
|
@ -25,16 +25,26 @@ extern NSString *const kFTSCommandAutoMerge; // "automerge=%u"
|
||||
@interface FMDatabase (FTS3)
|
||||
|
||||
/**
|
||||
Register a delgate implementation in the global table. The name should be used
|
||||
as a parameter when creating the table.
|
||||
Register a delegate implementation in the global table. This should be used when using a single tokenizer.
|
||||
*/
|
||||
+ (void)registerTokenizer:(id<FMTokenizerDelegate>)tokenizer withName:(NSString *)name;
|
||||
+ (void)registerTokenizer:(id<FMTokenizerDelegate>)tokenizer;
|
||||
|
||||
/**
|
||||
Calls the `fts3_tokenizer()` function on this database, installing the "fmdb" tokenizer module.
|
||||
Register a delegate implementation in the global table. The key should be used
|
||||
as a parameter when creating the table.
|
||||
*/
|
||||
+ (void)registerTokenizer:(id<FMTokenizerDelegate>)tokenizer withKey:(NSString *)key;
|
||||
|
||||
/**
|
||||
Calls the `fts3_tokenizer()` function on this database, installing tokenizer module with the 'fmdb' name.
|
||||
*/
|
||||
- (BOOL)installTokenizerModule;
|
||||
|
||||
/**
|
||||
Calls the `fts3_tokenizer()` function on this database, installing the tokenizer module with specified name.
|
||||
*/
|
||||
- (BOOL)installTokenizerModuleWithName:(NSString *)name;
|
||||
|
||||
/**
|
||||
Runs a "special command" for FTS3/FTS4 tables.
|
||||
*/
|
||||
|
@ -18,6 +18,8 @@ NSString *const kFTSCommandAutoMerge = @"automerge=%u";
|
||||
/* I know this is an evil global, but we need to be able to map names to implementations. */
|
||||
static NSMapTable *g_delegateMap = nil;
|
||||
|
||||
static NSString *kDefaultTokenizerDelegateKey = @"DefaultTokenizerDelegateKey";
|
||||
|
||||
/*
|
||||
** Class derived from sqlite3_tokenizer
|
||||
*/
|
||||
@ -32,8 +34,6 @@ typedef struct FMDBTokenizer
|
||||
*/
|
||||
static int FMDBTokenizerCreate(int argc, const char * const *argv, sqlite3_tokenizer **ppTokenizer)
|
||||
{
|
||||
NSCParameterAssert(argc > 0); // Check that the name of the tokenizer is set in CREATE VIRTUAL TABLE
|
||||
|
||||
FMDBTokenizer *tokenizer = (FMDBTokenizer *) sqlite3_malloc(sizeof(FMDBTokenizer));
|
||||
|
||||
if (tokenizer == NULL) {
|
||||
@ -41,7 +41,13 @@ static int FMDBTokenizerCreate(int argc, const char * const *argv, sqlite3_token
|
||||
}
|
||||
|
||||
memset(tokenizer, 0, sizeof(*tokenizer));
|
||||
tokenizer->delegate = [g_delegateMap objectForKey:[NSString stringWithUTF8String:argv[0]]];
|
||||
|
||||
NSString *key = kDefaultTokenizerDelegateKey;
|
||||
if (argc > 0) {
|
||||
key = [NSString stringWithUTF8String:argv[0]];
|
||||
}
|
||||
|
||||
tokenizer->delegate = [g_delegateMap objectForKey:key];
|
||||
|
||||
if (!tokenizer->delegate) {
|
||||
return SQLITE_ERROR;
|
||||
@ -179,10 +185,10 @@ static const sqlite3_tokenizer_module FMDBTokenizerModule =
|
||||
|
||||
@implementation FMDatabase (FTS3)
|
||||
|
||||
+ (void)registerTokenizer:(id<FMTokenizerDelegate>)tokenizer withName:(NSString *)name
|
||||
+ (void)registerTokenizer:(id<FMTokenizerDelegate>)tokenizer withKey:(NSString *)key
|
||||
{
|
||||
NSParameterAssert(tokenizer);
|
||||
NSParameterAssert([name length]);
|
||||
NSParameterAssert([key length]);
|
||||
|
||||
static dispatch_once_t onceToken;
|
||||
|
||||
@ -191,15 +197,20 @@ static const sqlite3_tokenizer_module FMDBTokenizerModule =
|
||||
valueOptions:NSPointerFunctionsWeakMemory];
|
||||
});
|
||||
|
||||
[g_delegateMap setObject:tokenizer forKey:name];
|
||||
[g_delegateMap setObject:tokenizer forKey:key];
|
||||
}
|
||||
|
||||
- (BOOL)installTokenizerModule
|
||||
+ (void)registerTokenizer:(id<FMTokenizerDelegate>)tokenizer
|
||||
{
|
||||
[self registerTokenizer:tokenizer withKey:kDefaultTokenizerDelegateKey];
|
||||
}
|
||||
|
||||
- (BOOL)installTokenizerModuleWithName:(NSString *)name
|
||||
{
|
||||
const sqlite3_tokenizer_module *module = &FMDBTokenizerModule;
|
||||
NSData *tokenizerData = [NSData dataWithBytes:&module length:sizeof(module)];
|
||||
|
||||
FMResultSet *results = [self executeQuery:@"SELECT fts3_tokenizer('fmdb', ?)", tokenizerData];
|
||||
FMResultSet *results = [self executeQuery:@"SELECT fts3_tokenizer(?, ?)", name, tokenizerData];
|
||||
|
||||
if ([results next]) {
|
||||
[results close];
|
||||
@ -209,6 +220,11 @@ static const sqlite3_tokenizer_module FMDBTokenizerModule =
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)installTokenizerModule
|
||||
{
|
||||
return [self installTokenizerModuleWithName:@"fmdb"];
|
||||
}
|
||||
|
||||
- (BOOL)issueCommand:(NSString *)command forTable:(NSString *)tableName
|
||||
{
|
||||
NSString *sql = [NSString stringWithFormat:@"INSERT INTO %1$@(%1$@) VALUES (?)", tableName];
|
||||
|
Loading…
x
Reference in New Issue
Block a user