Re: [Exim] mysql lookups / !SELECT / affected_rows

Top Page
Delete this message
Reply to this message
Author: Alexander Sabourenkov
Date:  
To: exim-users
Subject: Re: [Exim] mysql lookups / !SELECT / affected_rows
Hello.

In case someone's still interested in ${lookup mysql ... } returning number of affected rows instead of deferring
for non-SELECT queries, here is the patch against 4.12's src/lookups/mysql.c

While Nico's point that INSERTs/DELETEs/UPDATEs belong to some sidekick daemon holds true, I think
that perfectly valid mysql query should not cause the lookup to defer.

I believe it can be applied to most of 4.x releases as well.


--- exim-4.12-orig/src/lookups/mysql.c  Wed Dec 18 13:28:02 2002
+++ exim-4.12/src/lookups/mysql.c       Fri Dec 27 13:47:33 2002
@@ -243,6 +243,11 @@


  if ((mysql_result = mysql_use_result(mysql_handle)) == NULL)
    {
+  if ( mysql_field_count(mysql_handle) == 0 )
+    {
+    result = string_sprintf("%d", mysql_affected_rows(mysql_handle));
+    goto MYSQL_EXIT;
+    }
    *errmsg = string_sprintf("MYSQL: lookup result failed: %s\n",
      mysql_error(mysql_handle));
    *defer_break = FALSE;



--

./lxnt