22 #include <drizzled/session.h>
23 #include <drizzled/sql_base.h>
24 #include <drizzled/charset.h>
25 #include <drizzled/transaction_services.h>
26 #include <drizzled/open_tables_state.h>
27 #include <drizzled/table/cache.h>
28 #include <drizzled/plugin/storage_engine.h>
29 #include <drizzled/plugin/authorization.h>
35 public std::unary_function<StorageEngine *, void>
37 identifier::schema::vector &schemas;
46 result_type operator() (argument_type engine)
48 engine->doGetSchemaIdentifiers(schemas);
52 void StorageEngine::getIdentifiers(
Session &session, identifier::schema::vector &schemas)
55 std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
64 message::schema::shared_ptr &schema_proto;
68 message::schema::shared_ptr &schema_proto_arg) :
69 identifier(identifier_arg),
70 schema_proto(schema_proto_arg)
74 result_type operator() (argument_type engine)
76 schema_proto= engine->doGetSchemaDefinition(identifier);
87 return StorageEngine::getSchemaDefinition(schema_identifier);
90 message::schema::shared_ptr StorageEngine::getSchemaDefinition(
const identifier::Schema &identifier)
92 message::schema::shared_ptr proto;
94 EngineVector::iterator iter=
95 std::find_if(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
96 StorageEngineGetSchemaDefinition(identifier, proto));
98 if (iter != StorageEngine::getSchemaEngines().end())
103 return message::schema::shared_ptr();
106 bool StorageEngine::doesSchemaExist(
const identifier::Schema &identifier)
108 message::schema::shared_ptr proto;
110 return StorageEngine::getSchemaDefinition(identifier);
114 const charset_info_st *StorageEngine::getSchemaCollation(
const identifier::Schema &identifier)
116 message::schema::shared_ptr schmema_proto= StorageEngine::getSchemaDefinition(identifier);
117 if (not schmema_proto || not schmema_proto->has_collation())
118 return default_charset_info;
119 const std::string buffer= schmema_proto->collation();
120 if (
const charset_info_st* cs= get_charset_by_name(buffer.c_str()))
122 errmsg_printf(error::ERROR, _(
"Error while loading database options: '%s':"), identifier.getSQLPath().c_str());
123 errmsg_printf(error::ERROR, ER(ER_UNKNOWN_COLLATION), buffer.c_str());
124 return default_charset_info;
128 public std::unary_function<StorageEngine *, void>
131 uint64_t &success_count;
137 success_count(success_count_arg)
141 result_type operator() (argument_type engine)
144 bool success= engine->doCreateSchema(schema_message);
149 TransactionServices::allocateNewTransactionId();
157 uint64_t success_count= 0;
158 std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
163 TransactionServices::allocateNewTransactionId();
166 return (
bool)success_count;
170 public std::unary_function<StorageEngine *, void>
172 uint64_t &success_count;
178 success_count(count_arg),
183 result_type operator() (argument_type engine)
186 bool success= engine->doDropSchema(identifier);
191 TransactionServices::allocateNewTransactionId();
196 static bool drop_all_tables_in_schema(
Session& session,
198 identifier::table::vector &dropped_tables,
201 plugin::StorageEngine::getIdentifiers(session, identifier, dropped_tables);
203 for (identifier::table::vector::iterator it= dropped_tables.begin(); it != dropped_tables.end(); it++)
205 boost::mutex::scoped_lock scopedLock(table::Cache::mutex());
207 message::table::shared_ptr message= StorageEngine::getTableMessage(session, *it,
false);
210 my_error(ER_TABLE_DROP, *it);
214 table::Cache::removeTable(session, *it, RTFC_WAIT_OTHER_THREAD_FLAG | RTFC_CHECK_KILLED_FLAG);
215 if (not plugin::StorageEngine::dropTable(session, *it))
217 my_error(ER_TABLE_DROP, *it);
227 bool StorageEngine::dropSchema(Session& session,
228 const identifier::Schema& identifier,
229 message::schema::const_reference schema_message)
233 identifier::table::vector dropped_tables;
241 identifier::table::vector set_of_identifiers;
242 session.open_tables.doGetTableIdentifiers(identifier, set_of_identifiers);
244 for (identifier::table::vector::iterator iter= set_of_identifiers.begin(); iter != set_of_identifiers.end(); iter++)
246 if (session.open_tables.drop_temporary_table(*iter))
248 my_error(ER_TABLE_DROP, *iter);
256 table::Cache::removeSchema(identifier);
258 if (not drop_all_tables_in_schema(session, identifier, dropped_tables, deleted))
261 my_error(ER_DROP_SCHEMA, identifier);
267 std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
268 DropSchema(identifier, counter));
272 my_error(ER_DROP_SCHEMA, identifier);
286 session.clear_error();
287 session.server_status|= SERVER_STATUS_DB_DROPPED;
288 session.my_ok((uint32_t) deleted);
289 session.server_status&= ~SERVER_STATUS_DB_DROPPED;
297 public std::unary_function<StorageEngine *, void>
299 uint64_t &success_count;
305 success_count(count_arg),
310 result_type operator() (argument_type engine)
313 bool success= engine->doAlterSchema(schema_message);
325 uint64_t success_count= 0;
327 std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
332 TransactionServices::allocateNewTransactionId();
335 return success_count ?
true :
false;
static void pruneSchemaNames(const drizzled::identifier::User &user_ctx, identifier::schema::vector &set_of_schemas)
static void dropTable(Session &, const identifier::Table &identifier, message::table::const_reference table, bool if_exists)
static void dropSchema(Session &, const identifier::Schema &identifier, message::schema::const_reference schema)