Check whether sequence values are valid. Sets default values for fields that are not used, according to Oracle spec. @param in thd The connection @param in set_reserved_until Whether to set reserved_until to start @param in adjust_next Whether to call flush next_free_value. Default to true @retval false
| 173 | true invalid |
| 174 | */ |
| 175 | bool sequence_definition::check_and_adjust(THD *thd, bool set_reserved_until, |
| 176 | bool adjust_next) |
| 177 | { |
| 178 | DBUG_ENTER("sequence_definition::check_and_adjust"); |
| 179 | |
| 180 | /* Easy error to detect. */ |
| 181 | if (!is_allowed_value_type(value_type) || cache < 0) |
| 182 | DBUG_RETURN(TRUE); |
| 183 | |
| 184 | if (!(real_increment= increment)) |
| 185 | real_increment= global_system_variables.auto_increment_increment; |
| 186 | |
| 187 | /* |
| 188 | If min_value is not set, in case of signed sequence, set it to |
| 189 | value_type_min()+1 or 1, depending on real_increment, and in case |
| 190 | of unsigned sequence, set it to value_type_min()+1 |
| 191 | */ |
| 192 | if (!(used_fields & seq_field_specified_min_value)) |
| 193 | min_value= real_increment < 0 || is_unsigned ? value_type_min()+1 : 1; |
| 194 | else |
| 195 | { |
| 196 | min_value= truncate_value(min_value_from_parser); |
| 197 | if ((is_unsigned && |
| 198 | (ulonglong) min_value <= (ulonglong) value_type_min()) || |
| 199 | (!is_unsigned && min_value <= value_type_min())) |
| 200 | { |
| 201 | push_warning_printf( |
| 202 | thd, Sql_condition::WARN_LEVEL_NOTE, ER_TRUNCATED_WRONG_VALUE, |
| 203 | ER_THD(thd, ER_TRUNCATED_WRONG_VALUE), "INTEGER", "MINVALUE"); |
| 204 | min_value= value_type_min() + 1; |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | /* |
| 209 | If max_value is not set, in case of signed sequence set it to |
| 210 | value_type_max()-1 or -1, depending on real_increment, and in case |
| 211 | of unsigned sequence, set it to value_type_max()-1 |
| 212 | */ |
| 213 | if (!(used_fields & seq_field_specified_max_value)) |
| 214 | max_value= real_increment > 0 || is_unsigned ? value_type_max()-1 : -1; |
| 215 | else |
| 216 | { |
| 217 | max_value= truncate_value(max_value_from_parser); |
| 218 | if ((is_unsigned && |
| 219 | (ulonglong) max_value >= (ulonglong) value_type_max()) || |
| 220 | (!is_unsigned && max_value >= value_type_max())) |
| 221 | { |
| 222 | push_warning_printf( |
| 223 | thd, Sql_condition::WARN_LEVEL_NOTE, ER_TRUNCATED_WRONG_VALUE, |
| 224 | ER_THD(thd, ER_TRUNCATED_WRONG_VALUE), "INTEGER", "MAXVALUE"); |
| 225 | max_value= value_type_max() - 1; |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | if (!(used_fields & seq_field_used_start)) |
| 230 | { |
| 231 | /* Use min_value or max_value for start depending on real_increment */ |
| 232 | start= real_increment < 0 ? max_value : min_value; |
no test coverage detected