X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/b7670459b9549ad6dcca2398580165e54b09b92d..f6efe9ce58f5c88c63f21527255552f27a12498d:/src/src/lookups/mysql.c diff --git a/src/src/lookups/mysql.c b/src/src/lookups/mysql.c index 781b09575..f2e9a1565 100644 --- a/src/src/lookups/mysql.c +++ b/src/src/lookups/mysql.c @@ -1,10 +1,10 @@ -/* $Cambridge: exim/src/src/lookups/mysql.c,v 1.5 2007/08/23 10:16:51 ph10 Exp $ */ +/* $Cambridge: exim/src/src/lookups/mysql.c,v 1.7 2010/03/05 15:59:29 nm4 Exp $ */ /************************************************* * Exim - an Internet mail transport agent * *************************************************/ -/* Copyright (c) University of Cambridge 1995 - 2007 */ +/* Copyright (c) University of Cambridge 1995 - 2009 */ /* See the file NOTICE for conditions of use and distribution. */ /* Thanks to Paul Kelly for contributing the original code for these @@ -202,7 +202,7 @@ if (cn == NULL) 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)); @@ -291,6 +291,21 @@ while ((mysql_row_data = mysql_fetch_row(mysql_result)) != NULL) } } +/* more results? -1 = no, >0 = error, 0 = yes (keep looping) + This is needed because of the CLIENT_MULTI_RESULTS on mysql_real_connect(), + we don't expect any more results. */ + +while((i = mysql_next_result(mysql_handle)) >= 0) { + if(i == 0) { /* Just ignore more results */ + DEBUG(D_lookup) debug_printf("MYSQL: got unexpected more results\n"); + continue; + } + + *errmsg = string_sprintf("MYSQL: lookup result error when checking for more results: %s\n", + mysql_error(mysql_handle)); + goto MYSQL_EXIT; +} + /* If result is NULL then no data has been found and so we return FAIL. Otherwise, we must terminate the string which has been built; string_cat() always leaves enough room for a terminating zero. */