<docbook><section><title>IODBCChHOWTO</title><title> iODBC+Ch HOWTO for Linux/UNIX Systems</title> iODBC+Ch HOWTO for Linux/UNIX Systems
<para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h2"> Disclaimer</bridgehead>
<para>The following is a HOWTO document for installing Ch with iODBC on Linux or Unix.
 Feel free to criticize, suggest modifications, or ask further questions.
 It is currently maintained by Tim Haynes of Openlink Software (iodbc@openlinksw.com)</para>
<para>Prerequisites include basic Unix familiarity, such as creating directories and users, using an editor, etc.</para>
<para>This HOWTO is intended to assist in connecting Ch to back-end databases via ODBC in a development environment and should not take the place of thorough testing before deployment on a production system.</para>
<para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h2"> ODBC Overview</bridgehead>
<para>ODBC (Open Database Connectivity) is an operating system- and database- independent communication API for database connectivity.
 It enables ODBC compliant client applications to connect transparently to back-end databases via ODBC function calls which are implemented by ODBC Drivers for target back-end databases.</para>
<para>ODBC provides your applications with database independence; consequentially, you no longer have to incur the development and maintenance cost of inextricably binding your application to backend database engines via their proprietary data-access (aka native) APIs.</para>
<para>ODBC connections involve an ODBC-compliant Application or Data Access Layer, ODBC Driver Manager, ODBC Driver, and back-end Database.
 The ODBC Driver Manager for Microsoft Windows platforms is administered via the ODBC Administrator Control Panel applet at setup and configuration time.
 The Driver Manager registers a set of ODBC driver connection parameters called a Data Source Name (DSN), and maintains (in persistent form) a relationship between the DSN and an underlying ODBC Driver that will honor data access request via that DSN.</para>
<para>At runtime an application looks to the driver manager for a DSN, and then passes the connection parameters specified in the DSN to the appropriate driver, which makes the actual database connection.
 Under non-Windows platforms you may need to install a Driver Manager if this isn&#39;t delivered as an integral part of your operating environment.
 Platform independent ODBC (aka iODBC) is an Open Source ODBC project (dual license LGPL / BSD)for non Windows platforms maintained by <ulink url="OpenLink">OpenLink</ulink> Software that consists of an ODBC SDK (libraries and header files) and ODBC Runtime components (Administrator and Driver Manager).</para>
<para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h2"> HOWTO Preface:</bridgehead>
<para>You will also need an ODBC Driver and Database to complete the architecture.</para>
<para>If you need ODBC drivers to connect to a third-party database on the same or another machine, <ulink url="OpenLink">OpenLink</ulink> ODBC Drivers are available, and may be downloaded from <ulink url="http://www.openlinksw.com">http://www.openlinksw.com</ulink></para>
<para>The Virtuoso database may also be downloaded from <ulink url="http://virtuoso.openlinksw.com/">http://virtuoso.openlinksw.com/</ulink></para>
<para>Both sets of ODBC Drivers are available on a free 30-day evaluation basis.</para>
<para>Support for setting up the <ulink url="OpenLink">OpenLink</ulink> Drivers may be obtained at <ulink url="http://support.openlinksw.com/">http://support.openlinksw.com/</ulink></para>
<para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h2"> Installing Ch</bridgehead>
<para>If you already have Ch installed and running, you probably do not need to rebuild it.
 Otherwise, you should install it, thus:</para>
<para>First, download the latest distribution appropriate to your OS from <ulink url="http://www.softintegration.com/">http://www.softintegration.com/</ulink> - currently this is version 4.0.</para>
<para>Unpack it with a command like</para>
<programlisting>gzip -cd &lt; chstandard-4.0.0.linux2.2.5.intel.tar.gz | tar xvpf -
</programlisting><para> Enter the resultant directory, and run the install script:</para>
<programlisting>zsh, purple  1:05PM chstandard-4.0.0.linux2.2.5.intel/ % ls
README  ch.bin  install.sh*  license.txt
zsh, purple  1:05PM chstandard-4.0.0.linux2.2.5.intel/ % ./install.sh
</programlisting><para> You will also probably need to set the CHHOME environment variable to the base directory you chose as Ch&#39;s installation destination - depending on your current shell, choose one or other of the following:</para>
<para> </para>
<programlisting>echo &#39;setenv CHHOME $HOME/ch4&#39; &gt;&gt; .tcshrc
</programlisting><para> or </para>
<programlisting>echo &#39;export CHHOME=$HOME/ch4&#39; &gt;&gt; .bashrc
</programlisting><para> These are not necessary if Ch is installed as root into a default system-wide location.</para>
<para>After installation, if you run the command</para>
<programlisting>ch -d
</programlisting><para> It will create a ~/.chrc file for you with useful default settings.</para>
<para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h3"> Installing Ch on <ulink url="MacOS">MacOS</ulink> X</bridgehead>
<para>First, download the compressed Ch from <ulink url="http://www.softintegration.com/download">http://www.softintegration.com/download</ulink></para>
<para>Your Mac OS X shuttle will uncompress the file and create a directory such as chsandard-4.0.0.macosx in your Desktop.
 If not, you can decompress and untar the downloaded file with the command:</para>
