+ sqlite logging cosmetics
This commit is contained in:
parent
406b3b92fa
commit
ce3e7e5eeb
4 changed files with 27 additions and 42 deletions
|
@ -34,9 +34,6 @@
|
||||||
#include <boost/tokenizer.hpp>
|
#include <boost/tokenizer.hpp>
|
||||||
#include <boost/filesystem/operations.hpp>
|
#include <boost/filesystem/operations.hpp>
|
||||||
|
|
||||||
using std::clog;
|
|
||||||
using std::endl;
|
|
||||||
|
|
||||||
using boost::lexical_cast;
|
using boost::lexical_cast;
|
||||||
using boost::bad_lexical_cast;
|
using boost::bad_lexical_cast;
|
||||||
|
|
||||||
|
@ -60,6 +57,7 @@ sqlite_datasource::sqlite_datasource(parameters const& params, bool bind)
|
||||||
extent_initialized_(false),
|
extent_initialized_(false),
|
||||||
type_(datasource::Vector),
|
type_(datasource::Vector),
|
||||||
table_(*params.get<std::string>("table","")),
|
table_(*params.get<std::string>("table","")),
|
||||||
|
fields_(*params.get<std::string>("fields","*")),
|
||||||
metadata_(*params.get<std::string>("metadata","")),
|
metadata_(*params.get<std::string>("metadata","")),
|
||||||
geometry_field_(*params.get<std::string>("geometry_field","the_geom")),
|
geometry_field_(*params.get<std::string>("geometry_field","the_geom")),
|
||||||
key_field_(*params.get<std::string>("key_field","OGC_FID")),
|
key_field_(*params.get<std::string>("key_field","OGC_FID")),
|
||||||
|
@ -69,7 +67,7 @@ sqlite_datasource::sqlite_datasource(parameters const& params, bool bind)
|
||||||
format_(mapnik::wkbGeneric)
|
format_(mapnik::wkbGeneric)
|
||||||
{
|
{
|
||||||
boost::optional<std::string> file = params.get<std::string>("file");
|
boost::optional<std::string> file = params.get<std::string>("file");
|
||||||
if (!file) throw datasource_exception("missing <file> parameter");
|
if (!file) throw datasource_exception("Sqlite Plugin: missing <file> parameter");
|
||||||
|
|
||||||
boost::optional<std::string> wkb = params.get<std::string>("wkb_format");
|
boost::optional<std::string> wkb = params.get<std::string>("wkb_format");
|
||||||
if (wkb)
|
if (wkb)
|
||||||
|
@ -100,7 +98,8 @@ void sqlite_datasource::bind() const
|
||||||
{
|
{
|
||||||
if (is_bound_) return;
|
if (is_bound_) return;
|
||||||
|
|
||||||
if (!boost::filesystem::exists(dataset_name_)) throw datasource_exception(dataset_name_ + " does not exist");
|
if (!boost::filesystem::exists(dataset_name_))
|
||||||
|
throw datasource_exception("Sqlite Plugin: " + dataset_name_ + " does not exist");
|
||||||
|
|
||||||
dataset_ = new sqlite_connection (dataset_name_);
|
dataset_ = new sqlite_connection (dataset_name_);
|
||||||
|
|
||||||
|
@ -109,8 +108,8 @@ void sqlite_datasource::bind() const
|
||||||
if (metadata_ != "" && ! extent_initialized_)
|
if (metadata_ != "" && ! extent_initialized_)
|
||||||
{
|
{
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
s << "select xmin, ymin, xmax, ymax from " << metadata_;
|
s << "SELECT xmin, ymin, xmax, ymax FROM " << metadata_;
|
||||||
s << " where lower(f_table_name) = lower('" << table_name << "')";
|
s << " WHERE LOWER(f_table_name) = LOWER('" << table_name << "')";
|
||||||
boost::scoped_ptr<sqlite_resultset> rs (dataset_->execute_query (s.str()));
|
boost::scoped_ptr<sqlite_resultset> rs (dataset_->execute_query (s.str()));
|
||||||
if (rs->is_valid () && rs->step_next())
|
if (rs->is_valid () && rs->step_next())
|
||||||
{
|
{
|
||||||
|
@ -127,8 +126,8 @@ void sqlite_datasource::bind() const
|
||||||
if (use_spatial_index_)
|
if (use_spatial_index_)
|
||||||
{
|
{
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
s << "select count (*) from sqlite_master";
|
s << "SELECT COUNT (*) FROM sqlite_master";
|
||||||
s << " where lower(name) = lower('idx_" << table_name << "_" << geometry_field_ << "')";
|
s << " WHERE LOWER(name) = LOWER('idx_" << table_name << "_" << geometry_field_ << "')";
|
||||||
boost::scoped_ptr<sqlite_resultset> rs (dataset_->execute_query (s.str()));
|
boost::scoped_ptr<sqlite_resultset> rs (dataset_->execute_query (s.str()));
|
||||||
if (rs->is_valid () && rs->step_next())
|
if (rs->is_valid () && rs->step_next())
|
||||||
{
|
{
|
||||||
|
@ -137,7 +136,7 @@ void sqlite_datasource::bind() const
|
||||||
|
|
||||||
#ifdef MAPNIK_DEBUG
|
#ifdef MAPNIK_DEBUG
|
||||||
if (! use_spatial_index_)
|
if (! use_spatial_index_)
|
||||||
clog << "cannot use the spatial index " << endl;
|
std::clog << "Sqlite Plugin: cannot use the spatial index " << std::endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +148,7 @@ void sqlite_datasource::bind() const
|
||||||
*/
|
*/
|
||||||
|
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
s << "select * from (" << table_name << ") limit 1";
|
s << "SELECT " << fields_ << " FROM (" << table_name << ") LIMIT 1";
|
||||||
|
|
||||||
boost::scoped_ptr<sqlite_resultset> rs (dataset_->execute_query (s.str()));
|
boost::scoped_ptr<sqlite_resultset> rs (dataset_->execute_query (s.str()));
|
||||||
if (rs->is_valid () && rs->step_next())
|
if (rs->is_valid () && rs->step_next())
|
||||||
|
@ -178,7 +177,7 @@ void sqlite_datasource::bind() const
|
||||||
|
|
||||||
default:
|
default:
|
||||||
#ifdef MAPNIK_DEBUG
|
#ifdef MAPNIK_DEBUG
|
||||||
clog << "unknown type_oid="<<type_oid<<endl;
|
std::clog << "Sqlite Plugin: unknown type_oid=" << type_oid << std::endl;
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -228,7 +227,7 @@ featureset_ptr sqlite_datasource::features(query const& q) const
|
||||||
|
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
|
|
||||||
s << "select " << geometry_field_ << "," << key_field_;
|
s << "SELECT " << geometry_field_ << "," << key_field_;
|
||||||
std::set<std::string> const& props = q.property_names();
|
std::set<std::string> const& props = q.property_names();
|
||||||
std::set<std::string>::const_iterator pos = props.begin();
|
std::set<std::string>::const_iterator pos = props.begin();
|
||||||
std::set<std::string>::const_iterator end = props.end();
|
std::set<std::string>::const_iterator end = props.end();
|
||||||
|
@ -238,7 +237,7 @@ featureset_ptr sqlite_datasource::features(query const& q) const
|
||||||
++pos;
|
++pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
s << " from ";
|
s << " FROM ";
|
||||||
|
|
||||||
std::string query (table_);
|
std::string query (table_);
|
||||||
|
|
||||||
|
@ -247,31 +246,31 @@ featureset_ptr sqlite_datasource::features(query const& q) const
|
||||||
std::string table_name = mapnik::table_from_sql(query);
|
std::string table_name = mapnik::table_from_sql(query);
|
||||||
std::ostringstream spatial_sql;
|
std::ostringstream spatial_sql;
|
||||||
spatial_sql << std::setprecision(16);
|
spatial_sql << std::setprecision(16);
|
||||||
spatial_sql << " where rowid in (select pkid from idx_" << table_name << "_" << geometry_field_;
|
spatial_sql << " WHERE rowid IN (SELECT pkid FROM idx_" << table_name << "_" << geometry_field_;
|
||||||
spatial_sql << " where xmax>=" << e.minx() << " and xmin<=" << e.maxx() ;
|
spatial_sql << " WHERE xmax>=" << e.minx() << " AND xmin<=" << e.maxx() ;
|
||||||
spatial_sql << " and ymax>=" << e.miny() << " and ymin<=" << e.maxy() << ")";
|
spatial_sql << " AND ymax>=" << e.miny() << " AND ymin<=" << e.maxy() << ")";
|
||||||
if (boost::algorithm::ifind_first(query,"where"))
|
if (boost::algorithm::ifind_first(query, "WHERE"))
|
||||||
{
|
{
|
||||||
boost::algorithm::ireplace_first(query, "where", spatial_sql.str() + " and");
|
boost::algorithm::ireplace_first(query, "WHERE", spatial_sql.str() + " AND ");
|
||||||
}
|
}
|
||||||
else if (boost::algorithm::find_first(query,table_name))
|
else if (boost::algorithm::ifind_first(query, table_name))
|
||||||
{
|
{
|
||||||
boost::algorithm::ireplace_first(query, table_name , table_name + " " + spatial_sql.str());
|
boost::algorithm::ireplace_first(query, table_name, table_name + " " + spatial_sql.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s << query ;
|
s << query ;
|
||||||
|
|
||||||
if (row_limit_ > 0) {
|
if (row_limit_ > 0) {
|
||||||
s << " limit " << row_limit_;
|
s << " LIMIT " << row_limit_;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (row_offset_ > 0) {
|
if (row_offset_ > 0) {
|
||||||
s << " offset " << row_offset_;
|
s << " OFFSET " << row_offset_;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MAPNIK_DEBUG
|
#ifdef MAPNIK_DEBUG
|
||||||
std::cerr << s.str() << "\n";
|
std::clog << "Sqlite Plugin: " << s.str() << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
boost::shared_ptr<sqlite_resultset> rs (dataset_->execute_query (s.str()));
|
boost::shared_ptr<sqlite_resultset> rs (dataset_->execute_query (s.str()));
|
||||||
|
@ -285,18 +284,6 @@ featureset_ptr sqlite_datasource::features(query const& q) const
|
||||||
featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt) const
|
featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt) const
|
||||||
{
|
{
|
||||||
if (!is_bound_) bind();
|
if (!is_bound_) bind();
|
||||||
#if 0
|
|
||||||
if (dataset_ && layer_)
|
|
||||||
{
|
|
||||||
OGRPoint point;
|
|
||||||
point.setX (pt.x);
|
|
||||||
point.setY (pt.y);
|
|
||||||
|
|
||||||
layer_->SetSpatialFilter (&point);
|
|
||||||
|
|
||||||
return featureset_ptr(new ogr_featureset(*dataset_, *layer_, desc_.get_encoding(), multiple_geometries_));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return featureset_ptr();
|
return featureset_ptr();
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,7 @@ class sqlite_datasource : public mapnik::datasource
|
||||||
std::string dataset_name_;
|
std::string dataset_name_;
|
||||||
mutable sqlite_connection* dataset_;
|
mutable sqlite_connection* dataset_;
|
||||||
std::string table_;
|
std::string table_;
|
||||||
|
std::string fields_;
|
||||||
std::string metadata_;
|
std::string metadata_;
|
||||||
std::string geometry_field_;
|
std::string geometry_field_;
|
||||||
std::string key_field_;
|
std::string key_field_;
|
||||||
|
|
|
@ -33,9 +33,6 @@
|
||||||
// ogr
|
// ogr
|
||||||
#include "sqlite_featureset.hpp"
|
#include "sqlite_featureset.hpp"
|
||||||
|
|
||||||
using std::clog;
|
|
||||||
using std::endl;
|
|
||||||
|
|
||||||
using mapnik::query;
|
using mapnik::query;
|
||||||
using mapnik::box2d;
|
using mapnik::box2d;
|
||||||
using mapnik::CoordTransform;
|
using mapnik::CoordTransform;
|
||||||
|
@ -68,7 +65,7 @@ feature_ptr sqlite_featureset::next()
|
||||||
int feature_id = rs_->column_integer (1);
|
int feature_id = rs_->column_integer (1);
|
||||||
|
|
||||||
#ifdef MAPNIK_DEBUG
|
#ifdef MAPNIK_DEBUG
|
||||||
// clog << "feature_oid=" << feature_id << endl;
|
// std::clog << "Sqlite Plugin: feature_oid=" << feature_id << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
feature_ptr feature(new Feature(feature_id));
|
feature_ptr feature(new Feature(feature_id));
|
||||||
|
@ -106,7 +103,7 @@ feature_ptr sqlite_featureset::next()
|
||||||
|
|
||||||
default:
|
default:
|
||||||
#ifdef MAPNIK_DEBUG
|
#ifdef MAPNIK_DEBUG
|
||||||
clog << "unhandled type_oid=" << type_oid << endl;
|
std::clog << "Sqlite Plugin: unhandled type_oid=" << type_oid << std::endl;
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,7 +141,7 @@ public:
|
||||||
int rc = sqlite3_prepare_v2 (db_, sql.c_str(), -1, &stmt, 0);
|
int rc = sqlite3_prepare_v2 (db_, sql.c_str(), -1, &stmt, 0);
|
||||||
if (rc != SQLITE_OK)
|
if (rc != SQLITE_OK)
|
||||||
{
|
{
|
||||||
std::clog << sqlite3_errmsg(db_) << std::endl;
|
std::clog << "Sqlite Plugin: " << sqlite3_errmsg(db_) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new sqlite_resultset (stmt);
|
return new sqlite_resultset (stmt);
|
||||||
|
|
Loading…
Reference in a new issue