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
* Modules I_S table methods.
30
#include "drizzled/session.h"
31
#include "drizzled/show.h"
32
#include "drizzled/plugin/library.h"
33
#include "drizzled/global_charset_info.h"
36
#include "helper_methods.h"
40
using namespace drizzled;
44
* Vectors of columns for the modules I_S table.
46
static vector<const plugin::ColumnInfo *> *columns= NULL;
49
* Methods for the modules I_S table.
51
static plugin::InfoSchemaMethods *methods= NULL;
56
static plugin::InfoSchemaTable *mods_table= NULL;
59
* Populate the vectors of columns for the I_S table.
61
* @return a pointer to a std::vector of Columns.
63
vector<const plugin::ColumnInfo *> *ModulesIS::createColumns()
67
columns= new vector<const plugin::ColumnInfo *>;
71
clearColumns(*columns);
74
columns->push_back(new plugin::ColumnInfo("MODULE_NAME",
81
columns->push_back(new plugin::ColumnInfo("MODULE_VERSION",
88
columns->push_back(new plugin::ColumnInfo("MODULE_AUTHOR",
95
columns->push_back(new plugin::ColumnInfo("IS_BUILTIN",
102
columns->push_back(new plugin::ColumnInfo("MODULE_LIBRARY",
104
DRIZZLE_TYPE_VARCHAR,
109
columns->push_back(new plugin::ColumnInfo("MODULE_DESCRIPTION",
111
DRIZZLE_TYPE_VARCHAR,
116
columns->push_back(new plugin::ColumnInfo("MODULE_LICENSE",
118
DRIZZLE_TYPE_VARCHAR,
126
* Initialize the I_S table.
128
* @return a pointer to an I_S table
130
plugin::InfoSchemaTable *ModulesIS::getTable()
132
columns= createColumns();
136
methods= new ModulesISMethods();
139
if (mods_table == NULL)
141
mods_table= new plugin::InfoSchemaTable("OLD_MODULES",
143
-1, -1, false, false, 0,
151
* Delete memory allocated for the table, columns and methods.
153
void ModulesIS::cleanup()
155
clearColumns(*columns);
161
class ShowModules : public unary_function<drizzled::plugin::Module *, bool>
165
plugin::InfoSchemaTable *schema_table;
167
const string LICENSE_GPL_STRING;
168
const string LICENSE_BSD_STRING;
169
const string LICENSE_LGPL_STRING;
170
const string LICENSE_PROPRIETARY_STRING;
173
ShowModules(Session *session_arg, Table *table_arg,
174
plugin::InfoSchemaTable *sch_tab_arg)
175
: session(session_arg), table(table_arg), schema_table(sch_tab_arg),
176
LICENSE_GPL_STRING("GPL"),
177
LICENSE_BSD_STRING("BSD"),
178
LICENSE_LGPL_STRING("LGPL"),
179
LICENSE_PROPRIETARY_STRING("PROPRIETARY")
182
result_type operator() (argument_type module)
184
const drizzled::plugin::Manifest &manifest= module->getManifest();
185
const CHARSET_INFO * const cs= system_charset_info;
187
table->restoreRecordAsDefault();
188
table->setWriteSet(0);
189
table->setWriteSet(1);
190
table->setWriteSet(2);
191
table->setWriteSet(3);
192
table->setWriteSet(4);
193
table->setWriteSet(5);
194
table->setWriteSet(6);
196
table->field[0]->store(module->getName().c_str(),
197
module->getName().size(), cs);
199
if (manifest.version)
201
table->field[1]->store(manifest.version, strlen(manifest.version), cs);
202
table->field[1]->set_notnull();
205
table->field[1]->set_null();
209
table->field[2]->store(manifest.author, strlen(manifest.author), cs);
210
table->field[2]->set_notnull();
214
table->field[2]->set_null();
217
if (module->plugin_dl == NULL)
219
table->field[3]->store(STRING_WITH_LEN("YES"),cs);
220
table->field[4]->set_null();
224
table->field[3]->store(STRING_WITH_LEN("NO"),cs);
225
table->field[4]->store(module->plugin_dl->getName().c_str(),
226
module->plugin_dl->getName().size(), cs);
231
table->field[5]->store(manifest.descr, strlen(manifest.descr), cs);
232
table->field[5]->set_notnull();
236
table->field[5]->set_null();
239
switch (manifest.license) {
240
case PLUGIN_LICENSE_GPL:
241
table->field[6]->store(LICENSE_GPL_STRING.c_str(),
242
LICENSE_GPL_STRING.size(), cs);
244
case PLUGIN_LICENSE_BSD:
245
table->field[6]->store(LICENSE_BSD_STRING.c_str(),
246
LICENSE_BSD_STRING.size(), cs);
248
case PLUGIN_LICENSE_LGPL:
249
table->field[6]->store(LICENSE_LGPL_STRING.c_str(),
250
LICENSE_LGPL_STRING.size(), cs);
253
table->field[6]->store(LICENSE_PROPRIETARY_STRING.c_str(),
254
LICENSE_PROPRIETARY_STRING.size(),
258
table->field[6]->set_notnull();
260
schema_table->addRow(table->record[0], table->s->reclength);
265
int ModulesISMethods::fillTable(Session *session,
267
plugin::InfoSchemaTable *schema_table)
269
drizzled::plugin::Registry ®istry= drizzled::plugin::Registry::singleton();
270
vector<drizzled::plugin::Module *> modules= registry.getList(true);
271
vector<drizzled::plugin::Module *>::iterator iter=
272
find_if(modules.begin(), modules.end(), ShowModules(session, table, schema_table));
273
if (iter != modules.end())