SIP Router Project
FS#193 - no avpops bigint handling breaks custom select queries
Attached to Project:
sip-router
Opened by Walter Doekes (wdoekes) - Monday, 19 December 2011, 10:09 GMT
Last edited by Daniel-Constantin Mierla (miconda) - Thursday, 29 December 2011, 09:18 GMT
Opened by Walter Doekes (wdoekes) - Monday, 19 December 2011, 10:09 GMT
Last edited by Daniel-Constantin Mierla (miconda) - Thursday, 29 December 2011, 09:18 GMT
|
DetailsHi,
If I do this query: avp_query("SELECT 1, id, IFNULL(id, 3) FROM sometable WHERE id = 1", "$avp(val1),$avp(val2),$avp(val3)"); I expect these values in val1..val3: 1 1 1 However, I get these values: <null> 1 <null> This is because there is not DB1_BIGINT handling in avpops_db.c. Only the 'id' fields gets read correctly, because it is of type integer (32bits). I'm using avpops.so and db_mysql.so on 3.2.x. Attached patch fixes that it works. But it won't fix actual bigint handling for numbers larger than 32bit on systems where sizeof(int) < 8. Regards, Walter Doekes OSSO B.V. |
This task depends upon
See my example:
id => int
IFNULL(id, 1) => string => ugly casts
I haven't touched any big numbers and suddenly I'm required to handle them through a string. I'm not saying this is kamailios fault -- mysql is to blame here (I think) for choosing the largest int possible -- but fixing this through a string cast doesn't make it any more intuitive.
I'm not fond of that solution at all.
For your case casting should do the job, but AFAIK mysql does not support casting from bigint to int, but you can write a small function to do that - take big int as parameter and just return it back as int.
- cast to int
- cast to str
Indeed, when figuring out what was broken, I tried the CAST(.. UNSIGNED / TINYINT) but it all failed. First the cast to CHAR returned something usable.
> Or alternative, modparam for avpops (and eventually sqlops) to control the handling of bigints returned by mysql:
I like that option. It introduces a place to document reasons for one or the other. ("Are you using big numbers? Use the string. Are you just affected by mysql automatic type selection in dynamic column values? Choose int.")
I think that's a bit short sighted. Remember that I don't want any bigints. They're imposed on me by the SQL backend and/or driver, without any warning and without non-trivial workarounds. Having to create a mysql function that casts to a smaller int is not something immediately obvious when results are simply returned as <null> instead of an expected integer.
I think it's a bug until it is transparently handled OR until the user is warned (a) that there is a problem (no bigint handling) and preferably (b) how to solve it.
Regards,
Walter
AVPs are from their beginning dealing with string or int values, someone has to know the underline db system to return such values if they are going to be stored in AVPs -- reason I don't see it as a bug, but enhancement request. Even now, there are so many DB types unsupported internally, as each db system has different types, not all standard.
We cannot go through all possible db data types, for each version of db systems -- they change, new appear, a.s.o.