iOS用中文字串查詢SQLite資料庫多條資料的坑
阿新 • • 發佈:2021-01-11
技術標籤:ios資料庫字串mysqlsqlitepython
例如有這樣一個數據表:
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)
.都只能查到第一條符合的資料.