[SR-Users] Negative value returned when using sql_pvquery

Daniel Tryba d.tryba at pocos.nl
Tue Jan 5 17:51:46 CET 2016

On Tue, Jan 05, 2016 at 03:38:58PM +0000, Jonathan Hunter wrote:
> sql_pvquery("cd","select DestinationMsisdn,SourceMsisdn from MsisdnPoolAllocations where PoolMsisdn='$rU'","$var(MOdest),$var(NewSourceMSISDN)");
> However this returns a value of -509264926 for $var(MOdest) which should just be the 3785702370  number.
> What can cause kamailio to interpret this as a negative value? Has anyone seen this before?

What you are seeing is an integer overflow, in this case you are trying
to store a number greater than 2^31 in a signed 32bit int. -509264926
(3785702370-2^32) is the correct answer if the var is a signed 32bit

I treat phonenumbers as strings (both in the database and kamailio)
since I store them as E.164 with a leading + (which results in a bit
more diskspace)

If you don't need the number as int in kamailio, try casting it to a
string in the query.

More information about the sr-users mailing list