这看起来很基本,但在使用变量时我找不到正确的语法。
这有效:
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)
答案 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"