我已经查看了其他答案,但没有看到任何答案可以解决我遇到的问题。我更感兴趣的是,我所做的事情是否会起作用,如果是的话,如何起作用;这里有替代方法。该项目适用于使用 objective-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 上实现了相同的代码,并且运行良好。任何帮助将不胜感激。
最佳答案
sqlite3_prepare_v2()
不执行语句; sqlite3_step()
确实如此。
关于ios - 在 iOS 上填充 SQLite FTS 表时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41098730/