如何在 LuaSQLite 3 中使用参数化查询?
如何在 LuaSQLite 3 中使用参数化查询?
我尝试理解以下文档:
http://luasqlite.luaforge.net/lsqlite3.html #methods 用于准备好的语句
并查看此处的示例:
但我无法让它工作:
getTable = function( _key)
local path = system.pathForFile("database.db", system.ResourceDirectory)
local dc = sqlite3.open( path )
local stmt = dc:prepare[[ SELECT * FROM Table WHERE Key = :Key ]]
local sql = stmt:bind({key=_weaponType})
return dc:nrows(sql)
end
我收到错误:
attempt to index 'stmt' (a nil value)
在线:
local sql = stmt:bind({key=_weaponType})
PS 我目前正在 Corona SDK 中开发游戏。
How do you use parameterized query in LuaSQLite 3?
I've tried understanding the documentations at:
http://luasqlite.luaforge.net/lsqlite3.html#methods for prepared statements
and looked at the example here:
How to quote values for LuaSQL?
but I can't get this to work:
getTable = function( _key)
local path = system.pathForFile("database.db", system.ResourceDirectory)
local dc = sqlite3.open( path )
local stmt = dc:prepare[[ SELECT * FROM Table WHERE Key = :Key ]]
local sql = stmt:bind({key=_weaponType})
return dc:nrows(sql)
end
I get the error:
attempt to index 'stmt' (a nil value)
on the line:
local sql = stmt:bind({key=_weaponType})
P.S. I'm currently developing a game in Corona SDK.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您
尝试索引“stmt”(零值)
错误意味着dc:prepare
没有返回任何内容。我假设它实际上返回 nil,errormsg:检查错误是什么;你的陈述可能格式不正确。
You
attempt to index 'stmt' (a nil value)
error meansdc:prepare
didn't return anything.I assume it is actually returning
nil,errormsg
: check what the error is; your statement is probably ill-formed.当 stmt 为空值时,是因为准备指令失败。确保所有字段存在并且查询有效
When stmt is a null value is because the prepare instruction failed. Ensure that all the fields exist and the query is valid