diff --git a/src/mysql.cpp b/src/mysql.cpp index 80f7da3..59cc5f6 100644 --- a/src/mysql.cpp +++ b/src/mysql.cpp @@ -195,10 +195,11 @@ bool mySQL::change(const string sql_command) { string mySQL::getTable(const string req) { size_t from = req.find("FROM") < req.find("from") ? req.find("FROM") : req.find("from"); + size_t ends = req.find(" ", from+5) < req.length() ? req.find(" ", from+5) : req.length(); if (from > req.length()) { return ""; } - string table = req.substr(from+5, req.find(" ", from+5)); + string table = req.substr(from+5, ends-from-5); return table; } diff --git a/test/test.cpp b/test/test.cpp index 70bec39..f80a0be 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -10,7 +10,7 @@ int main() { try { - auto res = mydb.query("SELECT * FROM records"); + auto res = mydb.query("SELECT * FROM records WHERE enabled = 1;"); for (auto i : res) { for (auto j: i.second) { diff --git a/test/test.o b/test/test.o index 81818ce..4b2c9c0 100755 Binary files a/test/test.o and b/test/test.o differ