~drizzle-trunk/drizzle/development

1273.13.1 by Brian Aker
First pass through data dictionary.
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1273.13.18 by Brian Aker
Update code, first pass through cleaner method for recursing through
4
 *  Copyright (C) 2010 Sun Microsystems
1273.13.1 by Brian Aker
First pass through data dictionary.
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
1273.14.5 by Monty Taylor
Merged trunk.
21
#include "config.h"
22
1273.13.55 by Brian Aker
Naming fixes.
23
#include <plugin/function_engine/function.h>
24
#include <plugin/function_engine/cursor.h>
1273.13.1 by Brian Aker
First pass through data dictionary.
25
26
#include <string>
27
28
using namespace std;
29
using namespace drizzled;
30
1415 by Brian Aker
Mass overhaul to use schema_identifier.
31
static SchemaIdentifier INFORMATION_SCHEMA_IDENTIFIER("INFORMATION_SCHEMA");
32
static SchemaIdentifier DATA_DICTIONARY_IDENTIFIER("DATA_DICTIONARY");
33
1273.13.18 by Brian Aker
Update code, first pass through cleaner method for recursing through
34
Function::Function(const std::string &name_arg) :
1273.13.1 by Brian Aker
First pass through data dictionary.
35
  drizzled::plugin::StorageEngine(name_arg,
36
                                  HTON_ALTER_NOT_SUPPORTED |
1273.19.30 by Brian Aker
Performance patch... we now only cycle through engines that actually have
37
                                  HTON_HAS_SCHEMA_DICTIONARY |
1273.13.1 by Brian Aker
First pass through data dictionary.
38
                                  HTON_SKIP_STORE_LOCK |
1812.3.8 by Brian Aker
This switches our schema system over to using a shared ptr. Lets see how
39
                                  HTON_TEMPORARY_NOT_SUPPORTED),
40
  information_message(new(message::Schema)),
41
  data_dictionary_message(new(message::Schema))
42
1273.13.1 by Brian Aker
First pass through data dictionary.
43
{
1812.3.8 by Brian Aker
This switches our schema system over to using a shared ptr. Lets see how
44
  information_message->set_name("information_schema");
45
  data_dictionary_message->set_collation("utf8_general_ci");
46
47
  data_dictionary_message->set_name("data_dictionary");
48
  data_dictionary_message->set_collation("utf8_general_ci");
1273.13.1 by Brian Aker
First pass through data dictionary.
49
}
50
51
1680.6.1 by Brian Aker
Remove call for using special new for a cursor.
52
Cursor *Function::create(TableShare &table)
1273.13.1 by Brian Aker
First pass through data dictionary.
53
{
1680.6.1 by Brian Aker
Remove call for using special new for a cursor.
54
  return new FunctionCursor(*this, table);
1273.13.1 by Brian Aker
First pass through data dictionary.
55
}
56
1273.13.18 by Brian Aker
Update code, first pass through cleaner method for recursing through
57
int Function::doGetTableDefinition(Session &,
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
58
                                   const TableIdentifier &identifier,
1358.1.1 by Brian Aker
Fixes regression in performance from Exists patch.
59
                                   message::Table &table_proto)
