mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 20:20:07 +00:00
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: https://origsvn.digium.com/svn/asterisk/branches/1.4@143674 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -90,7 +90,7 @@ static void odbc_disconnect(void)
|
|||||||
connected = 0;
|
connected = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int odbc_log(struct ast_cdr *cdr)
|
static void build_query(struct ast_cdr *cdr)
|
||||||
{
|
{
|
||||||
int ODBC_res;
|
int ODBC_res;
|
||||||
char sqlcmd[2048] = "", timestr[128];
|
char sqlcmd[2048] = "", timestr[128];
|
||||||
@@ -102,7 +102,6 @@ static int odbc_log(struct ast_cdr *cdr)
|
|||||||
else
|
else
|
||||||
ast_localtime(&cdr->start.tv_sec, &tm, NULL);
|
ast_localtime(&cdr->start.tv_sec, &tm, NULL);
|
||||||
|
|
||||||
ast_mutex_lock(&odbc_lock);
|
|
||||||
strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
|
strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
|
||||||
memset(sqlcmd,0,2048);
|
memset(sqlcmd,0,2048);
|
||||||
if (loguniqueid) {
|
if (loguniqueid) {
|
||||||
@@ -116,13 +115,12 @@ static int odbc_log(struct ast_cdr *cdr)
|
|||||||
"duration,billsec,disposition,amaflags,accountcode) "
|
"duration,billsec,disposition,amaflags,accountcode) "
|
||||||
"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)", table);
|
"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)", table);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!connected) {
|
if (!connected) {
|
||||||
res = odbc_init();
|
res = odbc_init();
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
odbc_disconnect();
|
odbc_disconnect();
|
||||||
ast_mutex_unlock(&odbc_lock);
|
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);
|
SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
|
||||||
odbc_disconnect();
|
odbc_disconnect();
|
||||||
ast_mutex_unlock(&odbc_lock);
|
ast_mutex_unlock(&odbc_lock);
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We really should only have to do this once. But for some
|
/* 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);
|
SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
|
||||||
odbc_disconnect();
|
odbc_disconnect();
|
||||||
ast_mutex_unlock(&odbc_lock);
|
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);
|
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, 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);
|
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) {
|
if (connected) {
|
||||||
res = odbc_do_query();
|
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");
|
ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Query FAILED Call not logged!\n");
|
||||||
if (option_verbose > 10)
|
if (option_verbose > 10)
|
||||||
ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Reconnecting to dsn %s\n", dsn);
|
ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Reconnecting to dsn %s\n", dsn);
|
||||||
SQLDisconnect(ODBC_con);
|
odbc_disconnect();
|
||||||
res = odbc_init();
|
res = odbc_init();
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
if (option_verbose > 10)
|
if (option_verbose > 10)
|
||||||
@@ -191,6 +197,8 @@ static int odbc_log(struct ast_cdr *cdr)
|
|||||||
} else {
|
} else {
|
||||||
if (option_verbose > 10)
|
if (option_verbose > 10)
|
||||||
ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Trying Query again!\n");
|
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();
|
res = odbc_do_query();
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
if (option_verbose > 10)
|
if (option_verbose > 10)
|
||||||
@@ -374,14 +382,11 @@ out:
|
|||||||
static int odbc_do_query(void)
|
static int odbc_do_query(void)
|
||||||
{
|
{
|
||||||
int ODBC_res;
|
int ODBC_res;
|
||||||
|
|
||||||
ODBC_res = SQLExecute(ODBC_stmt);
|
ODBC_res = SQLExecute(ODBC_stmt);
|
||||||
|
|
||||||
if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
|
if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
if (option_verbose > 10)
|
if (option_verbose > 10)
|
||||||
ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error in Query %d\n", ODBC_res);
|
ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error in Query %d\n", ODBC_res);
|
||||||
SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
|
|
||||||
odbc_disconnect();
|
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
if (option_verbose > 10)
|
if (option_verbose > 10)
|
||||||
|
Reference in New Issue
Block a user