~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/info_schema.h

Merge Padraig

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2009 Sun Microsystems
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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
 
19
 */
 
20
 
 
21
#ifndef DRIZZLED_INFO_SCHEMA_H
 
22
#define DRIZZLED_INFO_SCHEMA_H
 
23
 
 
24
/**
 
25
 * @file
 
26
 *   info_schema.h
 
27
 * @brief 
 
28
 *   Header file which contains all classes related to I_S
 
29
 */
 
30
 
 
31
typedef class Item COND;
 
32
 
 
33
 
 
34
/**
 
35
 * @class 
 
36
 *   ColumnInfo
 
37
 * @brief
 
38
 *   Represents a field (column) in an I_S table.
 
39
 */
 
40
class ColumnInfo
 
41
{
 
42
public:
 
43
  ColumnInfo(const char *in_name,
 
44
            uint32_t in_field_length,
 
45
            enum enum_field_types in_field_type,
 
46
            int in_value,
 
47
            uint32_t in_field_flags,
 
48
            const char *in_old_name,
 
49
            uint32_t in_open_method)
 
50
    :
 
51
      field_name(in_name),
 
52
      field_length(in_field_length),
 
53
      field_type(in_field_type),
 
54
      value(in_value),
 
55
      field_flags(in_field_flags),
 
56
      old_name(in_old_name),
 
57
      open_method(in_open_method)
 
58
  {}
 
59
 
 
60
  ColumnInfo()
 
61
    :
 
62
      field_name(NULL),
 
63
      field_length(0),
 
64
      field_type(DRIZZLE_TYPE_VARCHAR),
 
65
      field_flags(0),
 
66
      old_name(NULL),
 
67
      open_method(SKIP_OPEN_TABLE)
 
68
  {}
 
69
 
 
70
  /**
 
71
   * @return the name of this field.
 
72
   */
 
73
  const char *getName() const
 
74
  {
 
75
    return field_name;
 
76
  }
 
77
 
 
78
  /**
 
79
   * @return the old name of this field.
 
80
   */
 
81
  const char *getOldName() const
 
82
  {
 
83
    return old_name;
 
84
  }
 
85
 
 
86
  /**
 
87
   * @return the open method for this field.
 
88
   */
 
89
  uint32_t getOpenMethod() const
 
90
  {
 
91
    return open_method;
 
92
  }
 
93
 
 
94
  /**
 
95
   * @return the flags for this field.
 
96
   */
 
97
  uint32_t getFlags() const
 
98
  {
 
99
    return field_flags;
 
100
  }
 
101
 
 
102
  /**
 
103
   * @return the length of this field.
 
104
   */
 
105
  uint32_t getLength() const
 
106
  {
 
107
    return field_length;
 
108
  }
 
109
 
 
110
  /**
 
111
   * @return the value of this field.
 
112
   */
 
113
  int getValue() const
 
114
  {
 
115
    return value;
 
116
  }
 
117
 
 
118
  /**
 
119
   * @return this field's type.
 
120
   */
 
121
  enum enum_field_types getType() const
 
122
  {
 
123
    return field_type;
 
124
  }
 
125
 
 
126
private:
 
127
 
 
128
  /**
 
129
   * This is used as column name.
 
130
   */
 
131
  const char* field_name;
 
132
 
 
133
  /**
 
134
   * For string-type columns, this is the maximum number of
 
135
   * characters. Otherwise, it is the 'display-length' for the column.
 
136
   */
 
137
  uint32_t field_length;
 
138
 
 
139
  /**
 
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.
 
143
   */
 
144
  enum enum_field_types field_type;
 
145
 
 
146
  int value;
 
147
 
 
148
  /**
 
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.
 
155
   */
 
156
  uint32_t field_flags;
 
157
 
 
158
  const char* old_name;
 
159
 
 
160
  /**
 
161
   * This should be one of @c SKIP_OPEN_TABLE,
 
162
   * @c OPEN_FRM_ONLY or @c OPEN_FULL_TABLE.
 
163
   */
 
164
  uint32_t open_method;
 
165
 
 
166
};
 
167
 
 
168
/**
 
169
 * @class 
 
170
 *   InfoSchemaMethods
 
171
 * @brief
 
172
 *   The methods that an I_S table can support
 
173
 */
 
