~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/info_schema.h

  • Committer: devananda
  • Date: 2009-06-30 14:27:54 UTC
  • mfrom: (1030.2.4 trunk)
  • mto: (1093.1.7 captain)
  • mto: This revision was merged to the branch mainline in revision 1095.
  • Revision ID: devananda.vdv@gmail.com-20090630142754-vm9w374yxkf1pikc
mergeĀ fromĀ lp

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 std::string& in_name, 
 
44
             uint32_t in_length, 
 
45
             enum enum_field_types in_type,
 
46
             int32_t in_value,
 
47
             uint32_t in_flags,
 
48
             const std::string& in_old_name,
 
49
             uint32_t in_open_method)
 
50
    :
 
51
      name(in_name),
 
52
      length(in_length),
 
53
      type(in_type),
 
54
      value(in_value),
 
55
      flags(in_flags),
 
56
      old_name(in_old_name),
 
57
      open_method(in_open_method)
 
58
  {}
 
59
 
 
60
  ColumnInfo()
 
61
    :
 
62
      name(),
 
63
      length(0),
 
64
      type(DRIZZLE_TYPE_VARCHAR),
 
65
      flags(0),
 
66
      old_name(),
 
67
      open_method(SKIP_OPEN_TABLE)
 
68
  {}
 
69
 
 
70
  /**
 
71
   * @return the name of this column.
 
72
   */
 
73
  const std::string &getName() const
 
74
  {
 
75
    return name;
 
76
  }
 
77
 
 
78
  /**
 
79
   * This method is only ever called from the
 
80
   * InfoSchemaMethods::oldFormat() methods. It is mostly
 
81
   * for old SHOW compatability. It is used when a list
 
82
   * of fields need to be generated for SHOW. The names
 
83
   * for those fields (or columns) are found by calling
 
84
   * this method on each column in the I_S table.
 
85
   *
 
86
   * @return the old name of this column.
 
87
   */
 
88
  const std::string &getOldName() const
 
89
  {
 
90
    return old_name;
 
91
  }
 
92
 
 
93
  /**
 
94
   * @return the open method for this column.
 
95
   */
 
96
  uint32_t getOpenMethod() const
 
97
  {
 
98
    return open_method;
 
99
  }
 
100
 
 
101
  /**
 
102
   * @return the flags for this column.
 
103
   */
 
104
  uint32_t getFlags() const
 
105
  {
 
106
    return flags;
 
107
  }
 
108
 
 
109
  /**
 
110
   * @return the length of this column.
 
111
   */
 
112
  uint32_t getLength() const
 
113
  {
 
114
    return length;
 
115
  }
 
116
 
 
117
  /**
 
118
   * @return the value of this column.
 
119
   */
 
120
  int32_t getValue() const
 
121
  {
 
122
    return value;
 
123
  }
 
124
 
 
125
  /**
 
126
   * @return this column's type.
 
127
   */
 
128
  enum enum_field_types getType() const
 
129
  {
 
130
    return type;
 
131
  }
 
132
 
 
133
private:
 
134
 
 
135
  /**
 
136
   * This is used as column name.
 
137
   */
 
138
  const std::string name;
 
139
 
 
140
  /**
 
141
   * For string-type columns, this is the maximum number of
 
142
   * characters. Otherwise, it is the 'display-length' for the column.
 
143
   */
 
144
  uint32_t length;
 
145
 
 
146
  /**
 
147
   * This denotes data type for the column. For the most part, there seems to
 
148
   * be one entry in the enum for each SQL data type, although there seem to
 
149
   * be a number of additional entries in the enum.
 
150
   */
 
151
  enum enum_field_types type;
 
152
 
 
153
  int32_t value;
 
154
 
 
155
  /**
 
156
   * This is used to set column attributes. By default, columns are @c NOT
 
157
   * @c NULL and @c SIGNED, and you can deviate from the default
 
158
   * by setting the appopriate flags. You can use either one of the flags
 
159
   * @c MY_I_S_MAYBE_NULL and @cMY_I_S_UNSIGNED or
 
160
   * combine them using the bitwise or operator @c |. Both flags are
 
161
   * defined in table.h.
 
162
   */
 
163
  uint32_t flags;
 
164
 
 
165
  /**
 
166
   * The name of this column which is used for old SHOW
 
167
   * compatability.
 
168
   */
 
169
  const std::string old_name;
 
