~drizzle-trunk/drizzle/development

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 *
 *  Copyright (C) 2009 Sun Microsystems
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef DRIZZLED_INFO_SCHEMA_H
#define DRIZZLED_INFO_SCHEMA_H

/**
 * @file
 *   info_schema.h
 * @brief 
 *   Header file which contains all classes related to I_S
 */

typedef class Item COND;


/**
 * @class 
 *   ColumnInfo
 * @brief
 *   Represents a field (column) in an I_S table.
 */
class ColumnInfo
{
public:
  ColumnInfo(const char *in_name,
            uint32_t in_field_length,
            enum enum_field_types in_field_type,
            int in_value,
            uint32_t in_field_flags,
            const char *in_old_name,
            uint32_t in_open_method)
    :
      field_name(in_name),
      field_length(in_field_length),
      field_type(in_field_type),
      value(in_value),
      field_flags(in_field_flags),
      old_name(in_old_name),
      open_method(in_open_method)
  {}

  ColumnInfo()
    :
      field_name(NULL),
      field_length(0),
      field_type(DRIZZLE_TYPE_VARCHAR),
      field_flags(0),
      old_name(NULL),
      open_method(SKIP_OPEN_TABLE)
  {}

  /**
   * @return the name of this field.
   */
  const char *getName() const
  {
    return field_name;
  }

  /**
   * @return the old name of this field.
   */
  const char *getOldName() const
  {
    return old_name;
  }

  /**
   * @return the open method for this field.
   */
  uint32_t getOpenMethod() const
  {
    return open_method;
  }

  /**
   * @return the flags for this field.
   */
  uint32_t getFlags() const
  {
    return field_flags;
  }

  /**
   * @return the length of this field.
   */
  uint32_t getLength() const
  {
    return field_length;
  }

  /**
   * @return the value of this field.
   */
  int getValue() const
  {
    return value;
  }

  /**
   * @return this field's type.
   */
  enum enum_field_types getType() const
  {
    return field_type;
  }

private:

  /**
   * This is used as column name.
   */
  const char* field_name;

  /**
   * For string-type columns, this is the maximum number of
   * characters. Otherwise, it is the 'display-length' for the column.
   */
  uint32_t field_length;

  /**
   * This denotes data type for the column. For the most part, there seems to
   * be one entry in the enum for each SQL data type, although there seem to
   * be a number of additional entries in the enum.
   */
  enum enum_field_types field_type;

  int value;

  /**
   * This is used to set column attributes. By default, columns are @c NOT
   * @c NULL and @c SIGNED, and you can deviate from the default
   * by setting the appopriate flags. You can use either one of the flags
   * @c MY_I_S_MAYBE_NULL and @cMY_I_S_UNSIGNED or
   * combine them using the bitwise or operator @c |. Both flags are
   * defined in table.h.
   */
  uint32_t field_flags;

  const char* old_name;

  /**
   * This should be one of @c SKIP_OPEN_TABLE,
   * @c OPEN_FRM_ONLY or @c OPEN_FULL_TABLE.
   */
  uint32_t open_method;

};

/**
 * @class 
 *   InfoSchemaMethods
 * @brief
 *   The methods that an I_S table can support
 */
class InfoSchemaMethods
{
public:
  virtual ~InfoSchemaMethods() {}

  virtual Table *createSchemaTable(Session *session,
                                   TableList *table_list) const;
  virtual int fillTable(Session *session, 
                        TableList *tables,
                        COND *cond);
  virtual int processTable(Session *session, TableList *tables,
                           Table *table, bool res, LEX_STRING *db_name,
                           LEX_STRING *table_name) const;
  virtual int oldFormat(Session *session, 
                        InfoSchemaTable *schema_table) const;
};

class CharSetISMethods : public InfoSchemaMethods
{
public:
  virtual int fillTable(Session *session, 
                        TableList *tables,
                        COND *cond);
  virtual int oldFormat(Session *session, InfoSchemaTable *schema_table) const;
};

class CollationISMethods : public InfoSchemaMethods
{
public:
  virtual int fillTable(Session *session, 
                        TableList *tables,
                        COND *cond);
};

class CollCharISMethods : public InfoSchemaMethods
{
public:
  virtual int fillTable(Session *session, 
                        TableList *tables,
                        COND *cond);
};

