added errno support for prepared statement execution

This commit is contained in:
SJ 2014-07-10 09:55:07 +02:00
parent d73a38830d
commit 5abff0fe48
3 changed files with 10 additions and 2 deletions

View File

@ -213,6 +213,7 @@ struct session_data {
int journal_envelope_length, journal_bottom_length; int journal_envelope_length, journal_bottom_length;
#ifdef NEED_MYSQL #ifdef NEED_MYSQL
MYSQL mysql; MYSQL mysql;
unsigned int errno;
#endif #endif
#ifdef NEED_PSQL #ifdef NEED_PSQL
PGconn *psql; PGconn *psql;

View File

@ -510,6 +510,10 @@ void init_session_data(struct session_data *sdata, struct __config *cfg){
time(&(sdata->now)); time(&(sdata->now));
sdata->sent = sdata->delivered = sdata->retained = sdata->now; sdata->sent = sdata->delivered = sdata->retained = sdata->now;
#ifdef NEED_MYSQL
sdata->errno = 0;
#endif
#ifdef HAVE_TWEAK_SENT_TIME #ifdef HAVE_TWEAK_SENT_TIME
sdata->sent += cfg->tweak_sent_time_offset; sdata->sent += cfg->tweak_sent_time_offset;
#endif #endif

View File

@ -57,6 +57,7 @@ int p_exec_query(struct session_data *sdata, MYSQL_STMT *stmt, struct __data *da
unsigned long length[MAX_SQL_VARS]; unsigned long length[MAX_SQL_VARS];
int i, ret=ERR; int i, ret=ERR;
sdata->errno = 0;
memset(bind, 0, sizeof(bind)); memset(bind, 0, sizeof(bind));
for(i=0; i<MAX_SQL_VARS; i++){ for(i=0; i<MAX_SQL_VARS; i++){
@ -105,12 +106,14 @@ int p_exec_query(struct session_data *sdata, MYSQL_STMT *stmt, struct __data *da
} }
if(mysql_stmt_bind_param(stmt, bind)){ if(mysql_stmt_bind_param(stmt, bind)){
syslog(LOG_PRIORITY, "%s: mysql_stmt_bind_param() error: %s", sdata->ttmpfile, 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; goto CLOSE;
} }
if(mysql_stmt_execute(stmt)){ 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; goto CLOSE;
} }