170
 
 
171
  /**
 
172
   * This should be one of @c SKIP_OPEN_TABLE,
 
173
   * @c OPEN_FRM_ONLY or @c OPEN_FULL_TABLE.
 
174
   */
 
175
  uint32_t open_method;
 
176
 
 
177
};
 
178
 
 
179
/**
 
180
 * @class 
 
181
 *   InfoSchemaMethods
 
182
 * @brief
 
183
 *   The methods that an I_S table can support
 
184
 */
 
185
class InfoSchemaMethods
 
186
{
 
187
public:
 
188
  virtual ~InfoSchemaMethods() {}
 
189
 
 
190
  virtual Table *createSchemaTable(Session *session,
 
191
                                   TableList *table_list) const;
 
192
  virtual int fillTable(Session *session, 
 
193
                        TableList *tables,
 
194
                        COND *cond);
 
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;
 
200
};
 
201
 
 
202
class ColumnsISMethods : public InfoSchemaMethods
 
203
{
 
204
public:
 
205
  virtual int oldFormat(Session *session, InfoSchemaTable *schema_table) const;
 
206
};
 
207
 
 
208
class StatusISMethods : public InfoSchemaMethods
 
209
{
 
210
public:
 
211
  virtual int fillTable(Session *session, 
 
212
                        TableList *tables,
 
213
                        COND *cond);
 
214
};
 
215
 
 
216
class VariablesISMethods : public InfoSchemaMethods
 
217
{
 
218
public:
 
219
  virtual int fillTable(Session *session, 
 
220
                        TableList *tables,
 
221
                        COND *cond);
 
222
};
 
223
 
 
224
class OpenTablesISMethods : public InfoSchemaMethods
 
225
{
 
226
public:
 
227
  virtual int fillTable(Session *session, 
 
228
                        TableList *tables,
 
229
                        COND *cond);
 
230
};
 
231
 
 
232
class SchemataISMethods : public InfoSchemaMethods
 
233
{
 
234
public:
 
235
  virtual int fillTable(Session *session, 
 
236
                        TableList *tables,
 
237
                        COND *cond);
 
238
  virtual int oldFormat(Session *session, InfoSchemaTable *schema_table) const;
 
239
};
 
240
 
 
241
class StatsISMethods : public InfoSchemaMethods
 
242
{
 
243
public:
 
244
  virtual int processTable(Session *session, TableList *tables,
 
245
                           Table *table, bool res, LEX_STRING *db_name,
 
246
                           LEX_STRING *table_name) const;
 
247
};
 
248
 
 
249
class TablesISMethods : public InfoSchemaMethods
 
250
{
 
251
public:
 
252
  virtual int processTable(Session *session, TableList *tables,
 
253
                           Table *table, bool res, LEX_STRING *db_name,
 
254
                           LEX_STRING *table_name) const;
 
255
};
 
256
 
 
257
class TabNamesISMethods : public InfoSchemaMethods
 
258
{
 
259
public:
 
260
  virtual int oldFormat(Session *session, InfoSchemaTable *schema_table) const;
 
261
};
 
262
 
 
263
/**
 
264
 * @class 
 
265
 *   InfoSchemaTable
 
266
 * @brief 
 
267
 *   Represents an I_S table.
 
268
 */
 
269
class InfoSchemaTable
 
