bool BlockTableExists(OWConnection* connection, std::string tableName) { std::ostringstream oss; char szTable[OWNAME]= ""; oss << "select table_name from user_tables where table_name like upper('%%"<< tableName <<"%%') "; OWStatement* statement = 0; statement = connection->CreateStatement(oss.str().c_str()); statement->Define(szTable); try { statement->Execute(); } catch (std::runtime_error const& ) { // Assume for now that an error returned here is OCI_NODATA, which means // the table doesn't exist. If this really isn't the case, we're going // to get more legit message further down the line. return false; // delete statement; // std::ostringstream oss; // oss << "Failed select if block table "<< tableName << " exists. Do you have rights to select?" // << std::endl << e.what() << std::endl; // throw std::runtime_error(oss.str()); } return true; }
bool IsGeographic(OWConnection* connection, long srid) { std::ostringstream oss; char* kind = (char* ) malloc (OWNAME * sizeof(char)); oss << "SELECT COORD_REF_SYS_KIND from MDSYS.SDO_COORD_REF_SYSTEM WHERE SRID = :1"; OWStatement* statement = 0; statement = connection->CreateStatement(oss.str().c_str()); long* p_srid = (long*) malloc( 1 * sizeof(long)); p_srid[0] = srid; statement->Bind(p_srid); statement->Define(kind); try { statement->Execute(); } catch (std::runtime_error const& e) { delete statement; std::ostringstream oss; oss << "Failed to fetch geographicness of srid " << srid << std::endl << e.what() << std::endl; throw std::runtime_error(oss.str()); } if (compare_no_case(kind, "GEOGRAPHIC2D",12) == 0) { delete statement; free(kind); free(p_srid); return true; } if (compare_no_case(kind, "GEOGRAPHIC3D",12) == 0) { delete statement; free(kind); free(p_srid); return true; } free(kind); free(p_srid); return false; }
const GDALRasterAttributeTable *GeoRasterRasterBand::GetDefaultRAT() { if( poDefaultRAT ) { return poDefaultRAT->Clone(); } else { poDefaultRAT = new GDALRasterAttributeTable(); } GeoRasterDataset* poGDS = (GeoRasterDataset*) poDS; // ---------------------------------------------------------- // Get the name of the VAT Table // ---------------------------------------------------------- char* pszVATName = poGDS->poGeoRaster->GetVAT( nBand ); if( pszVATName == NULL ) { return NULL; } OCIParam* phDesc = NULL; phDesc = poGDS->poGeoRaster->poConnection->GetDescription( pszVATName ); if( phDesc == NULL ) { return NULL; } // ---------------------------------------------------------- // Create the RAT and the SELECT statemet based on fields description // ---------------------------------------------------------- int iCol = 0; char szField[OWNAME]; int hType = 0; int nSize = 0; int nPrecision = 0; signed short nScale = 0; char szColumnList[OWTEXT]; szColumnList[0] = '\0'; while( poGDS->poGeoRaster->poConnection->GetNextField( phDesc, iCol, szField, &hType, &nSize, &nPrecision, &nScale ) ) { switch( hType ) { case SQLT_FLT: poDefaultRAT->CreateColumn( szField, GFT_Real, GFU_Generic ); break; case SQLT_NUM: if( nPrecision == 0 ) { poDefaultRAT->CreateColumn( szField, GFT_Integer, GFU_Generic ); } else { poDefaultRAT->CreateColumn( szField, GFT_Real, GFU_Generic ); } break; case SQLT_CHR: case SQLT_AFC: case SQLT_DAT: case SQLT_DATE: case SQLT_TIMESTAMP: case SQLT_TIMESTAMP_TZ: case SQLT_TIMESTAMP_LTZ: case SQLT_TIME: case SQLT_TIME_TZ: poDefaultRAT->CreateColumn( szField, GFT_String, GFU_Generic ); break; default: CPLDebug("GEORASTER", "VAT (%s) Column (%s) type (%d) not supported" "as GDAL RAT", pszVATName, szField, hType ); continue; } strcpy( szColumnList, CPLSPrintf( "%s substr(%s,1,%d),", szColumnList, szField, MIN(nSize,OWNAME) ) ); iCol++; } szColumnList[strlen(szColumnList) - 1] = '\0'; // remove the last comma // ---------------------------------------------------------- // Read VAT and load RAT // ---------------------------------------------------------- OWStatement* poStmt = NULL; poStmt = poGeoRaster->poConnection->CreateStatement( CPLSPrintf ( "SELECT %s FROM %s", szColumnList, pszVATName ) ); char** papszValue = (char**) CPLMalloc( sizeof(char**) * iCol ); int i = 0; for( i = 0; i < iCol; i++ ) { papszValue[i] = (char*) CPLMalloc( sizeof(char*) * OWNAME ); poStmt->Define( papszValue[i] ); } if( ! poStmt->Execute() ) { CPLError( CE_Failure, CPLE_AppDefined, "Error reading VAT %s", pszVATName ); return NULL; } int iRow = 0; while( poStmt->Fetch() ) { for( i = 0; i < iCol; i++ ) { poDefaultRAT->SetValue( iRow, i, papszValue[i] ); } iRow++; } for( i = 0; i < iCol; i++ ) { CPLFree( papszValue[i] ); } CPLFree( papszValue ); delete poStmt; CPLFree( pszVATName ); return poDefaultRAT; }