diff --git a/src/MyFirstUDRKit.cpp b/src/MyFirstUDRKit.cpp new file mode 100644 index 0000000..be23ae5 --- /dev/null +++ b/src/MyFirstUDRKit.cpp @@ -0,0 +1,95 @@ +/* + * 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 + * and all contributors signed below. + * + * All Rights Reserved. + * Contributor(s): ______________________________________. + * + * Paul Reeves, 2023 + * + */ + + +#define FB_UDR_STATUS_TYPE ::Firebird::ThrowStatusWrapper + + +#include +#include + +#include +#include +#include + +#ifdef HAVE_MATH_H +#include +#endif + +#ifdef HAVE_STRING_H +#include +#endif + +#ifdef TIME_WITH_SYS_TIME +# include +# include +#else +# ifdef HAVE_SYS_TIME_H +# include +# else +# include +# endif +#endif + +#ifdef HAVE_SYS_TIMEB_H +# include +#endif + +#ifdef HAVE_LOCALE_H +#include +#endif + +#include + +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 + { + if ( flags == NULL ) { + return 0; + } + ISC_UINT64 i = ( 1ULL << *flag ); + return ( *flags & i ) ? 1 : 0; + } +FB_UDR_END_FUNCTION +