diff --git a/.gitignore b/.gitignore index bbf225e80..eb3ccbd1a 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,4 @@ demo/viewer/ui_about.h demo/viewer/ui_info.h demo/viewer/ui_layer_info.h tests/cpp_tests/*-bin +tests/cxx/run diff --git a/include/mapnik/sql_utils.hpp b/include/mapnik/sql_utils.hpp index ddadd21cb..f45af6ca8 100644 --- a/include/mapnik/sql_utils.hpp +++ b/include/mapnik/sql_utils.hpp @@ -73,7 +73,7 @@ namespace mapnik { namespace sql_utils { { table_name=table_name.substr(idx); } - idx = table_name.find_first_of(" )"); + idx = table_name.find_first_of(", )"); if (idx != std::string::npos) { table_name = table_name.substr(0,idx); diff --git a/tests/cxx/sql_parse.cpp b/tests/cxx/sql_parse.cpp new file mode 100644 index 000000000..43a6eb2d1 --- /dev/null +++ b/tests/cxx/sql_parse.cpp @@ -0,0 +1,33 @@ + +#include "catch.hpp" + +#include + +TEST_CASE("sql parse") { + +SECTION("table") { + std::string subquery("table"); + REQUIRE( subquery == mapnik::sql_utils::table_from_sql(subquery) ); +} + +SECTION("complex sql 1") { + std::string subquery("(select * FROM table1, table2) AS data"); + REQUIRE( "table1" == mapnik::sql_utils::table_from_sql(subquery) ); +} + +SECTION("complex sql 2") { + std::string subquery("(select * FROM table1 , table2) AS data"); + REQUIRE( "table1" == mapnik::sql_utils::table_from_sql(subquery) ); +} + +SECTION("complex sql 3") { + std::string subquery("(select * FROM table1,table2) AS data"); + REQUIRE( "table1" == mapnik::sql_utils::table_from_sql(subquery) ); +} + +SECTION("complex sql 4") { + std::string subquery("(select * FROM table1) AS data"); + REQUIRE( "table1" == mapnik::sql_utils::table_from_sql(subquery) ); +} + +}