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

Eric Chamberlain eric at rf.com
Sun Sep 14 11:24:53 CDT 2008


On Sep 13, 2008, at 7:08 PM, Tilghman Lesher wrote:

> 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.
>
>

Thank you that's exactly the explanation I was looking for.

Will HASH work with a single argument on more than just ODBC_  
functions?  Ideally, I'd like to format a CURL response such that it  
can be used with HASH.  Allowing access to a CURL response key-value  
pairs without having to use ARRAY to enumerate each field.

--
Eric Chamberlain









More information about the asterisk-users mailing list