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;
203
* @class InfoSchemaTable
205
* Represents an I_S table.
207
class InfoSchemaTable
211
typedef std::vector<const ColumnInfo *> Columns;
213
InfoSchemaTable(const std::string& tab_name,
214
Columns& in_column_info,
218
bool in_opt_possible,
220
InfoSchemaMethods *in_methods)
222
table_name(tab_name),
224
is_opt_possible(in_opt_possible),
225
first_column_index(idx_col1),
226
second_column_index(idx_col2),
227
requested_object(req_object),
228
column_info(in_column_info),
229
i_s_methods(in_methods)
236
is_opt_possible(false),
237
first_column_index(0),
238
second_column_index(0),
245
* Set the methods available on this I_S table.
246
* @param[in] new_methods the methods to use
248
void setInfoSchemaMethods(InfoSchemaMethods *new_methods)
250
i_s_methods= new_methods;
254
* Create the temporary I_S tables using schema_table data.
256
* @param[in] session a session handler
257
* @param[in] table_list Used to pass I_S table information (fields,
258
* tables, parameters, etc.) and table name
259
* @retval \# pointer to created table
260
* @retval NULL Can't create table
262
Table *createSchemaTable(Session *session, TableList *table_list) const
264
Table *retval= i_s_methods->createSchemaTable(session, table_list);
271
* @param[in] session a session handler
272
* @param[in] tables I_S table
273
* @param[in] cond 'WHERE' condition
274
* @return 0 on success; 1 on error
276
int fillTable(Session *session, TableList *tables, COND *cond)
278
int retval= i_s_methods->fillTable(session, tables, cond);
283
* Fill and store records into an I_S table.
285
* @param[in] session a session handler
286
* @param[in] tables table list (processed table)
287
* @param[in] table I_S table
288
* @param[in] res 1 means error during opening of the processed table
289
* 0 means processed table opened without error
290
* @param[in] db_name database name
291
* @param[in] tab_name table name
292
* @return 0 on success; 1 on error
294
int processTable(Session *session, TableList *tables, Table *table,
295
bool res, LEX_STRING *db_name, LEX_STRING *tab_name) const
297
int retval= i_s_methods->processTable(session, tables, table,
298
res, db_name, tab_name);
303
* For old SHOW compatibility. It is used when old SHOW doesn't
304
* have generated column names. Generates the list of fields
307
* @param[in] session a session handler
308
* @param[in] schema_table pointer to element of the I_S tables list
310
int oldFormat(Session *session, InfoSchemaTable *schema_table) const
312
int retval= i_s_methods->oldFormat(session, schema_table);
317
* Set the I_S tables name.
318
* @param[in] new_name the name to set the table to
320
void setTableName(const std::string &new_name)
322
table_name= new_name;
326
* @param[in] new_first_index value to set first column index to
328
void setFirstColumnIndex(int32_t new_first_index)
330
first_column_index= new_first_index;
334
* @param[in] new_second_index value to set second column index to
336
void setSecondColumnIndex(int32_t new_second_index)
338
second_column_index= new_second_index;
342
* @param[in] in_column_info the columns info to use for this I_S table
344
void setColumnInfo(ColumnInfo *in_column_info)
346
ColumnInfo *tmp= in_column_info;
347
for (; tmp->getName().length() != 0; tmp++)
349
column_info.push_back(tmp);
354
* @return the name of the I_S table.
356
const std::string &getTableName() const
362
* @return true if this I_S table is hidden; false otherwise.
364
bool isHidden() const
370
* @return true if I_S optimizations can be performed on this
371
* I_S table when running the fillTable method; false
374
bool isOptimizationPossible() const
376
return is_opt_possible;
380
* @return the index for the first field.
382
int32_t getFirstColumnIndex() const
384
return first_column_index;
388
* @return the index the second field.
390
int32_t getSecondColumnIndex() const
392
return second_column_index;
396
* @return the requested object.
398
uint32_t getRequestedObject() const
400
return requested_object;
404
* @return the columns for this I_S table
406
const Columns &getColumns() const
412
* @param[in] index the index of this column
413
* @return the name for the column at the given index
415
const std::string &getColumnName(int index) const
417
return column_info[index]->getName();
421
* @param[in] index the index of this column
422
* @return the open method for the column at the given index
424
uint32_t getColumnOpenMethod(int index) const
426
return column_info[index]->getOpenMethod();
433
std::string table_name;
436
* Boolean which indicates whether this I_S table
437
* is hidden or not. If it is hidden, it will not show
438
* up in the list of I_S tables.
443
* Boolean which indicates whether optimizations are
444
* possible on this I_S table when performing the
447
bool is_opt_possible;
450
* The index of the first column.
452
int32_t first_column_index;
455
* The index of the second column.
457
int32_t second_column_index;
460
* The object to open (TABLE | VIEW).
462
uint32_t requested_object;
465
* The columns for this I_S table.
470
* Contains the methods available on this I_S table.
472
InfoSchemaMethods *i_s_methods;
476
#endif /* DRIZZLED_INFO_SCHEMA_H */