<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<tt>Hi Ahmed,<br>
<br>
Note the $rc holds the return code of the LAST executed
statement/instruction/function in the script. In the first case
you do it right by saving the ret code of the avp_db_query into a
separate variable, so you can use it even later.<br>
<br>
In the sync script, the $rc, when entering the resume route, it
will hold the return code of the avp_db_query() function. But the
$rc will be changed when doing the xlog(), the if(), etc...So when
you do the last xlog(), the $rc will have nothing to do with the </tt><tt>avp_db_query().
If you need it later in the script, better save it, as you do in
the first example.<br>
<br>
Regards,<br>
</tt>
<pre class="moz-signature" cols="72">Bogdan-Andrei Iancu
OpenSIPS Founder and Developer
<a class="moz-txt-link-freetext" href="http://www.opensips-solutions.com">http://www.opensips-solutions.com</a></pre>
<div class="moz-cite-prefix">On 01/20/2017 01:31 AM, Ahmed Munir
wrote:<br>
</div>
<blockquote
cite="mid:CAGMN=Jeyp+kFrDvjDMPwVhw3wP=KQOU8_fD1Y40DR_PAp00KvQ@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>
<div>
<div>
<div>
<div>Hi,<br>
<br>
</div>
Currently I'm trying to use async fucntion for
avp_db_query. The issue I'm facing while using it as not
retrieving or returning correct return code and not
execute later part of the routing script. See old &
new DB queries;<br>
<br>
</div>
Without Async:<br>
----------------------<br>
route[1]{<br>
...<br>
<br>
if($var(Outpluseflag) == 0) {<br>
avp_db_query("SELECT Outpulse_number,setid
FROM Prefix_data where Program_prefix =
'$var(pg_prefix)'", "$avp(outpluse), $avp(trunkid)");<br>
$var(res) = $retcode; # or you can just
use $retcode!<br>
xlog("--------- OB Route 1-1 DB fetched
value outpluse -> $avp(outpluse) | trunkid ->
$avp(trunkid) | Return Code: $rc | Var Res:
$var(res)-------");<br>
if ($var(res) > 0) {<br>
cache_store("local", "DID_$tU",
"$avp(outpluse)", 60);<br>
cache_store("local",
"Trunk_$tU", "$avp(trunkid)", 60);<br>
}<br>
#xlog("DB fetched value outpluse ->
$avp(outpluse) | trunkid -> $avp(trunkid) | Return Code
-> $var(res)");<br>
xlog("--------- OB Route 1-2 DB fetched
value outpluse -> $avp(outpluse) | trunkid ->
$avp(trunkid) | Return Code: $rc | Var Res:
$var(res)-------");<br>
}<br>
</div>
}<br>
<br>
With Async:<br>
-------------------<br>
</div>
route[1]{<br>
<br>
</div>
<div>...<br>
<br>
<div>
<div>
<div>
<div>if($var(Outpluseflag) == 0) {<br>
async(avp_db_query("SELECT Outpulse_number,setid
FROM Prefix_data where Program_prefix =
'$var(pg_prefix)'", "$avp(outpluse),
$avp(trunkid)"),ob_route_1);<br>
}<br>
}<br>
<br>
</div>
<div>route[ob_route_1]{<br>
xlog("--------- OB Route 1-1 DB fetched value
outpluse -> $avp(outpluse) | trunkid ->
$avp(trunkid) | Return Code: $rc-------");<br>
<br>
if ($rc > 0) {<br>
cache_store("local", "DID_$tU",
"$avp(outpluse)", 60);<br>
cache_store("local", "Trunk_$tU",
"$avp(trunkid)", 60);<br>
}<br>
xlog("--------- OB Route 1-2 DB fetched value
outpluse -> $avp(outpluse) | trunkid ->
$avp(trunkid) | Return Code: $rc-------");<br>
<br>
}<br clear="all">
</div>
<div>
<div><br>
<br>
</div>
<div>The records in xlog I'm getting without using
async;<br>
<br>
Jan 19 18:05:39 qorblpsisprxyd1
/usr/sbin/opensips[14040]: --------- OB Route 1-1 DB
fetched value outpluse -> 6099020000 | trunkid
-> 117 | Return Code: 1 | Var Res: 1-------<br>
Jan 19 18:05:39 qorblpsisprxyd1
/usr/sbin/opensips[14040]: --------- OB Route 1-2 DB
fetched value outpluse -> 6099020000 | trunkid
-> 117 | Return Code: 1 | Var Res: 1-------<br>
<br>
<div>Whereas, records in xlog I'm getting using
async;<br>
<br>
Jan 19 18:10:07 qorblpsisprxyd1
/usr/sbin/opensips[14109]: --------- OB Route 1-1
DB fetched value outpluse -> 6099020000 |
trunkid -> 117 | Return Code: 1-------<br>
Jan 19 18:10:07 qorblpsisprxyd1
/usr/sbin/opensips[14109]: --------- OB Route 1-2
DB fetched value outpluse -> 6099020000 |
trunkid -> 117 | Return Code: 0-------<br>
<br>
</div>
<div>Is there is way to properly retain the
$retcode/$rc in version 2.2.2? Seems like using
async return code(s) are not properly set or the
avp variables are not setting up correct using
async statement.<br>
<br>
</div>
<div>Please advise, if the above async db statement
is correct as shared in sample above.<br>
</div>
<br>
<br>
</div>
<div>-- <br>
<div class="gmail_signature">Regards,<br>
<br>
Ahmed Munir Chohan<br>
<br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a>
<a class="moz-txt-link-freetext" href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a>
</pre>
</blockquote>
<br>
</body>
</html>