[Liblas-commits] hg-main-tree: more libpc::drivers::oci::Reader work
liblas-commits at liblas.org
liblas-commits at liblas.org
Thu Mar 31 08:27:54 EDT 2011
details: http://hg.libpc.orghg-main-tree/rev/d1159a5c7fdf
changeset: 485:d1159a5c7fdf
user: Howard Butler <hobu.inc at gmail.com>
date: Thu Mar 31 07:27:43 2011 -0500
description:
more libpc::drivers::oci::Reader work
diffstat:
apps/pc2pc.cpp | 3 +-
include/libpc/drivers/oci/Reader.hpp | 1 +
include/libpc/drivers/oci/oci_wrapper.h | 47 ++++++
src/drivers/oci/Reader.cpp | 229 +++++++++++++++++++++++-----
src/drivers/oci/common.cpp | 12 +
src/drivers/oci/oci_wrapper.cpp | 250 +++++++++++++++++++++++++++++++-
6 files changed, 494 insertions(+), 48 deletions(-)
diffs (truncated from 705 to 300 lines):
diff -r 55dd6b15eee2 -r d1159a5c7fdf apps/pc2pc.cpp
--- a/apps/pc2pc.cpp Tue Mar 29 12:22:08 2011 -0500
+++ b/apps/pc2pc.cpp Thu Mar 31 07:27:43 2011 -0500
@@ -154,7 +154,8 @@
tree.put("connection", "lidar/lidar at oracle.hobu.biz/crrel");
tree.put("debug", true);
tree.put("verbose", true);
- tree.put("select_sql", "select * from output");
+ // tree.put("select_sql", "select * from output");
+ tree.put("select_sql", "select cloud from hobu where id = 5");
libpc::drivers::oci::Reader reader(options);
diff -r 55dd6b15eee2 -r d1159a5c7fdf include/libpc/drivers/oci/Reader.hpp
--- a/include/libpc/drivers/oci/Reader.hpp Tue Mar 29 12:22:08 2011 -0500
+++ b/include/libpc/drivers/oci/Reader.hpp Thu Mar 31 07:27:43 2011 -0500
@@ -71,6 +71,7 @@
void Debug();
void registerFields();
+ void fetchPCFields();
Options& m_options;
Connection m_connection;
diff -r 55dd6b15eee2 -r d1159a5c7fdf include/libpc/drivers/oci/oci_wrapper.h
--- a/include/libpc/drivers/oci/oci_wrapper.h Tue Mar 29 12:22:08 2011 -0500
+++ b/include/libpc/drivers/oci/oci_wrapper.h Thu Mar 31 07:27:43 2011 -0500
@@ -86,6 +86,7 @@
#define SDO_GEOMETRY TYPE_OWNER".SDO_GEOMETRY"
#define SDO_GEORASTER TYPE_OWNER".SDO_GEORASTER"
#define SDO_PC TYPE_OWNER".SDO_PC"
+#define SDO_PC_BLK TYPE_OWNER".SDO_PC_BLK"
#define SDO_NUMBER_ARRAY TYPE_OWNER".SDO_NUMBER_ARRAY"
#define SDO_ORDINATE_ARRAY TYPE_OWNER".SDO_ORDINATE_ARRAY"
#define SDO_ELEM_INFO_ARRAY TYPE_OWNER".SDO_ELEM_INFO_ARRAY"
@@ -250,6 +251,35 @@
};
typedef struct sdo_pc_ind SDO_PC_ind;
+struct sdo_pc_blk
+{
+ OCINumber obj_id;
+ OCINumber blk_id;
+ SDO_GEOMETRY_TYPE blk_extent;
+ SDO_ORGSCL_TYPE blk_domain;
+ OCINumber pcblk_min_res;
+ OCINumber pcblk_max_res;
+ OCINumber num_points;
+ OCINumber num_unsorted_points;
+ OCINumber pt_sort_dim;
+ void* points;
+};
+typedef struct sdo_pc_blk SDO_PC_BLK_TYPE;
+
+struct sdo_pc_blk_type_ind
+{
+ OCIInd _atomic;
+ OCIInd obj_id;
+ OCIInd blk_id;
+ sdo_geometry_ind blk_extent;
+ sdo_orgscl_type_ind blk_domain;
+ OCIInd pcblk_min_res;
+ OCIInd pcblk_max_res;
+ OCIInd num_points;
+ OCIInd num_unsorted_points;
+ OCIInd pt_sort_dim;
+};
+typedef struct sdo_pc_blk_type_ind SDO_PC_BLK_TYPE_ind;
/***************************************************************************/
/* Oracle class wrappers */
/***************************************************************************/
@@ -295,6 +325,8 @@
OCIType* hGeometryTDO;
OCIType* hGeoRasterTDO;
OCIType* hPCTDO;
+ OCIType* hPC_BLK_TDO;
+
OCIType* hElemArrayTDO;
OCIType* hOrdnArrayTDO;
@@ -313,6 +345,8 @@
void CreateType( sdo_geometry** pphData );
void DestroyType( sdo_geometry** pphData );
+ void CreateType( sdo_pc** pphData );
+ void DestroyType( sdo_pc** pphData );
void CreateType( OCIArray** phData , OCIType* type);
void DestroyType( OCIArray** phData );
OCIType* DescribeType( const char *pszTypeName );
@@ -329,6 +363,7 @@
OCIType* GetGeoRasterType() { return hGeoRasterTDO; }
OCIType* GetElemInfoType() {return hElemArrayTDO; }
OCIType* GetOrdinateType() {return hOrdnArrayTDO; }
+ OCIType* GetPCType() {return hPCTDO; }
bool Commit(); // OCITransCommit()
bool StartTransaction(); // //OCITransStart()
@@ -366,6 +401,16 @@
bool Fetch( int nRows = 1 );
unsigned int nFetchCount;
+ bool GetNextField(
+ int nIndex,
+ char* pszName,
+ int* pnType,
+ int* pnSize,
+ int* pnPrecision,
+ signed short* pnScale,
+ char* pszTypeName);
+
+
int GetInteger( OCINumber* ppoData );
double GetDouble( OCINumber* ppoData );
char* GetString( OCIString* ppoData );
@@ -375,6 +420,7 @@
void Bind( double* pnData );
void Bind( char* pData, long nData );
void Bind( sdo_geometry** pphData );
+ void Bind( sdo_pc_blk** pphData );
void Bind( OCILobLocator** pphLocator );
void Bind( OCIArray** pphData, OCIType* type );
void Bind( char* pszData, int nSize = OWNAME );
@@ -387,6 +433,7 @@
void Define( sdo_georaster** pphData );
void Define( sdo_geometry** pphData );
void Define( sdo_pc** pphData );
+ void Define( sdo_pc_blk** pphData );
void Define( OCILobLocator** pphLocator, long nIterations );
void BindName( const char* pszName, int* pnData );
void BindName( const char* pszName, double* pnData );
diff -r 55dd6b15eee2 -r d1159a5c7fdf src/drivers/oci/Reader.cpp
--- a/src/drivers/oci/Reader.cpp Tue Mar 29 12:22:08 2011 -0500
+++ b/src/drivers/oci/Reader.cpp Thu Mar 31 07:27:43 2011 -0500
@@ -38,6 +38,8 @@
#include <libpc/exceptions.hpp>
#include <iostream>
+#include <sstream>
+#include <map>
namespace libpc { namespace drivers { namespace oci {
@@ -60,9 +62,165 @@
throw libpc_error("'select_sql' statement is empty. No data can be read from libpc::drivers::oci::Reader");
m_statement = Statement(m_connection->CreateStatement(sql.c_str()));
-
+
+ registerFields();
+
+ m_statement->Execute(0);
+
+ fetchPCFields();
+
+ // int foo;
+ // int block_id;
+ //
+ // m_statement->Define(&foo);
+ // m_statement->Define(&block_id);
+
+ sdo_pc_blk* block;
+ sdo_pc* pc;
+
+ m_connection->CreateType(&pc);
+
+
+ m_statement->Define(&pc);
+
+
+ while(m_statement->Fetch() )
+ {
+ std::cout << " Block: " << m_statement->GetInteger(&(pc->pc_id)) << std::endl;
+ }
+
+
}
+void Reader::fetchPCFields()
+{
+
+
+ int iCol = 0;
+ char szFieldName[OWNAME];
+ int hType = 0;
+ int nSize = 0;
+ int nPrecision = 0;
+ signed short nScale = 0;
+ char szTypeName[OWNAME];
+
+ bool isPCObject = false;
+ bool isBlockTable = false;
+
+
+ const int columns_size = 10;
+ std::string block_columns[columns_size];
+ block_columns[0] = "OBJ_ID";
+ block_columns[1] = "BLK_ID";
+ block_columns[2] = "BLK_EXTENT";
+ block_columns[3] = "BLK_DOMAIN";
+ block_columns[4] = "PCBLK_MIN_RES";
+ block_columns[5] = "PCBLK_MAX_RES";
+ block_columns[6] = "NUM_POINTS";
+ block_columns[7] = "NUM_UNSORTED_POINTS";
+ block_columns[8] = "PT_SORT_DIM";
+ block_columns[9] = "POINTS";
+
+ std::map<std::string, bool> columns_map;
+
+ for(int i = 0; i < columns_size; ++i)
+ {
+ columns_map.insert(std::pair<std::string, bool>(block_columns[i], false));
+ }
+
+ while( m_statement->GetNextField(iCol, szFieldName, &hType, &nSize, &nPrecision, &nScale, szTypeName) )
+ {
+ std::string name = to_upper(std::string(szFieldName));
+
+ std::map<std::string, bool>::iterator it = columns_map.find(name);
+ if (it != columns_map.end())
+ {
+ // std::cout << "setting columns to true for " << it->first << std::endl;
+ (*it).second = true;
+
+ }
+
+ switch( hType )
+ {
+ case SQLT_FLT:
+ std::cout << "Field " << szFieldName << " is SQL_FLT" << std::endl;
+ break;
+ case SQLT_NUM:
+ if( nPrecision == 0 )
+ {
+ std::cout << "Field " << szFieldName << " is SQLT_NUM with precision 0" << std::endl;
+ }
+ else
+ {
+ std::cout << "Field " << szFieldName << " is SQLT_NUM with precision " << nPrecision << std::endl;
+
+ }
+ break;
+
+ case SQLT_BLOB:
+ std::cout << "Field " << szFieldName << " is SQLT_BLOB" << std::endl;
+ break;
+
+ case SQLT_NTY:
+ if (compare_no_case(szTypeName, "SDO_PC", 6) == 0)
+ isPCObject = true;
+ std::cout << "Field " << szFieldName << " is SQLT_NTY with type name " << szTypeName << std::endl;
+ break;
+
+ case SQLT_AFC:
+ case SQLT_CHR:
+ std::cout << "Field " << szFieldName << " is SQLT_CHR" << std::endl;
+ break;
+
+
+
+ case SQLT_DAT:
+ case SQLT_DATE:
+ case SQLT_TIMESTAMP:
+ case SQLT_TIMESTAMP_TZ:
+ case SQLT_TIMESTAMP_LTZ:
+ case SQLT_TIME:
+ case SQLT_TIME_TZ:
+ std::cout << "Field " << szFieldName << " is some kind of time type" << std::endl;
+
+ break;
+ default:
+ std::ostringstream oss;
+ oss << "Field " << szFieldName << " with type " << hType << " is not handled by fetchPCFields";
+ throw libpc_error(oss.str());
+ }
+
+ iCol++;
+ }
+
+ // Assume we're a block table until we say we aren't. Loop through all of
+ // the required columns that make up a block table and if we find one that
+ // wasn't marked in the loop above, we're not a block table.
+ isBlockTable = true;
+ std::map<std::string, bool>::iterator it = columns_map.begin();
+ while (it != columns_map.end())
+ {
+ if (it->second == false)
+ {
+ isBlockTable = false;
+ break;
+ }
+ ++it;
+ }
+
+
+ if (!isBlockTable && !isPCObject)
+ {
+ std::ostringstream oss;
+ std::string sql = m_options.GetPTree().get<std::string>("select_sql");
+ oss << "Select statement '" << sql << "' does not fetch an SDO_PC object"
+ " or one that is equivalent to SDO_PC_BLK_TYPE";
More information about the Liblas-commits
mailing list