~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
 *
4
 *  Copyright (C) 2009 Sun Microsystems
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
1241.9.36 by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h.
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>
1241.9.23 by Monty Taylor
Removed sql_table.h from server_includes.h.
26
#include "drizzled/sql_table.h"
1100.3.42 by Padraig O'Sullivan
Extracted the DROP TABLE command into its own class and implementation
27
1130.3.12 by Monty Taylor
using namespace drizzled; to namespace drizzled { in statement/
28
namespace drizzled
29
{
1100.3.42 by Padraig O'Sullivan
Extracted the DROP TABLE command into its own class and implementation
30
1223.4.9 by Brian Aker
Moved mysql_rm to its statement since it is just used there. Also removed
31
32
/*
33
 delete (drop) tables.
34
35
  SYNOPSIS
36
   mysql_rm_table()
37
   session			Thread handle
38
   tables		List of tables to delete
39
   if_exists		If 1, don't give error if one table doesn't exists
40
41
  NOTES
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
45
    before dropping it
46
47
    Wait if global_read_lock (FLUSH TABLES WITH READ LOCK) is set, but
48
    not if under LOCK TABLES.
49
50
  RETURN
51
    false OK.  In this case ok packet is sent to user
52
    true  Error
53
54
*/
55
1223.4.11 by Brian Aker
Modifications to use mysql_rm_table
56
static bool mysql_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
57
{
58
  bool error, need_start_waiting= false;
59
60
  /* mark for close and remove all cached entries */
61
1412 by Brian Aker
Innodb is now in the house (aka... it handls its own DFE).
62
  if (not drop_temporary)
1223.4.9 by Brian Aker
Moved mysql_rm to its statement since it is just used there. Also removed
63
  {
1412 by Brian Aker
Innodb is now in the house (aka... it handls its own DFE).
64
    if (not (need_start_waiting= !wait_if_global_read_lock(session, false, true)))
1223.4.9 by Brian Aker
Moved mysql_rm to its statement since it is just used there. Also removed
65
      return true;
66
  }
67
68
  /*
69
    Acquire LOCK_open after wait_if_global_read_lock(). If we would hold
70
    LOCK_open during wait_if_global_read_lock(), other threads could not
71
    close their tables. This would make a pretty deadlock.
72
  */
73
  error= mysql_rm_table_part2(session, tables, if_exists, drop_temporary);
74
75
  if (need_start_waiting)
76
    start_waiting_global_read_lock(session);
77
78
  if (error)
79
    return true;
80
81
  session->my_ok();
82
83
  return false;
84
}
85
1100.3.42 by Padraig O'Sullivan
Extracted the DROP TABLE command into its own class and implementation
86
bool statement::DropTable::execute()
87
{
88
  TableList *first_table= (TableList *) session->lex->select_lex.table_list.first;
89
  TableList *all_tables= session->lex->query_tables;
90
  assert(first_table == all_tables && first_table != 0);
1412 by Brian Aker
Innodb is now in the house (aka... it handls its own DFE).
91
92
  if (not drop_temporary)
1100.3.42 by Padraig O'Sullivan
Extracted the DROP TABLE command into its own class and implementation
93
  {
1412 by Brian Aker
Innodb is now in the house (aka... it handls its own DFE).
94
    if (not session->endActiveTransaction())
1100.3.42 by Padraig O'Sullivan
Extracted the DROP TABLE command into its own class and implementation
95
    {
96
      return true;
97
    }
98
  }
1412 by Brian Aker
Innodb is now in the house (aka... it handls its own DFE).
99
1100.3.42 by Padraig O'Sullivan
Extracted the DROP TABLE command into its own class and implementation
100
  /* DDL and binlog write order protected by LOCK_open */
1223.4.9 by Brian Aker
Moved mysql_rm to its statement since it is just used there. Also removed
101
  bool res= mysql_rm_table(session,
102
                           first_table,
103
                           drop_if_exists,
1128.2.10 by Brian Aker
A number of changes for LEx -> CreateTable
104
                           drop_temporary);
1100.3.42 by Padraig O'Sullivan
Extracted the DROP TABLE command into its own class and implementation
105
  return res;
106
}
1130.3.12 by Monty Taylor
using namespace drizzled; to namespace drizzled { in statement/
107
108
} /* namespace drizzled */