drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
table_function.h
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, Inc.
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#pragma once
24
26#include <drizzled/plugin.h>
27#include <drizzled/plugin/plugin.h>
28#include <drizzled/identifier.h>
29#include <drizzled/message/table.pb.h>
30#include <drizzled/charset.h>
31#include <drizzled/field.h>
32#include <drizzled/catalog/local.h>
33
34#include <string>
35#include <set>
36#include <algorithm>
37
38#include <drizzled/visibility.h>
39
40namespace drizzled {
41namespace plugin {
42
43#define TABLE_FUNCTION_BLOB_SIZE 2049
44
45// Not thread safe, but plugins are just loaded in a single thread right
46// now.
47static const char *local_string_append(const char *arg1, const char *arg2)
48{
49 static char buffer[1024];
50 char *buffer_ptr= buffer;
51 strcpy(buffer_ptr, arg1);
52 buffer_ptr+= strlen(arg1);
53 buffer_ptr[0]= '-';
54 buffer_ptr++;
55 strcpy(buffer_ptr, arg2);
56
57 return buffer;
58}
59
60class DRIZZLED_API TableFunction : public Plugin
61{
62 message::Table proto;
63 identifier::Table identifier;
64 std::string local_path;
65 std::string original_table_label;
66
67 void setName(); // init name
68 void init();
69
70public:
71 /* FIXME: should use a universal catalog identifier */
72 TableFunction(const char *schema_arg, const char *table_arg) :
73 Plugin(local_string_append(schema_arg, table_arg) , "TableFunction"),
74 identifier(drizzled::catalog::local_identifier(),
75 schema_arg, table_arg),
76 original_table_label(table_arg)
77 {
78 init();
79 }
80
81 static bool addPlugin(TableFunction &function);
82 static void removePlugin(TableFunction &)
83 { }
84 static TableFunction *getFunction(const std::string &arg);
85 static void getNames(const std::string &arg,
86 std::set<std::string> &set_of_names);
87
88 enum ColumnType {
89 BOOLEAN,
90 NUMBER,
91 STRING,
92 VARBINARY,
93 SIZE
94 };
95
96 class Generator
97 {
98 Field **columns;
99 Field **columns_iterator;
100 Session *session;
101
102 protected:
103 LEX& lex();
104 statement::Statement& statement();
105
106 drizzled::Session &getSession()
107 {
108 return *session;
109 }
110
111 public:
112 const charset_info_st *scs;
113
114 Generator(Field **arg);
115 virtual ~Generator()
116 { }
117
118 /*
119 Return type is bool meaning "are there more rows".
120 */
121 bool sub_populate(uint32_t field_size);
122
123 virtual bool populate()
124 {
125 return false;
126 }
127
128 void push(uint64_t arg);
129 void push(int64_t arg);
130 void push(const char *arg, uint32_t length= 0);
131 void push(str_ref);
132 void push(bool arg);
133 void push();
134
135 bool isWild(const std::string &predicate);
136 };
137
138 void define(message::Table &arg)
139 {
140 arg.CopyFrom(proto);
141 }
142
143 const std::string &getTableLabel()
144 {
145 return original_table_label;
146 }
147
148 const std::string &getIdentifierTableName()
149 {
150 return identifier.getTableName();
151 }
152
153 const std::string &getSchemaHome()
154 {
155 return identifier.getSchemaName();
156 }
157
158 const std::string &getPath()
159 {
160 return identifier.getPath();
161 }
162
163 virtual Generator *generator(Field **arg);
164
165 void add_field(const char *label,
166 message::Table::Field::FieldType type,
167 uint32_t length= 0);
168
169 void add_field(const char *label,
170 uint32_t field_length= MAXIMUM_IDENTIFIER_LENGTH);
171
172 void add_field(const char *label,
173 TableFunction::ColumnType type,
174 bool is_default_null= true);
175
176 void add_field(const char *label,
177 TableFunction::ColumnType type,
178 uint32_t field_length,
179 bool is_default_null= false);
180
181 virtual bool visible() const { return true; }
182};
183
184} /* namespace plugin */
185} /* namespace drizzled */
186
Represents a statement to be executed.
Definition statement.h:36
TODO: Rename this file - func.h is stupid.
Visibility Control Macros.
#define DRIZZLED_API
Definition visibility.h:38