当我在应用程序上单击“保存”按钮时,出现所有错误,但一切正常,但是当我尝试保存时,数据库抛出的错误被锁定。.
我检查数据库表仍然存在,但是错误不断出现,我尝试了很多方法来解决此错误,但是找不到解决方案 我还完成了sqlite_finalize(querystatement)和sqlite_close(db)。
func singlesave(queryString:String)
{
db = openDatabase()
var queryStatement: OpaquePointer? = nil
if sqlite3_prepare_v2(db, queryString, -1, &queryStatement, nil) == SQLITE_OK{
if sqlite3_exec(db, queryString, nil, nil, nil) == SQLITE_OK {
print("save successfuly")}
else{
let errmsg = String(cString: sqlite3_errmsg(db)!)
print("failed to save in single table: \(errmsg)")
}
}
sqlite3_finalize(queryStatement)
sqlite3_close(db)
}
func loadsingle()->single
{
db = openDatabase()
var data = single()
let queryStatementString = "SELECT * from single"
var queryStatement: OpaquePointer? = nil
// 1
if sqlite3_prepare(db, queryStatementString, -1, &queryStatement, nil) == SQLITE_OK {
while sqlite3_step(queryStatement) == SQLITE_ROW
{
let queryResultCol1 = sqlite3_column_int(queryStatement, 0)//id
let queryResultCol2 = sqlite3_column_text(queryStatement, 1)//name
let queryResultCol3 = sqlite3_column_text(queryStatement, 2)//arabic
let queryResultCol4 = sqlite3_column_text(queryStatement, 3)//urdu
let queryResultCol5 = sqlite3_column_text(queryStatement, 4)//english
let queryResultCol6 = sqlite3_column_text(queryStatement, 5)//Discription
let queryResultCol7 = sqlite3_column_int(queryStatement, 6)//count
let queryResultCol8 = sqlite3_column_int(queryStatement, 7)//surahid
let queryResultCol9 = sqlite3_column_int(queryStatement, 8)//ayatid
data.Name = String(cString :queryResultCol2!)
data.Arabic = String(cString :queryResultCol3!)
data.Urdu = String(cString :queryResultCol4!)
data.English = String(cString :queryResultCol5!)
data.Discription = String(cString :queryResultCol6!)
data.count = Int(queryResultCol7)
data.surahid = Int(queryResultCol8)
data.ayatid = Int(queryResultCol9)
}
}
else
{print("error")}
sqlite3_finalize(queryStatement)
sqlite3_close(db)
return data
}
函数IUDQuery(queryString:String) { db = openDatabase()
var queryStatement: OpaquePointer? = nil
if sqlite3_prepare_v2(db, queryString, -1, &queryStatement, nil) == SQLITE_OK {
if sqlite3_exec(db,queryString,nil,nil,nil) == SQLITE_OK
{
print("saved")
}
else
{
let errmsg = String(cString: sqlite3_errmsg(db)!)
print("IUDQuery: \(errmsg)")
}
}
sqlite3_finalize(queryStatement)
}