Hi, I would like to summarize how $avp's and $var's handle the null value, 0 and empty string. For this I've writen the following test I've checked in Kamailio 1.5.4:
-------------------------- $var(null) = null; $avp(s:null) = null; $var(empty) = ""; $avp(s:empty) = "";
xlog("var(null): '$var(null)'\n"); if $var(null) == null xlog("*** if var(null) == null \n"); if $var(null) xlog("*** if var(null) \n"); if $var(null) != null xlog("*** if var(null) != null \n"); if ! $var(null) xlog("*** if ! var(null) \n"); if $var(null) == '' xlog("*** if var(null) == '' \n"); if $var(null) == 0 xlog("*** if var(null) == 0 \n");
xlog("\n"); xlog("avp(s:null): '$avp(s:null)'\n"); if $avp(s:null) == null xlog("*** if avp(s:null) == null \n"); if $avp(s:null) xlog("*** if avp(s:null) \n"); if $avp(s:null) != null xlog("*** if avp(s:null) != null \n"); if ! $avp(s:null) xlog("*** if ! avp(s:null) \n"); if $avp(s:null) == '' xlog("*** if avp(s:null) == '' \n"); if $avp(s:null) == 0 xlog("*** if avp(s:null) == 0 \n");
xlog("\n"); xlog("var(empty): '$var(empty)'\n"); if $var(empty) == null xlog("*** if var(empty) == null \n"); if $var(empty) xlog("*** if var(empty) \n"); if $var(empty) != null xlog("*** if var(empty) != null \n"); if ! $var(empty) xlog("*** if ! var(empty) \n"); if $var(empty) == '' xlog("*** if var(empty) == '' \n"); if $var(empty)== 0 xlog("*** if var(empty) == 0 \n");
xlog("\n"); xlog("avp(s:empty): '$avp(s:empty)' \n"); if $avp(s:empty) == null xlog("*** if avp(s:empty) == null \n"); if $avp(s:empty) xlog("*** if avp(s:empty) \n"); if $avp(s:empty) != null xlog("*** if avp(s:empty) != null \n"); if ! $avp(s:empty) xlog("*** if ! avp(s:empty) \n"); if $avp(s:empty) == '' xlog("*** if avp(s:empty) == '' \n"); if $avp(s:empty) == 0 xlog("*** if avp(s:empty) == 0 \n"); -------------------------
The result is:
------------------------- var(null): '0' *** if var(null) != null *** if ! var(null) *** if var(null) == 0
avp(s:null): '<null>' *** if avp(s:null) == null *** if ! avp(s:null)
var(empty): '' *** if var(empty) != null *** if ! var(empty) *** if var(empty) == '' CRITICAL:core:comp_scriptvar: invalid operation 20/3/4!! WARNING:core:do_action: error in expression (l=356)
avp(s:empty): '' *** if avp(s:empty) != null *** if ! avp(s:empty) *** if avp(s:empty) == '' CRITICAL:core:comp_scriptvar: invalid operation 20/3/4!! WARNING:core:do_action: error in expression (l=372) -------------------------
Conclusions:
- $var cannot store null value. If so it converts it to 0.
- When cheking "if $avp(...) {" the result is false in case the content of the $avp is null, 0 or an empty string.
- When cheking "if $var(...) {" the result is false in case the content of the $var is 0 or an empty string.
Any thoughts on this? Regards.
2010/9/15 Iñaki Baz Castillo ibc@aliax.net:
Conclusions:
- $var cannot store null value. If so it converts it to 0.
However this is not the case with sqlops module:
I retrieve the value of an integer column in a MySQL table. In this case the value is NULL. I store the result in a $var:
$var(client_max_calls) = $dbr(client=>[0,0]);
But the stored value is "" (empty string) rather than 0. Isn't a bit confussing?
Hi, I would like to summarize how $avp's and $var's handle the null value, 0 and empty string. For this I've writen the following test I've checked in Kamailio 1.5.4:
-------------------------- $var(null) = null; $avp(s:null) = null; $var(empty) = ""; $avp(s:empty) = "";
xlog("var(null): '$var(null)'\n"); if $var(null) == null xlog("*** if var(null) == null \n"); if $var(null) xlog("*** if var(null) \n"); if $var(null) != null xlog("*** if var(null) != null \n"); if ! $var(null) xlog("*** if ! var(null) \n"); if $var(null) == '' xlog("*** if var(null) == '' \n"); if $var(null) == 0 xlog("*** if var(null) == 0 \n");
xlog("\n"); xlog("avp(s:null): '$avp(s:null)'\n"); if $avp(s:null) == null xlog("*** if avp(s:null) == null \n"); if $avp(s:null) xlog("*** if avp(s:null) \n"); if $avp(s:null) != null xlog("*** if avp(s:null) != null \n"); if ! $avp(s:null) xlog("*** if ! avp(s:null) \n"); if $avp(s:null) == '' xlog("*** if avp(s:null) == '' \n"); if $avp(s:null) == 0 xlog("*** if avp(s:null) == 0 \n");
xlog("\n"); xlog("var(empty): '$var(empty)'\n"); if $var(empty) == null xlog("*** if var(empty) == null \n"); if $var(empty) xlog("*** if var(empty) \n"); if $var(empty) != null xlog("*** if var(empty) != null \n"); if ! $var(empty) xlog("*** if ! var(empty) \n"); if $var(empty) == '' xlog("*** if var(empty) == '' \n"); if $var(empty)== 0 xlog("*** if var(empty) == 0 \n");
xlog("\n"); xlog("avp(s:empty): '$avp(s:empty)' \n"); if $avp(s:empty) == null xlog("*** if avp(s:empty) == null \n"); if $avp(s:empty) xlog("*** if avp(s:empty) \n"); if $avp(s:empty) != null xlog("*** if avp(s:empty) != null \n"); if ! $avp(s:empty) xlog("*** if ! avp(s:empty) \n"); if $avp(s:empty) == '' xlog("*** if avp(s:empty) == '' \n"); if $avp(s:empty) == 0 xlog("*** if avp(s:empty) == 0 \n"); -------------------------
The result is:
------------------------- var(null): '0' *** if var(null) != null *** if ! var(null) *** if var(null) == 0
avp(s:null): '<null>' *** if avp(s:null) == null *** if ! avp(s:null)
var(empty): '' *** if var(empty) != null *** if ! var(empty) *** if var(empty) == '' CRITICAL:core:comp_scriptvar: invalid operation 20/3/4!! WARNING:core:do_action: error in expression (l=356)
avp(s:empty): '' *** if avp(s:empty) != null *** if ! avp(s:empty) *** if avp(s:empty) == '' CRITICAL:core:comp_scriptvar: invalid operation 20/3/4!! WARNING:core:do_action: error in expression (l=372) -------------------------
Conclusions:
- $var cannot store null value. If so it converts it to 0.
- When cheking "if $avp(...) {" the result is false in case the content of the $avp is null, 0 or an empty string.
- When cheking "if $var(...) {" the result is false in case the content of the $var is 0 or an empty string.
Any thoughts on this? Regards.
-- Iñaki Baz Castillo ibc@aliax.net
2010/9/15 Iñaki Baz Castillo ibc@aliax.net:
Conclusions:
- $var cannot store null value. If so it converts it to 0.
However this is not the case with sqlops module:
I retrieve the value of an integer column in a MySQL table. In this case the value is NULL. I store the result in a $var:
$var(client_max_calls) = $dbr(client=>[0,0]);
But the stored value is "" (empty string) rather than 0. Isn't a bit confussing?
Iñaki Baz Castillo writes:
I retrieve the value of an integer column in a MySQL table. In this case the value is NULL. I store the result in a $var:
$var(client_max_calls) = $dbr(client=>[0,0]);
But the stored value is "" (empty string) rather than 0. Isn't a bit confussing?
inaki,
yes, it is.
have you tried what happens if you explicitly convert the rhs value to (int)?
-- juha
2010/9/15 Juha Heinanen jh@tutpro.com:
Iñaki Baz Castillo writes:
I retrieve the value of an integer column in a MySQL table. In this case the value is NULL. I store the result in a $var:
$var(client_max_calls) = $dbr(client=>[0,0]);
But the stored value is "" (empty string) rather than 0. Isn't a bit confussing?
inaki,
yes, it is.
have you tried what happens if you explicitly convert the rhs value to (int)?
No. I expect it becomes 0. But anyhow it seems for me like a workaround on top of an unexpected behavior :)
Hello,
On 9/15/10 5:44 PM, Iñaki Baz Castillo wrote:
2010/9/15 Juha Heinanenjh@tutpro.com:
Iñaki Baz Castillo writes:
I retrieve the value of an integer column in a MySQL table. In this case the value is NULL. I store the result in a $var:
$var(client_max_calls) = $dbr(client=>[0,0]);
But the stored value is "" (empty string) rather than 0. Isn't a bit confussing?
inaki,
yes, it is.
have you tried what happens if you explicitly convert the rhs value to (int)?
the config does not have the concept of pointers, so $null is pretty much particular to each PV class: - it is like 'not defined' for those PV that can be completely removed from the config space. For example, AVPs are are a list of (name, value) pairs. When you remove one pair, it is gone from config. You can say they are dynamic named variables. - it is like 'default value' for those PVs that cannot be completely removed from config space. For exampe, $var(x) is resolved to a memory address structure at startup (for fast access) and cannot be removed (otherwise the C pointer will be lost). So assigning $null resets it to default, which is integer 0. You can say they are static named variables
Cheers, Daniel