使用 Corona 在 SQLite 中插入查询



如何插入这样的字符串:

 local Namestring="my mother's gift"
local insertQuery1 =[[INSERT INTO planne_tbl VALUES (']]..Namestring..[[');]]
db:exec( insertQuery1 )

如何在 sqlite 中插入'符号。

通过连接字符串来构造 SQL 命令不仅会导致格式问题,而且还会允许 SQL 注入攻击。

在 SQL 中使用字符串值的推荐方法是使用参数。在Lua中,它的工作原理是这样的:

local Namestring="my mother's gift"
local insertQuery1 = "INSERT INTO planne_tbl VALUES (?)"
local stmt = db:prepare(insertQuery1)
stmt:bind(1, Namestring)
stmt:step()
stmt:finalize()

(这非常复杂;您可能需要为此编写一个帮助程序函数。

最新更新