1 /* Copyright (c) 2008, 2012, 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 #include "sql_alloc.h" 27 #include "sp_pcontext.h" 28 29 /** 30 This enumeration list all the condition item names of a condition in the 31 SQL condition area. 32 */ 33 enum enum_condition_item_name 34 { 35 /* 36 Conditions that can be set by the user (SIGNAL/RESIGNAL), 37 and by the server implementation. 38 */ 39 40 CIN_CLASS_ORIGIN= 0, 41 CIN_FIRST_PROPERTY= CIN_CLASS_ORIGIN, 42 CIN_SUBCLASS_ORIGIN= 1, 43 CIN_CONSTRAINT_CATALOG= 2, 44 CIN_CONSTRAINT_SCHEMA= 3, 45 CIN_CONSTRAINT_NAME= 4, 46 CIN_CATALOG_NAME= 5, 47 CIN_SCHEMA_NAME= 6, 48 CIN_TABLE_NAME= 7, 49 CIN_COLUMN_NAME= 8, 50 CIN_CURSOR_NAME= 9, 51 CIN_MESSAGE_TEXT= 10, 52 CIN_MYSQL_ERRNO= 11, 53 CIN_LAST_PROPERTY= CIN_MYSQL_ERRNO 54 }; 55 56 57 /** 58 Set_signal_information is a container used in the parsed tree to represent 59 the collection of assignments to condition items in the SIGNAL and RESIGNAL 60 statements. 61 */ 62 class Set_signal_information : public Sql_alloc 63 { 64 public: Set_signal_information()65 Set_signal_information() 66 { memset(m_item, 0, sizeof(m_item)); } 67 ~Set_signal_information()68 ~Set_signal_information() {} 69 70 bool set_item(enum_condition_item_name name, Item *item); 71 72 /** 73 For each condition item assignment, m_item[] contains the parsed tree 74 that represents the expression assigned, if any. 75 m_item[] is an array indexed by enum_condition_item_name. 76 */ 77 Item *m_item[CIN_LAST_PROPERTY + 1]; 78 }; 79 80 81 /** 82 Sql_cmd_common_signal represents the common properties of the 83 SIGNAL and RESIGNAL statements. 84 */ 85 class Sql_cmd_common_signal : public Sql_cmd 86 { 87 protected: 88 /** 89 Constructor. 90 @param cond the condition signaled if any, or NULL. 91 @param set collection of signal condition item assignments. 92 */ Sql_cmd_common_signal(const sp_condition_value * cond,Set_signal_information * set)93 Sql_cmd_common_signal(const sp_condition_value *cond, 94 Set_signal_information *set) 95 : Sql_cmd(), 96 m_cond(cond), 97 m_set_signal_information(set) 98 {} 99 ~Sql_cmd_common_signal()100 virtual ~Sql_cmd_common_signal() 101 {} 102 103 /** 104 Assign the condition items 'MYSQL_ERRNO', 'level' and 'MESSAGE_TEXT' 105 default values of a condition. 106 @param cond the condition to update. 107 @param set_level_code true if 'level' and 'MYSQL_ERRNO' needs to be overwritten 108 @param level the level to assign 109 @param sqlcode the sql code to assign 110 */ 111 static void assign_defaults(Sql_condition *cond, 112 bool set_level_code, 113 Sql_condition::enum_severity_level level, 114 int sqlcode); 115 116 /** 117 Evaluate the condition items 'SQLSTATE', 'MYSQL_ERRNO', 'level' and 'MESSAGE_TEXT' 118 default values for this statement. 119 @param thd the current thread. 120 @param cond the condition to update. 121 */ 122 void eval_defaults(THD *thd, Sql_condition *cond); 123 124 /** 125 Evaluate each signal condition items for this statement. 126 @param thd the current thread. 127 @param cond the condition to update. 128 @return 0 on success. 129 */ 130 int eval_signal_informations(THD *thd, Sql_condition *cond); 131 132 /** 133 The condition to signal or resignal. 134 This member is optional and can be NULL (RESIGNAL). 135 */ 136 const sp_condition_value *m_cond; 137 138 /** 139 Collection of 'SET item = value' assignments in the 140 SIGNAL/RESIGNAL statement. 141 */ 142 Set_signal_information *m_set_signal_information; 143 }; 144 145 /** 146 Sql_cmd_signal represents a SIGNAL statement. 147 */ 148 class Sql_cmd_signal : public Sql_cmd_common_signal 149 { 150 public: 151 /** 152 Constructor, used to represent a SIGNAL statement. 153 @param cond the SQL condition to signal (required). 154 @param set the collection of signal informations to signal. 155 */ Sql_cmd_signal(const sp_condition_value * cond,Set_signal_information * set)156 Sql_cmd_signal(const sp_condition_value *cond, 157 Set_signal_information *set) 158 : Sql_cmd_common_signal(cond, set) 159 {} 160 ~Sql_cmd_signal()161 virtual ~Sql_cmd_signal() 162 {} 163 sql_command_code()164 virtual enum_sql_command sql_command_code() const 165 { 166 return SQLCOM_SIGNAL; 167 } 168 169 virtual bool execute(THD *thd); 170 }; 171 172 /** 173 Sql_cmd_resignal represents a RESIGNAL statement. 174 */ 175 class Sql_cmd_resignal : public Sql_cmd_common_signal 176 { 177 public: 178 /** 179 Constructor, used to represent a RESIGNAL statement. 180 @param cond the SQL condition to resignal (optional, may be NULL). 181 @param set the collection of signal informations to resignal. 182 */ Sql_cmd_resignal(const sp_condition_value * cond,Set_signal_information * set)183 Sql_cmd_resignal(const sp_condition_value *cond, 184 Set_signal_information *set) 185 : Sql_cmd_common_signal(cond, set) 186 {} 187 ~Sql_cmd_resignal()188 virtual ~Sql_cmd_resignal() 189 {} 190 sql_command_code()191 virtual enum_sql_command sql_command_code() const 192 { 193 return SQLCOM_RESIGNAL; 194 } 195 196 virtual bool execute(THD *thd); 197 }; 198 199 #endif 200 201