From ba6c4f8903ba94cf04c91a9d7cf4e5082fe10e86 Mon Sep 17 00:00:00 2001 From: murf Date: Tue, 23 Sep 2008 14:22:10 +0000 Subject: In at least one machine, we noted that the timestr was not getting set in the STMT; it was coming out, usually, as binary garbage to an mssql server. These changes fixed the problem. The only thing I can venture forth as a guess, is that the pointer is being stored in the interface, not a copy of the string. Because we ripped the build process into a subroutine, the timestr became a temp. stack variable, and between the time the STMT got built and the time it was executed on the server, the string being pointed to was damaged. At any rate, even if this theory is false, and some mechanism was at fault, this fix worked reliably where it didn't before. Why this bug didn't bite last week, I have no idea. This change basically defines the timestr buffer in the calling function, extending the life of the buffer to cover both the STMT's building and processing to the server. git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@143964 f38db490-d61c-443f-a65b-d21fe96a405b --- cdr/cdr_odbc.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'cdr') diff --git a/cdr/cdr_odbc.c b/cdr/cdr_odbc.c index 09a10ecaa..289f3ae5b 100644 --- a/cdr/cdr_odbc.c +++ b/cdr/cdr_odbc.c @@ -90,10 +90,10 @@ static void odbc_disconnect(void) connected = 0; } -static void build_query(struct ast_cdr *cdr) +static void build_query(struct ast_cdr *cdr, char *timestr, int timesize) { int ODBC_res; - char sqlcmd[2048] = "", timestr[128]; + char sqlcmd[2048] = ""; int res = 0; struct tm tm; @@ -102,7 +102,7 @@ static void build_query(struct ast_cdr *cdr) else ast_localtime(&cdr->start.tv_sec, &tm, NULL); - strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm); + strftime(timestr, timesize, DATE_FORMAT, &tm); memset(sqlcmd,0,2048); if (loguniqueid) { snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO %s " @@ -150,7 +150,7 @@ static void build_query(struct ast_cdr *cdr) return; } - SQLBindParameter(ODBC_stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(timestr), 0, ×tr, 0, NULL); + SQLBindParameter(ODBC_stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, timesize, 0, timestr, 0, NULL); SQLBindParameter(ODBC_stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->clid), 0, cdr->clid, 0, NULL); SQLBindParameter(ODBC_stmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->src), 0, cdr->src, 0, NULL); SQLBindParameter(ODBC_stmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->dst), 0, cdr->dst, 0, NULL); @@ -177,15 +177,14 @@ static void build_query(struct ast_cdr *cdr) static int odbc_log(struct ast_cdr *cdr) { int res = 0; + char timestr[150]; ast_mutex_lock(&odbc_lock); - build_query(cdr); + build_query(cdr, timestr, sizeof(timestr)); if (connected) { res = odbc_do_query(); if (res < 0) { - if (option_verbose > 10) - ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Query FAILED Call not logged!\n"); if (option_verbose > 10) ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Reconnecting to dsn %s\n", dsn); odbc_disconnect(); @@ -198,7 +197,7 @@ static int odbc_log(struct ast_cdr *cdr) if (option_verbose > 10) ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Trying Query again!\n"); SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt); - build_query(cdr); /* what a waste. If we have to reconnect, we have to build a new query */ + build_query(cdr, timestr, sizeof(timestr)); /* what a waste. If we have to reconnect, we have to build a new query */ res = odbc_do_query(); if (res < 0) { if (option_verbose > 10) -- cgit v1.2.3