Created
May 22, 2019 17:50
-
-
Save fmitha/fc89c3f55dcfdf9e2dbb0f8d770d5b52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\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