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_PLUGIN_INFO_SCHEMA_TABLE_H
22
#define DRIZZLED_PLUGIN_INFO_SCHEMA_TABLE_H
35
* Header file which contains all classes related to I_S
38
typedef class Item COND;
44
* Represents a field (column) in an I_S table.
49
ColumnInfo(const std::string& in_name,
51
enum enum_field_types in_type,
54
const std::string& in_old_name,
55
uint32_t in_open_method)
62
old_name(in_old_name),
63
open_method(in_open_method)
70
type(DRIZZLE_TYPE_VARCHAR),
73
open_method(SKIP_OPEN_TABLE)
77
* @return the name of this column.
79
const std::string &getName() const
85
* This method is only ever called from the
86
* InfoSchemaMethods::oldFormat() methods. It is mostly
87
* for old SHOW compatability. It is used when a list
88
* of fields need to be generated for SHOW. The names
89
* for those fields (or columns) are found by calling
90
* this method on each column in the I_S table.
92
* @return the old name of this column.
94
const std::string &getOldName() const
100
* @return the open method for this column.
102
uint32_t getOpenMethod() const
108
* @return the flags for this column.
110
uint32_t getFlags() const
116
* @return the length of this column.
118
uint32_t getLength() const
124
* @return the value of this column.
126
int32_t getValue() const
132
* @return this column's type.
134
enum enum_field_types getType() const
142
* This is used as column name.
144
const std::string name;
147
* For string-type columns, this is the maximum number of
148
* characters. Otherwise, it is the 'display-length' for the column.
153
* This denotes data type for the column. For the most part, there seems to
154
* be one entry in the enum for each SQL data type, although there seem to
155
* be a number of additional entries in the enum.
157
enum enum_field_types type;
162
* This is used to set column attributes. By default, columns are @c NOT
163
* @c NULL and @c SIGNED, and you can deviate from the default
164
* by setting the appopriate flags. You can use either one of the flags
165
* @c MY_I_S_MAYBE_NULL and @cMY_I_S_UNSIGNED or
166
* combine them using the bitwise or operator @c |. Both flags are
167
* defined in table.h.
172
* The name of this column which is used for old SHOW
175
const std::string old_name;
178
* This should be one of @c SKIP_OPEN_TABLE,
179
* @c OPEN_FRM_ONLY or @c OPEN_FULL_TABLE.
181
uint32_t open_method;
186
* @class InfoSchemaMethods
188
* The methods that an I_S table can support
190
class InfoSchemaMethods
193
virtual ~InfoSchemaMethods() {}
195
virtual Table *createSchemaTable(Session *session,
196
TableList *table_list) const;
197
virtual int fillTable(Session *session,
200
virtual int processTable(Session *session, TableList *tables,
201
Table *table, bool res, LEX_STRING *db_name,
202
LEX_STRING *table_name) const;
203
virtual int oldFormat(Session *session,
204
InfoSchemaTable *schema_table) const;
208
* @class InfoSchemaTable
210
* Represents an I_S table.
212
class InfoSchemaTable : public Plugin
216
typedef std::vector<const ColumnInfo *> Columns;
218
InfoSchemaTable(const std::string& tab_name,
219
Columns& in_column_info,
223
bool in_opt_possible,
225
InfoSchemaMethods *in_methods)
228
table_name(tab_name),
230
is_opt_possible(in_opt_possible),
231
first_column_index(idx_col1),
232
second_column_index(idx_col2),
233
requested_object(req_object),
234
column_info(in_column_info),
235
i_s_methods(in_methods)
238
explicit InfoSchemaTable(const std::string& tab_name)
243
is_opt_possible(false),
244
first_column_index(0),
245
second_column_index(0),
252
* Set the methods available on this I_S table.
253
* @param[in] new_methods the methods to use
255
void setInfoSchemaMethods(InfoSchemaMethods *new_methods)
257
i_s_methods= new_methods;
261
* Create the temporary I_S tables using schema_table data.
263
* @param[in] session a session handler
264
* @param[in] table_list Used to pass I_S table information (fields,
265
* tables, parameters, etc.) and table name
266
* @retval \# pointer to created table
267
* @retval NULL Can't create table
269
Table *createSchemaTable(Session *session, TableList *table_list) const
271
Table *retval= i_s_methods->createSchemaTable(session, table_list);
278
* @param[in] session a session handler
279
* @param[in] tables I_S table
280
* @param[in] cond 'WHERE' condition
281
* @return 0 on success; 1 on error
283
int fillTable(Session *session, TableList *tables, COND *cond)
285
int retval= i_s_methods->fillTable(session, tables, cond);
290
* Fill and store records into an I_S table.
292
* @param[in] session a session handler
293
* @param[in] tables table list (processed table)
294
* @param[in] table I_S table
295
* @param[in] res 1 means error during opening of the processed table
296
* 0 means processed table opened without error
297
* @param[in] db_name database name
298
* @param[in] tab_name table name
299
* @return 0 on success; 1 on error
301
int processTable(Session *session, TableList *tables, Table *table,
302
bool res, LEX_STRING *db_name, LEX_STRING *tab_name) const
304
int retval= i_s_methods->processTable(session, tables, table,
305
res, db_name, tab_name);
310
* For old SHOW compatibility. It is used when old SHOW doesn't
311
* have generated column names. Generates the list of fields
314
* @param[in] session a session handler
315
* @param[in] schema_table pointer to element of the I_S tables list
317
int oldFormat(Session *session, InfoSchemaTable *schema_table) const
319
int retval= i_s_methods->oldFormat(session, schema_table);
324
* Set the I_S tables name.
325
* @param[in] new_name the name to set the table to
327
void setTableName(const std::string &new_name)
329
table_name= new_name;
333
* @param[in] new_first_index value to set first column index to
335
void setFirstColumnIndex(int32_t new_first_index)
337
first_column_index= new_first_index;
341
* @param[in] new_second_index value to set second column index to
343
void setSecondColumnIndex(int32_t new_second_index)
345
second_column_index= new_second_index;
349
* @param[in] in_column_info the columns info to use for this I_S table
351
void setColumnInfo(ColumnInfo *in_column_info)
353
ColumnInfo *tmp= in_column_info;
354
for (; tmp->getName().length() != 0; tmp++)
356
column_info.push_back(tmp);
361
* @return the name of the I_S table.
363
const std::string &getTableName() const
369
* @return true if this I_S table is hidden; false otherwise.
371
bool isHidden() const
377
* @return true if I_S optimizations can be performed on this
378
* I_S table when running the fillTable method; false
381
bool isOptimizationPossible() const
383
return is_opt_possible;
387
* @return the index for the first field.
389
int32_t getFirstColumnIndex() const
391
return first_column_index;
395
* @return the index the second field.
397
int32_t getSecondColumnIndex() const
399
return second_column_index;
403
* @return the requested object.
405
uint32_t getRequestedObject() const
407
return requested_object;
411
* @return the columns for this I_S table
413
const Columns &getColumns() const
419
* @param[in] index the index of this column
420
* @return the name for the column at the given index
422
const std::string &getColumnName(int index) const
424
return column_info[index]->getName();
428
* @param[in] index the index of this column
429
* @return the open method for the column at the given index
431
uint32_t getColumnOpenMethod(int index) const
433
return column_info[index]->getOpenMethod();
440
std::string table_name;
443
* Boolean which indicates whether this I_S table
444
* is hidden or not. If it is hidden, it will not show
445
* up in the list of I_S tables.
450
* Boolean which indicates whether optimizations are
451
* possible on this I_S table when performing the
454
bool is_opt_possible;
457
* The index of the first column.
459
int32_t first_column_index;
462
* The index of the second column.
464
int32_t second_column_index;
467
* The object to open (TABLE | VIEW).
469
uint32_t requested_object;
472
* The columns for this I_S table.
477
* Contains the methods available on this I_S table.
479
InfoSchemaMethods *i_s_methods;
482
static void add(plugin::InfoSchemaTable *schema_table);
483
static void remove(plugin::InfoSchemaTable *table);
485
static plugin::InfoSchemaTable *getTable(const char *table_name);
486
static int addTableToList(Session *session, std::vector<LEX_STRING*> &files,
490
} /* namespace plugin */
491
} /* namespace drizzled */
493
#endif /* DRIZZLED_PLUGIN_INFO_SCHEMA_TABLE_H */