Mod spidermonkey odbc

From FreeSWITCH Wiki
Jump to: navigation, search

Contents

SpiderMonkey ODBC

FreeSWITCH supports unixODBC library. As of at least March 23, 2009 the FreeSWITCH build scripts auto-detect the unixODBC library and no longer require the "--enable-core-odbc-support" flag to be passed in.

  1. First download and install unixodbc. See below if you are struggling with this step. Make sure to install headers, libraries and source for the unixodbc library set.
  2. In the FreeSWITCH source directory, uncomment the languages/mod_spidermonkey_odbc line within the modules.conf file.
  3. Compile core odbc support into freeswitch.
  4. Uncomment the <load mod_spidermonkey_odbc /> in {prefix installation location}/freeswitch/conf/autoload_config/spidermonkey.conf.xml and restart freeswitch for the changes to take effect.
./configure
make; make install

or (old way, no auto-detection of unixODBC installation)

./configure --enable-core-odbc-support
 make; make install

unixODBC

32 bit platform

Debian

  • For Debian, if the spidermonkey_odbc module does not compile you can try to install the package unixodbc-dev - it compiled just fine for me afterwards.

See Using_ODBC_in_the_core#PostgreSQL_8.4_on_Debian_Squeeze

Gentoo

  • For Gentoo it's just a simple install from portage
emerge unixODBC
  • Also note that you need to install the driver for choice of database server, for example for MySQL:
emerge myodbc

Other

  1. Download latest version of unixodbc.
    1. tar -xvzf unixodbc*.tar.gz
    2. Run ./configure --enable-gui=no
    3. Run make
    4. Run make install Run as root user
  2. Run make for freeswitch.

64 bit platform

Debian

See Using_ODBC_in_the_core#PostgreSQL_8.4_on_Debian_Squeeze

Gentoo

  • For Gentoo it's just a simple install from portage
emerge unixODBC
  • Also note that you need to install the driver for choice of database server, for example for MySQL:
emerge myodbc

SLES 11

  • zypper install unixODBC
  • zypper install unixODBC Devel
  • For MySQL 5.0
    • Download the mysql ODBC connector
mysql-connector-odbc-5.1.6-linux-glibc2.3-x86-64bit.tar.gz (http://dev.mysql.com/downloads/mirror.php?id=376312)
      • Untar and place in your lib directory
  • Create the odbc template file as noted below:
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/libmyodbc5.so
UsageCount = 1000000 
  • Edit the odbc.ini file (/etc/unixODBC)
  • Check to ensure that your odbc driver can connect to the db.
    • isql -v <DSN> (-v will give you a verbose output it something is jacked)



Other

  1. Download latest version of unixodbc.
    1. tar -xvzf unixodbc*.tar.gz
    2. Run ./configure --enable-gui=no
    3. Run make
    4. Run make install Run as root user
  2. Run make for freeswitch.

Errors

Debian 64 Bit

  • Chris 21:40, 26 June 2007 (EDT) Debian etch seems to have 64 bit OS mismatch with the unixodbc library. I used aptitude to download the development and compiled version only to find that they were compiled for 32 bit. Here are the facts and a fix for those that need a helping hand.
MaxPowerSoft001:/home/MaxPowerSoft/freeswitch/freeswitch# uname -a
Linux MaxPowerSoft001 2.6.18-4-amd64 #1 SMP Mon Mar 26 11:36:53 CEST 2007 x86_64 GNU/Linux
  • Compiling freeswitch after uncommenting spidermonkey modules within modules.conf rendered:
mod_spidermonkey_odbc.c:369: warning: passing argument 2 of âSQLRowCountâ from incompatible pointer type
mod_spidermonkey_odbc.c:378: warning: passing argument 7 of âSQLDescribeColâ from incompatible pointer type
mod_spidermonkey_odbc.c:373: warning: unused variable âColumnSizeâ
mod_spidermonkey_odbc.c:372: warning: unused variable âNullableâ
mod_spidermonkey_odbc.c:372: warning: unused variable âDecimalDigitsâ
mod_spidermonkey_odbc.c:372: warning: unused variable âDataTypeâ
mod_spidermonkey_odbc.c:372: warning: unused variable âNameLengthâ

FIX:

  1. aptitude remove unixodbc-dev libodbcinstq1c2 unixodbc (If previously installed.)
  2. Download latest version of unixodbc.
    1. tar -xvzf unixodbc*.tar.gz
    2. Run ./configure --enable-gui=no
    3. Run make
    4. Run make install Run as root user
  3. Run make for freeswitch.

General Configuration

GUI Installation

  • Run ODBCConfig.

Manual Installation

[Reading material on manual configuration]

  • After you install unixODBC, run ./odbcinst -j. This will show you list of config files. Make sure you add the following information in all of those
  • Add the following with the correct information into your odbc.ini file located at /etc/odbc.ini. (if /root/.odbc.ini is generated, add this there too.)
[maxpowersoft_odbc]
Driver=MySQL
SERVER=localhost
PORT=3306
DATABASE=myDatabase
Socket = /var/lib/mysql/mysql.sock
  • Create a template_file containing:
[MySQL]
Description = ODBC for MySQL
Driver = /usr/local/lib/libmyodbc3.so
UsageCount = 1000000
  • Run the following to add the information into the odbcinst.ini
    • odbcinst -i -d -f template_file
  • Test your ODBC setup by running the utility isql
    • isql maxpowersoft_odbc myUser myPass

FreeSWITCH ODBC Configuration

After a successful compilation and installation of mod_spidermonkey_odbc make sure to modify the configuration files as follows prior to executing freeswitch.

  • Edit: conf/autoload_configs/spidermonkey.conf.xml
    • Uncomment:
      <load module="mod_spidermonkey_odbc"/>

ODBC Example

use("ODBC");

var DSN="my_odbc_conn";
var DB_USER="my_username";
var DB_PASS="my_password";

var db = new ODBC(DSN, DB_USER, DB_PASS);
db.connect();

var digits = "9998"; //an example pin code.

var sql = "SELECT c.name, c.phone FROM user u, contact c WHERE u.userid=c.userid AND u.pin=\""+digits+"\";";
var row;

db.query(sql);

while (db.nextRow()) {
        row = db.getData();
        console_log("notice", "CONTACT FOUND " + row["name"] + " " + row["phone"] + "\n");
}
db.close(); /* shown as an example, not necessary. As the script finishes execution the system will automatically release odbc resources. */
  • Note, FreeSWITCH needs to be run under the same user that has a .odbc.ini in the root of the home folder. (ex: /home/fs/.odbc.ini)