lsqlite
a simple libsqlite3 binding for lua5.0-5.2 that provides 3 functions only and is still fully functional: local db = lsqlite.open(database) results, err = db:exec(statments) db:close()
require("lsqlite")
-- open an in memory database
-- db = lsqlite.open(":memory:")
-- open a file
local db = lsqlite.open("test.db")
-- open an inaccessible file
-- db = lsqlite.open("/root/test.db")
-- check if we got an handle
if not db then print("could not open the database") return end
db:exec("drop table 'my_table';")
db:exec("create table 'my_table' ( 'a', 'b' );")
db:exec("insert into 'my_table' values ( 1, 2 );")
db:exec("insert into 'my_table' values ( 3, 4 );")
db:exec("insert into 'my_table' values ( 5, 6 );")
db:exec("insert into 'my_table' values ( -111, -222 );")
results, err=db:exec("select * from 'my_table';")
print(err, results)
local sum=0
for i = 1, #results do
for k, v in pairs( results[i] ) do
print( i, k, v )
sum=sum+v
end
end
print("sum: " .. sum)
db:close()
浙公网安备 33010602011771号