swift - 如何在查询中使用like

标签 swift sqlite

我在 sqlite 查询中遇到问题,我想使用“like”进行搜索,但 Xcode 显示此错误

"Ambiguous reference to member 'like(_:escape:)'"

这样写可能有问题吗?但我阅读了 SQLite-Swift 的 GitHub 文档。

GitHub 中的示例是

users.filter(email.like("%@mac.com"))
// SELECT * FROM "users" WHERE ("email" LIKE '%@mac.com') 

这是我的代码

import Foundation
import SQLite
import UIKit
class ViewService {

  var database : Connection!

  let inputDetailTable = Table("input_detail")
  let deleteFlag = Expression<Int>("delete_flag")
  let id = Expression<Int>("id")

func selectTableData(date :Date) -> [InputDetail] {

let selectedData = self.inputDetailTable.filter(self.deleteFlag == 0 
&& self.deleteFlag.like("0%"))

}
}

希望有人能帮助我。

最佳答案

您的删除标志是一个 Int。您不能在 Int 上使用“LIKE”,因为它模式匹配字符序列:

来自the documentation :

The LIKE, GLOB, REGEXP, and MATCH operators

The LIKE operator does a pattern matching comparison. The operand to the right of the LIKE operator contains the pattern and the left hand operand contains the string to match against the pattern. A percent symbol ("%") in the LIKE pattern matches any sequence of zero or more characters in the string. An underscore ("_") in the LIKE pattern matches any single character in the string. Any other character matches itself or its lower/upper case equivalent (i.e. case-insensitive matching). Important Note: SQLite only understands upper/lower case for ASCII characters by default. The LIKE operator is case sensitive by default for unicode characters that are beyond the ASCII range. For example, the expression 'a' LIKE 'A' is TRUE but 'æ' LIKE 'Æ' is FALSE. The ICU extension to SQLite includes an enhanced version of the LIKE operator that does case folding across all unicode characters.

关于swift - 如何在查询中使用like,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47099399/

相关文章:

python - Django sqlite 数据库被锁定

ios - 在自定义 UITableViewCell 中单击按钮时重新加载 UITableView

arrays - 获取 JSON 数据以从数组填充 TableView

ios - Xcode 8 似乎错误地使用 Swift 3 更改了嵌入式框架函数签名

ios - GCDWebservers 后台模式无法在设备上运行

java - JDBC-SQLite 应用程序的调试和运行配置期间的不同结果

ios - 为什么会有 exc_breakpoint?

android - “Table” : syntax error附近的E/SQLiteLog:(1)

sql - 如何在不损害数据库的情况下删除 -journal 文件?

WHERE 表达式中的 SQLite substr 函数