在使用变量时,corona lua sql更新语句的正确语法

这可能看起来非常基础,但我在使用变量时找不到正确的语法。

以下是有效的:

local updateTable = [[UPDATE userDetails SET month_id = 100 WHERE id=1]]

db:exec( updateTable)

以下是无效的:

local myVariable = 100

local updateTable = [[UPDATE userDetails SET month_id = myVariable WHERE id=1]]

db:exec( updateTable)
点赞
用户50476
用户50476

使用连接运算符..来实现,例如:

local updateTable = [[UPDATE userDetails SET month_id = ]] .. myVariable .. [[ WHERE id=1]]

如果myVariable来自应用程序外部,请注意SQL注入。请参考:Lua mysql,需要一种转义数据的方式,或者在谷歌搜索“lua + prepared statement”。

2012-06-17 17:52:46