Exporting to an Oracle Spatial Database
The following code sample illustrates exporting spatial data from a project drawing to an Oracle database.
Note The sample assumes an open project drawing
containing some objects. It also assumes that the connection object
is actually connected to a database. Click "Connecting to an Oracle
Database" for sample code.
#include "StdAfx.h"
#include "StdArx.h"
#include "AdMapOracleConnection.h"
#include "AdMapOracleExport.h"
BOOL ExportToOracle()
{
// Get connection pointer
AcMapOSEConnection *pConnection = AcMapOracleGetConnection();
// Declare export interface
AcMapOSEExport *pExport = new AcMapOSEExport(pConnection);
// Note: Before calling export functions, initialize the
// export interface to specify export options and which
// features to export
// Export Option 1 - Export only new objects and erase
// exported objects from the drawing
// Empty feature vector means export all features in the
// drawing database when you call export functions
std::vector<std::string> vFeatureNames;
// Initialize
if(pExport->Init(vFeatureNames, kRemoveExported))
{
acutPrintf("\nInit() successful\n");
// Export
AcDbDatabase *pDwg;
// Get a valid drawing database reference for *pDwg
// ... (add code here)
if(pExport->ExportObjectsAll(pDwg))
{
acutPrintf("\nExport successful\n");
}
else
{
acutPrintf("\nExport failed\n");
}
}
else
{
acutPrintf("\nExport->Init() failed\n");
}
// Export Option 2 - Export selected features, update
// modified objects in Oracle, and delete erased objects
// from Oracle
vFeatureNames.push_back("Feature1");
vFeatureNames.push_back("Feature2");
// Initialize
if(pExport->Init(vFeatureNames,
AcMapOSEExport::kUpdateModified |
AcMapOSEExport::kUpdateErased |
AcMapOSEExport::kRemoveExported))
{
acutPrintf("\nInit() successful\n");
// Export
if(pExport->ExportObjectsAll(pDwg))
{
acutPrintf("\nExport successful\n");
}
else
{
acutPrintf("\nExport failed\n");
}
}
else
{
acutPrintf("\nExport->Init() failed\n");
}
// Export Option 3 - Export a specific set of objects
// Initialize - see initializing code samples above
// Export
AcDbObjectIdArray idArray;
// Populate idArray with a set of objects to export by
// manually selecting or iterating through the drawing
// database
// ... (add code to populate idArray)
if(pExport->ExportObjects(idArray);
{
acutPrintf("\nExport successful\n");
}
else
{
acutPrintf("\nExport failed\n");
}
delete pExport;
}