Skip to content

Commit

Permalink
Fixed CORE-1343 - Bug with a simple case and a subquery
Browse files Browse the repository at this point in the history
  • Loading branch information
asfernandes committed Aug 21, 2008
1 parent bd2dbfc commit e54682e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/dsql/gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/dsql/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion src/dsql/pass1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down

0 comments on commit e54682e

Please sign in to comment.