From 70a191e8d756eed82e722fc5b173d6ec62676b16 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 5 Dec 2011 13:57:00 -0800 Subject: [PATCH] ogr plugin: throw if non-existant fields are queried - refs #792 --- plugins/input/ogr/ogr_datasource.cpp | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/plugins/input/ogr/ogr_datasource.cpp b/plugins/input/ogr/ogr_datasource.cpp index 997cb0bfd..7fbca6486 100644 --- a/plugins/input/ogr/ogr_datasource.cpp +++ b/plugins/input/ogr/ogr_datasource.cpp @@ -356,6 +356,43 @@ featureset_ptr ogr_datasource::features(query const& q) const if (dataset_ && layer_.is_valid()) { + // First we validate query fields: https://github.com/mapnik/mapnik/issues/792 + std::vector const& desc_ar = desc_.get_descriptors(); + std::vector::const_iterator it = desc_ar.begin(); + std::vector::const_iterator end = desc_ar.end(); + std::vector known_fields; + for (; it != end; ++it) + { + known_fields.push_back(it->get_name()); + } + + const std::set& attribute_names = q.property_names(); + std::set::const_iterator pos = attribute_names.begin(); + while (pos != attribute_names.end()) + { + bool found_name = false; + for (int i = 0; i < known_fields.size(); ++i) + { + if (known_fields[i] == *pos) + { + found_name = true; + break; + } + } + + if (! found_name) + { + std::ostringstream s; + + s << "OGR Plugin: no attribute '" << *pos << "'. Valid attributes are: " + << boost::algorithm::join(known_fields, ",") << "."; + + throw mapnik::datasource_exception(s.str()); + } + ++pos; + } + + OGRLayer* layer = layer_.layer(); if (indexed_)