While trying to execute ODBC function in Asterisk dialplan error is thrown:
[Oct 27 14:20:21] ERROR[4601]: pbx.c:3380 ast_func_read: Function ODBC_INSERT cannot be read
— Executing [XXXXXXXXX@internal:5] Set(“SIP/out-0000001a”, “ins=”) in new stack
func_odbc.conf looks like this:
1 2 3 |
[UPDATE] dsn=asterisk writesql = UPDATE dutylist SET lastcaller ='${SQL_ESC(${ARG1})}' |
and my extensions.conf is:
1 |
exten=>_X.,n,Set(ins=${ODBC_UPDATE(${CALLERID(num)})}) |
All variables are correct, ODBC is also configured correctly (read from DB statements work).
There is a difference in syntax and logic between “read” and “write” functions.
In our func_odbc.conf we are trying to write VAL1 and but in fact we want to use ARG1. In the dialplan above, VAL1 is not set (it comes after the =)
So acting in the same way as for “read” functions we are trying to read a value from the function which is only a “write” function.
We need an “=” in our Set command to avoid errors, but it should be at the end. Also the function doesn’t need to be wrapped in ${} for writing:
1 |
exten=>_X.,n,Set(ODBC_UPDATE(${CALLERID(num)})=) |
Regarding ARG vs VAL, here is an example that uses both:
1 2 3 |
[INSERT] dsn=asterisk writesql = INSERT INTO info SET ${ARG1}='${VAL1}',${ARG2}='${VAL2}' |
We use both VAL and ARG; then put this in the dialplan:
1 |
exten=>_X.,n,Set(ODBC_INSERT(name,phone)=${name},${phone}) |
The final note: use escaping of input with SQL_ESC() and stay safe!
Good luck!