LuaSQLite3

Check-in [2ad6aad5b6]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add update_hook example; fix examples for Lua 5.2.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2ad6aad5b6237a5b1b43e133224294f05e8345a0
User & Date: e 2013-03-30 23:33:11
Context
2013-03-31
13:01
Update documentation. Add unit tests for update_hook. Include extra fikes for deprecated make. check-in: 6337de362e user: e tags: trunk
2013-03-30
23:33
Add update_hook example; fix examples for Lua 5.2. check-in: 2ad6aad5b6 user: e tags: trunk
16:58
Move tests to their own directory. Remove installpath.lua now unused. check-in: 6ec6a38f08 user: e tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to examples/aggregate.lua.

1
2
3
4
5
6
7
8
9

require("lsqlite3")

local db = sqlite3.open_memory()

assert( db:exec "CREATE TABLE test (col1, col2)" )
assert( db:exec "INSERT INTO test VALUES (1, 2)" )
assert( db:exec "INSERT INTO test VALUES (2, 4)" )
assert( db:exec "INSERT INTO test VALUES (3, 6)" )

|







1
2
3
4
5
6
7
8
9

local sqlite3 = require("lsqlite3")

local db = sqlite3.open_memory()

assert( db:exec "CREATE TABLE test (col1, col2)" )
assert( db:exec "INSERT INTO test VALUES (1, 2)" )
assert( db:exec "INSERT INTO test VALUES (2, 4)" )
assert( db:exec "INSERT INTO test VALUES (3, 6)" )

Changes to examples/function.lua.

1
2
3
4
5
6
7
8
9

require("lsqlite3")


local db = sqlite3.open_memory()

assert( db:exec "CREATE TABLE test (col1, col2)" )
assert( db:exec "INSERT INTO test VALUES (1, 2)" )
assert( db:exec "INSERT INTO test VALUES (2, 4)" )

|







1
2
3
4
5
6
7
8
9

local sqlite3 = require("lsqlite3")


local db = sqlite3.open_memory()

assert( db:exec "CREATE TABLE test (col1, col2)" )
assert( db:exec "INSERT INTO test VALUES (1, 2)" )
assert( db:exec "INSERT INTO test VALUES (2, 4)" )

Changes to examples/order.lua.

1
2
3
4
5
6
7
8
9

require("lsqlite3")

local db = assert( sqlite3:open_memory() )

assert( db:exec[[

  CREATE TABLE customer (
    id		INTEGER PRIMARY KEY, 

|







1
2
3
4
5
6
7
8
9

local sqlite3 = require("lsqlite3")

local db = assert( sqlite3:open_memory() )

assert( db:exec[[

  CREATE TABLE customer (
    id		INTEGER PRIMARY KEY, 

Changes to examples/simple.lua.

1
2
3
4
5
6
7
8
9

require("lsqlite3")

local db = sqlite3.open_memory()

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

  INSERT INTO test VALUES (NULL, 'Hello World');

|







1
2
3
4
5
6
7
8
9

local sqlite3 = require("lsqlite3")

local db = sqlite3.open_memory()

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

  INSERT INTO test VALUES (NULL, 'Hello World');

Changes to examples/smart.lua.

1
2
3
4
5
6
7
8
9

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) ]]


|







1
2
3
4
5
6
7
8
9

local sqlite3 = 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) ]]

Changes to examples/statement.lua.

1
2
3
4
5
6
7
8
9

require("lsqlite3")

local db = sqlite3.open_memory()

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

|







1
2
3
4
5
6
7
8
9

local sqlite3 = require("lsqlite3")

local db = sqlite3.open_memory()

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

Changes to examples/tracing.lua.

1
2
3
4
5
6
7
8
9

require("lsqlite3")

local db = sqlite3.open_memory()

db:trace( function(ud, sql)
  print("Sqlite Trace:", sql)
end )


|







1
2
3
4
5
6
7
8
9

local sqlite3 = require("lsqlite3")

local db = sqlite3.open_memory()

db:trace( function(ud, sql)
  print("Sqlite Trace:", sql)
end )

Added examples/update_hook.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

local sqlite3 = require("lsqlite3")

local db = sqlite3.open_memory()

optbl = { [sqlite3.UPDATE] = "UPDATE";
          [sqlite3.INSERT] = "INSERT";
          [sqlite3.DELETE] = "DELETE"
        }
setmetatable(optbl,
	{__index=function(t,n) return string.format("Unknown op %d",n) end})

udtbl = {0, 0, 0}

db:update_hook( function(ud, op, dname, tname, rowid)
  print("Sqlite Update Hook:", optbl[op], dname, tname, rowid)
end, udtbl)

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

  INSERT INTO test VALUES (NULL, 'Hello World');
  INSERT INTO test VALUES (NULL, 'Hello Lua');
  INSERT INTO test VALUES (NULL, 'Hello Sqlite3');
  UPDATE test SET content = 'Hello Again World' WHERE id = 1;
  DELETE FROM test WHERE id = 2;
]]

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