~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/drop_table.cc

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
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
 
 
28
 
namespace drizzled
29
 
{
30
 
 
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
 
 
56
 
static bool mysql_rm_table(Session *session, TableList *tables, bool if_exists, bool drop_temporary)
57
 
{
58
 
  bool error, need_start_waiting= false;
59
 
 
60
 
  /* mark for close and remove all cached entries */
61
 
 
62
 
  if (not drop_temporary)
63
 
  {
64
 
    if (not (need_start_waiting= !wait_if_global_read_lock(session, false, true)))
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
 
 
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);
91
 
 
92
 
  if (not drop_temporary)
93
 
  {
94
 
    if (not session->endActiveTransaction())
95
 
    {
96
 
      return true;
97
 
    }
98
 
  }
99
 
 
100
 
  /* DDL and binlog write order protected by LOCK_open */
101
 
  bool res= mysql_rm_table(session,
102
 
                           first_table,
103
 
                           drop_if_exists,
104
 
                           drop_temporary);
105
 
  return res;
106
 
}
107
 
 
108
 
} /* namespace drizzled */