Variable lookup failing, cannot initialize query

I am using this string for a database lookup based on the number dialed, the idea being to pull an “account code” from the DB and run a GoTo in the dialplan based on the returned result of the lookup.

same => Set(ACCOUNTCODE=${ABC_ACCT(${EXTEN})})
same => n,Goto(${ACCOUNTCODE},${EXTEN},)

after making changes in func_odbc, when I run module reload func_odbc.so I get an error ONLY for the variable/query I have created: Cannot initialize query ACCT. When I test the query in my SQL engine it returns as expected. what I am doing wrong in func_odbc that the variable/query lookup is not working as I intend?

There are other variables that use ABC prefix, I dont think that would create a conflict, but is it?

[ACCT]
prefix=ABC
;dsn=asterisk
dsn=local-db
SELECT accountcode FROM table WHERE field = '${ARG1}'
;readsql=SELECT accountcode FROM some_other_table WHERE number = '${ARG1}'

First, what does the database say? Secondly, maybe you forgot the “readsql=”?

ah, yeah thanks. that cleared up the cannot initialize query issue. didnt even realize I was missing the readsql bit to start the query. thank you

as for what the database says, I am not sure what youre asking. the query returns the data I am looking for when I run it in the DB. and also now when I run odbc read ABC_ACCT it seems to test the query, which it wasn’t before

I meant the log file of the db. In your case there was probably nothing indicating that the problem was before the query made it to the db.

yeah that seems to be the case. I dont see anything in the logging.

with the query fixed though…any idea why the lookup would be failing? Here is the returned output from the CLI

   -- Executing [xxxxxxxxxx@messages-in:1] NoOp("Message/ast_msg_queue", "MODIFIED receiving dialplan invoked") in new stack
   -- Executing [xxxxxxxxxx@messages-in:2] Goto("Message/ast_msg_queue", ",xxxxxxxxxx,") in new stack

so it looks like I am in the dialplan where I would expect to be to handle an incoming message, but my Set(ACCOUNTCODE=${ABC_ACCT(${EXTEN})}) lookup doesnt return the accountcode I need to execute the GoTo…any ideas?

I can’t see what you are trying to do. You’d need to post the relevant dialplan and possibly the console output for “verbose” >= 3. You should also describe which database you are using. Usually you should be able to log the sql statements, just in case.

In the log you posted, there’s no Set() application, only a Noop() and Goto() applications seems to be used.

Are you sure the call is sent to the correct dialplan?

Also, assuming the function is actually registered. You can find out by running in the Asterisk CLI

core show function ABC_ACCT

So the problem with the lookup failing was that I didn’t indicate “next” before my Set()

same => Set(ACCOUNTCODE=${ABC_ACCT(${EXTEN})})

should have been

same => n,Set(ACCOUNTCODE=${ABC_ACCT(${EXTEN})})

as its not the start of this context but the next step after a pattern match. The lookup now works as expected.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.