create an sql_utils header for all sql-based plugins to be able to leverage, and move the postgis table_from_sql function into it
This commit is contained in:
parent
18d77f0f6c
commit
385ad05205
3 changed files with 61 additions and 27 deletions
59
include/mapnik/sql_utils.hpp
Normal file
59
include/mapnik/sql_utils.hpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2010 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id: sql_utils.hpp 39 2005-04-10 20:39:53Z pavlenko $
|
||||
|
||||
#ifndef SQL_UTILS_HPP
|
||||
#define SQL_UTILS_HPP
|
||||
|
||||
// boost
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
|
||||
MAPNIK_DECL std::string table_from_sql(const std::string& sql)
|
||||
{
|
||||
std::string table_name = boost::algorithm::to_lower_copy(sql);
|
||||
boost::algorithm::replace_all(table_name,"\n"," ");
|
||||
|
||||
std::string::size_type idx = table_name.rfind(" from ");
|
||||
if (idx!=std::string::npos)
|
||||
{
|
||||
|
||||
idx = table_name.find_first_not_of(" ",idx+5);
|
||||
if (idx != std::string::npos)
|
||||
{
|
||||
table_name=table_name.substr(idx);
|
||||
}
|
||||
idx = table_name.find_first_of(" )");
|
||||
if (idx != std::string::npos)
|
||||
{
|
||||
table_name = table_name.substr(0,idx);
|
||||
}
|
||||
}
|
||||
return table_name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //SQL_UTILS_HPP
|
|
@ -25,6 +25,7 @@
|
|||
// mapnik
|
||||
#include <mapnik/global.hpp>
|
||||
#include <mapnik/ptree_helpers.hpp>
|
||||
#include <mapnik/sql_utils.hpp>
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
//#include <mapnik/wall_clock_timer.hpp>
|
||||
|
@ -158,7 +159,7 @@ void postgis_datasource::bind() const
|
|||
|
||||
if(geometry_table_.empty())
|
||||
{
|
||||
geometry_table_ = table_from_sql(table_);
|
||||
geometry_table_ = mapnik::table_from_sql(table_);
|
||||
}
|
||||
std::string::size_type idx = geometry_table_.find_last_of('.');
|
||||
if (idx!=std::string::npos)
|
||||
|
@ -402,31 +403,6 @@ std::string postgis_datasource::unquote(const std::string& sql)
|
|||
return table_name;
|
||||
}
|
||||
|
||||
// TODO - make smarter and potentially move to reusable utilities
|
||||
// available to other SQL-based plugins
|
||||
std::string postgis_datasource::table_from_sql(const std::string& sql)
|
||||
{
|
||||
std::string table_name = boost::algorithm::to_lower_copy(sql);
|
||||
boost::algorithm::replace_all(table_name,"\n"," ");
|
||||
|
||||
std::string::size_type idx = table_name.rfind(" from ");
|
||||
if (idx!=std::string::npos)
|
||||
{
|
||||
|
||||
idx=table_name.find_first_not_of(" ",idx+5);
|
||||
if (idx != std::string::npos)
|
||||
{
|
||||
table_name=table_name.substr(idx);
|
||||
}
|
||||
idx=table_name.find_first_of(" )");
|
||||
if (idx != std::string::npos)
|
||||
{
|
||||
table_name = table_name.substr(0,idx);
|
||||
}
|
||||
}
|
||||
return table_name;
|
||||
}
|
||||
|
||||
boost::shared_ptr<IResultSet> postgis_datasource::get_resultset(boost::shared_ptr<Connection> const &conn, const std::string &sql) const
|
||||
{
|
||||
if (cursor_fetch_size_ > 0) {
|
||||
|
|
|
@ -94,7 +94,6 @@ class postgis_datasource : public datasource
|
|||
std::string populate_tokens(const std::string& sql, double const& scale_denom, box2d<double> const& env) const;
|
||||
std::string populate_tokens(const std::string& sql) const;
|
||||
static std::string unquote(const std::string& sql);
|
||||
static std::string table_from_sql(const std::string& sql);
|
||||
boost::shared_ptr<IResultSet> get_resultset(boost::shared_ptr<Connection> const &conn, const std::string &sql) const;
|
||||
postgis_datasource(const postgis_datasource&);
|
||||
postgis_datasource& operator=(const postgis_datasource&);
|
||||
|
|
Loading…
Reference in a new issue