【问题标题】:Trouble populating an SQLite FTS table on iOS在 iOS 上填充 SQLite FTS 表时遇到问题
【发布时间】: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


    【解决方案1】:

    sqlite3_prepare_v2() 不执行语句; sqlite3_step() 会。

    【讨论】:

    • 感谢您的回答,有趣的是有时您会错过显而易见的事情。
    猜你喜欢
    • 1970-01-01
    • 2011-11-20
    • 2022-01-04
    • 2011-10-30
    • 1970-01-01
    • 2019-05-13
    • 1970-01-01
    • 2011-05-22
    • 2017-05-01
    相关资源
    最近更新 更多