174
class InfoSchemaMethods
 
175
{
 
176
public:
 
177
  virtual ~InfoSchemaMethods() {}
 
178
 
 
179
  virtual Table *createSchemaTable(Session *session,
 
180
                                   TableList *table_list) const;
 
181
  virtual int fillTable(Session *session, 
 
182
                        TableList *tables,
 
183
                        COND *cond);
 
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;
 
189
};
 
190
 
 
191
class CharSetISMethods : public InfoSchemaMethods
 
192
{
 
193
public:
 
194
  virtual int fillTable(Session *session, 
 
195
                        TableList *tables,
 
196
                        COND *cond);
 
197
  virtual int oldFormat(Session *session, InfoSchemaTable *schema_table) const;
 
198
};
 
199
 
 
200
class CollationISMethods : public InfoSchemaMethods
 
201
{
 
202
public:
 
203
  virtual int fillTable(Session *session, 
 
204
                        TableList *tables,
 
205
                        COND *cond);
 
206
};
 
207
 
 
208
class CollCharISMethods : public InfoSchemaMethods
 
209
{
 
210
public:
 
211
  virtual int fillTable(Session *session, 
 
212
                        TableList *tables,
 
213
                        COND *cond);
 
214
};
 
215
 
 
216
class ColumnsISMethods : public InfoSchemaMethods
 
217
{
 
218
public:
 
219
  virtual int oldFormat(Session *session, InfoSchemaTable *schema_table) const;
 
220
};
 
221
 
 
222
class StatusISMethods : public InfoSchemaMethods
 
223
{
 
224
public:
 
225
  virtual int fillTable(Session *session, 
 
226
                        TableList *tables,
 
227
                        COND *cond);
 
228
};
 
229
 
 
230
class VariablesISMethods : public InfoSchemaMethods
 
231
{
 
232
public:
 
233
  virtual int fillTable(Session *session, 
 
234
                        TableList *tables,
 
235
                        COND *cond);
 
236
};
 
237
 
 
238
class KeyColUsageISMethods : public InfoSchemaMethods
 
239
{
 
240
public:
 
241
  virtual int processTable(Session *session, TableList *tables,
 
242
                           Table *table, bool res, LEX_STRING *db_name,
 
243
                           LEX_STRING *table_name) const;
 
244
};
 
245
 
 
246
class OpenTablesISMethods : public InfoSchemaMethods
 
247
{
 
248
public:
 
249
  virtual int fillTable(Session *session, 
 
250
                        TableList *tables,
 
251
                        COND *cond);
 
252
};
 
253
 
 
254
class PluginsISMethods : public InfoSchemaMethods
 
255
{
 
256
public:
 
257
  virtual int fillTable(Session *session, 
 
258
                        TableList *tables,
 
259
                        COND *cond);
 
260
};
 
261
 
 
262
class ProcessListISMethods : public InfoSchemaMethods
 
263
{
 
264
public:
 
265
  virtual int fillTable(Session *session, 
 
266
                        TableList *tables,
 
267
                        COND *cond);
 
268
};
 
269
 
 
270
class RefConstraintsISMethods : public InfoSchemaMethods
 
271
{
 
272
public:
 
273
  virtual int processTable(Session *session, TableList *tables,
 
274
                           Table *table, bool res, LEX_STRING *db_name,
 
275
                           LEX_STRING *table_name) const;
 
276
};
 
277
 
 
278
class SchemataISMethods : public InfoSchemaMethods
 
279
{
 
280
public:
 
281
  virtual int fillTable(Session *session, 
 
282
                        TableList *tables,
 
283
                        COND *cond);
 
284
  virtual int oldFormat(Session *session, InfoSchemaTable *schema_table) const;
 
285
};
 
286
 
 
287
class StatsISMethods : public InfoSchemaMethods
 
288
{
 
289
public:
 
290
  virtual int processTable(Session *session, TableList *tables,
 
291
                           Table *table, bool res, LEX_STRING *db_name,
 
292
                           LEX_STRING *table_name) const;
 
293
};
 
294
 
 
295
class TablesISMethods : public InfoSchemaMethods
 
296
{
 
297
public:
 
298
  virtual int processTable(Session *session, TableList *tables,
 
299
                           Table *table, bool res, LEX_STRING *db_name,
 
300
                           LEX_STRING *table_name) const;
 
301
};
 
