windows – Luasql和SQLite?
发布时间:2020-12-14 02:48:18 所属栏目:Windows 来源:网络整理
导读:我刚开始将Lua看作是访问SQLite DLL的简单方法,但在尝试使用与DB无关的LuaSQL模块时遇到了错误: require "luasql.sqlite"module "luasql.sqlite"print("Content-type: Text/htmln")print("Hello!") 请注意,我正在尝试从最基本的设置开始,因此只在工作目录
我刚开始将Lua看作是访问SQLite DLL的简单方法,但在尝试使用与DB无关的LuaSQL模块时遇到了错误:
require "luasql.sqlite" module "luasql.sqlite" print("Content-type: Text/htmln") print("Hello!") 请注意,我正在尝试从最基本的设置开始,因此只在工作目录中包含以下文件,而sqlite.dll实际上是从LuaForge站点重命名的sqlite3.dll: Directory of C:Temp <DIR> luasql lua5.1.exe lua5.1.dll hello.lua Directory of C:Templuasql sqlite.dll 我错过了一些可以解释错误的二进制文件吗? 谢谢. 编辑:我将DLL重命名为其原始sqlite3.dll并更新源以反映这一点(最初重命名它,因为它是在我找到的样本中调用它的方式). 在这一点上,这是代码的样子…… require "luasql.sqlite3" -- attempt to call field 'sqlite' (a nil value) env = luasql.sqlite() env:close() …以及我收到的错误消息: C:&;lua5.1.exe hello.lua lua5.1.exe: hello.lua:4: attempt to call field 'sqlite' (a nil value) 编辑:发现它是什么:env = luasql.sqlite3()而不是env = luasql.sqlite(). 对于像我这样的新手,这是最新的SQLite LuaSQL driver的完整示例: require "luasql.sqlite3" env = luasql.sqlite3() conn = env:connect("test.sqlite") assert(conn:execute("create table if not exists tbl1(one varchar(10),two smallint)")) assert(conn:execute("insert into tbl1 values('hello!',10)")) assert(conn:execute("insert into tbl1 values('goodbye',20)")) cursor = assert(conn:execute("select * from tbl1")) row = {} while cursor:fetch(row) do print(table.concat(row,'|')) end cursor:close() conn:close() env:close() 谢谢. 解决方法
>不要重命名DLL文件:这将导致Lua找不到DLL中的初始化函数(其名称与DLL相同).
>您不需要模块调用,只需要.在创建模块时使用模块,而不是在使用模块时使用. 编辑:根据LuaSQL文档,看起来你需要调用luasql.sqlite3()而不是luasql.sqlite(). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容