corona lua sql update语句使用变量时的正确语法

时间:2012-06-17 17:46:34

标签: sql lua corona

这看起来很基本,但在使用变量时我找不到正确的语法。

这有效:

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)

1 个答案:

答案 0 :(得分:2)

只需使用concat运算符..,就像这样:

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

如果myVariable来自您的应用外部,请注意SQL注入。请参阅:Lua mysql, need a way to escape data或Google lua + "prepared statement"