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
23
* I_S plugin implementation.
26
#include <drizzled/server_includes.h>
27
#include <drizzled/session.h>
28
#include <drizzled/show.h>
30
#include "info_schema_methods.h"
31
#include "info_schema_columns.h"
38
* Vectors of columns for various I_S tables.
40
static vector<const ColumnInfo *> char_set_columns;
41
static vector<const ColumnInfo *> collation_columns;
42
static vector<const ColumnInfo *> coll_char_columns;
43
static vector<const ColumnInfo *> col_columns;
44
static vector<const ColumnInfo *> key_col_usage_columns;
45
static vector<const ColumnInfo *> open_tab_columns;
46
static vector<const ColumnInfo *> plugin_columns;
47
static vector<const ColumnInfo *> processlist_columns;
48
static vector<const ColumnInfo *> ref_constraint_columns;
49
static vector<const ColumnInfo *> schemata_columns;
50
static vector<const ColumnInfo *> stats_columns;
51
static vector<const ColumnInfo *> status_columns;
52
static vector<const ColumnInfo *> tab_constraints_columns;
53
static vector<const ColumnInfo *> tables_columns;
54
static vector<const ColumnInfo *> tab_names_columns;
57
* Methods for various I_S tables.
59
static InfoSchemaMethods *char_set_methods= NULL;
60
static InfoSchemaMethods *collation_methods= NULL;
61
static InfoSchemaMethods *coll_char_methods= NULL;
62
static InfoSchemaMethods *columns_methods= NULL;
63
static InfoSchemaMethods *key_col_usage_methods= NULL;
64
static InfoSchemaMethods *open_tab_methods= NULL;
65
static InfoSchemaMethods *plugins_methods= NULL;
66
static InfoSchemaMethods *processlist_methods= NULL;
67
static InfoSchemaMethods *ref_constraint_methods= NULL;
68
static InfoSchemaMethods *schemata_methods= NULL;
69
static InfoSchemaMethods *stats_methods= NULL;
70
static InfoSchemaMethods *status_methods= NULL;
71
static InfoSchemaMethods *tab_constraints_methods= NULL;
72
static InfoSchemaMethods *tables_methods= NULL;
73
static InfoSchemaMethods *tab_names_methods= NULL;
74
static InfoSchemaMethods *variables_methods= NULL;
79
static InfoSchemaTable *char_set_table= NULL;
80
static InfoSchemaTable *collation_table= NULL;
81
static InfoSchemaTable *coll_char_set_table= NULL;
82
static InfoSchemaTable *columns_table= NULL;
83
static InfoSchemaTable *key_col_usage_table= NULL;
84
static InfoSchemaTable *global_stat_table= NULL;
85
static InfoSchemaTable *global_var_table= NULL;
86
static InfoSchemaTable *open_tab_table= NULL;
87
static InfoSchemaTable *plugins_table= NULL;
88
static InfoSchemaTable *processlist_table= NULL;
89
static InfoSchemaTable *ref_constraint_table= NULL;
90
static InfoSchemaTable *schemata_table= NULL;
91
static InfoSchemaTable *sess_stat_table= NULL;
92
static InfoSchemaTable *sess_var_table= NULL;
93
static InfoSchemaTable *stats_table= NULL;
94
static InfoSchemaTable *status_table= NULL;
95
static InfoSchemaTable *tab_constraints_table= NULL;
96
static InfoSchemaTable *tables_table= NULL;
97
static InfoSchemaTable *tab_names_table= NULL;
98
static InfoSchemaTable *var_table= NULL;
101
* Populate the vectors of columns for each I_S table.
103
* @return false on success; true on failure.
105
static bool initTableColumns()
109
if ((retval= createCharSetColumns(char_set_columns)) == true)
114
if ((retval= createCollationColumns(collation_columns)) == true)
119
if ((retval= createCollCharSetColumns(coll_char_columns)) == true)
124
if ((retval= createColColumns(col_columns)) == true)
129
if ((retval= createKeyColUsageColumns(key_col_usage_columns)) == true)
134
if ((retval= createOpenTabColumns(open_tab_columns)) == true)
139
if ((retval= createPluginsColumns(plugin_columns)) == true)
144
if ((retval= createProcessListColumns(processlist_columns)) == true)
149
if ((retval= createRefConstraintColumns(ref_constraint_columns)) == true)
154
if ((retval= createSchemataColumns(schemata_columns)) == true)
159
if ((retval= createStatsColumns(stats_columns)) == true)
164
if ((retval= createStatusColumns(status_columns)) == true)
169
if ((retval= createTabConstraintsColumns(tab_constraints_columns)) == true)
174
if ((retval= createTablesColumns(tables_columns)) == true)
179
if ((retval= createTabNamesColumns(tab_names_columns)) == true)
188
* Clear the vectors of columns for each I_S table.
190
static void cleanupTableColumns()
192
clearColumns(char_set_columns);
193
clearColumns(collation_columns);
194
clearColumns(coll_char_columns);
195
clearColumns(col_columns);
196
clearColumns(key_col_usage_columns);
197
clearColumns(open_tab_columns);
198
clearColumns(plugin_columns);
199
clearColumns(processlist_columns);
200
clearColumns(ref_constraint_columns);
201
clearColumns(schemata_columns);
202
clearColumns(stats_columns);
203
clearColumns(status_columns);
204
clearColumns(tab_constraints_columns);
205
clearColumns(tables_columns);
206
clearColumns(tab_names_columns);
210
* Initialize the methods for each I_S table.
212
* @return false on success; true on failure
214
static bool initTableMethods()
216
if ((char_set_methods= new(std::nothrow) CharSetISMethods()) == NULL)
221
if ((collation_methods= new(std::nothrow) CollationISMethods()) == NULL)
226
if ((coll_char_methods= new(std::nothrow) CollCharISMethods()) == NULL)
231
if ((columns_methods= new(std::nothrow) ColumnsISMethods()) == NULL)
236
if ((key_col_usage_methods= new(std::nothrow) KeyColUsageISMethods()) == NULL)
241
if ((open_tab_methods= new(std::nothrow) OpenTablesISMethods()) == NULL)
246
if ((plugins_methods= new(std::nothrow) PluginsISMethods()) == NULL)
251
if ((processlist_methods= new(std::nothrow) ProcessListISMethods()) == NULL)
256
if ((ref_constraint_methods= new(std::nothrow) RefConstraintsISMethods()) == NULL)
261
if ((schemata_methods= new(std::nothrow) SchemataISMethods()) == NULL)
266
if ((stats_methods= new(std::nothrow) StatsISMethods()) == NULL)
271
if ((status_methods= new(std::nothrow) StatusISMethods()) == NULL)
276
if ((tab_constraints_methods= new(std::nothrow) TabConstraintsISMethods()) == NULL)
281
if ((tables_methods= new(std::nothrow) TablesISMethods()) == NULL)
286
if ((tab_names_methods= new(std::nothrow) TabNamesISMethods()) == NULL)
291
if ((variables_methods= new(std::nothrow) VariablesISMethods()) == NULL)
300
* Delete memory allocated for the I_S table methods.
302
static void cleanupTableMethods()
304
delete char_set_methods;
305
delete collation_methods;
306
delete coll_char_methods;
307
delete columns_methods;
308
delete key_col_usage_methods;
309
delete open_tab_methods;
310
delete plugins_methods;
311
delete processlist_methods;
312
delete ref_constraint_methods;
313
delete schemata_methods;
314
delete stats_methods;
315
delete status_methods;
316
delete tab_constraints_methods;
317
delete tables_methods;
318
delete tab_names_methods;
319
delete variables_methods;
323
* Initialize the I_S tables.
325
* @return false on success; true on failure
327
static bool initTables()
330
char_set_table= new(std::nothrow) InfoSchemaTable("CHARACTER_SETS",
332
-1, -1, false, false, 0,
334
if (char_set_table == NULL)
339
collation_table= new(std::nothrow) InfoSchemaTable("COLLATIONS",
341
-1, -1, false, false, 0,
343
if (collation_table == NULL)
348
coll_char_set_table= new(std::nothrow) InfoSchemaTable("COLLATION_CHARACTER_SET_APPLICABILITY",
350
-1, -1, false, false, 0,
352
if (coll_char_set_table == NULL)
357
columns_table= new(std::nothrow) InfoSchemaTable("COLUMNS",
362
if (columns_table == NULL)
367
key_col_usage_table= new(std::nothrow) InfoSchemaTable("KEY_COLUMN_USAGE",
368
key_col_usage_columns,
371
key_col_usage_methods);
372
if (key_col_usage_table == NULL)
377
global_stat_table= new(std::nothrow) InfoSchemaTable("GLOBAL_STATUS",
379
-1, -1, false, false,
381
if (global_stat_table == NULL)
386
global_var_table= new(std::nothrow) InfoSchemaTable("GLOBAL_VARIABLES",
388
-1, -1, false, false,
389
0, variables_methods);
390
if (global_var_table == NULL)
395
open_tab_table= new(std::nothrow) InfoSchemaTable("OPEN_TABLES",
397
-1, -1, true, false, 0,
399
if (open_tab_table == NULL)
404
plugins_table= new(std::nothrow) InfoSchemaTable("PLUGINS",
406
-1, -1, false, false, 0,
408
if (plugins_table == NULL)
413
processlist_table= new(std::nothrow) InfoSchemaTable("PROCESSLIST",
415
-1, -1, false, false, 0,
416
processlist_methods);
417
if (processlist_table == NULL)
422
ref_constraint_table= new(std::nothrow) InfoSchemaTable("REFERENTIAL_CONSTRAINTS",
423
ref_constraint_columns,
426
ref_constraint_methods);
427
if (ref_constraint_table == NULL)
432
schemata_table= new(std::nothrow) InfoSchemaTable("SCHEMATA",
434
1, -1, false, false, 0,
436
if (schemata_table == NULL)
441
sess_stat_table= new(std::nothrow) InfoSchemaTable("SESSION_STATUS",
443
-1, -1, false, false,
445
if (sess_stat_table == NULL)
450
sess_var_table= new(std::nothrow) InfoSchemaTable("SESSION_VARIABLES",
452
-1, -1, false, false, 0,
454
if (sess_var_table == NULL)
459
stats_table= new(std::nothrow) InfoSchemaTable("STATISTICS",
462
OPEN_TABLE_ONLY | OPTIMIZE_I_S_TABLE,
464
if (stats_table == NULL)
469
status_table= new(std::nothrow) InfoSchemaTable("STATUS",
471
-1, -1, true, false, 0,
473
if (status_table == NULL)
478
tab_constraints_table= new(std::nothrow) InfoSchemaTable("TABLE_CONSTRAINTS",
479
tab_constraints_columns,
482
tab_constraints_methods);
483
if (tab_constraints_table == NULL)
488
tables_table= new(std::nothrow) InfoSchemaTable("TABLES",
493
if (tables_table == NULL)
498
tab_names_table= new(std::nothrow) InfoSchemaTable("TABLE_NAMES",
502
if (tab_names_table == NULL)
507
var_table= new(std::nothrow) InfoSchemaTable("VARIABLES",
509
-1, -1, true, false, 0,
511
if (var_table == NULL)
520
* Delete memory allocated for the I_S tables.
522
static void cleanupTables()
524
delete char_set_table;
525
delete collation_table;
526
delete coll_char_set_table;
527
delete columns_table;
528
delete key_col_usage_table;
529
delete global_stat_table;
530
delete global_var_table;
531
delete open_tab_table;
532
delete plugins_table;
533
delete processlist_table;
534
delete ref_constraint_table;
535
delete schemata_table;
536
delete sess_stat_table;
537
delete sess_var_table;
540
delete tab_constraints_table;
542
delete tab_names_table;
547
* Initialize the I_S plugin.
549
* @param[in] registry the drizzled::plugin::Registry singleton
550
* @return 0 on success; 1 on failure.
552
static int infoSchemaInit(drizzled::plugin::Registry& registry)
556
if ((retval= initTableMethods()) == true)
561
if ((retval= initTableColumns()) == true)
566
if ((retval= initTables()) == true)
571
registry.add(char_set_table);
572
registry.add(collation_table);
573
registry.add(coll_char_set_table);
574
registry.add(columns_table);
575
registry.add(key_col_usage_table);
576
registry.add(global_stat_table);
577
registry.add(global_var_table);
578
registry.add(open_tab_table);
579
registry.add(plugins_table);
580
registry.add(processlist_table);
581
registry.add(ref_constraint_table);
582
registry.add(schemata_table);
583
registry.add(sess_stat_table);
584
registry.add(sess_var_table);
585
registry.add(stats_table);
586
registry.add(status_table);
587
registry.add(tab_constraints_table);
588
registry.add(tables_table);
589
registry.add(tab_names_table);
590
registry.add(var_table);
596
* Clean up the I_S plugin.
598
* @param[in] registry the drizzled::plugin::Registry singleton
599
* @return 0 on success; 1 on failure
601
static int infoSchemaDone(drizzled::plugin::Registry& registry)
603
registry.remove(char_set_table);
604
registry.remove(collation_table);
605
registry.remove(coll_char_set_table);
606
registry.remove(columns_table);
607
registry.remove(key_col_usage_table);
608
registry.remove(global_stat_table);
609
registry.remove(global_var_table);
610
registry.remove(open_tab_table);
611
registry.remove(plugins_table);
612
registry.remove(processlist_table);
613
registry.remove(ref_constraint_table);
614
registry.remove(schemata_table);
615
registry.remove(sess_stat_table);
616
registry.remove(sess_var_table);
617
registry.remove(stats_table);
618
registry.remove(status_table);
619
registry.remove(tab_constraints_table);
620
registry.remove(tables_table);
621
registry.remove(tab_names_table);
622
registry.remove(var_table);
624
cleanupTableMethods();
625
cleanupTableColumns();
631
drizzle_declare_plugin(info_schema)
635
"Padraig O'Sullivan",
644
drizzle_declare_plugin_end;