Skip to content

Commit

Permalink
fixes #33
Browse files Browse the repository at this point in the history
  • Loading branch information
dzsquared authored Mar 6, 2022
1 parent 3070b2d commit 9a1c786
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ std::string GetTableName(const std::string& sql_statement){
auto rest = sql_statement.substr(found + table_template.size());
// Strip space at beginning
rest = std::regex_replace(rest, std::regex("^ +| +$|( ) +"), "$1");
auto table_name = rest.substr(0, rest.find(' '));
// check if space or ( comes first in remaining string
if (rest.find(' ') < rest.find('(')) {
// space comes first
rest = rest.substr(0, rest.find(' '));
} else {
// ( comes first
rest = rest.substr(0, rest.find('('));
}
auto table_name = rest;

return table_name;
}
Expand Down
15 changes: 15 additions & 0 deletions test/test_suite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,4 +475,19 @@ TEST(TestSuite, JoinEqualityTest) {

}

TEST(TestSuite, SingleColumnTable) {
Configuration default_conf;
default_conf.testing_mode = true;
default_conf.verbose = true;

std::unique_ptr<std::istringstream> stream(new std::istringstream());
stream->str(
"CREATE TABLE sometable(singlecolumn int);"
);

default_conf.test_stream.reset(stream.release());

Check(default_conf);
}

} // End machine sqlcheck

0 comments on commit 9a1c786

Please # to comment.