~drizzle-trunk/drizzle/development

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 *
 *  Copyright (C) 2009 Sun Microsystems
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

/**
 * @file 
 *   status I_S table methods.
 */

#include "drizzled/server_includes.h"
#include "drizzled/session.h"
#include "drizzled/show.h"
#include "drizzled/tztime.h"

#include "helper_methods.h"
#include "status.h"

#include <vector>

using namespace drizzled;
using namespace std;

/*
 * Vectors of columns for the status I_S tables.
 */
vector<const plugin::ColumnInfo *> *status_columns= NULL;

/*
 * Methods for the status related I_S tables.
 */
static plugin::InfoSchemaMethods *methods= NULL;

/*
 * status I_S tables.
 */
static plugin::InfoSchemaTable *glob_status_table= NULL;
static plugin::InfoSchemaTable *sess_status_table= NULL;
static plugin::InfoSchemaTable *status_table= NULL;

/**
 * Populate the vectors of columns for the I_S table.
 *
 * @return a pointer to a std::vector of Columns.
 */
vector<const plugin::ColumnInfo *> *GlobalStatusIS::createColumns()
{
  if (status_columns == NULL)
  {
    status_columns= new vector<const plugin::ColumnInfo *>;
  }
  else
  {
    clearColumns(*status_columns);
  }

  status_columns->push_back(new plugin::ColumnInfo("VARIABLE_NAME",
                                                   64,
                                                   DRIZZLE_TYPE_VARCHAR,
                                                   0,
                                                   0,
                                                   "Variable_name",
                                                   SKIP_OPEN_TABLE));

  status_columns->push_back(new plugin::ColumnInfo("VARIABLE_VALUE",
                                                   16300,
                                                   DRIZZLE_TYPE_VARCHAR,
                                                   0,
                                                   1,
                                                   "Value",
                                                   SKIP_OPEN_TABLE));

  return status_columns;
}

/**
 * Initialize the I_S table.
 *
 * @return a pointer to an I_S table
 */
plugin::InfoSchemaTable *GlobalStatusIS::getTable()
{
  status_columns= createColumns();

  if (methods == NULL)
  {
    methods= new StatusISMethods();
  }

  if (glob_status_table == NULL)
  {
    glob_status_table= new plugin::InfoSchemaTable("GLOBAL_STATUS",
                                                   *status_columns,
                                                   -1, -1, false, false,
                                                   0, 
                                                   methods);
  }

  return glob_status_table;
}

/**
 * Delete memory allocated for the table, columns and methods.
 */
void GlobalStatusIS::cleanup()
{
  clearColumns(*status_columns);
  delete glob_status_table;
  delete methods;
  delete status_columns;
}

/**
 * Initialize the I_S table.
 *
 * @return a pointer to an I_S table
 */
plugin::InfoSchemaTable *SessionStatusIS::getTable()
{
  if (sess_status_table == NULL)
  {
    sess_status_table= new plugin::InfoSchemaTable("SESSION_STATUS",
                                                   *status_columns,
                                                   -1, -1, false, false,
                                                   0, 
                                                   methods);
  }

  return sess_status_table;
}

/**
 * Delete memory allocated for the table, columns and methods.
 */
void SessionStatusIS::cleanup()
{
  delete sess_status_table;
}

/**
 * Initialize the I_S table.
 *
 * @return a pointer to an I_S table
 */
plugin::InfoSchemaTable *StatusIS::getTable()
{
  if (status_table == NULL)
  {
    status_table= new plugin::InfoSchemaTable("STATUS",
                                              *status_columns,
                                              -1, -1, true, false, 0,
                                              methods);
  }

  return status_table;
}

/**
 * Delete memory allocated for the table, columns and methods.
 */
void StatusIS::cleanup()
{
  delete status_table;
}

int StatusISMethods::fillTable(Session *session, TableList *tables)
{
  LEX *lex= session->lex;
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
  int res= 0;
  STATUS_VAR *tmp1, tmp;
  const string schema_table_name= tables->schema_table->getTableName();
  enum enum_var_type option_type;
  bool upper_case_names= (schema_table_name.compare("STATUS") != 0);

  if (schema_table_name.compare("STATUS") == 0)
  {
    option_type= lex->option_type;
    if (option_type == OPT_GLOBAL)
    {
      tmp1= &tmp;
    }
    else
    {
      tmp1= session->initial_status_var;
    }
  }
  else if (schema_table_name.compare("GLOBAL_STATUS") == 0)
  {
    option_type= OPT_GLOBAL;
    tmp1= &tmp;
  }
  else
  {
    option_type= OPT_SESSION;
    tmp1= &session->status_var;
  }

  pthread_mutex_lock(&LOCK_status);
  if (option_type == OPT_GLOBAL)
  {
    calc_sum_of_all_status(&tmp);
  }
  res= show_status_array(session, wild,
                         getFrontOfStatusVars(),
                         option_type, tmp1, "", tables->table,
                         upper_case_names);
  pthread_mutex_unlock(&LOCK_status);
  return res;
}