improve sql subselect parsing + add tests - closes #2704
This commit is contained in:
parent
54dc9dd0f3
commit
1ebd6afd9c
3 changed files with 35 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -44,3 +44,4 @@ demo/viewer/ui_about.h
|
||||||
demo/viewer/ui_info.h
|
demo/viewer/ui_info.h
|
||||||
demo/viewer/ui_layer_info.h
|
demo/viewer/ui_layer_info.h
|
||||||
tests/cpp_tests/*-bin
|
tests/cpp_tests/*-bin
|
||||||
|
tests/cxx/run
|
||||||
|
|
|
@ -73,7 +73,7 @@ namespace mapnik { namespace sql_utils {
|
||||||
{
|
{
|
||||||
table_name=table_name.substr(idx);
|
table_name=table_name.substr(idx);
|
||||||
}
|
}
|
||||||
idx = table_name.find_first_of(" )");
|
idx = table_name.find_first_of(", )");
|
||||||
if (idx != std::string::npos)
|
if (idx != std::string::npos)
|
||||||
{
|
{
|
||||||
table_name = table_name.substr(0,idx);
|
table_name = table_name.substr(0,idx);
|
||||||
|
|
33
tests/cxx/sql_parse.cpp
Normal file
33
tests/cxx/sql_parse.cpp
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
|
||||||
|
#include "catch.hpp"
|
||||||
|
|
||||||
|
#include <mapnik/sql_utils.hpp>
|
||||||
|
|
||||||
|
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) );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue