55
void StorageEngine::getIdentifiers(Session &session, identifier::Schema::vector &schemas)
56
void StorageEngine::getIdentifiers(Session &session, SchemaIdentifiers &schemas)
57
58
// Add hook here for engines to register schema.
58
std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
59
for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
59
60
AddSchemaNames(schemas));
61
plugin::Authorization::pruneSchemaNames(session.user(), schemas);
62
plugin::Authorization::pruneSchemaNames(session.getSecurityContext(), schemas);
64
class StorageEngineGetSchemaDefinition: public std::unary_function<StorageEngine *, bool>
65
class StorageEngineGetSchemaDefinition: public unary_function<StorageEngine *, bool>
66
const identifier::Schema &identifier;
67
message::schema::shared_ptr &schema_proto;
67
const SchemaIdentifier &identifier;
68
message::Schema &schema_proto;
70
StorageEngineGetSchemaDefinition(const identifier::Schema &identifier_arg,
71
message::schema::shared_ptr &schema_proto_arg) :
71
StorageEngineGetSchemaDefinition(const SchemaIdentifier &identifier_arg,
72
message::Schema &schema_proto_arg) :
72
73
identifier(identifier_arg),
73
74
schema_proto(schema_proto_arg)
84
85
Return value is "if parsed"
86
bool StorageEngine::getSchemaDefinition(const drizzled::identifier::Table &identifier, message::schema::shared_ptr &proto)
87
bool StorageEngine::getSchemaDefinition(const drizzled::TableIdentifier &identifier, message::Schema &proto)
88
89
return StorageEngine::getSchemaDefinition(identifier, proto);
91
bool StorageEngine::getSchemaDefinition(const identifier::Schema &identifier, message::schema::shared_ptr &proto)
92
bool StorageEngine::getSchemaDefinition(const SchemaIdentifier &identifier, message::Schema &proto)
93
96
EngineVector::iterator iter=
94
std::find_if(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
95
StorageEngineGetSchemaDefinition(identifier, proto));
97
find_if(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
98
StorageEngineGetSchemaDefinition(identifier, proto));
97
100
if (iter != StorageEngine::getSchemaEngines().end())
105
bool StorageEngine::doesSchemaExist(const identifier::Schema &identifier)
108
bool StorageEngine::doesSchemaExist(const SchemaIdentifier &identifier)
107
message::schema::shared_ptr proto;
110
message::Schema proto;
109
112
return StorageEngine::getSchemaDefinition(identifier, proto);
113
const CHARSET_INFO *StorageEngine::getSchemaCollation(const identifier::Schema &identifier)
116
const CHARSET_INFO *StorageEngine::getSchemaCollation(const SchemaIdentifier &identifier)
115
message::schema::shared_ptr schmema_proto;
118
message::Schema schmema_proto;
118
121
found= StorageEngine::getSchemaDefinition(identifier, schmema_proto);
120
if (found && schmema_proto->has_collation())
123
if (found && schmema_proto.has_collation())
122
const std::string buffer= schmema_proto->collation();
125
const string buffer= schmema_proto.collation();
123
126
const CHARSET_INFO* cs= get_charset_by_name(buffer.c_str());
128
identifier.getSQLPath(path);
130
errmsg_printf(error::ERROR,
131
_("Error while loading database options: '%s':"), path.c_str());
132
errmsg_printf(error::ERROR, ER(ER_UNKNOWN_COLLATION), buffer.c_str());
130
errmsg_printf(ERRMSG_LVL_ERROR,
131
_("Error while loading database options: '%s':"), const_cast<SchemaIdentifier &>(identifier).getSQLPath().c_str());
132
errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_UNKNOWN_COLLATION), buffer.c_str());
134
134
return default_charset_info;
143
143
class CreateSchema :
144
public std::unary_function<StorageEngine *, void>
144
public unary_function<StorageEngine *, void>
146
146
const drizzled::message::Schema &schema_message;
147
uint64_t &success_count;
151
CreateSchema(const drizzled::message::Schema &arg, uint64_t &success_count_arg) :
153
success_count(success_count_arg)
150
CreateSchema(const drizzled::message::Schema &arg) :
157
155
result_type operator() (argument_type engine)
159
157
// @todo eomeday check that at least one engine said "true"
160
bool success= engine->doCreateSchema(schema_message);
165
TransactionServices &transaction_services= TransactionServices::singleton();
166
transaction_services.allocateNewTransactionId();
158
(void)engine->doCreateSchema(schema_message);
171
162
bool StorageEngine::createSchema(const drizzled::message::Schema &schema_message)
173
164
// Add hook here for engines to register schema.
174
uint64_t success_count= 0;
175
std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
176
CreateSchema(schema_message, success_count));
180
TransactionServices &transaction_services= TransactionServices::singleton();
181
transaction_services.allocateNewTransactionId();
184
return (bool)success_count;
165
for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
166
CreateSchema(schema_message));
187
171
class DropSchema :
188
public std::unary_function<StorageEngine *, void>
172
public unary_function<StorageEngine *, void>
190
174
uint64_t &success_count;
191
const identifier::Schema &identifier;
175
const SchemaIdentifier &identifier;
195
DropSchema(const identifier::Schema &arg, uint64_t &count_arg) :
179
DropSchema(const SchemaIdentifier &arg, uint64_t &count_arg) :
196
180
success_count(count_arg),
204
188
bool success= engine->doDropSchema(identifier);
209
TransactionServices &transaction_services= TransactionServices::singleton();
210
transaction_services.allocateNewTransactionId();
215
static bool drop_all_tables_in_schema(Session& session,
216
identifier::Schema::const_reference identifier,
217
identifier::Table::vector &dropped_tables,
220
TransactionServices &transaction_services= TransactionServices::singleton();
222
plugin::StorageEngine::getIdentifiers(session, identifier, dropped_tables);
224
for (identifier::Table::vector::iterator it= dropped_tables.begin();
225
it != dropped_tables.end();
228
boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex());
229
table::Cache::singleton().removeTable(&session, *it,
230
RTFC_WAIT_OTHER_THREAD_FLAG |
231
RTFC_CHECK_KILLED_FLAG);
232
if (not plugin::StorageEngine::dropTable(session, *it))
234
my_error(ER_TABLE_DROP, *it);
237
transaction_services.dropTable(session, *it, true);
244
bool StorageEngine::dropSchema(Session::reference session, identifier::Schema::const_reference identifier)
248
identifier::Table::vector dropped_tables;
249
message::Schema schema_proto;
253
// Remove all temp tables first, this prevents loss of table from
254
// shadowing (ie temp over standard table)
256
// Lets delete the temporary tables first outside of locks.
257
identifier::Table::vector set_of_identifiers;
258
session.doGetTableIdentifiers(identifier, set_of_identifiers);
260
for (identifier::Table::vector::iterator iter= set_of_identifiers.begin(); iter != set_of_identifiers.end(); iter++)
262
if (session.drop_temporary_table(*iter))
264
my_error(ER_TABLE_DROP, *iter);
271
/* After deleting database, remove all cache entries related to schema */
272
table::Cache::singleton().removeSchema(identifier);
274
if (not drop_all_tables_in_schema(session, identifier, dropped_tables, deleted))
277
my_error(ER_DROP_SCHEMA, identifier);
282
// Add hook here for engines to register schema.
283
std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
284
DropSchema(identifier, counter));
288
my_error(ER_DROP_SCHEMA, identifier);
295
/* We've already verified that the schema does exist, so safe to log it */
296
TransactionServices &transaction_services= TransactionServices::singleton();
297
transaction_services.dropSchema(session, identifier);
303
session.clear_error();
304
session.server_status|= SERVER_STATUS_DB_DROPPED;
305
session.my_ok((uint32_t) deleted);
306
session.server_status&= ~SERVER_STATUS_DB_DROPPED;
195
bool StorageEngine::dropSchema(const 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;
313
205
class AlterSchema :
314
public std::unary_function<StorageEngine *, void>
206
public unary_function<StorageEngine *, void>
316
208
uint64_t &success_count;
317
209
const drizzled::message::Schema &schema_message;
342
232
uint64_t success_count= 0;
344
std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
345
AlterSchema(schema_message, success_count));
349
TransactionServices &transaction_services= TransactionServices::singleton();
350
transaction_services.allocateNewTransactionId();
234
for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
235
AlterSchema(schema_message, success_count));
353
237
return success_count ? true : false;