int OGRFMELayerDB::CreateReader() { FME_MsgNum err; IFMESession *poSession = poDS->GetFMESession(); FME_UInt32 i; CPLAssert( poReader == NULL && nPreviousFeature == -1 ); /* -------------------------------------------------------------------- */ /* Make a copy of the user directives, so we won't be altering */ /* the originals. */ /* -------------------------------------------------------------------- */ IFMEStringArray *poUDC = poSession->createStringArray(); for( i = 0; i < poUserDirectives->entries(); i++ ) poUDC->append( (*poUserDirectives)(i) ); /* -------------------------------------------------------------------- */ /* Update the IDLIST to just select the desired table. */ /* -------------------------------------------------------------------- */ for( i = 0; i < poUDC->entries(); i++ ) { if( EQUAL((const char *) (*poUDC)(i),"IDLIST") ) { IFMEString *poIDList = poSession->createString(); *poIDList = GetLayerDefn()->GetName(); poUDC->setElement( i+1, *poIDList ); poSession->destroyString( poIDList ); break; } } if( i == poUDC->entries() ) { poUDC->append( "IDLIST" ); poUDC->append( GetLayerDefn()->GetName() ); } /* -------------------------------------------------------------------- */ /* Update the macros for source information, if needed. */ /* -------------------------------------------------------------------- */ if( m_poFilterGeom != NULL ) { const char *pszDirective = "RUNTIME_MACROS"; if( !poUDC->contains(pszDirective) ) { poUDC->append(pszDirective); poUDC->append(""); } for( i = 0; i < poUDC->entries(); i++ ) { if( EQUAL((const char *) (*poUDC)(i),pszDirective) ) { IFMEString *poMacroValue = poSession->createString(); char szSEARCH_ENVELOPE[1024]; OGREnvelope oEnvelope; poUDC->getElement( i+1, *poMacroValue ); m_poFilterGeom->getEnvelope( &oEnvelope ); if( STARTS_WITH_CI(pszReaderName, "SDE") ) { sprintf( szSEARCH_ENVELOPE, "%.16f", oEnvelope.MinX ); SetMacro( poMacroValue, "_SDE3MINX", szSEARCH_ENVELOPE ); sprintf( szSEARCH_ENVELOPE, "%.16f", oEnvelope.MinY ); SetMacro( poMacroValue, "_SDE3MINY", szSEARCH_ENVELOPE ); sprintf( szSEARCH_ENVELOPE, "%.16f", oEnvelope.MaxX ); SetMacro( poMacroValue, "_SDE3MAXX", szSEARCH_ENVELOPE ); sprintf( szSEARCH_ENVELOPE, "%.16f", oEnvelope.MaxY ); SetMacro( poMacroValue, "_SDE3MAXY", szSEARCH_ENVELOPE ); } else { sprintf( szSEARCH_ENVELOPE, "%.16f", oEnvelope.MinX ); SetMacro( poMacroValue, "_ORACLE_MINX", szSEARCH_ENVELOPE); sprintf( szSEARCH_ENVELOPE, "%.16f", oEnvelope.MinY ); SetMacro( poMacroValue, "_ORACLE_MINY", szSEARCH_ENVELOPE); sprintf( szSEARCH_ENVELOPE, "%.16f", oEnvelope.MaxX ); SetMacro( poMacroValue, "_ORACLE_MAXX", szSEARCH_ENVELOPE); sprintf( szSEARCH_ENVELOPE, "%.16f", oEnvelope.MaxY ); SetMacro( poMacroValue, "_ORACLE_MAXY", szSEARCH_ENVELOPE); } poUDC->setElement( i+1, *poMacroValue ); CPLDebug( "FMEOLEDB", "Update %s to:\n%s", pszDirective, poMacroValue->data() ); poSession->destroyString( poMacroValue ); break; } } } /* -------------------------------------------------------------------- */ /* Create new reader with desired constraints. */ /* -------------------------------------------------------------------- */ poReader = poSession->createReader(pszReaderName, FME_FALSE, poUDC); poSession->destroyStringArray( poUDC ); if( poReader == NULL ) { CPLFMEError( poSession, "Failed to create reader of type `%s'.\n", pszReaderName ); return FALSE; } /* -------------------------------------------------------------------- */ /* Setup constraints applied in open(). */ /* -------------------------------------------------------------------- */ IFMEStringArray *poParms = poSession->createStringArray(); if( pszAttributeFilter != NULL && strlen(pszAttributeFilter) > 0 ) { if( STARTS_WITH_CI(pszReaderName, "SDE") ) poParms->append( "WHERE" ); else poParms->append( "WHERE_CLAUSE" ); poParms->append( pszAttributeFilter ); } #ifdef notdef if( m_poFilterGeom != NULL ) { char szSEARCH_ENVELOPE[1024]; OGREnvelope oEnvelope; m_poFilterGeom->getEnvelope( &oEnvelope ); sprintf( szSEARCH_ENVELOPE, "%.16f", oEnvelope.MinX ); poParms->append( "SEARCH_ENVELOPE" ); poParms->append( szSEARCH_ENVELOPE ); sprintf( szSEARCH_ENVELOPE, "%.16f", oEnvelope.MinY ); poParms->append( "SEARCH_ENVELOPE" ); poParms->append( szSEARCH_ENVELOPE ); sprintf( szSEARCH_ENVELOPE, "%.16f", oEnvelope.MaxX ); poParms->append( "SEARCH_ENVELOPE" ); poParms->append( szSEARCH_ENVELOPE ); sprintf( szSEARCH_ENVELOPE, "%.16f", oEnvelope.MaxY ); poParms->append( "SEARCH_ENVELOPE" ); poParms->append( szSEARCH_ENVELOPE ); } #endif for( i = 0; i < poParms->entries(); i++ ) { CPLDebug( "FMEOLEDB", "openParms[%d] = %s", i, (const char *) (*poParms)(i) ); } /* -------------------------------------------------------------------- */ /* Now try to open the dataset. */ /* -------------------------------------------------------------------- */ err = poReader->open( pszDataset, *poParms ); if( err ) { CPLFMEError( poSession, "Failed to open dataset `%s' with reader of type `%s'.\n", pszDataset, pszReaderName ); return FALSE; } poSession->destroyStringArray( poParms ); return TRUE; }