char * build_query(const struct WciReadParameterCollection * parameters, enum DataSource dataSource, enum OutputType output, const char * selectWhat, const char * ordering, const char * groupby) { try { query::Builder builder; if ( dataSource == FloatTable ) builder.from(WCI_SCHEMA".floatvalue_v v"); else // dataSource == GridTable builder.from(WCI_SCHEMA".gridvalue_v v"); builder.what(selectWhat); if ( parameters ) { addDataProviderQuery(builder, parameters->dataProvider); addReferenceTimeQuery(builder, parameters->referenceTime); addValidTimeQuery(builder, parameters->validTime); addParameterQuery(builder, parameters->parameter); addLevelQuery(builder, parameters->level); addDataVersionQuery(builder, parameters->dataVersion); addLocationQuery(builder, parameters->location, dataSource, output); } if ( ordering ) builder.orderBy(ordering); if ( groupby ) builder.groupBy(groupby); //builder.debugPrint(std::cout) << std::flush; std::string ret = builder.str(); return pstrdup(ret.c_str()); } catch (std::exception & e) { ereport( ERROR, ( errcode( ERRCODE_DATA_EXCEPTION ), errmsg( "%s", pstrdup(e.what()) ) ) ); } catch ( ... ) { ereport( ERROR, ( errcode( ERRCODE_RAISE_EXCEPTION ), errmsg( "Unrecognized error" ) ) ); } // Never reached: return NULL; }
char * build_query(const struct WciReadParameterCollection * parameters, enum DataSource dataSource, enum OutputType output, const char * selectWhat, const char * ordering) { try { std::ostringstream q; q << "SELECT "<< selectWhat << " FROM "; if ( dataSource == FloatTable ) q << WCI_SCHEMA << ".floatvalue v "; else // dataSource == GridTable q << WCI_SCHEMA << ".gridvalue v "; if ( parameters ) { std::ostringstream w; addDataProviderQuery(w, parameters->dataProvider); addReferenceTimeQuery(w, parameters->referenceTime); addValidTimeQuery(w, parameters->validTime); addParameterQuery(w, parameters->parameter); addLevelQuery(w, parameters->level); addDataVersionQuery(w, parameters->dataVersion); addLocationQuery(w, parameters->location, dataSource, output); q << "WHERE " << w.str(); } if ( ordering ) { q << ordering; } std::string ret = q.str(); return pstrdup(ret.c_str()); } catch (std::exception & e) { ereport( ERROR, ( errcode( ERRCODE_DATA_EXCEPTION ), errmsg( pstrdup(e.what()) ) ) ); } catch ( ... ) { ereport( ERROR, ( errcode( ERRCODE_RAISE_EXCEPTION ), errmsg( "Unrecognized error" ) ) ); } // Never reached: return NULL; }