lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, Mar 27, 2013 at 1:30 AM, Christian Bielert <cib123@googlemail.com> wrote:
I would like to use sqlite3 with lua. Luckily, there exist a wrapper
library. As neither luadist nor luarocks seem to work out of the box
with msys(or if they do, both their luasql packages are broken), I've
downloaded the windows binary release from
http://lua.sqlite.org/index.cgi/index. I unpacked luasql/sqlite3.dll
into the directory with my lua files and called the lua interpreter to
try out the functionality outlined in the documentation(e.g.
"sqlite3.open(filename)")

> require "stdlib"
> require "luasql.sqlite3"
> pprint(luasql)
{sqlite3 = 'function: 0062B810', _VERSION = 'LuaSQL 2.1.0', _DESCRIPTION = 'LuaS
QL is a simple interface from Lua to a DBMS', _COPYRIGHT = 'Copyright (C) 2003-2
007 Kepler Project}

Okay, so the only thing I can do at all is call luasql.sqlite3()?
Let's try that.

> result = luasql.sqlite3()
> =result
SQLite3 environment (0062D290)
> =type(result)
userdata
> result.open("foo")
The function to call is result:connect(). See LuaSQL documentation[1]. The module is included in the batteries package and works out of the box in LuaDist.

local sql = require "luasql.sqlite3"
local driver = sql.sqlite3()
local db = sql:connect("test")

pd

[1] http://www.keplerproject.org/luasql/manual.html#drivers