~drizzle-trunk/drizzle/development

1215.2.21 by Padraig O'Sullivan
Extracted the status and variable related I_S tables into their own header
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2009 Sun Microsystems
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
/**
22
 * @file 
23
 *   variables I_S table methods.
24
 */
25
26
#include "drizzled/server_includes.h"
27
#include "drizzled/session.h"
28
#include "drizzled/show.h"
29
1215.2.22 by Padraig O'Sullivan
Removed the info_schema_methods files and created a helper_methods header
30
#include "helper_methods.h"
1215.2.21 by Padraig O'Sullivan
Extracted the status and variable related I_S tables into their own header
31
#include "variables.h"
32
33
#include <vector>
34
35
using namespace drizzled;
36
using namespace std;
37
38
/*
39
 * Vectors of columns for the variables I_S tables.
40
 */
41
extern vector<const plugin::ColumnInfo *> *status_columns;
42
43
/*
44
 * Methods for the variables related I_S tables.
45
 */
46
static plugin::InfoSchemaMethods *methods= NULL;
47
48
/*
49
 * variables I_S tables.
50
 */
51
static plugin::InfoSchemaTable *glob_var_table= NULL;
52
static plugin::InfoSchemaTable *sess_var_table= NULL;
53
static plugin::InfoSchemaTable *var_table= NULL;
54
55
/**
56
 * Initialize the I_S table.
57
 *
58
 * @return a pointer to an I_S table
59
 */
60
plugin::InfoSchemaTable *GlobalVariablesIS::getTable()
61
{
62
  if (methods == NULL)
63
  {
64
    methods= new VariablesISMethods();
65
  }
66
67
  if (glob_var_table == NULL)
68
  {
69
    glob_var_table= new plugin::InfoSchemaTable("GLOBAL_VARIABLES",
70
                                                *status_columns,
71
                                                -1, -1, false, false,
72
                                                0, 
73
                                                methods);
74
  }
75
76
  return glob_var_table;
77
}
78
79
/**
80
 * Delete memory allocated for the table, columns and methods.
81
 */
82
void GlobalVariablesIS::cleanup()
83
{
84
  delete glob_var_table;
85
  delete methods;
86
}
87
88
/**
89
 * Initialize the I_S table.
90
 *
91
 * @return a pointer to an I_S table
92
 */
93
plugin::InfoSchemaTable *SessionVariablesIS::getTable()
94
{
95
  if (sess_var_table == NULL)
96
  {
97
    sess_var_table= new plugin::InfoSchemaTable("SESSION_VARIABLES",
98
                                                *status_columns,
99
                                                -1, -1, false, false, 0,
100
                                                methods);
101
  }
102
103
  return sess_var_table;
104
}
105
106
/**
107
 * Delete memory allocated for the table, columns and methods.
108
 */
109
void SessionVariablesIS::cleanup()
110
{
111
  delete sess_var_table;
112
}
113
114
/**
115
 * Initialize the I_S table.
116
 *
117
 * @return a pointer to an I_S table
118
 */
119
plugin::InfoSchemaTable *VariablesIS::getTable()
120
{
121
  if (var_table == NULL)
122
  {
123
    var_table= new plugin::InfoSchemaTable("VARIABLES",
124
                                           *status_columns,
125
                                           -1, -1, true, false, 0,
126
                                           methods);
127
  }
128
129
  return var_table;
130
}
131
132
/**
133
 * Delete memory allocated for the table, columns and methods.
134
 */
135
void VariablesIS::cleanup()
136
{
137
  delete var_table;
138
}
139
1225.1.19 by Padraig O'Sullivan
Modified the fillTable method to not take a TableList parameter anymore. Instead we now take a Table
140
int VariablesISMethods::fillTable(Session *session, 
141
                                  Table *table,
142
                                  plugin::InfoSchemaTable *schema_table)
1215.2.21 by Padraig O'Sullivan
Extracted the status and variable related I_S tables into their own header
143
{
144
  int res= 0;
145
  LEX *lex= session->lex;
146
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1225.1.19 by Padraig O'Sullivan
Modified the fillTable method to not take a TableList parameter anymore. Instead we now take a Table
147
  const string schema_table_name= schema_table->getTableName();
1215.2.21 by Padraig O'Sullivan
Extracted the status and variable related I_S tables into their own header
148
  enum enum_var_type option_type= OPT_SESSION;
149
  bool upper_case_names= (schema_table_name.compare("VARIABLES") != 0);
150
  bool sorted_vars= (schema_table_name.compare("VARIABLES") == 0);
151
152
  if (lex->option_type == OPT_GLOBAL ||
153
      schema_table_name.compare("GLOBAL_VARIABLES") == 0)
154
  {
155
    option_type= OPT_GLOBAL;
156
  }
157
158
  pthread_rwlock_rdlock(&LOCK_system_variables_hash);
159
  res= show_status_array(session, wild, enumerate_sys_vars(session, sorted_vars),
1225.1.19 by Padraig O'Sullivan
Modified the fillTable method to not take a TableList parameter anymore. Instead we now take a Table
160
                         option_type, NULL, "", table, upper_case_names, schema_table);
1215.2.21 by Padraig O'Sullivan
Extracted the status and variable related I_S tables into their own header
161
  pthread_rwlock_unlock(&LOCK_system_variables_hash);
162
  return res;
163
}
164