带有 SQLITE FTS3 Xcode 版本的 iPhone 应用程序无法正常工作

发布于 2024-08-21 13:13:24 字数 616 浏览 3 评论 0原文

我的 iPhone 应用程序使用 SQLITE 的 FTS3 函数(特别是 MATCH 和 OFFSET)。这些对于我的优化搜索算法至关重要。我通过在项目中的一个名为 SQLite 的组下包含三个 SQLITE 源文件(即 sqlite3.c、sqlite3.h 和 sqlite3ext.h)来实现 FTS3。我从框架组中删除了之前对 libsqlite3.dylib 库的引用。我将“其他 C 标志”和“其他 C++ 标志”项目设置设置为 -DSQLITE_ENABLE_FTS3=1。 (我还尝试简单地将这些标志设置为 -DSQLITE_ENABLE_FTS3。)

该应用程序在调试和发布版本的模拟器中都表现良好。该应用程序在 iPhone 上也能完美运行,但仅限于调试版本!

发布版本不会为任何使用 MATCH 和 OFFSET 关键字的 SQL 调用返回结果行。我的具体问题是,“当我在连接 iPhone 的情况下构建发布版本时,我的启用 FTS3 的 SQLITE 版本是否未与我的应用程序一起安装?”我在 Mac 上相应的 Release-iphoneos 子文件夹中看到 sqlite.o 对象文件。它比 Debug-iphoneos 子文件夹中的小一点,但我得出的结论是,这是由于缺少调试符号造成的。

我迫切需要一个解决方案,因此任何想法都将不胜感激。

My iPhone application uses SQLITE's FTS3 functions (specifically MATCH and OFFSET). These are essential to my optimized searching algorithm. I implemented FTS3 by including three SQLITE source files, namely sqlite3.c, sqlite3.h and sqlite3ext.h in my project, under a group named SQLite. I removed from the Frameworks group my previous reference to the libsqlite3.dylib library. I set the "Other C Flags" and "Other C++ Flags" project settings to -DSQLITE_ENABLE_FTS3=1. (I also tried simply setting those flags to -DSQLITE_ENABLE_FTS3.)

The application performs perfectly in the Simulator for both debug and release builds. The application also performs perfectly on the iPhone, BUT only for the debug build!

The release build does not return result rows for any SQL calls using the MATCH and OFFSET keywords. My specific question is, "When I build the release version with my iPhone connected, is my FTS3 enabled version of SQLITE not being installing along with my app?" I see the sqlite.o object file in the appropriate Release-iphoneos subfolder on my Mac. It is a bit smaller than the one in the Debug-iphoneos subfolder, but I concluded this is due to a lack of debug symbols.

I am desperate for a solution, so any ideas at all will be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

南汐寒笙箫 2024-08-28 13:13:24

好吧,对于那些可能从我的古怪经历中受益的人来说,这就是解决方案。经过一番折腾后,我决定放松发布版本中的一些优化。我这样做只是为了获得有关问题的另一条线索,而不是作为解决方案。果然,代码完美运行!然后,我说“好吧,让我把优化放回最小和最快,继续我的调查。”神奇的是,一切仍然有效!总而言之,我所做的唯一一件事就是更改项目设置中的优化,然后将其放回去!当然,所有这一切都是经过大量调试、清理所有目标后重新编译等之后的。直到我更改并将优化重置为原始值之前,一切都没有产生任何影响。疯狂,但这就是我的故事,我会坚持下去。希望这可以帮助遇到此问题的其他人。

OK, for those who may benefit from my quirky experience, here was the solution. After much hair pulling I decided to relax some of the optimization in the Release version. I did this just to get another clue as to the problem - not as a solution. Sure enough, the code worked perfectly! Then, I said "OK, let me put the optimization back to smallest and fastest to continue my investigation." Magically, everything still worked!!! In summary, the only thing that I did was to change the optimization in the the Project settings, and then put it back! All of this, of course, was after a lot of debugging, recompiling after cleaning all targets, etc. NOTHING had made a difference until I changed and reset the optimization to the original value. Crazy, but that is my story and I'm sticking to it. Hope this helps someone else experiencing this problem.

千秋岁 2024-08-28 13:13:24

请注意,如果您只使用 fts3,则可以使用 SDK 附带的普通 sqlite3 库。如果执行以下命令:

