Asterisk func hash

Function HASH

New in Asterisk 1.6.x (?): 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.

New in Asterisk 1.8: HASH-associated variables now can be inherited across channel creation, by prefixing the name of the hash at assignment with the appropriate number of underscores, just like variables.

Example 1

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.

Example 2


HASH(SIP_CAUSE,<slave-channel-name>) ; as set by Asterisk 1.8


See also

  • function Asterisk func hashkeys
  • function Asterisk func clearhash
  • Asterisk func ARRAY
  • Asterisk func MASTER_CHANNEL of Asterisk 1.8: Retrieve and set variables on the channel which created the current channel
  • Asterisk functions

Function HASH

New in Asterisk 1.6.x (?): 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.

New in Asterisk 1.8: HASH-associated variables now can be inherited across channel creation, by prefixing the name of the hash at assignment with the appropriate number of underscores, just like variables.

Example 1

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.

Example 2


HASH(SIP_CAUSE,<slave-channel-name>) ; as set by Asterisk 1.8


See also

  • function Asterisk func hashkeys
  • function Asterisk func clearhash
  • Asterisk func ARRAY
  • Asterisk func MASTER_CHANNEL of Asterisk 1.8: Retrieve and set variables on the channel which created the current channel
  • Asterisk functions

Created by: JustRumours, Last modification: Sun 01 of Aug, 2010 (03:52 UTC)
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+