【发布时间】:2015-01-31 01:27:32
【问题描述】:
我已经查看了有关此问题的所有论坛,并为我的第一个插入找到了解决方案,我使用“双引号”而不是单引号,如下所示:
insertGiftShop(2,"photo02","Modern City by night photo", "item-grumdy1l", "A view of Modern City''s skytrain",1,100, "","no","items",0)
前面的函数是在游戏开始时插入我的行。当我检查数据库时,值是这样存储的:“现代城市轻轨的视图”。
效果很好!现在我正在尝试获取存储的信息“A view of Modern City's skytrain”并将其插入到另一个表中,如下所示:
function insertInventory(id, code, name, src, desc, sale, qtyoninventory, price, usetxt, type)
local sql = "insert into inventory (id, code, name, src, desc, sale, qtyoninventory, price, usetxt, type) values (" .. id.. ",'" .. code .. "','" .. name .. "', '" .. src .. "', '" .. desc .. "', '" .. sale .. "',"..qtyoninventory..","..price..",'"..usetxt.."','"..type.."')"
db:exec(sql)
end
insertInventory(maxid+1,row_2.code, row_2.name, row_2.src, row_2.desc, "no",1,row_2.price,row_2.usetxt, row_2.type)
在这种情况下,我直接从存储的文件中获取 row_2.desc(什么是“等视图”)。但它不起作用,因为它需要“单引号”!
当文本内部有单引号时,如何告诉“格式化” row_2.desc 以便添加所需的“双引号”?
编辑:
根据您的评论,我更改了在表格中“插入”数据的方式。
所以,我尝试了这个:
tx.executeSql("INSERT INTO inventory(id, code, name) VALUES(?,?,?)",[2, "photo02", "Modern City's skytrain"])
“[”附近有一个错误。语法正确吗?
我用过这个,是否正确并防止SQL注入?
db:exec([[INSERT INTO items(id, code, name, src, desc, sale, qty, price, usetxt, type, onscene, area) VALUES(1,"ls01","LETP", "item-lss", "LVP","no",0,100, "It this burger?", "items", "yes", "table02")]])
【问题讨论】: