[firebase-br] Fwd: Criando uma UDF no Firebird 2.1

Eliseu Corrona eliseucorrona em jbsoft.com.br
Seg Out 26 16:35:06 -03 2009


  Olá amigos, tudo bem?
Preciso criar uma UDF no Firebird 2.1, porém, apesar de seguir todos os 
passos de alguns exemplos que encontrei na internet, consegui criá-la 
porém não executá-la.

O exemplo que criei é simples. Criei uma Dll no delphi para retornar o 
módulo de um número e postei todos os passos abaixo.
É gerado um erro na execução e não teve jeito de fazer funcionar. Li 
alguns relatos no fórum sobre o mesmo erro. O meu sistema operacional é 
o Windows XP 32bits e o Firebird é a versão 2.1.218118.

Grato se puderem ajudar.



*Unit de funções da DLL:*

unit UdfFunctions;

interface

function Modulo(var i, j: Integer): Integer; cdecl; export;

implementation

function Modulo(var i, j: Integer): Integer;
begin
   if (j = 0) then
     result := -1 // just check the boundary condition, and
     // return a reasonably uninteresting answer.
   else
     result := i mod j;
end;

end.


*Declaração da DLL:*
library DllUtils;

{ Important note about DLL memory management: ShareMem must be the
   first unit in your library's USES clause AND your project's (select
   Project-View Source) USES clause if your DLL exports any procedures or
   functions that pass strings as parameters or function results. This
   applies to all strings passed to and from your DLL--even those that
   are nested in records and classes. ShareMem is the interface unit to
   the BORLNDMM.DLL shared memory manager, which must be deployed along
   with your DLL. To avoid using BORLNDMM.DLL, pass string information
   using PChar or ShortString parameters. }

uses
   SysUtils,
   Classes,
   UdfFunctions in 'UdfFunctions.pas';



{$R *.res}


exports
   Modulo;

begin

end.


*Código para criar a UDF no firebird:*
declare external function f_Modulo integer, integer
returns
integer free_it
entry_point 'Modulo' module_name 'DllUtils';


*SQL de execução:*
select f_Modulo(3, 2) from rdb$database;

*Erro gerado:*
Invalid token.
invalid request BLR at offset 60.
function F_MODULO is not defined.
module name or entrypoint could not be found.





Mais detalhes sobre a lista de discussão lista