【发布时间】:2019-11-11 01:59:14
【问题描述】:
我正在尝试使用 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]?)
}
}
}
【问题讨论】: