~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/info_schema/variables.cc

  • Committer: Brian Aker
  • Date: 2010-02-17 01:56:39 UTC
  • mfrom: (1273.13.69 build)
  • Revision ID: brian@gaz-20100217015639-ou3s722vekucn5fd
Many updates. Brian, Monty.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 "config.h"
27
 
#include "drizzled/session.h"
28
 
#include "drizzled/show.h"
29
 
 
30
 
#include "helper_methods.h"
31
 
#include "variables.h"
32
 
 
33
 
#include <vector>
34
 
 
35
 
#include "drizzled/pthread_globals.h"
36
 
 
37
 
using namespace drizzled;
38
 
using namespace std;
39
 
 
40
 
/*
41
 
 * Vectors of columns for the variables I_S tables.
42
 
 */
43
 
extern vector<const plugin::ColumnInfo *> *status_columns;
44
 
 
45
 
/*
46
 
 * Methods for the variables related I_S tables.
47
 
 */
48
 
static plugin::InfoSchemaMethods *methods= NULL;
49
 
 
50
 
/*
51
 
 * variables I_S tables.
52
 
 */
53
 
static plugin::InfoSchemaTable *glob_var_table= NULL;
54
 
static plugin::InfoSchemaTable *sess_var_table= NULL;
55
 
static plugin::InfoSchemaTable *var_table= NULL;
56
 
 
57
 
/**
58
 
 * Initialize the I_S table.
59
 
 *
60
 
 * @return a pointer to an I_S table
61
 
 */
62
 
plugin::InfoSchemaTable *GlobalVariablesIS::getTable()
63
 
{
64
 
  if (methods == NULL)
65
 
  {
66
 
    methods= new VariablesISMethods();
67
 
  }
68
 
 
69
 
  if (glob_var_table == NULL)
70
 
  {
71
 
    glob_var_table= new plugin::InfoSchemaTable("OLD_GLOBAL_VARIABLES",
72
 
                                                *status_columns,
73
 
                                                -1, -1, false, false,
74
 
                                                0, 
75
 
                                                methods);
76
 
  }
77
 
 
78
 
  return glob_var_table;
79
 
}
80
 
 
81
 
/**
82
 
 * Delete memory allocated for the table, columns and methods.
83
 
 */
84
 
void GlobalVariablesIS::cleanup()
85
 
{
86
 
  delete glob_var_table;
87
 
  delete methods;
88
 
}
89
 
 
90
 
/**
91
 
 * Initialize the I_S table.
92
 
 *
93
 
 * @return a pointer to an I_S table
94
 
 */
95
 
plugin::InfoSchemaTable *SessionVariablesIS::getTable()
96
 
{
97
 
  if (sess_var_table == NULL)
98
 
  {
99
 
    sess_var_table= new plugin::InfoSchemaTable("OLD_SESSION_VARIABLES",
100
 
                                                *status_columns,
101
 
                                                -1, -1, false, false, 0,
102
 
                                                methods);
103
 
  }
104
 
 
105
 
  return sess_var_table;
106
 
}
107
 
 
108
 
/**
109
 
 * Delete memory allocated for the table, columns and methods.
110
 
 */
111
 
void SessionVariablesIS::cleanup()
112
 
{
113
 
  delete sess_var_table;
114
 
}
115
 
 
116
 
/**
117
 
 * Initialize the I_S table.
118
 
 *
119
 
 * @return a pointer to an I_S table
120
 
 */
121
 
plugin::InfoSchemaTable *VariablesIS::getTable()
122
 
{
123
 
  if (var_table == NULL)
124
 
  {
125
 
    var_table= new plugin::InfoSchemaTable("OLD_VARIABLES",
126
 
                                           *status_columns,
127
 
                                           -1, -1, true, false, 0,
128
 
                                           methods);
129
 
  }
130
 
 
131
 
  return var_table;
132
 
}
133
 
 
134
 
/**
135
 
 * Delete memory allocated for the table, columns and methods.
136
 
 */
137
 
void VariablesIS::cleanup()
138
 
{
139
 
  delete var_table;
140
 
}
141
 
 
142
 
int VariablesISMethods::fillTable(Session *session, 
143
 
                                  Table *table,
144
 
                                  plugin::InfoSchemaTable *schema_table)
145
 
{
146
 
  int res= 0;
147
 
  LEX *lex= session->lex;
148
 
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
149
 
  const string schema_table_name= schema_table->getTableName();
150
 
  sql_var_t option_type= OPT_SESSION;
151
 
  bool sorted_vars= (schema_table_name.compare("OLD_VARIABLES") == 0);
152
 
 
153
 
  if (lex->option_type == OPT_GLOBAL ||
154
 
      schema_table_name.compare("GLOBAL_VARIABLES") == 0)
155
 
  {
156
 
    option_type= OPT_GLOBAL;
157
 
  }
158
 
 
159
 
  pthread_rwlock_rdlock(&LOCK_system_variables_hash);
160
 
  res= show_status_array(session, wild, enumerate_sys_vars(session, sorted_vars),
161
 
                         option_type, NULL, "", table, false, schema_table);
162
 
  pthread_rwlock_unlock(&LOCK_system_variables_hash);
163
 
  return res;
164
 
}
165