1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Definitions required for TableFunction plugin
6
* Copyright (C) 2010 Sun Microsystems
7
* Copyright (C) 2010 Monty Taylor
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.
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.
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
23
#ifndef DRIZZLED_PLUGIN_TABLE_FUNCTION_H
24
#define DRIZZLED_PLUGIN_TABLE_FUNCTION_H
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"
41
extern int wild_case_compare(const CHARSET_INFO * const cs,
42
const char *str,const char *wildstr);
47
// Not thread safe, but plugins are just loaded in a single thread right
49
static const char *local_string_append(const char *arg1, const char *arg2)
51
static char buffer[1024];
52
char *buffer_ptr= buffer;
53
strcpy(buffer_ptr, arg1);
54
buffer_ptr+= strlen(arg1);
57
strcpy(buffer_ptr, arg2);
62
class TableFunction : public Plugin
65
TableFunction(const TableFunction &);
66
TableFunction& operator=(const TableFunction &);
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;
75
void setName(); // init name
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)
88
virtual ~TableFunction() {}
90
static bool addPlugin(TableFunction *function);
91
static void removePlugin(TableFunction *)
93
static TableFunction *getFunction(const std::string &arg);
94
static void getNames(const std::string &arg,
95
std::set<std::string> &set_of_names);
107
Field **columns_iterator;
110
const CHARSET_INFO *scs;
112
Generator(Field **arg);
117
Return type is bool meaning "are there more rows".
119
bool sub_populate(uint32_t field_size);
121
virtual bool populate()
126
void push(uint64_t arg);
127
void push(int64_t arg);
128
void push(const char *arg, uint32_t length= 0);
129
void push(const std::string& arg);
133
bool isWild(const std::string &predicate);
136
void define(message::Table &arg)
141
const std::string &getTableLabel()
143
return original_table_label;
146
const std::string &getIdentifierTableName()
148
if (local_table_name.empty())
150
local_table_name= identifier.getTableName();
151
std::transform(local_table_name.begin(), local_table_name.end(),
152
local_table_name.begin(), ::tolower);
155
return local_table_name;
158
const std::string &getSchemaHome()
160
if (local_schema.empty())
162
local_schema= identifier.getSchemaName();
163
std::transform(local_schema.begin(), local_schema.end(),
164
local_schema.begin(), ::tolower);
170
const std::string &getPath()
172
if (local_path.empty())
174
local_path= identifier.getPath();
175
std::transform(local_path.begin(), local_path.end(),
176
local_path.begin(), ::tolower);
182
virtual Generator *generator(Field **arg);
184
void add_field(const char *label,
185
message::Table::Field::FieldType type,
188
void add_field(const char *label,
189
uint32_t field_length= 64);
191
void add_field(const char *label,
192
TableFunction::ColumnType type,
193
bool is_default_null= true);
195
void add_field(const char *label,
196
TableFunction::ColumnType type,
197
uint32_t field_length,
198
bool is_default_null= false);
201
} /* namespace plugin */
202
} /* namespace drizzled */
204
#endif /* DRIZZLED_PLUGIN_TABLE_FUNCTION_H */