/** * Create and run the basic query on the gridvalue table, for use by the wciReadFloat function */ static void runWciReadFloatQueryGrid(struct ReadStore * out, FuncCallContext * funcctx, FunctionCallInfo fcinfo) { initializeGeos(); struct WciReadParameterCollection p; parseReadParameters(& p, fcinfo); const char * whatToSelect = "value, dataprovidername, placename::text, placegeometry, referencetime, validtimefrom, validtimeto, validtimeindeterminatecode, valueparametername, valueunitname, levelparametername, levelunitname, levelfrom, levelto, levelindeterminatecode, dataversion, confidencecode, valuestoretime, valueid, valuetype, placeid"; const char * gridQuery = build_query(& p, GridTable, OutputFloat, whatToSelect, NULL); elog(DEBUG1, gridQuery); // Perform primary query SPIPlanPtr queryPlan = getSpiPlan(gridQuery); if (SPI_OK_SELECT != SPI_execute_plan(queryPlan, NULL, NULL, true, 0)) { ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg( "Error when performing base query"))); } MemoryContext oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); if ( PG_ARGISNULL(1) ) { ReadStoreGridReturnInit(out, SPI_tuptable, SPI_processed, NULL); } else { text * location_t = PG_GETARG_TEXT_P(1); const char * location = TextPGetCString(location_t); ReadStoreGridReturnInit(out, SPI_tuptable, SPI_processed, location); } MemoryContextSwitchTo(oldcontext); }
Datum getWciBrowseValueParameterQuery(PG_FUNCTION_ARGS) { struct WciReadParameterCollection p; parseReadParameters(& p, fcinfo); const char * query = build_query(& p, GridTable, OutputGid, "valueparametername, valueunitname, count(*)", "GROUP BY valueparametername, valueunitname"); text * ret = CStringGetTextP(query); PG_RETURN_TEXT_P(ret); }
Datum getWciBrowsePlaceQuery(PG_FUNCTION_ARGS) { struct WciReadParameterCollection p; parseReadParameters(& p, fcinfo); const char * query = build_query(& p, GridTable, OutputGid, "placename, min(referencetime), max(referencetime), count(*)", "GROUP BY placename"); text * ret = CStringGetTextP(query); PG_RETURN_TEXT_P(ret); }
Datum getWciBrowseLevelParameterQuery(PG_FUNCTION_ARGS) { struct WciReadParameterCollection p; parseReadParameters(& p, fcinfo); const char * query = build_query(& p, GridTable, OutputGid, "levelparametername, levelunitname, min(levelfrom), max(levelto), count(*)", "GROUP BY levelparametername, levelunitname"); text * ret = CStringGetTextP(query); PG_RETURN_TEXT_P(ret); }
Datum getWciBrowseDataVersionQuery(PG_FUNCTION_ARGS) { struct WciReadParameterCollection p; parseReadParameters(& p, fcinfo); const char * query = build_query(& p, GridTable, OutputGid, "dataversion, count(*)", "GROUP BY 1 ORDER BY 1"); text * ret = CStringGetTextP(query); PG_RETURN_TEXT_P(ret); }
/** * Create and run the basic query on the floatvalue table, for use by the wciReadFloat function */ static void runWciReadFloatQueryFloat(struct ReadStore * out, FunctionCallInfo fcinfo) { struct WciReadParameterCollection p; parseReadParameters(& p, fcinfo); // This must match exactly the return type for wci.returnfloat const char * whatToSelect = "value::float, dataprovidername, placename::text, st_astext(placegeometry), referencetime, validtimefrom, validtimeto, validtimeindeterminatecode, valueparametername, valueunitname, levelparametername, levelunitname, levelfrom, levelto, levelindeterminatecode, dataversion, confidencecode, valuestoretime, valueid, valuetype"; const char * gridQuery = build_query(& p, FloatTable, OutputFloat, whatToSelect, NULL); elog(DEBUG1, gridQuery); // Perform primary query SPIPlanPtr queryPlan = getSpiPlan(gridQuery); if (SPI_OK_SELECT != SPI_execute_plan(queryPlan, NULL, NULL, true, 0)) { ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg( "Error when performing base query"))); } out->tuples = SPI_tuptable; out->tupleCount = SPI_processed; }