1 /* Copyright (c) 2008 MySQL AB, 2009 Sun Microsystems, Inc. 2 Use is subject to license terms. 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; version 2 of the License. 7 8 This program is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License 14 along with this program; if not, write to the Free Software 15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 16 17 #ifndef SQL_SIGNAL_H 18 #define SQL_SIGNAL_H 19 20 /** 21 Signal_common represents the common properties of the SIGNAL and RESIGNAL 22 statements. 23 */ 24 class Signal_common : public Sql_statement 25 { 26 protected: 27 /** 28 Constructor. 29 @param lex the LEX structure for this statement. 30 @param cond the condition signaled if any, or NULL. 31 @param set collection of signal condition item assignments. 32 */ Signal_common(LEX * lex,const sp_cond_type_t * cond,const Set_signal_information & set)33 Signal_common(LEX *lex, 34 const sp_cond_type_t *cond, 35 const Set_signal_information& set) 36 : Sql_statement(lex), 37 m_cond(cond), 38 m_set_signal_information(set) 39 {} 40 ~Signal_common()41 virtual ~Signal_common() 42 {} 43 44 /** 45 Assign the condition items 'MYSQL_ERRNO', 'level' and 'MESSAGE_TEXT' 46 default values of a condition. 47 @param cond the condition to update. 48 @param set_level_code true if 'level' and 'MYSQL_ERRNO' needs to be overwritten 49 @param level the level to assign 50 @param sqlcode the sql code to assign 51 */ 52 static void assign_defaults(MYSQL_ERROR *cond, 53 bool set_level_code, 54 MYSQL_ERROR::enum_warning_level level, 55 int sqlcode); 56 57 /** 58 Evaluate the condition items 'SQLSTATE', 'MYSQL_ERRNO', 'level' and 'MESSAGE_TEXT' 59 default values for this statement. 60 @param thd the current thread. 61 @param cond the condition to update. 62 */ 63 void eval_defaults(THD *thd, MYSQL_ERROR *cond); 64 65 /** 66 Evaluate each signal condition items for this statement. 67 @param thd the current thread. 68 @param cond the condition to update. 69 @return 0 on success. 70 */ 71 int eval_signal_informations(THD *thd, MYSQL_ERROR *cond); 72 73 /** 74 Raise a SQL condition. 75 @param thd the current thread. 76 @param cond the condition to raise. 77 @return false on success. 78 */ 79 bool raise_condition(THD *thd, MYSQL_ERROR *cond); 80 81 /** 82 The condition to signal or resignal. 83 This member is optional and can be NULL (RESIGNAL). 84 */ 85 const sp_cond_type_t *m_cond; 86 87 /** 88 Collection of 'SET item = value' assignments in the 89 SIGNAL/RESIGNAL statement. 90 */ 91 Set_signal_information m_set_signal_information; 92 }; 93 94 /** 95 Signal_statement represents a SIGNAL statement. 96 */ 97 class Signal_statement : public Signal_common 98 { 99 public: 100 /** 101 Constructor, used to represent a SIGNAL statement. 102 @param lex the LEX structure for this statement. 103 @param cond the SQL condition to signal (required). 104 @param set the collection of signal informations to signal. 105 */ Signal_statement(LEX * lex,const sp_cond_type_t * cond,const Set_signal_information & set)106 Signal_statement(LEX *lex, 107 const sp_cond_type_t *cond, 108 const Set_signal_information& set) 109 : Signal_common(lex, cond, set) 110 {} 111 ~Signal_statement()112 virtual ~Signal_statement() 113 {} 114 115 /** 116 Execute a SIGNAL statement at runtime. 117 @param thd the current thread. 118 @return false on success. 119 */ 120 virtual bool execute(THD *thd); 121 }; 122 123 /** 124 Resignal_statement represents a RESIGNAL statement. 125 */ 126 class Resignal_statement : public Signal_common 127 { 128 public: 129 /** 130 Constructor, used to represent a RESIGNAL statement. 131 @param lex the LEX structure for this statement. 132 @param cond the SQL condition to resignal (optional, may be NULL). 133 @param set the collection of signal informations to resignal. 134 */ Resignal_statement(LEX * lex,const sp_cond_type_t * cond,const Set_signal_information & set)135 Resignal_statement(LEX *lex, 136 const sp_cond_type_t *cond, 137 const Set_signal_information& set) 138 : Signal_common(lex, cond, set) 139 {} 140 ~Resignal_statement()141 virtual ~Resignal_statement() 142 {} 143 144 /** 145 Execute a RESIGNAL statement at runtime. 146 @param thd the current thread. 147 @return 0 on success. 148 */ 149 virtual bool execute(THD *thd); 150 }; 151 152 #endif 153 154