gpt4 book ai didi

swift - 如何在查询中使用like

转载 作者:行者123 更新时间:2023-11-30 12:02:02 24 4
gpt4 key购买 nike

我在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com