1273.13.1 by Brian Aker
First pass through data dictionary.
60
{
1669.3.3 by Brian Aker
Remove the need for tolower in retrieval of table functions.
61
  drizzled::plugin::TableFunction *function= getFunction(identifier.getPath());
1273.13.6 by Brian Aker
Updates for interface/etc.
62
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
63
  if (not function)
1273.13.6 by Brian Aker
Updates for interface/etc.
64
  {
1273.13.1 by Brian Aker
First pass through data dictionary.
65
    return ENOENT;
66
  }
67
1354.1.1 by Brian Aker
Modify ptr to reference.
68
  function->define(table_proto);
1273.13.6 by Brian Aker
Updates for interface/etc.
69
1273.13.1 by Brian Aker
First pass through data dictionary.
70
  return EEXIST;
71
}
72
1643.3.3 by Brian Aker
Updated to harmonize the identifier API.
73
void Function::doGetSchemaIdentifiers(SchemaIdentifiers& schemas)
1415 by Brian Aker
Mass overhaul to use schema_identifier.
74
{
75
  schemas.push_back(INFORMATION_SCHEMA_IDENTIFIER);
76
  schemas.push_back(DATA_DICTIONARY_IDENTIFIER);
77
}
78
1812.3.8 by Brian Aker
This switches our schema system over to using a shared ptr. Lets see how
79
bool Function::doGetSchemaDefinition(const SchemaIdentifier &schema_identifier, message::SchemaPtr &schema_message)
1415 by Brian Aker
Mass overhaul to use schema_identifier.
80
{
1812.3.8 by Brian Aker
This switches our schema system over to using a shared ptr. Lets see how
81
  schema_message.reset(new message::Schema); // This should be fixed, we could just be using ones we built on startup.
82
1415 by Brian Aker
Mass overhaul to use schema_identifier.
83
  if (schema_identifier == INFORMATION_SCHEMA_IDENTIFIER)
1273.19.23 by Brian Aker
Updated meta calls for data_dictionary
84
  {
1812.3.8 by Brian Aker
This switches our schema system over to using a shared ptr. Lets see how
85
    schema_message= information_message;
1273.19.23 by Brian Aker
Updated meta calls for data_dictionary
86
  }
1415 by Brian Aker
Mass overhaul to use schema_identifier.
87
  else if (schema_identifier == DATA_DICTIONARY_IDENTIFIER)
1273.19.23 by Brian Aker
Updated meta calls for data_dictionary
88
  {
1812.3.8 by Brian Aker
This switches our schema system over to using a shared ptr. Lets see how
89
    schema_message= data_dictionary_message;
1273.19.23 by Brian Aker
Updated meta calls for data_dictionary
90
  }
91
  else
92
  {
93
    return false;
94
  }
95
96
  return true;
1273.19.22 by Brian Aker
Shuffled information_schema;
97
}
98
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
99
bool Function::doCanCreateTable(const drizzled::TableIdentifier &table_identifier)
1320.1.8 by Brian Aker
Temporary fix for allowing engines to say "don't do this".
100
{
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
101
  if (static_cast<const SchemaIdentifier&>(table_identifier) == INFORMATION_SCHEMA_IDENTIFIER)
1320.1.8 by Brian Aker
Temporary fix for allowing engines to say "don't do this".
102
  {
103
    return false;
104
  }
105
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
106
  else if (static_cast<const SchemaIdentifier&>(table_identifier) == DATA_DICTIONARY_IDENTIFIER)
1320.1.8 by Brian Aker
Temporary fix for allowing engines to say "don't do this".
107
  {
108
    return false;
109
  }
110
111
  return true;
112
}
113
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
114
bool Function::doDoesTableExist(Session&, const TableIdentifier &identifier)
1358.1.1 by Brian Aker
Fixes regression in performance from Exists patch.
115
{
116
  drizzled::plugin::TableFunction *function= getFunction(identifier.getPath());
117
118
  if (function)
119
    return true;
120
121
  return false;
122
}
123
1273.13.1 by Brian Aker
First pass through data dictionary.
124
1429.1.3 by Brian Aker
Merge in work for fetching a list of table identifiers.
125
void Function::doGetTableIdentifiers(drizzled::CachedDirectory&,
1642 by Brian Aker
This adds const to SchemaIdentifier.
126
                                     const drizzled::SchemaIdentifier &schema_identifier,
1429.1.3 by Brian Aker
Merge in work for fetching a list of table identifiers.
127
                                     drizzled::TableIdentifiers &set_of_identifiers)
128
{
129
  set<string> set_of_names;
130
  drizzled::plugin::TableFunction::getNames(schema_identifier.getSchemaName(), set_of_names);
131
132
  for (set<string>::iterator iter= set_of_names.begin(); iter != set_of_names.end(); iter++)
133
  {
1643.3.9 by Brian Aker
Updated to hold tables in I_S.
134
    set_of_identifiers.push_back(TableIdentifier(schema_identifier, *iter, drizzled::message::Table::FUNCTION));
1429.1.3 by Brian Aker
Merge in work for fetching a list of table identifiers.
135
  }
136
}
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
137
1530.2.6 by Monty Taylor
Moved plugin::Context to module::Context.
138
static int init(drizzled::module::Context &context)
1273.13.1 by Brian Aker
First pass through data dictionary.
139
{
1429.1.3 by Brian Aker
Merge in work for fetching a list of table identifiers.
140
  context.add(new Function("FunctionEngine"));
1273.13.36 by Brian Aker
Adding support for LOCAL_TABLE_NAMES and SCHEMA_NAMES
141
1273.13.1 by Brian Aker
First pass through data dictionary.
142
  return 0;
143
}
144
145
DRIZZLE_DECLARE_PLUGIN
146
{
147
  DRIZZLE_VERSION_ID,
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
148
  "FunctionEngine",
1273.13.1 by Brian Aker
First pass through data dictionary.
149
  "1.0",
150
  "Brian Aker",
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
151
  "Function Engine provides the infrastructure for Table Functions,etc.",
1273.13.1 by Brian Aker
First pass through data dictionary.
152
  PLUGIN_LICENSE_GPL,
153
  init,     /* Plugin Init */
154
  NULL,               /* system variables */
155
  NULL                /* config options   */
156
}
157
DRIZZLE_DECLARE_PLUGIN_END;