ogrocisession.cpp
来自「支持各种栅格图像和矢量图像读取的库」· C++ 代码 · 共 439 行 · 第 1/2 页
CPP
439 行
/****************************************************************************** * $Id: ogrocisession.cpp 10646 2007-01-18 02:38:10Z warmerdam $ * * Project: Oracle Spatial Driver * Purpose: Implementation of OGROCISession, which encapsulates much of the * direct access to OCI. * 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"CPL_CVSID("$Id: ogrocisession.cpp 10646 2007-01-18 02:38:10Z warmerdam $");static OCIEnv *ghOracleEnvironment = NULL;/************************************************************************//* OGRGetOCISession() *//************************************************************************/OGROCISession * OGRGetOCISession( const char *pszUserid, const char *pszPassword, const char *pszDatabase ){ OGROCISession *poSession; poSession = new OGROCISession(); if( poSession->EstablishSession( pszUserid, pszPassword, pszDatabase ) ) return poSession; else { delete poSession; return NULL; }}/************************************************************************//* OGROCISession() *//************************************************************************/OGROCISession::OGROCISession(){ hEnv = NULL; hError = NULL; hSvcCtx = NULL; hDescribe = NULL; hGeometryTDO = NULL; hOrdinatesTDO = NULL;}/************************************************************************//* ~OGROCISession() *//************************************************************************/OGROCISession::~OGROCISession(){ if( hDescribe != NULL ) OCIHandleFree((dvoid *)hDescribe, (ub4)OCI_HTYPE_DESCRIBE); if( hSvcCtx != NULL ) OCILogoff( hSvcCtx, hError );}/************************************************************************//* EstablishSession() *//************************************************************************/int OGROCISession::EstablishSession( const char *pszUserid, const char *pszPassword, const char *pszDatabase ){ sword nStatus;/* -------------------------------------------------------------------- *//* Establish the environment. *//* -------------------------------------------------------------------- */ if( ghOracleEnvironment == NULL ) { nStatus = OCIEnvCreate( &ghOracleEnvironment, OCI_OBJECT, (dvoid *)0, 0, 0, 0, (size_t) 0, (dvoid **)0 ); if( nStatus == -1 || ghOracleEnvironment == NULL ) { CPLDebug("OCI", "OCIEnvCreate() failed with status %d.\n" "Presumably Oracle is not properly installed, skipping."); return FALSE; } } hEnv = ghOracleEnvironment;/* -------------------------------------------------------------------- *//* Create the error handle. *//* -------------------------------------------------------------------- */ nStatus = OCIHandleAlloc( (dvoid *) hEnv, (dvoid **) &hError, (ub4) OCI_HTYPE_ERROR, (size_t) 0, (dvoid **) NULL );/* -------------------------------------------------------------------- *//* Attempt Logon. *//* -------------------------------------------------------------------- */ if( Failed( OCILogon( hEnv, hError, &hSvcCtx, (text *) pszUserid, strlen(pszUserid), (text *) pszPassword, strlen(pszPassword), (text *) pszDatabase, pszDatabase ? strlen(pszDatabase):0 ) )) return FALSE;/* -------------------------------------------------------------------- *//* Create a describe handle. *//* -------------------------------------------------------------------- */ if( Failed( OCIHandleAlloc( hEnv, (dvoid **) &hDescribe, (ub4)OCI_HTYPE_DESCRIBE, (size_t)0, (dvoid **)0 ), "OCIHandleAlloc(Describe)" ) ) return FALSE;/* -------------------------------------------------------------------- *//* Try to get the MDSYS.SDO_GEOMETRY type object. *//* -------------------------------------------------------------------- */ hGeometryTDO = PinTDO( SDO_GEOMETRY ); if( hGeometryTDO == NULL ) return FALSE;/* -------------------------------------------------------------------- *//* Try to get the MDSYS.SDO_ORDINATE_ARRAY type object. *//* -------------------------------------------------------------------- */ hOrdinatesTDO = PinTDO( "MDSYS.SDO_ORDINATE_ARRAY" ); if( hOrdinatesTDO == NULL ) return FALSE;/* -------------------------------------------------------------------- *//* Try to get the MDSYS.SDO_ELEM_INFO_ARRAY type object. *//* -------------------------------------------------------------------- */ hElemInfoTDO = PinTDO( "MDSYS.SDO_ELEM_INFO_ARRAY" ); if( hElemInfoTDO == NULL ) return FALSE;/* -------------------------------------------------------------------- *//* Record information about the session. *//* -------------------------------------------------------------------- */ this->pszUserid = CPLStrdup(pszUserid); this->pszPassword = CPLStrdup(pszPassword); this->pszDatabase = CPLStrdup(pszDatabase); return TRUE;}/************************************************************************//* Failed() *//************************************************************************/int OGROCISession::Failed( sword nStatus, const char *pszFunction ){ if( pszFunction == NULL ) pszFunction = "<unnamed>"; if( nStatus == OCI_ERROR ) { sb4 nErrCode = 0; char szErrorMsg[10000]; szErrorMsg[0] = '\0'; if( hError != NULL ) { OCIErrorGet( (dvoid *) hError, (ub4) 1, NULL, &nErrCode, (text *) szErrorMsg, (ub4) sizeof(szErrorMsg), OCI_HTYPE_ERROR ); } szErrorMsg[sizeof(szErrorMsg)-1] = '\0'; CPLError( CE_Failure, CPLE_AppDefined, "%s in %s", szErrorMsg, pszFunction ); return TRUE; } else if( nStatus == OCI_NEED_DATA ) { CPLError( CE_Failure, CPLE_AppDefined, "OCI_NEED_DATA" ); return TRUE; } else if( nStatus == OCI_INVALID_HANDLE ) { CPLError( CE_Failure, CPLE_AppDefined, "OCI_INVALID_HANDLE in %s", pszFunction ); return TRUE; } else if( nStatus == OCI_STILL_EXECUTING ) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?