MCPcopy Create free account
hub / github.com/Tencent/phxsql / CanExecute

Method CanExecute

phxsqlproxy/plugin/requestfilter/freqfilter_plugin.cpp:23–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21namespace phxsqlproxy {
22
23bool FreqFilterPlugin::CanExecute(bool is_master_port, const std::string & db_name, const char * buf, int buf_size) {
24 if (buf_size < 6) {
25 return true;
26 }
27 int command = buf[4];
28 if (command != COM_QUERY) {
29 return true;
30 }
31
32 //FreqCtrlConfig :: GetDefault()->LoadIfModified();
33 if (is_master_port == false) {
34 return FreqCtrlConfig::GetDefault()->Apply(db_name, false);
35 }
36
37 string sql_string = string(buf + 5, buf_size - 5);
38 transform(sql_string.begin(), sql_string.end(), sql_string.begin(), ::toupper);
39
40 static string write_queries[] = { "INSERT", "UPDATE", "REPLACE", "DELETE" };
41
42 //int key = 33;
43 bool is_write_query = false;
44 size_t begin = 0;
45 for (size_t i = 0; i < sql_string.size(); ++i) {
46 if (sql_string[i] == ' ' || sql_string[i] == ';') {
47 if (i > begin) {
48 string word = sql_string.substr(begin, i - begin);
49 for (size_t j = 0; j < sizeof(write_queries) / sizeof(string); ++j) {
50 if (word == write_queries[j]) {
51 is_write_query = true;
52 break;
53 }
54 }
55 }
56 i++;
57 begin = i;
58 }
59 if (is_write_query)
60 break;
61 }
62 return FreqCtrlConfig::GetDefault()->Apply(db_name, is_write_query);
63}
64
65void FreqFilterPlugin::SetConfig(phxsqlproxy::PHXSqlProxyConfig * config, phxsqlproxy::WorkerConfig_t * worker_config) {
66 FreqCtrlConfig * freq_ctrl_config = FreqCtrlConfig::GetDefault();

Callers

nothing calls this directly

Calls 1

ApplyMethod · 0.45

Tested by

no test coverage detected