Caché SQL is automatically installed as part of a Caché installation. After Caché is configured, Caché SQL does not typically require any additional configuration or setup. Most of the Caché SQL configuration options deal with the operation of DDL (how different flavors of DDL map to Caché) and with management of cached queries.
For Windows systems, there is an “SQL client only” installation option available that installs only the client access (ODBC driver) components of Caché.
SQL Options
You can view and modify the various Caché SQL configuration settings using the Advanced tab of the Caché Configuration Manager and expanding the SQL folder in the options tree:
SQL Section of the Caché Configuration Manager
ODBC Configuration
By default, Caché performs a full ODBC installation with a standard installation. This section describes how to set up and configure the ODBC driver. The architecture of an ODBC system has five parts:
In practice, a connection is established as follows:
  1. A client application includes ODBC calls that attempt to connect to a particular DSN. A client application is linked to an ODBC driver manager, which accepts the calls.
  2. The ODBC driver manager reads the Caché ODBC initialization file to obtain the location of the Caché ODBC client driver and load the client driver into memory.
  3. Once loaded into memory, the Caché client driver uses the Caché ODBC initialization file to locate connection information for the DSN, including the host on which Caché is running, the name of the Caché installation, and the namespace containing the data. Using both the DSN and other information from the initialization file, the client driver connects to the specified Caché installation and namespace.
  4. Having established the connection, the client driver maintains communications with the Caché database server.
