Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Announcement: One-page C++ Oracle API
Hi All,
I'd like to introduce the Oracle Call Interface Template Library (OTL), Version 2.0.0. OTL provides incredibly simple (see for yourself!) and powerful C++ Oracle API (see examples below) via the SQL stream. It works with both native OCI7 and native OCI8. Also, it has STL-compliant (http://www.sgi.com/Technology/STL/Iterators.html) iterators that bring the power of generic programming to Oracle applications developers. OTL is a Freeware package.
Take a closer look at:
http://home.sprynet.com/sprynet/skuchin/otl_1pg.htm
Feel free to contact me at skuchin_at_sprynet.com
Thank you,
Sergei Kuchin
Source code
#include <iostream.h>
#include <stdio.h>
#include <otl.h>
otl_connect db; // connect object
void insert()
// insert rows into table
{
otl_stream o(50, // buffer size
"insert into test_tab values(:f1<float>,:f2<char[31]>)", // SQL statement db // connect object );
for(int i=1;i<=100;++i){
sprintf(tmp,"Name%d",i);
o<<(float)i<<tmp;
}
} /* insert */
void select()
{
otl_stream i(50, // buffer size
"select * from test_tab where f1>=:f<int> and f1<=:f*2", // SELECT statement db // connect object );
int f1;
char f2[31];
i<<8; // assigning :f = 8
// SELECT automatically executes when all input variables are
// assigned. First portion of out rows is fetched to the buffer
while(!i.eof()){ // while not end-of-data
i>>f1>>f2;
cout<<"f1="<<f1<<", f2="<<f2<<endl;
}
i<<4; // assigning :f = 4
// SELECT automatically re-executes when all input variables are
// assigned. First portion of out rows is fetched to the buffer
while(!i.eof()){ // while not end-of-data
i>>f1>>f2;
cout<<"f1="<<f1<<", f2="<<f2<<endl;
}
} /* select */
int main()
{
otl_connect::otl_initialize(); // initialize OCI environment
try{
db.rlogon("scott/tiger"); // connect to Oracle
otl_cursor::direct_exec
(
db,
"drop table test_tab",
otl_exception::disabled // disable OTL exceptions
); // drop table
otl_cursor::direct_exec
(
db,
"create table test_tab(f1 number, f2 varchar2(30))"
); // create table
insert(); // insert records into table select(); // select records from table
}
catch(otl_exception& p){ // intercept OTL exceptions cerr<<p.msg<<endl; // print out error message cerr<<p.stm_text<<endl; // print out SQL that caused the error }
db.logoff(); // disconnect from Oracle
return 0;
} /* main */
Output
f1=8, f2=Name8 f1=9, f2=Name9 f1=10, f2=Name10 f1=11, f2=Name11 f1=12, f2=Name12 f1=13, f2=Name13 f1=14, f2=Name14 f1=15, f2=Name15 f1=16, f2=Name16 f1=4, f2=Name4 f1=5, f2=Name5 f1=6, f2=Name6 f1=7, f2=Name7 f1=8, f2=Name8 =============== EXAMPLE 2 (with PL/SQL block) ========================
Source code
#include <iostream.h>
#include <stdio.h>
#include <otl.h>
otl_connect db; // connect object
void plsql()
// invoking PL/SQL block
{
otl_stream o(5, // buffer size
"begin " " :A<int,inout> := :A+1; " " :B<char[31],out> := :C<char[31],in>; " "end;", // PL/SQL block db // connect object ); o<<1<<"Test String1"; // assigning :A = 1, :C = "Test String1"o<<2<<"Test String2"; // assigning :A = 2, :C = "Test String2" o<<3<<"Test String3"; // assigning :A = 3, :C = "Test String3"
o.flush(); // executing PL/SQL block 3 times
int a;
char b[32];
while(!o.eof()){ // not end-of-data
o>>a>>b;
cout<<"A="<<a<<", B="<<b<<endl;
}
} /* plsql */
int main()
{
otl_connect::otl_initialize(); // initialize OCI environment
try{
db.rlogon("scott/tiger"); // connect to Oracle
plsql(); // invoking PL/SQL block
}
catch(otl_exception& p){ // intercept OTL exceptions
cerr<<p.msg<<endl; // print out error message
cerr<<p.stm_text<<endl; // print out SQL that caused the error
}
db.logoff(); // disconnect from Oracle
return 0;
} /* main */
Output
A=2, B=Test String1 A=3, B=Test String2 A=4, B=Test String3
Source code
#include <iostream.h>
#include <stdio.h>
#include <otl.h>
otl_connect db; // connect object
void insert()
// insert rows into table
{
otl_stream o(50, // buffer size
"insert into test_tab values(:f1<int>,:f2<char[31]>)", // SQL statement db // connect object );
for(int i=1;i<=100;++i){
sprintf(tmp,"Name%d",i);
o.printf("%d %s",i,tmp); // write one row into stream
}
} /* insert */
void select()
{
otl_stream i(50, // buffer size
"select * from test_tab where f1>=:f<int> and f1<=:f*2", // SELECT statement db // connect object );
int f1;
char f2[31];
i<<8; // assigning :f = 8
// SELECT automatically executes when all input variables are
// assigned. First portion of out rows is fetched to the buffer
while(!i.eof()){ // while not end-of-data
i.scanf("%d %s",&f1,f2); // read one row from stream
cout<<"f1="<<f1<<", f2="<<f2<<endl;
}
i<<4; // assigning :f = 4
// SELECT automatically re-executes when all input variables are
// assigned. First portion of out rows is fetched to the buffer
while(!i.eof()){ // while not end-of-data
i.scanf("%d %s",&f1,f2); // read one row from stream
cout<<"f1="<<f1<<", f2="<<f2<<endl;
}
} /* select */
int main()
{
otl_connect::otl_initialize(); // initialize OCI environment
try{
db.rlogon("scott/tiger"); // connect to Oracle
otl_cursor::direct_exec
(
db,
"drop table test_tab",
otl_exception::disabled // disable OTL exceptions
); // drop table
otl_cursor::direct_exec
(
db,
"create table test_tab(f1 number, f2 varchar2(30))"
); // create table
insert(); // insert records into table select(); // select records from table
}
catch(otl_exception& p){ // intercept OTL exceptions cerr<<p.msg<<endl; // print out error message cerr<<p.stm_text<<endl; // print out SQL that caused the error }
db.logoff(); // disconnect from Oracle
return 0;
} /* main */
Output
f1=8, f2=Name8 f1=9, f2=Name9 f1=10, f2=Name10 f1=11, f2=Name11 f1=12, f2=Name12 f1=13, f2=Name13 f1=14, f2=Name14 f1=15, f2=Name15 f1=16, f2=Name16 f1=4, f2=Name4 f1=5, f2=Name5 f1=6, f2=Name6 f1=7, f2=Name7 f1=8, f2=Name8
Source code
#include <iostream.h>
#include <stdio.h>
#include <otl.h>
otl_connect db; // connect object
void insert()
// insert rows into table
{
otl_stream o(50, // buffer size
"insert into test_tab values(:f1<float>,:f2<char[31]>)", // SQL statement db // connect object );
for(int i=1;i<=100;++i){
sprintf(tmp,"Name%d",i);
o<<(float)i<<tmp;
}
} /* insert */
void select()
{
otl_stream i(50, // buffer size
"begin " " open :cur for " " select * " " from test_tab " " where f1>=:f<int> and f1<=:f*2; " "end;", // PL/SQL block returns a referenced cursor db, // connect object ":cur" // referenced cursor placeholder name );
int f1;
char f2[31];
i<<8; // assigning :f = 8
// SELECT automatically executes when all input variables are
// assigned. First portion of out rows is fetched to the buffer
while(!i.eof()){ // while not end-of-data
i>>f1>>f2;
cout<<"f1="<<f1<<", f2="<<f2<<endl;
}
i<<4; // assigning :f = 4
// SELECT automatically re-executes when all input variables are
// assigned. First portion of out rows is fetched to the buffer
while(!i.eof()){ // while not end-of-data
i>>f1>>f2;
cout<<"f1="<<f1<<", f2="<<f2<<endl;
}
} /* select */
int main()
{
otl_connect::otl_initialize(); // initialize OCI environment
try{
db.rlogon("scott/tiger"); // connect to Oracle
otl_cursor::direct_exec
(
db,
"drop table test_tab",
otl_exception::disabled // disable OTL exceptions
); // drop table
otl_cursor::direct_exec
(
db,
"create table test_tab(f1 number, f2 varchar2(30))"
); // create table
insert(); // insert records into table select(); // select records from table
}
catch(otl_exception& p){ // intercept OTL exceptions cerr<<p.msg<<endl; // print out error message cerr<<p.stm_text<<endl; // print out SQL that caused the error }
db.logoff(); // disconnect from Oracle
return 0;
} /* main */
Output
f1=8, f2=Name8 f1=9, f2=Name9 f1=10, f2=Name10 f1=11, f2=Name11 f1=12, f2=Name12 f1=13, f2=Name13 f1=14, f2=Name14 f1=15, f2=Name15 f1=16, f2=Name16 f1=4, f2=Name4 f1=5, f2=Name5 f1=6, f2=Name6 f1=7, f2=Name7 f1=8, f2=Name8Received on Wed Aug 19 1998 - 21:09:38 CDT
![]() |
![]() |