nlatexdb Version 0.04
Database Access in LaTeX
Copyright (C) 2011 Robin Höns
A few years ago, I wanted to do database reports, and MS Reporting
Services appeared rather inconvenient to me. So I figured I'd use the
typesetting power of Latex, and I
found latexdb by
Hans-Georg Eßer. The idea was great, but
unfortunately I couldn't make it run under Windows, so I wrote a clone
in Ruby, called ratexdb.
At the time, Ruby had a convenient and powerful database access
package called DBI, so I really didn't have to write much code in
order to support a whole bunch of data sources. Great! In the next few
years, I fixed some bugs, added some nice features at the request of
helpful users (thank you!), -- and then I got a new computer.
I installed Latex, I installed Ruby, and it turned out DBI wouldn't
work any more. It seems that people have chosen that from now on DBI
shall be deprecated, there is a new thing called RDBI, and everybody
should use that. I tried it, it didn't work. It depended on some
packages, and those packages on some other packages, and I can't
really claim I had a good time installing all these packages.
So what did I do? Well, I had a good time rewriting the whole thing in
C# -- since my Ruby code was rather ugly anyway, I decided this time
I'd do it a bit more cleanly. Most of the code was written in a
delayed train, so thanks to the Deutsche Bahn for making this program
possible.
- You can connect to a wide variety of data sources, as supported by
.Net DbProviderFactories.
- One executable only, one language. Works fine under Microsoft .Net or Mono.
- Latexdb writes a series of output files for nested queries. Nlatexdb
writes one output file only, nested queries are done by recursion.
- Added the \texdbif{##query}{latex stuff} command: Include "latex
stuff" only if the query returns at least one row. This is useful
for table headings, which can be omitted if there is no data anyway.
- In database results, Latex special characters (\, _, $, &, #, {, }
and %) are replaced by appropriate Latex commands. You can easily
add more character replacements.
- If variables are used in nested SQL queries, they are protected
against SQL injection.
- The database results can be post-processed by regular expression
search and replace.
- Nlatexdb allows command line arguments, which can be referenced in
the Latex source by variable names ##1, ##2, etc. The prefix ("##")
is configurable.
- Added the \texdbcommand{database command}, which sends SQL commands
directly to the database.
- In ratexdb, variables came in one of three flavours:
##varname, $$varname, and &&varname. This doesn't exist any more.
Nlatexdb, unlike ratexdb, knows whether we are in Latex or in SQL,
and behaves accordingly.
In fact, query or variable names don't even have to start with "##"
any more (except for the command line variables, which are still
called "##1", "##2" etc.), but it is still recommended to name them
with a unique prefix, so there is no danger of confusion.
- The parser has less restrictions (I hope). You can split all
commands among several lines. You can comment out the texdb stuff
using the "%" character.
You need Latex (I used Miktex 2.9)
and a .Net runtime 2.0 or newer. Under newer Windows versions, it should
already be installed, otherwise you can get it from Microsoft
here. Under Linux or MacOS you can use
Mono.
For using your favourite database, you might need to install an
appropriate database provider. Usually it should be installed
automatically with the database client. Mono comes with a whole bunch
of DbProviders included.
Nlatexdb is published under the GNU General Public License
and available here:
Added some more debug output. This should help in debugging the SQL
queries.
Added variables RegexSplitter and VariableSplitter.
Added command \texdbforfile.
More debug output.
Compiled under Mono for .Net 2.0. Should be more platform-independent.
Added exe.config file for some configuration possibilities.
Renamed from natexdb to nlatexdb (turns out there is somebody calling himself natexdb... no need to create name clashes)
Initial release.
Please read the README file for more information.
Just copy nlatexdb.exe to a place where it is found. You might have to
install a database provider for your favourite database.
Nlatexdb is just a preprocessor. So it won't work with multi-part
documents (joined by the Latex "\input" command). You can
put the query definitions in each file, and run nlatexdb on all of
them. But you won't be able to use SQL variables of one file in
another file.
Therefore, a kind user sent me an
awk script which
combines all Latex files in one resulting file:
latexmerge.awk
If you have a question, find a bug, like to propose an
improvement, or just wish to tell me you used this tool successfully,
contact me!
Many thanks to Hans-Georg
Eßer for LatexDb.
Many thanks to myself
for ratexdb, and to the people who helped improving it.
nlatexdb is Copyright ©
2011 Robin Höns.
It is released under the GNU
GPL,
a copy of which you find in the package after downloading.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Last Change: 29. August 2011 by Robin Höns