summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rest.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/rest.c b/src/rest.c
index 7ffebbf..3d881a8 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -1812,11 +1812,11 @@ static int og_cmd_post_center_update(json_t *element,
struct og_msg_params *params)
{
const char *key, *msglog;
+ uint32_t center_id;
struct og_dbi *dbi;
dbi_result result;
json_t *value;
int err = 0;
- unsigned int center_id;
json_object_foreach(element, key, value) {
if (!strcmp(key, "name")) {
@@ -1865,8 +1865,9 @@ static int og_cmd_post_center_update(json_t *element,
dbi_result_free(result);
result = dbi_conn_queryf(dbi->conn,
- "SELECT nombrecentro FROM centros WHERE nombrecentro='%s'",
- params->name);
+ "SELECT idcentro FROM centros "
+ "WHERE nombrecentro='%s' and idcentro<>'%u'",
+ params->name, center_id);
if (!result) {
dbi_conn_error(dbi->conn, &msglog);
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
@@ -1874,9 +1875,10 @@ static int og_cmd_post_center_update(json_t *element,
og_dbi_close(dbi);
return -1;
}
- if (dbi_result_get_numrows(result) != 0) {
- syslog(LOG_ERR, "a center with that name already exists: %s\n",
- params->name);
+ if (dbi_result_next_row(result)) {
+ center_id = dbi_result_get_uint(result, "idcentro");
+ syslog(LOG_ERR, "the center with id %u already has the name: %s\n",
+ center_id, params->name);
dbi_result_free(result);
og_dbi_close(dbi);
return -1;