我正在尝试根据本教程(CoreData
此处)设置索引数据库FMDB
我是ios的初学者,所以添加时可能会出错
SQLITE_ENABLE_FTS3 SQLITE_ENABLE_FTS3_PARENTHESIS 宏。
我将它们添加到其他 C 标志。
这是我的代码:
- (void) setIndexDatabase
{
// Create (or open) our database
NSString *dbPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
dbPath = [dbPath stringByAppendingPathComponent:@"Index.sqlite"];
// Using the FMDatabaseQueue ensures that we don't accidentally talk to our database concurrently from two different threads
FMDatabaseQueue *queue = [FMDatabaseQueue databaseQueueWithPath:dbPath];
[queue inTransaction:^(FMDatabase *db, BOOL *rollback) {
[db executeUpdate:@"CREATE VIRTUAL TABLE IF NOT EXISTS docs USING fts4(name, contents);"];
}];
//Add content to index
[queue inDatabase:^(FMDatabase *db) {
[db executeUpdate:@"INSERT INTO docs (name, contents) VALUES(?, ?);", @"doc1", @"She sells sea shells by the sea shore."];
}];
//Search
__block NSMutableArray *matches = [NSMutableArray array];
[queue inDatabase:^(FMDatabase *db) {
FMResultSet *resultSet = [db executeQuery:@"SELECT name FROM docs WHERE docs MATCH ?", @"she*"];
while ([resultSet next]) {
[matches addObject:[resultSet stringForColumn:@"name"]];
}
}];
}
编辑:
DB 错误:1“没有这样的模块:fts4”
我在应用程序委托中的 didFinishLaunchingWithOptions 方法中调用此函数