Connecting to an Oracle Spatial Database

AutoCAD Map 3D ObjectARX

 
Connecting to an Oracle Spatial Database
 
 
 

The following code sample illustrates connecting to an Oracle 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.

Managing the Connection (Overview) Subclassing Custom Reactors (Sample) Other Related Samples

#include "StdAfx.h"
#include "StdArx.h"
#include "AdMapOracleConnection.h"
#include "MyMapOracleReactors.h"   // Custom reactors
      
BOOL ConnectToOracle()
{
        
// Get connection pointer
AcMapOSEConnection *pConnection = AcMapOSEGetConnection();
        
// Initialize reactors
MyConnectionReactor *pConnectReactor = new MyConnectionReactor();
MyExportReactor *pExportReactor = new MyExportReactor();
MyImportReactor *pImportReactor = new MyImportReactor();
        
// Add reactors to connection object
pConnection->AddConnectionReactor(pConnectReactor);
pConnection->AddExportReactor(pExportReactor);
pConnection->AddImportReactor(pImportReactor);
        
// Make the connection
BOOL bConnect = FALSE;
        
if(!pConnection->IsConnected())
{
bConnect = pConnection->Connect("Scott", "TestDB", "Scott", "Tiger", false);
}
else
{
acutPrintf("Already connected to Oracle!");
return FALSE;
}
        
// Check for valid connection using various diagnostic functions
        
// Check if schema is valid()
if(pConnection->IsSchemaValid())
{
acutPrintf("\nSchema is valid for this connection\n");
}
else
{
acutPrintf("\nSchema is not valid\n");
}
        
// Get the latest state of the Oracle database if it has been 
// changed since the connection was made 
if(pConnection->RefreshSchema())
{
acutPrintf("\nSchema refreshed\n");
}
else
{
acutPrintf("\nError refreshing schema\n"):
}
        
// Get a list of the feature names in the current schema
std::vector<std::string> vFeatureNames;
if(pConnection->Features(vFeatureNames))
{
acutPrintf("\nGot feature names\n");
}
else
{
acutPrintf("\nError getting feature names\n");
}
        
// Get the service name
char *pService = 0;
pSerive = new char[80];
        
strcpy(pService, pConnection->Service());
acutPritnf("\nService is %s\n",pService);
        
delete [] pService;
        
// Get the schema name
char *pSchema = 0;
pschema = new char[80];
        
strcpy(pSchema,pConnection->Schema());
acutPritnf("\nSchema is %s\n",pSchema);
        
delete [] pSchema;
        
// Get the user name
char *pUserName = 0;
pUserName = new char[80];
        
strcpy(pUserName,pConnection->UserName());
acutPritnf("\nUserName is %s\n",pUserName);
        
delete [] pUserName;
        
// Break the connection
if(pConnection->Disconnect())
acutPritnf("\nDisconnected from Oracle\n");
else  
acutPritnf("\nError disconnecting from Oracle\n");
        
// Remove reactors from connection interface
pConnection->RemoveConnectionReactor(pConnectReactor);
pConnection->RemoveExportReactor(pExportReactor);
pConnection->RemoveImportReactor(pImportReactor);
        
delete pConnectReactor
delete pExportReactor
delete pImportReactor
}