The newly-released 32-bit Informix Client-SDK for the Mac OS X platform provides enhanced Open Database Connectivity (ODBC) capabilities, thereby enabling ODBC-aware applications to integrate seamlessly with Informix Dynamic Server (IDS).
The ODBC driver is provided as a dynamic library and as an application plug-in on Mac OS X. Developers that directly invoke the ODBC API through their applications can use the dynamic library, while Apple's ODBC data source administrator utility uses the plug-in. The product installer copies the libraries, creates the necessary configuration files, and updates the system configuration automatically.
All applications can share a single instance of the driver. Once driver configuration is complete, data sources can be added through the ODBC Administrator utility built into the operating system and made available to ODBC-aware applications, such as Microsoft® Excel and Appleâs native data source utilities, such as FileMaker Pro, OpenOffice.org, and iODBC SDK with iodbctest.
Understanding the Informix ODBC driver file types available for Mac
The bundle file: .bundle (plug-in file)
The .bundle extension is a file extension used for plug-in files that adds
extra features to the operating system or an application in Mac OS X. The
example in this article uses the bundle module of the Informix ODBC driver
(iclit09b.bundle), which was built using required Mac-specific bundling
-bundle -flat_namespace -undefined suppress.
Listing 1 shows the plug-in file format.
Listing 1. Plug-in file format
iclit09b.bundle: Mach header magic cputype cpusubtype caps filetype ncmds sizeofcmds flags MH_MAGIC_64 X86_64 ALL 0x00 BUNDLE 10 1920 DYLDLINK
The dynamic library file: .dylib (dynamic library file)
A file with .dylib extension is a dynamic library file that contains
declarations and functions a Mac OS X application references. The example
in this article uses the dynamic library module of the Informix ODBC
driver (iclit09b.dylib), which was built using the required Mac-specific
dynamic build flags
-dynamiclib -dynamic -undefined dynamic_lookup.
Listing 2 shows the dynamic library file format.
Listing 2. Dynamic library file format
iclit09b.dylib: Mach header magic cputype cpusubtype caps filetype ncmds sizeofcmds flags MH_MAGIC_64 X86_64 ALL 0x00 DYLIB 12 1976 NOUNDEFS DYLDLINK TWOLEVEL NO_REEXPORTED_DYLIBS
Distribution location of Informix ODBC Driver files on Mac OS X inside CSDK product
Both the types of Informix ODBC driver files (iclit09b.bundle and iclit09b.dylib) for CSDK Mac OS X 32-bit and CSDK Mac OS X 64-bit products are shipped together inside $INFORMIXDIR/lib/cli.
Installing and registering an ODBC driver
The Informix Client-SDK installer automatically installs and configures the Informix ODBC driver for use on Mac OS X. The process consists of two phases: installation and registration. The installation process is documented in the IBM Informix Client Products Installation Guide (see Resources). Some key points to remember:
- Registration configures the system to recognize the Informix ODBC driver.
- The driver can be installed in multiple locations on the same system.
- Only the first installation of the Informix ODBC driver is registered with the system.
In order to register the plug-in from a different location, do one of the following:
- Uninstall the registered plug-in and then install the product in the new location.
- Manually reconfigure the system to use the new location, as described later in this article.
When uninstalling the product, you have the option to retain the global INFORMIXSQLHOSTS file for future Informix client installations to use.
Figure 1. The uninstaller application prompting to remove the INFORMIXSQLHOSTS file
Configuring the system environment files and variables
The Client-SDK and Informix Connect installers configure several system files for the Informix ODBC driver.
If the product was installed into the default location /Applications/IBM/informix, the following lines are appended:
[ODBC Drivers] IBM INFORMIX ODBC DRIVER=Installed [IBM INFORMIX ODBC DRIVER] Driver=/Applications/IBM/informix/lib/cli/iclit09b.bundle Setup=/Applications/IBM/informix/lib/cli/iclit09b.bundle APILevel=1 ConnectFunctions=YYY DriverODBCVer=03.51 FileUsage=0 SQLLevel=1 smProcessPerConnect=Y
If the file does not exist, the installation application creates it.
The same configuration can be edited using the ODBC administrator utility built into Mac OS X, which is located in the Utilities folder inside the Applications folder.
Figure 2. List of Installed ODBC drivers on Mac OS X
After selecting the Informix ODBC driver and clicking Configure, a configuration dialog appears. The ODBC attributes for the Informix driver are displayed.
Figure 3. ODBC driver configuration
The location of the driver and setup files can be specified by clicking the Choose button. Figure 4 shows the selection of the file within /Applications/IBM/informix/lib/cli.
Figure 4. Browsing for the location of the driver file
The installer places a copy of the demo sqlhosts file under /etc/InformixODBC. Specify your host connection information, including server name, network protocol, host name, service, and port. Each Informix DSN needs to have a corresponding entry in this sqlhosts file. An example of such an entry might look like the information in Table 1.
Table 1. Format of the INFORMIXSQLHOSTS file
|Column 1 (IDS server name)||2 (Connection protocol)||3 (Host name)||4 (Service from /etc/services or port number)||5 (Optional connection settings)|
For a list of supported protocols, consult the Informix ODBC Programmer's Guide (see Resources).
Configuring launch services
Mac OS X applications use the Launch Services facility (launchd) to start
up. In order to load the ODBC driver successfully, the Launch Services
facility must have access to the same environment variables the driver
requires. The installer adds the following
setenv commands to the /etc/launchd.conf file.
If he file does not already exist, the installation application creates
Note: the backslashes are indicated for publication purposes only. In practice, the lines separated by a backslash must appear on a single line.
setenv INFORMIXDIR /Applications/IBM/informix setenv INFORMIXSQLHOSTS /etc/InformixODBC/sqlhosts setenv ODBCINI /Library/ODBC/odbc.ini setenv DYLD_LIBRARY_PATH /Applications/IBM/informix/lib: \ /Applications/IBM/informix/lib/cli: \ /Applications/IBM/informix/lib/esql
For more information about the launchd.conf file, see the launchd
documentation, or enter
Discovering differences between a System DSN and a User DSN and their creations
Suppose you need to create and maintain a separate set of data source definitions. Because the changes to /etc/launchd.conf affect the entire system, you need to override the system-wide ODBCINI and INFORMIXSQLHOSTS environment variables. You can do this by creating or editing a property list file within the user's home directory. For example, in order to enable user John to use the sqlhosts file and data sources defined in his home directory, perform the following steps.
- Create a file ~/.MacOSX/environment.plist in John's home directory. If a folder called .MacOSX does not exist under the home directory, create it.
- Using a text editor, enter the text in the following code section into
environment.plist. Alternatively, you can use the Property List Editor
included with the Apple Developer tools to create the file.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>INFORMIXSQLHOSTS</key> <string>/Users/John/sqlhosts</string> <key>ODBCINI</key> <string>/Users/John/Library/ODBC/odbc.ini</string> </dict> </plist>
The new settings will take effect the next time the user logs into the system.
The following sections walk through the process of enabling connectivity between an ODBC client application and a running instance of IDS.
Creating DSN and establishing connectivity with the server
Creating an Informix ODBC data source consists of entering server connection information in the /etc/InformixODBC/sqlhosts file and specifying the connection parameters within the ODBC Administrator tool. To create a data source, perform the following steps:
- If you need to set up a new server connection, open /etc/InformixODBC/sqlhosts in a text editor and add a line indicating the server connection details required to locate the database server, as described in the INFORMIXSQLHOSTS section. This file is present on the file system only after Client-SDK or I-Connect have been installed.
- Launch the ODBC Administrator tool, by selecting Applications
Figure 4. The System DSN tab
- Click the System DSN tab, and then click the Add
Figure 5. Driver selection dialog box
- Select IBM INFORMIX ODBC DRIVER, and click OK.
Figure 6. Enter a Data Source Name and optional description
- Enter a name for this data source and, optionally, a description. Click OK.
- Click the Add button. A new row appears in the table with the words Key and Value.
- Click Key twice to edit it. Type in UID, and press Enter.
- Click Value twice to edit it. Type in the name of the login
user that will be used to connect to the database.
Figure 7. Enter the user name to be used for connections
- Repeat steps 6 through 8 to add PWD (password), Database, and
ServerName to the data source. The entries are case-sensitive.
Figure 8. All connection parameters specified
- Click OK, and then exit the ODBC Administrator application. The data source is ready to use.
Testing data source connectivity
If you have the iODBC SDK installed, you can use the OpenLink ODBC Administrator application to test your data source. Data sources created using the Apple ODBC Administrator will also appear. Follow these steps to test the data source:
- Highlight the data source to test.
- Click the Test button.
- Enter the database username and password. The OpenLink ODBC Administrator informs you whether the connection was successful.
Figure 9. Connection through OpenLink ODBC Administrator successful
Mac OS X comes with a command-line utility called iodbctest you can use to test ODBC drivers and data sources. The following set of steps describes how to use iodbctest to verify the DSN created above.
- Launch the Terminal application.
- Set the INFORMIXDIR, INFORMIXSQLHOSTS, ODBCINI, and
DYLD_LIBRARY_PATH variables (if not already set). The commands for
to use bash, ksh, and other Bourne-compatible shells are:
export INFORMIXDIR=<substitute path to your Client SDK installation here> export INFORMIXSQLHOSTS=/etc/InformixODBC/sqlhosts export ODBCINI=/Library/ODBC/odbc.ini export DYLD_LIBRARY_PATH=$INFORMIXDIR/lib:$INFORMIXDIR/lib/cli:$INFORMIXDIR/lib/esql
To commands to use csh and other C-shell compatible shells are:
setenv INFORMIXDIR <substitute path to your Client SDK installation here> setenv INFORMIXSQLHOSTS /etc/InformixODBC/sqlhosts setenv ODBCINI /Library/ODBC/odbc.ini setenv DYLD_LIBRARY_PATH $INFORMIXDIR/lib:$INFORMIXDIR/lib/cli:$INFORMIXDIR/lib/esql
- Type iodbctest and press Enter.
- When asked for the DSN connection string, enter
DSN=storedemo;UID=informix;PWD=<informix_password>;ServerName=demo_on, replacing <informix_password> with the actual password for the Informix user account. The UID, PWD, and ServerName parameters are optional. The driver version and an SQL prompt appear.
- Enter an SQL statement, such as
select * from customer. The results are displayed, as shown in Figure 10.
Figure 10. Output from iodbctest
- Type exit, and press Enter to close the connection and iodbctest.
Applied connectivity using FileMaker Pro and OpenOffice.org
In Part 2 of this series, you can see walkthroughs of Informix CSDK ODBC connectivity using FileMaker Pro and OpenOffice.org tools.
This article demonstrated how to use the new Mac OS X ODBC features available with Informix Client-SDK and Connect 3.50.xC3. Full integration with the native Apple ODBC framework makes connecting native Mac OS X applications to IBM Informix Dynamic Server as straightforward and simple as point-and-click.
- Continue with Part 2 to see walkthroughs of Informix CSDK ODBC connectivity using FileMaker Pro and OpenOffice.org tools.
- Connect to Runtime Configuration Guidelines for more Mac OS X documentation.
- Refer to Launch Services Reference to get more details on the Mac OS X Launch Services API.
- Visit the developerWorks Informix page to read articles and tutorials and connect to other resources to expand your Informix skills.
- Learn more about Informix at the IBM Informix Dynamic Server 11 Information Center.
- Learn more about Information Management at the developerWorks Information Management zone. Find technical documentation, how-to articles, education, downloads, product information, and more.
- Stay current with developerWorks technical events and webcasts.
Get products and technologies
- Download a free trial version of Informix Dynamic Server.
- Build your next development project with IBM trial software, available for download directly from developerWorks.
- Participate in the discussion forum.
- Check out the developerWorks blogs and get involved in the developerWorks community.