Importing from an Oracle Spatial Database
Importing from an Oracle Spatial Database
The following sample illustrates importing spatial data from an Oracle database to a project drawing.
The sample 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 (use the MAPOSEREAD command).
It also assumes that the connection object is actually connected
to a database. Click "Connecting to an Oracle Database" for sample
code.
Connecting to an Oracle Spatial Database
#include "StdAfx.h"#include "StdArx.h"#include "AdMapOracleConnection.h"#include "AdMapOracleQuery.h"#include "AdMapOracleImport.h"BOOL ImportFromOracle(){// Define Query// Get connection pointerAcMapOSEConnection *pConnection = AcMapOSEGetConnection();// Declare query interfaceAcmapOSEQuery *pQuery = new AcMapOSEQuery(pConnection);// Initialize query interface with the current import query// (defined through the user interface) of an open project// drawing; in this case, the current project drawingpQuery->InitWithCurrent(acdbHostApplicationServices()->workingDatabase());// Or initialize with a NULL database, which has the same// effect as the previous callpQuery->InitWithCurrent();// Or initialize with specific condition(s)// Empty vector of features means query all features in the// Oracle databasestd::vector<std::string> vFeatureNames;pQuery->AddWhereConditionInFeatures(vFeatureNames,"AdMapEntityType IS NOT NULL");// You can clear the query with pQuery->Clear(),// but not right now; we still need it// Check the query with ConvertToSql()char *psql = pQuery->ConvertToSql();// Save the query to the Oracle databasepQuery->Save("MyQuery");// Load the saved query into another query objectAcMapOSEQuery *pNewQuery = new AcMapOSEQuery(pConnection);pNewQuery->Load("MyQuery");// Compare old and new querieschar *pNewSql = pNewQuery->ConvertToSql();if(strcmp(pSql,pNewSql) == 0)acutPrintf("Query Load/Save works!\n");elseacutPrintf("Query Load/Save failed!\n");// Import DataAcMapOSEImport *pImport = new AcMapOSEImport(pConnection);// Use query defined above to import dataif(pImport->Import(pQuery))acutPrintf("\n Import successful\n");elseacutPrintf("\n Import failed\n");delete pQuery;delete pImport;}