From 60a956f260edac458724c0debd1b31469c852107 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Tue, 3 Feb 2009 20:09:26 +0000 Subject: [PATCH] + allow multi-line SQL queries in table parameter (#173) --- plugins/input/postgis/postgis.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/plugins/input/postgis/postgis.cpp b/plugins/input/postgis/postgis.cpp index 4cc389f83..7958a6569 100644 --- a/plugins/input/postgis/postgis.cpp +++ b/plugins/input/postgis/postgis.cpp @@ -214,15 +214,23 @@ layer_descriptor postgis_datasource::get_descriptor() const std::string postgis_datasource::table_from_sql(const std::string& sql) { - std::string table_name(sql); - std::transform(table_name.begin(),table_name.end(),table_name.begin(),tolower); - std::string::size_type idx=table_name.rfind("from"); + 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+4); - table_name=table_name.substr(idx); + if (idx != std::string::npos) + { + table_name=table_name.substr(idx); + } idx=table_name.find_first_of(" )"); - return table_name.substr(0,idx); + if (idx != std::string::npos) + { + table_name = table_name.substr(0,idx); + } } return table_name; }