例如有这样一个数据表:
Paste_Image.png
想要查询league=”英超”的数据集.
可以直接写死let sql = " SELECT * FROM match where league = '英超'"
,这样可以查询想要的结果.
而如果使用let sql = "SELECT * FROM match where league = ?"
.
假如参数是let canshustr = "英超"
, 则在绑定参数时,必须是把参数转成utf8
let canshustrutf = canshustr.cString(using: String.Encoding.utf8)
sqlite3_bind_text(statement,1,canshustrutf,-1,nil)
直接使用sqlite3_bind_text(statement,1, canshustr,-1,nil)
或者
sqlite3_bind_text(statement,1,canshustr.cString(using: String.Encoding.utf8),-1,nil)
.都只能查到第一条符合的数据.