~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/function_engine/function.cc

  • Committer: Stewart Smith
  • Date: 2010-06-16 14:17:58 UTC
  • mto: (1626.1.3 build)
  • mto: This revision was merged to the branch mainline in revision 1633.
  • Revision ID: stewart@flamingspork.com-20100616141758-odpf36m0wo09ok4c
add handler_write status variable test for when statement was rolled back

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2010 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2010 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
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
38
                                  HTON_SKIP_STORE_LOCK |
36
 
                                  HTON_TEMPORARY_NOT_SUPPORTED),
37
 
  information_message(new(message::Schema)),
38
 
  data_dictionary_message(new(message::Schema))
39
 
 
 
39
                                  HTON_TEMPORARY_NOT_SUPPORTED)
40
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
41
}
47
42
 
48
43
 
49
 
Cursor *Function::create(Table &table)
 
44
Cursor *Function::create(TableShare &table, memory::Root *mem_root)
50
45
{
51
 
  return new FunctionCursor(*this, table);
 
46
  return new (mem_root) FunctionCursor(*this, table);
52
47
}
53
48
 
54
49
int Function::doGetTableDefinition(Session &,
55
 
                                   const identifier::Table &identifier,
 
50
                                   TableIdentifier &identifier,
56
51
                                   message::Table &table_proto)
57
52
{
58
 
  drizzled::plugin::TableFunction *function= getFunction(identifier.getPath());
 
53
  string tab_name(identifier.getPath());
 
54
  transform(tab_name.begin(), tab_name.end(),
 
55
            tab_name.begin(), ::tolower);
 
56
 
 
57
  drizzled::plugin::TableFunction *function= getFunction(tab_name);
59
58
 
60
59
  if (not function)
61
60
  {
67
66
  return EEXIST;
68
67
}
69
68
 
70
 
void Function::doGetSchemaIdentifiers(identifier::Schema::vector& schemas)
 
69
 
 
70
void Function::doGetTableNames(drizzled::CachedDirectory&, 
 
71
                               drizzled::SchemaIdentifier &schema_identifier,
 
72
                               set<string> &set_of_names)
 
73
{
 
74
  drizzled::plugin::TableFunction::getNames(schema_identifier.getSchemaName(), set_of_names);
 
75
}
 
76
 
 
77
void Function::doGetSchemaIdentifiers(SchemaIdentifierList& schemas)
71
78
{
72
79
  schemas.push_back(INFORMATION_SCHEMA_IDENTIFIER);
73
80
  schemas.push_back(DATA_DICTIONARY_IDENTIFIER);
74
81
}
75
82
 
76
 
bool Function::doGetSchemaDefinition(const identifier::Schema &schema_identifier, message::schema::shared_ptr &schema_message)
 
83
bool Function::doGetSchemaDefinition(SchemaIdentifier &schema_identifier, message::Schema &schema_message)
77
84
{
78
 
  schema_message.reset(new message::Schema); // This should be fixed, we could just be using ones we built on startup.
79
 
 
80
85
  if (schema_identifier == INFORMATION_SCHEMA_IDENTIFIER)
81
86
  {
82
 
    schema_message= information_message;
 
87
    schema_message.set_name("information_schema");
 
88
    schema_message.set_collation("utf8_general_ci");
83
89
  }
84
90
  else if (schema_identifier == DATA_DICTIONARY_IDENTIFIER)
85
91
  {
86
 
    schema_message= data_dictionary_message;
 
92
    schema_message.set_name("data_dictionary");
 
93
    schema_message.set_collation("utf8_general_ci");
87
94
  }
88
95
  else
89
96
  {
93
100
  return true;
94
101
}
95
102
 
96
 
bool Function::doCanCreateTable(const drizzled::identifier::Table &table_identifier)
 
103
bool Function::doCanCreateTable(drizzled::TableIdentifier &table_identifier)
97
104
{
98
 
  if (static_cast<const identifier::Schema&>(table_identifier) == INFORMATION_SCHEMA_IDENTIFIER)
 
105
  if (static_cast<SchemaIdentifier&>(table_identifier) == INFORMATION_SCHEMA_IDENTIFIER)
99
106
  {
100
107
    return false;
101
108
  }
102
109
 
103
 
  else if (static_cast<const identifier::Schema&>(table_identifier) == DATA_DICTIONARY_IDENTIFIER)
 
110
  else if (static_cast<SchemaIdentifier&>(table_identifier) == DATA_DICTIONARY_IDENTIFIER)
104
111
  {
105
112
    return false;
106
113
  }
108
115
  return true;
109
116
}
110
117
 
111
 
bool Function::doDoesTableExist(Session&, const identifier::Table &identifier)
 
118
bool Function::doDoesTableExist(Session&, TableIdentifier &identifier)
112
119
{
113
120
  drizzled::plugin::TableFunction *function= getFunction(identifier.getPath());
114
121
 
120
127
 
121
128
 
122
129
void Function::doGetTableIdentifiers(drizzled::CachedDirectory&,
123
 
                                     const drizzled::identifier::Schema &schema_identifier,
124
 
                                     drizzled::identifier::Table::vector &set_of_identifiers)
 
130
                                     drizzled::SchemaIdentifier &schema_identifier,
 
131
                                     drizzled::TableIdentifiers &set_of_identifiers)
125
132
{
126
 
  set<std::string> set_of_names;
 
133
  set<string> set_of_names;
127
134
  drizzled::plugin::TableFunction::getNames(schema_identifier.getSchemaName(), set_of_names);
128
135
 
129
 
  for (set<std::string>::iterator iter= set_of_names.begin(); iter != set_of_names.end(); iter++)
 
136
  for (set<string>::iterator iter= set_of_names.begin(); iter != set_of_names.end(); iter++)
130
137
  {
131
 
    set_of_identifiers.push_back(identifier::Table(schema_identifier, *iter, drizzled::message::Table::FUNCTION));
 
138
    set_of_identifiers.push_back(TableIdentifier(schema_identifier, *iter));
132
139
  }
133
140
}
134
141
 
148
155
  "Function Engine provides the infrastructure for Table Functions,etc.",
149
156
  PLUGIN_LICENSE_GPL,
150
157
  init,     /* Plugin Init */
151
 
  NULL,               /* depends */
 
158
  NULL,               /* system variables */
152
159
  NULL                /* config options   */
153
160
}
154
161
DRIZZLE_DECLARE_PLUGIN_END;