Skip to content

Commit

Permalink
Update test and fix MYSQL plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerkaraszewski committed Jul 25, 2024
1 parent 4123bec commit a99813b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 5 additions & 4 deletions plugins/MySQL.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "MySQL.h"

#include <pcrecpp.h>

#include <bedrockVersion.h>
#include <libstuff/SQResult.h>

#include <cstring>

#undef SLOGPREFIX
#define SLOGPREFIX "{" << getName() << "} "

Expand Down Expand Up @@ -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<string> 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);
Expand Down
11 changes: 11 additions & 0 deletions test/tests/LibStuffTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> 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() {
Expand Down

0 comments on commit a99813b

Please sign in to comment.