[Liblas-commits] hg-main-tree: add support for boundary insertion via CLOBs to li...

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Mar 31 10:33:49 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/712ec8b1bd73
changeset: 486:712ec8b1bd73
user:      Howard Butler <hobu.inc at gmail.com>
date:      Thu Mar 31 09:33:40 2011 -0500
description:
add support for boundary insertion via CLOBs to libpc::drivers::oci::Writer

diffstat:

 include/libpc/drivers/oci/oci_wrapper.h |   2 +
 src/drivers/oci/Writer.cpp              |  33 +++++++++++++++++---
 src/drivers/oci/oci_wrapper.cpp         |  52 +++++++++++++++++++++++++++++++++
 3 files changed, 81 insertions(+), 6 deletions(-)

diffs (153 lines):

diff -r d1159a5c7fdf -r 712ec8b1bd73 include/libpc/drivers/oci/oci_wrapper.h
--- a/include/libpc/drivers/oci/oci_wrapper.h	Thu Mar 31 07:27:43 2011 -0500
+++ b/include/libpc/drivers/oci/oci_wrapper.h	Thu Mar 31 09:33:40 2011 -0500
@@ -419,6 +419,7 @@
     void                Bind( long* pnData );
     void                Bind( double* pnData );
     void                Bind( char* pData, long nData );
+    void                BindClob( char* pData, long nData );    
     void                Bind( sdo_geometry** pphData );
     void                Bind( sdo_pc_blk** pphData );
     void                Bind( OCILobLocator** pphLocator );
@@ -435,6 +436,7 @@
     void                Define( sdo_pc** pphData );
     void                Define( sdo_pc_blk** pphData );
     void                Define( OCILobLocator** pphLocator, long nIterations );
+    void                DefineClob( OCILobLocator** pphLocator, long nIterations );
     void                BindName( const char* pszName, int* pnData );
     void                BindName( const char* pszName, double* pnData );
     void                BindName( const char* pszName, char* pszData,
diff -r d1159a5c7fdf -r 712ec8b1bd73 src/drivers/oci/Writer.cpp
--- a/src/drivers/oci/Writer.cpp	Thu Mar 31 07:27:43 2011 -0500
+++ b/src/drivers/oci/Writer.cpp	Thu Mar 31 09:33:40 2011 -0500
@@ -464,12 +464,22 @@
         columns << cloud_column_name;
         values << "pc";
     }
-    
+
+    int nPos = 1; // Bind column position    
     if (!header_blob_column_name.empty()){
         columns << "," << header_blob_column_name;
-        values <<", :2";
+        values <<", :" << nPos++;
     }
 
+    if (!base_table_boundary_column.empty()){
+        columns << "," << base_table_boundary_column;
+        nPos++;
+        values <<", SDO_GEOMETRY(:"<<nPos;
+        nPos++;
+        values <<", :"<<nPos<<")";
+    }
+    
+
 
     std::ostringstream s_srid;
     std::ostringstream s_gtype;
@@ -546,13 +556,23 @@
     Statement statement = Statement(m_connection->CreateStatement(oss.str().c_str()));
 
     statement->Bind(&pc_id);
-    if (header_data->size() != 0) {
+    if (header_data->size() != 0) 
+    {
         OCILobLocator** locator =(OCILobLocator**) VSIMalloc( sizeof(OCILobLocator*) * 1 );
         statement->Define( locator, 1 ); 
+        statement->Bind((char*)&(header_data[0]),(long)header_data->size());
+    }
 
-        statement->Bind((char*)&(header_data[0]),(long)header_data->size());
-    
+    char* wkt = (char*) malloc(base_table_boundary_wkt.size() * sizeof(char));
+    strncpy(wkt, base_table_boundary_wkt.c_str(), base_table_boundary_wkt.size());
+    if (!base_table_boundary_column.empty())
+    {
+        OCILobLocator** locator =(OCILobLocator**) VSIMalloc( sizeof(OCILobLocator*) * 1 );
+        statement->DefineClob( locator, 1 ); 
+        statement->BindClob(wkt,(long)base_table_boundary_wkt.size());
+        statement->Bind((long int*)&srid);
     }
+
     try {
         statement->Execute();
     } catch (std::runtime_error const& e) {
@@ -561,7 +581,8 @@
         throw std::runtime_error(oss.str());
     }
     output = pc_id;
-
+    
+    free(wkt);
     tree.put("cloud_id", pc_id);
     
 }
diff -r d1159a5c7fdf -r 712ec8b1bd73 src/drivers/oci/oci_wrapper.cpp
--- a/src/drivers/oci/oci_wrapper.cpp	Thu Mar 31 07:27:43 2011 -0500
+++ b/src/drivers/oci/oci_wrapper.cpp	Thu Mar 31 09:33:40 2011 -0500
@@ -899,6 +899,29 @@
         hError );
 }
 
+void OWStatement::BindClob( char* pData, long nData )
+{
+    OCIBind* hBind = NULL;
+
+    nNextBnd++;
+
+    CheckError( OCIBindByPos(
+        hStmt,
+        &hBind,
+        hError,
+        (ub4) nNextBnd,
+        (dvoid*) pData,
+        (sb4) nData,
+        (ub2) SQLT_LNG,
+        (void*) NULL,
+        (ub2*) NULL,
+        (ub2*) NULL,
+        (ub4) NULL,
+        (ub4) NULL,
+        (ub4) OCI_DEFAULT ),
+        hError );
+}
+
 void OWStatement::Bind( sdo_geometry** pphData )
 {
     OCIBind* hBind = NULL;
@@ -1153,6 +1176,35 @@
         (ub4) OCI_DEFAULT ),
         hError );
 }
+void OWStatement::DefineClob( OCILobLocator** pphLocator, long nIterations )
+{
+    OCIDefine* hDefine = NULL;
+
+    nNextCol++;
+
+    long i;
+
+    for (i = 0; i < nIterations; i++)
+    {
+        OCIDescriptorAlloc(
+            poConnection->hEnv,
+            (void**) &pphLocator[i],
+            OCI_DTYPE_LOB, (size_t) 0, (void**) 0);
+    }
+
+    CheckError( OCIDefineByPos( hStmt,
+        &hDefine,
+        hError,
+        (ub4) nNextCol,
+        (dvoid*) pphLocator,
+        (sb4) -1,
+        (ub2) SQLT_CLOB,
+        (void*) 0,
+        (ub2*) 0,
+        (ub2*) 0,
+        (ub4) OCI_DEFAULT ), hError );
+}
+
 
 void OWStatement::WriteCLob( OCILobLocator** pphLocator, char* pszData )
 {


More information about the Liblas-commits mailing list