Fix execute_string() function and fix memory leak in _callback() function.

This commit is contained in:
Eliot Gable 2012-10-10 18:50:58 +00:00
parent b1c90dff53
commit 192c0143fd
1 changed files with 15 additions and 10 deletions

View File

@ -496,9 +496,19 @@ SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_exec_string(switch_pgs
goto error;
}
if (!result || result->status != PGRES_COMMAND_OK) {
sstatus = SWITCH_PGSQL_FAIL;
goto done;
if (!result) {
switch (result->status) {
#if POSTGRESQL_MAJOR_VERSION >= 9 && POSTGRESQL_MINOR_VERSION >= 2
case PGRES_SINGLE_TUPLE:
/* Added in PostgreSQL 9.2 */
#endif
case PGRES_COMMAND_OK:
case PGRES_TUPLES_OK:
break;
default:
sstatus = SWITCH_PGSQL_FAIL;
goto done;
}
}
if (handle->affected_rows <= 0) {
@ -658,7 +668,8 @@ SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_callback_exec_detailed
/*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Executing callback for row %d...\n", row);*/
if (callback(pdata, result->cols, vals, names)) {
goto done;
switch_pgsql_finish_results(handle); /* Makes sure next call to switch_pgsql_next_result will return NULL */
row = result->rows; /* Makes us exit the for loop */
}
for (col = 0; col < result->cols; ++col) {
@ -686,12 +697,6 @@ SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_callback_exec_detailed
goto error;
}
done:
if (result) {
switch_pgsql_free_result(&result);
}
switch_pgsql_finish_results(handle);
return SWITCH_PGSQL_SUCCESS;
error:
#endif