~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/info_schema/modules.cc

  • Committer: Brian Aker
  • Date: 2009-11-18 23:28:30 UTC
  • mfrom: (1215.2.25 is-split)
  • Revision ID: brian@gaz-20091118232830-v28y7o26squz3c9c
Merge of Padraig

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
/**
 
22
 * @file 
 
23
 *   Modules I_S table methods.
 
24
 */
 
25
 
 
26
#include "drizzled/server_includes.h"
 
27
#include "drizzled/session.h"
 
28
#include "drizzled/show.h"
 
29
 
 
30
#include "helper_methods.h"
 
31
#include "modules.h"
 
32
 
 
33
#include <vector>
 
34
 
 
35
using namespace drizzled;
 
36
using namespace std;
 
37
 
 
38
/*
 
39
 * Vectors of columns for the modules I_S table.
 
40
 */
 
41
static vector<const plugin::ColumnInfo *> *columns= NULL;
 
42
 
 
43
/*
 
44
 * Methods for the modules I_S table.
 
45
 */
 
46
static plugin::InfoSchemaMethods *methods= NULL;
 
47
 
 
48
/*
 
49
 * modules I_S table.
 
50
 */
 
51
static plugin::InfoSchemaTable *mods_table= NULL;
 
52
 
 
53
/**
 
54
 * Populate the vectors of columns for the I_S table.
 
55
 *
 
56
 * @return a pointer to a std::vector of Columns.
 
57
 */
 
58
vector<const plugin::ColumnInfo *> *ModulesIS::createColumns()
 
59
{
 
60
  if (columns == NULL)
 
61
  {
 
62
    columns= new vector<const plugin::ColumnInfo *>;
 
63
  }
 
64
  else
 
65
  {
 
66
    clearColumns(*columns);
 
67
  }
 
68
 
 
69
  columns->push_back(new plugin::ColumnInfo("MODULE_NAME",
 
70
                                            NAME_CHAR_LEN,
 
71
                                            DRIZZLE_TYPE_VARCHAR,
 
72
                                            0,
 
73
                                            0,
 
74
                                            "Name",
 
75
                                            SKIP_OPEN_TABLE));
 
76
 
 
77
  columns->push_back(new plugin::ColumnInfo("MODULE_VERSION",
 
78
                                            20,
 
79
                                            DRIZZLE_TYPE_VARCHAR,
 
80
                                            0,
 
81
                                            0,
 
82
                                            "",
 
83
                                            SKIP_OPEN_TABLE));
 
84
 
 
85
  columns->push_back(new plugin::ColumnInfo("MODULE_AUTHOR",
 
86
                                            NAME_CHAR_LEN,
 
87
                                            DRIZZLE_TYPE_VARCHAR,
 
88
                                            0,
 
89
                                            1,
 
90
                                            "",
 
91
                                            SKIP_OPEN_TABLE));
 
92
 
 
93
  columns->push_back(new plugin::ColumnInfo("IS_BUILTIN",
 
94
                                            3,
 
95
                                            DRIZZLE_TYPE_VARCHAR,
 
96
                                            0,
 
97
                                            0,
 
98
                                            "",
 
99
                                            SKIP_OPEN_TABLE));
 
100
 
 
101
  columns->push_back(new plugin::ColumnInfo("MODULE_LIBRARY",
 
102
                                            65535,
 
103
                                            DRIZZLE_TYPE_VARCHAR,
 
104
                                            0,
 
105
                                            1,
 
106
                                            "",
 
107
                                            SKIP_OPEN_TABLE));
 
108
 
 
109
  columns->push_back(new plugin::ColumnInfo("MODULE_DESCRIPTION",
 
110
                                            65535,
 
111
                                            DRIZZLE_TYPE_VARCHAR,
 
112
                                            0,
 
113
                                            1,
 
114
                                            "",
 
115
                                            SKIP_OPEN_TABLE));
 
116
 
 
117
  columns->push_back(new plugin::ColumnInfo("MODULE_LICENSE",
 
118
                                            80,
 
119
                                            DRIZZLE_TYPE_VARCHAR,
 
120
                                            0,
 
121
                                            1,
 
122
                                            "License",
 
123
                                            SKIP_OPEN_TABLE));
 
124
  return columns;
 
125
}
 
126
 
 
127
/**
 
128
 * Initialize the I_S table.
 
129
 *
 
130
 * @return a pointer to an I_S table
 
131
 */
 
132
plugin::InfoSchemaTable *ModulesIS::getTable()
 
