void OGROCIDataSource::DeleteLayer( const char *pszLayerName ) { int iLayer; /* -------------------------------------------------------------------- */ /* Try to find layer. */ /* -------------------------------------------------------------------- */ for( iLayer = 0; iLayer < nLayers; iLayer++ ) { if( EQUAL(pszLayerName,papoLayers[iLayer]->GetLayerDefn()->GetName()) ) { pszLayerName = CPLStrdup(papoLayers[iLayer]->GetLayerDefn()->GetName()); break; } } if( iLayer == nLayers ) { CPLDebug( "OCI", "DeleteLayer: %s not found in layer list." \ " Layer * not* deleted.", pszLayerName ); return; } /* -------------------------------------------------------------------- */ /* Blow away our OGR structures related to the layer. This is */ /* pretty dangerous if anything has a reference to this layer! */ /* -------------------------------------------------------------------- */ CPLDebug( "OCI", "DeleteLayer(%s)", pszLayerName ); delete papoLayers[iLayer]; memmove( papoLayers + iLayer, papoLayers + iLayer + 1, sizeof(void *) * (nLayers - iLayer - 1) ); nLayers--; /* -------------------------------------------------------------------- */ /* Remove from the database. */ /* -------------------------------------------------------------------- */ OGROCIStatement oCommand( poSession ); char szCommand[1024]; sprintf( szCommand, "DROP TABLE \"%s\"", pszLayerName ); oCommand.Execute( szCommand ); sprintf( szCommand, "DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = UPPER('%s')", pszLayerName ); oCommand.Execute( szCommand ); CPLFree( (char *) pszLayerName ); }
void OGROCIDataSource::TruncateLayer( const char *pszLayerName ) { /* -------------------------------------------------------------------- */ /* Set OGR Debug statement explaining what is happening */ /* -------------------------------------------------------------------- */ CPLDebug( "OCI", "Truncate TABLE %s", pszLayerName ); /* -------------------------------------------------------------------- */ /* Truncate the layer in the database. */ /* -------------------------------------------------------------------- */ OGROCIStatement oCommand( poSession ); CPLString osCommand; osCommand.Printf( "TRUNCATE TABLE \"%s\"", pszLayerName ); oCommand.Execute( osCommand ); }
OGRErr OGROCIDataSource::DeleteLayer( int iLayer ) { /* -------------------------------------------------------------------- */ /* Blow away our OGR structures related to the layer. This is */ /* pretty dangerous if anything has a reference to this layer! */ /* -------------------------------------------------------------------- */ CPLString osLayerName = papoLayers[iLayer]->GetLayerDefn()->GetName(); CPLDebug( "OCI", "DeleteLayer(%s)", osLayerName.c_str() ); delete papoLayers[iLayer]; memmove( papoLayers + iLayer, papoLayers + iLayer + 1, sizeof(void *) * (nLayers - iLayer - 1) ); nLayers--; /* -------------------------------------------------------------------- */ /* Remove from the database. */ /* -------------------------------------------------------------------- */ OGROCIStatement oCommand( poSession ); CPLString osCommand; int nFailures = 0; osCommand.Printf( "DROP TABLE \"%s\"", osLayerName.c_str() ); if( oCommand.Execute( osCommand ) != CE_None ) nFailures++; osCommand.Printf( "DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = UPPER('%s')", osLayerName.c_str() ); if( oCommand.Execute( osCommand ) != CE_None ) nFailures++; if( nFailures == 0 ) return OGRERR_NONE; else return OGRERR_FAILURE; }
OGRLayer * OGROCIDataSource::ExecuteSQL( const char *pszSQLCommand, OGRGeometry *poSpatialFilter, const char *pszDialect ) { /* -------------------------------------------------------------------- */ /* Use generic implementation for recognized dialects */ /* -------------------------------------------------------------------- */ if( IsGenericSQLDialect(pszDialect) ) return OGRDataSource::ExecuteSQL( pszSQLCommand, poSpatialFilter, pszDialect ); /* -------------------------------------------------------------------- */ /* Ensure any pending stuff is flushed to the database. */ /* -------------------------------------------------------------------- */ FlushCache(); CPLDebug( "OCI", "ExecuteSQL(%s)", pszSQLCommand ); /* -------------------------------------------------------------------- */ /* Special case DELLAYER: command. */ /* -------------------------------------------------------------------- */ if( STARTS_WITH_CI(pszSQLCommand, "DELLAYER:") ) { const char *pszLayerName = pszSQLCommand + 9; while( *pszLayerName == ' ' ) pszLayerName++; DeleteLayer( pszLayerName ); return NULL; } /* -------------------------------------------------------------------- */ /* Special case VALLAYER: command. */ /* -------------------------------------------------------------------- */ if( STARTS_WITH_CI(pszSQLCommand, "VALLAYER:") ) { const char *pszLayerName = pszSQLCommand + 9; while( *pszLayerName == ' ' ) pszLayerName++; ValidateLayer( pszLayerName ); return NULL; } /* -------------------------------------------------------------------- */ /* Just execute simple command. */ /* -------------------------------------------------------------------- */ if( !STARTS_WITH_CI(pszSQLCommand, "SELECT") ) { OGROCIStatement oCommand( poSession ); oCommand.Execute( pszSQLCommand, OCI_COMMIT_ON_SUCCESS ); return NULL; } /* -------------------------------------------------------------------- */ /* Otherwise instantiate a layer. */ /* -------------------------------------------------------------------- */ else { OGROCIStatement oCommand( poSession ); if( oCommand.Execute( pszSQLCommand, OCI_DESCRIBE_ONLY ) == CE_None ) return new OGROCISelectLayer( this, pszSQLCommand, &oCommand ); else return NULL; } }