C/C++/Perl DCOM/MTS CORBA XML UNIX Windows NT links


[ Home ]  [ oci_tl Home ] [ Back ]

 

oci_tl Library Home - program sample


Sample program:


#include "iostream"
using namespace std;

#include "oci_tl.h"
using namespace ina_lib;

//declare environment
oci_env env;

//declare database (connection)
oci_db db(env);

//queryes see "test.pkg" and "test.pkb" files
const char select_query[]="select * from emp";
const char func_query[]="begin :retval:=test.test_func(:par1,:par2); end;";
const char func_cursor_query[]="begin :retval:=test.test_cursor_func(:par1,:cur1); end;";

void func1()
{
    cout<<"*************************"<<endl;
    cout<<"Select query"<<endl;

    //string variable declaration
    oci_var_string<50> var1,var2,var3,var4;

    //declaring stream (cursor)
    oci_stream str(db);

    //parsing query
    str.parse(select_query);

    //execute query
    str.execute();

    //bind output variables
    str>>var1>>var2>>var3>>var4;

    //fetching resultset
    while(str.fetch())
    {
        cout<<var1.c_str()
            <<":"<<var2.c_str()
            <<":"<<var3.c_str()
            <<":"<<var4.c_str()
            <<endl;
    }

}

void func2()
{
    cout<<"*************************"<<endl;
    cout<<"Test function"<<endl;
	
    //int variable declaration
    oci_var_int var1(":par1"),var2(":par2"),retval(":retval");

    //declaring stream (cursor)
    oci_stream str(db);

    //parsing query
    str.parse(func_query);

    //assigning value
    var1=34;

    //binding variables
    str<<var1<<var2<<retval;

    //execute query
    str.execute();

	//don't have to fetch
    cout<<var1.i_val()
        <<":"<<var2.i_val()
        <<":"<<retval.i_val()
        <<endl;
}

void func3()
{
    cout<<"*************************"<<endl;
	cout<<"Test function - cursor binding"<<endl;

    //int variable declaration
    oci_var_int par1(":par1"),retval(":retval");

    //declaring stream (cursor) to bind
    oci_stream cur1(db,":cur1");

    //output variable declaration
    oci_var_string<> var1,var2,var3,var4;

    //declaring stream (cursor)
    oci_stream str(db);

    //parsing query
    str.parse(func_cursor_query);

    par1=7777;

    //binding variables
    str<<par1<<cur1<<retval;

    //execute query
    str.execute();

    //binding variables to cursor we got
    cur1>>var1>>var2>>var3>>var4;

    //fetching resultset
    while(cur1.fetch())
    {
        cout<<var1.c_str()
            <<":"<<var2.c_str()
            <<":"<<var3.c_str()
            <<":"<<var4.c_str()
            <<endl;
    }


}

int main(int argc, char* argv[])
{
    try
    {
        //login to database
        db.login("SCOTT","TIGER","ORCL");
        
        //function execution
        func1();
        func2();
        func3();
        
        //logout from database
        db.logout();
    }
    //exception handling
    catch(oci_tl_exception& ex)
    {
        cerr<<ex.what()<<endl;
    }
    catch(...)
    {
        cerr<<"Another Error"<<endl;
    }
    return 0;
}

 

 

 [ Home ]  [ oci_tl Home ] [ Back ]

[ Top ]


Vasiliy Astapov (c) 2001.  To send me e-mail click here