~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_commands.h

Beginnings of reworking the mysql_execute_command() method. 

Essentially, we want to remove the giant switch statement within that
function. This commit sets the groundwork for that. We added a new base
class named SqlCommand that every command we want to implement inherits
from. It has an execute method that commands can override. Thus, instead of
a large switch statement, we will just have command->execute().

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
#ifndef DRIZZLE_SERVER_SQL_COMMANDS_H
 
22
#define DRIZZLE_SERVER_SQL_COMMANDS_H
 
23
 
 
24
#include <drizzled/server_includes.h>
 
25
#include <drizzled/definitions.h>
 
26
#include <drizzled/logging.h>
 
27
#include <drizzled/db.h>
 
28
#include <drizzled/error.h>
 
29
#include <drizzled/query_id.h>
 
30
#include <drizzled/sql_parse.h>
 
31
#include <drizzled/sql_base.h>
 
32
#include <drizzled/show.h>
 
33
#include <drizzled/rename.h>
 
34
#include <drizzled/function/time/unix_timestamp.h>
 
35
#include <drizzled/function/get_system_var.h>
 
36
#include <drizzled/item/null.h>
 
37
#include <drizzled/sql_load.h>
 
38
#include <drizzled/connect.h>
 
39
#include <drizzled/lock.h>
 
40
 
 
41
class Session;
 
42
class TableList;
 
43
class Item;
 
44
 
 
45
namespace drizzled
 
46
{
 
47
 
 
48
/**
 
49
 * @class SqlCommand
 
50
 * @brief Represents a command to be executed
 
51
 */
 
52
class SqlCommand
 
53
{
 
54
public:
 
55
  SqlCommand(enum enum_sql_command in_comm_type,
 
56
             Session *in_session)
 
57
    :
 
58
      comm_type(in_comm_type),
 
59
      session(in_session),
 
60
      all_tables(NULL),
 
61
      first_table(NULL),
 
62
      show_lock(NULL),
 
63
      need_start_waiting(NULL)
 
64
  {}
 
65
 
 
66
  SqlCommand(enum enum_sql_command in_comm_type,
 
67
             Session *in_session,
 
68
             TableList *in_all_tables)
 
69
    :
 
70
      comm_type(in_comm_type),
 
71
      session(in_session),
 
72
      all_tables(in_all_tables),
 
73
      first_table(NULL),
 
74
      show_lock(NULL),
 
75
      need_start_waiting(NULL)
 
76
  {}
 
77
 
 
78
  virtual ~SqlCommand() {}
 
79
 
 
80
  /**
 
81
   *
 
82
   */
 
83
  virtual int execute();
 
84
 
 
85
  void setTableList(TableList *in_all_tables)
 
86
  {
 
87
    all_tables= in_all_tables;
 
88
  }
 
89
 
 
90
  void setFirstTable(TableList *in_first_table)
 
91
  {
 
92
    first_table= in_first_table;
 
93
  }
 
94
 
 
95
  void setShowLock(pthread_mutex_t *in_lock)
 
96
  {
 
97
    show_lock= in_lock;
 
98
  }
 
99
 
 
100
  void setNeedStartWaiting(bool *in_need_start_waiting)
 
101
  {
 
102
    need_start_waiting= in_need_start_waiting;
 
103
  }
 
104
 
 
105
protected:
 
106
  enum enum_sql_command comm_type;
 
107
  Session *session;
 
108
  TableList *all_tables;
 
109
  TableList *first_table;
 
110
 
 
111
  /**
 
112
   * A mutex that is only needed by the SHOW STATUS
 
113
   * command but declare it in the base class since
 
114
   * we will not know what command we are working with
 
115
   * at runtime.
 
116
   */
 
117
  pthread_mutex_t *show_lock;
 
118
  bool *need_start_waiting;
 
119
};
 
120
 
 
121
/**
 
122
 * @class ShowStatusCommand
 
123
 * @brief Represents the SHOW STATUS command
 
124
 */
 
125
class ShowStatusCommand : public SqlCommand
 
126
{
 
127
public:
 
128
  ShowStatusCommand(enum enum_sql_command in_comm_type,
 
129
                    Session *in_session)
 
130
    :
 
131
      SqlCommand(in_comm_type, in_session)
 
132
  {}
 
133
 
 
134
  int execute();
 
135
};
 
136
 
 
137
} /* end namespace drizzled */
 
138
 
 
139
#endif /* DRIZZLE_SERVER_SQL_COMMANDS_H */