Using Oracle Template Library and CodeGen 'lite'
This page describes a streamlined approach to accessing Oracle data using Sergei Kuchins excellent Oracle Template Library (OTL). I have personally found conventional Oracle Call Interface (OCI) programming to be tedious and ugly, Sergei has done a great job of wrapping this library into what he terms an 'appliance', where i/o is done with otl_streams. An otl_stream is much like any other i/o stream, except it is opened with SQL to be run against the server, and data is shunted back and forth using the >> and << operators.
Lets assume you have an existing Oracle database schema which contains a table named FILESET:
SQL> desc FILESET;
Name Null? Type
------------------------------- -------- ----
FILESET_NAME VARCHAR2(128)
DS_NAME_ID NUMBER(38)
TAPE_LABEL VARCHAR2(128)
TAPE_PARTITION NUMBER(38)
CREATE_TIME NUMBER(38)
FILE_COUNT NUMBER(38)
SQL>
- Define a c++ structure like FilesetStruct.dat which will be used as input to the code generation step. Right now the code generator only accepts simple types such as (strings, longs, doubles, ints, and floats), which correspond to the most common database datatypes of (varchar, int, int, float, float) or if you've been using Oracle too long to remember standard SQL, (varchar2, number,number,number,number).
- Use the perl script makeRaw.pl to generate a C++ class FilesetStruct.hh which uses OTL operators >> and << to do I/O from an oracle database.
From the command line:
makeRaw.pl FilesetStruct.dat > FilesetStruct.hh
- Use the perl script makeHarness.pl to generate a C++ test harness program FilesetStruct.Harness.cc which excercises the above class.
From the command line:
makeHarness.pl FilesetStruct.dat > FilesetStruct.Harness.cc
- You will also need otl8.hh to compile, link, and run.....
- The example Makefile and its associated include file arch_spec_otl.mk have been tested successfully under the following environments:
- KAI C++ compiler
- Gnu Make
- Oracle 8.0.5
- Linux 2.0.36, SunOS 5.6, and IRIX 6.5
- To Do:
- a script that takes oracle 'desc' output and generates the .dat structure would be nice
- Translate the above scripts into python....Why??? do you ask???
Dennis Box
Last modified: Fri Dec 10 18:03:36 CST 1999