Skip to content

Commit d9a8e20

Browse files
committed
Merge branch 'mysql-5.6' into mysql-5.7
Change-Id: I10134bdbd011668ee333d59724d15f09f120f296
2 parents f849f27 + 353ada2 commit d9a8e20

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

sql/sql_yacc.yy

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,10 +2949,22 @@ sp_decl:
29492949
uint num_vars= pctx->context_var_count();
29502950
enum enum_field_types var_type= (enum enum_field_types) $4;
29512951
Item *dflt_value_item= $5;
2952+
const bool has_default_clause = (dflt_value_item != NULL);
2953+
bool is_const_item = false;
2954+
29522955
LEX_STRING dflt_value_query= EMPTY_STR;
29532956

2954-
if (dflt_value_item)
2955-
{
2957+
if (has_default_clause) {
2958+
// Handling a NEG_FUNC wrapping a constant.
2959+
if (dflt_value_item->type() == Item::FUNC_ITEM) {
2960+
Item_func *func_item = down_cast<Item_func *>(dflt_value_item);
2961+
if (func_item->functype() == Item_func::NEG_FUNC) {
2962+
is_const_item = true;
2963+
}
2964+
} else if (dflt_value_item->const_item()) {
2965+
is_const_item = true;
2966+
}
2967+
29562968
// sp_opt_default only pushes start ptr for DEFAULT clause.
29572969
const char *expr_start_ptr=
29582970
sp->m_parser_data.pop_expr_start_ptr();
@@ -2972,10 +2984,13 @@ sp_decl:
29722984
MYSQL_YYABORT;
29732985
}
29742986

2987+
sp_variable *first_spvar = NULL;
2988+
const uint first_var_num = num_vars - $2;
2989+
29752990
// We can have several variables in DECLARE statement.
29762991
// We need to create an sp_instr_set instruction for each variable.
29772992

2978-
for (uint i = num_vars-$2 ; i < num_vars ; i++)
2993+
for (uint i = first_var_num; i < num_vars; i++)
29792994
{
29802995
uint var_idx= pctx->var_context2runtime(i);
29812996
sp_variable *spvar= pctx->find_variable(var_idx);
@@ -2984,8 +2999,33 @@ sp_decl:
29842999
MYSQL_YYABORT;
29853000

29863001
spvar->type= var_type;
3002+
3003+
// Transforming the following declare statements having non-const
3004+
// expressions:
3005+
// DECLARE a, b, c type DEFAULT expr;
3006+
// to
3007+
// DECLARE a type DEFAULT expr, b type DEFAULT a,
3008+
// c type DEFAULT a;
3009+
3010+
if (i == first_var_num) {
3011+
first_spvar = spvar;
3012+
} else if (has_default_clause && !is_const_item) {
3013+
Item_splocal *item =
3014+
NEW_PTN Item_splocal(first_spvar->name, first_spvar->offset,
3015+
first_spvar->type, 0, 0);
3016+
if (item == NULL)
3017+
MYSQL_YYABORT; // OOM
3018+
#ifndef NDEBUG
3019+
item->m_sp = lex->sphead;
3020+
#endif
3021+
dflt_value_item = item;
3022+
}
29873023
spvar->default_value= dflt_value_item;
29883024

3025+
if (has_default_clause && !is_const_item && (i > first_var_num)) {
3026+
dflt_value_query = first_spvar->name;
3027+
}
3028+
29893029
if (fill_field_definition(thd, sp, var_type, &spvar->field_def))
29903030
MYSQL_YYABORT;
29913031

0 commit comments

Comments
 (0)