create a update and delete function for sqlite that uses the following parameters “(using db: opaquepointer?, with query: string)” in swift

main.swift
import SQLite3

func executeQuery(using db: OpaquePointer?, with query: String) {
    var stmt: OpaquePointer?
    if sqlite3_prepare_v2(db, query, -1, &stmt, nil) == SQLITE_OK {
        if sqlite3_step(stmt) == SQLITE_DONE {
            print("Query executed successfully")
        } else {
            print("Error executing query")
        }
    } else {
        print("Error preparing query")
    }
    sqlite3_finalize(stmt)
}

// Update function
func updateRecord(using db: OpaquePointer?, with query: String) {
    executeQuery(using: db, with: query)
}

// Delete function
func deleteRecord(using db: OpaquePointer?, with query: String) {
    executeQuery(using: db, with: query)
}
690 chars
26 lines

related categories

gistlibby LogSnag