我读到了这个,我认为这个值可能是nil,并且您不能断言nil bla bla bla,好吧,我尝试检查此sqlite3_bind_text!= sqlite_ok我尝试了防护,但似乎无济于事。请需要帮助!
func insert(_ name: String = "",_ image: String = "",_ ingredients:String = "", instructions:String = ""){
var stmt:OpaquePointer?
let query = "INSERT INTO Recipe (name,image,ingredients,instructions) VALUES(?,?,?,?)"
if sqlite3_prepare(db,query, -1,&stmt,nil) == SQLITE_OK {
sqlite3_bind_text(db, 1, name, -1, nil)
sqlite3_bind_text(db,2,image,-1,nil)
sqlite3_bind_text(db,3,ingredients,-1,nil)
sqlite3_bind_text(db,4,instructions,-1,nil)
}
}
答案 0 :(得分:0)
nvm解决了
sqlite3_bind_text(db, 1, name, -1, nil)
sqlite3_bind_text(db,2,image,-1,nil)
sqlite3_bind_text(db,3,ingredients,-1,nil)
sqlite3_bind_text(db,4,instructions,-1,nil)
db应该已经替换为stmt而不是dunno为什么
sqlite3_bind_text(stmt, 1, name, -1, nil)
sqlite3_bind_text(stmt,2,image,-1,nil)
sqlite3_bind_text(stmt,3,ingredients,-1,nil)
sqlite3_bind_text(stmt,4,instructions,-1,nil)