133
{
 
134
  columns= createColumns();
 
135
 
 
136
  if (methods == NULL)
 
137
  {
 
138
    methods= new ModulesISMethods();
 
139
  }
 
140
 
 
141
  if (mods_table == NULL)
 
142
  {
 
143
    mods_table= new plugin::InfoSchemaTable("MODULES",
 
144
                                            *columns,
 
145
                                            -1, -1, false, false, 0,
 
146
                                            methods);
 
147
  }
 
148
 
 
149
  return mods_table;
 
150
}
 
151
 
 
152
/**
 
153
 * Delete memory allocated for the table, columns and methods.
 
154
 */
 
155
void ModulesIS::cleanup()
 
156
{
 
157
  clearColumns(*columns);
 
158
  delete mods_table;
 
159
  delete methods;
 
160
  delete columns;
 
161
}
 
162
 
 
163
class ShowModules : public unary_function<drizzled::plugin::Module *, bool>
 
164
{
 
165
  Session *session;
 
166
  Table *table;
 
167
public:
 
168
  ShowModules(Session *session_arg, Table *table_arg)
 
169
    : session(session_arg), table(table_arg) {}
 
170
 
 
171
  result_type operator() (argument_type module)
 
172
  {
 
173
    const drizzled::plugin::Manifest &manifest= module->getManifest();
 
174
    const CHARSET_INFO * const cs= system_charset_info;
 
175
 
 
176
    table->restoreRecordAsDefault();
 
177
 
 
178
    table->field[0]->store(module->getName().c_str(),
 
179
                           module->getName().size(), cs);
 
180
 
 
181
    if (manifest.version)
 
182
    {
 
183
      table->field[1]->store(manifest.version, strlen(manifest.version), cs);
 
184
      table->field[1]->set_notnull();
 
185
    }
 
186
    else
 
187
      table->field[1]->set_null();
 
188
 
 
189
    if (manifest.author)
 
190
    {
 
191
      table->field[2]->store(manifest.author, strlen(manifest.author), cs);
 
192
      table->field[2]->set_notnull();
 
193
    }
 
194
    else
 
195
    {
 
196
      table->field[2]->set_null();
 
197
    }
 
198
 
 
199
    if (module->plugin_dl == NULL)
 
200
    {
 
201
      table->field[3]->store(STRING_WITH_LEN("YES"),cs);
 
202
      table->field[4]->set_null();
 
203
    }
 
204
    else
 
205
    {
 
206
      table->field[3]->store(STRING_WITH_LEN("NO"),cs);
 
207
      table->field[4]->store(module->plugin_dl->dl.str,
 
208
                             module->plugin_dl->dl.length, cs);
 
209
    }
 
210
 
 
211
    if (manifest.descr)
 
212
    {
 
213
      table->field[5]->store(manifest.descr, strlen(manifest.descr), cs);
 
214
      table->field[5]->set_notnull();
 
215
    }
 
216
    else
 
217
    {
 
218
      table->field[5]->set_null();
 
219
    }
 
220
 
 
221
    switch (manifest.license) {
 
222
    case PLUGIN_LICENSE_GPL:
 
223
      table->field[6]->store(drizzled::plugin::LICENSE_GPL_STRING.c_str(),
 
224
                             drizzled::plugin::LICENSE_GPL_STRING.size(), cs);
 
225
      break;
 
226
    case PLUGIN_LICENSE_BSD:
 
227
      table->field[6]->store(drizzled::plugin::LICENSE_BSD_STRING.c_str(),
 
228
                             drizzled::plugin::LICENSE_BSD_STRING.size(), cs);
 
229
      break;
 
230
    case PLUGIN_LICENSE_LGPL:
 
231
      table->field[6]->store(drizzled::plugin::LICENSE_LGPL_STRING.c_str(),
 
232
                             drizzled::plugin::LICENSE_LGPL_STRING.size(), cs);
 
233
      break;
 
234
    default:
 
235
      table->field[6]->store(drizzled::plugin::LICENSE_PROPRIETARY_STRING.c_str(),
 
236
                             drizzled::plugin::LICENSE_PROPRIETARY_STRING.size(),
 
237
                             cs);
 
238
      break;
 
239
    }
 
240
    table->field[6]->set_notnull();
 
241
 
 
242
    return schema_table_store_record(session, table);
 
243
  }
 
244
};
 
245
 
 
246
int ModulesISMethods::fillTable(Session *session, TableList *tables)
 
247
{
 
248
  Table *table= tables->table;
 
249
 
 
250
  drizzled::plugin::Registry &registry= drizzled::plugin::Registry::singleton();
 
251
  vector<drizzled::plugin::Module *> modules= registry.getList(true);
 
252
  vector<drizzled::plugin::Module *>::iterator iter=
 
253
    find_if(modules.begin(), modules.end(), ShowModules(session, table));
 
254
  if (iter != modules.end())
 
255
  {
 
256
    return 1;
 
257
  }
 
258
  return 0;
 
259
}