summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/lsqlite3/examples/smart.lua
blob: 9ee807d8bdbf1b9bf6e0adcc6a49545922b13132 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
require("lsqlite3")

local db = sqlite3.open_memory()

db:exec[[ CREATE TABLE test (id INTEGER PRIMARY KEY, content) ]]

local stmt = db:prepare[[ INSERT INTO test VALUES (:key, :value) ]]

stmt:bind_names{  key = 1,  value = "Hello World"    }
stmt:step()
stmt:reset()
stmt:bind_names{  key = 2,  value = "Hello Lua"      }
stmt:step()
stmt:reset()
stmt:bind_names{  key = 3,  value = "Hello Sqlite3"  }
stmt:step()
stmt:finalize()

for row in db:nrows("SELECT * FROM test") do
  print(row.id, row.content)
end