Before you start
Informix provides access to external data sources through the virtual table interface (VTI). External data sources include flat files, other databases, internet feeds, and other sources.
The VTI provides a set of hooks called purpose functions. As a developer, your task is to create an access method that implements VTI purpose functions and as many additional user-defined routines (UDRs) as necessary to access your external data source.
This tutorial shows you how to compile and run your VTI UDR as a shared library. For clarity in the examples, the VTI purpose functions reside in one source file and the auxiliary C functions reside in a separate source file. The VTI purpose functions are compiled and linked into a datablade library called tutorial.bld. The auxiliary C functions are compiled and linked into a separate shared library called libtutorial. One advantage of compiling the VTI purpose functions and the auxiliary C functions into separate libraries is that the auxiliary C functions can be used by multiple VTI libraries.
You must have the Informix server installed. This tutorial was validated with Informix versions 11.50 and 11.70. Later versions are expected to behave similarly.
You need intermediate programming skills, as well as some background with the C programming language. You need a working knowledge of how to install and configure Informix. The Informix virtual appliance is used in this tutorial to provide a common environment. You can download the Informix virtual appliance from the IBM Informix free downloads site, which is listed in the Resources section. You can also find the Informix virtual appliance by searching for IBM virtual appliances on the IBM web site. Or you can go to the IBM free downloads web page and search for Informix virtual appliance.
You can find documentation for the Informix virtual appliance in the Informix Information Center and on the appliance itself once the image is booted.
This tutorial assumes you are using Linux, but the basic concepts apply and the demo code can be ported to any system that supports Informix.
This tutorial demonstrates how to use a shared library in conjunction with the VTI. Shared libraries have the advantage that they are loaded dynamically and only when necessary. This limits your process to grow only when needed.
This tutorial also shows you how to debug UDR code that resides in a shared library. Note that the symbols in the shared library are not visible until the shared library is loaded.
The shared library in this demonstration implements a print method. This method is used to implement a trace facility for the VTI purpose functions invoked during a simple select SQL statement. You can build on this demonstration to create your own custom C library. Your customized library is available for use by VTI purpose functions and can perform any general task.
This demonstration VTI UDR shows only four of the complete set of purpose functions. The server calls a purpose function to perform well-defined tasks to access and manage your external data sources. You will need to implement all of the remaining purpose functions for a complete VTI UDR. Refer to Resources for larger, more advanced examples.