302
 
 
303
class TabConstraintsISMethods : public InfoSchemaMethods
 
304
{
 
305
public:
 
306
  virtual int processTable(Session *session, TableList *tables,
 
307
                           Table *table, bool res, LEX_STRING *db_name,
 
308
                           LEX_STRING *table_name) const;
 
309
};
 
310
 
 
311
class TabNamesISMethods : public InfoSchemaMethods
 
312
{
 
313
public:
 
314
  virtual int oldFormat(Session *session, InfoSchemaTable *schema_table) const;
 
315
};
 
316
 
 
317
/**
 
318
 * @class 
 
319
 *   InfoSchemaTable
 
320
 * @brief 
 
321
 *   Represents an I_S table.
 
322
 */
 
323
class InfoSchemaTable
 
324
{
 
325
public:
 
326
  InfoSchemaTable(const char *tabName,
 
327
                  ColumnInfo *inColumnInfo,
 
328
                  int idxCol1,
 
329
                  int idxCol2,
 
330
                  bool inHidden,
 
331
                  bool inOptPossible,
 
332
                  uint32_t reqObject,
 
333
                  InfoSchemaMethods *inMethods)
 
334
    :
 
335
      table_name(tabName),
 
336
      hidden(inHidden),
 
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)
 
343
  {}
 
344
 
 
345
  InfoSchemaTable()
 
346
    :
 
347
      table_name(NULL),
 
348
      hidden(false),
 
349
      is_opt_possible(false),
 
350
      first_column_index(0),
 
351
      second_column_index(0),
 
352
      requested_object(0),
 
353
      column_info(0),
 
354
      i_s_methods(NULL)
 
355
  {}
 
356
 
 
357
  /**
 
358
   * Set the methods available on this I_S table.
 
359
   * @param[in] new_methods the methods to use
 
360
   */
 
361
  void setInfoSchemaMethods(InfoSchemaMethods *new_methods)
 
362
  {
 
363
    i_s_methods= new_methods;
 
364
  }
 
365
 
 
366
  /**
 
367
   * Create the temporary I_S tables using schema_table data.
 
368
   *
 
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
 
374
   */
 
375
  Table *createSchemaTable(Session *session, TableList *table_list) const
 
376
  {
 
377
    Table *retval= i_s_methods->createSchemaTable(session, table_list);
 
378
    return retval;
 
379
  }
 
380
 
 
381
  /**
 
382
   * Fill I_S table.
 
383
   *
 
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
 
388
   */
 
389
  int fillTable(Session *session, TableList *tables, COND *cond)
 
390
  {
 
391
    int retval= i_s_methods->fillTable(session, tables, cond);
 
392
    return retval;
 
393
  }
 
394
 
 
395
  /**
 
396
   * Fill and store records into an I_S table.
 
397
   *
 
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
 
406
   */
 
407
  int processTable(Session *session, TableList *tables, Table *table,
 
408
                   bool res, LEX_STRING *db_name, LEX_STRING *tab_name) const
 
409
  {
 
410
    int retval= i_s_methods->processTable(session, tables, table,
 
411
                                          res, db_name, tab_name);
 
412
    return retval;
 
413
  }
 
414
 
 
415
  /**
 
416
   * For old SHOW compatibility. It is used when old SHOW doesn't
 
417
   * have generated column names. Generates the list of fields
 
418
   * for SHOW.
 
419
   *
 
420
   * @param[in] session a session handler
 
421
   * @param[in] schema_table pointer to element of the I_S tables list
 
422
   */
 
423
  int oldFormat(Session *session, InfoSchemaTable *schema_table) const
 
424
  {
 
425
    int retval= i_s_methods->oldFormat(session, schema_table);
 
426
    return retval;
 
427
  }
 
428
 
 
429
  /**
 
430
   * Set the I_S tables name.
 
431
   * @param[in] new_name the name to set the table to
 
432
   */
 
433
  void setTableName(const char *new_name)
 
434
  {
 
435
    table_name= new_name;
 
436
  }
 
437
 
 
438
  /**
 
439
   * @param[in] new_first_index value to set first column index to
 
440
   */
 
441
  void setFirstColumnIndex(int new_first_index)
 
