diff options
author | murf <murf@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-09-19 21:07:05 +0000 |
---|---|---|
committer | murf <murf@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-09-19 21:07:05 +0000 |
commit | 1e69392dd26aa405404246901965175e7dc1a1d5 (patch) | |
tree | 371da48ef20e117f271940ea2c9c109c06a9e363 /cdr | |
parent | 86b95eb2be6713339b26511972e122536f36d2ab (diff) |
This fix comes from a debugging session on a test box that has been getting hung channels when the mssqlserver bounces. All the connections then become invalid, and must be reconnected. The cdr_odbc backend had code to do it, but depended on re-establishing the connection, but re-using the STMT that had been built. By trial and error, we determined that the STMT could not be re-used after the connection was re-established. and must be rebuilt. These changes accomplish this.
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@143674 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'cdr')
-rw-r--r-- | cdr/cdr_odbc.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/cdr/cdr_odbc.c b/cdr/cdr_odbc.c index 2cd559af8..09a10ecaa 100644 --- a/cdr/cdr_odbc.c +++ b/cdr/cdr_odbc.c @@ -90,7 +90,7 @@ static void odbc_disconnect(void) connected = 0; } -static int odbc_log(struct ast_cdr *cdr) +static void build_query(struct ast_cdr *cdr) { int ODBC_res; char sqlcmd[2048] = "", timestr[128]; @@ -102,7 +102,6 @@ static int odbc_log(struct ast_cdr *cdr) else ast_localtime(&cdr->start.tv_sec, &tm, NULL); - ast_mutex_lock(&odbc_lock); strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm); memset(sqlcmd,0,2048); if (loguniqueid) { @@ -116,13 +115,12 @@ static int odbc_log(struct ast_cdr *cdr) "duration,billsec,disposition,amaflags,accountcode) " "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)", table); } - if (!connected) { res = odbc_init(); if (res < 0) { odbc_disconnect(); ast_mutex_unlock(&odbc_lock); - return 0; + return; } } @@ -134,7 +132,7 @@ static int odbc_log(struct ast_cdr *cdr) SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt); odbc_disconnect(); ast_mutex_unlock(&odbc_lock); - return 0; + return; } /* We really should only have to do this once. But for some @@ -149,7 +147,7 @@ static int odbc_log(struct ast_cdr *cdr) SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt); odbc_disconnect(); ast_mutex_unlock(&odbc_lock); - return 0; + return; } SQLBindParameter(ODBC_stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(timestr), 0, ×tr, 0, NULL); @@ -174,6 +172,14 @@ static int odbc_log(struct ast_cdr *cdr) SQLBindParameter(ODBC_stmt, 15, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->uniqueid), 0, cdr->uniqueid, 0, NULL); SQLBindParameter(ODBC_stmt, 16, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->userfield), 0, cdr->userfield, 0, NULL); } +} + +static int odbc_log(struct ast_cdr *cdr) +{ + int res = 0; + + ast_mutex_lock(&odbc_lock); + build_query(cdr); if (connected) { res = odbc_do_query(); @@ -182,7 +188,7 @@ static int odbc_log(struct ast_cdr *cdr) 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); - SQLDisconnect(ODBC_con); + odbc_disconnect(); res = odbc_init(); if (res < 0) { if (option_verbose > 10) @@ -191,6 +197,8 @@ static int odbc_log(struct ast_cdr *cdr) } else { 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 */ res = odbc_do_query(); if (res < 0) { if (option_verbose > 10) @@ -374,14 +382,11 @@ out: static int odbc_do_query(void) { int ODBC_res; - ODBC_res = SQLExecute(ODBC_stmt); if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) { if (option_verbose > 10) ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error in Query %d\n", ODBC_res); - SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt); - odbc_disconnect(); return -1; } else { if (option_verbose > 10) |