~posulliv/drizzle/optimizer-style-cleanup

« back to all changes in this revision

Viewing changes to plugin/function_engine/function.cc

  • Committer: Padraig O'Sullivan
  • Date: 2010-04-17 01:38:47 UTC
  • mfrom: (1237.9.238 bad-staging)
  • Revision ID: osullivan.padraig@gmail.com-20100417013847-ibjioqsfbmf5yg4g
Merge trunk.

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
{
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
                                   TableIdentifier &identifier,
 
51
                                   message::Table &table_proto)
53
52
{
54
 
  string tab_name(path);
 
53
  string tab_name(identifier.getPath());
55
54
  transform(tab_name.begin(), tab_name.end(),
56
55
            tab_name.begin(), ::tolower);
57
56
 
62
61
    return ENOENT;
63
62
  }
64
63
 
65
 
  if (table_proto)
66
 
  {
67
 
    function->define(*table_proto);
68
 
  }
 
64
  function->define(table_proto);
69
65
 
70
66
  return EEXIST;
71
67
}
72
68
 
73
69
 
74
70
void Function::doGetTableNames(drizzled::CachedDirectory&, 
75
 
                               string &db, 
 
71
                               drizzled::SchemaIdentifier &schema_identifier,
76
72
                               set<string> &set_of_names)
77
73
{
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"))
 
74
  drizzled::plugin::TableFunction::getNames(schema_identifier.getSchemaName(), set_of_names);
 
75
}
 
76
 
 
77
void Function::doGetSchemaIdentifiers(SchemaIdentifierList& schemas)
 
78
{
 
79
  schemas.push_back(INFORMATION_SCHEMA_IDENTIFIER);
 
80
  schemas.push_back(DATA_DICTIONARY_IDENTIFIER);
 
81
}
 
82
 
 
83
bool Function::doGetSchemaDefinition(SchemaIdentifier &schema_identifier, message::Schema &schema_message)
 
84
{
 
85
  if (schema_identifier == INFORMATION_SCHEMA_IDENTIFIER)
90
86
  {
91
87
    schema_message.set_name("information_schema");
92
88
    schema_message.set_collation("utf8_general_ci");
93
89
  }
94
 
  else if (not schema_name.compare("data_dictionary"))
 
90
  else if (schema_identifier == DATA_DICTIONARY_IDENTIFIER)
95
91
  {
96
92
    schema_message.set_name("data_dictionary");
97
93
    schema_message.set_collation("utf8_general_ci");
104
100
  return true;
105
101
}
106
102
 
107
 
bool Function::doCanCreateTable(const drizzled::TableIdentifier &identifier)
 
103
bool Function::doCanCreateTable(drizzled::TableIdentifier &table_identifier)
108
104
{
109
 
  if (not strcasecmp(identifier.getSchemaName(), "information_schema"))
 
105
  if (static_cast<SchemaIdentifier&>(table_identifier) == INFORMATION_SCHEMA_IDENTIFIER)
110
106
  {
111
107
    return false;
112
108
  }
113
109
 
114
 
  if (not strcasecmp(identifier.getSchemaName(), "data_dictionary"))
 
110
  else if (static_cast<SchemaIdentifier&>(table_identifier) == DATA_DICTIONARY_IDENTIFIER)
115
111
  {
116
112
    return false;
117
113
  }
119
115
  return true;
120
116
}
121
117
 
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)
 
118
bool Function::doDoesTableExist(Session&, TableIdentifier &identifier)
 
119
{
 
120
  drizzled::plugin::TableFunction *function= getFunction(identifier.getPath());
 
121
 
 
122
  if (function)
 
123
    return true;
 
124
 
 
125
  return false;
 
126
}
 
127
 
 
128
 
 
129
void Function::doGetTableIdentifiers(drizzled::CachedDirectory&,
 
130
                                     drizzled::SchemaIdentifier &schema_identifier,
 
131
                                     drizzled::TableIdentifiers &set_of_identifiers)
 
132
{
 
133
  set<string> set_of_names;
 
134
  drizzled::plugin::TableFunction::getNames(schema_identifier.getSchemaName(), set_of_names);
 
135
 
 
136
  for (set<string>::iterator iter= set_of_names.begin(); iter != set_of_names.end(); iter++)
130
137
  {
131
 
    return 1;
 
138
    set_of_identifiers.push_back(TableIdentifier(schema_identifier, *iter));
132
139
  }
133
 
 
134
 
  registry.add(function_plugin);
135
 
 
136
 
  return 0;
137
140
}
138
141
 
139
 
static int finalize(drizzled::plugin::Registry &registry)
 
142
static int init(drizzled::plugin::Context &context)
140
143
{
141
 
  registry.remove(function_plugin);
142
 
  delete function_plugin;
 
144
  context.add(new Function("FunctionEngine"));
143
145
 
144
146
  return 0;
145
147
}
153
155
  "Function Engine provides the infrastructure for Table Functions,etc.",
154
156
  PLUGIN_LICENSE_GPL,
155
157
  init,     /* Plugin Init */
156
 
  finalize,     /* Plugin Deinit */
157
158
  NULL,               /* system variables */
158
159
  NULL                /* config options   */
159
160
}