Skip to content

Commit

Permalink
Extended MySQL query generator to support simple searches
Browse files Browse the repository at this point in the history
  • Loading branch information
iagaponenko committed Aug 1, 2023
1 parent 7344288 commit c661f0f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/replica/DatabaseMySQLGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,11 @@ class QueryGenerator {
return op2(id(col), val(expr), " REGEXP ");
}

/// @return "<quoted-col> LIKE <escaped-quoted-expr>"
std::string like(std::string const& col, std::string const& expr) const {
return op2(id(col), val(expr), " LIKE ");
}

/**
* Pack pairs of column/variable names and their new values into a string which can be
* further used to form SQL statements of the following kind:
Expand Down
1 change: 1 addition & 0 deletions src/replica/testQueryGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ BOOST_AUTO_TEST_CASE(QueryGeneratorTest) {
{"NOW()>1234567890", g.gt(Sql::NOW, 1234567890)},
{"`col`>=123", g.geq("col", 123)},
{"`col` REGEXP '[0-9]+'", g.regexp("col", "[0-9]+")},
{"`col` LIKE '%abc%'", g.like("col", "%abc%")},
{"NOW()<=UNIX_TIMESTAMP(`time`)", g.op2(Sql::NOW, g.UNIX_TIMESTAMP("time"), "<=")},
{"NOW()=`time`", g.op2(Sql::NOW, g.id("time"), "=")},

Expand Down

0 comments on commit c661f0f

Please sign in to comment.