~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/function_engine/function.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
using namespace std;
29
29
using namespace drizzled;
30
30
 
 
31
static SchemaIdentifier INFORMATION_SCHEMA_IDENTIFIER("INFORMATION_SCHEMA");
 
32
static SchemaIdentifier DATA_DICTIONARY_IDENTIFIER("DATA_DICTIONARY");
 
33
 
31
34
Function::Function(const std::string &name_arg) :
32
35
  drizzled::plugin::StorageEngine(name_arg,
33
36
                                  HTON_ALTER_NOT_SUPPORTED |
34
37
                                  HTON_HAS_SCHEMA_DICTIONARY |
35
 
                                  HTON_HAS_DATA_DICTIONARY |
36
38
                                  HTON_SKIP_STORE_LOCK |
37
39
                                  HTON_TEMPORARY_NOT_SUPPORTED)
38
40
{
39
41
}
40
42
 
41
43
 
42
 
Cursor *Function::create(TableShare &table, memory::Root *mem_root)
 
44
Cursor *Function::create(TableShare &table)
43
45
{
44
 
  return new (mem_root) FunctionCursor(*this, table);
 
46
  return new FunctionCursor(*this, table);
45
47
}
46
48
 
47
49
int Function::doGetTableDefinition(Session &,
48
 
                                     const char *path,
49
 
                                     const char *,
50
 
                                     const char *,
51
 
                                     const bool,
52
 
                                     message::Table *table_proto)
 
50
                                   const TableIdentifier &identifier,
 
51
                                   message::Table &table_proto)
53
52
{
54
 
  string tab_name(path);
55
 
  transform(tab_name.begin(), tab_name.end(),
56
 
            tab_name.begin(), ::tolower);
57
 
 
58
 
  drizzled::plugin::TableFunction *function= getFunction(tab_name);
 
53
  drizzled::plugin::TableFunction *function= getFunction(identifier.getPath());
59
54
 
60
55
  if (not function)
61
56
  {
62
57
    return ENOENT;
63
58
  }
64
59
 
65
 
  if (table_proto)
66
 
  {
67
 
    function->define(*table_proto);
68
 
  }
 
60
  function->define(table_proto);
69
61
 
70
62
  return EEXIST;
71
63
}
72
64
 
73
 
 
74
 
void Function::doGetTableNames(drizzled::CachedDirectory&, 
75
 
                               string &db, 
76
 
                               set<string> &set_of_names)
77
 
{
78
 
  drizzled::plugin::TableFunction::getNames(db, set_of_names);
79
 
}
80
 
 
81
 
void Function::doGetSchemaNames(std::set<std::string>& set_of_names)
82
 
{
83
 
  set_of_names.insert("information_schema"); // special cases suck
84
 
  set_of_names.insert("data_dictionary"); // special cases suck
85
 
}
86
 
 
87
 
bool Function::doGetSchemaDefinition(const std::string &schema_name, message::Schema &schema_message)
88
 
{
89
 
  if (not schema_name.compare("information_schema"))
 
65
void Function::doGetSchemaIdentifiers(SchemaIdentifiers& schemas)
 
66
{
 
67
  schemas.push_back(INFORMATION_SCHEMA_IDENTIFIER);
 
68
  schemas.push_back(DATA_DICTIONARY_IDENTIFIER);
 
69
}
 
70
 
 
71
bool Function::doGetSchemaDefinition(const SchemaIdentifier &schema_identifier, message::Schema &schema_message)
 
72
{
 
73
  if (schema_identifier == INFORMATION_SCHEMA_IDENTIFIER)
90
74
  {
91
75
    schema_message.set_name("information_schema");
92
76
    schema_message.set_collation("utf8_general_ci");
93
77
  }
94
 
  else if (not schema_name.compare("data_dictionary"))
 
78
  else if (schema_identifier == DATA_DICTIONARY_IDENTIFIER)
95
79
  {
96
80
    schema_message.set_name("data_dictionary");
97
81
    schema_message.set_collation("utf8_general_ci");
104
88
  return true;
105
89
}
106
90
 
107
 
bool Function::doCanCreateTable(const drizzled::TableIdentifier &identifier)
 
91
bool Function::doCanCreateTable(const drizzled::TableIdentifier &table_identifier)
108
92
{
109
 
  if (not strcasecmp(identifier.getSchemaName(), "information_schema"))
 
93
  if (static_cast<const SchemaIdentifier&>(table_identifier) == INFORMATION_SCHEMA_IDENTIFIER)
110
94
  {
111
95
    return false;
112
96
  }
113
97
 
114
 
  if (not strcasecmp(identifier.getSchemaName(), "data_dictionary"))
 
98
  else if (static_cast<const SchemaIdentifier&>(table_identifier) == DATA_DICTIONARY_IDENTIFIER)
115
99
  {
116
100
    return false;
117
101
  }
119
103
  return true;
120
104
}
121
105
 
122
 
 
123
 
static drizzled::plugin::StorageEngine *function_plugin= NULL;
124
 
 
125
 
static int init(drizzled::plugin::Registry &registry)
126
 
{
127
 
  function_plugin= new(std::nothrow) Function("FunctionEngine");
128
 
 
129
 
  if (not function_plugin)
 
106
bool Function::doDoesTableExist(Session&, const TableIdentifier &identifier)
 
107
{
 
108
  drizzled::plugin::TableFunction *function= getFunction(identifier.getPath());
 
109
 
 
110
  if (function)
 
111
    return true;
 
112
 
 
113
  return false;
 
114
}
 
115
 
 
116
 
 
117
void Function::doGetTableIdentifiers(drizzled::CachedDirectory&,
 
118
                                     const drizzled::SchemaIdentifier &schema_identifier,
 
119
                                     drizzled::TableIdentifiers &set_of_identifiers)
 
120
{
 
121
  set<string> set_of_names;
 
122
  drizzled::plugin::TableFunction::getNames(schema_identifier.getSchemaName(), set_of_names);
 
123
 
 
124
  for (set<string>::iterator iter= set_of_names.begin(); iter != set_of_names.end(); iter++)
130
125
  {
131
 
    return 1;
 
126
    set_of_identifiers.push_back(TableIdentifier(schema_identifier, *iter, drizzled::message::Table::FUNCTION));
132
127
  }
133
 
 
134
 
  registry.add(function_plugin);
135
 
 
136
 
  return 0;
137
128
}
138
129
 
139
 
static int finalize(drizzled::plugin::Registry &registry)
 
130
static int init(drizzled::module::Context &context)
140
131
{
141
 
  registry.remove(function_plugin);
142
 
  delete function_plugin;
 
132
  context.add(new Function("FunctionEngine"));
143
133
 
144
134
  return 0;
145
135
}
153
143
  "Function Engine provides the infrastructure for Table Functions,etc.",
154
144
  PLUGIN_LICENSE_GPL,
155
145
  init,     /* Plugin Init */
156
 
  finalize,     /* Plugin Deinit */
157
146
  NULL,               /* system variables */
158
147
  NULL                /* config options   */
159
148
}