Skip to content

Commit

Permalink
[CBRD-25139] When using oracle style empty string, the result of repl…
Browse files Browse the repository at this point in the history
  • Loading branch information
beyondykk9 authored and mhoh3963 committed Aug 6, 2024
1 parent f1ea0e4 commit 5d130f0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
30 changes: 26 additions & 4 deletions src/parser/type_checking.c
Original file line number Diff line number Diff line change
Expand Up @@ -19390,24 +19390,47 @@ pt_fold_const_expr (PARSER_CONTEXT * parser, PT_NODE * expr, void *arg)
}

if (prm_get_bool_value (PRM_ID_ORACLE_STYLE_EMPTY_STRING)
&& (op == PT_STRCAT || op == PT_PLUS || op == PT_CONCAT || op == PT_CONCAT_WS))
&& (op == PT_STRCAT || op == PT_PLUS || op == PT_CONCAT || op == PT_CONCAT_WS || op == PT_REPLACE))
{
TP_DOMAIN *domain;

if (op == PT_REPLACE)
{
opd3 = expr->info.expr.arg3;
type3 = (opd3) ? opd3->type_enum : PT_TYPE_NULL;
}

/* use the caching variant of this function ! */
domain = pt_xasl_node_to_domain (parser, expr);

if (domain
&& (QSTR_IS_ANY_CHAR_OR_BIT (TP_DOMAIN_TYPE (domain)) || type1 == PT_TYPE_NULL || type2 == PT_TYPE_NULL))
{
if (opd1 && opd1->node_type == PT_VALUE && type1 == PT_TYPE_NULL)
if (opd3) /* REPLACE */
{
if (opd3->node_type == PT_VALUE && type3 == PT_TYPE_NULL)
{
/* need to replace the NULL with empty string */
int err =
db_string_make_empty_typed_string (&opd3->info.value.db_value, DB_TYPE_STRING, DB_DEFAULT_PRECISION,
TP_DOMAIN_CODESET (domain), TP_DOMAIN_COLLATION (domain));
if (err != NO_ERROR)
{
has_error = true;
}
else
{
result = expr;
}
}
}
else if (opd1 && opd1->node_type == PT_VALUE && type1 == PT_TYPE_NULL)
{
/* fold 'null || char_opnd' expr to 'char_opnd' */
result = parser_copy_tree (parser, opd2);
if (result == NULL)
{
has_error = true;
goto end;
}
}
else if (opd2 && opd2->node_type == PT_VALUE && type2 == PT_TYPE_NULL)
Expand All @@ -19417,7 +19440,6 @@ pt_fold_const_expr (PARSER_CONTEXT * parser, PT_NODE * expr, void *arg)
if (result == NULL)
{
has_error = true;
goto end;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/query/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,8 @@ fetch_peek_arith (THREAD_ENTRY * thread_p, REGU_VARIABLE * regu_var, val_descr *
goto error;
}
}
if (DB_IS_NULL (peek_left) || (peek_third && DB_IS_NULL (peek_third)))
if (!prm_get_bool_value (PRM_ID_ORACLE_STYLE_EMPTY_STRING)
&& (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right) || (peek_third && DB_IS_NULL (peek_third))))
{
PRIM_SET_NULL (arithptr->value);
}
Expand Down

0 comments on commit 5d130f0

Please sign in to comment.