Creating New DBA technology
Home Features Presentations Download Purchase Company
Simple C++ Application Program Interface (API) for Oracle

Classes encapsulate powerful but very complex OCI (Oracle Call Interface) functions for easy C++ coding. Require Oracle Client.

DBConnect class includes function for connecting to database and disconnecting from it.

DBStmt class includes function for statement preparing, bind, define variables and fetch data. Extended possibilities is defining count of columns in result set, defining its data types and find position of error in SQL statement. Exception Classes control runtime errors.

 

Examples

Connect to Oracle Database

 

#include "OraCall.h"

 

      DBConnect * OraConnect = new DBConnect;

 

      try

      {

            OraConnect->Connect(Username,Password,ConnectString);

      }

      catch(DBConnect::OtherException)

      {

            AfxMessageBox(OraConnect->GetErrorText());

      }

      //...

 

      delete OraConnect;

 

Simple select statement. Error control on execution step.

     

      #include "OraCall.h"

 

      char ObjectName[31];

      //...

 

      char * GetObjectTypeStatement = "SELECT OBJECT_TYPE FROM USER_OBJECTS WHERE OBJECT_NAME = :1";

      char ObjectType[31];

      DBStmt GetObjectType(OraConnect,GetObjectTypeStatement);

             GetObjectType.Bind(1,ObjectName,strlen(ObjectName));

             GetObjectType.DefineStr(1,ObjectType,31);

 

      try

      {

            GetObjectType.Do();

      }

      catch(DBStmt::OtherException)

      {

            AfxMessageBox(GetObjectType.GetErrorText());

            OraConnect->Reset();

            return;

      }

      //...

 

Fetch data in a loop. Using pointer for cursor object.

     

      #include "OraCall.h"

 

      char * GetObjectNameStatement = "SELECT OBJECT_NAME FROM USER_OBJECTS";

      char ObjectName[31];

 

      DBStmt * GetObjectName = new DBStmt;

 

      try

      {

            GetObjectName->Prepare(OraConnect,GetObjectNameStatement);

            GetObjectName->DefineStr(1,ObjectName,31);

      }

      catch(DBStmt::OtherException)

      {

            AfxMessageBox(GetObjectName->GetErrorText());

            OraConnect->Reset();

            return;

      }

 

      for (;;)

      {

            try

            {

                  GetObjectName->Fetch();

            }

            catch(DBStmt::OtherException)

            {

                  if (GetObjectName->GetErrorCode() == NO_DATA_FOUND)

                  {

                        OraConnect->Reset();

                        break;

                  }

                  else

                  {

                        AfxMessageBox(GetObjectName->GetErrorText());

                        OraConnect->Reset();

                        return;

                  }

            }

           

            //...

      }

   

Sources

Source code is free for use and distribute. Files are provided "as is" with no expressed or implied warranty.

Download

 
www.dbaeasy.com   Copyright © DBA Inventions Ltd. 2007 All Rights Reserved.