Login
or
register
Usando_um_BD
Usando um BD
Anonymous users must enter
captcha
below.
Don't put anything here
Don't put anything here
Page Content
Existem algumas bibliotecas para acessar banco de dados com Lua, mas apenas [LuaSQL](http://www.keplerproject.org/luasql/) fornece acesso uniforme a diferentes bancos de dados. Aqui está um exemplo simples de como usar o LuaSQL: -- Initialization (1) require"luasql.postgres" local env = luasql.postgres () local conn = assert (env:connect ("lpg")) -- Building SQL statement (2) course_list = { "Music", "Literature", } for i, course in ipairs (course_list) do course_list[i] = "'"..course.."'" end local c_list = table.concat (course_list, ",") local stmt = [=[ select a.id, a.name from alumn a inner join course c on (a.course_id = c.id) where c.name in (]=]..c_list..")" -- SQL execution and error handling (3) local cur, err = conn:execute (stmt) if not cur then error (err.." SQL = [=["..stmt.."]=]") end -- Iteration loop (4) local id, name = cur:fetch () while id do cgilua.put (string.format ("<tr><td>id = %%s<td>name = %%s</tr>", id, name)) id, name = cur:fetch () end No entanto, seria melhor definir um iterator para usar dentro de uma página Lua: function lines (stmt) local cur = assert (conn:execute(stmt)) return function () return cur:fetch() end end <table> <%% for id, name in lines"select id, name from alumn" do %%> <tr> <td><%%= id %%> <td><%%= name %%> </tr> <%% end %%> </table>
Advanced Fields
Page Name (for URL)
Page Title
Breadcrumb Text
Category
Apresentação
Créditos
Equipe
Exemplos
Instalação
Lista de discussão
Lista de tarefas
Mapa do site
Perguntas (FAQ)
Porque Lua?
Servidores
Visão
Visão geral
Don't put anything here
Don't put anything here
A summary of your changes
Don't put anything here
Don't put anything here
save
preview
cancel
Projeto Kepler
Apresentação
Porque Lua?
Visão
Perguntas (FAQ)
Créditos
Mapa do site
Como usar o WSAPI
Instalação
Servidores
Exemplos
Comunidade
Visão geral
Equipe
Lista de discussão
Lista de tarefas