<para> </para>
<programlisting>gzip -cd chstandard-4.0.0.macosx.tgz |tar xvf -
</programlisting><para> Goto the chstandard-4.0.0.macosx folder on the Mac OS X Desktop, double-click chstandard-4.0.0.pkg, then follow the instructions to install.</para>
<bridgehead class="http://www.w3.org/1999/xhtml:h2"> Installing iODBC</bridgehead>
<para>If you do not already have iODBC installed, either install an RPM from <ulink url="http://www.iodbc.org/,">http://www.iodbc.org/,</ulink> or install from source:</para>
<para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h3"> Compiling iODBC from source</bridgehead>
<para>Requirements: C-compiler; optionally gtk+-1.2 (required if building from CVS).</para>
<para>As before, unpack the iODBC sources, enter the build directory, configure, make and make install:</para>
<programlisting>zsh, purple  4:13PM C/ % tar xvpfz libiodbc-3.51.1.tar.gz
libiodbc-3.51.1/
libiodbc-3.51.1/admin/
libiodbc-3.51.1/admin/Makefile.am
libiodbc-3.51.1/admin/Makefile.in
libiodbc-3.51.1/admin/acinclude.m4
[snip]
libiodbc-3.51.1/samples/Makefile.in
libiodbc-3.51.1/samples/iodbctest.c
zsh, purple  4:14PM C/ % cd libiodbc-3.51.1
zsh, purple  4:14PM libiodbc-3.51.1/ % ./configure --prefix=/usr/local/stow/iodbc-3.51.1
checking for a BSD-compatible install... /bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
[snip]
config.status: executing depfiles commands
config.status: executing default commands
zsh, purple  4:15PM libiodbc-3.51.1/ % make
Making all in admin
make[1]: Entering directory `/home/tim/C/libiodbc-3.51.1/admin&#39;
[snip]
make[1]: Leaving directory `/home/tim/C/libiodbc-3.51.1&#39;
zsh, purple  4:15PM libiodbc-3.51.1/ % su root -c &#39;make install&#39;
</programlisting><para> It&#39;s advisable to install into /usr/local, or stow your installation into /usr/local, as that is searched by most other applications trying to locate iODBC.</para>
<bridgehead class="http://www.w3.org/1999/xhtml:h3"> Testing iODBC</bridgehead>
<para>Now is a good time to configure iODBC, by adding a DSN - create a file ~/.odbc.ini, edit it to look something like this:</para>
<programlisting>[ODBC Data Sources]
PostgreSQL native localhost = PostgreSQL native driver
Local Virtuoso Demo = localhost virtuoso (demo instance)
Local Virtuoso = localhost virtuoso

[Local Virtuoso Demo]
Description = Virtuoso 3.2
Driver      = /home/tim/virtuoso/lib/virtodbc32.so
Address     = localhost:1112
UserName    = dba
User        = dba

[Local Virtuoso]
Description = Virtuoso 3.2
Driver      = /home/tim/virtuoso/lib/virtodbc32.so
Address     = localhost:1111
UserName    = dba
User        = dba

[PostgreSQL native localhost]
Driver     = /usr/lib/postgresql/lib/libodbcpsql.so
Host       = localhost
Server     = localhost
ServerName = localhost
Database   = tim
UserName   = tim
UID        = tim
Port       = 5432
</programlisting><para> It is advisable to export the environment variable ODBCINI to point to this file, too - depending on your shell, either:</para>
<para> </para>
<programlisting>echo &#39;export ODBCINI=$HOME/.odbc.ini&#39; &gt;&gt; .bashrc
</programlisting><para> or</para>
<programlisting>echo &#39;setenv ODBCINI $HOME/.odbc.ini&#39; &gt;&gt; .tcshrc
</programlisting><para> as appropriate.</para>
<para>You can now make a test connection with the <emphasis>iodbctest</emphasis> utility, thus:</para>
<para> </para>
<programlisting>zsh, purple  4:54PM libiodbc-3.51.1/ % which iodbctest
/usr/local/bin//iodbctest
zsh, purple  4:54PM libiodbc-3.51.1/ % iodbctest      
iODBC Demonstration program
This program shows an interactive SQL processor
Driver Manager: 03.51.0001.0908

Enter ODBC connect string (? shows list): ?

