Func ODBC - more than one parameter?

Hi,

I’m running Asterisk 16 and for an application function I need to lookup database values which match multiple conditions.
But: This seems not to be supported. It’s a bit confusing, since there are manuals on the Internet which are happily using ${ARG2} or ${ARG3} in func_odbc.conf - but I can’t get this to work and after looking here I’m even more confused, if “argument” is indeed meant to be in singular.

Is there official support for having multiple arguments in readsql?
I’m trying to use it like i.e.

[MYFUNC]
dsn=asterisk
readsl=SELECT thing FROM table WHERE this = ${ARG1} AND that = ${ARG2}

and calling from dialplan:

same => Set(MYVARIABLE=${ODBC_MYFUNC(${myvariable1},${myvariable2})})

Is there any trick to get ODBC working with more than one argument?

Thanks!

Maybe Getting Funky with func_odbc: Hot-Desking and the previous chapter helps. There should be no problem with multiple arguments.

You can do something like:

readsql=${ARG1}

And then pass the the entire select from…

I tried this, but with no luck:

func_odbc.conf

[DSTBYDEPARTMENT]
dsn=asterisk
readsql=SELECT `dstexten` FROM `extenlist` WHERE `department` = '${SQL_ESC(${ARG1})}' AND `callerid` = '${SQL_ESC(${ARG2})}';

Dialplan:

same => n,Set(LG_DEPARTMENT=5)
same => n,Set(LG_DSTEXTEN=${ODBC_DSTBYDEPARTMENT(${LG_DEPARTMENT},${CALLERID(num)})

Unfortunately, this is not working.
When executing this ODBC function on the CLI, I can clearly see, the second (or third, fourth, whatever count) argument is simply lost - only the first argument is accepted:

odbc read ODBC_DSTBYDEPARTMENT 5 123456
SELECT `dstexten` FROM `extenlist` WHERE `department` = '5' AND `callerid` = ''

And now it’s getting weird: If I add any more arguments (i.e. the “exec” argument), all I get is the help about the correct syntax:

odbc read ODBC_DSTBYDEPARTMENT 5 123456 exec
Usage: odbc read <name> <args> [exec]
       Evaluates the SQL provided in the ODBC function <name>, and
       optionally executes the function.  This function is intended for
       testing purposes.  Remember to quote arguments containing spaces.

I have a feeling, giving multiple arguments to ODBC worked at some point (based on the amount of manuals and guides that show you can use it that way), but now for some reason, only one argument is accepted :frowning:

Based on the Code of func_odbc.c it should be possible to use a variable amount of arguments, but for some reason, it’s not working.