On Wednesday 29 June 2011, Andrade Ricardo (CI/AFU1) wrote:
> Perhaps this fits better into a bug report, but I'd like to know if
> somebody out there experienced a similar issue. I am executing a "select
> count" query using the avp_db_query function, but it is not storing the
> results in any avp. Other queries are working fine. I use db_mysql
> connected with a mysql 5.1 server.
> 
> I have tested this with kamailio-3.1.0 and kamailio-3.1.3, both didn't
> work. In an old box (version 1.3.x), the same query was returning the
> correct value.
> 
> ---------------------------------------------------
> Here is the case which is not working:
> 
> Code:
> avp_delete("$avp(s:count)");
> $var(ret) = avp_db_query("SELECT count(*) FROM subscriber where
> username='foo'", "$avp(s:count)");
> xlog("L_INFO", "var(ret)=$var(ret) avp(s:count)=$avp(s:count)");
> 
> 
> Output:
> INFO: <script>: var(ret)=1 avp(s:count)=<null>
> 
> (notice the return code 1, which means that the query was successfull and
> there should be some output value stored in the avp, but it is <null>)

The return type of the COUNT() function is a BIGINT, which is ignored in 
kamailio. The attached patch converts the lower 32 bits of the result to an 
int usable by kamailio. I'll push this eventually.
-- 
Greetings,

Alex Hermann

commit 700102448a65b2fca95f763025503c910b2065bd
Author: Alex Hermann <a...@speakup.nl>
Date:   Mon Jul 4 17:33:50 2011 +0200

    modules/avpops: avp_db_query: treat BIGINT result as INT, disregarding the most significant 32 bits.

diff --git a/modules/avpops/avpops_db.c b/modules/avpops/avpops_db.c
index b5caabe..f8a18fc 100644
--- a/modules/avpops/avpops_db.c
+++ b/modules/avpops/avpops_db.c
@@ -395,6 +395,10 @@ int db_query_avp(struct sip_msg *msg, char *query, pvname_list_t* dest)
 					avp_val.n
 						= (int)RES_ROWS(db_res)[i].values[j].val.int_val;
 				break;
+				case DB1_BIGINT:
+					avp_val.n
+						= (int)RES_ROWS(db_res)[i].values[j].val.ll_val;
+				break;
 				case DB1_DATETIME:
 					avp_val.n
 						= (int)RES_ROWS(db_res)[i].values[j].val.time_val;
_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users

Reply via email to