class ColumnsISMethods : public InfoSchemaMethods
{
public:
  virtual int oldFormat(Session *session, InfoSchemaTable *schema_table) const;
};

class StatusISMethods : public InfoSchemaMethods
{
public:
  virtual int fillTable(Session *session, 
                        TableList *tables,
                        COND *cond);
};

class VariablesISMethods : public InfoSchemaMethods
{
public:
  virtual int fillTable(Session *session, 
                        TableList *tables,
                        COND *cond);
};

class KeyColUsageISMethods : public InfoSchemaMethods
{
public:
  virtual int processTable(Session *session, TableList *tables,
                           Table *table, bool res, LEX_STRING *db_name,
                           LEX_STRING *table_name) const;
};

class OpenTablesISMethods : public InfoSchemaMethods
{
public:
  virtual int fillTable(Session *session, 
                        TableList *tables,
                        COND *cond);
};

class PluginsISMethods : public InfoSchemaMethods
{
public:
  virtual int fillTable(Session *session, 
                        TableList *tables,
                        COND *cond);
};

class ProcessListISMethods : public InfoSchemaMethods
{
public:
  virtual int fillTable(Session *session, 
                        TableList *tables,
                        COND *cond);
};

class RefConstraintsISMethods : public InfoSchemaMethods
{
public:
  virtual int processTable(Session *session, TableList *tables,
                           Table *table, bool res, LEX_STRING *db_name,
                           LEX_STRING *table_name) const;
};

class SchemataISMethods : public InfoSchemaMethods
{
public:
  virtual int fillTable(Session *session, 
                        TableList *tables,
                        COND *cond);
  virtual int oldFormat(Session *session, InfoSchemaTable *schema_table) const;
};

class StatsISMethods : public InfoSchemaMethods
{
public:
  virtual int processTable(Session *session, TableList *tables,
                           Table *table, bool res, LEX_STRING *db_name,
                           LEX_STRING *table_name) const;
};

class TablesISMethods : public InfoSchemaMethods
{
public:
  virtual int processTable(Session *session, TableList *tables,
                           Table *table, bool res, LEX_STRING *db_name,
                           LEX_STRING *table_name) const;
};

class TabConstraintsISMethods : public InfoSchemaMethods
{
public:
  virtual int processTable(Session *session, TableList *tables,
                           Table *table, bool res, LEX_STRING *db_name,
                           LEX_STRING *table_name) const;
};

class TabNamesISMethods : public InfoSchemaMethods
{
public:
  virtual int oldFormat(Session *session, InfoSchemaTable *schema_table) const;
};

/**
 * @class 
 *   InfoSchemaTable
 * @brief 
 *   Represents an I_S table.
 */
class InfoSchemaTable
{
public:
  InfoSchemaTable(const char *tabName,
                  ColumnInfo *inColumnInfo,
                  int idxCol1,
                  int idxCol2,
                  bool inHidden,
                  bool inOptPossible,
                  uint32_t reqObject,
                  InfoSchemaMethods *inMethods)
    :
      table_name(tabName),
      hidden(inHidden),
      is_opt_possible(inOptPossible),
      first_column_index(idxCol1),
      second_column_index(idxCol2),
      requested_object(reqObject),
      column_info(inColumnInfo),
      i_s_methods(inMethods)
  {}

  InfoSchemaTable()
    :
      table_name(NULL),
      hidden(false),
      is_opt_possible(false),
      first_column_index(0),
      second_column_index(0),
      requested_object(0),
      column_info(0),
      i_s_methods(NULL)
  {}

  /**
   * Set the methods available on this I_S table.
   * @param[in] new_methods the methods to use
   */
  void setInfoSchemaMethods(InfoSchemaMethods *new_methods)
  {
    i_s_methods= new_methods;
  }

  /**
   * Create the temporary I_S tables using schema_table data.
   *
   * @param[in] session a session handler
   * @param[in] table_list Used to pass I_S table information (fields,
   *                       tables, parameters, etc.) and table name
   * @retval \# pointer to created table
   * @retval NULL Can't create table
   */
  Table *createSchemaTable(Session *session, TableList *table_list) const
  {
    Table *retval= i_s_methods->createSchemaTable(session, table_list);
    return retval;
  }

