Codwiz51's Wiki

Oracle Template Library (OTL)

Modified: 2008/07/19 06:25 by codewiz51 - Categorized as: Oracle XE, OTL
One of my favorite programming tools for C++ and Oracle is the Oracle Template Library. This is a really nice template library that let's you start using Oracle very quickly. No ADO or DAO or ADO.NET required. Excellent documentation. How's this for some quick coding? It's a rip off of one of the examples, but it illustrates the simplicity:

#include <iostream>
using namespace std;

#include <stdio.h>

// include the OTL 4.0 header file #include <otlv4.h>

// Declare the connect object otl_connect db;

int main() { // initialize OCI environment otl_connect::otl_initialize();

try{

// connect to Oracle db.rlogon("admin/P@ssw0rd1@XE");

// Disable exceptions just in case the table test_tab // does not exist. otl_cursor::direct_exec ( db, "drop table test_tab", otl_exception::disabled );

// Recreate the table otl_cursor::direct_exec ( db, "create table test_tab(f1 number, f2 varchar2(30))" );

// Drop the table otl_cursor::direct_exec ( db, "drop table test_tab" );

}

// intercept OTL exceptions catch(otl_exception& p){ // print out error message cerr << p.msg << endl; // print out SQL that caused the error cerr << p.stm_text << endl; // print out the variable that caused the error cerr << p.var_info << endl; }

// disconnect from Oracle db.logoff();

return 0;

}

I hope you appreciate how simple this coding is. No bloated Microsoft libraries are utilized. It's simple. If you've ever tried to program with Oracle Call Interface directly, you'll appreciate the object oriented C++ interface this template library provides.

ScrewTurn Wiki version 2.0.31. Some of the icons created by FamFamFam.