1 /* Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
2 
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License, version 2.0,
5    as published by the Free Software Foundation.
6 
7    This program is also distributed with certain software (including
8    but not limited to OpenSSL) that is licensed under separate terms,
9    as designated in a particular file or component or in included license
10    documentation.  The authors of MySQL hereby grant you an additional
11    permission to link the program and your derivative works with the
12    separately licensed software that they have included with MySQL.
13 
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License, version 2.0, for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
22 
23 #ifndef SQL_HANDLER_INCLUDED
24 #define SQL_HANDLER_INCLUDED
25 
26 #include "sql_class.h"                 /* enum_ha_read_mode */
27 #include "my_base.h"                   /* ha_rkey_function, ha_rows */
28 #include "sql_list.h"                  /* List */
29 
30 class THD;
31 struct TABLE_LIST;
32 
33 /**
34   Sql_cmd_handler_open represents HANDLER OPEN statement.
35 
36   @note Some information about this statement, for example, table to be
37         opened is still kept in LEX class.
38 */
39 
40 class Sql_cmd_handler_open : public Sql_cmd
41 {
42 public:
Sql_cmd_handler_open()43   Sql_cmd_handler_open()
44   {}
45 
~Sql_cmd_handler_open()46   virtual ~Sql_cmd_handler_open()
47   {}
48 
sql_command_code()49   virtual enum_sql_command sql_command_code() const
50   {
51     return SQLCOM_HA_OPEN;
52   }
53 
54   virtual bool execute(THD *thd);
55 };
56 
57 
58 /**
59   Sql_cmd_handler_read represents HANDLER READ statement.
60 
61   @note Some information about this statement, for example, table
62         list element which identifies HANDLER to be read from,
63         WHERE and LIMIT clauses is still kept in LEX class.
64 */
65 
66 class Sql_cmd_handler_read : public Sql_cmd
67 {
68 public:
Sql_cmd_handler_read(enum_ha_read_modes read_mode,const char * key_name,List<Item> * key_expr,ha_rkey_function rkey_mode)69   Sql_cmd_handler_read(enum_ha_read_modes read_mode,
70                        const char *key_name,
71                        List<Item> *key_expr,
72                        ha_rkey_function rkey_mode)
73     : m_read_mode(read_mode), m_key_name(key_name), m_key_expr(key_expr),
74       m_rkey_mode(rkey_mode)
75   {}
76 
~Sql_cmd_handler_read()77   virtual ~Sql_cmd_handler_read()
78   {}
79 
sql_command_code()80   virtual enum_sql_command sql_command_code() const
81   {
82     return SQLCOM_HA_READ;
83   }
84 
85   virtual bool execute(THD *thd);
86 
87 private:
88   /** Read mode for HANDLER READ: FIRST, NEXT, LAST, ... */
89   enum enum_ha_read_modes m_read_mode;
90 
91   /**
92     Name of key to be used for reading,
93     NULL in cases when natural row-order is to be used.
94   */
95   const char *m_key_name;
96 
97   /** Key values to be satisfied. */
98   List<Item> *m_key_expr;
99 
100   /** Type of condition for key values to be satisfied. */
101   enum ha_rkey_function m_rkey_mode;
102 };
103 
104 
105 /**
106   Sql_cmd_handler_close represents HANDLER CLOSE statement.
107 
108   @note Table list element which identifies HANDLER to be closed
109         still resides in LEX class.
110 */
111 
112 class Sql_cmd_handler_close : public Sql_cmd
113 {
114 public:
Sql_cmd_handler_close()115   Sql_cmd_handler_close()
116   {}
117 
~Sql_cmd_handler_close()118   virtual ~Sql_cmd_handler_close()
119   {}
120 
sql_command_code()121   virtual enum_sql_command sql_command_code() const
122   {
123     return SQLCOM_HA_CLOSE;
124   }
125 
126   virtual bool execute(THD *thd);
127 };
128 
129 
130 void mysql_ha_flush(THD *thd);
131 void mysql_ha_flush_tables(THD *thd, TABLE_LIST *all_tables);
132 void mysql_ha_rm_tables(THD *thd, TABLE_LIST *tables);
133 void mysql_ha_rm_temporary_tables(THD *thd);
134 void mysql_ha_cleanup(THD *thd);
135 void mysql_ha_set_explicit_lock_duration(THD *thd);
136 
137 typedef bool Log_func(THD*, TABLE*, bool,
138                       const uchar*, const uchar*);
139 
140 int  binlog_log_row(TABLE* table,
141                           const uchar *before_record,
142                           const uchar *after_record,
143                           Log_func *log_func);
144 
145 #endif /* SQL_HANDLER_INCLUDED */
146