1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems, Inc.
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; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include <drizzled/show.h>
23
#include <drizzled/session.h>
24
#include <drizzled/lock.h>
25
#include <drizzled/statement/drop_table.h>
26
#include "drizzled/sql_table.h"
38
tables List of tables to delete
39
if_exists If 1, don't give error if one table doesn't exists
42
Will delete all tables that can be deleted and give a compact error
43
messages for tables that could not be deleted.
44
If a table is in use, we will wait for all users to free the table
47
Wait if global_read_lock (FLUSH TABLES WITH READ LOCK) is set, but
48
not if under LOCK TABLES.
51
false OK. In this case ok packet is sent to user
56
static bool rm_table(Session *session, TableList *tables, bool if_exists, bool drop_temporary)
58
bool error, need_start_waiting= false;
60
/* mark for close and remove all cached entries */
62
if (not drop_temporary)
64
if (not (need_start_waiting= not session->wait_if_global_read_lock(false, true)))
69
Acquire table::Cache::singleton().mutex() after wait_if_global_read_lock(). If we would hold
70
table::Cache::singleton().mutex() during wait_if_global_read_lock(), other threads could not
71
close their tables. This would make a pretty deadlock.
73
error= rm_table_part2(session, tables, if_exists, drop_temporary);
75
if (need_start_waiting)
77
session->startWaitingGlobalReadLock();
88
bool statement::DropTable::execute()
90
TableList *first_table= (TableList *) getSession()->lex->select_lex.table_list.first;
91
TableList *all_tables= getSession()->lex->query_tables;
92
assert(first_table == all_tables && first_table != 0);
94
if (not drop_temporary)
96
if (getSession()->inTransaction())
98
my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
103
/* DDL and binlog write order protected by table::Cache::singleton().mutex() */
105
return rm_table(getSession(), first_table, drop_if_exists, drop_temporary);
108
} /* namespace drizzled */