From 5abff0fe486cd1c917454261845d9b993faca24c Mon Sep 17 00:00:00 2001 From: SJ Date: Thu, 10 Jul 2014 09:55:07 +0200 Subject: [PATCH] added errno support for prepared statement execution --- src/defs.h | 1 + src/misc.c | 4 ++++ src/mysql.c | 7 +++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/defs.h b/src/defs.h index ac50e262..aa8dd348 100644 --- a/src/defs.h +++ b/src/defs.h @@ -213,6 +213,7 @@ struct session_data { int journal_envelope_length, journal_bottom_length; #ifdef NEED_MYSQL MYSQL mysql; + unsigned int errno; #endif #ifdef NEED_PSQL PGconn *psql; diff --git a/src/misc.c b/src/misc.c index dc7f8ee4..426e1526 100644 --- a/src/misc.c +++ b/src/misc.c @@ -510,6 +510,10 @@ void init_session_data(struct session_data *sdata, struct __config *cfg){ time(&(sdata->now)); sdata->sent = sdata->delivered = sdata->retained = sdata->now; +#ifdef NEED_MYSQL + sdata->errno = 0; +#endif + #ifdef HAVE_TWEAK_SENT_TIME sdata->sent += cfg->tweak_sent_time_offset; #endif diff --git a/src/mysql.c b/src/mysql.c index 139cc987..d1aa0d79 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -57,6 +57,7 @@ int p_exec_query(struct session_data *sdata, MYSQL_STMT *stmt, struct __data *da unsigned long length[MAX_SQL_VARS]; int i, ret=ERR; + sdata->errno = 0; memset(bind, 0, sizeof(bind)); for(i=0; ittmpfile, mysql_stmt_error(stmt)); + sdata->errno = mysql_stmt_errno(stmt); + syslog(LOG_PRIORITY, "%s: mysql_stmt_bind_param() error: %s (errno: %d)", sdata->ttmpfile, mysql_stmt_error(stmt), sdata->errno); goto CLOSE; } if(mysql_stmt_execute(stmt)){ - syslog(LOG_PRIORITY, "%s: mysql_stmt_execute error: *%s*", sdata->ttmpfile, mysql_error(&(sdata->mysql))); + sdata->errno = mysql_stmt_errno(stmt); + syslog(LOG_PRIORITY, "%s: mysql_stmt_execute error: *%s* (errno: %d)", sdata->ttmpfile, mysql_error(&(sdata->mysql)), sdata->errno); goto CLOSE; }