ODBC Environment Variables and Logging
This section describes the ODBC environment variables and what they do. They are:
To set a Windows environment variable, use the Advanced tab of the System dialog from the Windows Control Panel. In that tab, in the Environment Variables section, select the New..., Edit..., or Delete... button to perform whatever task you need.
To set a UNIX environment variable on the Bourne or Korn shell, use the following commands:
VARIABLE=value
export VARIABLE
To set a UNIX environment variable on the C-Shell, use either of the following commands:
setenv VARIABLE value
set VARIABLE=value
To turn off an environment variable in a UNIX shell, run unset or set it equal to 0. If you never initially set its value, it remains disabled.
CACHEODBCDEFTIMEOUT
This variable allows you to specify the duration of a timeout for a default login. Its value is in seconds.
CACHEODBCHEADER
This boolean variable specifies that the driver writes header information to the log file. Header information is printed when the driver is loaded and includes build version, date, and time. A value of 1 turns on header generation and a value of 0 turns off header generation. By default, header generation is off.
CACHEODBCPID
This boolean variable enables the automatic appending of the process ID number to the log file name. A value of 1 enables appending and a value of 0 disables it. By default, appending is off.
With CACHEODBCPID enabled, if the base log file is CacheODBC.log and is in your current directory, then the process ID of 21933 generates a full log file name of “CacheODBC.log.21933”.
CACHEODBCPID interacts with CACHEODBCTRACEFILE. If you use CACHEODBCTRACEFILE to set the base file name of the log file (for instance, to C:/home/mylogs/mylog.txt and enable CACHEODBCPID, then log file names generated will be of the form C:/home/mylogs/mylog.txt.21965.
CACHEODBCTRACE (UNIX Only)
This boolean variable enables client driver logging. The default name for this file is CacheODBC.log. On Windows, enable client driver logging by checking the ODBC Log check box on the DSN setup dialog.
To enable driver manager logging on UNIX, set Trace entry in the Initialization file; to enable driver manager logging on Windows, use the ODBC Data Source Administrator dialog .
CACHEODBCTRACEFILE
This variable specifies the location and name of the trace file. This can be useful for placing the trace file in a unique directory or giving it a unique name. For UNIX, the trace file is generated in the current directory by default; for Windows, the trace file is generated in C:/WinNT or C:/Windows by default.
Windows Client Management
The tasks you can perform on Windows include:
Windows Client Driver Configuration
The configuration of the ODBC client is performed using the Caché ODBC Data Source Setup dialog. This is accessible by clicking the ODBC Data Sources icon, either in Windows Control Panel or its Administrative Tools subpanel:
Caché ODBC Data Source Setup Dialog
The InterSystems Caché ODBC Data Source Setup dialog is used to configure a specific Caché ODBC data source. You then can use this data source to make an ODBC connection to Caché from an ODBC-aware application (such as a development tool or report writer). The elements of this dialog are analogous to those in each section heading of a UNIX ODBC initialization file.
The fields within the Data Source dialog are listed below and are required unless otherwise specified:
After you have configured an ODBC Data Source, you can use the Test Connection button to see if your data source is working correctly.
Enabling Driver Manager Logging on Windows
To enable driver manager logging on Windows, click the Start Tracing Now button on the Tracing panel of the ODBC Data Source Administrator dialog. This dialog is accessible through the Windows Control Panel, either from the Administrative Tools subpanel or directly as the ODBC Data Sources choice, depending on which version of Windows is running. The file specified in the Log file Path field determines the location of the trace file.
To enable driver manager logging on UNIX, use the Trace entry in the initialization file. To enable client driver logging on Windows, use the ODBC Log check box in the Windows ODBC Data Source Setup dialog; to enable client driver logging on UNIX, use the CACHEODBCTRACE environment variable.
UNIX Client Management
This section covers the following topics:
Supported Drivers and Platforms
See the ODBC Driver Supported Platforms section of the Caché Supported Platforms document for a list of supported platforms.
To use the Caché ODBC Driver, you must have an ODBC driver manager on UNIX. The suppliers of UNIX ODBC driver managers for use with the Caché ODBC driver are:
There is also a commercial driver manager available from DataDirect, formerly Merant, formerly InterSolve. Note that this product's licensing agreement allows for connections to it only from DataDirect ODBC drivers (and not the Caché ODBC driver).
InterSystems currently supports the ODBC narrow interface on all UNIX platforms through the libcacheodbc library. Caché ships with a pre-built iODBC driver manager.
Installing and Configuring a Caché UNIX ODBC Client Driver as Part of a Full Install
This section describes tasks for using ODBC as part of a complete Caché installation. You can also perform a stand-alone client installation.
  1. During Caché installation, there is the following prompt:
    Do you want to install ODBC and SQL Gateway <Yes>?
    Answer “Yes,” which is the default. This ensures that you have the appropriate ODBC software on your machine.
  2. After installation, start Caché with the ccontrol command:
    # ccontrol start <configname>
    
    where configname is the configuration name that you chose during installation.
What Gets Installed
The installation places the following components under the cachesys directory:
Installing and Configuring a Stand-alone Caché UNIX ODBC Client Driver
To create a stand-alone client installation, the steps are:
  1. Create the directory where you wish to install the client, such as /usr/cacheodbc/:
    # mkdir /usr/cacheodbc
  2. Copy the zipped tar containing the files for client driver from the mounted CD drive to the directory where you just created with a command of the form:
    # cp <CD-dir>/dist/ODBC/ODBC-<release-code>-<platform>.tar.Z <client-install-dir>
    where CD-dir is the mounted location of the Caché, release-code and platform are release-specific and operating-system–specific codes (see next step), client-install-dir is the client installation directory that you created in the previous step.
  3. Go to the client installation directory and manually unpack the .tar file. From the same directory on the CD where the cinstall program located, the .tar file is in the ./dist/ODBC/ directory.
    To manually unpack the .tar file, the procedure is:
    # cd <client-install-dir>
    # gunzip ODBC-<release-code>-<platform>.tar.Z
    # tar xvf ODBC-<release-code>-<platform>.tar
    
    where release-code is a release-specific code (that varies among Caché versions and releases) and platform specifies the operating system for the driver. Possible values of platform are:
    This creates bin and dev directories, and installs a set of files.
  4. Run the ODBCInstall program, which will be in the directory that you created previously. This program creates the several sample scripts and configures cacheodbc.ini under the mgr directory. For example:
    # pwd
    /usr/cacheodbc
    # ./ODBCInstall
    
  5. Configure the installation's initialization file.
  6. Test the installation.
The ODBC Initialization File
To establish connections between a client application and an ODBC driver, the iODBC driver manager uses an initialization file. This file provides information so that the driver manager can locate and connect to an available DSN, including the path of the ODBC driver required for that connection. The Caché ODBC driver, libcacheodbc.so, references the initialization file to specify DSN options (such as a timeout duration) when connecting on UNIX platforms. The file can have any name, but, typically, it is called .odbc.ini when it is located in a user's personal directory, odbc.ini when located in an ODBC-specific directory; the Caché-specific version of it is called cacheodbc.ini and is located in a the /<cache-install-dir>/mgr directory.
To locate this file, the Caché ODBC driver mimics the search order of iODBC release 3.0.6. It looks for the file in the following places (in this order):
  1. The file specified by the ODBCINI environment variable, if this is defined. When defined, this variable specifies a path and file, such as:
    ODBCINI=/usr/cachesys/cacheodbc.ini
    export ODBCINI
  2. The .odbc.ini file in the directory specified by the user's $HOME variable, if $HOME is defined and .odbc.ini exists.
  3. If $HOME is not defined, the .odbc.ini file in the “home” directory specified in the passwd file.
  4. The file specified by the system-wide SYSODBCINI environment variable, if this is defined. As with ODBCINI, when defined, this variable specifies a path and file, such as:
    SYSODBCINI=/usr/cachesys/cacheodbc.ini
    export SYSODBCINI 
  5. The file odbc.ini file located in the default directory for building the iODBC driver manager (/etc/), so that the full path and file name are /etc/odbc.ini.
The iODBC 3.0.6 driver manager ships with Caché releases, built as a nonthreaded shared object. The driver manager is used for SQLGateway (cgate.so) and with a select program we build for testing ODBC. Our examples use cacheodbc.ini in the mgr directory which is configured during the install for accessing the samples and user namespace. You should modify cacheodbc.ini to add additional DSNs for use with cgate.so and iODBC, as Caché sets the ODBCINI environment variable to access this file. If you wish to use a different odbc.ini file then you should delete/rename the cacheodbc.ini file to allow the driver manager to search the $HOME or /etc/odbc.ini paths.
The following is a sample initialization file:
[ODBC Data Sources]
samples=samples

[samples]
Driver          = /usr/cachesys/bin/libcacheodbc.so
Description     = Cache' 5.x ODBC driver
Host            = localhost
Namespace       = SAMPLES
UID             = _SYSTEM
Password        = sys
Port            = 1972
Protocol        = TCP
Query Timeout   = 1
Static Cursors  = 0
Trace           = off
TraceFile       = iodbctrace.log 

[Default]
Driver = /usr/cachesys/bin/libcacheodbc.so
This file includes the following variables:
Testing a Caché ODBC Client Driver for UNIX
This section describes how to test the UNIX ODBC client driver:
  1. Run the select program to ensure that the client can read data:
    # cd <cache-install-dir>/dev/odbc/samples/select
    # ./select.sh
    What is the select.sh script doing? It calls the select program that is installed with the kit; the script also provides the select program with a particular DSN (“SAMPLES”). The select program is linked to the iODBC driver manager (libiodbc.so); the driver manager reads the Caché initialization file (<cache-install-dir>/mgr/cacheodbc.ini) to get connection information for the “SAMPLES” DSN. The driver manager determines the location of the Caché ODBC client driver and loads it into memory. The client driver then establishes a TCP/IP connection to port 1972 and is connected to the Caché “SAMPLES” namespace using the DSN information inside the Caché initialization file. Once the connection is established, the client application runs an SQL select statement against the Caché database. Specifically, the statement is “SELECT * from Sample.Person WHERE ID < 11”, which obtains the first ten rows of the Sample.Person table in the “SAMPLES” namespace. To see the application ODBC calls, refer to select.c.
  2. With a client driver that is part of a full Caché installation (not a stand-alone client), you can also test SQL Gateway access from Caché:
    ./sqlgateway/gatewaytest.sh 
    from the same directory as the previous step.
    The gatewaytest.sh script starts a Caché session and runs the routine SQLGatewayTest in the “SAMPLES” namespace. This application routine then loads a shared object called cgate.so, which is linked against the iODBC driver manager. As in the previous example, the driver manager load the client driver using information from the Caché initialization file. The client driver then establishes a TCP/IP connection to port 1972 and is connected to the Caché “SAMPLES” namespace using the DSN information inside the Caché initialization file. The application routine runs the same query as above.
    The difference between this example and the simple select example above is that in this example, the Caché process making the initial call is the client application. Typically, a Gateway call from Caché calls the DSN of another vendor's database.
The select.sh and gatewaytest.sh scripts should work without errors after the installation. To create your own calls, examine the content of the files for these projects for code that you can modify for your own needs.
Troubleshooting for Shared Object Dependencies
To validate dependencies on other shared objects and correct any problems, the process is:
  1. Use the ldd command against an executable or shared object:
    # ldd <cache-install-dir>/bin/libcacheodbc.so
    If any dependencies are not found, ldd displays an error similar to the following:
    libstlport_gcc.so => not found
  2. If there are no errors, then all dependencies are valid; if there are errors, run the following commands to force the shared object loader to look in the current directory:
    # sh
    # cd <cache-install-dir>/bin 
    # LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH
    # export LD_LIBRARY_PATH
    
    The sh command starts the Bourne shell; the cd command changes to the appropriate directory; and the export command sets the path to look up shared objects.
  3. Once you have added the current directory to the path, run ldd again and check for missing dependencies. If any shared objects cannot be found, add them to the same directory as the ODBC driver.
  4. To permanently make shared objects accessible, begin by copying the shared objects to /usr/lib or /usr/local/lib, depending on your operating system. Consult the documentation for your operating system to determine which is the appropriate directory and if there are any special commands for this, such as registering them on Linux with the ldconfig command.
Compiling and Linking select.c
To compile and link the select.c sample program:
  1. Go to <cachesys>/dev/odbc/samples/select, the directory containing the select.c file.
  2. Compile the program using cc, the UNIX compiler, ensuring that you include any include files. For a default Caché installation, the command is:
    # cc -c select.c -I../../redist/iodbc/include
    
  3. Link the file using cc, ensuring that you link to any required libraries. Again, for a default installation, the command is:
    # cc -o select select.o -L../../redist/iodbc -ldl -liodbc
    
You can also compile and link against a custom installation of iODBC. For example, if it is installed in /usr/local, the commands are:
# cc -c select.c -I/usr/local/iodbc/include 
# cc -o select select.o -L/usr/local/iodbc/lib -ldl -liodbc
Installing and Configuring the iODBC Driver
By default, each Caché installation includes an iODBC driver manager (v. 3.0.6) that is built as a single threaded executable under <cache-install-dir>/bin/libiodbc.so or libiodbc.sl. This built to run as installed.
If you want to build your own iODBC driver manager to operate under custom conditions, the process is described below. For all builds, the iODBC executable and include files should be in the <cache-install-dir>/dev/odbc/redist/iodbc/ directory. You need to set LD_LIBRARY_PATH (LIBPATH on AIX) and the include path in order to use these directories to build your applications.
Note:
The following references are provided as an example. Please check the documentation provided by iODBC for the correct version number as well as complete installation instructions and release notes.
The process of building the iODBC driver manager is:
  1. Download the iODBC Driver Manager.
  2. Log in as user root and uncompress/unzip and un-tar the kit in /tmp or other temporary area:
    # gunzip /tmp/libiodbc-3.0.6.tar.gz
    # tar xvf libiodbc-3.0.6.tar 
  3. In the installation directory, configure the iODBC source code:
    # cd /tmp/libiodbc-3.0.6
    # ./configure --prefix=/usr/local --with-iodbc-inidir=/etc
    This configures iODBC for the default installation directory of /usr/local and the default initialization directory of /etc.
  4. Compile the package with the make command:
    # make
  5. Optionally, run any self-tests that come with iODBC as follows:
    # make check 
  6. Install the test tools, samples, shared objects, data files, and documentation:
    # make install
Configuring PHP with Apache and the Driver Manager for libcacheodbc.so
You can use the ODBC functionality of Caché in conjunction with PHP (PHP: Hypertext Processor, which is a recursive acronym). PHP is a scripting language that allows developers to create dynamically generated pages. The process is as follows:
  1. Get or have root privileges on the machine where you are performing the installation.
  2. Install either the iODBC or unixODBC driver manager.
  3. Download the PHP source kit and un-tar it.
  4. Download the Apache HTTP server source kit and un-tar it.
  5. Build PHP and install it.
  6. Build the Apache HTTP server, install it, and start it.
  7. Test PHP and the Web server using info.php in the Apache root directory, as specified in the Apache configuration file (often httpd.conf). The URL for this is http://127.0.0.1/info.php.
  8. Copy the Caché-specific initialization file, cacheodbc.ini to /etc/odbc.ini as this location functions better with the Apache Web server if the $HOME environment variable is not defined.
  9. Configure and test the libcacheodbc.so driver with the steps for the basic testing.
  10. Copy the sample.php file from the Caché ODBC kit to Apache root directory (that is, the directory where info.php is located), and tailor it to your machine for the location of Caché. You can then run the sample.php program, which uses the Caché “SAMPLES” namespace, by pointing your browser to http://127.0.0.1/sample.php.
JDBC Client Configuration
The configuration of the JDBC client consists of the following steps:
  1. Installing the Caché JDBC driver (this is automatically installed by Caché within the <cachesys>/dev/java/lib/CacheDB.jar file).
  2. Setting up your CLASSPATH environment variable to refer to this .jar file.
For more information refer to Java Binding Configuration.