drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
drop_table.cc
1/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2009 Sun Microsystems, Inc.
5 *
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.
10 *
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.
15 *
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
19 */
20
21#include <config.h>
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>
27#include <drizzled/sql_lex.h>
28
29namespace drizzled
30{
31
32
33/*
34 delete (drop) tables.
35
36 SYNOPSIS
37 rm_table()
38 session Thread handle
39 tables List of tables to delete
40 if_exists If 1, don't give error if one table doesn't exists
41
42 NOTES
43 Will delete all tables that can be deleted and give a compact error
44 messages for tables that could not be deleted.
45 If a table is in use, we will wait for all users to free the table
46 before dropping it
47
48 Wait if global_read_lock (FLUSH TABLES WITH READ LOCK) is set, but
49 not if under LOCK TABLES.
50
51 RETURN
52 false OK. In this case ok packet is sent to user
53 true Error
54
55*/
56
57static bool rm_table(Session *session, TableList *tables, bool if_exists, bool drop_temporary)
58{
59 bool need_start_waiting= false;
60
61 /* mark for close and remove all cached entries */
62
63 if (not drop_temporary)
64 {
65 if (not (need_start_waiting= not session->wait_if_global_read_lock(false, true)))
66 return true;
67 }
68
69 /*
70 Acquire table::Cache::mutex() after wait_if_global_read_lock(). If we would hold
71 table::Cache::mutex() during wait_if_global_read_lock(), other threads could not
72 close their tables. This would make a pretty deadlock.
73 */
74 bool error= rm_table_part2(session, tables, if_exists, drop_temporary);
75
76 if (need_start_waiting)
77 {
78 session->startWaitingGlobalReadLock();
79 }
80
81 if (error)
82 return true;
83
84 session->my_ok();
85
86 return false;
87}
88
90{
91 TableList *first_table= (TableList *) lex().select_lex.table_list.first;
92 TableList *all_tables= lex().query_tables;
93 assert(first_table == all_tables && first_table != 0);
94
95 if (not drop_temporary)
96 {
97 if (session().inTransaction())
98 {
99 my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
100 return true;
101 }
102 }
103
104 return rm_table(&session(), first_table, drop_if_exists, drop_temporary);
105}
106
107} /* namespace drizzled */
Select_Lex * select_lex
Definition table_list.h:208
TODO: Rename this file - func.h is stupid.