00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022 #include <boost/foreach.hpp>
00023 #include <plugin/function_engine/function.h>
00024 #include <plugin/function_engine/cursor.h>
00025 #include <string>
00026
00027 using namespace std;
00028 using namespace drizzled;
00029
00030 Function::Function(const std::string &name_arg) :
00031 drizzled::plugin::StorageEngine(name_arg,
00032 HTON_ALTER_NOT_SUPPORTED |
00033 HTON_HAS_SCHEMA_DICTIONARY |
00034 HTON_SKIP_STORE_LOCK |
00035 HTON_TEMPORARY_NOT_SUPPORTED),
00036 information_message(new message::Schema),
00037 data_dictionary_message(new message::Schema)
00038
00039 {
00040 information_message->set_name(INFORMATION_SCHEMA_IDENTIFIER.getSchemaName());
00041 information_message->set_collation("utf8_general_ci");
00042 message::set_is_replicated(*information_message, false);
00043
00044 data_dictionary_message->set_name(DATA_DICTIONARY_IDENTIFIER.getSchemaName());
00045 data_dictionary_message->set_collation("utf8_general_ci");
00046 message::set_is_replicated(*data_dictionary_message, false);
00047 }
00048
00049
00050 Cursor *Function::create(Table &table)
00051 {
00052 return new FunctionCursor(*this, table);
00053 }
00054
00055 int Function::doGetTableDefinition(Session &,
00056 const identifier::Table &identifier,
00057 message::Table &table_proto)
00058 {
00059 drizzled::plugin::TableFunction *function= getFunction(identifier.getPath());
00060
00061 if (not function)
00062 {
00063 return ENOENT;
00064 }
00065
00066 function->define(table_proto);
00067
00068 return EEXIST;
00069 }
00070
00071 void Function::doGetSchemaIdentifiers(identifier::schema::vector& schemas)
00072 {
00073 schemas.push_back(INFORMATION_SCHEMA_IDENTIFIER);
00074 schemas.push_back(DATA_DICTIONARY_IDENTIFIER);
00075 }
00076
00077 drizzled::message::schema::shared_ptr Function::doGetSchemaDefinition(const identifier::Schema &schema_identifier)
00078 {
00079 drizzled::message::schema::shared_ptr schema_message;
00080
00081 if (schema_identifier == INFORMATION_SCHEMA_IDENTIFIER)
00082 {
00083 schema_message= information_message;
00084 }
00085 else if (schema_identifier == DATA_DICTIONARY_IDENTIFIER)
00086 {
00087 schema_message= data_dictionary_message;
00088 }
00089 else
00090 {
00091 return drizzled::message::schema::shared_ptr();
00092 }
00093
00094 return schema_message;
00095 }
00096
00097 bool Function::doCanCreateTable(const drizzled::identifier::Table &table_identifier)
00098 {
00099 if (static_cast<const identifier::Schema&>(table_identifier) == INFORMATION_SCHEMA_IDENTIFIER)
00100 {
00101 return false;
00102 }
00103
00104 else if (static_cast<const identifier::Schema&>(table_identifier) == DATA_DICTIONARY_IDENTIFIER)
00105 {
00106 return false;
00107 }
00108
00109 return true;
00110 }
00111
00112 bool Function::doDoesTableExist(Session&, const identifier::Table &identifier)
00113 {
00114 return getFunction(identifier.getPath());
00115 }
00116
00117
00118 void Function::doGetTableIdentifiers(drizzled::CachedDirectory&,
00119 const drizzled::identifier::Schema &schema_identifier,
00120 drizzled::identifier::table::vector &set_of_identifiers)
00121 {
00122 set<std::string> set_of_names;
00123 drizzled::plugin::TableFunction::getNames(schema_identifier.getSchemaName(), set_of_names);
00124
00125 BOOST_FOREACH(const std::string& iter, set_of_names)
00126 {
00127 set_of_identifiers.push_back(identifier::Table(schema_identifier, iter, drizzled::message::Table::FUNCTION));
00128 }
00129 }
00130
00131 static int init(drizzled::module::Context &context)
00132 {
00133 context.add(new Function("FunctionEngine"));
00134
00135 return 0;
00136 }
00137
00138 DRIZZLE_DECLARE_PLUGIN
00139 {
00140 DRIZZLE_VERSION_ID,
00141 "FunctionEngine",
00142 "1.0",
00143 "Brian Aker",
00144 "Function Engine provides the infrastructure for Table Functions,etc.",
00145 PLUGIN_LICENSE_GPL,
00146 init,
00147 NULL,
00148 NULL
00149 }
00150 DRIZZLE_DECLARE_PLUGIN_END;