drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
plugin/function_engine/function.cc
1/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Sun Microsystems, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <config.h>
22#include <plugin/function_engine/function.h>
23#include <plugin/function_engine/cursor.h>
24#include <string>
25
26using namespace std;
27using namespace drizzled;
28
29Function::Function(const std::string &name_arg) :
30 drizzled::plugin::StorageEngine(name_arg,
31 HTON_ALTER_NOT_SUPPORTED |
32 HTON_HAS_SCHEMA_DICTIONARY |
33 HTON_SKIP_STORE_LOCK |
34 HTON_TEMPORARY_NOT_SUPPORTED),
35 information_message(new message::Schema),
36 data_dictionary_message(new message::Schema)
37
38{
39 information_message->set_name(INFORMATION_SCHEMA_IDENTIFIER.getSchemaName());
40 information_message->set_collation("utf8_general_ci");
41 message::set_is_replicated(*information_message, false);
42
43 data_dictionary_message->set_name(DATA_DICTIONARY_IDENTIFIER.getSchemaName());
44 data_dictionary_message->set_collation("utf8_general_ci");
45 message::set_is_replicated(*data_dictionary_message, false);
46}
47
48
49Cursor *Function::create(Table &table)
50{
51 return new FunctionCursor(*this, table);
52}
53
54int Function::doGetTableDefinition(Session &,
55 const identifier::Table &identifier,
56 message::Table &table_proto)
57{
58 drizzled::plugin::TableFunction *function= getFunction(identifier.getPath());
59
60 if (not function)
61 {
62 return ENOENT;
63 }
64
65 function->define(table_proto);
66
67 return EEXIST;
68}
69
70void Function::doGetSchemaIdentifiers(identifier::schema::vector& schemas)
71{
72 schemas.push_back(INFORMATION_SCHEMA_IDENTIFIER);
73 schemas.push_back(DATA_DICTIONARY_IDENTIFIER);
74}
75
76drizzled::message::schema::shared_ptr Function::doGetSchemaDefinition(const identifier::Schema &schema_identifier)
77{
78 drizzled::message::schema::shared_ptr schema_message;
79
80 if (schema_identifier == INFORMATION_SCHEMA_IDENTIFIER)
81 {
82 schema_message= information_message;
83 }
84 else if (schema_identifier == DATA_DICTIONARY_IDENTIFIER)
85 {
86 schema_message= data_dictionary_message;
87 }
88 else
89 {
90 return drizzled::message::schema::shared_ptr();
91 }
92
93 return schema_message;
94}
95
96bool Function::doCanCreateTable(const drizzled::identifier::Table &table_identifier)
97{
98 if (static_cast<const identifier::Schema&>(table_identifier) == INFORMATION_SCHEMA_IDENTIFIER)
99 {
100 return false;
101 }
102
103 else if (static_cast<const identifier::Schema&>(table_identifier) == DATA_DICTIONARY_IDENTIFIER)
104 {
105 return false;
106 }
107
108 return true;
109}
110
111bool Function::doDoesTableExist(Session&, const identifier::Table &identifier)
112{
113 return getFunction(identifier.getPath());
114}
115
116
117void Function::doGetTableIdentifiers(drizzled::CachedDirectory&,
118 const drizzled::identifier::Schema &schema_identifier,
119 drizzled::identifier::table::vector &set_of_identifiers)
120{
121 set<std::string> set_of_names;
122 drizzled::plugin::TableFunction::getNames(schema_identifier.getSchemaName(), set_of_names);
123
124 for (const std::string& iter : set_of_names)
125 {
126 set_of_identifiers.push_back(identifier::Table(schema_identifier, iter, drizzled::message::Table::FUNCTION));
127 }
128}
129
130static int init(drizzled::module::Context &context)
131{
132 context.add(new Function("FunctionEngine"));
133
134 return 0;
135}
136
137DRIZZLE_DECLARE_PLUGIN
138{
139 DRIZZLE_VERSION_ID,
140 "function_engine",
141 "1.0",
142 "Brian Aker",
143 N_("Function engine"),
144 PLUGIN_LICENSE_GPL,
145 init,
146 NULL,
147 NULL
148}
149DRIZZLE_DECLARE_PLUGIN_END;
TODO: Rename this file - func.h is stupid.
STL namespace.