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"
26
#include "drizzled/transaction_services.h"
28
#include "drizzled/plugin/storage_engine.h"
29
#include "drizzled/plugin/authorization.h"
37
class AddSchemaNames :
38
public std::unary_function<StorageEngine *, void>
40
SchemaIdentifier::vector &schemas;
44
AddSchemaNames(SchemaIdentifier::vector &of_names) :
49
result_type operator() (argument_type engine)
51
engine->doGetSchemaIdentifiers(schemas);
55
void StorageEngine::getIdentifiers(Session &session, SchemaIdentifier::vector &schemas)
57
// Add hook here for engines to register schema.
58
std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
59
AddSchemaNames(schemas));
61
plugin::Authorization::pruneSchemaNames(session.getSecurityContext(), schemas);
64
class StorageEngineGetSchemaDefinition: public std::unary_function<StorageEngine *, bool>
66
const SchemaIdentifier &identifier;
67
message::schema::shared_ptr &schema_proto;
70
StorageEngineGetSchemaDefinition(const SchemaIdentifier &identifier_arg,
71
message::schema::shared_ptr &schema_proto_arg) :
72
identifier(identifier_arg),
73
schema_proto(schema_proto_arg)
77
result_type operator() (argument_type engine)
79
return engine->doGetSchemaDefinition(identifier, schema_proto);
84
Return value is "if parsed"
86
bool StorageEngine::getSchemaDefinition(const drizzled::TableIdentifier &identifier, message::schema::shared_ptr &proto)
88
return StorageEngine::getSchemaDefinition(identifier, proto);
91
bool StorageEngine::getSchemaDefinition(const SchemaIdentifier &identifier, message::schema::shared_ptr &proto)
93
EngineVector::iterator iter=
94
std::find_if(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
95
StorageEngineGetSchemaDefinition(identifier, proto));
97
if (iter != StorageEngine::getSchemaEngines().end())
105
bool StorageEngine::doesSchemaExist(const SchemaIdentifier &identifier)
107
message::schema::shared_ptr proto;
109
return StorageEngine::getSchemaDefinition(identifier, proto);
113
const CHARSET_INFO *StorageEngine::getSchemaCollation(const SchemaIdentifier &identifier)
115
message::schema::shared_ptr schmema_proto;
118
found= StorageEngine::getSchemaDefinition(identifier, schmema_proto);
120
if (found && schmema_proto->has_collation())
122
const std::string buffer= schmema_proto->collation();
123
const CHARSET_INFO* cs= get_charset_by_name(buffer.c_str());
128
identifier.getSQLPath(path);
130
errmsg_printf(ERRMSG_LVL_ERROR,
131
_("Error while loading database options: '%s':"), path.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 std::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
bool success= engine->doCreateSchema(schema_message);
162
TransactionServices &transaction_services= TransactionServices::singleton();
163
transaction_services.allocateNewTransactionId();
168
bool StorageEngine::createSchema(const drizzled::message::Schema &schema_message)
170
// Add hook here for engines to register schema.
171
std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
172
CreateSchema(schema_message));
178
public std::unary_function<StorageEngine *, void>
180
uint64_t &success_count;
181
const SchemaIdentifier &identifier;
185
DropSchema(const SchemaIdentifier &arg, uint64_t &count_arg) :
186
success_count(count_arg),
191
result_type operator() (argument_type engine)
193
// @todo someday check that at least one engine said "true"
194
bool success= engine->doDropSchema(identifier);
199
TransactionServices &transaction_services= TransactionServices::singleton();
200
transaction_services.allocateNewTransactionId();
205
bool StorageEngine::dropSchema(const SchemaIdentifier &identifier)
208
// Add hook here for engines to register schema.
209
std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
210
DropSchema(identifier, counter));
212
return counter ? true : false;
216
public std::unary_function<StorageEngine *, void>
218
uint64_t &success_count;
219
const drizzled::message::Schema &schema_message;
223
AlterSchema(const drizzled::message::Schema &arg, uint64_t &count_arg) :
224
success_count(count_arg),
229
result_type operator() (argument_type engine)
231
// @todo eomeday check that at least one engine said "true"
232
bool success= engine->doAlterSchema(schema_message);
238
TransactionServices &transaction_services= TransactionServices::singleton();
239
transaction_services.allocateNewTransactionId();
244
bool StorageEngine::alterSchema(const drizzled::message::Schema &schema_message)
246
uint64_t success_count= 0;
248
std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
249
AlterSchema(schema_message, success_count));
251
return success_count ? true : false;
254
} /* namespace plugin */
255
} /* namespace drizzled */