Skip to content

Instantly share code, notes, and snippets.

@fmitha
Created May 22, 2019 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fmitha/fc89c3f55dcfdf9e2dbb0f8d770d5b52 to your computer and use it in GitHub Desktop.
Save fmitha/fc89c3f55dcfdf9e2dbb0f8d770d5b52 to your computer and use it in GitHub Desktop.
\documentclass{article}
\usepackage{luacode,booktabs}
\usepackage{luapackageloader}
\begin{document}
\begin{luacode*}
-- print(package.cpath)
package.cpath="/usr/lib/x86_64-linux-gnu/lua/5.2/?.so;"..package.cpath
-- print(package.cpath)
local luasql = require "luasql.sqlite3"
env = assert (luasql.sqlite3())
-- connect to data source
con = assert (env:connect("luasql-test"))
-- retrieve a cursor
cur = assert (con:execute"SELECT name, email from people")
-- print all rows, the rows will be indexed by field names
row = cur:fetch ({}, "a")
tex.sprint([[\begin{tabular}{@{}ll@{}}\toprule]])
tex.sprint([[Name & email \\\midrule]])
while row do
tex.sprint(-2,row.name)
tex.sprint("&")
tex.sprint(-2, row.email)
tex.sprint("\\\\")
-- reusing the table of results
row = cur:fetch (row, "a")
end
tex.sprint([[\bottomrule\end{tabular}]])
-- close everything
cur:close()
con:close()
env:close()
\end{luacode*}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-engine: luatex
%%% TeX-master: t
%%% End:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment