在 SQLite 中使用准备好的语句和全文搜索
我正在使用 SQLite C 接口来编写应用程序。由于我喜欢安全性,因此我使用准备好的语句来查询数据库。在一个这样的查询中,我使用 MATCH 关键字从虚拟数据库中选择行进行全文搜索。下面是一个示例:
SELECT * FROM Emails
WHERE ( Subject LIKE ?001 OR ?001 IS NULL )
AND ( Author LIKE ?002 OR ?002 IS NULL )
AND ( Body MATCH ?003 OR ?003 IS NULL )
这允许用户单独或以任意组合输入任何术语(主题、作者或正文)来进行搜索。任何未输入的术语,我都会将 NULL 绑定到该参数。该语句的问题在于不能将 OR 关键字与 MATCH 关键字一起使用。我正在寻找一个可以与 MATCH 关键字一起使用的语句,以便在不在“正文”列中搜索时返回所有行。有这样的说法吗?
I'm using the SQLite C interface to write an application. Since I like security, I'm using prepared statements to query the database. In one such query, I'm selecting rows from a virtual database using the MATCH keyword for full-text-searching. Here's an example:
SELECT * FROM Emails
WHERE ( Subject LIKE ?001 OR ?001 IS NULL )
AND ( Author LIKE ?002 OR ?002 IS NULL )
AND ( Body MATCH ?003 OR ?003 IS NULL )
This allows the user to enter any terms (Subject, Author, or Body) individually or in any combination to do a search. Any term that isn't entered, I'll bind NULL to that parameter. The problem with that statement is that you can't use the OR keyword with the MATCH keyword. I'm looking for a statement I can use with the MATCH keyword to return all rows if not searching in the Body column. Is there such a statement?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议如下:
I suggest the following:
我最终在运行时修改了 SQL 语句,将 MATCH 替换为 LIKE '%'。不是很优雅,但目前可以使用。
I ended up modifying the SQL statement at runtime to replace MATCH with LIKE '%'. Not very elegant, but it works for now.