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"
35
using namespace drizzled;
39
* Vectors of columns for various I_S tables.
41
static vector<const plugin::ColumnInfo *> char_set_columns;
42
static vector<const plugin::ColumnInfo *> collation_columns;
43
static vector<const plugin::ColumnInfo *> coll_char_columns;
44
static vector<const plugin::ColumnInfo *> col_columns;
45
static vector<const plugin::ColumnInfo *> key_col_usage_columns;
46
static vector<const plugin::ColumnInfo *> open_tab_columns;
47
static vector<const plugin::ColumnInfo *> plugin_columns;
48
static vector<const plugin::ColumnInfo *> processlist_columns;
49
static vector<const plugin::ColumnInfo *> ref_constraint_columns;
50
static vector<const plugin::ColumnInfo *> schemata_columns;
51
static vector<const plugin::ColumnInfo *> stats_columns;
52
static vector<const plugin::ColumnInfo *> status_columns;
53
static vector<const plugin::ColumnInfo *> tab_constraints_columns;
54
static vector<const plugin::ColumnInfo *> tables_columns;
55
static vector<const plugin::ColumnInfo *> tab_names_columns;
58
* Methods for various I_S tables.
60
static plugin::InfoSchemaMethods *char_set_methods= NULL;
61
static plugin::InfoSchemaMethods *collation_methods= NULL;
62
static plugin::InfoSchemaMethods *coll_char_methods= NULL;
63
static plugin::InfoSchemaMethods *columns_methods= NULL;
64
static plugin::InfoSchemaMethods *key_col_usage_methods= NULL;
65
static plugin::InfoSchemaMethods *open_tab_methods= NULL;
66
static plugin::InfoSchemaMethods *plugins_methods= NULL;
67
static plugin::InfoSchemaMethods *processlist_methods= NULL;
68
static plugin::InfoSchemaMethods *ref_constraint_methods= NULL;
69
static plugin::InfoSchemaMethods *schemata_methods= NULL;
70
static plugin::InfoSchemaMethods *stats_methods= NULL;
71
static plugin::InfoSchemaMethods *status_methods= NULL;
72
static plugin::InfoSchemaMethods *tab_constraints_methods= NULL;
73
static plugin::InfoSchemaMethods *tables_methods= NULL;
74
static plugin::InfoSchemaMethods *tab_names_methods= NULL;
75
static plugin::InfoSchemaMethods *variables_methods= NULL;
80
static plugin::InfoSchemaTable *char_set_table= NULL;
81
static plugin::InfoSchemaTable *collation_table= NULL;
82
static plugin::InfoSchemaTable *coll_char_set_table= NULL;
83
static plugin::InfoSchemaTable *columns_table= NULL;
84
static plugin::InfoSchemaTable *key_col_usage_table= NULL;
85
static plugin::InfoSchemaTable *global_stat_table= NULL;
86
static plugin::InfoSchemaTable *global_var_table= NULL;
87
static plugin::InfoSchemaTable *open_tab_table= NULL;
88
static plugin::InfoSchemaTable *plugins_table= NULL;
89
static plugin::InfoSchemaTable *processlist_table= NULL;
90
static plugin::InfoSchemaTable *ref_constraint_table= NULL;
91
static plugin::InfoSchemaTable *schemata_table= NULL;
92
static plugin::InfoSchemaTable *sess_stat_table= NULL;
93
static plugin::InfoSchemaTable *sess_var_table= NULL;
94
static plugin::InfoSchemaTable *stats_table= NULL;
95
static plugin::InfoSchemaTable *status_table= NULL;
96
static plugin::InfoSchemaTable *tab_constraints_table= NULL;
97
static plugin::InfoSchemaTable *tables_table= NULL;
98
static plugin::InfoSchemaTable *tab_names_table= NULL;
99
static plugin::InfoSchemaTable *var_table= NULL;
102
* Populate the vectors of columns for each I_S table.
104
* @return false on success; true on failure.
106
static bool initTableColumns()
110
if ((retval= createCharSetColumns(char_set_columns)) == true)
115
if ((retval= createCollationColumns(collation_columns)) == true)
120
if ((retval= createCollCharSetColumns(coll_char_columns)) == true)
125
if ((retval= createColColumns(col_columns)) == true)
130
if ((retval= createKeyColUsageColumns(key_col_usage_columns)) == true)
135
if ((retval= createOpenTabColumns(open_tab_columns)) == true)
140
if ((retval= createPluginsColumns(plugin_columns)) == true)
145
if ((retval= createProcessListColumns(processlist_columns)) == true)
150
if ((retval= createRefConstraintColumns(ref_constraint_columns)) == true)
155
if ((retval= createSchemataColumns(schemata_columns)) == true)
160
if ((retval= createStatsColumns(stats_columns)) == true)
165
if ((retval= createStatusColumns(status_columns)) == true)
170
if ((retval= createTabConstraintsColumns(tab_constraints_columns)) == true)
175
if ((retval= createTablesColumns(tables_columns)) == true)
180
if ((retval= createTabNamesColumns(tab_names_columns)) == true)
189
* Clear the vectors of columns for each I_S table.
191
static void cleanupTableColumns()
193
clearColumns(char_set_columns);
194
clearColumns(collation_columns);
195
clearColumns(coll_char_columns);
196
clearColumns(col_columns);
197
clearColumns(key_col_usage_columns);
198
clearColumns(open_tab_columns);
199
clearColumns(plugin_columns);
200
clearColumns(processlist_columns);
201
clearColumns(ref_constraint_columns);
202
clearColumns(schemata_columns);
203
clearColumns(stats_columns);
204
clearColumns(status_columns);
205
clearColumns(tab_constraints_columns);
206
clearColumns(tables_columns);
207
clearColumns(tab_names_columns);
211
* Initialize the methods for each I_S table.
213
* @return false on success; true on failure
215
static bool initTableMethods()
217
if ((char_set_methods= new(nothrow) CharSetISMethods()) == NULL)
222
if ((collation_methods= new(nothrow) CollationISMethods()) == NULL)
227
if ((coll_char_methods= new(nothrow) CollCharISMethods()) == NULL)
232
if ((columns_methods= new(nothrow) ColumnsISMethods()) == NULL)
237
if ((key_col_usage_methods= new(nothrow) KeyColUsageISMethods()) == NULL)
242
if ((open_tab_methods= new(nothrow) OpenTablesISMethods()) == NULL)
247
if ((plugins_methods= new(nothrow) PluginsISMethods()) == NULL)
252
if ((processlist_methods= new(nothrow) ProcessListISMethods()) == NULL)
257
if ((ref_constraint_methods= new(nothrow) RefConstraintsISMethods()) == NULL)
262
if ((schemata_methods= new(nothrow) SchemataISMethods()) == NULL)
267
if ((stats_methods= new(nothrow) StatsISMethods()) == NULL)
272
if ((status_methods= new(nothrow) StatusISMethods()) == NULL)
277
if ((tab_constraints_methods= new(nothrow) TabConstraintsISMethods()) == NULL)
282
if ((tables_methods= new(nothrow) TablesISMethods()) == NULL)
287
if ((tab_names_methods= new(nothrow) TabNamesISMethods()) == NULL)
292
if ((variables_methods= new(nothrow) VariablesISMethods()) == NULL)
301
* Delete memory allocated for the I_S table methods.
303
static void cleanupTableMethods()
305
delete char_set_methods;
306
delete collation_methods;
307
delete coll_char_methods;
308
delete columns_methods;
309
delete key_col_usage_methods;
310
delete open_tab_methods;
311
delete plugins_methods;
312
delete processlist_methods;
313
delete ref_constraint_methods;
314
delete schemata_methods;
315
delete stats_methods;
316
delete status_methods;
317
delete tab_constraints_methods;
318
delete tables_methods;
319
delete tab_names_methods;
320
delete variables_methods;
324
* Initialize the I_S tables.
326
* @return false on success; true on failure
328
static bool initTables()
331
char_set_table= new(nothrow) plugin::InfoSchemaTable("CHARACTER_SETS",
333
-1, -1, false, false, 0,
335
if (char_set_table == NULL)
340
collation_table= new(nothrow) plugin::InfoSchemaTable("COLLATIONS",
342
-1, -1, false, false, 0,
344
if (collation_table == NULL)
349
coll_char_set_table= new(nothrow) plugin::InfoSchemaTable("COLLATION_CHARACTER_SET_APPLICABILITY",
351
-1, -1, false, false, 0,
353
if (coll_char_set_table == NULL)
358
columns_table= new(nothrow) plugin::InfoSchemaTable("COLUMNS",
363
if (columns_table == NULL)
368
key_col_usage_table= new(nothrow) plugin::InfoSchemaTable("KEY_COLUMN_USAGE",
369
key_col_usage_columns,
372
key_col_usage_methods);
373
if (key_col_usage_table == NULL)
378
global_stat_table= new(nothrow) plugin::InfoSchemaTable("GLOBAL_STATUS",
380
-1, -1, false, false,
382
if (global_stat_table == NULL)
387
global_var_table= new(nothrow) plugin::InfoSchemaTable("GLOBAL_VARIABLES",
389
-1, -1, false, false,
390
0, variables_methods);
391
if (global_var_table == NULL)
396
open_tab_table= new(nothrow) plugin::InfoSchemaTable("OPEN_TABLES",
398
-1, -1, true, false, 0,
400
if (open_tab_table == NULL)
405
plugins_table= new(nothrow) plugin::InfoSchemaTable("PLUGINS",
407
-1, -1, false, false, 0,
409
if (plugins_table == NULL)
414
processlist_table= new(nothrow) plugin::InfoSchemaTable("PROCESSLIST",
416
-1, -1, false, false, 0,
417
processlist_methods);
418
if (processlist_table == NULL)
423
ref_constraint_table= new(nothrow) plugin::InfoSchemaTable("REFERENTIAL_CONSTRAINTS",
424
ref_constraint_columns,
427
ref_constraint_methods);
428
if (ref_constraint_table == NULL)
433
schemata_table= new(nothrow) plugin::InfoSchemaTable("SCHEMATA",
435
1, -1, false, false, 0,
437
if (schemata_table == NULL)
442
sess_stat_table= new(nothrow) plugin::InfoSchemaTable("SESSION_STATUS",
444
-1, -1, false, false,
446
if (sess_stat_table == NULL)
451
sess_var_table= new(nothrow) plugin::InfoSchemaTable("SESSION_VARIABLES",
453
-1, -1, false, false, 0,
455
if (sess_var_table == NULL)
460
stats_table= new(nothrow) plugin::InfoSchemaTable("STATISTICS",
463
OPEN_TABLE_ONLY | OPTIMIZE_I_S_TABLE,
465
if (stats_table == NULL)
470
status_table= new(nothrow) plugin::InfoSchemaTable("STATUS",
472
-1, -1, true, false, 0,
474
if (status_table == NULL)
479
tab_constraints_table= new(nothrow) plugin::InfoSchemaTable("TABLE_CONSTRAINTS",
480
tab_constraints_columns,
483
tab_constraints_methods);
484
if (tab_constraints_table == NULL)
489
tables_table= new(nothrow) plugin::InfoSchemaTable("TABLES",
494
if (tables_table == NULL)
499
tab_names_table= new(nothrow) plugin::InfoSchemaTable("TABLE_NAMES",
503
if (tab_names_table == NULL)
508
var_table= new(nothrow) plugin::InfoSchemaTable("VARIABLES",
510
-1, -1, true, false, 0,
512
if (var_table == NULL)
521
* Delete memory allocated for the I_S tables.
523
static void cleanupTables()
525
delete char_set_table;
526
delete collation_table;
527
delete coll_char_set_table;
528
delete columns_table;
529
delete key_col_usage_table;
530
delete global_stat_table;
531
delete global_var_table;
532
delete open_tab_table;
533
delete plugins_table;
534
delete processlist_table;
535
delete ref_constraint_table;
536
delete schemata_table;
537
delete sess_stat_table;
538
delete sess_var_table;
541
delete tab_constraints_table;
543
delete tab_names_table;
548
* Initialize the I_S plugin.
550
* @param[in] registry the drizzled::plugin::Registry singleton
551
* @return 0 on success; 1 on failure.
553
static int infoSchemaInit(drizzled::plugin::Registry& registry)
557
if ((retval= initTableMethods()) == true)
562
if ((retval= initTableColumns()) == true)
567
if ((retval= initTables()) == true)
572
registry.add(char_set_table);
573
registry.add(collation_table);
574
registry.add(coll_char_set_table);
575
registry.add(columns_table);
576
registry.add(key_col_usage_table);
577
registry.add(global_stat_table);
578
registry.add(global_var_table);
579
registry.add(open_tab_table);
580
registry.add(plugins_table);
581
registry.add(processlist_table);
582
registry.add(ref_constraint_table);
583
registry.add(schemata_table);
584
registry.add(sess_stat_table);
585
registry.add(sess_var_table);
586
registry.add(stats_table);
587
registry.add(status_table);
588
registry.add(tab_constraints_table);
589
registry.add(tables_table);
590
registry.add(tab_names_table);
591
registry.add(var_table);
597
* Clean up the I_S plugin.
599
* @param[in] registry the drizzled::plugin::Registry singleton
600
* @return 0 on success; 1 on failure
602
static int infoSchemaDone(drizzled::plugin::Registry& registry)
604
registry.remove(char_set_table);
605
registry.remove(collation_table);
606
registry.remove(coll_char_set_table);
607
registry.remove(columns_table);
608
registry.remove(key_col_usage_table);
609
registry.remove(global_stat_table);
610
registry.remove(global_var_table);
611
registry.remove(open_tab_table);
612
registry.remove(plugins_table);
613
registry.remove(processlist_table);
614
registry.remove(ref_constraint_table);
615
registry.remove(schemata_table);
616
registry.remove(sess_stat_table);
617
registry.remove(sess_var_table);
618
registry.remove(stats_table);
619
registry.remove(status_table);
620
registry.remove(tab_constraints_table);
621
registry.remove(tables_table);
622
registry.remove(tab_names_table);
623
registry.remove(var_table);
625
cleanupTableMethods();
626
cleanupTableColumns();
632
drizzle_declare_plugin(info_schema)
636
"Padraig O'Sullivan",
645
drizzle_declare_plugin_end;