ios - 在 iOS 上填充 SQLite FTS 表时遇到问题

标签 ios objective-c sqlite full-text-search

我已经查看了其他答案,但没有看到任何答案可以解决我遇到的问题。我更感兴趣的是,我所做的事情是否会起作用,如果是的话,如何起作用;这里有替代方法。该项目适用于使用 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/

相关文章:

iphone - 为什么我的电影不能使用 MPMoviePlayerController 播放?

iphone - 如何在后台线程中延迟调用方法

java - 是否可以在 Android 上的共享首选项中存储 SQLite 表

ios - GameplayKit > 让代理在目标跟随路径后停止移动

ios - 发送到实例的无法识别的选择器 - 有人可以帮助我吗?

ios - UITableView 单元格行为不当,显示没有披露等

在框架的某些文件中找不到 iOS 框架 header

python - sqlite3 数据类型中的拼写错误但仍然有效,为什么?

java - 在 Sqlite 中忽略查询中的标点符号

ios - Swift 优化级别 'Fastest' 中断数组排序