IBM®
Skip to main content
    Country/region [select]      Terms of use
 
 
      
     Home      Products      Services & solutions      Support & downloads      My account     

developerWorks > DB2 >
developerWorks
Informix flat-file access
Downloade-mail it!
Contents:
Introduction
Accessing an External File
Directory content
Installation
Testing
Tracing
Download
About the author
Rate this article
Subscriptions:
dW newsletters
dW Subscription
(CDs and downloads)

Level: Introductory

Jacques Roy
IBM Worldwide Sales Support, IBM Corporation
27 Apr 2001

This demo creates an Informix DataBlade that implements an access method for building virtual tables based on operating system files. Includes source code.

Introduction
This primary access method (FFAccess) implements a read-only interface to make external files look like tables in the server. The types supported are:

boolean, char, date, datetime, decimal, float, int8, integer, interval, lvarchar, money, nchar, nvarchar, smallfloat, smallint, varchar

This includes any distinct types based on these types.

Accessing an External File
An external file is identified in a CREATE TABLE statement. For example:


 CREATE TABLE mytab (
   a BOOLEAN,
   b VARCHAR(20),
   c DATE,
   d DATETIME year to second,
   e DECIMAL,
   f DOUBLE PRECISION,
   g SMALLFLOAT,
   h INT8
 ) USING FFAccess (path='/tmp/mytab.txt', delim=';');
  

The last part of the statement identifies the access method used, followed by arguments to the access method that includes the path to the external file and the delimiter used in the file to separate columns. The default separator is ':'.

An external dbspace could also be used as the external file by using the "IN" keyword in the CREATE TABLE statement.

Once the table is created it can be used in any SELECT statements including joining with existing tables.

Directory content

ffvti.cSource code for the flat-file access method
ffutil.cSource code for utility functions for the flat-file access method
ffvti.defExported names for an NT DLL
ffvti.hInclude file for ffvti.c and ffutil.c
ffvti.sqlSQL script used to create the access method
ffvti_d.sqlSQL script used to remove all traces of the access method
MakefileGeneric UNIX makefile that creates the shared library
(Change line 2 identifying the TARGET include file)
README.txtThis file
tab.txtTest file
tryit.sqlTest script
WinNT.makNT makefile used to create the DLL (requires Visual C++)

Installation
You should install the content of this directory under $INFORMIXDIR/extend/ffvti

Once the shared library (or DLL) is created, move it from the bin directory to the top directory ($INFORMIXDIR/extend/ffvti). Then, execute ffvti.sql in the database that requires this access method. At this point you can create tables that access external files as shown above.

Testing
To test the access method, you can use the tryit.sql script. You first need to copy the tab.txt file to the /tmp directory.

Tracing
The source code contains tracing statement. To enable tracing in your current session, execute the following statement:


 EXECUTE FUNCTION set_tracing("ffvti", 50, "
 $INFORMIXDIR/extend/ffvti/trace.out");
   

For trace to be active, you must compile the source without the MITRACE_OFF flag


IBM, DB2, Informix, and WebSphere are trademarks or registered trademarks of IBM Corporation in the United States, other countries, or both.

Windows and Windows NT are registered trademarks of Microsoft Corporation in the United States, other countries, or both.

Java and all Java-based trademarks and logos are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States, other countries, or both.

Other company, product, and service names may be trademarks or service marks of others.

IBM copyright and trademark information

Download
NameSizeDownload method
ffvti.zip12 KBFTP|HTTP
*Information about download methods
About the author
Jacques Roy is a member of IBM's worldwide sales support organization.


Downloade-mail it!
Rate this article

This content was helpful to me:

Strongly disagree (1)Disagree (2)Neutral (3)Agree (4)Strongly agree (5)

Comments?



developerWorks > DB2 >
developerWorks
    About IBM Privacy Contact