Re: [SR-Users] sql_xquery return 1 on 0 rows?
Just to brainstorm: We may want to look into implementing something like the old xpath or new shiny jpath (for json) for the xavps. And if someone volunteer to write more xavp example code to explain them I think we would make life easier for a lot of Kamailians. /O > On 9 Nov 2021, at 08:26, Daniel-Constantin Mierla wrote: > > Hello, > > sql_xquery() does not store anything inside $dbr(...), it stores the > result inside $xavp(...). > > You have to use sql_query() to store inside $dbr(). > > Cheers, > Daniel > > On 05.11.21 15:55, Benoît Panizzon wrote: >> 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 >> -- >> I m p r o W a r e A G-Leiter Commerce Kunden >> __ >> >> Zurlindenstrasse 29 Tel +41 61 826 93 00 >> CH-4133 PrattelnFax +41 61 826 93 01 >> Schweiz Web http://www.imp.ch >> __ >> >> __ >> Kamailio - Users Mailing List - Non Commercial Discussions >> * sr-users@lists.kamailio.org >> Important: keep the mailing list in the recipients, do not reply only to the >> sender! >> Edit mailing list options or unsubscribe: >> * https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users > > -- > Daniel-Constantin Mierla -- www.asipto.com > www.twitter.com/miconda -- www.linkedin.com/in/miconda > Kamailio Advanced Training - Online > Nov 08-11, 2021 (Europe Timezone) - Feb 21-24, 2022 (America Timezone) > * https://www.asipto.com/sw/kamailio-advanced-training-online/ > > > __ > Kamailio - Users Mailing List - Non Commercial Discussions > * sr-users@lists.kamailio.org > Important: keep the mailing list in the recipients, do not reply only to the > sender! > Edit mailing list options or unsubscribe: > * https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users __ Kamailio - Users Mailing List - Non Commercial Discussions * sr-users@lists.kamailio.org Important: keep the mailing list in the recipients, do not reply only to the sender! Edit mailing list options or unsubscribe: * https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
Re: [SR-Users] sql_xquery return 1 on 0 rows?
Hello, checking the presence of the xavp with the result is probably the way to do it, the docs do not list different return code for no-result case. Cheers, Daniel On 07.11.21 18:30, Chaigneau, Nicolas wrote: > 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 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 > -- > I m p r o W a r e A G-Leiter Commerce Kunden > __ > > Zurlindenstrasse 29 Tel +41 61 826 93 00 > CH-4133 PrattelnFax +41 61 826 93 01 > Schweiz Web http://www.imp.ch > __ > > __ > Kamailio - Users Mailing List - Non Commercial Discussions > * sr-users@lists.kamailio.org > Important: keep the mailing list in the recipients, do not reply only to the > sender! > Edit mailing list options or unsubscribe: > * https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users > This message contains information that may be privileged or confidential and > is the property of the Capgemini Group. It is intended only for the person to > whom it is addressed. If you are not the intended recipient, you are not > authorized to read, print, retain, copy, disseminate, distribute, or use this > message or any part thereof. If you receive this message in error, please > notify the sender immediately and delete all copies of this message. > __ > Kamailio - Users Mailing List - Non Commercial Discussions > * sr-users@lists.kamailio.org > Important: keep the mailing list in the recipients, do not reply only to the > sender! > Edit mailing list options or unsubscribe: > * https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users -- Daniel-Constantin Mierla -- www.asipto.com www.twitter.com/miconda -- www.linkedin.com/in/miconda Kamailio Advanced Training - Online Nov 08-11, 2021 (Europe Timezone) - Feb 21-24, 2022 (America Timezone) * https://www.asipto.com/sw/kamailio-advanced-training-online/ __ Kamailio - Users Mailing List - Non Commercial Discussions * sr-users@lists.kamailio.org Important: keep the mailing list in the recipients, do not reply only to the sender! Edit mailing list options or unsubscribe: * https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
Re: [SR-Users] sql_xquery return 1 on 0 rows?
Hello, sql_xquery() does not store anything inside $dbr(...), it stores the result inside $xavp(...). You have to use sql_query() to store inside $dbr(). Cheers, Daniel On 05.11.21 15:55, Benoît Panizzon wrote: > 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 > -- > I m p r o W a r e A G-Leiter Commerce Kunden > __ > > Zurlindenstrasse 29 Tel +41 61 826 93 00 > CH-4133 PrattelnFax +41 61 826 93 01 > Schweiz Web http://www.imp.ch > __ > > __ > Kamailio - Users Mailing List - Non Commercial Discussions > * sr-users@lists.kamailio.org > Important: keep the mailing list in the recipients, do not reply only to the > sender! > Edit mailing list options or unsubscribe: > * https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users -- Daniel-Constantin Mierla -- www.asipto.com www.twitter.com/miconda -- www.linkedin.com/in/miconda Kamailio Advanced Training - Online Nov 08-11, 2021 (Europe Timezone) - Feb 21-24, 2022 (America Timezone) * https://www.asipto.com/sw/kamailio-advanced-training-online/ __ Kamailio - Users Mailing List - Non Commercial Discussions * sr-users@lists.kamailio.org Important: keep the mailing list in the recipients, do not reply only to the sender! Edit mailing list options or unsubscribe: * https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
[SR-Users] sql_xquery return 1 on 0 rows?
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 -- I m p r o W a r e A G-Leiter Commerce Kunden __ Zurlindenstrasse 29 Tel +41 61 826 93 00 CH-4133 PrattelnFax +41 61 826 93 01 Schweiz Web http://www.imp.ch __ __ Kamailio - Users Mailing List - Non Commercial Discussions * sr-users@lists.kamailio.org Important: keep the mailing list in the recipients, do not reply only to the sender! Edit mailing list options or unsubscribe: * https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users