I have created SQLite DB file and filled it with data in an App in simulator and now I need the same database and filled data in a new project. I have copied the SQLite file to new project but every time I update a row (delete/edit) the data is updated until the next run and after rerunning the project my data and SQLite file is like it has been freshly copied to the project.
P.S.: The "clearData(_ SID: Int)" function deletes a row but after rerunning the project in xcode the row is there...
Here is my database structure:
import SQLite
var db: Connection!
let sherTable = Table("Sher");
let ID = Expression<Int>("SID");
let Fname = Expression<String?>("Fname");
let Ename = Expression<String?>("Ename");
let Flike = Expression<Bool?>("Flike");
let Elike = Expression<Bool?>("Elike");
let byteTable = Table("Byte");
let BID = Expression<Int>("BID");
let BSID = Expression<Int>("SID");
let Byte = Expression<String?>("Byte");
let searchText = Expression<String?>("searchText");
let BIsFarsi = Expression<Bool?>("IsFarsi");
let maniTable = Table("Mani");
let MID = Expression<Int>("MID");
let MSID = Expression<Int>("SID");
let Word = Expression<String?>("Word");
let Meaning = Expression<String?>("Meaning");
let MIsFarsi = Expression<Bool?>("IsFarsi");
func connectToDB() {
do {
let path = Bundle.main.path(forResource: "hafezDb", ofType: "sqlite3")!;
let tmp = try Connection(path);
db = tmp;
} catch {
print(error);
}
}
func clearData(_ SID: Int) {
let sher = sherTable.filter(ID == SID);
let u = sher.update(Flike <- !Flike);
do {
try db.run(u);
} catch {
print(error)
}
}