[asterisk-users] Can someone give a plain english explanation of the HASH function?

Tilghman Lesher tilghman at mail.jeffandtilghman.com
Sat Sep 13 21:08:20 CDT 2008


On Saturday 13 September 2008 19:40:45 Eric Chamberlain wrote:
> Can someone explain what the HASH function does and how to use it?

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.

-- 
Tilghman



More information about the asterisk-users mailing list