[firebase-br] My Source Code
//---- Kelsie.Z.Marshall ----//
kelsie.z.marshall em gmail.com
Seg Set 7 17:42:05 -03 2009
Douglas
Não sabia está do LOG, muito bom obrigado, a cada comentário postado vou
aprendendo mais sobre o FB.
LOG
JU (Server) Mon Sep 07 17:20:44 2009
The user defined function: F_VAL
referencing entrypoint: Valida
in module: fb_UDFs
caused the fatal exception: An exception occurred that does
not have a description. Exception number EEDFADE.
This exception will cause the Firebird server
to terminate abnormally.
JU (Client) Mon Sep 07 17:20:44 2009
"C:\Users\Kelsie\Documents\Firebird_2_1\bin\fbserver.exe": terminated
abnormally (4294967295)
JU (Client) Mon Sep 07 17:20:45 2009
XNET error: Server shutdown detected
JU (Client) Mon Sep 07 17:20:45 2009
Guardian starting:
"C:\Users\Kelsie\Documents\Firebird_2_1\bin\fbserver.exe"
----- fim LOG
O estranho é que alterei a UDF fazendo com que ela exibisse os valores de
fossem passados como parâmetro e tudo parecia correto.
Mas meu código está correto é simples e funciona se compliado normalmente no
DELPHI, ai vai , não vi erros.
CREATE TABLE A_TAB
(
CNPJ VARCHAR( 14)
);
//---- Inclusão de Dados
INSERT INTO A_TAB (CNPJ) VALUES ('06947284000104');/*VÁLIDO*/
INSERT INTO A_TAB (CNPJ) VALUES ('06947284000104');/*INVÁLIDO*/
//---- Código DLL Delphi 2009
library fb_teste;
uses
SysUtils,
Classes;
//--------------------------------------------------------------------------------------------------------------------------------------------------
function ValidaCNPJ(str: Pchar) : Integer; cdecl;
var
n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12:integer;
d1,d2:integer;
digitado, calculado,num:string;
begin
d1 := 0;
d2 := 0;
result := -1;
num:= string(str);
n1:= strtoint(num[1]);
n2:= strtoint(num[2]);
n3:= strtoint(num[3]);
n4:= strtoint(num[4]);
n5:= strtoint(num[5]);
n6:= strtoint(num[6]);
n7:= strtoint(num[7]);
n8:= strtoint(num[8]);
n9:= strtoint(num[9]);
n10:= strtoint(num[10]);
n11:= strtoint(num[11]);
n12:= strtoint(num[12]);
d1:= n12*2+n11*3+n10*4+n9*5+n8*6+n7*7+n6*8+n5*9+n4*2+n3*3+n2*4+n1*5;
d1:= 11-(d1 mod 11);
if d1>=10 then d1:=0;
d2:=d2*2+ n12*3+n11*4+n10*5+n9*6+n8*7+n7*8+n6*9+n5*2+n4*3+n3*4+n2*5+n1*6;
d2:= 11-(d2 mod 11);
if d2>=10 then d2:=0;
calculado:= IntToStr(d1) + IntToStr(d2);
digitado:=num[13]+num[14];
if calculado = digitado then
begin
result := 0
end
else
begin
result := 1;
end;
end;
//---EXPORT'S---------------------------------------------------------------------------------------------------------------------------------------
exports
ValidaCNPJ;
//--------------------------------------------------------------------------------------------------------------------------------------------------
begin
end.
//-----------------------------------------------------------------------------------------------------------------------------------------------EOF-
/---- Implementação UDF
DECLARE EXTERNAL FUNCTION F_VAL
CSTRING(14)
RETURNS INTEGER BY VALUE
ENTRY_POINT 'ValidaCNPJ' MODULE_NAME 'fb_teste';
//---- testes para chamada da UDF
select f_val(cnpj) from a_tab
select f_val('12345678901234') from a_tab
ERRO
Error Message:
----------------------------------------
Unsuccessful execution caused by a system error that precludes
successful execution of subsequent statements.
Error writing data to the connection.
[]s,
Kelsie
"Douglas Tosi" <douglasht em gmail.com> wrote in
message news:249af69e0909071104k64efa7b2gf81f003570857557 em mail.gmail.com...
2009/9/7 //---- Kelsie.Z.Marshall ----//
<kelsie.z.marshall em gmail.com>:
> Error Message:
> ----------------------------------------
> Unsuccessful execution caused by a system error that precludes
> successful execution of subsequent statements.
> Error writing data to the connection.
Dê uma olhada no firebird.log. Deve ter mais detalhes sobre o erro.
E UDFs são bem estáveis sim, mas não é fácil escrevê-las corretamente.
hth,
--
Douglas Tosi
www.sinatica.com
______________________________________________
FireBase-BR (www.firebase.com.br) - Hospedado em www.locador.com.br
Para saber como gerenciar/excluir seu cadastro na lista, use:
http://www.firebase.com.br/fb/artigo.php?id=1107
Para consultar mensagens antigas: http://firebase.com.br/pesquisa
Mais detalhes sobre a lista de discussão lista