About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Account
Latest news 2021-06-05: New blog post: Dickimaw Books Site Account.

Display Product List (SQL)

This code requires the samples SQL database. The .dbtex files are created using:

datatooltk --output products.dbtex --sqluser sampleuser --sqldb samples --sql "SELECT * FROM books" 
datatooltk --output customers.dbtex --sqluser sampleuser --sqldb samples --sql "SELECT * FROM people"
datatooltk --output countries.dbtex --sqluser sampleuser --sqldb samples --sql "SELECT * FROM countries"
Alternatively you can use datatooltk-gui to import the data and save it to a file called customer.dbtex.
\documentclass[captions=tableheading]{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{longtable}% required for \DTLdisplaylongdb
\usepackage{datatool}

\DTLloaddbtex{\products}{products.dbtex}

\DTLloaddbtex{\customers}{customers.dbtex}

\DTLloaddbtex{\countries}{countries.dbtex}

\begin{document}

First an example that just uses the \texttt{table} and
\texttt{tabular} environments. See Table~\ref{tab:products}.

\begin{table}
  \caption{A Sample Product List}
  \label{tab:products}
  \centering
  \DTLdisplaydb{\products}
\end{table}

Data loaded from a CSV file has empty rather than null values.
See Table~\ref{tab:customers}.

\begin{table}
  \caption{A Sample Customer List}
  \label{tab:customers}
  \centering
  \DTLdisplaydb
   [id,forenames,title,country,postcode,dob]% omit these columns
  {\customers}
\end{table}

If the data is too large to fit on a single page we need to use the
\texttt{longtable} environment instead. See Table~\ref{tab:countries}.

\DTLdisplaylongdb
 [
   caption={A Sample Long Table},% main caption
   contcaption={A Sample Long Table (Continued)},% continuation caption
   label={tab:countries},% label
   foot={\emph{Continued on next page}},% table foot
   lastfoot={}% final table foot
 ]
 {\countries}

\end{document}

Download sample-datatooltk-sql.tex or sample-datatooltk-sql.pdf.

© 2015 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs