【问题标题】:Deleting specific row in table doesn't work, SQLite.Swift, Xcode 7删除表中的特定行不起作用,SQLite.Swift,Xcode 7
【发布时间】:2015-12-17 17:46:47
【问题描述】:

我想在 SQLite.Swift 中删除具有给定值 (contactID) 的行,这也是主键:

let delRowCo = ContactTable.filter(ContactID == contactID) try db.run(delRowCo.delete())

给定的contactID 肯定存在,但它不会删除该行...

【问题讨论】:

    标签: ios8 swift2 xcode7 sqlite.swift


    【解决方案1】:

    尝试一些错误处理。如果有任何错误,您会发现。

    do {
       if try db.run(delRowCo.delete()) > 0 {
           print("deleted")
       } else {
           print("row not found")
       }
    } catch {
        print("delete failed: \(error)")
    }
    

    【讨论】:

      【解决方案2】:

      也试试这个。

      let mytable = Table("ContactTable")
      let delRowCo = mytable.filter(ContactID == 'contact_id')
      try db.run(delRowCo.delete())
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-21
        • 1970-01-01
        • 2011-05-01
        • 1970-01-01
        • 1970-01-01
        • 2023-01-16
        • 1970-01-01
        相关资源
        最近更新 更多