<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style>
<!--
@font-face
        {font-family:Calibri}
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif"}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif"}
span.EmailStyle17
        {font-family:"Calibri","sans-serif";
        color:windowtext}
.MsoChpDefault
        {font-family:"Calibri","sans-serif"}
@page WordSection1
        {margin:72.0pt 72.0pt 72.0pt 72.0pt}
div.WordSection1
        {}
ol
        {margin-bottom:0cm}
ul
        {margin-bottom:0cm}
-->
</style>
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Hi ,</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">I’m trying to use the db_text and avpops modules to implement a simple custom database but having problems getting it to work .</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">I’m trying to find the Identity of the  recipient for an inbound  call based on the called number . I have a database file:-</p>
<p class="MsoNormal"> </p>
<p class="MsoListParagraph" style="text-indent:-18.0pt"><span style="">1)<span style="font:7.0pt "Times New Roman"">     
</span></span>LineIDs -  contains the called numbers  in the username field and an  attribute for that line ID   (inbound/ outbound)  ,and  the recipient identity  in the value  field</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">I am trying to get the attribute and value pairs  that matches the  line number in the user name column ,</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">id(int,auto) uuid(str,null) username(str) domain(str,null) attribute(str) type(int) value(str)</p>
<p class="MsoNormal">1::+12125551212::inbound:0:Foster</p>
<p class="MsoNormal">2::012125551212::inbound:0:Foster</p>
<p class="MsoNormal">3::12125551212::inbound:0:Foster</p>
<p class="MsoNormal">4::+4412125551212::inbound:0:Foster</p>
<p class="MsoNormal">5::+12125551213::inbound:0:Foster</p>
<p class="MsoNormal">6::012125551213::inbound:0:Foster</p>
<p class="MsoNormal">7::013440001::inbound:0:Foster</p>
<p class="MsoNormal">8::call-centre::inbound:0:MBA</p>
<p class="MsoNormal">9::call-centre::outbound:0:MBA</p>
<p class="MsoNormal">10::01344665544::inbound:0:chicken</p>
<p class="MsoNormal">11::01344665544::outbound:0:chicken</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">I  try to load the AVPs  that match a received  number using  the following line in  the kamailio  script file
</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">           $var(rc)=avp_db_load("01344665544/username","s:recipient/LineIDs");</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">I have also tried </p>
<p class="MsoNormal" style="text-indent:36.0pt"> </p>
<p class="MsoNormal" style="text-indent:36.0pt">$var(rc)=avp_db_load("01344665544/username","$avp(s:tenants)/LineIDs");</p>
<p class="MsoNormal" style="text-indent:36.0pt"> </p>
<p class="MsoNormal">And </p>
<p class="MsoNormal"> </p>
<p class="MsoNormal" style="text-indent:36.0pt">$var(rc)=avp_db_load("01344665544","$avp(i:123)/LineIDs");</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">But it fails to find any matching rows  ( AVPS)  .   Am I using the function correctly ?</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">The debug output is shown below , there are some custom debug  lines I have added in the  db_text   C files .</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">DEBUG: avpops [avpops_impl.c:378]: AVPOPS: calls db_load_avp</p>
<p class="MsoNormal">DEBUG: db_text [dbt_base.c:185]: DBTEXT: dbt_query called</p>
<p class="MsoNormal">DEBUG: db_text [dbt_file.c:102]: request for table [LineIDs]</p>
<p class="MsoNormal">DEBUG: db_text [dbt_file.c:109]: db is [/etc/kamailio/Tenants]</p>
<p class="MsoNormal">DEBUG: db_text [dbt_file.c:124]: loading file [/etc/kamailio/Tenants/LineIDs]</p>
<p class="MsoNormal">DEBUG: db_text [dbt_tb.c:187]: mtime is 1383910898</p>
<p class="MsoNormal">DEBUG: db_text [dbt_file.c:215]: column[0] is INT!</p>
<p class="MsoNormal">DEBUG: db_text [dbt_file.c:210]: column[1] is STR!</p>
<p class="MsoNormal">DEBUG: db_text [dbt_file.c:210]: column[2] is STR!</p>
<p class="MsoNormal">DEBUG: db_text [dbt_file.c:210]: column[3] is STR!</p>
<p class="MsoNormal">DEBUG: db_text [dbt_file.c:210]: column[4] is STR!</p>
<p class="MsoNormal">DEBUG: db_text [dbt_file.c:215]: column[5] is INT!</p>
<p class="MsoNormal">DEBUG: db_text [dbt_file.c:210]: column[6] is STR!</p>
<p class="MsoNormal">DEBUG: db_text [dbt_base.c:240]: new res with 3 cols</p>
<p class="MsoNormal">DEBUG: db_text [dbt_res.c:52]: DBTEXT: dbt_result_new called</p>
<p class="MsoNormal">DEBUG: db_text [dbt_res.c:79]: new res with 3 cols</p>
<p class="MsoNormal">DEBUG: db_text [dbt_res.c:100]: DBTEXT: dbt_result_new returns</p>
<p class="MsoNormal">DEBUG: db_text [dbt_api.c:255]: DBTEXT: dbt_get_result called</p>
<p class="MsoNormal">DEBUG: <core> [db_res.c:118]: allocate 48 bytes for result set at 0x7f334a85c390</p>
<p class="MsoNormal">DEBUG: <core> [db_res.c:155]: allocate 24 bytes for result names at 0x7f334a85c3e0</p>
<p class="MsoNormal">DEBUG: <core> [db_res.c:165]: allocate 12 bytes for result types at 0x7f334a85c1f0</p>
<p class="MsoNormal">DEBUG: db_text [dbt_api.c:80]: allocate 16 bytes for RES_NAMES[0] at 0x7f334a85c1c0</p>
<p class="MsoNormal">DEBUG: db_text [dbt_api.c:80]: allocate 16 bytes for RES_NAMES[1] at 0x7f334a85c420</p>
<p class="MsoNormal">DEBUG: db_text [dbt_api.c:80]: allocate 16 bytes for RES_NAMES[2] at 0x7f334a85c450</p>
<p class="MsoNormal">DEBUG: db_text [dbt_api.c:281]: DBTEXT: dbt_get_result returns 0</p>
<p class="MsoNormal">DEBUG: avpops [avpops_impl.c:389]: AVPOPS: db_load_avp returns 0</p>
<p class="MsoNormal">DEBUG: avpops [avpops_db.c:271]: close avp query</p>
<p class="MsoNormal">DEBUG: <core> [db_res.c:81]: freeing 3 columns</p>
<p class="MsoNormal">DEBUG: <core> [db_res.c:85]: freeing RES_NAMES[0] at 0x7f334a85c1c0</p>
<p class="MsoNormal">DEBUG: <core> [db_res.c:85]: freeing RES_NAMES[1] at 0x7f334a85c420</p>
<p class="MsoNormal">DEBUG: <core> [db_res.c:85]: freeing RES_NAMES[2] at 0x7f334a85c450</p>
<p class="MsoNormal">DEBUG: <core> [db_res.c:94]: freeing result names at 0x7f334a85c3e0</p>
<p class="MsoNormal">DEBUG: <core> [db_res.c:99]: freeing result types at 0x7f334a85c1f0</p>
<p class="MsoNormal">DEBUG: <core> [db_res.c:136]: freeing result set at 0x7f334a85c390</p>
<p class="MsoNormal">DEBUG: avpops [avpops_impl.c:420]: loaded avps = 0</p>
<p class="MsoNormal">INFO: avp_db_load return result is -1</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">I was expecting it to return  at least one AVP .</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Any suggestions gratefully received .</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Hugh James</p>
<p class="MsoNormal"> </p>
</div>
<h1 style="font-family:Calibri,sans-serif; font-size:20px; font-weight:bold; color:#4D4D4D">
Hugh James <span style="color:#808080">| Telephony Developer</span></h1>
<table cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td><img src="http://www.semafone.com/resources/signature/icons.jpg" alt="icons"></td>
<td>
<ul style="font-family:Calibri,sans-serif; color:#4D4D4D; list-style:none; margin:0; padding:0; font-size:15px; line-height:28px">
<li>0845 543 0822 </li><li></li><li>Hugh.James@semafone.com </li><li><a href="http://www.semafone.com" style="color:#4D4D4D">www.semafone.com</a> </li><li><a href="http://twitter.com/semafone" style="color:#4D4D4D">@semafone</a> </li><li>SEMAFONE, 3 The Billings, Walnut Tree Close, Guildford, Surrey GU1 4UL </li></ul>
</td>
</tr>
</tbody>
</table>
<img src="http://www.semafone.com/resources/signature/logo.jpg" alt="logo">
<p style="font-size:11px; font-family:Calibri,sans-serif; color:#4D4D4D">This e-mail is intended only for the addressee named above. As this e-mail may contain confidential or privileged information if you are not the named addressee or the person responsible
 for delivering the message to the named addressee, please telephone us immediately. Please note that we cannot guarantee that this message, or any attachment, is virus free or has not been intercepted and amended. The views of the author may not necessarily
 reflect those of the Company.</p>
</body>
</html>