[OpenSIPS-Users] MySQL Type: FIELD_TYPE_NEWDECIMAL (246) uses DB_INT result type but should use float

Calvin Ellison calvin.ellison at voxox.com
Tue Mar 10 17:07:32 EST 2020


The patch appears to be working as intended with regards to storing and
later using the decimal value as a string:

Mar 10 09:50:15 localhost /usr/sbin/opensips[27541]:
DBG:db_mysql:db_mysql_get_columns: RES_NAMES(0x7f8ecd2b5d68)[14]=[delay]
Mar 10 09:50:15 localhost /usr/sbin/opensips[27541]:
DBG:db_mysql:db_mysql_get_columns: use DB_DOUBLE result type
Mar 10 09:50:15 localhost /usr/sbin/opensips[27541]:
DBG:db_mysql:db_mysql_str2val: converting DOUBLE [0.0019]

However, when printed it appears as "0.001900". If that his how thing
string would be passed to mathops, etc., it would cause problems for anyone
interested in significant digits. E.g this could affect the precision of
billing calculations. At this point, I'm just happy the Error and Warning
are gone and the value is useful at all, but if someone wanted to take this
a step further, they could get the precision of the value from the SQL
data. Here's an example MySQL data packet with "Decimals: 4":

MySQL Protocol
    Packet Length: 27
    Packet Number: 16
    Catalog: def
    Database:
    Table:
    Original table:
    Name: delay
    Original name:
    Charset number: binary COLLATE binary (63)
    Length: 26
    Type: FIELD_TYPE_NEWDECIMAL (246)
    Flags: 0x0080
    Decimals: 4

Regards,

*Calvin Ellison*
Senior Voice Operations Engineer
calvin.ellison at voxox.com
+1 (213) 285-0555

-----------------------------------------------
*voxox.com <http://www.voxox.com/> *
5825 Oberlin Drive, Suite 5
San Diego, CA 92121
[image: Voxox]


On Tue, Mar 10, 2020 at 9:49 AM Brett Nemeroff <brett at nemeroff.com> wrote:

> Totally agree that this is the right thing to do. I just wanted the list
> to know it’s a STRING. I don’t think it’s obvious.
>
> Thanks again!!
>
>
> On Tue, Mar 10, 2020 at 11:45 AM Liviu Chircu <liviu at opensips.org> wrote:
>
>> On 10.03.2020 18:39, Brett Nemeroff wrote:
>> > This isn’t really a problem unless you are going to math it or push it
>> > into something else without casting it.
>>
>> I agree, but at script level, there is no support for manipulating
>> "long" integers,
>> let along "double" precision integers.  So casting the "double" number
>> to a string
>> within avpops and returning it to the script seemed like a pretty good
>> workaround.
>>
>> Additionally, this doesn't stop you from doing floating point math in
>> the script using mathops [1]!
>>
>> [1]: https://opensips.org/docs/modules/3.1.x/mathops.html
>>
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20200310/f796b7ac/attachment.html>


More information about the Users mailing list