442
  {
 
443
    first_column_index= new_first_index;
 
444
  }
 
445
 
 
446
  /**
 
447
   * @param[in] new_second_index value to set second column index to
 
448
   */
 
449
  void setSecondColumnIndex(int new_second_index)
 
450
  {
 
451
    second_column_index= new_second_index;
 
452
  }
 
453
 
 
454
  /**
 
455
   * @param[in] in_column_info the columns info to use for this I_S table
 
456
   */
 
457
  void setColumnInfo(ColumnInfo *in_column_info)
 
458
  {
 
459
    column_info= in_column_info;
 
460
  }
 
461
 
 
462
  /**
 
463
   * @return the name of the I_S table.
 
464
   */
 
465
  const char *getTableName() const
 
466
  {
 
467
    return table_name;
 
468
  }
 
469
 
 
470
  /**
 
471
   * @return true if this I_S table is hidden; false otherwise.
 
472
   */
 
473
  bool isHidden() const
 
474
  {
 
475
    return hidden;
 
476
  }
 
477
 
 
478
  /**
 
479
   * @return true if I_S optimizations can be performed on this
 
480
   *         I_S table when running the fillTable method; false
 
481
   *         otherwise.
 
482
   */
 
483
  bool isOptimizationPossible() const
 
484
  {
 
485
    return is_opt_possible;
 
486
  }
 
487
 
 
488
  /**
 
489
   * @return the index for the first field.
 
490
   */
 
491
  int getFirstColumnIndex() const
 
492
  {
 
493
    return first_column_index;
 
494
  }
 
495
 
 
496
  /**
 
497
   * @return the index the second field.
 
498
   */
 
499
  int getSecondColumnIndex() const
 
500
  {
 
501
    return second_column_index;
 
502
  }
 
503
 
 
504
  /**
 
505
   * @return the requested object.
 
506
   */
 
507
  uint32_t getRequestedObject() const
 
508
  {
 
509
    return requested_object;
 
510
  }
 
511
 
 
512
  /**
 
513
   * @return the columns info for this I_S table.
 
514
   */
 
515
  ColumnInfo *getColumnsInfo() const
 
516
  {
 
517
    return column_info;
 
518
  }
 
519
 
 
520
  /**
 
521
   * @param[in] index the index of this column
 
522
   * @return the column at the given index
 
523
   */
 
524
  ColumnInfo *getSpecificColumn(int index) const
 
525
  {
 
526
    return &column_info[index];
 
527
  }
 
528
 
 
529
  /**
 
530
   * @param[in] index the index of this column
 
531
   * @return the name for the column at the given index
 
532
   */
 
533
  const char *getColumnName(int index) const
 
534
  {
 
535
    return column_info[index].getName();
 
536
  }
 
537
 
 
538
  /**
 
539
   * @param[in] index the index of this column
 
540
   * @return the open method for the column at the given index
 
541
   */
 
542
  int getColumnOpenMethod(int index) const
 
543
  {
 
544
    return column_info[index].getOpenMethod();
 
545
  }
 
546
 
 
547
private:
 
548
  /**
 
549
   * I_S table name.
 
550
   */
 
551
  const char *table_name;
 
552
 
 
553
  /**
 
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.
 
557
   */
 
558
  bool hidden;
 
559
 
 
560
  /**
 
561
   * Boolean which indicates whether optimizations are
 
562
   * possible on this I_S table when performing the
 
563
   * fillTable method.
 
564
   */
 
565
  bool is_opt_possible;
 
566
 
 
567
  /**
 
568
   * The index of the first column.
 
569
   */
 
570
  int first_column_index;
 
571
 
 
572
  /**
 
573
   * The index of the second column.
 
574
   */
 
575
  int second_column_index;
 
576
 
 
577
  /**
 
578
   * The object to open (TABLE | VIEW).
 
579
   */
 
580
  uint32_t requested_object;
 
581
 
 
582
  /**
 
583
   * The columns for this I_S table.
 
584
   */
 
585
  ColumnInfo *column_info;
 
586
 
 
587
  /**
 
588
   * Contains the methods available on this I_S table.
 
589
   */
 
590
  InfoSchemaMethods *i_s_methods;
 
591
 
 
592
};
 
593
 
 
594
#endif /* DRIZZLED_INFO_SCHEMA_H */