提交 d1a9b377 authored 作者: Anthony Minessale's avatar Anthony Minessale

FS-3794 try this please

上级 7788f3e9
......@@ -6266,6 +6266,7 @@ void sofia_glue_actually_execute_sql_trans(sofia_profile_t *profile, char *sql,
void sofia_glue_actually_execute_sql(sofia_profile_t *profile, char *sql, switch_mutex_t *mutex)
{
switch_cache_db_handle_t *dbh = NULL;
char *err = NULL;
if (mutex) {
switch_mutex_lock(mutex);
......@@ -6276,7 +6277,12 @@ void sofia_glue_actually_execute_sql(sofia_profile_t *profile, char *sql, switch
goto end;
}
switch_cache_db_execute_sql(dbh, sql, NULL);
switch_cache_db_execute_sql(dbh, sql, &err);
if (err) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s]\n%s\n", err, sql);
free(err);
}
end:
......@@ -6324,7 +6330,7 @@ switch_bool_t sofia_glue_execute_sql_callback(sofia_profile_t *profile,
char *sofia_glue_execute_sql2str(sofia_profile_t *profile, switch_mutex_t *mutex, char *sql, char *resbuf, size_t len)
{
char *ret = NULL;
char *err = NULL;
switch_cache_db_handle_t *dbh = NULL;
if (!(dbh = sofia_glue_get_db_handle(profile))) {
......@@ -6336,7 +6342,12 @@ char *sofia_glue_execute_sql2str(sofia_profile_t *profile, switch_mutex_t *mutex
switch_mutex_lock(mutex);
}
ret = switch_cache_db_execute_sql2str(dbh, sql, resbuf, len, NULL);
ret = switch_cache_db_execute_sql2str(dbh, sql, resbuf, len, &err);
if (err) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s]\n%s\n", err, sql);
free(err);
}
if (mutex) {
switch_mutex_unlock(mutex);
......
......@@ -480,10 +480,15 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_
error:
if (stmt) {
err_str = switch_odbc_handle_get_error(handle, stmt);
}
if (zstr(err_str)) {
err_str = strdup((char *)"SQL ERROR!");
}
if (err_str) {
if (!switch_stristr("already exists", err_str) && !switch_stristr("duplicate key name", err_str)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str));
......@@ -513,7 +518,7 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec_detailed(c
SQLHSTMT stmt = NULL;
SQLSMALLINT c = 0, x = 0;
SQLLEN m = 0;
char *err_str = NULL;
char *x_err = NULL, *err_str = NULL;
int result;
int err_cnt = 0;
int done = 0;
......@@ -523,22 +528,24 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec_detailed(c
switch_assert(callback != NULL);
if (!db_is_up(handle)) {
x_err = "DB is not up!";
goto error;
}
if (SQLAllocHandle(SQL_HANDLE_STMT, handle->con, &stmt) != SQL_SUCCESS) {
err_str = strdup("Unable to SQL allocate handle.");
x_err = "Unable to SQL allocate handle!";
goto error;
}
if (SQLPrepare(stmt, (unsigned char *) sql, SQL_NTS) != SQL_SUCCESS) {
err_str = strdup("Unable to prepare SQL statement.");
x_err = "Unable to prepare SQL statement!";
goto error;
}
result = SQLExecute(stmt);
if (result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO && result != SQL_NO_DATA) {
x_err = "execute error!";
goto error;
}
......@@ -598,10 +605,8 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec_detailed(c
free(vals);
}
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
stmt = NULL; /* Make sure we don't try to free this handle again */
if (!err_cnt) {
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
return SWITCH_ODBC_SUCCESS;
}
......@@ -609,7 +614,10 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec_detailed(c
if (stmt) {
err_str = switch_odbc_handle_get_error(handle, stmt);
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
}
if (zstr(err_str) && !zstr(x_err)) {
err_str = strdup(x_err);
}
if (err_str) {
......@@ -621,6 +629,11 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec_detailed(c
}
}
if (stmt) {
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
}
#endif
return SWITCH_ODBC_FAIL;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论