diff --git a/plugins/MySQL.cpp b/plugins/MySQL.cpp index 1cce8871f..b9687c0c0 100644 --- a/plugins/MySQL.cpp +++ b/plugins/MySQL.cpp @@ -1,10 +1,10 @@ #include "MySQL.h" -#include - #include #include +#include + #undef SLOGPREFIX #define SLOGPREFIX "{" << getName() << "} " @@ -269,9 +269,10 @@ void BedrockPlugin_MySQL::onPortRecv(STCPManager::Socket* s, SData& request) { SINFO("Processing query '" << query << "'"); // See if it's asking for a global variable - string varName; string regExp = "^(?:(?:SELECT\\s+)?@@(?:\\w+\\.)?|SHOW VARIABLES LIKE ')(\\w+).*$"; - if (pcrecpp::RE(regExp, pcrecpp::RE_Options().set_caseless(true)).FullMatch(query, &varName)) { + vector matches; + if (SREMatch(regExp, query, false, false, &matches)) { + string varName = matches[0]; // Loop across and look for it SQResult result; result.headers.push_back(varName); diff --git a/test/tests/LibStuffTest.cpp b/test/tests/LibStuffTest.cpp index 0494220e1..9c3e85a96 100644 --- a/test/tests/LibStuffTest.cpp +++ b/test/tests/LibStuffTest.cpp @@ -661,6 +661,17 @@ struct LibStuff : tpunit::TestFixture { // Now try with partial specified, should work. ASSERT_TRUE(SREMatch("cat", "this contains cat", true, true)); + + // Test returning matches. + vector matches; + SREMatch(R"((\w+) (\w+) (\w+))", "this contains cat", false, false, &matches); + + // The whole string, and the three groups. + ASSERT_EQUAL(matches.size(), 4); + ASSERT_EQUAL(matches[0], "this contains cat"); + ASSERT_EQUAL(matches[1], "this"); + ASSERT_EQUAL(matches[2], "contains"); + ASSERT_EQUAL(matches[3], "cat"); } void SREReplaceTest() {