Connecting to an Oracle Spatial Database: code sample

Land Desktop Development ARX CPP SDK

 

Connecting to an Oracle Spatial Database

The following code sample illustrates connecting to an Oracle Spatial database and adding custom reactors. Custom reactor declarations are in MyMapOracleReactors.h, one of the files included at the beginning of the sample. The "Subclassing Custom Reactors" sample shows what such a file would contain.

#include "StdAfx.h"
#include "StdArx.h"
#include "AcMapOracleConnection.h"
#include "MyMapOracleReactors.h"      // Custom reactors

BOOL ConnectToOracle()
{

// Get the connection object
AcMapOracleConnection *pConnection = AcMapOracleGetConnection();

// Initialize reactors
// Custom reactor types are declared in MyMapOracleReactors.h
MyConnectionReactor *pConnectReactor = new MyConnectionReactor();
MyExportReactor *pExportReactor = new MyExportReactor();
MyImportReactor *pImportReactor = new MyImportReactor();

// Add reactors to connection class
pConnection->AddConnectionReactor(pConnectReactor);
pConnection->AddExportReactor(pExportReactor);
pConnection->AddImportReactor(pImportReactor);

BOOL bConnect = FALSE;

// If no database is connected, connect one
if(!pConnection->IsConnected())
{
   bConnect = pConnection->Connect("Scott","TestDB","Scott","Tiger");
}
else
{
   acutPrintf("Already connected to Oracle!!");
   return FALSE;
}

// Check if schema is valid
if(bConnect)
{
   if(pConnection->IsSchemaValid())
      acutPrintf("\nSchema is valid for this connection\n");
   else
      acutPrintf("\nSchema is not valid\n");
}

// Get the service name
char *pService = 0;
pService = new char[80];

pService = pConnection->Service();
acutPritnf("\nService is %s\n", pService);

delete [] pService;

// Get the schema name
char *pSchema = 0;
pSchema = new char[80];

pSchema = pConnection->Schema();
acutPrintf("\nSchema is %s\n", pSchema);

delete [] pSchema;

// Get the user name
char *pUserName = 0;
pUserName = new char[80];

pUserName = pConnection->UserName();
acutPrintf("\nUserName is %s\n", pUserName);

delete [] pUserName;

// Disconnect the database
if(pConnection->Disconnect())
   acutPrintf("\nDisconnected successfully from Oracle\n");
else
   acutPrintf("\nError disconnecting from Oracle\n");

//Remove reactors from connection interface
pConnection->RemoveConnectionReactor(pConnectReactor);
pConnection->RemoveExportReactor(pExportReactor);
pConnection->RemoveImportReactor(pImportReactor);

}