~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/function_engine/function.cc

  • Committer: Monty Taylor
  • Date: 2008-09-16 00:00:48 UTC
  • mto: This revision was merged to the branch mainline in revision 391.
  • Revision ID: monty@inaugust.com-20080916000048-3rvrv3gv9l0ad3gs
Fixed copyright headers in drizzled/

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
23
 
#include <plugin/function_engine/function.h>
24
 
#include <plugin/function_engine/cursor.h>
25
 
 
26
 
#include <string>
27
 
 
28
 
using namespace std;
29
 
using namespace drizzled;
30
 
 
31
 
Function::Function(const std::string &name_arg) :
32
 
  drizzled::plugin::StorageEngine(name_arg,
33
 
                                  HTON_ALTER_NOT_SUPPORTED |
34
 
                                  HTON_HAS_SCHEMA_DICTIONARY |
35
 
                                  HTON_SKIP_STORE_LOCK |
36
 
                                  HTON_TEMPORARY_NOT_SUPPORTED),
37
 
  information_message(new(message::Schema)),
38
 
  data_dictionary_message(new(message::Schema))
39
 
 
40
 
{
41
 
  information_message->set_name(INFORMATION_SCHEMA_IDENTIFIER.getSchemaName());
42
 
  data_dictionary_message->set_collation("utf8_general_ci");
43
 
 
44
 
  data_dictionary_message->set_name(DATA_DICTIONARY_IDENTIFIER.getSchemaName());
45
 
  data_dictionary_message->set_collation("utf8_general_ci");
46
 
}
47
 
 
48
 
 
49
 
Cursor *Function::create(Table &table)
50
 
{
51
 
  return new FunctionCursor(*this, table);
52
 
}
53
 
 
54
 
int 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
 
 
70
 
void Function::doGetSchemaIdentifiers(identifier::Schema::vector& schemas)
71
 
{
72
 
  schemas.push_back(INFORMATION_SCHEMA_IDENTIFIER);
73
 
  schemas.push_back(DATA_DICTIONARY_IDENTIFIER);
74
 
}
75
 
 
76
 
bool Function::doGetSchemaDefinition(const identifier::Schema &schema_identifier, message::schema::shared_ptr &schema_message)
77
 
{
78
 
  schema_message.reset(new message::Schema); // This should be fixed, we could just be using ones we built on startup.
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 false;
91
 
  }
92
 
 
93
 
  return true;
94
 
}
95
 
 
96
 
bool 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
 
 
111
 
bool Function::doDoesTableExist(Session&, const identifier::Table &identifier)
112
 
{
113
 
  drizzled::plugin::TableFunction *function= getFunction(identifier.getPath());
114
 
 
115
 
  if (function)
116
 
    return true;
117
 
 
118
 
  return false;
119
 
}
120
 
 
121
 
 
122
 
void Function::doGetTableIdentifiers(drizzled::CachedDirectory&,
123
 
                                     const drizzled::identifier::Schema &schema_identifier,
124
 
                                     drizzled::identifier::Table::vector &set_of_identifiers)
125
 
{
126
 
  set<std::string> set_of_names;
127
 
  drizzled::plugin::TableFunction::getNames(schema_identifier.getSchemaName(), set_of_names);
128
 
 
129
 
  for (set<std::string>::iterator iter= set_of_names.begin(); iter != set_of_names.end(); iter++)
130
 
  {
131
 
    set_of_identifiers.push_back(identifier::Table(schema_identifier, *iter, drizzled::message::Table::FUNCTION));
132
 
  }
133
 
}
134
 
 
135
 
static int init(drizzled::module::Context &context)
136
 
{
137
 
  context.add(new Function("FunctionEngine"));
138
 
 
139
 
  return 0;
140
 
}
141
 
 
142
 
DRIZZLE_DECLARE_PLUGIN
143
 
{
144
 
  DRIZZLE_VERSION_ID,
145
 
  "FunctionEngine",
146
 
  "1.0",
147
 
  "Brian Aker",
148
 
  "Function Engine provides the infrastructure for Table Functions,etc.",
149
 
  PLUGIN_LICENSE_GPL,
150
 
  init,     /* Plugin Init */
151
 
  NULL,               /* depends */
152
 
  NULL                /* config options   */
153
 
}
154
 
DRIZZLE_DECLARE_PLUGIN_END;