1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Brian Aker
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; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include "drizzled/session.h"
24
#include "drizzled/global_charset_info.h"
25
#include "drizzled/charset.h"
27
#include "drizzled/plugin/storage_engine.h"
28
#include "drizzled/plugin/authorization.h"
38
class AddSchemaNames :
39
public unary_function<StorageEngine *, void>
41
SchemaIdentifiers &schemas;
45
AddSchemaNames(SchemaIdentifiers &of_names) :
50
result_type operator() (argument_type engine)
52
engine->doGetSchemaIdentifiers(schemas);
56
void StorageEngine::getIdentifiers(Session &session, SchemaIdentifiers &schemas)
58
// Add hook here for engines to register schema.
59
for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
60
AddSchemaNames(schemas));
62
plugin::Authorization::pruneSchemaNames(session.getSecurityContext(), schemas);
65
class StorageEngineGetSchemaDefinition: public unary_function<StorageEngine *, bool>
67
const SchemaIdentifier &identifier;
68
message::SchemaPtr &schema_proto;
71
StorageEngineGetSchemaDefinition(const SchemaIdentifier &identifier_arg,
72
message::SchemaPtr &schema_proto_arg) :
73
identifier(identifier_arg),
74
schema_proto(schema_proto_arg)
78
result_type operator() (argument_type engine)
80
return engine->doGetSchemaDefinition(identifier, schema_proto);
85
Return value is "if parsed"
87
bool StorageEngine::getSchemaDefinition(const drizzled::TableIdentifier &identifier, message::SchemaPtr &proto)
89
return StorageEngine::getSchemaDefinition(identifier, proto);
92
bool StorageEngine::getSchemaDefinition(const SchemaIdentifier &identifier, message::SchemaPtr &proto)
94
EngineVector::iterator iter=
95
find_if(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
96
StorageEngineGetSchemaDefinition(identifier, proto));
98
if (iter != StorageEngine::getSchemaEngines().end())
106
bool StorageEngine::doesSchemaExist(const SchemaIdentifier &identifier)
108
message::SchemaPtr proto;
110
return StorageEngine::getSchemaDefinition(identifier, proto);
114
const CHARSET_INFO *StorageEngine::getSchemaCollation(const SchemaIdentifier &identifier)
116
message::SchemaPtr schmema_proto;
119
found= StorageEngine::getSchemaDefinition(identifier, schmema_proto);
121
if (found && schmema_proto->has_collation())
123
const string buffer= schmema_proto->collation();
124
const CHARSET_INFO* cs= get_charset_by_name(buffer.c_str());
128
errmsg_printf(ERRMSG_LVL_ERROR,
129
_("Error while loading database options: '%s':"), const_cast<SchemaIdentifier &>(identifier).getSQLPath().c_str());
130
errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_UNKNOWN_COLLATION), buffer.c_str());
132
return default_charset_info;
138
return default_charset_info;
142
public unary_function<StorageEngine *, void>
144
const drizzled::message::Schema &schema_message;
148
CreateSchema(const drizzled::message::Schema &arg) :
153
result_type operator() (argument_type engine)
155
// @todo eomeday check that at least one engine said "true"
156
(void)engine->doCreateSchema(schema_message);
160
bool StorageEngine::createSchema(const drizzled::message::Schema &schema_message)
162
// Add hook here for engines to register schema.
163
for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
164
CreateSchema(schema_message));
170
public unary_function<StorageEngine *, void>
172
uint64_t &success_count;
173
const SchemaIdentifier &identifier;
177
DropSchema(const SchemaIdentifier &arg, uint64_t &count_arg) :
178
success_count(count_arg),
183
result_type operator() (argument_type engine)
185
// @todo someday check that at least one engine said "true"
186
bool success= engine->doDropSchema(identifier);
193
bool StorageEngine::dropSchema(const SchemaIdentifier &identifier)
196
// Add hook here for engines to register schema.
197
for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
198
DropSchema(identifier, counter));
200
return counter ? true : false;
204
public unary_function<StorageEngine *, void>
206
uint64_t &success_count;
207
const drizzled::message::Schema &schema_message;
211
AlterSchema(const drizzled::message::Schema &arg, uint64_t &count_arg) :
212
success_count(count_arg),
217
result_type operator() (argument_type engine)
219
// @todo eomeday check that at least one engine said "true"
220
bool success= engine->doAlterSchema(schema_message);
228
bool StorageEngine::alterSchema(const drizzled::message::Schema &schema_message)
230
uint64_t success_count= 0;
232
for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
233
AlterSchema(schema_message, success_count));
235
return success_count ? true : false;
238
} /* namespace plugin */
239
} /* namespace drizzled */