2
0

test_sql2.lua 650 B

123456789101112131415161718192021222324
  1. require"postgres"
  2. local env = assert (luasql.postgres ())
  3. local conn = assert (env:connect ("luasql-test", "tomas"))
  4. local cur = assert (conn:execute ("select count(*) from t1"))
  5. local total = tonumber (cur:fetch())
  6. cur:close()
  7. local aleatorio = math.random(total)
  8. local cur = assert (conn:execute ("select * from t1, t2 where b = d and a != "..2*aleatorio))
  9. cgilua.htmlheader()
  10. cgilua.put ("Aleatorio = "..aleatorio.."<br>\n")
  11. local a,b,c,d = cur:fetch()
  12. cgilua.put ("<table>\n")
  13. while a do
  14. -- cgilua.put ("<tr><td>",a,"<td>",b,"<td>",c,"<td>",d,"</tr>")
  15. a,b,c,d = cur:fetch()
  16. end
  17. cgilua.put ("</table>\n")
  18. cur:close()
  19. conn:close()
  20. env:close()