Can I insert values to SQLite Database (.db) in Swift (sqlite3) without mentioning Datatype like bind_int, bind_text, etc etc. Because this is available in Android by using Content Values. Is it possible??
1 Answer
I Have solved my Problem by
func BindStatement(stmt:OpaquePointer?,data:Any, pos:Int)->(Void){
if let dt = data as? String{
guard sqlite3_bind_text(stmt, Int32(pos), (dt as NSString).utf8String, -1, nil) == SQLITE_OK else{
print("error binding String ",pos,data)
return
}
return
}
if let dt = data as? Int{
guard sqlite3_bind_int(stmt, Int32(pos), Int32(dt)) == SQLITE_OK else{
print("error binding Int",pos,data)
return
}
return
}
if let dt = data as? Double{
guard sqlite3_bind_double(stmt, Int32(pos), dt) == SQLITE_OK else{
print("error binding Double ",pos,data)
return
}
return
}
if let _ = data as? NSNull{
guard sqlite3_bind_null(stmt, Int32(pos)) == SQLITE_OK else{
print("error binding ",data)
return
}
return
}
print("----------------nothing Binded ---------------------",pos)
}
Now can I bind key and value together? Because I saved the key-value to a Dictionary and first I have to prepare statement only with the key and then after preparing I have to bind values. So I have to iterate the Dictionary Again. Anyway??