create a update and delete function for sqlite that uses the following parameters “(using db: opaquepointer?, with query: string)” in swift with the option for specific errors thrown for each function in swift
main.swift
import SQLite3
enumDatabaseError: Error{
case connectionError
case queryError
case updateError
case deleteError
}
funcupdateRecord(usingdb: OpaquePointer?, withquery: String)throws {
guardlet db = db else {
throwDatabaseError.connectionError
}
var statement: OpaquePointer?
if sqlite3_prepare_v2(db, query, -1, &statement, nil) ==SQLITE_OK {
if sqlite3_step(statement) !=SQLITE_DONE {
throwDatabaseError.updateError
}
} else {
throwDatabaseError.queryError
}
sqlite3_finalize(statement)
}
funcdeleteRecord(usingdb: OpaquePointer?, withquery: String)throws {
guardlet db = db else {
throwDatabaseError.connectionError
}
var statement: OpaquePointer?
if sqlite3_prepare_v2(db, query, -1, &statement, nil) ==SQLITE_OK {
if sqlite3_step(statement) !=SQLITE_DONE {
throwDatabaseError.deleteError
}
} else {
throwDatabaseError.queryError
}
sqlite3_finalize(statement)
}