00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include <plugin/status_dictionary/dictionary.h>
00024
00025 #include <drizzled/pthread_globals.h>
00026 #include <drizzled/internal/m_string.h>
00027 #include <drizzled/definitions.h>
00028 #include <drizzled/status_helper.h>
00029 #include <drizzled/sql_lex.h>
00030
00031 #include <vector>
00032 #include <string>
00033 #include <sstream>
00034
00035 using namespace std;
00036 using namespace drizzled;
00037
00038 StateTool::StateTool(const char *arg, bool global) :
00039 plugin::TableFunction("DATA_DICTIONARY", arg),
00040 option_type(global ? OPT_GLOBAL : OPT_SESSION)
00041 {
00042 add_field("VARIABLE_NAME");
00043 add_field("VARIABLE_VALUE", 1024);
00044 }
00045
00046 StateTool::Generator::Generator(Field **arg, sql_var_t option_arg,
00047 drizzle_show_var *variables_args)
00048 :
00049 plugin::TableFunction::Generator(arg),
00050 option_type(option_arg),
00051 variables(variables_args)
00052 {
00053 }
00054
00055 StateTool::Generator::~Generator()
00056 {
00057 }
00058
00059 bool StateTool::Generator::populate()
00060 {
00061 while (variables && variables->name)
00062 {
00063 drizzle_show_var *var;
00064 MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
00065 char * const buff= (char *) &buff_data;
00066
00067
00068
00069
00070
00071 {
00072 drizzle_show_var tmp;
00073
00074 for (var= variables; var->type == SHOW_FUNC; var= &tmp)
00075 ((drizzle_show_var_func)((st_show_var_func_container *)var->value)->func)(&tmp, buff);
00076 }
00077
00078 if (isWild(variables->name))
00079 {
00080 variables++;
00081 continue;
00082 }
00083
00084 fill(variables->name, var->value, var->type);
00085
00086 variables++;
00087
00088 return true;
00089 }
00090
00091 return false;
00092 }
00093
00094 void StateTool::Generator::fill(const std::string &name, char *value, SHOW_TYPE show_type)
00095 {
00096 std::ostringstream oss;
00097 std::string return_value;
00098
00099 {
00100 boost::mutex::scoped_lock scopedLock(getSession().catalog().systemVariableLock());
00101
00102 if (show_type == SHOW_SYS)
00103 {
00104 show_type= ((sys_var*) value)->show_type();
00105 value= (char*) ((sys_var*) value)->value_ptr(&(getSession()), option_type,
00106 &null_lex_str);
00107 }
00108
00109 return_value= StatusHelper::fillHelper(NULL, value, show_type);
00110 }
00111 push(name);
00112
00113 if (return_value.length())
00114 push(return_value);
00115 else
00116 push(" ");
00117 }