[PATCH] add 'LIMIT' to dlr_pgsql

Alexander Malysh <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
Hi,

attached patch adds again 'LIMIT 1' to dlr_pgsql because after Stipe's fix
for #190 we will delete and update to much row in postgresql.

Comments/votes please!

P.S. IMO: this should go into 1.4.1

-- 
Thanks,
Alex
dlr_pgsql-add-limit.patch (text/x-diff, 2.2 KB)
Index: gw/dlr_pgsql.c
===================================================================
RCS file: /home/cvs/gateway/gw/dlr_pgsql.c,v
retrieving revision 1.4
diff -a -u -p -r1.4 dlr_pgsql.c
--- gw/dlr_pgsql.c	11 Feb 2005 15:35:48 -0000	1.4
+++ gw/dlr_pgsql.c	16 Feb 2005 18:45:06 -0000
@@ -163,7 +163,7 @@ static struct dlr_entry* dlr_pgsql_get(c
     Octstr *sql;
     List *result, *row;
 
-    sql = octstr_format("SELECT %s, %s, %s, %s, %s, %s FROM %s WHERE %s='%s' AND %s='%s';",
+    sql = octstr_format("SELECT %s, %s, %s, %s, %s, %s FROM %s WHERE %s='%s' AND %s='%s' LIMIT 1;",
                         octstr_get_cstr(fields->field_mask), octstr_get_cstr(fields->field_serv),
                         octstr_get_cstr(fields->field_url), octstr_get_cstr(fields->field_src),
                         octstr_get_cstr(fields->field_dst), octstr_get_cstr(fields->field_boxc),
@@ -215,8 +215,9 @@ static void dlr_pgsql_remove(const Octst
     Octstr *sql;
 
     debug("dlr.pgsql", 0, "removing DLR from database");
-    sql = octstr_format("DELETE FROM %s WHERE %s='%s' AND %s='%s';",
-                        octstr_get_cstr(fields->table), octstr_get_cstr(fields->field_smsc),
+    sql = octstr_format("DELETE FROM %s WHERE oid = (SELECT oid FROM %s WHERE %s='%s' AND %s='%s' LIMIT 1);",
+                        octstr_get_cstr(fields->table), octstr_get_cstr(fields->table),
+                        octstr_get_cstr(fields->field_smsc),
                         octstr_get_cstr(smsc), octstr_get_cstr(fields->field_ts), octstr_get_cstr(ts));
 
 
@@ -229,9 +230,10 @@ static void dlr_pgsql_update(const Octst
     Octstr *sql;
 
     debug("dlr.pgsql", 0, "updating DLR status in database");
-    sql = octstr_format("UPDATE %s SET %s=%d WHERE %s='%s' AND %s='%s';",
+    sql = octstr_format("UPDATE %s SET %s=%d WHERE oid = (SELECT oid FROM %s WHERE %s='%s' AND %s='%s' LIMIT 1);",
                         octstr_get_cstr(fields->table),
                         octstr_get_cstr(fields->field_status), status,
+                        octstr_get_cstr(fields->table),
                         octstr_get_cstr(fields->field_smsc), octstr_get_cstr(smsc),
                         octstr_get_cstr(fields->field_ts), octstr_get_cstr(ts));
     pgsql_update(sql);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.