lua-users home
lua-l archive

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


	Hi Rob

> Is any very basic tutorials anywhere on the relationship between the 
> luasql and sqlite
	The relationship is the same as with any other driver:
You have to start with:

require"luasql.sqlite" -- or the driver you want instead of sqlite
env = luasql.sqlite()
conn = env:connect("ex1") -- you may have to add a username and password

> how to write a simple thing like ex1 (from the man page for sqlite) in 
> lua using lua sql for example?
>        $ sqlite ex1
>        SQLite version 2.0.0
>        Enter ".help" for instructions
>        sqlite> create table tbl1(one varchar(10), two smallint);
>        sqlite> insert into tbl1 values("hello!",10);
>        sqlite> insert into tbl1 values("goodbye", 20);
>        sqlite> select * from tbl1;
>        hello!|10
>        goodbye|20
>        sqlite>
	After the mentioned lines above, you can continue with:

assert(conn:execute("create table 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

> the only example i've been able to find so far is the one here: 
> http://www.keplerproject.org/luasql/examples.html
	It is just a simple example; does it fail ?
	By reading the docs -- particularly the `fetch' method -- you'll
see that other constructions can be used instead of the above one.

	Regards,
		Tomás