+ occi plugin: fix table_from_sql namespace

+ occi plugin: space cosmetics
This commit is contained in:
Lucio Asnaghi 2010-11-15 09:25:06 +00:00
parent 73270bd76b
commit e0363a6bbe

View file

@ -85,7 +85,7 @@ occi_datasource::occi_datasource(parameters const& params, bool bind)
boost::optional<std::string> ext = params_.get<std::string>("extent"); boost::optional<std::string> ext = params_.get<std::string>("extent");
if (ext) extent_initialized_ = extent_.from_string(*ext); if (ext) extent_initialized_ = extent_.from_string(*ext);
if (bind) if (bind)
{ {
this->bind(); this->bind();
@ -94,11 +94,11 @@ occi_datasource::occi_datasource(parameters const& params, bool bind)
void occi_datasource::bind() const void occi_datasource::bind() const
{ {
if (is_bound_) return; if (is_bound_) return;
boost::optional<int> initial_size = params_.get<int>("initial_size",1); boost::optional<int> initial_size = params_.get<int>("initial_size",1);
boost::optional<int> max_size = params_.get<int>("max_size",10); boost::optional<int> max_size = params_.get<int>("max_size",10);
// connect to environment // connect to environment
try try
{ {
@ -218,7 +218,7 @@ void occi_datasource::bind() const
clog << "unknown type_oid="<<type_oid<<endl; clog << "unknown type_oid="<<type_oid<<endl;
#endif #endif
break; break;
} }
} }
} }
} }
@ -226,8 +226,8 @@ void occi_datasource::bind() const
{ {
throw datasource_exception(ex.getMessage()); throw datasource_exception(ex.getMessage());
} }
} }
is_bound_ = true; is_bound_ = true;
} }
@ -259,7 +259,7 @@ box2d<double> occi_datasource::envelope() const
occi_connection_ptr conn (pool_); occi_connection_ptr conn (pool_);
boost::optional<mapnik::boolean> estimate_extent = params_.get<mapnik::boolean>("estimate_extent",false); boost::optional<mapnik::boolean> estimate_extent = params_.get<mapnik::boolean>("estimate_extent",false);
if (estimate_extent && *estimate_extent) if (estimate_extent && *estimate_extent)
{ {
std::ostringstream s; std::ostringstream s;
@ -272,12 +272,12 @@ box2d<double> occi_datasource::envelope() const
ResultSet* rs = conn.execute_query (s.str()); ResultSet* rs = conn.execute_query (s.str());
if (rs && rs->next ()) if (rs && rs->next ())
{ {
try try
{ {
lox = lexical_cast<double>(rs->getDouble(1)); lox = lexical_cast<double>(rs->getDouble(1));
loy = lexical_cast<double>(rs->getDouble(2)); loy = lexical_cast<double>(rs->getDouble(2));
hix = lexical_cast<double>(rs->getDouble(3)); hix = lexical_cast<double>(rs->getDouble(3));
hiy = lexical_cast<double>(rs->getDouble(4)); hiy = lexical_cast<double>(rs->getDouble(4));
extent_.init (lox,loy,hix,hiy); extent_.init (lox,loy,hix,hiy);
extent_initialized_ = true; extent_initialized_ = true;
} }
@ -301,13 +301,13 @@ box2d<double> occi_datasource::envelope() const
s << "select dim.sdo_lb as lx, dim.sdo_ub as ux from "; s << "select dim.sdo_lb as lx, dim.sdo_ub as ux from ";
s << SDO_GEOMETRY_METADATA_TABLE << " m, table(m.diminfo) dim "; s << SDO_GEOMETRY_METADATA_TABLE << " m, table(m.diminfo) dim ";
s << " where lower(m.table_name) = '" << table_name << "' and dim.sdo_dimname = 'X'"; s << " where lower(m.table_name) = '" << table_name << "' and dim.sdo_dimname = 'X'";
try try
{ {
ResultSet* rs = conn.execute_query (s.str()); ResultSet* rs = conn.execute_query (s.str());
if (rs && rs->next ()) if (rs && rs->next ())
{ {
try try
{ {
lox = lexical_cast<double>(rs->getDouble(1)); lox = lexical_cast<double>(rs->getDouble(1));
hix = lexical_cast<double>(rs->getDouble(2)); hix = lexical_cast<double>(rs->getDouble(2));
@ -329,13 +329,13 @@ box2d<double> occi_datasource::envelope() const
s << "select dim.sdo_lb as ly, dim.sdo_ub as uy from "; s << "select dim.sdo_lb as ly, dim.sdo_ub as uy from ";
s << SDO_GEOMETRY_METADATA_TABLE << " m, table(m.diminfo) dim "; s << SDO_GEOMETRY_METADATA_TABLE << " m, table(m.diminfo) dim ";
s << " where lower(m.table_name) = '" << table_name << "' and dim.sdo_dimname = 'Y'"; s << " where lower(m.table_name) = '" << table_name << "' and dim.sdo_dimname = 'Y'";
try try
{ {
ResultSet* rs = conn.execute_query (s.str()); ResultSet* rs = conn.execute_query (s.str());
if (rs && rs->next ()) if (rs && rs->next ())
{ {
try try
{ {
loy = lexical_cast<double>(rs->getDouble(1)); loy = lexical_cast<double>(rs->getDouble(1));
hiy = lexical_cast<double>(rs->getDouble(2)); hiy = lexical_cast<double>(rs->getDouble(2));
@ -368,11 +368,11 @@ layer_descriptor occi_datasource::get_descriptor() const
featureset_ptr occi_datasource::features(query const& q) const featureset_ptr occi_datasource::features(query const& q) const
{ {
if (!is_bound_) bind(); if (!is_bound_) bind();
if (pool_) if (pool_)
{ {
box2d<double> const& box=q.get_bbox(); box2d<double> const& box=q.get_bbox();
std::ostringstream s; std::ostringstream s;
s << "select " << geometry_field_ << " as geom"; s << "select " << geometry_field_ << " as geom";
std::set<std::string> const& props=q.property_names(); std::set<std::string> const& props=q.property_names();
@ -382,12 +382,12 @@ featureset_ptr occi_datasource::features(query const& q) const
{ {
s <<",\""<<*pos<<"\""; s <<",\""<<*pos<<"\"";
++pos; ++pos;
} }
s << " from "; s << " from ";
std::string query (table_); std::string query (table_);
std::string table_name = table_from_sql(query); std::string table_name = mapnik::table_from_sql(query);
if (use_spatial_index_) if (use_spatial_index_)
{ {
@ -398,18 +398,18 @@ featureset_ptr occi_datasource::features(query const& q) const
spatial_sql << " mdsys.sdo_elem_info_array(1," << SDO_ETYPE_POLYGON << "," << SDO_INTERPRETATION_RECTANGLE << "),"; spatial_sql << " mdsys.sdo_elem_info_array(1," << SDO_ETYPE_POLYGON << "," << SDO_INTERPRETATION_RECTANGLE << "),";
spatial_sql << " mdsys.sdo_ordinate_array("; spatial_sql << " mdsys.sdo_ordinate_array(";
spatial_sql << box.minx() << "," << box.miny() << ", "; spatial_sql << box.minx() << "," << box.miny() << ", ";
spatial_sql << box.maxx() << "," << box.maxy() << ")), 'querytype=WINDOW') = 'TRUE'"; spatial_sql << box.maxx() << "," << box.maxy() << ")), 'querytype=WINDOW') = 'TRUE'";
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::find_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());
} }
} }
if (row_limit_ > 0) if (row_limit_ > 0)
{ {
std::string row_limit_string = "rownum < " + row_limit_; std::string row_limit_string = "rownum < " + row_limit_;
@ -418,18 +418,18 @@ featureset_ptr occi_datasource::features(query const& q) const
{ {
boost::algorithm::ireplace_first(query, "where", row_limit_string + " and"); boost::algorithm::ireplace_first(query, "where", row_limit_string + " and");
} }
else if (boost::algorithm::find_first(query,table_name)) else if (boost::algorithm::find_first(query,table_name))
{ {
boost::algorithm::ireplace_first(query, table_name , table_name + " " + row_limit_string); boost::algorithm::ireplace_first(query, table_name , table_name + " " + row_limit_string);
} }
} }
s << query; s << query;
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
clog << s.str() << endl; clog << s.str() << endl;
#endif #endif
return featureset_ptr (new occi_featureset (pool_, return featureset_ptr (new occi_featureset (pool_,
s.str(), s.str(),
desc_.get_encoding(), desc_.get_encoding(),
@ -437,7 +437,7 @@ featureset_ptr occi_datasource::features(query const& q) const
row_prefetch_, row_prefetch_,
props.size())); props.size()));
} }
return featureset_ptr(); return featureset_ptr();
} }
@ -461,8 +461,8 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const
s << " from "; s << " from ";
std::string query (table_); std::string query (table_);
std::string table_name = 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);
@ -470,13 +470,13 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const
spatial_sql << " mdsys.sdo_geometry(" << SDO_GTYPE_2DPOINT << "," << srid_ << ",NULL,"; spatial_sql << " mdsys.sdo_geometry(" << SDO_GTYPE_2DPOINT << "," << srid_ << ",NULL,";
spatial_sql << " mdsys.sdo_elem_info_array(1," << SDO_ETYPE_POINT << "," << SDO_INTERPRETATION_POINT << "),"; spatial_sql << " mdsys.sdo_elem_info_array(1," << SDO_ETYPE_POINT << "," << SDO_INTERPRETATION_POINT << "),";
spatial_sql << " mdsys.sdo_ordinate_array("; spatial_sql << " mdsys.sdo_ordinate_array(";
spatial_sql << pt.x << "," << pt.y << ")), 'querytype=WINDOW') = 'TRUE'"; spatial_sql << pt.x << "," << pt.y << ")), 'querytype=WINDOW') = 'TRUE'";
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::find_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());
} }
@ -489,18 +489,18 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const
{ {
boost::algorithm::ireplace_first(query, "where", row_limit_string + " and"); boost::algorithm::ireplace_first(query, "where", row_limit_string + " and");
} }
else if (boost::algorithm::find_first(query,table_name)) else if (boost::algorithm::find_first(query,table_name))
{ {
boost::algorithm::ireplace_first(query, table_name , table_name + " " + row_limit_string); boost::algorithm::ireplace_first(query, table_name , table_name + " " + row_limit_string);
} }
} }
s << query; s << query;
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
clog << s.str() << endl; clog << s.str() << endl;
#endif #endif
return featureset_ptr (new occi_featureset (pool_, return featureset_ptr (new occi_featureset (pool_,
s.str(), s.str(),
desc_.get_encoding(), desc_.get_encoding(),
@ -511,4 +511,3 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const
return featureset_ptr(); return featureset_ptr();
} }