~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/haildb/config_table_function.cc

  • Committer: Brian Aker
  • Date: 2010-11-08 18:54:26 UTC
  • mto: (1921.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 1916.
  • Revision ID: brian@tangent.org-20101108185426-fymkf2xnelupf11x
Rename lock methods to be style + well make sense.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2010 Stewart Smith
 
3
 
 
4
  This program is free software; you can redistribute it and/or
 
5
  modify it under the terms of the GNU General Public License
 
6
  as published by the Free Software Foundation; either version 2
 
7
  of the License, or (at your option) any later version.
 
8
 
 
9
  This program is distributed in the hope that it will be useful,
 
10
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
  GNU General Public License for more details.
 
13
 
 
14
  You should have received a copy of the GNU General Public License
 
15
  along with this program; if not, write to the Free Software
 
16
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
17
*/
 
18
 
 
19
#include "config.h"
 
20
#include "drizzled/plugin/table_function.h"
 
21
 
 
22
#include <haildb.h>
 
23
 
 
24
#include "config_table_function.h"
 
25
 
 
26
using namespace std;
 
27
using namespace drizzled;
 
28
 
 
29
class LibInnoDBConfigTool : public drizzled::plugin::TableFunction
 
30
{
 
31
public:
 
32
 
 
33
  LibInnoDBConfigTool();
 
34
 
 
35
  LibInnoDBConfigTool(const char *table_arg) :
 
36
    drizzled::plugin::TableFunction("data_dictionary", table_arg)
 
37
  { }
 
38
 
 
39
  ~LibInnoDBConfigTool() {}
 
40
 
 
41
  class Generator : public drizzled::plugin::TableFunction::Generator
 
42
  {
 
43
  private:
 
44
    const char **names;
 
45
    uint32_t names_count;
 
46
    uint32_t names_next;
 
47
  public:
 
48
    Generator(drizzled::Field **arg);
 
49
    ~Generator();
 
50
 
 
51
    bool populate();
 
52
  };
 
53
 
 
54
  LibInnoDBConfigTool::Generator *generator(drizzled::Field **arg)
 
55
  {
 
56
    return new Generator(arg);
 
57
  }
 
58
};
 
59
 
 
60
LibInnoDBConfigTool::LibInnoDBConfigTool() :
 
61
  plugin::TableFunction("DATA_DICTIONARY", "HAILDB_CONFIGURATION")
 
62
{
 
63
  add_field("NAME");
 
64
  add_field("TYPE");
 
65
  add_field("VALUE", plugin::TableFunction::STRING, 64, true);
 
66
}
 
67
 
 
68
LibInnoDBConfigTool::Generator::Generator(Field **arg) :
 
69
  plugin::TableFunction::Generator(arg),
 
70
  names_next(0)
 
71
{
 
72
  ib_err_t err= ib_cfg_get_all(&names, &names_count);
 
73
  assert(err == DB_SUCCESS);
 
74
}
 
75
 
 
76
LibInnoDBConfigTool::Generator::~Generator()
 
77
{
 
78
  free(names);
 
79
}
 
80
 
 
81
bool LibInnoDBConfigTool::Generator::populate()
 
82
{
 
83
  if (names_next < names_count)
 
84
  {
 
85
    const char* config_name= names[names_next];
 
86
 
 
87
    push(config_name);
 
88
 
 
89
    ib_cfg_type_t type;
 
90
    ib_err_t err= ib_cfg_var_get_type(config_name, &type);
 
91
    assert(err == DB_SUCCESS);
 
92
 
 
93
    void *value_ptr;
 
94
    err= ib_cfg_get(config_name, &value_ptr);
 
95
    assert(err == DB_SUCCESS);
 
96
 
 
97
    switch(type)
 
98
    {
 
99
    case IB_CFG_IBOOL:
 
100
    {
 
101
      push("BOOL");
 
102
      ib_bool_t value= (ib_bool_t)value_ptr;
 
103
      if (value == IB_FALSE)
 
104
        push("false");
 
105
      else
 
106
        push("true");
 
107
      break;
 
108
    }
 
109
    case IB_CFG_ULINT:
 
110
    {
 
111
      push("ULINT");
 
112
      push((uint64_t)value_ptr);
 
113
      break;
 
114
    }
 
115
    case IB_CFG_ULONG:
 
116
    {
 
117
      push("ULONG");
 
118
      push((uint64_t)value_ptr);
 
119
      break;
 
120
    }
 
121
    case IB_CFG_TEXT:
 
122
    {
 
123
      push("TEXT");
 
124
      if (value_ptr == NULL)
 
125
        push();
 
126
      else
 
127
        push((char*)value_ptr);
 
128
      break;
 
129
    }
 
130
    case IB_CFG_CB:
 
131
      push("CALLBACK");
 
132
      if (value_ptr == NULL)
 
133
        push();
 
134
      else
 
135
        push("Is set");
 
136
      break;
 
137
    default:
 
138
      push("UNKNOWN");
 
139
      push("UNKNOWN");
 
140
      break;
 
141
    }
 
142
 
 
143
    names_next++;
 
144
    return true;
 
145
  }
 
146
  return false; // No more rows
 
147
}
 
148
 
 
149
static LibInnoDBConfigTool *config_tool;
 
150
 
 
151
int config_table_function_initialize(drizzled::module::Context &context)
 
152
{
 
153
  config_tool= new(std::nothrow)LibInnoDBConfigTool();
 
154
  context.add(config_tool);
 
155
 
 
156
  return 0;
 
157
}