1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems
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.
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.
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
21
#ifndef DRIZZLED_INFO_SCHEMA_H
22
#define DRIZZLED_INFO_SCHEMA_H
30
* Header file which contains all classes related to I_S
33
typedef class Item COND;
39
* Represents a field (column) in an I_S table.
44
ColumnInfo(const std::string& in_name,
46
enum enum_field_types in_type,
49
const std::string& in_old_name,
50
uint32_t in_open_method)
57
old_name(in_old_name),
58
open_method(in_open_method)
65
type(DRIZZLE_TYPE_VARCHAR),
68
open_method(SKIP_OPEN_TABLE)
72
* @return the name of this column.
74
const std::string &getName() const
80
* This method is only ever called from the
81
* InfoSchemaMethods::oldFormat() methods. It is mostly
82
* for old SHOW compatability. It is used when a list
83
* of fields need to be generated for SHOW. The names
84
* for those fields (or columns) are found by calling
85
* this method on each column in the I_S table.
87
* @return the old name of this column.
89
const std::string &getOldName() const
95
* @return the open method for this column.
97
uint32_t getOpenMethod() const
103
* @return the flags for this column.
105
uint32_t getFlags() const
111
* @return the length of this column.
113
uint32_t getLength() const
119
* @return the value of this column.
121
int32_t getValue() const
127
* @return this column's type.
129
enum enum_field_types getType() const
137
* This is used as column name.
139
const std::string name;
142
* For string-type columns, this is the maximum number of
143
* characters. Otherwise, it is the 'display-length' for the column.
148
* This denotes data type for the column. For the most part, there seems to
149
* be one entry in the enum for each SQL data type, although there seem to
150
* be a number of additional entries in the enum.
152
enum enum_field_types type;
157
* This is used to set column attributes. By default, columns are @c NOT
158
* @c NULL and @c SIGNED, and you can deviate from the default
159
* by setting the appopriate flags. You can use either one of the flags
160
* @c MY_I_S_MAYBE_NULL and @cMY_I_S_UNSIGNED or
161
* combine them using the bitwise or operator @c |. Both flags are
162
* defined in table.h.
167
* The name of this column which is used for old SHOW
170
const std::string old_name;
173
* This should be one of @c SKIP_OPEN_TABLE,
174
* @c OPEN_FRM_ONLY or @c OPEN_FULL_TABLE.
176
uint32_t open_method;
181
* @class InfoSchemaMethods
183
* The methods that an I_S table can support
185
class InfoSchemaMethods
188
virtual ~InfoSchemaMethods() {}
190
virtual Table *createSchemaTable(Session *session,
191
TableList *table_list) const;
192
virtual int fillTable(Session *session,
195
virtual int processTable(Session *session, TableList *tables,
196
Table *table, bool res, LEX_STRING *db_name,
197
LEX_STRING *table_name) const;
198
virtual int oldFormat(Session *session,
199
InfoSchemaTable *schema_table) const;
202
class StatusISMethods : public InfoSchemaMethods
205
virtual int fillTable(Session *session,
210
class VariablesISMethods : public InfoSchemaMethods
213
virtual int fillTable(Session *session,
219
* @class InfoSchemaTable
221
* Represents an I_S table.
223
class InfoSchemaTable
227
typedef std::vector<const ColumnInfo *> Columns;
229
InfoSchemaTable(const std::string& tab_name,
230
ColumnInfo *in_column_info,
234
bool in_opt_possible,
236
InfoSchemaMethods *in_methods)
238
table_name(tab_name),
240
is_opt_possible(in_opt_possible),
241
first_column_index(idx_col1),
242
second_column_index(idx_col2),
243
requested_object(req_object),
245
i_s_methods(in_methods)
247
setColumnInfo(in_column_info);
250
InfoSchemaTable(const std::string& tab_name,
251
Columns& in_column_info,
255
bool in_opt_possible,
257
InfoSchemaMethods *in_methods)
259
table_name(tab_name),
261
is_opt_possible(in_opt_possible),
262
first_column_index(idx_col1),
263
second_column_index(idx_col2),
264
requested_object(req_object),
265
column_info(in_column_info),
266
i_s_methods(in_methods)
273
is_opt_possible(false),
274
first_column_index(0),
275
second_column_index(0),
282
* Set the methods available on this I_S table.
283
* @param[in] new_methods the methods to use
285
void setInfoSchemaMethods(InfoSchemaMethods *new_methods)
287
i_s_methods= new_methods;
291
* Create the temporary I_S tables using schema_table data.
293
* @param[in] session a session handler
294
* @param[in] table_list Used to pass I_S table information (fields,
295
* tables, parameters, etc.) and table name
296
* @retval \# pointer to created table
297
* @retval NULL Can't create table
299
Table *createSchemaTable(Session *session, TableList *table_list) const
301
Table *retval= i_s_methods->createSchemaTable(session, table_list);
308
* @param[in] session a session handler
309
* @param[in] tables I_S table
310
* @param[in] cond 'WHERE' condition
311
* @return 0 on success; 1 on error
313
int fillTable(Session *session, TableList *tables, COND *cond)
315
int retval= i_s_methods->fillTable(session, tables, cond);
320
* Fill and store records into an I_S table.
322
* @param[in] session a session handler
323
* @param[in] tables table list (processed table)
324
* @param[in] table I_S table
325
* @param[in] res 1 means error during opening of the processed table
326
* 0 means processed table opened without error
327
* @param[in] db_name database name
328
* @param[in] tab_name table name
329
* @return 0 on success; 1 on error
331
int processTable(Session *session, TableList *tables, Table *table,
332
bool res, LEX_STRING *db_name, LEX_STRING *tab_name) const
334
int retval= i_s_methods->processTable(session, tables, table,
335
res, db_name, tab_name);
340
* For old SHOW compatibility. It is used when old SHOW doesn't
341
* have generated column names. Generates the list of fields
344
* @param[in] session a session handler
345
* @param[in] schema_table pointer to element of the I_S tables list
347
int oldFormat(Session *session, InfoSchemaTable *schema_table) const
349
int retval= i_s_methods->oldFormat(session, schema_table);
354
* Set the I_S tables name.
355
* @param[in] new_name the name to set the table to
357
void setTableName(const std::string &new_name)
359
table_name= new_name;
363
* @param[in] new_first_index value to set first column index to
365
void setFirstColumnIndex(int32_t new_first_index)
367
first_column_index= new_first_index;
371
* @param[in] new_second_index value to set second column index to
373
void setSecondColumnIndex(int32_t new_second_index)
375
second_column_index= new_second_index;
379
* @param[in] in_column_info the columns info to use for this I_S table
381
void setColumnInfo(ColumnInfo *in_column_info)
383
ColumnInfo *tmp= in_column_info;
384
for (; tmp->getName().length() != 0; tmp++)
386
column_info.push_back(tmp);
391
* @return the name of the I_S table.
393
const std::string &getTableName() const
399
* @return true if this I_S table is hidden; false otherwise.
401
bool isHidden() const
407
* @return true if I_S optimizations can be performed on this
408
* I_S table when running the fillTable method; false
411
bool isOptimizationPossible() const
413
return is_opt_possible;
417
* @return the index for the first field.
419
int32_t getFirstColumnIndex() const
421
return first_column_index;
425
* @return the index the second field.
427
int32_t getSecondColumnIndex() const
429
return second_column_index;
433
* @return the requested object.
435
uint32_t getRequestedObject() const
437
return requested_object;
441
* @return the columns for this I_S table
443
const Columns &getColumns() const
449
* @param[in] index the index of this column
450
* @return the name for the column at the given index
452
const std::string &getColumnName(int index) const
454
return column_info[index]->getName();
458
* @param[in] index the index of this column
459
* @return the open method for the column at the given index
461
uint32_t getColumnOpenMethod(int index) const
463
return column_info[index]->getOpenMethod();
470
std::string table_name;
473
* Boolean which indicates whether this I_S table
474
* is hidden or not. If it is hidden, it will not show
475
* up in the list of I_S tables.
480
* Boolean which indicates whether optimizations are
481
* possible on this I_S table when performing the
484
bool is_opt_possible;
487
* The index of the first column.
489
int32_t first_column_index;
492
* The index of the second column.
494
int32_t second_column_index;
497
* The object to open (TABLE | VIEW).
499
uint32_t requested_object;
502
* The columns for this I_S table.
507
* Contains the methods available on this I_S table.
509
InfoSchemaMethods *i_s_methods;
513
#endif /* DRIZZLED_INFO_SCHEMA_H */