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 #include <drizzled/catalog/instance.h>
00031
00032 #include <vector>
00033 #include <string>
00034 #include <sstream>
00035
00036 using namespace std;
00037 using namespace drizzled;
00038
00039 StateTool::StateTool(const char *arg, bool global) :
00040 plugin::TableFunction("DATA_DICTIONARY", arg),
00041 option_type(global ? OPT_GLOBAL : OPT_SESSION)
00042 {
00043 add_field("VARIABLE_NAME");
00044 add_field("VARIABLE_VALUE", 1024);
00045 }
00046
00047 StateTool::Generator::Generator(Field **arg, sql_var_t option_arg, drizzle_show_var *variables_args) :
00048 plugin::TableFunction::Generator(arg),
00049 option_type(option_arg),
00050 variables(variables_args)
00051 {
00052 }
00053
00054 bool StateTool::Generator::populate()
00055 {
00056 while (variables && variables->name)
00057 {
00058 drizzle_show_var *var;
00059 MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
00060 char* buff= (char *) &buff_data;
00061
00062
00063
00064
00065
00066 {
00067 drizzle_show_var tmp;
00068
00069 for (var= variables; var->type == SHOW_FUNC; var= &tmp)
00070 ((drizzle_show_var_func)((st_show_var_func_container *)var->value)->func)(&tmp, buff);
00071 }
00072
00073 if (isWild(variables->name))
00074 {
00075 variables++;
00076 continue;
00077 }
00078
00079 fill(variables->name, var->value, var->type);
00080
00081 variables++;
00082
00083 return true;
00084 }
00085
00086 return false;
00087 }
00088
00089 void StateTool::Generator::fill(const std::string &name, const char *value, SHOW_TYPE show_type)
00090 {
00091 boost::mutex::scoped_lock lock(getSession().catalog().systemVariableLock());
00092
00093 if (show_type == SHOW_SYS)
00094 {
00095 show_type= ((sys_var*) value)->show_type();
00096 value= (const char*) ((sys_var*) value)->value_ptr(&(getSession()), option_type);
00097 }
00098
00099 std::string return_value= StatusHelper::fillHelper(NULL, value, show_type);
00100 push(name);
00101 push(return_value.empty() ? " " : return_value);
00102 }