postgis: test !@uservar! interpolation

This commit is contained in:
Mickey Rose 2017-02-08 21:05:52 +01:00
parent 6bbb391005
commit a13cb382e0

View file

@ -26,6 +26,7 @@
#include <mapnik/datasource.hpp> #include <mapnik/datasource.hpp>
#include <mapnik/datasource_cache.hpp> #include <mapnik/datasource_cache.hpp>
#include <mapnik/geometry/geometry_type.hpp> #include <mapnik/geometry/geometry_type.hpp>
#include <mapnik/unicode.hpp>
#include <mapnik/util/fs.hpp> #include <mapnik/util/fs.hpp>
/* /*
@ -303,6 +304,40 @@ TEST_CASE("postgis") {
} }
} }
SECTION("Postgis interpolates !@uservar! tokens in query")
{
mapnik::parameters params(base_params);
params["table"] = "(SELECT * FROM public.test"
" WHERE GeometryType(geom) = !@wantedGeomType!"
" LIMIT 1) AS data";
auto ds = mapnik::datasource_cache::instance().create(params);
REQUIRE(ds != nullptr);
mapnik::transcoder tr("utf8");
mapnik::query qry(ds->envelope());
qry.set_variables({{"wantedGeomType", tr.transcode("POINT")}});
CHECK(qry.variables().count("wantedGeomType") == 1);
auto featureset = ds->features(qry);
auto feature = featureset->next();
CHECKED_IF(feature != nullptr)
{
auto const& geom = feature->get_geometry();
CHECK(mapnik::geometry::geometry_type(geom) == mapnik::geometry::Point);
}
qry.set_variables({{"wantedGeomType", tr.transcode("POLYGON")}});
CHECK(qry.variables().count("wantedGeomType") == 1);
featureset = ds->features(qry);
feature = featureset->next();
CHECKED_IF(feature != nullptr)
{
auto const& geom = feature->get_geometry();
CHECK(mapnik::geometry::geometry_type(geom) == mapnik::geometry::Polygon);
}
}
SECTION("Postgis query extent: full dataset") SECTION("Postgis query extent: full dataset")
{ {
//include schema to increase coverage //include schema to increase coverage