Module: sip-router
Branch: master
Commit: da4e2976f0fc9f2217758c886a518e3406efafc3
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=da4e297…
Author: pd <peter.dunkley(a)crocodile-rcs.com>
Committer: pd <peter.dunkley(a)crocodile-rcs.com>
Date: Fri Oct 21 15:45:56 2011 +0100
lib/srdb1: Fixed problem with the new bitwise and DB operation
- In MySQL you can do "select * from table where value&mask;" but that
is not actually correct SQL and fails on other DBs (specifically
PostgreSQL). The correct SQL is
"select * from table where value&mask=mask;"
---
lib/srdb1/db_ut.c | 36 +++++++++++++++++++++++++-----------
1 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/lib/srdb1/db_ut.c b/lib/srdb1/db_ut.c
index c34930f..26637f4 100644
--- a/lib/srdb1/db_ut.c
+++ b/lib/srdb1/db_ut.c
@@ -334,21 +334,35 @@ int db_print_where(const db1_con_t* _c, char* _b, const int _l,
const db_key_t*
}
for(i = 0; i < _n; i++) {
- if (_o) {
- ret = snprintf(_b + len, _l - len, "%.*s%s", _k[i]->len, _k[i]->s,
_o[i]);
+ if (_o && strncmp(_o[i], OP_BITWISE_AND, 1) == 0) {
+ char tmp_buf[16];
+ int tmp_len = 15;
+ memset(tmp_buf, '0', 16);
+ if ((*val2str)(_c, &(_v[i]), tmp_buf, &tmp_len) < 0) {
+ LM_ERR("Error while converting value to string\n");
+ return -1;
+ }
+ ret = snprintf(_b + len, _l - len, "%.*s&%.*s=%.*s", _k[i]->len,
_k[i]->s, tmp_len, tmp_buf, tmp_len, tmp_buf);
if (ret < 0 || ret >= (_l - len)) goto error;
len += ret;
} else {
- ret = snprintf(_b + len, _l - len, "%.*s=", _k[i]->len, _k[i]->s);
- if (ret < 0 || ret >= (_l - len)) goto error;
- len += ret;
- }
- l = _l - len;
- if ( (*val2str)(_c, &(_v[i]), _b + len, &l) < 0) {
- LM_ERR("Error while converting value to string\n");
- return -1;
+ if (_o) {
+ ret = snprintf(_b + len, _l - len, "%.*s%s", _k[i]->len, _k[i]->s,
_o[i]);
+ if (ret < 0 || ret >= (_l - len)) goto error;
+ len += ret;
+ } else {
+ ret = snprintf(_b + len, _l - len, "%.*s=", _k[i]->len, _k[i]->s);
+ if (ret < 0 || ret >= (_l - len)) goto error;
+ len += ret;
+ }
+ l = _l - len;
+ if ( (*val2str)(_c, &(_v[i]), _b + len, &l) < 0) {
+ LM_ERR("Error while converting value to string\n");
+ return -1;
+ }
+ len += l;
}
- len += l;
+
if (i != (_n - 1)) {
ret = snprintf(_b + len, _l - len, " AND ");
if (ret < 0 || ret >= (_l - len)) goto error;