~drizzle-trunk/drizzle/development

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
  Copyright (C) 2010 Stewart Smith

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include "config.h"
#include "drizzled/plugin/table_function.h"

#include "embedded_innodb-1.0/innodb.h"

#include "config_table_function.h"

using namespace std;
using namespace drizzled;

class LibInnoDBConfigTool : public drizzled::plugin::TableFunction
{
public:

  LibInnoDBConfigTool();

  LibInnoDBConfigTool(const char *table_arg) :
    drizzled::plugin::TableFunction("data_dictionary", table_arg)
  { }

  ~LibInnoDBConfigTool() {}

  class Generator : public drizzled::plugin::TableFunction::Generator
  {
  private:
    const char **names;
    uint32_t names_count;
    uint32_t names_next;
  public:
    Generator(drizzled::Field **arg);
    ~Generator();

    bool populate();
  };

  LibInnoDBConfigTool::Generator *generator(drizzled::Field **arg)
  {
    return new Generator(arg);
  }
};

LibInnoDBConfigTool::LibInnoDBConfigTool() :
  plugin::TableFunction("DATA_DICTIONARY", "INNODB_CONFIGURATION")
{
  add_field("NAME");
  add_field("TYPE");
  add_field("VALUE");
}

LibInnoDBConfigTool::Generator::Generator(Field **arg) :
  plugin::TableFunction::Generator(arg),
  names_next(0)
{
  ib_err_t err= ib_cfg_get_all(&names, &names_count);
  assert(err == DB_SUCCESS);
}

LibInnoDBConfigTool::Generator::~Generator()
{
  free(names);
}

bool LibInnoDBConfigTool::Generator::populate()
{
  if (names_next < names_count)
  {
    push(names[names_next]);
    push("");
    push("");

    names_next++;
    return true;
  }
  return false; // No more rows
}

static LibInnoDBConfigTool *config_tool;

int config_table_function_initialize(drizzled::plugin::Registry &registry)
{
  config_tool= new(std::nothrow)LibInnoDBConfigTool();
  registry.add(config_tool);

  return 0;
}

int config_table_function_finalize(drizzled::plugin::Registry &registry)
{
  registry.remove(config_tool);
  delete config_tool;

  return 0;
}