DSN                            | Description                   
---------------------------------------------------------------
Local Virtuoso                 | localhost virtuoso 
Local Virtuoso Demo            | localhost virtuoso (demo instance)
MySQL                          | MySQL native driver           
PostgreSQL native localhost    | PostgreSQL native driver      
PostgreSQL OpenLink localhost  | PostgreSQL over OpenLink multi-tier
Virtuoso30                     | OpenLink Virtuoso 3.0         

Enter ODBC connect string (? shows list): DSN=Local Virtuoso Demo;UID=dba;PWD=cens0red
Driver: 03.50.2505 OpenLink Virtuoso ODBC Driver

SQL&gt;
</programlisting><para> If you see the SQL&gt; prompt there, then all has gone well.</para>
<para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h2"> Interfacing with Ch</bridgehead>
<para>SoftIntegration.com provide a module for Ch to interface with iODBC - you should download the chiodbc module from <ulink url="http://www.softintegration.com/.">http://www.softintegration.com/.</ulink></para>
<para>Installing this is simple; unpack the tarball into $CHHOME/package/ directory, thus:</para>
<para> </para>
<programlisting>zsh, purple  1:49PM chstandard-4.0.0.linux2.2.5.intel/ % cd ~/ch4/package 
zsh, purple  1:49PM package/ % gzip -cd &lt; ~/Downloads/chiodbc-3.5.0.linux2.2.5.intel.tar.gz| tar xvpf -
</programlisting><para> Now you need to set two variables in Ch&#39;s startup script to tell it where to find the system-wide installation of iODBC - edit $CHHOME/config/chrc or ~/.chrc and insert the following two lines:</para>
<programlisting>_ppath = stradd(_ppath, &quot;/home/tim/ch4/package/iodbc;&quot;);
_ipath = stradd(_ipath, &quot;/home/tim/ch4/package/iodbc/include;&quot;);
</programlisting><para> You can also export the ODBCINI environment variable from within Ch, thus:</para>
<programlisting>echo &#39;putenv(&quot;ODBCINI=$HOME/.odbc.ini&quot;);&#39; &gt;&gt; .chrc
</programlisting><bridgehead class="http://www.w3.org/1999/xhtml:h2"> Sample script combining Ch and iODBC</bridgehead>
<para>Having configured a DSN above, you should be able to use both the simple.c and odbctest.c scripts, thus:</para>
<para> </para>
<programlisting>zsh, purple  2:05PM demos/ % ch
Ch 
Standard edition, version 4.0.0.11291 
(C) Copyright 2001-2003 SoftIntegration, Inc.
http://www.softintegration.com
/home/tim/ch4/package/iodbc/demos&gt; cd $CHHOME/package/iodbc/demos
/home/tim/ch4/package/iodbc/demos&gt; ls
odbctest.c  simple.c
/home/tim/ch4/package/iodbc/demos&gt; ./simple.c
SQLAllocHandle() OK
SQLSetEnvAttr() ok
SQLAllocHandle() ok
SQLSetConnectAttr() ok

/home/tim/ch4/package/iodbc/demos&gt; ./odbctest.c
OpenLink ODBC Demonstration program
This program shows an interactive SQL processor

Enter ODBC connect string (? shows list): DSN=Local Virtuoso Demo;UID=dba;PWD=cens0red
Driver: 03.50.2604 OpenLink Virtuoso ODBC Driver (virtodbc.so)

SQL&gt;select * from Demo.demo.Shippers

ShipperID  |CompanyName                             |Phone                   
-----------+----------------------------------------+------------------------
1          |Speedy Express                          |(503) 555-9831          
2          |United Package                          |(503) 555-3199          
3          |Federal Shipping                        |(503) 555-9931          

result set 1 returned 3 rows.
</programlisting><para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h2"> Additional Resources</bridgehead>
<itemizedlist mark="bullet" spacing="compact"><listitem><ulink url="http://www.iodbc.org">iodbc.org</ulink> , the home of iODBC </listitem>
<listitem><ulink url="http://www.softintegration.com/">SoftIntegration.com</ulink> , authors of Ch </listitem>
<listitem><ulink url="http://www.softintegration.com/products/toolkit/odbc/">Ch iODBC home</ulink> </listitem>
<listitem>History of  <ulink url="index.php?page=docs/odbcstory">ODBC on Unix</ulink> </listitem>
<listitem><ulink url="http://www.openlinksw.com/">OpenLink Software</ulink> -  <ulink url="http://www.openlinksw.com/support/suppindx.htm">Support</ulink> ,  <ulink url="http://www.openlinksw.com/support/teclinks.htm">links</ulink> and  <ulink url="http://www.openlinksw.com/info/docs/odbcwhp/tableof.htm">white-papers</ulink></listitem>
</itemizedlist></section></docbook>