📄 ogrocidatasource.cpp
字号:
/****************************************************************************** * $Id: ogrocidatasource.cpp,v 1.26 2005/02/10 15:46:02 fwarmerdam Exp $ * * 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. ****************************************************************************** * * $Log: ogrocidatasource.cpp,v $ * Revision 1.26 2005/02/10 15:46:02 fwarmerdam * added GEOMETRY_NAME layer creation option * * Revision 1.25 2004/11/22 19:24:15 fwarmerdam * added support for a list of tables in the datasource name * * Revision 1.24 2004/11/09 02:49:12 fwarmerdam * Don't add user_sdo_geom_metadata record till finalize (layer load complete) * time as that is when we have all the diminfo details. Inserts of metadata * records with NULL diminfos fails in Oracle 10 due to new constraints. * * Revision 1.23 2004/07/09 07:07:39 warmerda * Added OGRSQL dialect support. * * Revision 1.22 2003/09/18 14:45:47 warmerda * return -1 from FetchSRSId() for SRS if not GEOGCS or PROJCS * * Revision 1.21 2003/09/13 04:52:38 warmerda * Added logic to mapping some EPSG codes to and from Oracle codes by table. * Added logic to recognise an Oracle authority in WKT as a direct mapping * request. Return authority information from MDSYS.CS_SRS where available. * * Revision 1.20 2003/05/21 03:54:01 warmerda * expand tabs * * Revision 1.19 2003/04/22 19:37:50 warmerda * Added sync to disk * * Revision 1.18 2003/04/04 06:18:08 warmerda * first pass implementation of loader support * * Revision 1.17 2003/03/18 18:34:17 warmerda * added reason code 13349 * * Revision 1.16 2003/02/06 21:14:43 warmerda * cleanup some memory leaks * * Revision 1.15 2003/01/15 06:10:04 warmerda * Added logic to hack angular unit name to "Decimal Degree". * * Revision 1.14 2003/01/15 05:35:32 warmerda * allow override of SRID, pass to table constructor * * Revision 1.13 2003/01/14 22:15:13 warmerda * added pseudo-sql commands DELLAYER and VALLAYER * * Revision 1.12 2003/01/14 15:09:44 warmerda * set layer creation options on OGROCITableLayer * * Revision 1.11 2003/01/13 13:49:43 warmerda * add multi-user table support (ALL_SDO_GEOM_METADATA) * * Revision 1.10 2003/01/10 22:31:06 warmerda * use OGROCISession::CleanName() to fixup names * * Revision 1.9 2003/01/10 19:30:14 warmerda * Another related initialization fix. * * Revision 1.8 2003/01/10 16:40:33 warmerda * initialize SRS table * * Revision 1.7 2003/01/07 22:24:35 warmerda * added SRS support * * Revision 1.6 2003/01/06 17:58:20 warmerda * Fix FID support, add DIM creation keyword * * Revision 1.5 2003/01/02 21:48:52 warmerda * uppercaseify layer names when creating tables * * Revision 1.4 2002/12/29 19:43:59 warmerda * avoid some warnings * * Revision 1.3 2002/12/29 03:19:48 warmerda * fixed extraction of database name * * Revision 1.2 2002/12/28 04:38:36 warmerda * converted to unix file conventions * * Revision 1.1 2002/12/28 04:07:27 warmerda * New * */#include "ogr_oci.h"#include "cpl_conv.h"#include "cpl_string.h"CPL_CVSID("$Id: ogrocidatasource.cpp,v 1.26 2005/02/10 15:46:02 fwarmerdam Exp $");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++ ) { delete papoSRS[i]; } CPLFree( papoSRS ); CPLFree( panSRID );}/************************************************************************//* 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() )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -