From a44e8ffbd0992e09d54573b8a8b131f604a0a33e Mon Sep 17 00:00:00 2001 From: asfernandes Date: Sun, 12 Jun 2005 21:20:12 +0000 Subject: [PATCH] Fix TRIM(NULL FROM ) to return NULL --- src/dsql/make.cpp | 7 ++++++- src/jrd/evl.cpp | 14 +++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/dsql/make.cpp b/src/dsql/make.cpp index 3c61ac2b90..a6209da19a 100644 --- a/src/dsql/make.cpp +++ b/src/dsql/make.cpp @@ -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: diff --git a/src/jrd/evl.cpp b/src/jrd/evl.cpp index 8f9566d003..385c005f04 100644 --- a/src/jrd/evl.cpp +++ b/src/jrd/evl.cpp @@ -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;