Subject RES: [firebird-support] Problems with UDF and Linux
Author Fabrício Fadel Kammer
Thanks Matign,

I'll try this. But can you indicate me some UDF code where I can see
this memory alocation?

Thanks

Fabrício

-----Mensagem original-----
De: firebird-support@yahoogroups.com
[mailto:firebird-support@yahoogroups.com] Em nome de Martijn Tonies
Enviada em: quarta-feira, 25 de janeiro de 2006 06:13
Para: firebird-support@yahoogroups.com
Assunto: Re: [firebird-support] Problems with UDF and Linux


> Can you explain a bit more about the strings?
> Can't I use string as a internal variable of my function in an udf
that
> will run in a linux server?
> Do you think that if I change the string to pchar I'll resolve my
> problem?

No, I think your problem will be solved if you properly allocate
memory to hold your data :-)

As I wrote earlier -- you don't allocate any memory for your result.
You should, cause your telling the Firebird server to free it (that's
what FREE_IT does).

Try reading into some other peoples UDF sources and see how
things are done.

Martijn Tonies
Database Workbench - tool for InterBase, Firebird, MySQL, Oracle & MS
SQL
Server
Upscene Productions
http://www.upscene.com
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com


> > I did a UDF in Delphi and it's work fine in my Windows servers.
> >
> > Than I compiled it in kylix with sucsses and put in the directory
> > /opt/interbase/UDF/abcs_udf.so on my linux server but I can't do the
> UDF
> > work.
> > Every time that I run a SQL using the UDF in the IBExpert I lose the
> > connection with the firebird server.
> > If I execute the select using the udf in the isql of my linux server
I
> > receive the message: "Statement failed, SQLCODE = -902 Error reading
> > data from the connection.".
>
> Sounds like the server has crashed.
>
> > Why do it occours? Why does the UDF works fine in the windows server
> and
> > it doesn't work on linux server?
> >
> > See the Object Pascal code of my function:
> >
> > function udf_FormatFloat(var Valor: Double; FormStr: PChar; Pontos:
> > PChar): PChar; cdecl; export;
> > var
> > ResAux: string;
> > begin
> > ResAux := pchar( FormatFloat( FormStr, Valor ) );
>
> Huh? PChar? ResAux was of type STRING!
>
> > if Pontos = 'N' then
> > begin
> > ResAux := AnsiReplaceStr( ResAux, '.', '' );
> > ResAux := AnsiReplaceStr( ResAux, ',', '' );
> > end;
> > Result := PChar( ResAux );
> > end;
>
> Where is your memory allocated for the result? Items
> of type "string" are cleaned up after being used. You have
> to allocate space for the resulting string (via ib_alloc or
> something) and then copy the contents from the string to
> the PChar memory place.



++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Visit http://firebird.sourceforge.net and click the Resources item
on the main (top) menu. Try Knowledgebase and FAQ links !

Also search the knowledgebases at http://www.ibphoenix.com

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++




_____

YAHOO! GROUPS LINKS



* Visit your group "firebird-support
<http://groups.yahoo.com/group/firebird-support> " on the web.


* To unsubscribe from this group, send an email to:
firebird-support-unsubscribe@yahoogroups.com
<mailto:firebird-support-unsubscribe@yahoogroups.com?subject=Unsubscribe
>


* Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service <http://docs.yahoo.com/info/terms/> .


_____




[Non-text portions of this message have been removed]