8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-24 06:03:02 +01:00

Fixed CORE-1343 - Bug with a simple case and a subquery

This commit is contained in:
asfernandes 2008-08-21 01:58:53 +00:00
parent bd2dbfc0bb
commit e54682efa0
3 changed files with 18 additions and 2 deletions

View File

@ -2682,7 +2682,8 @@ static void gen_simple_case( CompiledStatement* statement, const dsql_nod* node)
{
stuff(statement, blr_value_if);
stuff(statement, blr_eql);
GEN_expr(statement, node->nod_arg[e_simple_case_case_operand]);
GEN_expr(statement, node->nod_arg[(wptr == when_list->nod_arg ?
e_simple_case_case_operand : e_simple_case_case_operand2)]);
GEN_expr(statement, *wptr);
GEN_expr(statement, *rptr);
}

View File

@ -914,6 +914,7 @@ enum node_args {
e_simple_case_case_operand = 0, // 1 value
e_simple_case_when_operands, // list
e_simple_case_results, // list including else_result
e_simple_case_case_operand2, // operand for use after the first test
// CASE {WHEN <search_condition> THEN <when_result>}.. [ELSE <else_result>] END
// Node-constants for after pass1

View File

@ -8236,10 +8236,24 @@ static dsql_nod* pass1_simple_case( CompiledStatement* statement, dsql_nod* inpu
DEV_BLKCHK(input, dsql_type_nod);
DEV_BLKCHK(input->nod_arg[0], dsql_type_nod);
dsql_nod* node = MAKE_node(nod_simple_case, 3);
dsql_nod* node = MAKE_node(nod_simple_case, 4);
// build case_operand node
node->nod_arg[e_simple_case_case_operand] = PASS1_node(statement, input->nod_arg[0]);
node->nod_arg[e_simple_case_case_operand2] =
pass1_hidden_variable(statement, node->nod_arg[e_simple_case_case_operand]);
// If it's not a simple expression, create a assignment node for the initial test.
if (node->nod_arg[e_simple_case_case_operand2])
{
dsql_nod* assign = MAKE_node(nod_assign, e_asgn_count);
assign->nod_arg[e_asgn_value] = node->nod_arg[e_simple_case_case_operand];
assign->nod_arg[e_asgn_field] = node->nod_arg[e_simple_case_case_operand2];
node->nod_arg[e_simple_case_case_operand] = assign;
}
else
node->nod_arg[e_simple_case_case_operand2] = node->nod_arg[e_simple_case_case_operand];
dsql_nod* list = input->nod_arg[1];