HomeiOS Developmentios - SQLITE3 not updating in swift regardless of returning no errors

ios – SQLITE3 not updating in swift regardless of returning no errors


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 Person {
    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()
        
        // Verify person electronic mail is exist in Person desk or not
        for person in customers{
            if person.id == id {
                return false
            }
        }
        
        let insertStatementString = "INSERT INTO Person (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("Person 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 little thing is working as anticipated. all fields are set appropriately.

I attempt to replace the stability with the next code:

/ Replace Earnings on Person desk
    func updateEarnings(id: Int, stability: Double) -> Bool {
        let updateStatementString = "UPDATE Person 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 ideas could be appreciated.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments