drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
status.cc
1/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Sun Microsystems, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <config.h>
22
23#include <plugin/status_dictionary/dictionary.h>
24
25#include <drizzled/pthread_globals.h>
26#include <drizzled/internal/m_string.h>
28#include <drizzled/status_helper.h>
29#include <drizzled/sql_lex.h>
30#include <drizzled/catalog/instance.h>
31
32#include <vector>
33#include <string>
34#include <sstream>
35
36using namespace std;
37using namespace drizzled;
38
39StateTool::StateTool(const char *arg, bool global) :
40 plugin::TableFunction("DATA_DICTIONARY", arg),
41 option_type(global ? OPT_GLOBAL : OPT_SESSION)
42{
43 add_field("VARIABLE_NAME");
44 add_field("VARIABLE_VALUE", 1024);
45}
46
47StateTool::Generator::Generator(Field **arg, sql_var_t option_arg, drizzle_show_var *variables_args) :
48 plugin::TableFunction::Generator(arg),
49 option_type(option_arg),
50 variables(variables_args)
51{
52}
53
54bool StateTool::Generator::populate()
55{
56 while (variables && variables->name)
57 {
58 drizzle_show_var *var;
59 MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
60 char* buff= (char *) &buff_data;
61
62 /*
63 if var->type is SHOW_FUNC, call the function.
64 Repeat as necessary, if new var is again SHOW_FUNC
65 */
66 drizzle_show_var tmp;
67 for (var= variables; var->type == SHOW_FUNC; var= &tmp)
68 ((drizzle_show_var_func)((st_show_var_func_container *)var->value)->func)(&tmp, buff);
69
70 if (isWild(variables->name))
71 {
72 variables++;
73 continue;
74 }
75
76 fill(variables->name, var->value, var->type);
77
78 variables++;
79
80 return true;
81 }
82
83 return false;
84}
85
86void StateTool::Generator::fill(const std::string &name, const char *value, SHOW_TYPE show_type)
87{
88 boost::mutex::scoped_lock lock(getSession().catalog().systemVariableLock());
89
90 if (show_type == SHOW_SYS)
91 {
92 show_type= ((sys_var*) value)->show_type();
93 value= (const char*) ((sys_var*) value)->value_ptr(&(getSession()), option_type);
94 }
95
96 std::string return_value= StatusHelper::fillHelper(NULL, value, show_type);
97 push(name);
98 push(return_value.empty() ? " " : return_value);
99}
TODO: Rename this file - func.h is stupid.
STL namespace.