Hello,

the name of the avp in the second parameter has to match the value in the 'attribute' column, like:

avp_db_load("01344665544/username", "$avp(inbound)/LineIDs");

If you want to load all the records, you have to specify flags, not avp names, in the second parameter.

Cheers,
Daniel

On 11/12/13 11:44 AM, Hugh James wrote:

Hi ,

 

I’m trying to use the db_text and avpops modules to implement a simple custom database but having problems getting it to work .

 

I’m trying to find the Identity of the  recipient for an inbound  call based on the called number . I have a database file:-

 

1)      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

 

 

I am trying to get the attribute and value pairs  that matches the  line number in the user name column ,

 

 

id(int,auto) uuid(str,null) username(str) domain(str,null) attribute(str) type(int) value(str)

1::+12125551212::inbound:0:Foster

2::012125551212::inbound:0:Foster

3::12125551212::inbound:0:Foster

4::+4412125551212::inbound:0:Foster

5::+12125551213::inbound:0:Foster

6::012125551213::inbound:0:Foster

7::013440001::inbound:0:Foster

8::call-centre::inbound:0:MBA

9::call-centre::outbound:0:MBA

10::01344665544::inbound:0:chicken

11::01344665544::outbound:0:chicken

 

I  try to load the AVPs  that match a received  number using  the following line in  the kamailio  script file

 

           $var(rc)=avp_db_load("01344665544/username","s:recipient/LineIDs");

 

I have also tried

 

$var(rc)=avp_db_load("01344665544/username","$avp(s:tenants)/LineIDs");

 

And

 

$var(rc)=avp_db_load("01344665544","$avp(i:123)/LineIDs");

 

 

But it fails to find any matching rows  ( AVPS)  .   Am I using the function correctly ?

 

The debug output is shown below , there are some custom debug  lines I have added in the  db_text   C files .

 

DEBUG: avpops [avpops_impl.c:378]: AVPOPS: calls db_load_avp

DEBUG: db_text [dbt_base.c:185]: DBTEXT: dbt_query called

DEBUG: db_text [dbt_file.c:102]: request for table [LineIDs]

DEBUG: db_text [dbt_file.c:109]: db is [/etc/kamailio/Tenants]

DEBUG: db_text [dbt_file.c:124]: loading file [/etc/kamailio/Tenants/LineIDs]

DEBUG: db_text [dbt_tb.c:187]: mtime is 1383910898

DEBUG: db_text [dbt_file.c:215]: column[0] is INT!

DEBUG: db_text [dbt_file.c:210]: column[1] is STR!

DEBUG: db_text [dbt_file.c:210]: column[2] is STR!

DEBUG: db_text [dbt_file.c:210]: column[3] is STR!

DEBUG: db_text [dbt_file.c:210]: column[4] is STR!

DEBUG: db_text [dbt_file.c:215]: column[5] is INT!

DEBUG: db_text [dbt_file.c:210]: column[6] is STR!

DEBUG: db_text [dbt_base.c:240]: new res with 3 cols

DEBUG: db_text [dbt_res.c:52]: DBTEXT: dbt_result_new called

DEBUG: db_text [dbt_res.c:79]: new res with 3 cols

DEBUG: db_text [dbt_res.c:100]: DBTEXT: dbt_result_new returns

DEBUG: db_text [dbt_api.c:255]: DBTEXT: dbt_get_result called

DEBUG: <core> [db_res.c:118]: allocate 48 bytes for result set at 0x7f334a85c390

DEBUG: <core> [db_res.c:155]: allocate 24 bytes for result names at 0x7f334a85c3e0

DEBUG: <core> [db_res.c:165]: allocate 12 bytes for result types at 0x7f334a85c1f0

DEBUG: db_text [dbt_api.c:80]: allocate 16 bytes for RES_NAMES[0] at 0x7f334a85c1c0

DEBUG: db_text [dbt_api.c:80]: allocate 16 bytes for RES_NAMES[1] at 0x7f334a85c420

DEBUG: db_text [dbt_api.c:80]: allocate 16 bytes for RES_NAMES[2] at 0x7f334a85c450

DEBUG: db_text [dbt_api.c:281]: DBTEXT: dbt_get_result returns 0

DEBUG: avpops [avpops_impl.c:389]: AVPOPS: db_load_avp returns 0

DEBUG: avpops [avpops_db.c:271]: close avp query

DEBUG: <core> [db_res.c:81]: freeing 3 columns

DEBUG: <core> [db_res.c:85]: freeing RES_NAMES[0] at 0x7f334a85c1c0

DEBUG: <core> [db_res.c:85]: freeing RES_NAMES[1] at 0x7f334a85c420

DEBUG: <core> [db_res.c:85]: freeing RES_NAMES[2] at 0x7f334a85c450

DEBUG: <core> [db_res.c:94]: freeing result names at 0x7f334a85c3e0

DEBUG: <core> [db_res.c:99]: freeing result types at 0x7f334a85c1f0

DEBUG: <core> [db_res.c:136]: freeing result set at 0x7f334a85c390

DEBUG: avpops [avpops_impl.c:420]: loaded avps = 0

INFO: avp_db_load return result is -1

 

I was expecting it to return  at least one AVP .

 

Any suggestions gratefully received .

 

 

Hugh James

 

Hugh James | Telephony Developer

icons
logo

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.



_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users

-- 
Daniel-Constantin Mierla - http://www.asipto.com
http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
Kamailio Advanced Trainings - Berlin, Nov 25-28
  - more details about Kamailio trainings at http://www.asipto.com -