Subject Help needed, gen_uuid() UDF for 2.0
Author Sasha
I tried to implement gen_uuid() function as UDF for FB 2.0.0 and what I
though it would be a quick hack turned into 24 hours of frustration. I'd
like it to be implemented so it returns char(16) character set octets the
way it was done in 2.1 beta 1 and was discussed on firebird-devel group.

I wrote a .dll in Delphi 2006 and function is like this:

function gen_uuid: PChar;
uid: TGUID;
GetMem(Result, SizeOf(TGUID));
Move(uid, Result^, SizeOf(TGUID));

Function is registered like this:
declare external function gen_uuid returns cstring(16) character set octets
entry_point 'gen_uuid' module_name 'uuid.dll';

Basically it works most of the time, but if I do somethig like this (on Win
XP sp2):
select gen_uuid() from table_with_10000_rows it crashes the server with this
DY (Server) Fri Jul 06 12:53:56 2007
The user defined function: GEN_UUID
referencing entrypoint: gen_uuid
in module: uuid.dll
caused the fatal exception: Access violation.
The code attempted to access a virtual
address without privilege to do so.
This exception will cause the Firebird server
to terminate abnormally.

If I run this:
select octet_length(gen_uuid()) from table_with_200_rows
then most rows return 16 as expected... but some of them return less than
16... This one really confused me.

If I run this:
select gen_uuid() from rdb$database
everything works fine (it doesn't crash the server and result looks fine,
but based on other results it's not usable)

So, if anyone is willing to look at the code or possibly if you already have
a working implementation I'd be grateful for any help.