如何在 iOS 版 Monotouch 中使用 SQLite 中的 FTS

发布于 2024-10-24 18:59:32 字数 548 浏览 5 评论 0原文

我正在寻找使用 Monotouch 构建一个 iOS 应用程序,它有一个相当大的充满文本的 sqlite 数据库。我需要对此文本进行快速搜索。

我现在最好的解决方案是 FTS 模块(最好是版本 4)。我读到 iOS 上 sqlite 的默认实例不支持 FTS。如果这是真的,使用 Monotouch 构建 sqlite 自定义实例的推荐方法是什么?或者这根本可以做到吗?

我发现这个网站描述了如何使用 xcode 来完成此任务,但不清楚如何使用 Monotouch 来完成此任务。
http://longweekendmobile.com/2010/06/16/sqlite-full-text-search-for-iphone-ipadyour-own-sqlite-for-iphone-and-ipad/

任何帮助都很多赞赏!

I'm looking to build an iOS app using Monotouch that has a rather large sqlite db full of text. I need to provide fast searching over this text.

My best solution right now is the FTS module (preferably version 4). I have read that the default instance of sqlite on iOS does not support FTS. If this is true what is the recommended way to build a custom instance of sqlite with Monotouch? Or can this be done at all?

I found this site describing how to accomplish this with xcode, but it is not clear how I would accomplish with Monotouch.
http://longweekendmobile.com/2010/06/16/sqlite-full-text-search-for-iphone-ipadyour-own-sqlite-for-iphone-and-ipad/

Any help is much appreciated!

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

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

发布评论

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

