2023-01-20 13:00:07 +01:00
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Initial
|
|
|
|
* Developer's Public License Version 1.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed AS IS,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing rights
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code was created by Adriano dos Santos Fernandes
|
|
|
|
* for the Firebird Open Source RDBMS project.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 Adriano dos Santos Fernandes <adrianosf@gmail.com>
|
|
|
|
* and all contributors signed below.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
|
|
|
*
|
|
|
|
* Paul Reeves, 2023
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#define FB_UDR_STATUS_TYPE ::Firebird::ThrowStatusWrapper
|
|
|
|
|
|
|
|
|
|
|
|
#include <ibase.h>
|
|
|
|
#include <firebird/UdrCppEngine.h>
|
|
|
|
|
2023-01-20 16:17:06 +01:00
|
|
|
#include <cassert>
|
2023-01-20 13:00:07 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_MATH_H
|
|
|
|
#include <math.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef TIME_WITH_SYS_TIME
|
|
|
|
# include <sys/time.h>
|
|
|
|
# include <time.h>
|
|
|
|
#else
|
|
|
|
# ifdef HAVE_SYS_TIME_H
|
|
|
|
# include <sys/time.h>
|
|
|
|
# else
|
|
|
|
# include <time.h>
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_TIMEB_H
|
|
|
|
# include <sys/timeb.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_LOCALE_H
|
|
|
|
#include <locale.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
using namespace Firebird;
|
|
|
|
|
|
|
|
/*** DDL
|
|
|
|
create function flagged (
|
|
|
|
n1 integer,
|
|
|
|
n2 integer
|
|
|
|
) returns integer
|
|
|
|
external name 'my_first_udr_kit!MFK_flagged'
|
|
|
|
engine udr;
|
|
|
|
***/
|
|
|
|
FB_UDR_BEGIN_FUNCTION(MFK_flagged)
|
|
|
|
FB_UDR_MESSAGE(InMessage,
|
|
|
|
(FB_INTEGER, flags)
|
|
|
|
(FB_INTEGER, flag)
|
|
|
|
);
|
|
|
|
|
|
|
|
FB_UDR_MESSAGE(OutMessage,
|
|
|
|
(FB_INTEGER, result)
|
|
|
|
);
|
|
|
|
|
|
|
|
FB_UDR_EXECUTE_FUNCTION
|
|
|
|
{
|
2023-01-20 16:17:06 +01:00
|
|
|
// Original code
|
|
|
|
// if ( flags == NULL ) {
|
|
|
|
// return 0;
|
|
|
|
// }
|
|
|
|
if ( in->flagsNull ) {
|
|
|
|
out->resultNull = FB_TRUE;
|
|
|
|
out->result = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out->resultNull = FB_FALSE;
|
|
|
|
// Original code
|
|
|
|
// ISC_UINT64 i = ( 1ULL << *flag );
|
|
|
|
// return ( *flags & i ) ? 1 : 0;
|
|
|
|
ISC_UINT64 i = ( 1ULL << in->flag );
|
|
|
|
out->result = ( in->flags & i ) ? 1 : 0;
|
|
|
|
}
|
2023-01-20 13:00:07 +01:00
|
|
|
}
|
|
|
|
FB_UDR_END_FUNCTION
|
|
|
|
|
2023-01-20 16:17:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|