270
{
 
271
public:
 
272
 
 
273
  typedef std::vector<const ColumnInfo *> Columns;
 
274
  
 
275
  InfoSchemaTable(const std::string& tab_name,
 
276
                  ColumnInfo *in_column_info,
 
277
                  int32_t idx_col1,
 
278
                  int32_t idx_col2,
 
279
                  bool in_hidden,
 
280
                  bool in_opt_possible,
 
281
                  uint32_t req_object,
 
282
                  InfoSchemaMethods *in_methods)
 
283
    :
 
284
      table_name(tab_name),
 
285
      hidden(in_hidden),
 
286
      is_opt_possible(in_opt_possible),
 
287
      first_column_index(idx_col1),
 
288
      second_column_index(idx_col2),
 
289
      requested_object(req_object),
 
290
      column_info(),
 
291
      i_s_methods(in_methods)
 
292
  {
 
293
    setColumnInfo(in_column_info);
 
294
  }
 
295
 
 
296
  InfoSchemaTable(const std::string& tab_name,
 
297
                  Columns& in_column_info,
 
298
                  int idx_col1,
 
299
                  int idx_col2,
 
300
                  bool in_hidden,
 
301
                  bool in_opt_possible,
 
302
                  uint32_t req_object,
 
303
                  InfoSchemaMethods *in_methods)
 
304
    :
 
305
      table_name(tab_name),
 
306
      hidden(in_hidden),
 
307
      is_opt_possible(in_opt_possible),
 
308
      first_column_index(idx_col1),
 
309
      second_column_index(idx_col2),
 
310
      requested_object(req_object),
 
311
      column_info(in_column_info),
 
312
      i_s_methods(in_methods)
 
313
  {}
 
314
 
 
315
  InfoSchemaTable()
 
316
    :
 
317
      table_name(),
 
318
      hidden(false),
 
319
      is_opt_possible(false),
 
320
      first_column_index(0),
 
321
      second_column_index(0),
 
322
      requested_object(0),
 
323
      column_info(),
 
324
      i_s_methods(NULL)
 
325
  {}
 
326
 
 
327
  /**
 
328
   * Set the methods available on this I_S table.
 
329
   * @param[in] new_methods the methods to use
 
330
   */
 
331
  void setInfoSchemaMethods(InfoSchemaMethods *new_methods)
 
332
  {
 
333
    i_s_methods= new_methods;
 
334
  }
 
335
 
 
336
  /**
 
337
   * Create the temporary I_S tables using schema_table data.
 
338
   *
 
339
   * @param[in] session a session handler
 
340
   * @param[in] table_list Used to pass I_S table information (fields,
 
341
   *                       tables, parameters, etc.) and table name
 
342
   * @retval \# pointer to created table
 
343
   * @retval NULL Can't create table
 
344
   */
 
345
  Table *createSchemaTable(Session *session, TableList *table_list) const
 
346
  {
 
347
    Table *retval= i_s_methods->createSchemaTable(session, table_list);
 
348
    return retval;
 
349
  }
 
350
 
 
351
  /**
 
352
   * Fill I_S table.
 
353
   *
 
354
   * @param[in] session a session handler
 
355
   * @param[in] tables I_S table
 
356
   * @param[in] cond 'WHERE' condition
 
357
   * @return 0 on success; 1 on error
 
358
   */
 
359
  int fillTable(Session *session, TableList *tables, COND *cond)
 
360
  {
 
361
    int retval= i_s_methods->fillTable(session, tables, cond);
 
362
    return retval;
 
363
  }
 
364
 
 
365
  /**
 
366
   * Fill and store records into an I_S table.
 
367
   *
 
368
   * @param[in] session a session handler
 
369
   * @param[in] tables table list (processed table)
 
370
   * @param[in] table I_S table
 
371
   * @param[in] res 1 means error during opening of the processed table
 
372
   *                0 means processed table opened without error
 
373
   * @param[in] db_name database name
 
374
   * @param[in] tab_name table name
 
375
   * @return 0 on success; 1 on error
 
376
   */
 
377
  int processTable(Session *session, TableList *tables, Table *table,
 
378
                   bool res, LEX_STRING *db_name, LEX_STRING *tab_name) const
 
379
  {
 
380
    int retval= i_s_methods->processTable(session, tables, table,
 
381
                                          res, db_name, tab_name);
 
382
    return retval;
 
383
  }
 
384
 
 
385
  /**
 
386
   * For old SHOW compatibility. It is used when old SHOW doesn't
 
387
   * have generated column names. Generates the list of fields
 
388
   * for SHOW.
 
389
   *
 
390
   * @param[in] session a session handler
 
391
   * @param[in] schema_table pointer to element of the I_S tables list
 
392
   */
 
393
  int oldFormat(Session *session, InfoSchemaTable *schema_table) const
 
394
  {
 
395
    int retval= i_s_methods->oldFormat(session, schema_table);
 
396
    return retval;
 
397
  }
 
398
 
 
399
  /**
 
400
   * Set the I_S tables name.
 
401
   * @param[in] new_name the name to set the table to
 
402
   */
 
403
  void setTableName(const std::string &new_name)
 
404
  {
 
405
    table_name= new_name;
 
406
  }
 
407
 
 
408
  /**
 
409
   * @param[in] new_first_index value to set first column index to
 
410
   */
 
411
  void setFirstColumnIndex(int32_t new_first_index)
 
412
  {
 
413
    first_column_index= new_first_index;
 
414
  }
 
415
 
 
416
  /**
 
417
   * @param[in] new_second_index value to set second column index to
 
418
   */
 
419
  void setSecondColumnIndex(int32_t new_second_index)
 
420
  {
 
421
    second_column_index= new_second_index;
 
422
  }
 
423
 
 
424
  /**
 
425
   * @param[in] in_column_info the columns info to use for this I_S table
 
426
   */
 
427
  void setColumnInfo(ColumnInfo *in_column_info)
 
428
  {
 
429
    ColumnInfo *tmp= in_column_info;
 
430
    for (; tmp->getName().length() != 0; tmp++)
 
431
    {
 
432
      column_info.push_back(tmp);
 
433
    }
 
434
  }
 
435
 
 
436
  /**
 
437
   * @return the name of the I_S table.
 
438
   */
 
439
  const std::string &getTableName() const
 
440
  {
 
441
    return table_name;
 
442
  }
 
443
 
 
444
  /**
 
445
   * @return true if this I_S table is hidden; false otherwise.
 
446
   */
 
447
  bool isHidden() const
 
448
  {
 
449
    return hidden;
 
450
  }
 
451
 
 
452
  /**
 
453
   * @return true if I_S optimizations can be performed on this
 
454
   *         I_S table when running the fillTable method; false
 
455
   *         otherwise.
 
456
   */
 
457
  bool isOptimizationPossible() const
 
458
  {
 
459
    return is_opt_possible;
 
460
  }
 
461
 
 
462
  /**
 
463
   * @return the index for the first field.
 
464
   */
 
465
  int32_t getFirstColumnIndex() const
 
466
  {
 
467
    return first_column_index;
 
468
  }
 
469
 
 
470
  /**
 
471
   * @return the index the second field.
 
472
   */
 
473
  int32_t getSecondColumnIndex() const
 
474
  {
 
475
    return second_column_index;
 
476
  }
 
477
 
 
478
  /**
 
479
   * @return the requested object.
 
480
   */
 
481
  uint32_t getRequestedObject() const
 
482
  {
 
483
    return requested_object;
 
484
  }
 
485
 
 
486
  /**
 
487
   * @return the columns for this I_S table
 
488
   */
 
489
  const Columns &getColumns() const
 
490
  {
 
491
    return column_info;
 
492
  }
 
493
 
 
494
  /**
 
495
   * @param[in] index the index of this column
 
496
   * @return the name for the column at the given index
 
497
   */
 
498
  const std::string &getColumnName(int index) const
 
499
  {
 
500
    return column_info[index]->getName();
 
501
  }
 
502
 
 
503
  /**
 
504
   * @param[in] index the index of this column
 
505
   * @return the open method for the column at the given index
 
506
   */
 
507
  uint32_t getColumnOpenMethod(int index) const
 
508
  {
 
509
    return column_info[index]->getOpenMethod();
 
510
  }
 
511
 
 
512
private:
 
513
  /**
 
514
   * I_S table name.
 
515
   */
 
516
  std::string table_name;
 
517
 
 
518
  /**
 
519
   * Boolean which indicates whether this I_S table
 
520
   * is hidden or not. If it is hidden, it will not show
 
521
   * up in the list of I_S tables.
 
522
   */
 
523
  bool hidden;
 
524
 
 
525
  /**
 
526
   * Boolean which indicates whether optimizations are
 
527
   * possible on this I_S table when performing the
 
528
   * fillTable method.
 
529
   */
 
530
  bool is_opt_possible;
 
531
 
 
532
  /**
 
533
   * The index of the first column.
 
534
   */
 
535
  int32_t first_column_index;
 
536
 
 
537
  /**
 
538
   * The index of the second column.
 
539
   */
 
540
  int32_t second_column_index;
 
541
 
 
542
  /**
 
543
   * The object to open (TABLE | VIEW).
 
544
   */
 
545
  uint32_t requested_object;
 
546
 
 
547
  /**
 
548
   * The columns for this I_S table.
 
549
   */
 
550
  Columns column_info;
 
551
 
 
552
  /**
 
553
   * Contains the methods available on this I_S table.
 
554
   */
 
555
  InfoSchemaMethods *i_s_methods;
 
556
 
 
557
};
 
558
 
 
559
#endif /* DRIZZLED_INFO_SCHEMA_H */