FreeSWITCH          




Page tree
Skip to end of metadata
Go to start of metadata

About

This module can be used for doing ODBC queries as an APP from the dialplan or through the API interface.

 Click here to expand Table of Contents

Compiling/Enabling

  1. You can find the source in the git contrib repository in ledr/c/mod_odbc_query. 

  2. make/gmake the mod

  3. make install

  4. copy the .xml config file cp odbc_query.conf.xml /usr/local/freeswitch/conf/autoload_configs/

  5. Set your ODBC access in the xml

  6. Run "load mod_odbc_query" in the CLI and add it to your auto-load modules list in conf/autoload_configs/modules.conf.xml

v1.4 specific changes


Due to a function name change, the module doesn't compile cleanly with the v1.4.beta or master branches (as of 04.04.2014). Edit: Patch updated (15.04.2014), because of another function change. The following patch resolves the problem:

 Expand source

 

APP

When using odbc_query as an APP you can call it from the dialplan. Returned rows will then be stored as channel variables for later use.

Usage

Create an ''odbc_query.conf.xml'' file in ''autoload_configs'', that at least contains an ''odbc-dsn'':

 

Load ''mod_odbc_query'' in your ''modules.conf.xml'':

 

Then you can do queries directly from your xml dialplan:

Or,

The module simply checks whether the data attr contains a space. If it does, then that field will be seen as an SQL query, otherwise it will be seen as a query 'name' which then has to be defined in the modules configuration in a <queries> section like this:

 

The module will do the query and store each returned column name as channel variable name together with its corresponding value.

Another feature is, that if only two columns are returned, which have the column names "name" and "value", then the channel variables will be set according to them. This way you can have the query return multiple rows with different channel variables. If the query returns something else than column-names "name" and "value" and it returns multiple rows, then the channel variables will be overwritten with each iteration of the rows - which is probably useless.

The query may contain '''${blah}''' variables that will be '''expanded''' from '''channel variables''' before the query is performed.

This application may be run inline from the XML dialplan.

example foo / bar

Query: ''"SELECT foo, bar FROM some_table;"''

returns:

then the channel variables that will be set are:

example name / value

Query: ''"SELECT foo AS name, bar AS value FROM some_table;"''

returns:

 

then the channel variables that will be set are:


So, the first example should only be used when you know that only zero or one row will be returned, and second one if you know zero or more rows will be returned.

If zero rows are returned (in either foo/bar or name/value case) then no channel variables will be set, overwritten or deleted.

example find gateway and bridge to it

For selecting gateways, you should probably use mod_lcr, this is just for explanation's sake.

For example, you have a table named gateways:

Then in your odbc_query.conf.xml:

Then in your xml dialplan, do:


API

The API interface is accessable from several places, for easy testing use it from your fs_cli console.

Usage

  • If you omit the first argument (formatting) then the default 'txt' will be used.
  • If you omit the second argument (odbc dsn) then the default odbc-dsn as set in the odbc_query.conf.xml will be used.
  • The third argument (the query itself) is mandatory.


As stated above, the formatting can be txt, tab or xml. Here are examples of their output:

format txt

format tab

 

format xml

 

1 Comment

  1. Step 1 of "Compiling/Enabling" isn't very clear.

    Could it be changed to something like

    1. cd /usr/src/freeswitch/
    2. git clone https://freeswitch.org/stash/scm/fs/freeswitch-contrib.git
    3. cd freeswitch-contrib/ledr/c/mod_odbc_query