[PATCH] "limit" support for postgres/sdb for dlr's
Guillaume Cottenceau <[email protected]>
| Newsgroups | gmane.comp.mobile.kannel.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi, In current sdb driver for dlr's, when using postgres the queries are totally ignoring the "limit" argument (that will be still necessary until we don't have a way to disambiguate between messages, such as was suggested by Nicholas Rahn some time ago for example). The following short patch allows sdb queries aimed at postgres to correctly limit the results. -- Guillaume Cottenceau
limit-postgres-sdb-dlr.patch
(text/x-patch, 2.6 KB)
Index: gw/dlr_sdb.c
===================================================================
RCS file: /home/cvs/gateway/gw/dlr_sdb.c,v
retrieving revision 1.7
diff -u -r1.7 dlr_sdb.c
--- gw/dlr_sdb.c 22 Jan 2004 14:08:24 -0000 1.7
+++ gw/dlr_sdb.c 7 May 2004 15:02:25 -0000
@@ -85,6 +85,7 @@
enum {
SDB_ORACLE,
SDB_MYSQL,
+ SDB_POSTGRES,
SDB_OTHER
};
@@ -98,6 +99,8 @@
return "AND ROWNUM < 2";
case SDB_MYSQL:
return "LIMIT 1";
+ case SDB_POSTGRES:
+ return "LIMIT 1";
case SDB_OTHER:
default:
return "";
@@ -262,10 +265,24 @@
int state;
debug("dlr.sdb", 0, "removing DLR from database");
- sql = octstr_format("DELETE FROM %s WHERE %s='%s' AND %s='%s' %s",
- 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), sdb_get_limit_str());
+ if (sdb_conn_type == SDB_POSTGRES) {
+ /* postgres doesn't support limiting delete/update queries,
+ * thus we need to use a select subquery.
+ * - notice that for uniqueness use of `oid', postgres suggests
+ * to do vacuum regularly, even if it's virtually impossible
+ * to hit duplicates since oid's are given in a row */
+ 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));
+ } else {
+ sql = octstr_format("DELETE FROM %s WHERE %s='%s' AND %s='%s' %s",
+ 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), sdb_get_limit_str());
+ }
#if defined(DLR_TRACE)
debug("dlr.sdb", 0, "SDB: sql: %s", octstr_get_cstr(sql));
@@ -388,6 +405,9 @@
else if (octstr_search(sdb_url, octstr_imm("mysql:"), 0) == 0) {
warning(0, "DLR[sdb]: Please use native MySQL support, instead of libsdb.");
sdb_conn_type = SDB_MYSQL;
+ }
+ else if (octstr_search(sdb_url, octstr_imm("postgres:"), 0) == 0) {
+ sdb_conn_type = SDB_POSTGRES;
}
else
sdb_conn_type = SDB_OTHER;