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
215
InfoSchemaTable(const InfoSchemaTable &);
216
InfoSchemaTable& operator=(const InfoSchemaTable &);
219
typedef std::vector<const ColumnInfo *> Columns;
221
InfoSchemaTable(const std::string& tab_name,
222
Columns& in_column_info,
226
bool in_opt_possible,
228
InfoSchemaMethods *in_methods)
232
is_opt_possible(in_opt_possible),
233
first_column_index(idx_col1),
234
second_column_index(idx_col2),
235
requested_object(req_object),
236
column_info(in_column_info),
237
i_s_methods(in_methods)
240
explicit InfoSchemaTable(const std::string& tab_name)
244
is_opt_possible(false),
245
first_column_index(0),
246
second_column_index(0),
252
virtual ~InfoSchemaTable()
256
* Set the methods available on this I_S table.
257
* @param[in] new_methods the methods to use
259
void setInfoSchemaMethods(InfoSchemaMethods *new_methods)
261
i_s_methods= new_methods;
265
* Create the temporary I_S tables using schema_table data.
267
* @param[in] session a session handler
268
* @param[in] table_list Used to pass I_S table information (fields,
269
* tables, parameters, etc.) and table name
270
* @retval \# pointer to created table
271
* @retval NULL Can't create table
273
Table *createSchemaTable(Session *session, TableList *table_list) const
275
Table *retval= i_s_methods->createSchemaTable(session, table_list);
282
* @param[in] session a session handler
283
* @param[in] tables I_S table
284
* @param[in] cond 'WHERE' condition
285
* @return 0 on success; 1 on error
287
int fillTable(Session *session, TableList *tables, COND *cond)
289
int retval= i_s_methods->fillTable(session, tables, cond);
294
* Fill and store records into an I_S table.
296
* @param[in] session a session handler
297
* @param[in] tables table list (processed table)
298
* @param[in] table I_S table
299
* @param[in] res 1 means error during opening of the processed table
300
* 0 means processed table opened without error
301
* @param[in] db_name database name
302
* @param[in] tab_name table name
303
* @return 0 on success; 1 on error
305
int processTable(Session *session, TableList *tables, Table *table,
306
bool res, LEX_STRING *db_name, LEX_STRING *tab_name) const
308
int retval= i_s_methods->processTable(session, tables, table,
309
res, db_name, tab_name);
314
* For old SHOW compatibility. It is used when old SHOW doesn't
315
* have generated column names. Generates the list of fields
318
* @param[in] session a session handler
319
* @param[in] schema_table pointer to element of the I_S tables list
321
int oldFormat(Session *session, InfoSchemaTable *schema_table) const
323
int retval= i_s_methods->oldFormat(session, schema_table);
328
* @param[in] new_first_index value to set first column index to
330
void setFirstColumnIndex(int32_t new_first_index)
332
first_column_index= new_first_index;
336
* @param[in] new_second_index value to set second column index to
338
void setSecondColumnIndex(int32_t new_second_index)
340
second_column_index= new_second_index;
344
* @param[in] in_column_info the columns info to use for this I_S table
346
void setColumnInfo(ColumnInfo *in_column_info)
348
ColumnInfo *tmp= in_column_info;
349
for (; tmp->getName().length() != 0; tmp++)
351
column_info.push_back(tmp);
356
* @return the name of the I_S table.
358
const std::string &getTableName() const
364
* @return true if this I_S table is hidden; false otherwise.
366
bool isHidden() const
372
* @return true if I_S optimizations can be performed on this
373
* I_S table when running the fillTable method; false
376
bool isOptimizationPossible() const
378
return is_opt_possible;
382
* @return the index for the first field.
384
int32_t getFirstColumnIndex() const
386
return first_column_index;
390
* @return the index the second field.
392
int32_t getSecondColumnIndex() const
394
return second_column_index;
398
* @return the requested object.
400
uint32_t getRequestedObject() const
402
return requested_object;
406
* @return the columns for this I_S table
408
const Columns &getColumns() const
414
* @param[in] index the index of this column
415
* @return the name for the column at the given index
417
const std::string &getColumnName(int index) const
419
return column_info[index]->getName();
423
* @param[in] index the index of this column
424
* @return the open method for the column at the given index
426
uint32_t getColumnOpenMethod(int index) const
428
return column_info[index]->getOpenMethod();
434
* Boolean which indicates whether this I_S table
435
* is hidden or not. If it is hidden, it will not show
436
* up in the list of I_S tables.
441
* Boolean which indicates whether optimizations are
442
* possible on this I_S table when performing the
445
bool is_opt_possible;
448
* The index of the first column.
450
int32_t first_column_index;
453
* The index of the second column.
455
int32_t second_column_index;
458
* The object to open (TABLE | VIEW).
460
uint32_t requested_object;
463
* The columns for this I_S table.
468
* Contains the methods available on this I_S table.
470
InfoSchemaMethods *i_s_methods;
473
static bool addPlugin(plugin::InfoSchemaTable *schema_table);
474
static void removePlugin(plugin::InfoSchemaTable *table);
476
static plugin::InfoSchemaTable *getTable(const char *table_name);
477
static int addTableToList(Session *session, std::vector<LEX_STRING*> &files,
481
} /* namespace plugin */
482
} /* namespace drizzled */
484
#endif /* DRIZZLED_PLUGIN_INFO_SCHEMA_TABLE_H */