Module: sip-router
Branch: master
Commit: a74980270b655124c276279e54b8f82965f3f4b8
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=a749802…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Wed Apr 24 10:26:49 2013 +0200
sqlops: use one char buf for empty strings in db results
- safe for the parts of code that want to access it even for write
---
modules/sqlops/sql_api.c | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/modules/sqlops/sql_api.c b/modules/sqlops/sql_api.c
index b5ce758..6528078 100644
--- a/modules/sqlops/sql_api.c
+++ b/modules/sqlops/sql_api.c
@@ -42,7 +42,7 @@
sql_con_t *_sql_con_root = NULL;
sql_result_t *_sql_result_root = NULL;
-static str _sql_empty_str = {"", 0};
+static char _sql_empty_buf[1];
sql_con_t* sql_get_connection(str *name)
{
@@ -67,6 +67,8 @@ int sql_init_con(str *name, str *url)
sql_con_t *sc;
unsigned int conid;
+ *_sql_empty_buf = '\0';
+
conid = core_case_hash(name, 0, 0);
sc = _sql_con_root;
@@ -373,16 +375,18 @@ int sql_do_query(sql_con_t *con, str *query, sql_result_t *res)
LM_ERR("no more memory\n");
goto error;
}
- db_longlong2str(RES_ROWS(db_res)[i].values[j].val.ll_val,
res->vals[i][j].value.s.s, &res->vals[i][j].value.s.len);
+ db_longlong2str(RES_ROWS(db_res)[i].values[j].val.ll_val,
+ res->vals[i][j].value.s.s, &res->vals[i][j].value.s.len);
break;
default:
res->vals[i][j].flags = PV_VAL_NULL;
}
if(res->vals[i][j].flags == PV_VAL_STR && sv.s)
{
- if(sv.len==0)
+ if(sv.len<=0)
{
- res->vals[i][j].value.s = _sql_empty_str;
+ res->vals[i][j].value.s.s = _sql_empty_buf;
+ res->vals[i][j].value.s.len = 0;
continue;
}
res->vals[i][j].value.s.s