From f66fbe2eafccfc50b0f991d92e154731e25029a1 Mon Sep 17 00:00:00 2001 From: Eliot Gable Date: Tue, 9 Oct 2012 20:34:53 +0000 Subject: [PATCH] Fix callback method to pass column count instead of the integer representation of the row we are on. --- src/switch_pgsql.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/switch_pgsql.c b/src/switch_pgsql.c index 6c4e2e069d..3b8c238e7e 100644 --- a/src/switch_pgsql.c +++ b/src/switch_pgsql.c @@ -623,6 +623,7 @@ SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_callback_exec_detailed } while (result != NULL) { + /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Processing result with %d rows and %d columns.\n", result->rows, result->cols);*/ for (row = 0; row < result->rows; ++row) { char **names; char **vals; @@ -648,13 +649,16 @@ SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_callback_exec_detailed vals[col][len] = '\0'; tmp = PQgetvalue(result->result, row, col); strncpy(vals[col], tmp, len); + /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Processing result row %d, col %d: %s => %s\n", row, col, names[col], vals[col]);*/ } else { + /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Processing result row %d, col %d.\n", row, col);*/ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "ERR: Column number %d out of range\n", col); } } - if (callback(pdata, row, vals, names)) { - break; + /*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; } for (col = 0; col < result->cols; ++col) { @@ -682,6 +686,12 @@ 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