Hello,
I'm using sql_xquery also (Kamailio 5.5.2). I too have noticed that (except in case of error), it will always return 1.
So to check if rows are actually returned, I'm looking at the result XAVP.
E.g. :
if ($xavp(query_result[0]) == $null) { # no row (...)
Regards, Nicolas.
-----Message d'origine----- De : sr-users sr-users-bounces@lists.kamailio.org De la part de Benoît Panizzon Envoyé : vendredi 5 novembre 2021 15:55 À : Kamailio (SER) - Users Mailing List Objet : [SR-Users] sql_xquery return 1 on 0 rows?
***This mail has been sent by an external source***
Dear List...
kamcmd> version kamailio 5.4.7 (x86_64/linux)
Strange issue found.
According to: https://kamailio.org/docs/modules/5.4.x/modules/sqlops.html
I should get return value 2 if no rows returned:
$var(query) contains a query that does not match (number is not assigned)
if (sql_xquery("impkam", "$var(query)", "assignedtn") == 1) { if ($avp(debug) > 1) { xlog("L_INFO", "$cfg(route): SQL Dump Result: $var(assignedtn) ROWS: $dbr(assignedtn=>rows) \n"); } do stuff with the assigned number } else { do stuff in case that number is not assigned }
Log Output:
CHECK_ASSIGNED_TN: SQL Dump Result: 0 ROWS: 0
So the return value of the query was == 1 but the result contains no rows. How can that be?
-- Mit freundlichen Grüssen
-Benoît Panizzon- @ HomeOffice und normal erreichbar