From aa6da2dce99c7e89063bd9722dcb0199452febb2 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 23 Jan 2012 23:51:31 -0800 Subject: [PATCH] collect context before featureset creation in sqlite --- plugins/input/sqlite/sqlite_datasource.cpp | 23 +++++++++++++++++----- plugins/input/sqlite/sqlite_featureset.cpp | 7 ++----- plugins/input/sqlite/sqlite_featureset.hpp | 1 + 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/plugins/input/sqlite/sqlite_datasource.cpp b/plugins/input/sqlite/sqlite_datasource.cpp index 2cd3f11e0..7a7529584 100644 --- a/plugins/input/sqlite/sqlite_datasource.cpp +++ b/plugins/input/sqlite/sqlite_datasource.cpp @@ -547,19 +547,24 @@ featureset_ptr sqlite_datasource::features(query const& q) const mapnik::box2d const& e = q.get_bbox(); std::ostringstream s; + mapnik::context_ptr ctx = boost::make_shared(); s << "SELECT " << geometry_field_; if (!key_field_.empty()) + { s << "," << key_field_; + ctx->push(key_field_); + } std::set const& props = q.property_names(); std::set::const_iterator pos = props.begin(); std::set::const_iterator end = props.end(); - while (pos != end) + + for ( ;pos != end;++pos) { // TODO - should we restrict duplicate key query? //if (*pos != key_field_) s << ",[" << *pos << "]"; - ++pos; + ctx->push(*pos); } s << " FROM "; @@ -601,6 +606,7 @@ featureset_ptr sqlite_datasource::features(query const& q) const boost::shared_ptr rs(dataset_->execute_query(s.str())); return boost::make_shared(rs, + ctx, desc_.get_encoding(), format_, using_subquery_); @@ -619,20 +625,26 @@ featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt) const mapnik::box2d const e(pt.x, pt.y, pt.x, pt.y); std::ostringstream s; + mapnik::context_ptr ctx = boost::make_shared(); + s << "SELECT " << geometry_field_; if (!key_field_.empty()) + { s << "," << key_field_; + ctx->push(key_field_); + } + std::vector::const_iterator itr = desc_.get_descriptors().begin(); std::vector::const_iterator end = desc_.get_descriptors().end(); - while (itr != end) + + for ( ; itr != end; ++itr) { std::string fld_name = itr->get_name(); if (fld_name != key_field_) { s << ",[" << itr->get_name() << "]"; + ctx->push(itr->get_name()); } - - ++itr; } s << " FROM "; @@ -674,6 +686,7 @@ featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt) const boost::shared_ptr rs(dataset_->execute_query(s.str())); return boost::make_shared(rs, + ctx, desc_.get_encoding(), format_, using_subquery_); diff --git a/plugins/input/sqlite/sqlite_featureset.cpp b/plugins/input/sqlite/sqlite_featureset.cpp index 4e7fbe6df..dc9aeb5d8 100644 --- a/plugins/input/sqlite/sqlite_featureset.cpp +++ b/plugins/input/sqlite/sqlite_featureset.cpp @@ -45,6 +45,7 @@ using mapnik::transcoder; using mapnik::feature_factory; sqlite_featureset::sqlite_featureset(boost::shared_ptr rs, + mapnik::context_ptr const& ctx, std::string const& encoding, mapnik::wkbFormat format, bool using_subquery) @@ -52,12 +53,8 @@ sqlite_featureset::sqlite_featureset(boost::shared_ptr rs, tr_(new transcoder(encoding)), format_(format), using_subquery_(using_subquery), - ctx_(boost::make_shared()) + ctx_(ctx) { - for (int i = 2; i < rs_->column_count(); ++i) - { - ctx_->push(rs_->column_name(i)); - } } sqlite_featureset::~sqlite_featureset() diff --git a/plugins/input/sqlite/sqlite_featureset.hpp b/plugins/input/sqlite/sqlite_featureset.hpp index cddc5d89f..b7feb7386 100644 --- a/plugins/input/sqlite/sqlite_featureset.hpp +++ b/plugins/input/sqlite/sqlite_featureset.hpp @@ -40,6 +40,7 @@ class sqlite_featureset : public mapnik::Featureset { public: sqlite_featureset(boost::shared_ptr rs, + mapnik::context_ptr const& ctx, std::string const& encoding, mapnik::wkbFormat format, bool using_subquery);