Asterisk AEL and func_odbc.conf example.

Here is another Asterisk AEL example using func_odbc.conf.

You can call DB routines or querys from MySQL in your Asterisk AEL.

How to start ?

We first need to configure the ODBC connections which we will use in our func_odbc.conf. I assumed here, we have already setup ODBC DSN.

func_odbc.conf and extensions.ael are usually created in /etc/asterisk.

All the quries in the func_odbc.conf will be called a function and names will be defined as context, next line for DSN, and then read or write keywords.

e.g.,

[CHECKNAME] ;function name
dsn=mydsn ;dsn for ODBC connection
read=select name from users where user='1001' ;actual query. for update/insert use keyword "write" instead read

To use the arguments, coming from AEL, we will special functionSQL_ESC().

This function is a part of the ODBC module and ODBC must be compiled into Asterisk for this function to be available.

e.g.,
[CHECKNAME] ;function name
dsn=mydsn ;dsn for ODBC connection
read=select name from users where userid='${SQL_ESC(${ARG1})}' ;actual query. for update/insert use keyword "write" instead read

or for update the DB record

[UPDATENAME] ;function name
dsn=mydsn ;dsn for ODBC connection
write=update users set Active=1 where userid='${SQL_ESC(${VAL1})}'

VAL and ARG notations used usually for values supplied and the arguments passed to the query respectively.

Calling Queries in Asterisk AEL:

To call the query (read from DB) built in func_odbc.conf,

Set(USERNAME=${ODBC_CHECKNAME(${EXTEN})});

Here ODBC_ is the keyword that calls the function ‘CHECKNAME’ from func_odbc.conf

e.g.
context default {

1001 => {
Answer();

;This line calling function and supplying extension no as argument to SQL Query.
Set(USERNAME=${ODBC_CHECKNAME(${EXTEN})});

;Display output on CLI
NoOp( User of the extension is: ${USERNAME} );

;Now updating user name, here NiceName would be update where userid is extension.
Set(ODBC_CHECKNAME(${EXTEN})=NiceName);

};

};

Each time changing in the file func_odbc.conf, we need to reload the module using:

CLI> module reload func_odbc.so

Same goes for Asterisk AEL, it is needed to be reloaded after evey update in the file using:

CLI>aelreload

It’s better to compile and check the Asterisk AEL file before compiling in CLI. Use the application “aelparse” on the shell which will display
the compilation information including errors, if any.

RSS feed for comments on this post. TrackBack URI

Leave a Reply