From 394ff81ac671d58dcbd89b2491a53b7844632e2a Mon Sep 17 00:00:00 2001 From: SJ Date: Fri, 24 Jul 2015 15:01:22 +0200 Subject: [PATCH] more sql logging --- src/config.h | 2 +- src/counters.c | 4 ++-- src/import.c | 4 ++-- src/mysql.c | 6 ++++-- src/pilerpurge.c | 8 ++++---- src/sql.h | 2 +- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/config.h b/src/config.h index c92a2f55..94757396 100644 --- a/src/config.h +++ b/src/config.h @@ -14,7 +14,7 @@ #define VERSION "1.2.0-master" -#define BUILD 914 +#define BUILD 915 #define HOSTID "mailarchiver" diff --git a/src/counters.c b/src/counters.c index de0e6d68..8941157f 100644 --- a/src/counters.c +++ b/src/counters.c @@ -92,7 +92,7 @@ void update_counters(struct session_data *sdata, struct __data *data, struct __c //if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: update counters: %s", sdata->ttmpfile, buf); - p_query(sdata, buf); + p_query(sdata, buf, cfg); } } @@ -115,7 +115,7 @@ void update_counters(struct session_data *sdata, struct __data *data, struct __c else { #endif snprintf(buf, SMALLBUFSIZE-1, "UPDATE `%s` SET `rcvd`=`rcvd`+%llu, `virus`=`virus`+%llu, `duplicate`=`duplicate`+%llu, `ignore`=`ignore`+%llu, `size`=`size`+%llu, `stored_size`=`stored_size`+%llu", SQL_COUNTER_TABLE, counters->c_rcvd, counters->c_virus, counters->c_duplicate, counters->c_ignore, counters->c_size, counters->c_stored_size); - p_query(sdata, buf); + p_query(sdata, buf, cfg); #ifdef HAVE_MEMCACHED } diff --git a/src/import.c b/src/import.c index 647d695a..8d41bd7b 100644 --- a/src/import.c +++ b/src/import.c @@ -188,12 +188,12 @@ int add_new_folder(struct session_data *sdata, struct __data *data, char *folder } -void update_import_job_stat(struct session_data *sdata, struct __data *data){ +void update_import_job_stat(struct session_data *sdata, struct __data *data, struct __config *cfg){ char buf[SMALLBUFSIZE]; snprintf(buf, sizeof(buf)-1, "update import set status=%d, started=%ld, updated=%ld, finished=%ld, total=%d, imported=%d where id=%d", data->import->status, data->import->started, data->import->updated, data->import->finished, data->import->total_messages, data->import->processed_messages, data->import->import_job_id); - p_query(sdata, buf); + p_query(sdata, buf, cfg); } diff --git a/src/mysql.c b/src/mysql.c index 2f9ccc74..54607572 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -47,7 +47,9 @@ void p_bind_init(struct __data *data){ } -void p_query(struct session_data *sdata, char *s){ +void p_query(struct session_data *sdata, char *s, struct __config *cfg){ + if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: p_query=%s", sdata->ttmpfile, s); + mysql_real_query(&(sdata->mysql), s, strlen(s)); } @@ -210,7 +212,7 @@ int p_get_affected_rows(MYSQL_STMT *stmt){ int prepare_sql_statement(struct session_data *sdata, MYSQL_STMT **stmt, char *s, struct __config *cfg){ - if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: sql=%s", sdata->ttmpfile, s); + if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: prepare statement=%s", sdata->ttmpfile, s); *stmt = mysql_stmt_init(&(sdata->mysql)); if(!*stmt){ diff --git a/src/pilerpurge.c b/src/pilerpurge.c index ff3acff5..958fed5c 100644 --- a/src/pilerpurge.c +++ b/src/pilerpurge.c @@ -94,7 +94,7 @@ int remove_message_frame_files(char *s, char *update_meta_sql, struct session_da if(dryrun == 1){ printf("running sql query: *%s*\n\n", update_meta_sql); } else { - p_query(sdata, update_meta_sql); + p_query(sdata, update_meta_sql, cfg); } @@ -188,7 +188,7 @@ int remove_attachments(char *in, struct session_data *sdata, struct __data *data if(dryrun == 1){ printf("delete sql: *%s*\n", delete_attachment_stmt); } else { - p_query(sdata, delete_attachment_stmt); + p_query(sdata, delete_attachment_stmt, cfg); } } @@ -221,7 +221,7 @@ int remove_attachments(char *in, struct session_data *sdata, struct __data *data if(dryrun == 1){ printf("delete sql: *%s*\n", delete_attachment_stmt); } else { - p_query(sdata, delete_attachment_stmt); + p_query(sdata, delete_attachment_stmt, cfg); } } @@ -402,7 +402,7 @@ int main(int argc, char **argv){ if(purged_size > 100){ snprintf(buf, sizeof(buf)-1, "UPDATE `%s` SET size = size - %ld", SQL_COUNTER_TABLE, purged_size); - if(dryrun == 0) p_query(&sdata, buf); + if(dryrun == 0) p_query(&sdata, buf, &cfg); } diff --git a/src/sql.h b/src/sql.h index 07c214ce..e57671f5 100644 --- a/src/sql.h +++ b/src/sql.h @@ -9,7 +9,7 @@ int open_database(struct session_data *sdata, struct __config *cfg); void close_database(struct session_data *sdata); int prepare_sql_statement(struct session_data *sdata, MYSQL_STMT **stmt, char *s, struct __config *cfg); -void p_query(struct session_data *sdata, char *s); +void p_query(struct session_data *sdata, char *s, struct __config *cfg); int p_exec_query(struct session_data *sdata, MYSQL_STMT *stmt, struct __data *data); int p_store_results(struct session_data *sdata, MYSQL_STMT *stmt, struct __data *data); int p_fetch_results(MYSQL_STMT *stmt);