The following sample illustrates importing data from an Oracle Spatial database to a project drawing. It is in two parts. First, it defines a query to specify a condition for the objects to import, and then it imports them.
Note The sample assumes that there is an open project drawing, and that an import query has been defined already through the Import dialog box in the UI (choose Map > OracleSpatial > ImportObjectsFromOracle). It also assumes that the connection object is actually connected to a database. Click "Connecting to an Oracle Spatial Database" for sample code.
Connecting to an Oracle Spatial Database (sample)
Querying and importing data (overview)
Related samples
#include "StdAfx.h"
#include "StdArx.h"
#include "AcMapOracleConnection.h"
#include "AcMapOracleQuery.h"
#include "AcMapOracleImport.h"
BOOL ImportFromOracle()
{
// Get the connection object
AcMapOracleConnection *pConnection = AcMapOracleGetConnection();
/*********************/
/******* Query *******/
// Instantiate a query object
AcmapOracleQuery *pQuery =
new AcMapOracleQuery(pConnection);
// Initialize query object with current import query,
// which has been defined already through the UI
pQuery->InitWithCurrent(
acdbHostApplicationServices()->workingDatabase());
// Or initialize query with specific condition
pQuery->Init("EntityType = 'AcDbCircle'");
// You can check the whole query by
// using ConvertToSql function
char *pSql = pQuery->ConvertToSql();
acutPrintf("\nQuery in SQL format:%s", pSql);
// Save the query to the Oracle Spatial database
pQuery->Save("MyQuery");
// Load the saved query in a new query object
AcMapOracleQuery *pNewQuery =
new AcMapOracleQuery(pConnection);
pNewQuery->Load("MyQuery");
// Compare old and new query
char *pNewSql = pNewQuery->ConvertToSql();
if(strcmp(pSql, pNewSql) == 0)
acutPrintf("Query Load/Save works!!\n");
else
acutPrintf("Query Load/Save failed!!\n");
/**********************/
/******* Import *******/
// Instantiate an import object
AcMapOracleImport *pImport =
new AcMapOracleImport(pConnection);
// Use the query object defined above to
// import Oracle Spatial data
if(pImport->CheckImport())
{
if(pImport->Import(pQuery, false))
acutPrintf("\nImported successfully\n");
else
acutPrintf("\nImport failed\n");
}
else
acutPrintf("\nCheckImport() failed, can not import!\n");
}