I was just starting to learn Lua as an easy way to access the SQLite DLL, but when I tried to use the LuaSQL DB agnostic module, I encountered an error:
require "luasql.sqlite" module "luasql.sqlite" print("Content-type: Text/html\n") print("Hello!")
Please note that I am trying to start with the most basic installation, so only the following files are in the working directory, and sqlite.dll is actually renamed sqlite3.dll from the LuaForge site:
Directory of C: \ Temp
<DIR> luasql
lua5.1.exe
lua5.1.dll
hello.lua
Directory of C: \ Temp \ luasql
sqlite.dll
Am I missing some binaries that would explain the error?
Thanks.
Edit: I renamed the DLL to my sqlite3.dll source file and updated the source code to reflect this (originally renamed it because it was called in the sample I found).
At this point, what the code looks like ...
require "luasql.sqlite3" -- attempt to call field 'sqlite' (a nil value) env = luasql.sqlite() env:close()
... and the error message I get:
C:\>lua5.1.exe hello.lua lua5.1.exe: hello.lua:4: attempt to call field 'sqlite' (a nil value)
Edit: found it to be: env = luasql.sqlite3 () instead of env = luasql.sqlite ().
For beginners like me, here is a complete example with the latest 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()
Thanks.