[Liblas-commits] libpc: plumbing for OCI driver
liblas-commits at liblas.org
liblas-commits at liblas.org
Tue Mar 1 13:30:46 EST 2011
details: http://hg.liblas.orglibpc/rev/ce568eebe707
changeset: 133:ce568eebe707
user: Howard Butler <hobu.inc at gmail.com>
date: Tue Mar 01 12:29:56 2011 -0600
description:
plumbing for OCI driver
diffstat:
src/CMakeLists.txt | 3 +-
src/drivers/CMakeLists.txt | 7 +-
src/drivers/oci/CMakeLists.txt | 19 +
src/drivers/oci/oci_wrapper.cpp | 1774 +++++++++++++++++++++++++++++++++++++++
src/drivers/oci/oci_wrapper.h | 417 +++++++++
5 files changed, 2218 insertions(+), 2 deletions(-)
diffs (truncated from 2257 to 300 lines):
diff -r 4f0309a45e4e -r ce568eebe707 src/CMakeLists.txt
--- a/src/CMakeLists.txt Tue Mar 01 08:57:41 2011 -0600
+++ b/src/CMakeLists.txt Tue Mar 01 12:29:56 2011 -0600
@@ -52,6 +52,7 @@
${LIBPC_HEADERS_DIR}/Writer.hpp)
set (LIBPC_SOURCES "libpc_config.cpp" CACHE INTERNAL "sources to compile")
+set (APPS_CPP_DEPENDENCIES "${LIBPC_LIB_NAME}" CACHE INTERNAL "libraries to link")
add_subdirectory(drivers)
@@ -120,7 +121,7 @@
add_library(${LIBPC_LIB_NAME} SHARED ${LIBPC_SOURCES})
-target_link_libraries(${LIBPC_LIB_NAME}
+target_link_libraries(${APPS_CPP_DEPENDENCIES}
${LIBPC_LIB_NAME}
${LIBLAS_LIBRARY}
${TIFF_LIBRARY}
diff -r 4f0309a45e4e -r ce568eebe707 src/drivers/CMakeLists.txt
--- a/src/drivers/CMakeLists.txt Tue Mar 01 08:57:41 2011 -0600
+++ b/src/drivers/CMakeLists.txt Tue Mar 01 12:29:56 2011 -0600
@@ -9,4 +9,9 @@
add_subdirectory(liblas)
-add_subdirectory(las)
\ No newline at end of file
+add_subdirectory(las)
+
+if(ORACLE_FOUND AND GDAL_FOUND)
+ add_subdirectory(oci)
+endif()
+
diff -r 4f0309a45e4e -r ce568eebe707 src/drivers/oci/CMakeLists.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/drivers/oci/CMakeLists.txt Tue Mar 01 12:29:56 2011 -0600
@@ -0,0 +1,19 @@
+###############################################################################
+#
+# src/drivers/liblas/CMakeLists.txt controls building of libPC library
+#
+# Copyright (c) 2011 Howard Butler <hobu at hobu.net>
+#
+###############################################################################
+
+
+set (SOURCES
+ oci_wrapper.cpp
+ )
+
+SET(APPS_CPP_DEPENDENCIES "${APPS_CPP_DEPENDENCIES};${ORACLE_LIBRARY}" CACHE INTERNAL "source files for foo")
+
+
+FOREACH(file ${SOURCES})
+ SET(LIBPC_SOURCES "${LIBPC_SOURCES};${CMAKE_CURRENT_SOURCE_DIR}/${file}" CACHE INTERNAL "source files for foo")
+ENDFOREACH(file)
diff -r 4f0309a45e4e -r ce568eebe707 src/drivers/oci/oci_wrapper.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/drivers/oci/oci_wrapper.cpp Tue Mar 01 12:29:56 2011 -0600
@@ -0,0 +1,1774 @@
+/******************************************************************************
+ * $Id: $
+ *
+ * Name: oci_wrapper.cpp
+ * Project: Oracle Spatial GeoRaster Driver
+ * Purpose: Limited wrapper for OCI (Oracle Call Interfaces)
+ * Author: Ivan Lucena [ivan.lucena at pmldnet.com]
+ *
+ ******************************************************************************
+ * Copyright (c) 2008, Ivan Lucena
+ *
+ * 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 "oci_wrapper.h"
+
+static const OW_CellDepth ahOW_CellDepth[] = {
+ {"8BIT_U", GDT_Byte},
+ {"16BIT_U", GDT_UInt16},
+ {"16BIT_S", GDT_Int16},
+ {"32BIT_U", GDT_UInt32},
+ {"32BIT_S", GDT_Int32},
+ {"32BIT_REAL", GDT_Float32},
+ {"64BIT_REAL", GDT_Float64},
+ {"32BIT_COMPLEX", GDT_CFloat32},
+ {"64BIT_COMPLEX", GDT_CFloat64},
+ {"1BIT", GDT_Byte},
+ {"2BIT", GDT_Byte},
+ {"4BIT", GDT_Byte}
+};
+
+/*****************************************************************************/
+/* OWConnection */
+/*****************************************************************************/
+
+OWConnection::OWConnection( const char* pszUserIn,
+ const char* pszPasswordIn,
+ const char* pszServerIn )
+{
+ pszUser = CPLStrdup( pszUserIn );
+ pszPassword = CPLStrdup( pszPasswordIn );
+ pszServer = CPLStrdup( pszServerIn );
+ hEnv = NULL;
+ hError = NULL;
+ hSvcCtx = NULL;
+ hDescribe = NULL;
+ hNumArrayTDO = NULL;
+ hGeometryTDO = NULL;
+ hGeoRasterTDO = NULL;
+ hElemArrayTDO = NULL;
+ hOrdnArrayTDO = NULL;
+ bSuceeeded = false;
+ nCharSize = 1;
+
+ // ------------------------------------------------------
+ // Operational Systems's authentication option
+ // ------------------------------------------------------
+
+ const char* pszUserId = "/";
+
+ ub4 eCred = OCI_CRED_RDBMS;
+
+ if( EQUAL(pszServer, "") &&
+ EQUAL(pszPassword, "") &&
+ EQUAL(pszUser, "") )
+ {
+ eCred = OCI_CRED_EXT;
+ }
+ else
+ {
+ pszUserId = pszUser;
+ }
+
+ // ------------------------------------------------------
+ // Initialize Environment handler */
+ // ------------------------------------------------------
+
+ if( OCIEnvCreate( &hEnv,
+ (ub4) ( OCI_DEFAULT | OCI_OBJECT | OCI_THREADED ),
+ (dvoid *) 0, (dvoid * (*)(dvoid *, size_t)) 0,
+ (dvoid * (*)(dvoid *, dvoid *, size_t)) 0,
+ (void (*)(dvoid *, dvoid *)) 0, (size_t) 0,
+ (dvoid **) 0), NULL )
+ {
+ return;
+ }
+
+ // ------------------------------------------------------
+ // Initialize Error handler
+ // ------------------------------------------------------
+
+ if( CheckError( OCIHandleAlloc( (dvoid *) hEnv, (dvoid **) &hError,
+ OCI_HTYPE_ERROR, (size_t) 0, (dvoid **) 0), NULL ) )
+ {
+ return;
+ }
+
+ // ------------------------------------------------------
+ // Initialize Server Context
+ // ------------------------------------------------------
+
+ if( CheckError( OCIHandleAlloc( (dvoid *) hEnv, (dvoid **) &hSvcCtx,
+ OCI_HTYPE_SVCCTX, (size_t) 0, (dvoid **) 0), hError ) )
+ {
+ return;
+ }
+
+ // ------------------------------------------------------
+ // Allocate Server and Authentication (Session) handler
+ // ------------------------------------------------------
+
+ if( CheckError( OCIHandleAlloc( (dvoid *) hEnv, (dvoid **) &hServer,
+ (ub4) OCI_HTYPE_SERVER, (size_t) 0, (dvoid **) 0), hError ) )
+ {
+ return;
+ }
+
+ if( CheckError( OCIHandleAlloc((dvoid *) hEnv, (dvoid **)&hSession,
+ (ub4) OCI_HTYPE_SESSION, (size_t) 0, (dvoid **) 0), hError ) )
+ {
+ return;
+ }
+
+ // ------------------------------------------------------
+ // Attach to the server
+ // ------------------------------------------------------
+
+ if( CheckError( OCIServerAttach( hServer, hError, (text*) pszServer,
+ strlen((char*) pszServer), 0), hError ) )
+ {
+ return;
+ }
+
+ if( CheckError( OCIAttrSet((dvoid *) hSession, (ub4) OCI_HTYPE_SESSION,
+ (dvoid *) pszUserId, (ub4) strlen((char *) pszUserId),
+ (ub4) OCI_ATTR_USERNAME, hError), hError ) )
+ {
+ return;
+ }
+
+ if( CheckError( OCIAttrSet((dvoid *) hSession, (ub4) OCI_HTYPE_SESSION,
+ (dvoid *) pszPassword, (ub4) strlen((char *) pszPassword),
+ (ub4) OCI_ATTR_PASSWORD, hError), hError ) )
+ {
+ return;
+ }
+
+ if( CheckError( OCIAttrSet( (dvoid *) hSvcCtx, OCI_HTYPE_SVCCTX, (dvoid *)hServer,
+ (ub4) 0, OCI_ATTR_SERVER, (OCIError *) hError), hError ) )
+ {
+ return;
+ }
+
+ // ------------------------------------------------------
+ // Initialize Session
+ // ------------------------------------------------------
+
+ if( CheckError( OCISessionBegin(hSvcCtx, hError, hSession, eCred,
+ (ub4) OCI_DEFAULT), hError ) )
+ {
+ return;
+ }
+
+ // ------------------------------------------------------
+ // Initialize Service
+ // ------------------------------------------------------
+
+ if( CheckError( OCIAttrSet((dvoid *) hSvcCtx, (ub4) OCI_HTYPE_SVCCTX,
+ (dvoid *) hSession, (ub4) 0,
+ (ub4) OCI_ATTR_SESSION, hError), hError ) )
+ {
+ return;
+ }
+
+ bSuceeeded = true;
+
+ // ------------------------------------------------------
+ // Get Character Size based on current Locale
+ // ------------------------------------------------------
+
+ OCINlsNumericInfoGet( hEnv, hError,
+ &nCharSize, OCI_NLS_CHARSET_MAXBYTESZ );
+
+ // ------------------------------------------------------
+ // Get Server Version
+ // ------------------------------------------------------
+
+ char szVersionTxt[OWTEXT];
+
+ OCIServerVersion (
+ hSvcCtx,
+ hError,
+ (text*) szVersionTxt,
+ (ub4) OWTEXT,
+ (ub1) OCI_HTYPE_SVCCTX );
+
+ nVersion = OWParseServerVersion( szVersionTxt );
+
+ // ------------------------------------------------------
+ // Initialize/Describe types
+ // ------------------------------------------------------
+
+ CheckError( OCIHandleAlloc(
+ (dvoid*) hEnv,
+ (dvoid**) (dvoid*) &hDescribe,
+ (ub4) OCI_HTYPE_DESCRIBE,
+ (size_t) 0,
+ (dvoid**) NULL ), hError );
+
+ hNumArrayTDO = DescribeType( (char*) SDO_NUMBER_ARRAY );
+ hGeometryTDO = DescribeType( (char*) SDO_GEOMETRY );
+ hGeoRasterTDO = DescribeType( (char*) SDO_GEORASTER );
+ hPCTDO = DescribeType( (char*) SDO_PC );
+ hElemArrayTDO = DescribeType( (char*) SDO_ELEM_INFO_ARRAY);
+ hOrdnArrayTDO = DescribeType( (char* ) SDO_ORDINATE_ARRAY);
+}
+
+OWConnection::~OWConnection()
+{
+ OCIHandleFree( (dvoid*) hDescribe, (ub4) OCI_HTYPE_DESCRIBE);
+
+ if( hSvcCtx && hError && hSession )
More information about the Liblas-commits
mailing list