  /**
   * Fill I_S table.
   *
   * @param[in] session a session handler
   * @param[in] tables I_S table
   * @param[in] cond 'WHERE' condition
   * @return 0 on success; 1 on error
   */
  int fillTable(Session *session, TableList *tables, COND *cond)
  {
    int retval= i_s_methods->fillTable(session, tables, cond);
    return retval;
  }

  /**
   * Fill and store records into an I_S table.
   *
   * @param[in] session a session handler
   * @param[in] tables table list (processed table)
   * @param[in] table I_S table
   * @param[in] res 1 means error during opening of the processed table
   *                0 means processed table opened without error
   * @param[in] db_name database name
   * @param[in] tab_name table name
   * @return 0 on success; 1 on error
   */
  int processTable(Session *session, TableList *tables, Table *table,
                   bool res, LEX_STRING *db_name, LEX_STRING *tab_name) const
  {
    int retval= i_s_methods->processTable(session, tables, table,
                                          res, db_name, tab_name);
    return retval;
  }

  /**
   * For old SHOW compatibility. It is used when old SHOW doesn't
   * have generated column names. Generates the list of fields
   * for SHOW.
   *
   * @param[in] session a session handler
   * @param[in] schema_table pointer to element of the I_S tables list
   */
  int oldFormat(Session *session, InfoSchemaTable *schema_table) const
  {
    int retval= i_s_methods->oldFormat(session, schema_table);
    return retval;
  }

  /**
   * Set the I_S tables name.
   * @param[in] new_name the name to set the table to
   */
  void setTableName(const char *new_name)
  {
    table_name= new_name;
  }

  /**
   * @param[in] new_first_index value to set first column index to
   */
  void setFirstColumnIndex(int new_first_index)
  {
    first_column_index= new_first_index;
  }

  /**
   * @param[in] new_second_index value to set second column index to
   */
  void setSecondColumnIndex(int new_second_index)
  {
    second_column_index= new_second_index;
  }

  /**
   * @param[in] in_column_info the columns info to use for this I_S table
   */
  void setColumnInfo(ColumnInfo *in_column_info)
  {
    column_info= in_column_info;
  }

  /**
   * @return the name of the I_S table.
   */
  const char *getTableName() const
  {
    return table_name;
  }

  /**
   * @return true if this I_S table is hidden; false otherwise.
   */
  bool isHidden() const
  {
    return hidden;
  }

  /**
   * @return true if I_S optimizations can be performed on this
   *         I_S table when running the fillTable method; false
   *         otherwise.
   */
  bool isOptimizationPossible() const
  {
    return is_opt_possible;
  }

  /**
   * @return the index for the first field.
   */
  int getFirstColumnIndex() const
  {
    return first_column_index;
  }

  /**
   * @return the index the second field.
   */
  int getSecondColumnIndex() const
  {
    return second_column_index;
  }

  /**
   * @return the requested object.
   */
  uint32_t getRequestedObject() const
  {
    return requested_object;
  }

  /**
   * @return the columns info for this I_S table.
   */
  ColumnInfo *getColumnsInfo() const
  {
    return column_info;
  }

  /**
   * @param[in] index the index of this column
   * @return the column at the given index
   */
  ColumnInfo *getSpecificColumn(int index) const
  {
    return &column_info[index];
  }

  /**
   * @param[in] index the index of this column
   * @return the name for the column at the given index
   */
  const char *getColumnName(int index) const
  {
    return column_info[index].getName();
  }

  /**
   * @param[in] index the index of this column
   * @return the open method for the column at the given index
   */
  int getColumnOpenMethod(int index) const
  {
    return column_info[index].getOpenMethod();
  }

private:
  /**
   * I_S table name.
   */
  const char *table_name;

  /**
   * Boolean which indicates whether this I_S table
   * is hidden or not. If it is hidden, it will not show
   * up in the list of I_S tables.
   */
  bool hidden;

  /**
   * Boolean which indicates whether optimizations are
   * possible on this I_S table when performing the
   * fillTable method.
   */
  bool is_opt_possible;

  /**
   * The index of the first column.
   */
  int first_column_index;

  /**
   * The index of the second column.
   */
  int second_column_index;

  /**
   * The object to open (TABLE | VIEW).
   */
  uint32_t requested_object;

  /**
   * The columns for this I_S table.
   */
  ColumnInfo *column_info;

  /**
   * Contains the methods available on this I_S table.
   */
  InfoSchemaMethods *i_s_methods;

};

#endif /* DRIZZLED_INFO_SCHEMA_H */