databasevoipopensips

Opensips avp_db_query can't compare null value


I am using avp_db_query to retrieve my table row, sometimes one field value is null. But when I use if condition it does not follow and move on.

avp_db_query("select status from orders where id = 1", "$avp(status);")

Now if i write condition

if($avp(status)==1){
   do success
 } else {
   do failure
   exit();
 }

Above condition does not work on failure status and continue, but when I put two if conditions and check if it is equal to one or equal to 0 then it works.

another issue is if this column has null value than nothing work, and it proceeds with giving the following warning.

WARNING:core:comp_scriptvar: invalid EQUAL operation: left is 
VARIABLE_ELEMENT/STRING_VAL, right is NUMBER/NO_VAL

Solution

  • You can test for NULL SQL column values with:

    if ($avp(status) == "<null>")
    

    ... which is equivalent to:

    if ($(avp(status)[0]) == "<null>")
    

    It was the only way we could get this to work, given that the $avp(status) = NULL; statement is meant to delete the top-most value in the AVP's stack.

    If you are claiming that the else statement is not executed when it should be, please give a minimally viable example, along with the output of opensips -V, possibly opening up a new issue, separately.