std::string Writer::ShutOff_SDO_PC_Trigger() { std::string base_table_name = boost::to_upper_copy(getOptions().getValueOrThrow<std::string>("base_table_name")); std::string cloud_column_name = boost::to_upper_copy(getOptions().getValueOrThrow<std::string>("cloud_column_name")); // Don't monkey with the trigger unless the user says to. if (!getOptions().getValueOrDefault<bool>("disable_cloud_trigger", false)) return std::string(""); std::ostringstream oss; char szTrigger[OWNAME] = ""; char szStatus[OWNAME] = ""; oss << "select trigger_name, status from all_triggers where table_name = '" << base_table_name << "' AND TRIGGER_NAME like upper('%%MDTNPC_%%') "; Statement statement = Statement(m_connection->CreateStatement(oss.str().c_str())); statement->Define(szTrigger); statement->Define(szStatus); statement->Execute(); // Yes, we're assuming there's only one trigger that met these criteria. if (!strlen(szStatus)) { // No rows returned, no trigger exists return std::string(""); } if (boost::iequals(szStatus, "ENABLED")) { oss.str(""); oss << "ALTER TRIGGER " << szTrigger << " DISABLE "; statement = Statement(m_connection->CreateStatement(oss.str().c_str())); statement->Execute(); return std::string(szTrigger); } else { return std::string(""); } }
bool Writer::IsGeographic(boost::int32_t srid) { typedef boost::shared_ptr<long> shared_long; typedef boost::shared_ptr<char> shared_char; std::ostringstream oss; // char* kind = (char* ) malloc (OWNAME * sizeof(char)); shared_char kind = boost::shared_ptr<char>(new char[OWNAME]); oss << "SELECT COORD_REF_SYS_KIND from MDSYS.SDO_COORD_REF_SYSTEM WHERE SRID = :1"; Statement statement = Statement(m_connection->CreateStatement(oss.str().c_str())); shared_long p_srid = boost::shared_ptr<long>(new long); *p_srid = srid; statement->Bind(p_srid.get()); statement->Define(kind.get()); try { statement->Execute(); } catch (pdal_error const& e) { std::ostringstream oss; oss << "Failed to fetch geographicness of srid " << srid << std::endl << e.what() << std::endl; throw std::runtime_error(oss.str()); } if (boost::iequals(kind.get(), "GEOGRAPHIC2D")) { return true; } if (boost::iequals(kind.get(), "GEOGRAPHIC3D")) { return true; } return false; }
bool Writer::BlockTableExists() { std::ostringstream oss; std::string block_table_name = getOptions().getValueOrThrow<std::string>("block_table_name"); char szTable[OWNAME]= ""; oss << "select table_name from user_tables"; log()->get(logDEBUG) << "checking for " << block_table_name << " existence ... " ; Statement statement = Statement(m_connection->CreateStatement(oss.str().c_str())); // Because of OCIGDALErrorHandler, this is going to throw if there is a // problem. When it does, the statement should go out of scope and // be destroyed without leaking. statement->Define(szTable); statement->Execute(); log()->get(logDEBUG) << "checking ... " << szTable ; bool bDidRead(true); while (bDidRead) { log()->get(logDEBUG) << ", " << szTable; if (boost::iequals(szTable, block_table_name)) { log()->get(logDEBUG) << " -- '" << block_table_name << "' found." <<std::endl; return true; } bDidRead = statement->Fetch(); } log()->get(logDEBUG) << " -- '" << block_table_name << "' not found." << std::endl; return false; }
void OciReader::defineBlock(Statement stmt, BlockPtr block) const { int iCol = 0; char szFieldName[OWNAME]; int hType = 0; int nSize = 0; int nPrecision = 0; signed short nScale = 0; char szTypeName[OWNAME]; while (stmt->GetNextField(iCol, szFieldName, &hType, &nSize, &nPrecision, &nScale, szTypeName)) { std::string typeName = Utils::toupper(szTypeName); std::string fieldName = Utils::toupper(szFieldName); if (hType == SQLT_NTY && (typeName == "SDO_PC")) stmt->Define(&(block->pc)); else if (fieldName == "OBJ_ID") stmt->Define(&(block->obj_id)); else if (fieldName == "BLK_ID") stmt->Define(&(block->blk_id)); else if (fieldName == "BLK_EXTENT") stmt->Define(&(block->blk_extent)); else if (fieldName == "BLK_DOMAIN") stmt->Define(&(block->blk_domain)); else if (fieldName == "PCBLK_MIN_RES") stmt->Define(&(block->pcblk_min_res)); else if (fieldName == "PCBLK_MAX_RES") stmt->Define(&(block->pcblk_max_res)); else if (fieldName == "NUM_POINTS") stmt->Define(&(block->num_points)); else if (fieldName == "NUM_UNSORTED_POINTS") stmt->Define(&(block->num_unsorted_points)); else if (fieldName == "PT_SORT_DIM") stmt->Define(&(block->pt_sort_dim)); else if (fieldName == "POINTS") stmt->Define(&(block->locator)); iCol++; } }
bool Writer::WriteBlock(PointBuffer const& buffer) { bool bUsePartition = m_block_table_partition_column.size() != 0; // Pluck the block id out of the first point in the buffer pdal::Schema const& schema = buffer.getSchema(); Dimension const& blockDim = schema.getDimension("BlockID"); boost::int32_t block_id = buffer.getField<boost::int32_t>(blockDim, 0); std::ostringstream oss; std::ostringstream partition; if (bUsePartition) { partition << "," << m_block_table_partition_column; } oss << "INSERT INTO "<< m_block_table_name << "(OBJ_ID, BLK_ID, NUM_POINTS, POINTS, " "PCBLK_MIN_RES, BLK_EXTENT, PCBLK_MAX_RES, NUM_UNSORTED_POINTS, PT_SORT_DIM"; if (bUsePartition) oss << partition.str(); oss << ") " "VALUES ( :1, :2, :3, :4, 1, mdsys.sdo_geometry(:5, :6, null,:7, :8)" ", 1, 0, 1"; if (bUsePartition) oss << ", :9"; oss <<")"; // TODO: If gotdata == false below, this memory probably leaks --mloskot OCILobLocator** locator =(OCILobLocator**) VSIMalloc(sizeof(OCILobLocator*) * 1); Statement statement = Statement(m_connection->CreateStatement(oss.str().c_str())); long* p_pc_id = (long*) malloc(1 * sizeof(long)); p_pc_id[0] = m_pc_id; long* p_result_id = (long*) malloc(1 * sizeof(long)); p_result_id[0] = (long)block_id; long* p_num_points = (long*) malloc(1 * sizeof(long)); p_num_points[0] = (long)buffer.getNumPoints(); // std::cout << "point count on write: " << buffer.getNumPoints() << std::endl; // :1 statement->Bind(&m_pc_id); // :2 statement->Bind(p_result_id); // :3 statement->Bind(p_num_points); // :4 statement->Define(locator, 1); // std::vector<liblas::uint8_t> data; // bool gotdata = GetResultData(result, reader, data, 3); // if (! gotdata) throw std::runtime_error("unable to fetch point data byte array"); // boost::uint8_t* point_data = buffer.getData(0); boost::uint8_t* point_data; boost::uint32_t point_data_length; boost::uint32_t schema_byte_size; bool pack = getOptions().getValueOrDefault<bool>("pack_ignored_fields", true); if (pack) PackPointData(buffer, &point_data, point_data_length, schema_byte_size); else { point_data = buffer.getData(0); point_data_length = buffer.getSchema().getByteSize() * buffer.getNumPoints(); } // statement->Bind((char*)point_data,(long)(buffer.getSchema().getByteSize()*buffer.getNumPoints())); statement->Bind((char*)point_data,(long)(point_data_length)); // :5 long* p_gtype = (long*) malloc(1 * sizeof(long)); p_gtype[0] = m_gtype; statement->Bind(p_gtype); // :6 long* p_srid = 0; if (m_srid != 0) { p_srid = (long*) malloc(1 * sizeof(long)); p_srid[0] = m_srid; } statement->Bind(p_srid); // :7 OCIArray* sdo_elem_info=0; m_connection->CreateType(&sdo_elem_info, m_connection->GetElemInfoType()); SetElements(statement, sdo_elem_info); statement->Bind(&sdo_elem_info, m_connection->GetElemInfoType()); // :8 OCIArray* sdo_ordinates=0; m_connection->CreateType(&sdo_ordinates, m_connection->GetOrdinateType()); // x0, x1, y0, y1, z0, z1, bUse3d pdal::Bounds<double> bounds = CalculateBounds(buffer); SetOrdinates(statement, sdo_ordinates, bounds); statement->Bind(&sdo_ordinates, m_connection->GetOrdinateType()); // :9 long* p_partition_d = 0; if (bUsePartition) { p_partition_d = (long*) malloc(1 * sizeof(long)); p_partition_d[0] = m_block_table_partition_value; statement->Bind(p_partition_d); } try { statement->Execute(); } catch (std::runtime_error const& e) { std::ostringstream oss; oss << "Failed to insert block # into '" << m_block_table_name << "' table. Does the table exist? " << std::endl << e.what() << std::endl; throw std::runtime_error(oss.str()); } oss.str(""); OWStatement::Free(locator, 1); if (p_pc_id != 0) free(p_pc_id); if (p_result_id != 0) free(p_result_id); if (p_num_points != 0) free(p_num_points); if (p_gtype != 0) free(p_gtype); if (p_srid != 0) free(p_srid); if (p_partition_d != 0) free(p_partition_d); m_connection->DestroyType(&sdo_elem_info); m_connection->DestroyType(&sdo_ordinates); return true; }