📄 ogrocisession.cpp
字号:
/****************************************************************************** * $Id: ogrocisession.cpp,v 1.10 2003/08/03 02:39:40 warmerda Exp $ * * 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. ****************************************************************************** * * $Log: ogrocisession.cpp,v $ * Revision 1.10 2003/08/03 02:39:40 warmerda * Fixed problem with byPrecision actually being a short in Ned's experience, * instead of a short. Tried to work around this in a way that isn't likely * to break even if Oracle's behaviour changes to what is documented. * * Revision 1.9 2003/05/21 03:54:01 warmerda * expand tabs * * Revision 1.8 2003/04/10 17:54:08 warmerda * added PinTDO method * * Revision 1.7 2003/02/06 21:15:45 warmerda * Get hElemInfoTDO, improve initial session error chequing * * Revision 1.6 2003/01/14 16:58:39 warmerda * treat very long string fields as having no set width * * Revision 1.5 2003/01/10 22:30:40 warmerda * collect type info for SDO_ORDINATE_ARRAY and added CleanName() * * Revision 1.4 2003/01/09 21:47:34 warmerda * avoid debug info on schema * * Revision 1.3 2003/01/09 21:19:12 warmerda * improved data type support, get/set precision * * 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"CPL_CVSID("$Id: ogrocisession.cpp,v 1.10 2003/08/03 02:39:40 warmerda Exp $");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';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -