~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/drop_table.cc

  • Committer: Andy Lester
  • Date: 2008-08-10 02:15:48 UTC
  • mto: (266.1.31 use-replace-funcs)
  • mto: This revision was merged to the branch mainline in revision 295.
  • Revision ID: andy@petdance.com-20080810021548-0zx8nhzva6al10k3
Added a proper const qualifer.

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, 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
 
 
28
 
namespace drizzled
29
 
{
30
 
 
31
 
 
32
 
/*
33
 
 delete (drop) tables.
34
 
 
35
 
  SYNOPSIS
36
 
   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 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= not session->wait_if_global_read_lock(false, true)))
65
 
      return true;
66
 
  }
67
 
 
68
 
  /*
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.
72
 
  */
73
 
  error= rm_table_part2(session, tables, if_exists, drop_temporary);
74
 
 
75
 
  if (need_start_waiting)
76
 
  {
77
 
    session->startWaitingGlobalReadLock();
78
 
  }
79
 
 
80
 
  if (error)
81
 
    return true;
82
 
 
83
 
  session->my_ok();
84
 
 
85
 
  return false;
86
 
}
87
 
 
88
 
bool statement::DropTable::execute()
89
 
{
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);
93
 
 
94
 
  if (not drop_temporary)
95
 
  {
96
 
    if (getSession()->inTransaction())
97
 
    {
98
 
      my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
99
 
      return true;
100
 
    }
101
 
  }
102
 
 
103
 
  /* DDL and binlog write order protected by table::Cache::singleton().mutex() */
104
 
 
105
 
  return rm_table(getSession(), first_table, drop_if_exists, drop_temporary);
106
 
}
107
 
 
108
 
} /* namespace drizzled */