8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 07:23:04 +01:00

Fix TRIM(NULL FROM <something>) to return NULL

This commit is contained in:
asfernandes 2005-06-12 21:20:12 +00:00
parent 92e2c4e961
commit a44e8ffbd0
2 changed files with 11 additions and 10 deletions

View File

@ -487,11 +487,16 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
case nod_trim:
MAKE_desc(request, &desc1, node->nod_arg[e_trim_value], null_replacement);
if (node->nod_arg[e_trim_characters])
MAKE_desc(request, &desc2, node->nod_arg[e_trim_characters], null_replacement);
else
desc2.dsc_flags = 0;
if (desc1.dsc_dtype <= dtype_any_text) {
*desc = desc1;
desc->dsc_dtype = dtype_varying;
desc->dsc_length = sizeof(USHORT) + DSC_string_length(&desc1);
desc->dsc_flags = (desc1.dsc_flags | desc2.dsc_flags) & DSC_nullable;
return;
}
@ -499,7 +504,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl
desc->dsc_scale = 0;
desc->dsc_ttype() = ttype_ascii;
desc->dsc_length = sizeof(USHORT) + DSC_string_length(&desc1);
desc->dsc_flags = desc1.dsc_flags & DSC_nullable;
desc->dsc_flags = (desc1.dsc_flags | desc2.dsc_flags) & DSC_nullable;
return;
case nod_cast:

View File

@ -5015,18 +5015,14 @@ static dsc* trim(thread_db* tdbb, jrd_nod* node, impure_value* impure)
jrd_req* request = tdbb->tdbb_request;
const ULONG specification = (IPTR) node->nod_arg[e_trim_specification];
request->req_flags &= ~req_null;
dsc* characters = (node->nod_arg[e_trim_characters] ? EVL_expr(tdbb, node->nod_arg[e_trim_characters]) : NULL);
const ULONG flags = (node->nod_arg[e_trim_characters] ? request->req_flags : request->req_flags & ~req_null);
if (request->req_flags & req_null)
return characters;
request->req_flags &= ~req_null;
dsc* value = EVL_expr(tdbb, node->nod_arg[e_trim_value]);
// restore saved NULL state
if (flags & req_null)
{
request->req_flags |= req_null;
return characters;
}
if (request->req_flags & req_null)
return value;