I am having a little bit of an issue with an sqlite3 implementation in swift not updating a stability subject.
The desk is outlined as follows:
class Consumer {
var id: Int
var uid: String
var stability: Double
var password: String
var handle: String
init(id: Int, uid: String, stability: Double, password: String, handle: String) {
self.id = id
self.uid = uid
self.stability = stability
self.password = password
self.handle = handle
}
}
It’s being created with no points.
I’m writing an preliminary document at creation time with the next code:
func insertUser(id: Int, uid: String, stability: Double, password: String) -> Bool{
let customers = getAllUsers()
// Test consumer e-mail is exist in Consumer desk or not
for consumer in customers{
if consumer.id == id {
return false
}
}
let insertStatementString = "INSERT INTO Consumer (id, uid, stability, password, handle) VALUES (?, ?, ?, ?, ?);"
var insertStatement: OpaquePointer? = nil
if sqlite3_prepare_v2(db, insertStatementString, -1, &insertStatement, nil) == SQLITE_OK {
sqlite3_bind_int(insertStatement, 1, Int32(id))
sqlite3_bind_text(insertStatement, 2, (uid as NSString).utf8String, -1, nil)
sqlite3_bind_double(insertStatement, 3, Double(stability))
sqlite3_bind_text(insertStatement, 4, (password as NSString).utf8String, -1, nil)
sqlite3_bind_text(insertStatement, 5, "", -1, nil) // assign empty worth to deal with
if sqlite3_step(insertStatement) == SQLITE_DONE {
print("Consumer is created efficiently.")
sqlite3_finalize(insertStatement)
return true
} else {
print("Couldn't add.")
return false
}
} else {
print("INSERT assertion is failed.")
return false
}
}
Up thus far, every part is working as anticipated. all fields are set appropriately.
I attempt to replace the stability with the next code:
/ Replace Earnings on Consumer desk
func updateEarnings(id: Int, stability: Double) -> Bool {
let updateStatementString = "UPDATE Consumer set stability=? the place id=?;"
var updateStatement: OpaquePointer? = nil
if sqlite3_prepare_v2(db,updateStatementString, -1, &updateStatement, nil) == SQLITE_OK {
sqlite3_bind_double(updateStatement, 2, Double(stability))
if sqlite3_step(updateStatement) == SQLITE_DONE {
print("Earnings Up to date Efficiently.")
sqlite3_finalize(updateStatement)
return true
} else {
print("Couldn't replace.")
return false
}
} else {
print("UPDATE assertion is failed.")
return false
}
}
I’ve verified that it and stability each have the suitable values. It returns true however stability is rarely up to date with the worth handed in.
Any solutions can be appreciated.