You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "TeslaCN (via GitHub)" <gi...@apache.org> on 2023/04/20 08:48:35 UTC

[GitHub] [shardingsphere] TeslaCN commented on issue #23614: Consider refactoring proxy-mysql-default-version

TeslaCN commented on issue #23614:
URL: https://github.com/apache/shardingsphere/issues/23614#issuecomment-1515957638

   ```cpp
   #include <iostream>
   #include <map>
   #include <string>
   #include "set_var.h"
   #include "sys_vars.h"
   
   using namespace std;
   
   string generateFlag(const sys_var *v);
   
   string generateDefaultValue(sys_var *v);
   
   int main() {
     map<string, string> m;
     for (sys_var *v = all_sys_vars.first; v; v = v->next) {
       string name = v->name.str, generated;
       for (char c : name) {
         generated += (char)toupper(c);
       }
       generated += '(';
       string flag = generateFlag(v);
       generated += flag;
       generated += ", ";
       string def = generateDefaultValue(v);
       generated += def + ')';
       m[name] = ("\"TODO\"" == def ? "// " : "") + generated;
     }
     for (auto &iterator : m) {
       cout << iterator.second << "," << endl << endl;
     }
     return 0;
   }
   
   string generateFlag(const sys_var *v) {
     string flag;
     if (v->scope() & sys_var::GLOBAL) flag += " | Flag.GLOBAL";
     if (v->scope() & sys_var::SESSION) flag += " | Flag.SESSION";
     if (v->scope() & sys_var::ONLY_SESSION) flag += " | Flag.ONLY_SESSION";
     if (v->is_readonly()) flag += " | Flag.READONLY";
     if (v->not_visible()) flag += " | Flag.INVISIBLE";
     if (v->is_trilevel()) flag += " | Flag.TRI_LEVEL";
     if (v->is_hint_updateable()) flag += " | Flag.HINT_UPDATEABLE";
     if (v->is_persist_readonly()) flag += " | Flag.PERSIST_AS_READ_ONLY";
     if (v->is_sensitive()) flag += " | Flag.SENSITIVE";
     return flag.substr(3);
   }
   
   string generateDefaultValue(sys_var *v) {
     stringstream stream;
     stream << '"';
     switch (v->get_option()->var_type) {
       case GET_STR: {
         char *c = reinterpret_cast<char *>(v->get_option()->def_value);
         if (nullptr != c) stream << c;
         break;
       }
       case GET_INT:
       case GET_LONG:
       case GET_LL:
       case GET_UINT:
       case GET_ULONG:
       case GET_ULL:
       case GET_BOOL: {
         stream << v->get_option()->def_value;
         break;
       }
       case GET_DOUBLE: {
         stream << (double)v->get_option()->def_value;
         break;
       }
       default: {
         stream << "TODO";
       }
     }
     stream << '"';
     return stream.str();
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org