我的代碼如下:Sqlite.Swift不明確的列名斯威夫特
let assetTag = Expression<String>("asset_tag")
let query2 = mdm.select(mdm[assetTag],os, mac, lastReported)
.filter(mdm[assetTag] != "ipad" && location == facility)
.order(mdm[assetTag])
.join(mdm, on: ewp[assetTag] == mdm[assetTag])
let results2 = try! db.prepare(query2)
我得到的錯誤,說:
fatal error: 'try!' expression unexpectedly raised an error: ambiguous column name: mdm.asset_tag (code: 1): file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-802.0.53/src/swift/stdlib/public/core/ErrorType.swift, line 182
我的數據庫有兩個表,一個名爲EWP和一個叫MDM 。兩者都有一個名爲asset_tag的列,所以我想通過執行mdm [assetTag]來選擇正確的列,但仍會拋出錯誤。
編輯
仍然無法解決問題。我創造我的表如下:
let db = try Connection("\(path)/db.sqlite3")
try db.run(ewp.create { t in
t.column(assetTag)
t.column(location)
t.column(deviceStatus)
})
try db.run(mdm.create { t in
t.column(assetTag)
t.column(os)
t.column(mac)
t.column(lastReported)
})
}
出於某種原因,MDM [ASSETTAG]仍稱列是模糊的,但那裏有隻1列這樣。