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
28
* Header file which contains all classes related to I_S
31
typedef class Item COND;
38
* Represents a field (column) in an I_S table.
43
ColumnInfo(const std::string& in_name,
45
enum enum_field_types in_type,
48
const std::string& in_old_name,
49
uint32_t in_open_method)
56
old_name(in_old_name),
57
open_method(in_open_method)
64
type(DRIZZLE_TYPE_VARCHAR),
67
open_method(SKIP_OPEN_TABLE)
71
* @return the name of this column.
73
const std::string &getName() const
79
* This method is only ever called from the
80
* InfoSchemaMethods::oldFormat() methods. It is mostly
81
* for old SHOW compatability. It is used when a list
82
* of fields need to be generated for SHOW. The names
83
* for those fields (or columns) are found by calling
84
* this method on each column in the I_S table.
86
* @return the old name of this column.
88
const std::string &getOldName() const
94
* @return the open method for this column.
96
uint32_t getOpenMethod() const
102
* @return the flags for this column.
104
uint32_t getFlags() const
110
* @return the length of this column.
112
uint32_t getLength() const
118
* @return the value of this column.
120
int32_t getValue() const
126
* @return this column's type.
128
enum enum_field_types getType() const
136
* This is used as column name.
138
const std::string name;
141
* For string-type columns, this is the maximum number of
142
* characters. Otherwise, it is the 'display-length' for the column.
147
* This denotes data type for the column. For the most part, there seems to
148
* be one entry in the enum for each SQL data type, although there seem to
149
* be a number of additional entries in the enum.
151
enum enum_field_types type;
156
* This is used to set column attributes. By default, columns are @c NOT
157
* @c NULL and @c SIGNED, and you can deviate from the default
158
* by setting the appopriate flags. You can use either one of the flags
159
* @c MY_I_S_MAYBE_NULL and @cMY_I_S_UNSIGNED or
160
* combine them using the bitwise or operator @c |. Both flags are
161
* defined in table.h.
166
* The name of this column which is used for old SHOW
169
const std::string old_name;
172
* This should be one of @c SKIP_OPEN_TABLE,
173
* @c OPEN_FRM_ONLY or @c OPEN_FULL_TABLE.
175
uint32_t open_method;
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 ColumnsISMethods : public InfoSchemaMethods
205
virtual int oldFormat(Session *session, InfoSchemaTable *schema_table) const;
208
class StatusISMethods : public InfoSchemaMethods
211
virtual int fillTable(Session *session,
216
class VariablesISMethods : public InfoSchemaMethods
219
virtual int fillTable(Session *session,
224
class OpenTablesISMethods : public InfoSchemaMethods
227
virtual int fillTable(Session *session,
232
class SchemataISMethods : public InfoSchemaMethods
235
virtual int fillTable(Session *session,
238
virtual int oldFormat(Session *session, InfoSchemaTable *schema_table) const;
241
class StatsISMethods : public InfoSchemaMethods
244
virtual int processTable(Session *session, TableList *tables,
245
Table *table, bool res, LEX_STRING *db_name,
246
LEX_STRING *table_name) const;
249
class TablesISMethods : public InfoSchemaMethods
252
virtual int processTable(Session *session, TableList *tables,
253
Table *table, bool res, LEX_STRING *db_name,
254
LEX_STRING *table_name) const;
257
class TabNamesISMethods : public InfoSchemaMethods
260
virtual int oldFormat(Session *session, InfoSchemaTable *schema_table) const;
267
* Represents an I_S table.
269
class InfoSchemaTable
273
typedef std::vector<const ColumnInfo *> Columns;
275
InfoSchemaTable(const std::string& tab_name,
276
ColumnInfo *in_column_info,
280
bool in_opt_possible,
282
InfoSchemaMethods *in_methods)
284
table_name(tab_name),
286
is_opt_possible(in_opt_possible),
287
first_column_index(idx_col1),
288
second_column_index(idx_col2),
289
requested_object(req_object),
291
i_s_methods(in_methods)
293
setColumnInfo(in_column_info);
296
InfoSchemaTable(const std::string& tab_name,
297
Columns& in_column_info,
301
bool in_opt_possible,
303
InfoSchemaMethods *in_methods)
305
table_name(tab_name),
307
is_opt_possible(in_opt_possible),
308
first_column_index(idx_col1),
309
second_column_index(idx_col2),
310
requested_object(req_object),
311
column_info(in_column_info),
312
i_s_methods(in_methods)
319
is_opt_possible(false),
320
first_column_index(0),
321
second_column_index(0),
328
* Set the methods available on this I_S table.
329
* @param[in] new_methods the methods to use
331
void setInfoSchemaMethods(InfoSchemaMethods *new_methods)
333
i_s_methods= new_methods;
337
* Create the temporary I_S tables using schema_table data.
339
* @param[in] session a session handler
340
* @param[in] table_list Used to pass I_S table information (fields,
341
* tables, parameters, etc.) and table name
342
* @retval \# pointer to created table
343
* @retval NULL Can't create table
345
Table *createSchemaTable(Session *session, TableList *table_list) const
347
Table *retval= i_s_methods->createSchemaTable(session, table_list);
354
* @param[in] session a session handler
355
* @param[in] tables I_S table
356
* @param[in] cond 'WHERE' condition
357
* @return 0 on success; 1 on error
359
int fillTable(Session *session, TableList *tables, COND *cond)
361
int retval= i_s_methods->fillTable(session, tables, cond);
366
* Fill and store records into an I_S table.
368
* @param[in] session a session handler
369
* @param[in] tables table list (processed table)
370
* @param[in] table I_S table
371
* @param[in] res 1 means error during opening of the processed table
372
* 0 means processed table opened without error
373
* @param[in] db_name database name
374
* @param[in] tab_name table name
375
* @return 0 on success; 1 on error
377
int processTable(Session *session, TableList *tables, Table *table,
378
bool res, LEX_STRING *db_name, LEX_STRING *tab_name) const
380
int retval= i_s_methods->processTable(session, tables, table,
381
res, db_name, tab_name);
386
* For old SHOW compatibility. It is used when old SHOW doesn't
387
* have generated column names. Generates the list of fields
390
* @param[in] session a session handler
391
* @param[in] schema_table pointer to element of the I_S tables list
393
int oldFormat(Session *session, InfoSchemaTable *schema_table) const
395
int retval= i_s_methods->oldFormat(session, schema_table);
400
* Set the I_S tables name.
401
* @param[in] new_name the name to set the table to
403
void setTableName(const std::string &new_name)
405
table_name= new_name;
409
* @param[in] new_first_index value to set first column index to
411
void setFirstColumnIndex(int32_t new_first_index)
413
first_column_index= new_first_index;
417
* @param[in] new_second_index value to set second column index to
419
void setSecondColumnIndex(int32_t new_second_index)
421
second_column_index= new_second_index;
425
* @param[in] in_column_info the columns info to use for this I_S table
427
void setColumnInfo(ColumnInfo *in_column_info)
429
ColumnInfo *tmp= in_column_info;
430
for (; tmp->getName().length() != 0; tmp++)
432
column_info.push_back(tmp);
437
* @return the name of the I_S table.
439
const std::string &getTableName() const
445
* @return true if this I_S table is hidden; false otherwise.
447
bool isHidden() const
453
* @return true if I_S optimizations can be performed on this
454
* I_S table when running the fillTable method; false
457
bool isOptimizationPossible() const
459
return is_opt_possible;
463
* @return the index for the first field.
465
int32_t getFirstColumnIndex() const
467
return first_column_index;
471
* @return the index the second field.
473
int32_t getSecondColumnIndex() const
475
return second_column_index;
479
* @return the requested object.
481
uint32_t getRequestedObject() const
483
return requested_object;
487
* @return the columns for this I_S table
489
const Columns &getColumns() const
495
* @param[in] index the index of this column
496
* @return the name for the column at the given index
498
const std::string &getColumnName(int index) const
500
return column_info[index]->getName();
504
* @param[in] index the index of this column
505
* @return the open method for the column at the given index
507
uint32_t getColumnOpenMethod(int index) const
509
return column_info[index]->getOpenMethod();
516
std::string table_name;
519
* Boolean which indicates whether this I_S table
520
* is hidden or not. If it is hidden, it will not show
521
* up in the list of I_S tables.
526
* Boolean which indicates whether optimizations are
527
* possible on this I_S table when performing the
530
bool is_opt_possible;
533
* The index of the first column.
535
int32_t first_column_index;
538
* The index of the second column.
540
int32_t second_column_index;
543
* The object to open (TABLE | VIEW).
545
uint32_t requested_object;
548
* The columns for this I_S table.
553
* Contains the methods available on this I_S table.
555
InfoSchemaMethods *i_s_methods;
559
#endif /* DRIZZLED_INFO_SCHEMA_H */