I am trying to save game settings using sqlite backend. I would like to properly escape string for the player name. Here is what i am using but I am getting “attempt to index a number value”:
local player = “Anomymous”
local sound = 1
local music = 1
function M.saveSettings()
local sql = “delete from settings”
db:exec(sql)
if player=="" then
player = “anonymous”
end
--sql = “insert into settings (player, sound, music) values '” … player …"’,"…sound…","…music…")"
stmt = db:prepare[[insert into settings (player, sound, music) values(:p_player, :p_sound, :p_music)]]
stmt:bind_names({p_player=player, p_sound=sound, p_music=music}):exec()
end
can anyone tell me what’s wrong with the statement?
Thanks,
Kuan