NSLog(@"Compile options specified when Apple built the library:");
if (sqlite3_prepare_v2(contentDatabase, "PRAGMA compile_options", -1, &statement, NULL) == SQLITE_OK)
{
    while (sqlite3_step(statement) == SQLITE_ROW)
    {
        NSLog(@"%s", sqlite3_column_text(statement, 0));
    }
}

它将告诉您Apple在编译默认库时使用了哪些编译选项。当我运行此命令时,我看到:

SQLite version = 3.7.2
[DATABASE] 编译选项:

ENABLE_FTS3

ENABLE_FTS3_PARENTHESIS

ENABLE_LOCKING_STYLE=1

ENABLE_RTREE

OMIT_BUILTIN_TEST

OMIT_LOAD_EXTENSION

TEMP_STORE=1

THREADSAFE=2

这是针对 iOS 4.3.5 进行编译的。我可以确认 fts3 虚拟表和 MATCH 关键字在我的构建中正常工作。

Just a note that if you are only using fts3 you can just use the normal sqlite3 library that comes with the SDK. If you execute the following:

NSLog(@"Compile options specified when Apple built the library:");
if (sqlite3_prepare_v2(contentDatabase, "PRAGMA compile_options", -1, &statement, NULL) == SQLITE_OK)
{
    while (sqlite3_step(statement) == SQLITE_ROW)
    {
        NSLog(@"%s", sqlite3_column_text(statement, 0));
    }
}

It will tell you what compile options Apple used when compiling the default library. When I run this I see:

SQLite version = 3.7.2
[DATABASE] Compile options:

ENABLE_FTS3

ENABLE_FTS3_PARENTHESIS

ENABLE_LOCKING_STYLE=1

ENABLE_RTREE

OMIT_BUILTIN_TEST

OMIT_LOAD_EXTENSION

TEMP_STORE=1

THREADSAFE=2

This is compiling against iOS 4.3.5. I can confirm that fts3 virtual tables and the MATCH keyword are working in my build.

左耳近心 2024-08-28 13:13:24

我要做的第一件事是对 iPhone 发布版本进行干净的构建,并详细查看原始构建日志。您可以查看那里执行的实际命令,以查看这些额外的编译器/预处理器标志是否实际配置为用于该目标。

如果不是,那么您可能在目标设置中犯了错误。

The first thing I would do is make a clean build of the iPhone release build and look in detail at the raw build log. You can look at the actual commands executed there to see if those extra compiler/preprocessor flags are actually configured to be used for that target.

If they are not then you probably made a mistake in the Target settings.

︶葆Ⅱㄣ 2024-08-28 13:13:24

这个答案与其他答案的不同之处在于以下几个方面:

  • 重点介绍 @Robert Hawkey 提供的有用代码
  • 显示 Xcode 9/Swift 4.0.3 的完整代码和输出
  • 请注意,人们可以识别 iOS 中 SQLite 的有用功能(例如JSON SQL 函数)< /里>

tldr;

