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 char *in_name,
44
uint32_t in_field_length,
45
enum enum_field_types in_field_type,
47
uint32_t in_field_flags,
48
const char *in_old_name,
49
uint32_t in_open_method)
52
field_length(in_field_length),
53
field_type(in_field_type),
55
field_flags(in_field_flags),
56
old_name(in_old_name),
57
open_method(in_open_method)
64
field_type(DRIZZLE_TYPE_VARCHAR),
67
open_method(SKIP_OPEN_TABLE)
71
* @return the name of this field.
73
const char *getName() const
79
* @return the old name of this field.
81
const char *getOldName() const
87
* @return the open method for this field.
89
uint32_t getOpenMethod() const
95
* @return the flags for this field.
97
uint32_t getFlags() const
103
* @return the length of this field.
105
uint32_t getLength() const
111
* @return the value of this field.
119
* @return this field's type.
121
enum enum_field_types getType() const
129
* This is used as column name.
131
const char* field_name;
134
* For string-type columns, this is the maximum number of
135
* characters. Otherwise, it is the 'display-length' for the column.
137
uint32_t field_length;
140
* This denotes data type for the column. For the most part, there seems to
141
* be one entry in the enum for each SQL data type, although there seem to
142
* be a number of additional entries in the enum.
144
enum enum_field_types field_type;
149
* This is used to set column attributes. By default, columns are @c NOT
150
* @c NULL and @c SIGNED, and you can deviate from the default
151
* by setting the appopriate flags. You can use either one of the flags
152
* @c MY_I_S_MAYBE_NULL and @cMY_I_S_UNSIGNED or
153
* combine them using the bitwise or operator @c |. Both flags are
154
* defined in table.h.
156
uint32_t field_flags;
158
const char* old_name;
161
* This should be one of @c SKIP_OPEN_TABLE,
162
* @c OPEN_FRM_ONLY or @c OPEN_FULL_TABLE.
164
uint32_t open_method;
172
* The methods that an I_S table can support
174
class InfoSchemaMethods
177
virtual ~InfoSchemaMethods() {}
179
virtual Table *createSchemaTable(Session *session,
180
TableList *table_list) const;
181
virtual int fillTable(Session *session,
184
virtual int processTable(Session *session, TableList *tables,
185
Table *table, bool res, LEX_STRING *db_name,
186
LEX_STRING *table_name) const;
187
virtual int oldFormat(Session *session,
188
InfoSchemaTable *schema_table) const;
191
class CharSetISMethods : public InfoSchemaMethods
194
virtual int fillTable(Session *session,
197
virtual int oldFormat(Session *session, InfoSchemaTable *schema_table) const;
200
class CollationISMethods : public InfoSchemaMethods
203
virtual int fillTable(Session *session,
208
class CollCharISMethods : public InfoSchemaMethods
211
virtual int fillTable(Session *session,
216
class ColumnsISMethods : public InfoSchemaMethods
219
virtual int oldFormat(Session *session, InfoSchemaTable *schema_table) const;
222
class StatusISMethods : public InfoSchemaMethods
225
virtual int fillTable(Session *session,
230
class VariablesISMethods : public InfoSchemaMethods
233
virtual int fillTable(Session *session,
238
class KeyColUsageISMethods : public InfoSchemaMethods
241
virtual int processTable(Session *session, TableList *tables,
242
Table *table, bool res, LEX_STRING *db_name,
243
LEX_STRING *table_name) const;
246
class OpenTablesISMethods : public InfoSchemaMethods
249
virtual int fillTable(Session *session,
254
class PluginsISMethods : public InfoSchemaMethods
257
virtual int fillTable(Session *session,
262
class ProcessListISMethods : public InfoSchemaMethods
265
virtual int fillTable(Session *session,
270
class RefConstraintsISMethods : public InfoSchemaMethods
273
virtual int processTable(Session *session, TableList *tables,
274
Table *table, bool res, LEX_STRING *db_name,
275
LEX_STRING *table_name) const;
278
class SchemataISMethods : public InfoSchemaMethods
281
virtual int fillTable(Session *session,
284
virtual int oldFormat(Session *session, InfoSchemaTable *schema_table) const;
287
class StatsISMethods : public InfoSchemaMethods
290
virtual int processTable(Session *session, TableList *tables,
291
Table *table, bool res, LEX_STRING *db_name,
292
LEX_STRING *table_name) const;
295
class TablesISMethods : public InfoSchemaMethods
298
virtual int processTable(Session *session, TableList *tables,
299
Table *table, bool res, LEX_STRING *db_name,
300
LEX_STRING *table_name) const;
303
class TabConstraintsISMethods : public InfoSchemaMethods
306
virtual int processTable(Session *session, TableList *tables,
307
Table *table, bool res, LEX_STRING *db_name,
308
LEX_STRING *table_name) const;
311
class TabNamesISMethods : public InfoSchemaMethods
314
virtual int oldFormat(Session *session, InfoSchemaTable *schema_table) const;
321
* Represents an I_S table.
323
class InfoSchemaTable
326
InfoSchemaTable(const char *tabName,
327
ColumnInfo *inColumnInfo,
333
InfoSchemaMethods *inMethods)
337
is_opt_possible(inOptPossible),
338
first_column_index(idxCol1),
339
second_column_index(idxCol2),
340
requested_object(reqObject),
341
column_info(inColumnInfo),
342
i_s_methods(inMethods)
349
is_opt_possible(false),
350
first_column_index(0),
351
second_column_index(0),
358
* Set the methods available on this I_S table.
359
* @param[in] new_methods the methods to use
361
void setInfoSchemaMethods(InfoSchemaMethods *new_methods)
363
i_s_methods= new_methods;
367
* Create the temporary I_S tables using schema_table data.
369
* @param[in] session a session handler
370
* @param[in] table_list Used to pass I_S table information (fields,
371
* tables, parameters, etc.) and table name
372
* @retval \# pointer to created table
373
* @retval NULL Can't create table
375
Table *createSchemaTable(Session *session, TableList *table_list) const
377
Table *retval= i_s_methods->createSchemaTable(session, table_list);
384
* @param[in] session a session handler
385
* @param[in] tables I_S table
386
* @param[in] cond 'WHERE' condition
387
* @return 0 on success; 1 on error
389
int fillTable(Session *session, TableList *tables, COND *cond)
391
int retval= i_s_methods->fillTable(session, tables, cond);
396
* Fill and store records into an I_S table.
398
* @param[in] session a session handler
399
* @param[in] tables table list (processed table)
400
* @param[in] table I_S table
401
* @param[in] res 1 means error during opening of the processed table
402
* 0 means processed table opened without error
403
* @param[in] db_name database name
404
* @param[in] tab_name table name
405
* @return 0 on success; 1 on error
407
int processTable(Session *session, TableList *tables, Table *table,
408
bool res, LEX_STRING *db_name, LEX_STRING *tab_name) const
410
int retval= i_s_methods->processTable(session, tables, table,
411
res, db_name, tab_name);
416
* For old SHOW compatibility. It is used when old SHOW doesn't
417
* have generated column names. Generates the list of fields
420
* @param[in] session a session handler
421
* @param[in] schema_table pointer to element of the I_S tables list
423
int oldFormat(Session *session, InfoSchemaTable *schema_table) const
425
int retval= i_s_methods->oldFormat(session, schema_table);
430
* Set the I_S tables name.
431
* @param[in] new_name the name to set the table to
433
void setTableName(const char *new_name)
435
table_name= new_name;
439
* @param[in] new_first_index value to set first column index to
441
void setFirstColumnIndex(int new_first_index)
443
first_column_index= new_first_index;
447
* @param[in] new_second_index value to set second column index to
449
void setSecondColumnIndex(int new_second_index)
451
second_column_index= new_second_index;
455
* @param[in] in_column_info the columns info to use for this I_S table
457
void setColumnInfo(ColumnInfo *in_column_info)
459
column_info= in_column_info;
463
* @return the name of the I_S table.
465
const char *getTableName() const
471
* @return true if this I_S table is hidden; false otherwise.
473
bool isHidden() const
479
* @return true if I_S optimizations can be performed on this
480
* I_S table when running the fillTable method; false
483
bool isOptimizationPossible() const
485
return is_opt_possible;
489
* @return the index for the first field.
491
int getFirstColumnIndex() const
493
return first_column_index;
497
* @return the index the second field.
499
int getSecondColumnIndex() const
501
return second_column_index;
505
* @return the requested object.
507
uint32_t getRequestedObject() const
509
return requested_object;
513
* @return the columns info for this I_S table.
515
ColumnInfo *getColumnsInfo() const
521
* @param[in] index the index of this column
522
* @return the column at the given index
524
ColumnInfo *getSpecificColumn(int index) const
526
return &column_info[index];
530
* @param[in] index the index of this column
531
* @return the name for the column at the given index
533
const char *getColumnName(int index) const
535
return column_info[index].getName();
539
* @param[in] index the index of this column
540
* @return the open method for the column at the given index
542
int getColumnOpenMethod(int index) const
544
return column_info[index].getOpenMethod();
551
const char *table_name;
554
* Boolean which indicates whether this I_S table
555
* is hidden or not. If it is hidden, it will not show
556
* up in the list of I_S tables.
561
* Boolean which indicates whether optimizations are
562
* possible on this I_S table when performing the
565
bool is_opt_possible;
568
* The index of the first column.
570
int first_column_index;
573
* The index of the second column.
575
int second_column_index;
578
* The object to open (TABLE | VIEW).
580
uint32_t requested_object;
583
* The columns for this I_S table.
585
ColumnInfo *column_info;
588
* Contains the methods available on this I_S table.
590
InfoSchemaMethods *i_s_methods;
594
#endif /* DRIZZLED_INFO_SCHEMA_H */