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
SchemaIdentifierList &schemas;
45
AddSchemaNames(SchemaIdentifierList &of_names) :
50
result_type operator() (argument_type engine)
52
engine->doGetSchemaIdentifiers(schemas);
56
void StorageEngine::getSchemaIdentifiers(Session &session, SchemaIdentifierList &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
SchemaIdentifier &identifier;
68
message::Schema &schema_proto;
71
StorageEngineGetSchemaDefinition(SchemaIdentifier &identifier_arg,
72
message::Schema &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(TableIdentifier &identifier, message::Schema &proto)
89
return StorageEngine::getSchemaDefinition(identifier, proto);
92
bool StorageEngine::getSchemaDefinition(SchemaIdentifier &identifier, message::Schema &proto)
96
EngineVector::iterator iter=
97
find_if(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
98
StorageEngineGetSchemaDefinition(identifier, proto));
100
if (iter != StorageEngine::getSchemaEngines().end())
108
bool StorageEngine::doesSchemaExist(SchemaIdentifier &identifier)
110
message::Schema proto;
112
return StorageEngine::getSchemaDefinition(identifier, proto);
116
const CHARSET_INFO *StorageEngine::getSchemaCollation(SchemaIdentifier &identifier)
118
message::Schema schmema_proto;
121
found= StorageEngine::getSchemaDefinition(identifier, schmema_proto);
123
if (found && schmema_proto.has_collation())
125
const string buffer= schmema_proto.collation();
126
const CHARSET_INFO* cs= get_charset_by_name(buffer.c_str());
130
errmsg_printf(ERRMSG_LVL_ERROR,
131
_("Error while loading database options: '%s':"), identifier.getSQLPath().c_str());
132
errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_UNKNOWN_COLLATION), buffer.c_str());
134
return default_charset_info;
140
return default_charset_info;
144
public unary_function<StorageEngine *, void>
146
const drizzled::message::Schema &schema_message;
150
CreateSchema(const drizzled::message::Schema &arg) :
155
result_type operator() (argument_type engine)
157
// @todo eomeday check that at least one engine said "true"
158
(void)engine->doCreateSchema(schema_message);
162
bool StorageEngine::createSchema(const drizzled::message::Schema &schema_message)
164
// Add hook here for engines to register schema.
165
for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
166
CreateSchema(schema_message));
172
public unary_function<StorageEngine *, void>
174
uint64_t &success_count;
175
SchemaIdentifier &identifier;
179
DropSchema(SchemaIdentifier &arg, uint64_t &count_arg) :
180
success_count(count_arg),
185
result_type operator() (argument_type engine)
187
// @todo someday check that at least one engine said "true"
188
bool success= engine->doDropSchema(identifier);
195
bool StorageEngine::dropSchema(SchemaIdentifier &identifier)
198
// Add hook here for engines to register schema.
199
for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
200
DropSchema(identifier, counter));
202
return counter ? true : false;
206
public unary_function<StorageEngine *, void>
208
uint64_t &success_count;
209
const drizzled::message::Schema &schema_message;
213
AlterSchema(const drizzled::message::Schema &arg, uint64_t &count_arg) :
214
success_count(count_arg),
219
result_type operator() (argument_type engine)
221
// @todo eomeday check that at least one engine said "true"
222
bool success= engine->doAlterSchema(schema_message);
229
bool StorageEngine::alterSchema(const drizzled::message::Schema &schema_message)
231
uint64_t success_count= 0;
233
for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
234
AlterSchema(schema_message, success_count));
236
return success_count ? true : false;
239
} /* namespace plugin */
240
} /* namespace drizzled */