评论(2

分開簡單 2024-10-31 18:59:32

正如我在上面的评论中提到的,我得到了这个工作,并且由于 Stack Overflow 确实帮助了我,所以我想贡献一点来回馈社区。
免责声明
这是来自一位 .NET 开发人员,他在 iOS/MacOS/XCode/Monotouch 方面是 N00B。
虽然我在 iPad 模拟器上对此进行了测试,但我尚未在实际设备上对其进行测试。
结束免责声明

这是一个快速指南,介绍如何编译您自己的 SQLite 版本并将其包含在您的 Monotouch 项目中,以支持全文搜索。

第 1 步:
下载 SQLite 合并文件。

这包括一个文件中的所有 SQLite。
http://www.sqlite.org/download.html

第 2 步:在 Xcode 中编译 SQLite 源代码iOS。

这里有一个关于如何执行此操作的很好的演练:
http://pp.hillrippers .ch/blog/2009/08/08/Static+SQLite+Library+with+Unicode+Support+for+the+iPhone/

我遵循了步骤 1-5,跳过了#6,因为我们没有添加额外的内容标头。

我没有使用演练中使用的编译标志,而是使用:
SQLITE_ENABLE_COLUMN_METADATA
SQLITE_ENABLE_FTS4

您可能还想添加其他内容。
这些编译标志添加到 XCode 中的“预处理器宏”下项目的“构建”选项卡中。

编译完成后,您应该拥有“mylibrary.a”。

第 3 步:将此文件包含在您的 MonoDevelop 项目中
将 mylibrary.a 添加到 MonoDevelop 中,就像任何其他文件一样,右键单击它并确保构建操作为“Nothing”。

在您的项目选项中选择“iPhone Build”。您需要添加额外的 mtouch 参数。添加以下内容

-gcc_flags "-L${ProjectDir} -lmylibrary -force_load ${ProjectDir}/mylibrary.a"

第 4 步:构建 ac# 包装器
此时你可能会找到一个好的包装纸来包含,但我只是很快推出了自己的包装纸。

有关用 C# 编写 SQLite 包装器的优秀教程,请查看此页面:
http://www.switchonthecode.com/tutorials/csharp-tutorial- write-a-dotnet-wrapper-for-sqlite

因为您的库是项目的一部分,所以您不需要按名称引用库,而是使用“__Internal”关键字。 *注意“__INTERNAL”中有两个下划线*(不要问我在意识到这一点之前浪费了多少时间)

这是我的一个示例

[DllImport ("__Internal", EntryPoint="sqlite3_open")]  
static extern int sqlite3_open_v2(string filename, out IntPtr db);

显然要组合一个包装器还有很多工作,但是有很多信息那里有关于如何做到这一点的信息。一个问题是正确地整理从 SQLite 返回的字符串。 (参见http://blog.gebhardtcomputing.com/2007/11/marshal- utf8-strings-in-net.html 有关编组的更多信息)

这旨在快速演练如何将本机库编译到 MonoDevelop/monotouch 中,我希望它对某人有所帮助。

As I mentioned in my comment above I got this working and since Stack Overflow has really helped me out I wanted to contribute a little to give back to the community.
Disclaimer
This is coming from a .NET developer who is a N00B when it comes to iOS/MacOS/XCode/Monotouch.
Although I tested this out on the iPad simulator I have yet to test it out on an actual device.
End disclaimer

This is a quick how-to compile your own version of SQLite and include it in your Monotouch project with the goal of supporting Full text search.

Step 1:
Download the SQLite amalgamation file.

This includes all of SQLite in one file.
http://www.sqlite.org/download.html

Step 2: Compile the SQLite source in Xcode for iOS.

There is a good walkthrough on how to do this here:
http://pp.hillrippers.ch/blog/2009/08/08/Static+SQLite+Library+with+Unicode+Support+for+the+iPhone/

I followed steps 1-5, skipped #6 since we're not adding additional headers.

Instead of using the compile flags used in the walk through I used:
SQLITE_ENABLE_COLUMN_METADATA
SQLITE_ENABLE_FTS4

There may be others you want to add as well.
These compile flags are added in XCode, to the "Build" tab of the project under "Preprocessor Macros".

Once you've compiled this you should have "mylibrary.a".

Step 3: Include this file in your MonoDevelop project
Add mylibrary.a into MonoDevelop as any other file, right click it and make sure the build action is 'Nothing'.

In your project options select "iPhone Build". You need to add additional mtouch arguments. Add the following

-gcc_flags "-L${ProjectDir} -lmylibrary -force_load ${ProjectDir}/mylibrary.a"

Step 4: Build a c# wrapper
You could probably find a good wrapper to include at this point but I just quickly rolled my own.

For a good tutorial on writing an SQLite wrapper in C# check this page out:
http://www.switchonthecode.com/tutorials/csharp-tutorial-writing-a-dotnet-wrapper-for-sqlite

Because your library is a part of the project you don't need to reference the library by name but instead use the "__Internal" keyword. *NOTE THERE ARE TWO UNDERSCORES IN "__INTERNAL" * (Don't ask me how much time I wasted before I realized that)

Here's a sample of one of mine

[DllImport ("__Internal", EntryPoint="sqlite3_open")]  
static extern int sqlite3_open_v2(string filename, out IntPtr db);

There's obviously a lot more to putting together a wrapper, but there's lots of info out there on how to do that. One gotcha is to properly marshal the strings you get returned from SQLite. (see http://blog.gebhardtcomputing.com/2007/11/marshal-utf8-strings-in-net.html for more info on Marshaling)

This was intended to be a quick walkthrough on getting a native library compiled in into MonoDevelop/monotouch, and I hope it helps someone.

白馒头 2024-10-31 18:59:32

您必须做同样的事情,构建自己的 libsqlite3.a,并修改所有公共导出,这样它就不会与系统加载的 libsqlite 冲突,然后您需要修改要绑定到的任何库sqlite 到 [DllImport ("__Internal")] 而不是 libsqlite。

You would have to do the same thing, build your own libsqlite3.a, and mangle all the public exports so it doesn't conflict with the libsqlite loaded by the system, and then you would need to modify whatever library you want to bind to sqlite to [DllImport ("__Internal")] instead of libsqlite.

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