【发布时间】:2019-01-26 20:49:24
【问题描述】:
我想在 Flutter 中用 sqflite 保存 html 字符串。
但是html字符串中有很多特殊字符比如'?','=','&'......
它会抛出如下错误:DB Error: 1 "near "?": syntax error"。
我用的是iOS模拟器,所以是基于FMDB的。
这是我的代码:
await database.execute("INSERT INTO ChapterCache(bookName,chapterName,content) select '$bookName','$chapterName','$content' where not exists (select * from ChapterCache where bookName = '$bookName' and chapterName='$chapterName')");
【问题讨论】:
-
你能分享一个引发数据库错误的完整字符串的例子吗?
-
一件事:您不应该将 $bookName 之类的占位符放在引号中。如果 (bookName, chapterName) 是唯一键,您还可以避免插入中的整个讨厌的原因。只需使用
INSERT OR IGNORE ...