?? ogrocidatasource.cpp
字號:
/****************************************************************************** * $Id: ogrocidatasource.cpp 10646 2007-01-18 02:38:10Z warmerdam $ * * Project: Oracle Spatial Driver * Purpose: Implementation of the OGROCIDataSource class. * Author: Frank Warmerdam, warmerdam@pobox.com * ****************************************************************************** * Copyright (c) 2002, Frank Warmerdam <warmerdam@pobox.com> * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. ****************************************************************************/#include "ogr_oci.h"#include "cpl_conv.h"#include "cpl_string.h"CPL_CVSID("$Id: ogrocidatasource.cpp 10646 2007-01-18 02:38:10Z warmerdam $");static int anEPSGOracleMapping[] = { /* Oracle SRID, EPSG GCS/PCS Code */ 8192, 4326, // WGS84 8306, 4322, // WGS72 8267, 4269, // NAD83 8274, 4277, // OSGB 36 // NAD27 isn't easily mapped since there are many Oracle NAD27 codes. 81989, 27700, // UK National Grid 0, 0 // end marker};/************************************************************************//* OGROCIDataSource() *//************************************************************************/OGROCIDataSource::OGROCIDataSource(){ pszName = NULL; pszDBName = NULL; papoLayers = NULL; nLayers = 0; poSession = NULL; papoSRS = NULL; panSRID = NULL; nKnownSRID = 0;}/************************************************************************//* ~OGROCIDataSource() *//************************************************************************/OGROCIDataSource::~OGROCIDataSource(){ int i; CPLFree( pszName ); CPLFree( pszDBName ); for( i = 0; i < nLayers; i++ ) delete papoLayers[i]; CPLFree( papoLayers ); for( i = 0; i < nKnownSRID; i++ ) { papoSRS[i]->Release(); } CPLFree( papoSRS ); CPLFree( panSRID ); if( poSession != NULL ) delete poSession;}/************************************************************************//* Open() *//************************************************************************/int OGROCIDataSource::Open( const char * pszNewName, int bUpdate, int bTestOpen ){ CPLAssert( nLayers == 0 && poSession == NULL );/* -------------------------------------------------------------------- *//* Verify postgresql prefix. *//* -------------------------------------------------------------------- */ if( !EQUALN(pszNewName,"OCI:",3) ) { if( !bTestOpen ) CPLError( CE_Failure, CPLE_AppDefined, "%s does not conform to Oracle OCI driver naming convention," " OCI:*\n" ); return FALSE; }/* -------------------------------------------------------------------- *//* Try to parse out name, password and database name. *//* -------------------------------------------------------------------- */ char *pszUserid; const char *pszPassword = ""; const char *pszDatabase = ""; char **papszTableList = NULL; int i; pszUserid = CPLStrdup( pszNewName + 4 ); // Is there a table list? for( i = strlen(pszUserid)-1; i > 1; i-- ) { if( pszUserid[i] == ':' ) { papszTableList = CSLTokenizeStringComplex( pszUserid+i+1, ",", TRUE, FALSE ); pszUserid[i] = '\0'; break; } if( pszUserid[i] == '/' || pszUserid[i] == '@' ) break; } for( i = 0; pszUserid[i] != '\0' && pszUserid[i] != '/' && pszUserid[i] != '@'; i++ ) {} if( pszUserid[i] == '/' ) { pszUserid[i++] = '\0'; pszPassword = pszUserid + i; for( ; pszUserid[i] != '\0' && pszUserid[i] != '@'; i++ ) {} } if( pszUserid[i] == '@' ) { pszUserid[i++] = '\0'; pszDatabase = pszUserid + i; }/* -------------------------------------------------------------------- *//* Try to establish connection. *//* -------------------------------------------------------------------- */ CPLDebug( "OCI", "Userid=%s, Password=%s, Database=%s", pszUserid, pszPassword, pszDatabase ); poSession = OGRGetOCISession( pszUserid, pszPassword, pszDatabase ); if( poSession == NULL ) return FALSE; pszName = CPLStrdup( pszNewName ); bDSUpdate = bUpdate;/* -------------------------------------------------------------------- *//* If no list of target tables was provided, collect a list of *//* spatial tables now. *//* -------------------------------------------------------------------- */ if( papszTableList == NULL ) { OGROCIStatement oGetTables( poSession ); if( oGetTables.Execute( "SELECT TABLE_NAME, OWNER FROM ALL_SDO_GEOM_METADATA" ) == CE_None ) { char **papszRow; while( (papszRow = oGetTables.SimpleFetchRow()) != NULL ) { char szFullTableName[100]; if( EQUAL(papszRow[1],pszUserid) ) strcpy( szFullTableName, papszRow[0] ); else sprintf( szFullTableName, "%s.%s", papszRow[1], papszRow[0] ); if( CSLFindString( papszTableList, szFullTableName ) == -1 ) papszTableList = CSLAddString( papszTableList, szFullTableName ); } } } CPLFree( pszUserid );/* -------------------------------------------------------------------- *//* Open all the selected tables or views. *//* -------------------------------------------------------------------- */ for( i = 0; papszTableList != NULL && papszTableList[i] != NULL; i++ ) { OpenTable( papszTableList[i], -1, bUpdate, FALSE ); } return TRUE;}/************************************************************************//* OpenTable() *//************************************************************************/int OGROCIDataSource::OpenTable( const char *pszNewName, int nSRID, int bUpdate, int bTestOpen ){/* -------------------------------------------------------------------- *//* Create the layer object. *//* -------------------------------------------------------------------- */ OGROCITableLayer *poLayer; poLayer = new OGROCITableLayer( this, pszNewName, nSRID, bUpdate, FALSE ); if( !poLayer->IsValid() ) { delete poLayer; return FALSE; }/* -------------------------------------------------------------------- *//* Add layer to data source layer list. *//* -------------------------------------------------------------------- */ papoLayers = (OGROCILayer **) CPLRealloc( papoLayers, sizeof(OGROCILayer *) * (nLayers+1) ); papoLayers[nLayers++] = poLayer; return TRUE;}/************************************************************************//* ValidateLayer() *//************************************************************************/void OGROCIDataSource::ValidateLayer( const char *pszLayerName ){ int iLayer;/* -------------------------------------------------------------------- *//* Try to find layer. *//* -------------------------------------------------------------------- */ for( iLayer = 0; iLayer < nLayers; iLayer++ ) { if( EQUAL(pszLayerName,papoLayers[iLayer]->GetLayerDefn()->GetName()) ) break; } if( iLayer == nLayers ) { CPLError( CE_Failure, CPLE_AppDefined, "ValidateLayer(): %s is not a recognised layer.", pszLayerName ); return; }/* -------------------------------------------------------------------- *//* Verify we have an FID and geometry column for this table. *//* -------------------------------------------------------------------- */ OGROCITableLayer *poLayer = (OGROCITableLayer *) papoLayers[iLayer]; if( strlen(poLayer->GetFIDColumn()) == 0 || strlen(poLayer->GetGeometryColumn()) == 0 ) { CPLError( CE_Failure, CPLE_AppDefined, "ValidateLayer(): %s lacks a geometry or fid column.", pszLayerName ); return; }/* -------------------------------------------------------------------- */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -