~drizzle-trunk/drizzle/development

1273.13.5 by Brian Aker
Additional definitions.
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2010 Sun Microsystems, Inc.
1273.13.5 by Brian Aker
Additional definitions.
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
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
21
#include <config.h>
1273.14.5 by Monty Taylor
Merged trunk.
22
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
23
#include <plugin/status_dictionary/dictionary.h>
1273.13.50 by Brian Aker
Additional plugins.
24
1273.13.22 by Brian Aker
Added status bits. Variables next!
25
#include <drizzled/pthread_globals.h>
26
#include <drizzled/internal/m_string.h>
27
#include <drizzled/definitions.h>
1561.3.19 by Joe Daly
move GPL code back to the core from logging_stats plugin
28
#include <drizzled/status_helper.h>
2234.1.1 by Olaf van der Spek
Refactor includes
29
#include <drizzled/sql_lex.h>
2241.3.14 by Olaf van der Spek
Refactor
30
#include <drizzled/catalog/instance.h>
1273.13.22 by Brian Aker
Added status bits. Variables next!
31
32
#include <vector>
33
#include <string>
34
#include <sstream>
1273.13.5 by Brian Aker
Additional definitions.
35
36
using namespace std;
37
using namespace drizzled;
38
1273.13.24 by Brian Aker
Updating style, simplified code.
39
StateTool::StateTool(const char *arg, bool global) :
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
40
  plugin::TableFunction("DATA_DICTIONARY", arg),
1273.13.24 by Brian Aker
Updating style, simplified code.
41
  option_type(global ? OPT_GLOBAL : OPT_SESSION)
1273.13.22 by Brian Aker
Added status bits. Variables next!
42
{
43
  add_field("VARIABLE_NAME");
1273.13.72 by Brian Aker
1) Reduced the size of VARIABLE_VALUE.
44
  add_field("VARIABLE_VALUE", 1024);
1273.13.22 by Brian Aker
Added status bits. Variables next!
45
}
46
1273.13.24 by Brian Aker
Updating style, simplified code.
47
StateTool::Generator::Generator(Field **arg, sql_var_t option_arg,
1561.3.7 by Joe Daly
remove more bits related to old show status
48
                                drizzle_show_var *variables_args)
49
                                :
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
50
  plugin::TableFunction::Generator(arg),
1273.13.24 by Brian Aker
Updating style, simplified code.
51
  option_type(option_arg),
1273.13.22 by Brian Aker
Added status bits. Variables next!
52
  variables(variables_args)
53
{
54
}
55
1273.13.24 by Brian Aker
Updating style, simplified code.
56
StateTool::Generator::~Generator()
1273.13.22 by Brian Aker
Added status bits. Variables next!
57
{
58
}
59
1273.13.24 by Brian Aker
Updating style, simplified code.
60
bool StateTool::Generator::populate()
1273.13.22 by Brian Aker
Added status bits. Variables next!
61
{
62
  while (variables && variables->name)
63
  {
64
    drizzle_show_var *var;
65
    MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
66
    char * const buff= (char *) &buff_data;
67
68
    /*
69
      if var->type is SHOW_FUNC, call the function.
70
      Repeat as necessary, if new var is again SHOW_FUNC
71
    */
72
    {
73
      drizzle_show_var tmp;
74
75
      for (var= variables; var->type == SHOW_FUNC; var= &tmp)
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
76
        ((drizzle_show_var_func)((st_show_var_func_container *)var->value)->func)(&tmp, buff);
1273.13.22 by Brian Aker
Added status bits. Variables next!
77
    }
78
1273.13.59 by Brian Aker
Updates for VARIABLES
79
    if (isWild(variables->name))
80
    {
81
      variables++;
82
      continue;
83
    }
1273.13.76 by Brian Aker
Remove dead SHOW_ARRAY type.
84
85
    fill(variables->name, var->value, var->type);
1273.13.22 by Brian Aker
Added status bits. Variables next!
86
87
    variables++;
88
89
    return true;
90
  }
91
92
  return false;
93
}
1273.13.24 by Brian Aker
Updating style, simplified code.
94
1273.13.72 by Brian Aker
1) Reduced the size of VARIABLE_VALUE.
95
void StateTool::Generator::fill(const std::string &name, char *value, SHOW_TYPE show_type)
1273.13.22 by Brian Aker
Added status bits. Variables next!
96
{
1273.13.72 by Brian Aker
1) Reduced the size of VARIABLE_VALUE.
97
  std::ostringstream oss;
98
  std::string return_value;
1273.13.22 by Brian Aker
Added status bits. Variables next!
99
100
  {
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
101
    boost::mutex::scoped_lock scopedLock(getSession().catalog().systemVariableLock());
102
103
    if (show_type == SHOW_SYS)
104
    {
105
      show_type= ((sys_var*) value)->show_type();
106
      value= (char*) ((sys_var*) value)->value_ptr(&(getSession()), option_type,
107
                                                   &null_lex_str);
108
    }
109
110
    return_value= StatusHelper::fillHelper(NULL, value, show_type); 
1273.13.22 by Brian Aker
Added status bits. Variables next!
111
  }
112
  push(name);
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
113
1273.13.72 by Brian Aker
1) Reduced the size of VARIABLE_VALUE.
114
  if (return_value.length())
115
    push(return_value);
1273.13.46 by Brian Aker
Fixes valgrind issue with status variables.
116
  else 
1273.13.72 by Brian Aker
1) Reduced the size of VARIABLE_VALUE.
117
    push(" ");
1273.13.5 by Brian Aker
Additional definitions.
118
}