PRAGMA 编译选项; (有关编译指示的更多信息

Swift 4.0.3

func testSQLiteOptions(){
    var db: OpaquePointer? = nil
    var statement: OpaquePointer? = nil
    sqlite3_open(self.dbPath, &db)
    guard db != nil else {return}
    NSLog("Compile options specified when Apple built the library:");
    if (sqlite3_prepare_v2(db, "PRAGMA compile_options", -1, &statement, nil) == SQLITE_OK)
    {
      while (sqlite3_step(statement) == SQLITE_ROW)
      {
        NSLog("%s", sqlite3_column_text(statement, 0));
      }
    }
  }

< strong>输出

2017-12-09 06:34:04.233638-0800 jlmj[5997:2882220] Compile options specified when Apple built the library:
2017-12-09 06:34:04.236378-0800 jlmj[5997:2882220] BUG_COMPATIBLE_20160819
2017-12-09 06:34:04.236490-0800 jlmj[5997:2882220] COMPILER=clang-9.0.0
2017-12-09 06:34:04.236574-0800 jlmj[5997:2882220] DEFAULT_CACHE_SIZE=128
2017-12-09 06:34:04.236651-0800 jlmj[5997:2882220] DEFAULT_CKPTFULLFSYNC
2017-12-09 06:34:04.236727-0800 jlmj[5997:2882220] DEFAULT_JOURNAL_SIZE_LIMIT=32768
2017-12-09 06:34:04.236803-0800 jlmj[5997:2882220] DEFAULT_PAGE_SIZE=4096
2017-12-09 06:34:04.236968-0800 jlmj[5997:2882220] DEFAULT_SYNCHRONOUS=2
2017-12-09 06:34:04.237046-0800 jlmj[5997:2882220] DEFAULT_WAL_SYNCHRONOUS=1
2017-12-09 06:34:04.237121-0800 jlmj[5997:2882220] ENABLE_API_ARMOR
2017-12-09 06:34:04.237195-0800 jlmj[5997:2882220] ENABLE_COLUMN_METADATA
2017-12-09 06:34:04.237270-0800 jlmj[5997:2882220] ENABLE_DBSTAT_VTAB
2017-12-09 06:34:04.237345-0800 jlmj[5997:2882220] ENABLE_FTS3
2017-12-09 06:34:04.237421-0800 jlmj[5997:2882220] ENABLE_FTS3_PARENTHESIS
2017-12-09 06:34:04.237497-0800 jlmj[5997:2882220] ENABLE_FTS3_TOKENIZER
2017-12-09 06:34:04.237648-0800 jlmj[5997:2882220] ENABLE_FTS4
2017-12-09 06:34:04.237726-0800 jlmj[5997:2882220] ENABLE_FTS5
2017-12-09 06:34:04.237802-0800 jlmj[5997:2882220] ENABLE_JSON1
2017-12-09 06:34:04.237876-0800 jlmj[5997:2882220] ENABLE_LOCKING_STYLE=1
2017-12-09 06:34:04.237950-0800 jlmj[5997:2882220] ENABLE_PREUPDATE_HOOK
2017-12-09 06:34:04.238023-0800 jlmj[5997:2882220] ENABLE_RTREE
2017-12-09 06:34:04.238097-0800 jlmj[5997:2882220] ENABLE_SESSION
2017-12-09 06:34:04.238172-0800 jlmj[5997:2882220] ENABLE_SNAPSHOT
2017-12-09 06:34:04.238248-0800 jlmj[5997:2882220] ENABLE_SQLLOG
2017-12-09 06:34:04.238323-0800 jlmj[5997:2882220] ENABLE_UNKNOWN_SQL_FUNCTION
2017-12-09 06:34:04.238398-0800 jlmj[5997:2882220] ENABLE_UPDATE_DELETE_LIMIT
2017-12-09 06:34:04.238473-0800 jlmj[5997:2882220] HAS_CODEC_RESTRICTED
2017-12-09 06:34:04.238548-0800 jlmj[5997:2882220] HAVE_ISNAN
2017-12-09 06:34:04.238622-0800 jlmj[5997:2882220] MAX_LENGTH=2147483645
2017-12-09 06:34:04.238695-0800 jlmj[5997:2882220] MAX_MMAP_SIZE=20971520
2017-12-09 06:34:04.242805-0800 jlmj[5997:2882220] MAX_VARIABLE_NUMBER=500000
2017-12-09 06:34:04.242891-0800 jlmj[5997:2882220] OMIT_AUTORESET
2017-12-09 06:34:04.242967-0800 jlmj[5997:2882220] OMIT_LOAD_EXTENSION
2017-12-09 06:34:04.243045-0800 jlmj[5997:2882220] STMTJRNL_SPILL=131072
2017-12-09 06:34:04.243120-0800 jlmj[5997:2882220] SUBSTR_COMPATIBILITY
2017-12-09 06:34:04.243196-0800 jlmj[5997:2882220] THREADSAFE=2
2017-12-09 06:34:04.243509-0800 jlmj[5997:2882220] USE_URI

参考

  1. SQLite 编译时选项
  2. JSON SQLite 函数
  3. Pragma 编译选项

This answer is different from others in the following ways:

  • Highlights the useful code supplied by @Robert Hawkey
  • Shows full code and output for Xcode 9/Swift 4.0.3
  • Notes that one can identify useful features of SQLite in iOS (eg. JSON SQL Functions)

tldr;

PRAGMA compile_options; (more on pragma)

Swift 4.0.3

func testSQLiteOptions(){
    var db: OpaquePointer? = nil
    var statement: OpaquePointer? = nil
    sqlite3_open(self.dbPath, &db)
    guard db != nil else {return}
    NSLog("Compile options specified when Apple built the library:");
    if (sqlite3_prepare_v2(db, "PRAGMA compile_options", -1, &statement, nil) == SQLITE_OK)
    {
      while (sqlite3_step(statement) == SQLITE_ROW)
      {
        NSLog("%s", sqlite3_column_text(statement, 0));
      }
    }
  }

Output

2017-12-09 06:34:04.233638-0800 jlmj[5997:2882220] Compile options specified when Apple built the library:
2017-12-09 06:34:04.236378-0800 jlmj[5997:2882220] BUG_COMPATIBLE_20160819
2017-12-09 06:34:04.236490-0800 jlmj[5997:2882220] COMPILER=clang-9.0.0
2017-12-09 06:34:04.236574-0800 jlmj[5997:2882220] DEFAULT_CACHE_SIZE=128
2017-12-09 06:34:04.236651-0800 jlmj[5997:2882220] DEFAULT_CKPTFULLFSYNC
2017-12-09 06:34:04.236727-0800 jlmj[5997:2882220] DEFAULT_JOURNAL_SIZE_LIMIT=32768
2017-12-09 06:34:04.236803-0800 jlmj[5997:2882220] DEFAULT_PAGE_SIZE=4096
2017-12-09 06:34:04.236968-0800 jlmj[5997:2882220] DEFAULT_SYNCHRONOUS=2
2017-12-09 06:34:04.237046-0800 jlmj[5997:2882220] DEFAULT_WAL_SYNCHRONOUS=1
2017-12-09 06:34:04.237121-0800 jlmj[5997:2882220] ENABLE_API_ARMOR
2017-12-09 06:34:04.237195-0800 jlmj[5997:2882220] ENABLE_COLUMN_METADATA
2017-12-09 06:34:04.237270-0800 jlmj[5997:2882220] ENABLE_DBSTAT_VTAB
2017-12-09 06:34:04.237345-0800 jlmj[5997:2882220] ENABLE_FTS3
2017-12-09 06:34:04.237421-0800 jlmj[5997:2882220] ENABLE_FTS3_PARENTHESIS
2017-12-09 06:34:04.237497-0800 jlmj[5997:2882220] ENABLE_FTS3_TOKENIZER
2017-12-09 06:34:04.237648-0800 jlmj[5997:2882220] ENABLE_FTS4
2017-12-09 06:34:04.237726-0800 jlmj[5997:2882220] ENABLE_FTS5
2017-12-09 06:34:04.237802-0800 jlmj[5997:2882220] ENABLE_JSON1
2017-12-09 06:34:04.237876-0800 jlmj[5997:2882220] ENABLE_LOCKING_STYLE=1
2017-12-09 06:34:04.237950-0800 jlmj[5997:2882220] ENABLE_PREUPDATE_HOOK
2017-12-09 06:34:04.238023-0800 jlmj[5997:2882220] ENABLE_RTREE
2017-12-09 06:34:04.238097-0800 jlmj[5997:2882220] ENABLE_SESSION
2017-12-09 06:34:04.238172-0800 jlmj[5997:2882220] ENABLE_SNAPSHOT
2017-12-09 06:34:04.238248-0800 jlmj[5997:2882220] ENABLE_SQLLOG
2017-12-09 06:34:04.238323-0800 jlmj[5997:2882220] ENABLE_UNKNOWN_SQL_FUNCTION
2017-12-09 06:34:04.238398-0800 jlmj[5997:2882220] ENABLE_UPDATE_DELETE_LIMIT
2017-12-09 06:34:04.238473-0800 jlmj[5997:2882220] HAS_CODEC_RESTRICTED
2017-12-09 06:34:04.238548-0800 jlmj[5997:2882220] HAVE_ISNAN
2017-12-09 06:34:04.238622-0800 jlmj[5997:2882220] MAX_LENGTH=2147483645
2017-12-09 06:34:04.238695-0800 jlmj[5997:2882220] MAX_MMAP_SIZE=20971520
2017-12-09 06:34:04.242805-0800 jlmj[5997:2882220] MAX_VARIABLE_NUMBER=500000
2017-12-09 06:34:04.242891-0800 jlmj[5997:2882220] OMIT_AUTORESET
2017-12-09 06:34:04.242967-0800 jlmj[5997:2882220] OMIT_LOAD_EXTENSION
2017-12-09 06:34:04.243045-0800 jlmj[5997:2882220] STMTJRNL_SPILL=131072
2017-12-09 06:34:04.243120-0800 jlmj[5997:2882220] SUBSTR_COMPATIBILITY
2017-12-09 06:34:04.243196-0800 jlmj[5997:2882220] THREADSAFE=2
2017-12-09 06:34:04.243509-0800 jlmj[5997:2882220] USE_URI

Reference

  1. SQLite Compile-Time Options
  2. JSON SQLite Functions
  3. Pragma Compile Options
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文