Mailing List Archive

Patch to allow calling MySQL stored procedures from Exim
The below patch allows you to call MySQL stored procedures that return
results by adding the CLIENT_MULTI_RESULTS flag to the call to
mysql_real_connect(). For more information about this flag, see the
MySQL documentation at:

http://dev.mysql.com/doc/refman/5.0/en/mysql-real-connect.html

(search the page CLIENT_MULTI_RESULTS)

Unless anyone thinks this is a bad idea, I'd like to have this patch
included in the next Exim release.


Bob

--- exim-4.69-orig/src/lookups/mysql.c 2007-08-23 12:16:51.000000000 +0200
+++ exim-4.69/src/lookups/mysql.c 2008-03-20 17:43:04.000000000 +0100
@@ -202,7 +202,7 @@
if (mysql_real_connect(mysql_handle,
/* host user passwd database */
CS sdata[0], CS sdata[2], CS sdata[3], CS sdata[1],
- port, CS socket, 0) == NULL)
+ port, CS socket, CLIENT_MULTI_RESULTS) == NULL)
{
*errmsg = string_sprintf("MYSQL connection failed: %s",
mysql_error(mysql_handle));


--
## List details at http://lists.exim.org/mailman/listinfo/exim-dev Exim details at http://www.exim.org/ ##
Re: Patch to allow calling MySQL stored procedures from Exim [ In reply to ]
B. Johannessen wrote:
> The below patch allows you to call MySQL stored procedures that return
> results by adding the CLIENT_MULTI_RESULTS flag to the call to
> mysql_real_connect().

Huh! This wasn't as simple as I'd hoped. It seems that executing a CALL
query that returns results yields *at least* two result set. At least
one for the results returned from the stored procedure and finally one
for the CALL itself.

Without a fairly major rewrite, the MySQL lookup is unable to handle
multiple rows with different columns in a meaningful way, so to at least
be able to retrieve the first result set, I had to modify the patch a bit.

As this suddenly turned into a bigger change that I originally thought,
I also withdraw my request to have this included in the next Exim
release. Someone that knows a lot more about MySQL then me should really
have a look at it first. Paul Kelly is credited with contributing the
original code; is he still around?


Bob
Re: Patch to allow calling MySQL stored procedures from Exim [ In reply to ]
B. Johannessen wrote:
> Huh! This wasn't as simple as I'd hoped...

This Easter-break thing is no good. I haven't had a real cup of coffee
since yesterday and it shows. Attached it what is hopefully tonights
last attempt.


Bob
Re: Patch to allow calling MySQL stored procedures from Exim [ In reply to ]
Is there any interest in this patch at all or should I just resign
myself for maintaining it privately? For the record, it's been working
flawlessly for me for the last 10 days/~650.000 messages.

To illustrate the beauty of being able to call MySQL stored procedures:

+--------+------------------+--------+-------+------------+------------+
| status | server | filter | sieve | quota | home |
+--------+------------------+--------+-------+------------+------------+
| 0 | cacofonix.db.org | 2 | keep; | 1073741824 | /home/bob/ |
+--------+------------------+--------+-------+------------+------------+
1 row in set (0.00 sec)

This fetches information from 4 or 5 different tables and returns the
relevant values as a single row. Extremely easy to call from Exim, and
if you call it via a macro such as

RCPT = ${lookup mysql{CALL rcpt('${quote_mysql:$local_part}',
'${quote_mysql:$domain}')}}

you can then extract values from the result set such

${if eq {${extract{status}{RCPT}}}{1}}

With the help of the query-cache, this means then Exim will normally
only call the store procedure once per recipient per process.

If you have any interest in this at all, I would like to invite you to
try out the patch (preferably on a non-production system). If you do,
please report back with your results. If there's any interest, I'd
eventually like to this included in Exim, and I'm willing to work out
any bugs as they show up while testing...


Bob

B. Johannessen wrote:
> B. Johannessen wrote:
>> Huh! This wasn't as simple as I'd hoped...
>
> This Easter-break thing is no good. I haven't had a real cup of coffee
> since yesterday and it shows. Attached it what is hopefully tonights
> last attempt.

--
## List details at http://lists.exim.org/mailman/listinfo/exim-dev Exim details at http://www.exim.org/ ##
Re: Patch to allow calling MySQL stored procedures from Exim [ In reply to ]
On Mon, 2008-03-31 at 20:41 +0200, B. Johannessen wrote:
> Is there any interest in this patch at all or should I just resign
> myself for maintaining it privately?

It seems small enough; you should make a (probably wishlist) bug and
attach the patch so it isn't lost in the mailing list noise.

johannes