gpt4 book ai didi

ios - 如何使用 iOS Swift 在 Azure DB 中执行 SQL 字符串包含查询?

转载 作者:行者123 更新时间:2023-11-29 05:19:47 28 4
gpt4 key购买 nike

我正在尝试使用 iOS swift 在 Azure DB 中执行包含查询的字符串。

但是,我收到以下错误:由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“无法解析格式字符串“CONTAINS(title,”panda”)””

以下是我执行 Azure SQL 查询的代码:

static func tableQueryOrderBy(_ tableName: String, queryCondition: String,
orderBy: String, isDescending: Bool,
fetchOffset: Int, fetchLimit: Int,
queryCallBack: @escaping ([AnyObject]?) -> ()) {

guard let delegate = UIApplication.shared.delegate as? AppDelegate,
let client = delegate.client else { return }

// condition
guard let table = client.table(withName: tableName) else { return }
guard let query = MSQuery(table: table) else { return }
if queryCondition != "" {
query.predicate = NSPredicate(format: queryCondition)
}
isDescending ? query.order(byDescending: orderBy) : query.order(byAscending: orderBy)
query.fetchOffset = fetchOffset
query.fetchLimit = fetchLimit
query.read { result, error in
if let err = error {
// print("Query failed: ", err.localizedDescription)
queryCallBack(nil)

} else if let items = result?.items {
// print("Query succeeded!")
queryCallBack(items as [AnyObject]?)
}
}
}

最佳答案

终于找到了@Sanket Ray 的一个有效示例,将他/她的答案复制粘贴到此处:

let firstName = NSPredicate(format: "firstName CONTAINS[c] %@", searchText)
let lastName = NSPredicate(format: "lastName CONTAINS[c] %@", searchText)

let orCompoundPredicate = NSCompoundPredicate(orPredicateWithSubpredicates:
[firstNamePredicate,lastNamePredicate]

引用号:NSPredicate: Combine CONTAINS with IN

关于ios - 如何使用 iOS Swift 在 Azure DB 中执行 SQL 字符串包含查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58794688/

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