Philipp Januskovecz
Philipp Januskovecz

Reputation: 898

Deleting specific row in table doesn't work, SQLite.Swift, Xcode 7

I want to delete a row with the given value (contactID), which is also the primary key, in SQLite.Swift:

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

The given contactID surely exists, but it doesn't delete the row ...

Upvotes: 0

Views: 309

Answers (2)

Bee
Bee

Reputation: 12502

Try this too.

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

Upvotes: 0

Bee
Bee

Reputation: 12502

Try with some error handling. You'll catch if there are any errors.

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

Upvotes: 1

Related Questions