~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/table_function.h

  • Committer: Monty Taylor
  • Date: 2008-11-16 20:15:33 UTC
  • mto: (584.1.9 devel)
  • mto: This revision was merged to the branch mainline in revision 589.
  • Revision ID: monty@inaugust.com-20081116201533-d0f19s1bk1h95iyw
Removed a big bank of includes from item.h.

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
 
 *  Definitions required for TableFunction plugin
5
 
 *
6
 
 *  Copyright (C) 2010 Sun Microsystems
7
 
 *  Copyright (C) 2010 Monty Taylor
8
 
 *
9
 
 *  This program is free software; you can redistribute it and/or modify
10
 
 *  it under the terms of the GNU General Public License as published by
11
 
 *  the Free Software Foundation; version 2 of the License.
12
 
 *
13
 
 *  This program is distributed in the hope that it will be useful,
14
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
 *  GNU General Public License for more details.
17
 
 *
18
 
 *  You should have received a copy of the GNU General Public License
19
 
 *  along with this program; if not, write to the Free Software
20
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21
 
 */
22
 
 
23
 
#ifndef DRIZZLED_PLUGIN_TABLE_FUNCTION_H
24
 
#define DRIZZLED_PLUGIN_TABLE_FUNCTION_H
25
 
 
26
 
#include <drizzled/definitions.h>
27
 
#include "drizzled/plugin.h"
28
 
#include "drizzled/plugin/plugin.h"
29
 
#include "drizzled/table_identifier.h"
30
 
#include "drizzled/message/table.pb.h"
31
 
#include "drizzled/charset.h"
32
 
#include "drizzled/field.h"
33
 
 
34
 
#include <string>
35
 
#include <set>
36
 
#include <algorithm>
37
 
 
38
 
namespace drizzled
39
 
{
40
 
 
41
 
extern int wild_case_compare(const CHARSET_INFO * const cs, 
42
 
                             const char *str,const char *wildstr);
43
 
 
44
 
namespace plugin
45
 
{
46
 
 
47
 
// Not thread safe, but plugins are just loaded in a single thread right
48
 
// now.
49
 
static const char *local_string_append(const char *arg1, const char *arg2)
50
 
{
51
 
  static char buffer[1024];
52
 
  char *buffer_ptr= buffer;
53
 
  strcpy(buffer_ptr, arg1);
54
 
  buffer_ptr+= strlen(arg1);
55
 
  buffer_ptr[0]= '-';
56
 
  buffer_ptr++;
57
 
  strcpy(buffer_ptr, arg2);
58
 
 
59
 
  return buffer;
60
 
}
61
 
 
62
 
class TableFunction : public Plugin
63
 
{
64
 
  TableFunction();
65
 
  TableFunction(const TableFunction &);
66
 
  TableFunction& operator=(const TableFunction &);
67
 
 
68
 
  message::Table proto;
69
 
  TableIdentifier identifier;
70
 
  std::string local_path;
71
 
  std::string local_schema;
72
 
  std::string local_table_name;
73
 
  std::string original_table_label;
74
 
 
75
 
  void setName(); // init name
76
 
 
77
 
  void init();
78
 
 
79
 
public:
80
 
  TableFunction(const char *schema_arg, const char *table_arg) :
81
 
    Plugin(local_string_append(schema_arg, table_arg) , "TableFunction"),
82
 
    identifier(schema_arg, table_arg),
83
 
    original_table_label(table_arg)
84
 
  {
85
 
    init();
86
 
  }
87
 
 
88
 
  virtual ~TableFunction() {}
89
 
 
90
 
  static bool addPlugin(TableFunction *function);
91
 
  static void removePlugin(TableFunction *) 
92
 
  { }
93
 
  static TableFunction *getFunction(const std::string &arg);
94
 
  static void getNames(const std::string &arg,
95
 
                       std::set<std::string> &set_of_names);
96
 
 
97
 
  enum ColumnType {
98
 
    BOOLEAN,
99
 
    NUMBER,
100
 
    STRING,
101
 
    VARBINARY
102
 
  };
103
 
 
104
 
  class Generator 
105
 
  {
106
 
    Field **columns;
107
 
    Field **columns_iterator;
108
 
    Session *session;
109
 
 
110
 
  protected:
111
 
 
112
 
    drizzled::Session &getSession()
113
 
    {
114
 
      return *session;
115
 
    }
116
 
 
117
 
  public:
118
 
    const CHARSET_INFO *scs;
119
 
 
120
 
    Generator(Field **arg);
121
 
    virtual ~Generator()
122
 
    { }
123
 
 
124
 
    /*
125
 
      Return type is bool meaning "are there more rows".
126
 
    */
127
 
    bool sub_populate(uint32_t field_size);
128
 
 
129
 
    virtual bool populate()
130
 
    {
131
 
      return false;
132
 
    }
133
 
 
134
 
    void push(uint64_t arg);
135
 
    void push(int64_t arg);
136
 
    void push(const char *arg, uint32_t length= 0);
137
 
    void push(const std::string& arg);
138
 
    void push(bool arg);
139
 
    void push();
140
 
 
141
 
    bool isWild(const std::string &predicate);
142
 
  };
143
 
 
144
 
  void define(message::Table &arg)
145
 
  { 
146
 
    arg.CopyFrom(proto);
147
 
  }
148
 
 
149
 
  const std::string &getTableLabel()
150
 
  { 
151
 
    return original_table_label;
152
 
  }
153
 
 
154
 
  const std::string &getIdentifierTableName()
155
 
  { 
156
 
    if (local_table_name.empty())
157
 
    {
158
 
      local_table_name= identifier.getTableName();
159
 
      std::transform(local_table_name.begin(), local_table_name.end(),
160
 
                     local_table_name.begin(), ::tolower);
161
 
    }
162
 
 
163
 
    return local_table_name;
164
 
  }
165
 
 
166
 
  const std::string &getSchemaHome()
167
 
  { 
168
 
    if (local_schema.empty())
169
 
    {
170
 
      local_schema= identifier.getSchemaName();
171
 
      std::transform(local_schema.begin(), local_schema.end(),
172
 
                     local_schema.begin(), ::tolower);
173
 
    }
174
 
 
175
 
    return local_schema;
176
 
  }
177
 
 
178
 
  const std::string &getPath()
179
 
  { 
180
 
    if (local_path.empty())
181
 
    {
182
 
      local_path= identifier.getPath();
183
 
      std::transform(local_path.begin(), local_path.end(),
184
 
                     local_path.begin(), ::tolower);
185
 
    }
186
 
 
187
 
    return local_path;
188
 
  }
189
 
 
190
 
  virtual Generator *generator(Field **arg);
191
 
 
192
 
  void add_field(const char *label,
193
 
                 message::Table::Field::FieldType type,
194
 
                 uint32_t length= 0);
195
 
 
196
 
  void add_field(const char *label,
197
 
                 uint32_t field_length= 64);
198
 
 
199
 
  void add_field(const char *label,
200
 
                 TableFunction::ColumnType type,
201
 
                 bool is_default_null= true);
202
 
 
203
 
  void add_field(const char *label,
204
 
                 TableFunction::ColumnType type,
205
 
                 uint32_t field_length,
206
 
                 bool is_default_null= false);
207
 
};
208
 
 
209
 
} /* namespace plugin */
210
 
} /* namespace drizzled */
211
 
 
212
 
#endif /* DRIZZLED_PLUGIN_TABLE_FUNCTION_H */