アプリケーションをSwift2に移行中に、SQLite.swiftとの結合を作成する際に問題が発生しています。
この場合、1.2 で完璧に機能していたものが 2.0 では機能しません。バグであるか、更新された構文の問題である可能性がありますが、それを理解することはできません.
いくつかのテーブルの結合を実行しています:
// Prep tables
let equipment = Table("Equipment")
let equ_id = Expression<Int>("Equipment_ID")
let equ_type = Expression<Int>("EquipmentType_ID")
let equ_owner = Expression<Int>("Equipment_Owner_ID")
let equ_manufacturer = Expression<String>("Manufacturer")
let equ_model = Expression<String>("Model")
let equ_serial = Expression<String>("Serial")
let equ_notes = Expression<String>("Notes")
let equ_facid = Expression<Int>("Facility_ID")
let equ_depid = Expression<Int>("Department_ID")
let equ_cctid = Expression<Int>("CostCenter_ID")
let equ_location = Expression<String>("Location_Details")
let equ_status = Expression<Int>("Status")
let equ_esttime = Expression<Int>("Planned_Maint_Est_Time")
let facilities = Table("Facilities")
let fac_id = Expression<Int>("Facility_ID")
let fac_name = Expression<String>("Facility_Name")
let equipment_type = Table("EquipmentTypes")
let eqt_id = Expression<Int>("EquipmentType_ID")
let eqt_type = Expression<String>("Equipment_Type")
let preUsers = Table("PreUsers")
let Worker_ID = Expression<Int>("Worker_ID")
let First_Name = Expression<String>("First_Name")
let Last_Name = Expression<String>("Last_Name")
let Login = Expression<String>("Login")
let Client_ID = Expression<Int>("Client_ID")
let Company_ID = Expression<Int>("Company_ID")
let Date_LastLogin = Expression<NSDate>("Date_LastLogin")
// Load Initial Equipment Table
let ext_equipment = equipment.join(equipment_type, on: equipment_type[eqt_id] == equipment[equ_type])
.join(facilities, on: facilities[fac_id] == equipment[equ_facid])
.join(preUsers, on: preUsers[Worker_ID] == equipment[equ_owner])
.order(equ_model)
.filter(equ_status >= 0)
これは以前は正常に機能していましたが (新しいテーブル構造に変更する必要がありました)、今は何か間違っているか、結合がフィールドを見つけられません:
for item in db.prepare(ext_equipment)
{
//print("ID: \(item[equ_id]), Make: \(item[equ_model]), Type: \(item[equipment_type[eqt_type]]), Fac: \(item[facilities[fac_name]])")
//print("Owner: \(item[preUsers[First_Name]]) \(item[preUsers[Last_Name]])")
var iID: Int!
iID = item[equ_id]
print(iID)
var eqTemp = Equipment()
eqTemp.eq_ID = iID
eqTemp.eq_Manufacturer = item[equ_manufacturer]
eqTemp.eq_Model = item[equ_model]
eqTemp.eq_Serial = item[equ_serial]
eqTemp.eq_FacilityID = item[facilities[fac_id]]
eqTemp.eq_Facility = item[facilities[fac_name]]
eqTemp.eq_TypeID = item[equipment_type[eqt_id]]
eqTemp.eq_Type = item[equipment_type[eqt_type]]
eqTemp.eq_OwnerID = item[preUsers[Worker_ID]]
eqTemp.eq_Owner = item[preUsers[First_Name]] + " " + item[preUsers[Last_Name]]
eqTemp.eq_Location = item[equ_location]
eqTemp.eq_Status = item[equ_status]
eqTemp.eq_Notes = item[equ_notes]
allEquip.append(eqTemp)
}
また、構文を次のように変更しようとしました。
eqTemp.eq_FacilityID = item.get(facilities[fac_id])
eqTemp.eq_Facility = item.get(facilities[fac_name])
しかし、まだ運がありません。
致命的なエラーをスローします:
fatal error: no such column '"Facilities"."Facility_ID"' in columns:
[
"Expression<()>(template: \"\\\"EquipmentTypes\\\"\", bindings: []).\"Client_ID\"",
"Expression<()>(template: \"\\\"EquipmentTypes\\\"\", bindings: []).\"EquipmentType_ID\"",
"Expression<()>(template: \"\\\"EquipmentTypes\\\"\", bindings: []).\"Equipment_Type\"",
"Expression<()>(template: \"\\\"Equipment\\\"\", bindings: []).\"Client_ID\"",
"Expression<()>(template: \"\\\"Equipment\\\"\", bindings: []).\"CostCenter_ID\"",
"Expression<()>(template: \"\\\"Equipment\\\"\", bindings: []).\"Date_Created\"",
"Expression<()>(template: \"\\\"Equipment\\\"\", bindings: []).\"Date_Decomisioned\"",
"Expression<()>(template: \"\\\"Equipment\\\"\", bindings: []).\"Date_LastMaintenance\"",
"Expression<()>(template: \"\\\"Equipment\\\"\", bindings: []).\"Date_NextMaintenance\"",
"Expression<()>(template: \"\\\"Equipment\\\"\", bindings: []).\"Date_of_First_Use\"",
"Expression<()>(template: \"\\\"Equipment\\\"\", bindings: []).\"Date_of_Purchase\"",
"Expression<()>(template: \"\\\"Equipment\\\"\", bindings: []).\"Default_Priority\"",
"Expression<()>(template: \"\\\"Equipment\\\"\", bindings: []).\"Department_ID\"",
"Expression<()>(template: \"\\\"Equipment\\\"\", bindings: []).\"EquipmentType_ID\"",
"Expression<()>(template: \"\\\"Equipment\\\"\", bindings: []).\"Equipment_ID\"",
"Expression<()>(template: \"\\\"Equipment\\\"\", bindings: []).\"Equipment_Owner_ID\"",
"Expression<()>(template: \"\\\"Equipment\\\"\", bindings: []).\"Facility_ID\"",
"Expression<()>(template: \"\\\"Equipment\\\"\", bindings: []).\"Location_Details\"",
"Expression<()>(template: \"\\\"Equipment\\\"\", bindings: []).\"Maintenance_Peridicity\"",
"Expression<()>(template: \"\\\"Equipment\\\"\", bindings: []).\"Manufacturer\"",
"Expression<()>(template: \"\\\"Equipment\\\"\", bindings: []).\"Model\"",
"Expression<()>(template: \"\\\"Equipment\\\"\", bindings: []).\"Notes\"",
"Expression<()>(template: \"\\\"Equipment\\\"\", bindings: []).\"Planned_Maint_Est_Time\"",
"Expression<()>(template: \"\\\"Equipment\\\"\", bindings: []).\"Purchase_Price\"",
"Expression<()>(template: \"\\\"Equipment\\\"\", bindings: []).\"Safety_Inspection_Only\"",
"Expression<()>(template: \"\\\"Equipment\\\"\", bindings: []).\"Serial\"",
"Expression<()>(template: \"\\\"Equipment\\\"\", bindings: []).\"Status\"",
"Expression<()>(template: \"\\\"Facilities\\\"\", bindings: []).\"Facility_ID\"",
"Expression<()>(template: \"\\\"Facilities\\\"\", bindings: []).\"Facility_Name\"",
"Expression<()>(template: \"\\\"PreUsers\\\"\", bindings: []).\"Client_ID\"",
"Expression<()>(template: \"\\\"PreUsers\\\"\", bindings: []).\"Client_Identify\"",
"Expression<()>(template: \"\\\"PreUsers\\\"\", bindings: []).\"Company_ID\"",
"Expression<()>(template: \"\\\"PreUsers\\\"\", bindings: []).\"Date_LastLogin\"",
"Expression<()>(template: \"\\\"PreUsers\\\"\", bindings: []).\"First_Name\"",
"Expression<()>(template: \"\\\"PreUsers\\\"\", bindings: []).\"Last_Name\"",
"Expression<()>(template: \"\\\"PreUsers\\\"\", bindings: []).\"Login\"",
"Expression<()>(template: \"\\\"PreUsers\\\"\", bindings: []).\"Worker_ID\""
]:
リストには、次のフィールドが表示されます。
[...]
"Expression<()>(template: \"\\\"Facilities\\\"\", bindings: []).\"Facility_ID\"",
"Expression<()>(template: \"\\\"Facilities\\\"\", bindings: []).\"Facility_Name\"",
[...]
しかし、それでも致命的なエラーが発生します。
Equipment テーブルのすべてのフィールドにアクセスできますが、結合されたテーブルのフィールドにはアクセスできません。
生成された SQL は次のように正しいようです。
print(ext_equipment.asSQL())
戻り値:
SELECT * FROM "Equipment" INNER JOIN "EquipmentTypes" ON ("EquipmentTypes"."EquipmentType_ID" = "Equipment"."EquipmentType_ID") INNER JOIN "Facilities" ON ("Facilities"."Facility_ID" = "Equipment"."Facility_ID") INNER JOIN "PreUsers" ON ("PreUsers"."Worker_ID" = "Equipment"."Equipment_Owner_ID") WHERE ("Status" >= 0) ORDER BY "Model"
どんな助けでも大歓迎です