0

This may seem very basic but I cannot find correct syntax when using a variable.

This works:

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

db:exec( updateTable)

the below doesn't:

local myVariable = 100

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

db:exec( updateTable)
Bart Kiers
  • 166,582
  • 36
  • 299
  • 288

1 Answers1

2

Simply use the concat operator, .., like this:

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

If myVariable comes from outside your app, beware of SQL injection. See: Lua mysql, need a way to escape data, or Google for lua + "prepared statement"

Community
  • 1
  • 1
Bart Kiers
  • 166,582
  • 36
  • 299
  • 288