Skip to content

Commit

Permalink
1) Fixing another case of CORE-1514 - Many new 2.1 built in functions…
Browse files Browse the repository at this point in the history
… have incorrect NULL semantics

2) Improvement CORE-1569 - ROUND function second parameter - make optional like TRUNC
  • Loading branch information
asfernandes committed Nov 12, 2007
1 parent b7adcfe commit ca7004e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion doc/sql.extensions/README.builtin_functions.txt
Expand Up @@ -636,7 +636,7 @@ Function:
Returns a number rounded to the specified scale.

Format:
ROUND( <number>, <number> )
ROUND( <number> [, <number> ] )

Notes:
If the scale (second parameter) is negative, the integer part of
Expand Down
32 changes: 20 additions & 12 deletions src/jrd/SysFunction.cpp
Expand Up @@ -805,21 +805,24 @@ static void makeRound(DataTypeUtilBase* dataTypeUtil, const SysFunction* functio
fb_assert(argsCount == function->minArgCount);

const dsc* value1 = args[0];
const dsc* value2 = args[1];

if (value1->isNull() || value2->isNull())
if (value1->isNull() || (argsCount > 1 && args[1]->isNull()))
{
result->makeLong(0);
result->setNull();
return;
}

if (value1->isExact() || value1->dsc_dtype == dtype_real || value1->dsc_dtype == dtype_double)
{
*result = *value1;
if (argsCount == 1)
result->dsc_scale = 0;
}
else
status_exception::raise(isc_expression_eval_err, 0);

result->setNullable(value1->isNullable() || value2->isNullable());
result->setNullable(value1->isNullable() || (argsCount > 1 && args[1]->isNullable()));
}


Expand Down Expand Up @@ -851,7 +854,7 @@ static void makeTrunc(DataTypeUtilBase* dataTypeUtil, const SysFunction* functio
break;
}

result->setNullable(value->isNullable());
result->setNullable(value->isNullable() || (argsCount > 1 && args[1]->isNullable()));
}


Expand Down Expand Up @@ -2527,7 +2530,7 @@ static dsc* evlRight(Jrd::thread_db* tdbb, const SysFunction* function, Jrd::jrd

static dsc* evlRound(Jrd::thread_db* tdbb, const SysFunction* function, Jrd::jrd_nod* args, Jrd::impure_value* impure)
{
fb_assert(args->nod_count == 2);
fb_assert(args->nod_count >= 1);

jrd_req* request = tdbb->tdbb_request;

Expand All @@ -2536,13 +2539,18 @@ static dsc* evlRound(Jrd::thread_db* tdbb, const SysFunction* function, Jrd::jrd
if (request->req_flags & req_null) // return NULL if value is NULL
return NULL;

dsc* scaleDsc = EVL_expr(tdbb, args->nod_arg[1]);
if (request->req_flags & req_null) // return NULL if scaleDsc is NULL
return NULL;
SLONG scale = 0;

SLONG scale = -MOV_get_long(scaleDsc, 0);
if (!(scale >= MIN_SCHAR && scale <= MAX_SCHAR))
status_exception::raise(isc_expression_eval_err, 0);
if (args->nod_count > 1)
{
dsc* scaleDsc = EVL_expr(tdbb, args->nod_arg[1]);
if (request->req_flags & req_null) // return NULL if scaleDsc is NULL
return NULL;

scale = -MOV_get_long(scaleDsc, 0);
if (!(scale >= MIN_SCHAR && scale <= MAX_SCHAR))
status_exception::raise(isc_expression_eval_err, 0);
}

impure->vlu_misc.vlu_int64 = MOV_get_int64(value, scale);
impure->vlu_desc.makeInt64(scale, &impure->vlu_misc.vlu_int64);
Expand Down Expand Up @@ -2744,7 +2752,7 @@ const SysFunction SysFunction::functions[] =
SF("REPLACE", 3, 3, setParamsFromList, makeReplace, evlReplace, NULL),
SF("REVERSE", 1, 1, NULL, makeReverse, evlReverse, NULL),
SF("RIGHT", 2, 2, setParamsSecondInteger, makeLeftRight, evlRight, NULL),
SF("ROUND", 2, 2, setParamsRoundTrunc, makeRound, evlRound, NULL),
SF("ROUND", 1, 2, setParamsRoundTrunc, makeRound, evlRound, NULL),
SF("RPAD", 2, 3, setParamsSecondInteger, makePad, evlPad, (void*) funRPad),
SF("SIGN", 1, 1, setParamsDouble, makeShortResult, evlSign, NULL),
SF("SIN", 1, 1, setParamsDouble, makeDoubleResult, evlStdMath, (VoidPtrStdMathFunc) sin),
Expand Down

0 comments on commit ca7004e

Please sign in to comment.