~drizzle-trunk/drizzle/development

1100.3.42 by Padraig O'Sullivan
Extracted the DROP TABLE command into its own class and implementation
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2009 Sun Microsystems, Inc.
1100.3.42 by Padraig O'Sullivan
Extracted the DROP TABLE command into its own class and implementation
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
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
21
#include <config.h>
1100.3.42 by Padraig O'Sullivan
Extracted the DROP TABLE command into its own class and implementation
22
#include <drizzled/show.h>
23
#include <drizzled/session.h>
1223.4.9 by Brian Aker
Moved mysql_rm to its statement since it is just used there. Also removed
24
#include <drizzled/lock.h>
1100.3.42 by Padraig O'Sullivan
Extracted the DROP TABLE command into its own class and implementation
25
#include <drizzled/statement/drop_table.h>
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
26
#include <drizzled/sql_table.h>
2234.1.4 by Olaf van der Spek
Refactor includes
27
#include <drizzled/sql_lex.h>
1100.3.42 by Padraig O'Sullivan
Extracted the DROP TABLE command into its own class and implementation
28
1130.3.12 by Monty Taylor
using namespace drizzled; to namespace drizzled { in statement/
29
namespace drizzled
30
{
1100.3.42 by Padraig O'Sullivan
Extracted the DROP TABLE command into its own class and implementation
31
1223.4.9 by Brian Aker
Moved mysql_rm to its statement since it is just used there. Also removed
32
33
/*
34
 delete (drop) tables.
35
36
  SYNOPSIS
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
37
   rm_table()
1223.4.9 by Brian Aker
Moved mysql_rm to its statement since it is just used there. Also removed
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
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
57
static bool rm_table(Session *session, TableList *tables, bool if_exists, bool drop_temporary)
1223.4.9 by Brian Aker
Moved mysql_rm to its statement since it is just used there. Also removed
58
{
2318.8.6 by Olaf van der Spek
Add const
59
  bool need_start_waiting= false;
1223.4.9 by Brian Aker
Moved mysql_rm to its statement since it is just used there. Also removed
60
61
  /* mark for close and remove all cached entries */
62
1412 by Brian Aker
Innodb is now in the house (aka... it handls its own DFE).
63
  if (not drop_temporary)
1223.4.9 by Brian Aker
Moved mysql_rm to its statement since it is just used there. Also removed
64
  {
1910.2.3 by Brian Aker
Second pass on move code to global lock encapsulation.
65
    if (not (need_start_waiting= not session->wait_if_global_read_lock(false, true)))
1223.4.9 by Brian Aker
Moved mysql_rm to its statement since it is just used there. Also removed
66
      return true;
67
  }
68
69
  /*
2275.3.1 by Olaf van der Spek
Remove table::Cache::singleton()
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
1223.4.9 by Brian Aker
Moved mysql_rm to its statement since it is just used there. Also removed
72
    close their tables. This would make a pretty deadlock.
73
  */
2318.8.6 by Olaf van der Spek
Add const
74
  bool error= rm_table_part2(session, tables, if_exists, drop_temporary);
1223.4.9 by Brian Aker
Moved mysql_rm to its statement since it is just used there. Also removed
75
76
  if (need_start_waiting)
1910.2.2 by Brian Aker
First pass through the global lock refactor merge.
77
  {
78
    session->startWaitingGlobalReadLock();
79
  }
1223.4.9 by Brian Aker
Moved mysql_rm to its statement since it is just used there. Also removed
80
81
  if (error)
82
    return true;
83
84
  session->my_ok();
85
86
  return false;
87
}
88
1100.3.42 by Padraig O'Sullivan
Extracted the DROP TABLE command into its own class and implementation
89
bool statement::DropTable::execute()
90
{
2224.2.8 by Olaf van der Spek
Statement::lex()
91
  TableList *first_table= (TableList *) lex().select_lex.table_list.first;
92
  TableList *all_tables= lex().query_tables;
1100.3.42 by Padraig O'Sullivan
Extracted the DROP TABLE command into its own class and implementation
93
  assert(first_table == all_tables && first_table != 0);
1412 by Brian Aker
Innodb is now in the house (aka... it handls its own DFE).
94
95
  if (not drop_temporary)
1100.3.42 by Padraig O'Sullivan
Extracted the DROP TABLE command into its own class and implementation
96
  {
2227.4.1 by Olaf van der Spek
Statement::session()
97
    if (session().inTransaction())
1100.3.42 by Padraig O'Sullivan
Extracted the DROP TABLE command into its own class and implementation
98
    {
1890.2.13 by Stewart Smith
error out with ER_TRANSACTIONAL_DDL_NOT_SUPPORTED in DROP TABLE if there is an ongoing transaction.
99
      my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
1100.3.42 by Padraig O'Sullivan
Extracted the DROP TABLE command into its own class and implementation
100
      return true;
101
    }
102
  }
1412 by Brian Aker
Innodb is now in the house (aka... it handls its own DFE).
103
2275.3.1 by Olaf van der Spek
Remove table::Cache::singleton()
104
  /* DDL and binlog write order protected by table::Cache::mutex() */
2041.3.5 by Brian Aker
Make it so that tables are sent not as raw but actual drop table commands to
105
2227.4.2 by Olaf van der Spek
Statement::session()
106
  return rm_table(&session(), first_table, drop_if_exists, drop_temporary);
1100.3.42 by Padraig O'Sullivan
Extracted the DROP TABLE command into its own class and implementation
107
}
1130.3.12 by Monty Taylor
using namespace drizzled; to namespace drizzled { in statement/
108
109
} /* namespace drizzled */