login | register
Thu 04 of Dec, 2008 [00:02 UTC]

voip-info.org

History

Asterisk func hash

Created by: JustRumours,Last modification on Sun 14 of Sep, 2008 [12:12 UTC]

Function HASH


The primary intended use is in conjunction with func_odbc, to allow you to retrieve multiple values and reference them without having to assign each field to an individual variable. Think 'SELECT *' where the fields included might change over time, and you don't want the placement of a minor field to completely break your dialplan.

Example

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)

Basically, it's a way to retrieve multiple values from a database without using ARRAY() to enumerate each field, but also without polluting the variable namespace, which could cause unexpected behavior, such as when somebody adds a field to a database table whose name happens to coincide with an existing variable.

In short, it's a way to be able to use a 'SELECT *' query which doesn't break when somebody adds columns to a table.


See also



Comments