File: prepara_sql2.lua

package info (click to toggle)
lua-cgi 6.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 956 kB
  • sloc: javascript: 2,216; makefile: 25
file content (33 lines) | stat: -rwxr-xr-x 718 bytes parent folder | download | duplicates (8)
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
#!/usr/local/bin/lua
-- Prepara o 2o. teste de acesso ao banco de dados.
-- Sao criadas duas tabelas com uma chave estrangeira ligando-as.

MAX_ROWS = arg[1] or 10

require"postgres"

local env = assert (luasql.postgres ())
local conn = assert (env:connect ("luasql-test", "tomas"))

-- Apaga restos de outros testes.
conn:execute "drop table t2"
conn:execute "drop table t1"

-- Criando as tabelas.
assert (conn:execute [[create table t1 (
	a int,
	b int
)]])
assert (conn:execute [[create table t2 (
	c int,
	d int
)]])

-- Preenchedo as tabelas.
for i = 1, MAX_ROWS do
	local ii = 2*i
	assert (conn:execute (string.format ([[
insert into t1 values (%d, %d);
insert into t2 values (%d, %d);]],
		ii, i, ii, i)))
end