1

I've got an ODBC function that's pulling multiple values from my database and storing them in an array of variables. Later in the dialplan I'm using that variable, but all the double quote marks are getting removed – single quotes are untouched. If I store the value directly into a variable (as opposed to an array) quotes are maintained, but of course a comma-delimited string is not very usable.

Dialplan:

exten => 123,1,Set(ARRAY(FOO,BAR)=${MY_FUNC()})
exten => 123,2,NoOp(The value is now '${FOO}')
exten => 123,3,Set(FOO=${MY_FUNC()})
exten => 123,4,NoOp(The value is now '${FOO}')

Output:

Executing [123@mycontext:1] Set("SIP/7040-0000105b", "ARRAY(FOO,BAR)=I am "testing" it,23") in new stack
Executing [123@mycontext:2] NoOp("SIP/7040-0000105b", "The value is now 'I am testing it'") in new stack
Executing [123@mycontext:3] Set("SIP/7040-0000105b", "FOO=I am "testing" it,23") in new stack
Executing [123@mycontext:4] NoOp("SIP/7040-0000105b", "The value is now 'I am "testing" it,23'") in new stack

I've tried wrapping the function call in quotes, I have tried prefixing a backslash at the database level. Nothing seems to work, they are always removed.

Using HASH as suggested below does not change anything:

exten => 123,1,Set(HASH(FOO)=${MY_FUNC()})
exten => 123,2,NoOp(The value is now '${HASH(FOO,data1)}')

Output:

Executing [123@mycontext:1] Set("SIP/7040-00002bf9", "HASH(FOO)=I am "testing" it,23") in new stack
Executing [123@mycontext:2] NoOp("SIP/7040-00002bf9", "The value is now 'I am testing it'") in new stack

Storing data in an array is not a requirement, but I am pulling multiple values from the database and need to access them without corrupting the values, and without resorting to multiple functions each pulling a single value.

miken32
  • 35,483
  • 13
  • 81
  • 108

1 Answers1

0

Func_ODBC designed to be used with HASH function.

func_odbc.conf: [FOO]dsn=mysql readsql=SELECT * FROM foo WHERE somefield=’${SQL_ESC(${ARG1})}’

extensions.conf: Set(HASH(foo)=${ODBC_FOO(${bar})})

Now you can reference ${HASH(foo,somefield)} or ${HASH(foo,someotherfield)}. You can even add things to the HASH foo with:

Set(HASH(foo,notinthetable)=baz)

https://www.voip-info.org/asterisk-func-hash/

arheops
  • 14,867
  • 1
  • 15
  • 27