[LANG]
dsn=asterisk
readsql=SELECT language FROM sippeers WHERE name='${SQL_ESC(${ARG1})}'
This is odbc.ini
[asterisk]
Description = MySQL Connection for "Asterisk" Database
Driver = MySQL
Database = asterisk_test
User = asterisk
Password = mypass
Port = 3310
Server = 127.0.0.1
Socket = /var/lib/mysql/mysql.sock
Not sure how it’s handled inside of Asterisk, but “name” is a reserved word in MySQL. Can you try to surround name with back-ticks? (On a US keyboard, it’s above the Tab, left of the 1, and on the same key with the tilde) “Language” may also cause you a problem.
Backticks are for “escape” bash commands inside another string or command. That’s why you got that error.
Can you show the complete part of the dialplan where You invoke the query and also the enable the debug and check the full log if there is more information.
Executing [119@internal:1] NoOp("SIP/1001-00000001", "") in new stack
[Sep 21 14:58:45] ERROR[39677][C-00000002]: func_odbc.c:835 acf_odbc_read: Unable to execute query [SELECT language FROM sippeers WHERE name='1001']
-- Executing [119@internal:2] Set("SIP/1001-00000001", "LANG=") in new stack
-- Executing [119@internal:3] GotoIf("SIP/1001-00000001", "0?Voicemail,6") in new stack
-- Goto (internal,Voicemail,1)
-- Executing [Voicemail@internal:1] NoOp("SIP/1001-00000001", "") in new stack
-- Executing [Voicemail@internal:2] Playback("SIP/1001-00000001", "mainmenu") in new stack
In my case in database I have set ‘en’ and should Goto Voicemail,6 but as you can see “LANG=”
This is in my func_odbc.conf
[LANG]
dsn=asterisk
readsql=SELECT language FROM sippeers WHERE name='${SQL_ESC(${ARG1})}'
I prefer to have the SQL in the dialplan. It makes it easier for me to review, so here’s what I have…
I guess single-quotes don’t need to be escaped. I’ll have to clean my code up.
extensions.conf
same => n,Set(exten=${ODBC_READSQL(select ext_dialed from extensions where ext_did=\'${CALLERID(num)}\' or ext_dialed=\'${CALLERID(num)}\')})
same => n,Set(ARRAY(canpickup,devtype)=${ODBC_READSQL(select count(*)\, ext_dev_type from pickup left outer join extensions on extension=ext_dialed where extension='${EXTEN:3:5}' and allowed_exten='${CHANNEL:4:5}')})
same => n,Set(ODBC_WRITESQL()=update extensions set ext_forward_flag=\'1\' where ext_did=\'${CALLERID(num)}\' or ext_dialed=\'${CALLERID(num)}\')
func_odbc.conf
[READSQL]
dsn=asterisk
readsql=${ARG1}
[WRITESQL]
dsn=asterisk
writesql=${VAL1}
Try changing dsn name to general instead of asterisk in func_odbc.conf, reload func odbc and see.
Alternatively you can add below context in res_odbc.conf, reload res_odbc and try.
I 'm agreed with satish4asterisk , your problem it is your func_odbc.conf confguration incorrect dsn setting and also add a context on the res_odbc.conf file with the correct information, below you have a correct example of how your confinguration should be.
When I change the DSN in func_odbc.conf to general instead of asterisk and reload the module in CLI I see unregistering and registering them successfully
== Parsing '/etc/asterisk/func_odbc.conf': Found
== Unregistered custom function ODBC_LANG
== Unregistered custom function ODBC_EXIST
== Registered custom function 'ODBC_EXIST'
== Registered custom function 'ODBC_LANG'
Then when I try this command in CLI, the Asterisk is restarted and got this error
@mkozusnik, this doesn’t help because still need to use ODBC which is the problem part. It’s not that different from mine. Mine setup just have different prefix, no?
The version is asterisk-14-current. I have managed to fix the issue with Segmentation fault. It turns out that the problem is in the mysql and odbc connector/driver.
However, this issue still exists.
Failed to execute query. [SELECT language FROM sippeers WHERE name=‘1002’]
This one now is working and return correct result
echo “select name from sippeers where name = 1001” | isql -v asterisk
Okay, thanks to everybody for the help. The issue is resolved!
It turns out that for an unknown reason to me, asterisk doesn’t want to use table sippeers. When I created table sipfriends and added the record there is started working right away.
P.S.
I don’t know how to mark the thread as resolved.