Right now I'm using perl within Exim and then doing queries via SQL
Relay.
http://sqlrelay.sourceforge.net/
It seems like it may be easier if there were native sqlrelay support
within Exim.
I know sqlrelay provides drop in libraries for mysql to link against so
I will try that before long.