1 /* Copyright (c) 2008, 2010, 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 Foundation,
21    51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
22 
23 #ifndef SQL_SIGNAL_H
24 #define SQL_SIGNAL_H
25 
26 /**
27   Sql_cmd_common_signal represents the common properties of the
28   SIGNAL and RESIGNAL statements.
29 */
30 class Sql_cmd_common_signal : public Sql_cmd
31 {
32 protected:
33   /**
34     Constructor.
35     @param cond the condition signaled if any, or NULL.
36     @param set collection of signal condition item assignments.
37   */
Sql_cmd_common_signal(const sp_condition_value * cond,const Set_signal_information & set)38   Sql_cmd_common_signal(const sp_condition_value *cond,
39                         const Set_signal_information& set)
40     : Sql_cmd(),
41       m_cond(cond),
42       m_set_signal_information(set)
43   {}
44 
~Sql_cmd_common_signal()45   virtual ~Sql_cmd_common_signal()
46   {}
47 
48   /**
49     Assign the condition items 'MYSQL_ERRNO', 'level' and 'MESSAGE_TEXT'
50     default values of a condition.
51     @param cond the condition to update.
52     @param set_level_code true if 'level' and 'MYSQL_ERRNO' needs to be overwritten
53     @param level the level to assign
54     @param sqlcode the sql code to assign
55   */
56   static void assign_defaults(Sql_condition *cond,
57                               bool set_level_code,
58                               Sql_condition::enum_warning_level level,
59                               int sqlcode);
60 
61   /**
62     Evaluate the condition items 'SQLSTATE', 'MYSQL_ERRNO', 'level' and 'MESSAGE_TEXT'
63     default values for this statement.
64     @param thd the current thread.
65     @param cond the condition to update.
66   */
67   void eval_defaults(THD *thd, Sql_condition *cond);
68 
69   /**
70     Evaluate each signal condition items for this statement.
71     @param thd the current thread.
72     @param cond the condition to update.
73     @return 0 on success.
74   */
75   int eval_signal_informations(THD *thd, Sql_condition *cond);
76 
77   /**
78     Raise a SQL condition.
79     @param thd the current thread.
80     @param cond the condition to raise.
81     @return false on success.
82   */
83   bool raise_condition(THD *thd, Sql_condition *cond);
84 
85   /**
86     The condition to signal or resignal.
87     This member is optional and can be NULL (RESIGNAL).
88   */
89   const sp_condition_value *m_cond;
90 
91   /**
92     Collection of 'SET item = value' assignments in the
93     SIGNAL/RESIGNAL statement.
94   */
95   Set_signal_information m_set_signal_information;
96 };
97 
98 /**
99   Sql_cmd_signal represents a SIGNAL statement.
100 */
101 class Sql_cmd_signal : public Sql_cmd_common_signal
102 {
103 public:
104   /**
105     Constructor, used to represent a SIGNAL statement.
106     @param cond the SQL condition to signal (required).
107     @param set the collection of signal informations to signal.
108   */
Sql_cmd_signal(const sp_condition_value * cond,const Set_signal_information & set)109   Sql_cmd_signal(const sp_condition_value *cond,
110                  const Set_signal_information& set)
111     : Sql_cmd_common_signal(cond, set)
112   {}
113 
~Sql_cmd_signal()114   virtual ~Sql_cmd_signal()
115   {}
116 
sql_command_code()117   virtual enum_sql_command sql_command_code() const
118   {
119     return SQLCOM_SIGNAL;
120   }
121 
122   virtual bool execute(THD *thd);
123 };
124 
125 /**
126   Sql_cmd_resignal represents a RESIGNAL statement.
127 */
128 class Sql_cmd_resignal : public Sql_cmd_common_signal
129 {
130 public:
131   /**
132     Constructor, used to represent a RESIGNAL statement.
133     @param cond the SQL condition to resignal (optional, may be NULL).
134     @param set the collection of signal informations to resignal.
135   */
Sql_cmd_resignal(const sp_condition_value * cond,const Set_signal_information & set)136   Sql_cmd_resignal(const sp_condition_value *cond,
137                    const Set_signal_information& set)
138     : Sql_cmd_common_signal(cond, set)
139   {}
140 
~Sql_cmd_resignal()141   virtual ~Sql_cmd_resignal()
142   {}
143 
sql_command_code()144   virtual enum_sql_command sql_command_code() const
145   {
146     return SQLCOM_RESIGNAL;
147   }
148 
149   virtual bool execute(THD *thd);
150 };
151 
152 #endif
153 
154