prepara_sql2.lua 600 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/local/bin/lua
  2. MAX_ROWS = arg[1] or 10
  3. require"postgres"
  4. local env = assert (luasql.postgres ())
  5. local conn = assert (env:connect ("luasql-test", "tomas"))
  6. -- Apaga restos de outros testes.
  7. conn:execute "drop table t2"
  8. conn:execute "drop table t1"
  9. -- Criando as tabelas.
  10. assert (conn:execute [[create table t1 (
  11. a int,
  12. b int
  13. )]])
  14. assert (conn:execute [[create table t2 (
  15. c int,
  16. d int
  17. )]])
  18. -- Preenchedo as tabelas.
  19. for i = 1, MAX_ROWS do
  20. local ii = 2*i
  21. assert (conn:execute (string.format ([[
  22. insert into t1 values (%d, %d);
  23. insert into t2 values (%d, %d);]],
  24. ii, i, ii, i)))
  25. end