【发布时间】:2016-12-12 10:28:27
【问题描述】:
我查看了其他答案,但没有看到任何答案可以解决我遇到的问题。我更感兴趣的是,我这样做的方式是否可行,如果可行,如何;比这里是替代方法。该项目适用于使用目标 c 的移动设备。
首先创建常规表,然后创建 FTS 表,如下所示。
NSString *searchTable = [NSString stringWithFormat:@"CREATE TABLE IF NOT EXISTS %@ (%@ INTEGER PRIMARY KEY, %@ TEXT, %@ TEXT, %@ TEXT)", gPsalmVersesTableName, gIDKey , gNameKey, gVerseKey, gTextKey];
if (sqlite3_exec(mInfoDB, [searchTable UTF8String], NULL, NULL, &errMsg) != SQLITE_OK)
NSLog(@"Failed to create table %@", gPsalmVersesTableName);
NSString *virtualTable = [NSString stringWithFormat:@"CREATE VIRTUAL TABLE IF NOT EXISTS %@ USING fts4 (content='%@', %@)",gFTSPsalmVersesTableName, gPsalmVersesTableName, gTextKey];
if (sqlite3_exec(mInfoDB, [virtualTable UTF8String], NULL, NULL, &errMsg) != SQLITE_OK)
NSLog(@"Failed to create table %@", gFTSPsalmVersesTableName);
然后我填充常规表 (gPsalmVersesTableName),我已确认此步骤工作正常。通过下载应用内容并在数据库查看器中读取表格。
当我填充 FTS 表时,我没有收到任何错误,但是没有数据被添加到表中。
if (sqlite3_open([mDataBaseName UTF8String], &mInfoDB) == SQLITE_OK)
{
sqlite3_stmt *statement;
@try
{
NSString *rebuildSQL = [NSString stringWithFormat:@"INSERT INTO %@(%@) VALUES('rebuild')", gFTSPsalmVersesTableName, gFTSPsalmVersesTableName];
int result = sqlite3_prepare_v2(mInfoDB, [rebuildSQL UTF8String], -1, &statement, NULL);
NSLog(@"%s", sqlite3_errstr(result));
}
@finally
{
sqlite3_finalize(statement);
sqlite3_close(mInfoDB);
}
}
我已经在 Android 上实现了相同的代码,并且运行良好。任何帮助将不胜感激。
【问题讨论】:
标签: ios objective-c sqlite full-text-search