Add a better documented version of the div example

This commit is contained in:
Paul Reeves 2023-01-23 13:42:38 +01:00
parent 3e6facd820
commit 6259849525

View File

@ -65,6 +65,60 @@
using namespace Firebird; using namespace Firebird;
// First, let's start with a function from the UdfBackwardCompatibility
// library and add some additional comments.
// We will also use self-docmenting variable names
// //////////////////////////////////////////////////
/***
* create function div (
* anumerator integer,
* adenominator integer
* ) returns double precision
* external name 'udf_compat!UC_div!Divide param1 by param2'
* engine udr;
***/
FB_UDR_BEGIN_FUNCTION(UC_div)
// Divide integer param 1 by integer param2 using the stdlib
FB_UDR_MESSAGE(InMessage,
(FB_INTEGER, anumerator)
(FB_INTEGER, adenominator)
);
FB_UDR_MESSAGE(OutMessage,
(FB_DOUBLE, result)
);
FB_UDR_EXECUTE_FUNCTION
{
if (in->anumeratorNull || in->adenominatorNull)
{
out->resultNull = FB_TRUE;
out->result = 0;
}
else
{
out->resultNull = FB_FALSE;
if (in->adenominator) {
out->result = div(in->anumerator, in->adenominator).quot;
}
else
{
out->result = std::numeric_limits<double>::infinity();
ISC_STATUS_ARRAY StatusVector = {isc_arg_gds, isc_arith_except,
isc_arg_gds, isc_exception_integer_divide_by_zero, isc_arg_end};
FbException::check(isc_exception_integer_divide_by_zero, status, StatusVector);
}
}
}
FB_UDR_END_FUNCTION
/*** DDL /*** DDL
create function flagged ( create function flagged (
n1 integer, n1 integer,