Skip to content

Instantly share code, notes, and snippets.

@fmitha fmitha/luatable.tex
Created May 22, 2019

Embed
What would you like to do?
\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
You can’t perform that action at this time.