From 05710c7ea5242d9cac8eff99d237429212cbbfcd Mon Sep 17 00:00:00 2001
From: Walter Doekes <walter+asterisk@wjd.nu>
Date: Mon, 10 Feb 2014 16:34:27 +0000
Subject: [PATCH] res_config_pgsql: Fix ast_update2_realtime calls.

Fix so multiple updates from a single call works (add missing ',').
Remove bogus ast_free's that weren't supposed to be there.
Moved a few spaces for readability.

Review: https://reviewboard.asterisk.org/r/3194/
........

Merged revisions 407873 from http://svn.asterisk.org/svn/asterisk/branches/1.8


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@407874 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 res/res_config_pgsql.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/res/res_config_pgsql.c b/res/res_config_pgsql.c
index 40e46d2d98..0632d9592e 100644
--- a/res/res_config_pgsql.c
+++ b/res/res_config_pgsql.c
@@ -848,8 +848,8 @@ static int update2_pgsql(const char *database, const char *tablename, va_list ap
 		return -1;
 	}
 
-	ast_str_set(&sql, 0, "UPDATE %s SET ", tablename);
-	ast_str_set(&where, 0, "WHERE");
+	ast_str_set(&sql, 0, "UPDATE %s SET", tablename);
+	ast_str_set(&where, 0, " WHERE");
 
 	while ((newparam = va_arg(ap, const char *))) {
 		if (!find_column(table, newparam)) {
@@ -863,7 +863,6 @@ static int update2_pgsql(const char *database, const char *tablename, va_list ap
 		if (pgresult) {
 			ast_log(LOG_ERROR, "PostgreSQL RealTime: detected invalid input: '%s'\n", newval);
 			release_table(table);
-			ast_free(sql);
 			return -1;
 		}
 		ast_str_append(&where, 0, "%s %s='%s'", first ? "" : " AND", newparam, ast_str_buffer(escapebuf));
@@ -896,15 +895,15 @@ static int update2_pgsql(const char *database, const char *tablename, va_list ap
 		if (pgresult) {
 			ast_log(LOG_ERROR, "PostgreSQL RealTime: detected invalid input: '%s'\n", newval);
 			release_table(table);
-			ast_free(sql);
 			return -1;
 		}
 
 		ast_str_append(&sql, 0, "%s %s='%s'", first ? "" : ",", newparam, ast_str_buffer(escapebuf));
+		first = 0;
 	}
 	release_table(table);
 
-	ast_str_append(&sql, 0, " %s", ast_str_buffer(where));
+	ast_str_append(&sql, 0, "%s", ast_str_buffer(where));
 
 	ast_debug(1, "PostgreSQL RealTime: Update SQL: %s\n", ast_str_buffer(sql));
 
-- 
GitLab