17
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>
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"
58
58
std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
59
59
AddSchemaNames(schemas));
61
plugin::Authorization::pruneSchemaNames(*session.user(), schemas);
61
plugin::Authorization::pruneSchemaNames(session.user(), schemas);
64
64
class StorageEngineGetSchemaDefinition: public std::unary_function<StorageEngine *, bool>
77
77
result_type operator() (argument_type engine)
79
schema_proto= engine->doGetSchemaDefinition(identifier);
79
return engine->doGetSchemaDefinition(identifier, schema_proto);
85
84
Return value is "if parsed"
87
message::schema::shared_ptr StorageEngine::getSchemaDefinition(const drizzled::identifier::Table &identifier)
86
bool StorageEngine::getSchemaDefinition(const drizzled::identifier::Table &identifier, message::schema::shared_ptr &proto)
89
return StorageEngine::getSchemaDefinition(identifier);
88
return StorageEngine::getSchemaDefinition(identifier, proto);
92
message::schema::shared_ptr StorageEngine::getSchemaDefinition(const identifier::Schema &identifier)
91
bool StorageEngine::getSchemaDefinition(const identifier::Schema &identifier, message::schema::shared_ptr &proto)
94
message::schema::shared_ptr proto;
96
93
EngineVector::iterator iter=
97
94
std::find_if(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
98
95
StorageEngineGetSchemaDefinition(identifier, proto));
100
97
if (iter != StorageEngine::getSchemaEngines().end())
105
return message::schema::shared_ptr();
108
105
bool StorageEngine::doesSchemaExist(const identifier::Schema &identifier)
110
107
message::schema::shared_ptr proto;
112
return StorageEngine::getSchemaDefinition(identifier);
109
return StorageEngine::getSchemaDefinition(identifier, proto);
116
113
const CHARSET_INFO *StorageEngine::getSchemaCollation(const identifier::Schema &identifier)
118
115
message::schema::shared_ptr schmema_proto;
120
schmema_proto= StorageEngine::getSchemaDefinition(identifier);
122
if (schmema_proto && schmema_proto->has_collation())
118
found= StorageEngine::getSchemaDefinition(identifier, schmema_proto);
120
if (found && schmema_proto->has_collation())
124
122
const std::string buffer= schmema_proto->collation();
125
123
const CHARSET_INFO* cs= get_charset_by_name(buffer.c_str());
129
127
std::string path;
130
128
identifier.getSQLPath(path);
132
errmsg_printf(error::ERROR,
130
errmsg_printf(ERRMSG_LVL_ERROR,
133
131
_("Error while loading database options: '%s':"), path.c_str());
134
errmsg_printf(error::ERROR, ER(ER_UNKNOWN_COLLATION), buffer.c_str());
132
errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_UNKNOWN_COLLATION), buffer.c_str());
136
134
return default_charset_info;
146
144
public std::unary_function<StorageEngine *, void>
148
146
const drizzled::message::Schema &schema_message;
149
uint64_t &success_count;
153
CreateSchema(const drizzled::message::Schema &arg, uint64_t &success_count_arg) :
155
success_count(success_count_arg)
150
CreateSchema(const drizzled::message::Schema &arg) :
173
168
bool StorageEngine::createSchema(const drizzled::message::Schema &schema_message)
175
170
// Add hook here for engines to register schema.
176
uint64_t success_count= 0;
177
171
std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
178
CreateSchema(schema_message, success_count));
182
TransactionServices &transaction_services= TransactionServices::singleton();
183
transaction_services.allocateNewTransactionId();
186
return (bool)success_count;
172
CreateSchema(schema_message));
189
177
class DropSchema :
230
218
boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex());
232
message::table::shared_ptr message= StorageEngine::getTableMessage(session, *it, false);
235
my_error(ER_TABLE_DROP, *it);
239
219
table::Cache::singleton().removeTable(&session, *it,
240
220
RTFC_WAIT_OTHER_THREAD_FLAG |
241
221
RTFC_CHECK_KILLED_FLAG);
244
224
my_error(ER_TABLE_DROP, *it);
247
transaction_services.dropTable(session, *it, *message, true);
227
transaction_services.dropTable(&session, *it, true);
254
bool StorageEngine::dropSchema(Session::reference session,
255
identifier::Schema::const_reference identifier,
256
message::schema::const_reference schema_message)
234
bool StorageEngine::dropSchema(Session::reference session, identifier::Schema::const_reference identifier)
258
236
uint64_t deleted= 0;
259
237
bool error= false;
260
238
identifier::Table::vector dropped_tables;
239
message::Schema schema_proto;
306
285
/* We've already verified that the schema does exist, so safe to log it */
307
286
TransactionServices &transaction_services= TransactionServices::singleton();
308
transaction_services.dropSchema(session, identifier, schema_message);
287
transaction_services.dropSchema(&session, identifier);
355
336
std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
356
337
AlterSchema(schema_message, success_count));
360
TransactionServices &transaction_services= TransactionServices::singleton();
361
transaction_services.allocateNewTransactionId();
364
339
return success_count ? true : false;