On Mon, 28 Jan 2002, David S. Jackson wrote:

> I'm just starting my first MySQL db, and I'm going to want to
> print out reports from it and produce a camera-ready document.
> Has anyone done this before, using, say, Star Office or AbiWord
> or something?

David,

I go this way for high quality output:

echo "$QUERY" | mysql db | filter.sh > tempfile.tex
tex   tempfile.tex   -->  tempfile.dvi
dvips tempfile.dvi   -->  tempfile.ps

filter.sh may be quite complex. It is a shell script
(or you can use perl) launching sed or awk to produce 
the TeX source. The appendix is an example of a filter
to produce verbatim output from plain ASCII text
with fixed spacing.

Thomas Spahni

(pass the spam filter: MySQL table database query)

#!/bin/sh
# print ASCII texts "AS IS"
# this acts like a filter: taking input from stdin
# and sending output to the printer

# these are user-definable
TMPDIR="/tmp"
TMPFILE="printfile"
PRINTER="lpr -Php"

# --- no user configuration beyond this line ---

TMPDEST="${TMPDIR}/${TMPFILE}"

# just to avoid any conflicts:
# tmpfile is our lockfile at the same time
if test -e "${TMPDEST}.tex" ; then
   echo "$TMPDEST exists; aborting" >&2
   exit 1
fi

# create the necessary header first
cat > ${TMPDEST}.tex <<-'XXX'
\message{A4 paper size}%
\hsize 159.2mm %210mm - 1in * 2 for margins
\vsize 246.2mm %297mm - 1in * 2 for margins
% Define special characters for direct use
\catcode`Ç=\active  \defÇ{\c{C}}   \catcode`ü=\active  \defü{\"u}
\catcode`é=\active  \defé{\'e}     \catcode`â=\active  \defâ{\^a}
\catcode`ä=\active  \defä{\"a}     \catcode`à=\active  \defà{\`a}
\catcode`å=\active  \defå{{\aa}}   \catcode`ç=\active  \defç{\c{c}}
\catcode`ê=\active  \defê{\^e}     \catcode`ë=\active  \defë{\"e}
\catcode`è=\active  \defè{\`e}     \catcode`ï=\active  \defï{{\"\i}}
\catcode`î=\active  \defî{{\^\i}}  \catcode`ì=\active  \defì{{\`\i}}
\catcode`Ä=\active  \defÄ{\"A}     \catcode`Å=\active  \defÅ{{\AA}}
\catcode`É=\active  \defÉ{\'E}     \catcode`æ=\active  \defæ{{\ae}}
\catcode`Æ=\active  \defÆ{{\AE}}   \catcode`ô=\active  \defô{\^o}
\catcode`ö=\active  \defö{\"o}     \catcode`ò=\active  \defò{\`o}
\catcode`û=\active  \defû{\^u}     \catcode`ù=\active  \defù{\`u}
\catcode`Ö=\active  \defÖ{\"O}     \catcode`Ü=\active  \defÜ{\"U}
\catcode`á=\active  \defá{\'a}     \catcode`í=\active  \defí{{\'\i}}
\catcode`ó=\active  \defó{\'o}     \catcode`ú=\active  \defú{\'u}
\catcode`ñ=\active  \defñ{\~n}     \catcode`Ñ=\active  \defÑ{\~N}
\catcode`ß=\active  \defß{{\ss}}   \def\quest{?}
%
% strange fontsize to ensure that 80 characters make up one line
\font\vtt=cmtt10 at 10.77pt
\footline={\vtt\hfil - \the\pageno\ -\hfil}
%
\def\uncatcodespecials{\def\do##1{\catcode`##1=12 } \dospecials}
\def\setupverbatim{%
    \par \vtt \spaceskip=0pt % Make sure we get fixed vtt spacing
    \obeylines\uncatcodespecials\obeyspaces\verbatimdefs}
% This macro turns on verbatim mode until ?endverbatim is seen.
\def\verbatim{\begingroup \setupverbatim
  \parskip=0pt plus .05\baselineskip \parindent=0pt
   \catcode`\ =13 \catcode`\^^M=13 \catcode`\?=0
   \verbatimgobble}
{\catcode`\^^M=13{\catcode`\ =13\gdef\verbatimdefs{\def^^M{\ \par}\let =\ }}
  \gdef\verbatimgobble#1^^M{}}
% This defines ?endverbatim to end the group which begins with \verbatim
\let\endverbatim=\endgroup
\let\|=\relax
\verbatim
XXX
#echo -e "\n" >> ${TMPDEST}.tex

# now add what we get from stdin
cat - | sed -e "s/?/?quest?|/g" >> ${TMPDEST}.tex

# add the tail
cat >> ${TMPDEST}.tex <<-'XXX'
?endverbatim
\vfill\eject
\end
XXX

sync

(cd $TMPDIR && tex ${TMPFILE}.tex)

if test -r "${TMPDIR}/${TMPFILE}.dvi" ; then
   (cd $TMPDIR && dvips $DVIARGS ${TMPFILE}.dvi)
   $PRINTER "${TMPDIR}/${TMPFILE}.ps"
fi

# clean up

(cd $TMPDIR && rm -f \
  ${TMPFILE}.tex ${TMPFILE}.log ${TMPFILE}.dvi ${TMPFILE}.ps)


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <mysql-unsubscribe-##L=##[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to