-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.lua
36 lines (26 loc) · 882 Bytes
/
test.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
local lsqlite = require("lsqlite")
-- open an in memory database
-- local db = lsqlite.open(":memory:")
-- open a file
local db = lsqlite.open("test.db")
-- open an inaccessible file
-- local 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(results, "error:", err)
local sum=0
for i = 1, #results do
for k, v in pairs( results[i] ) do
print( "row:", i, "key:", k, "value:", v )
sum=sum+v
end
end
print("sum: " .. sum)
db:close()