GUID in Firebird

Hi Wagner,


I want to convert some existing ID's in our database to have GUID id's instead of integers to make distributive applications easier.  As usual the tools you provide are excellent and everything just works.  So this is perhaps out of the scope of your support but I bet I am not the only one who might have this issue so I'll post my question here and see if anyone has any ideas. 

We use Firebird for the back end database and it has a native UUID but not a GUID, at least in version 2.5.  So to enable us to pump data into the database from other sources or convert existing data I've tried to write a little UDF in Delphi to generate the GUID using the smart GUID function from Aurelius but I think I am running into issues with memory allocation.  I can use my function in a select statement but I get deadlocks if I try and use it to update all the data in an existing table.  Here's my code...



unit functions;


interface


function GenGuid: PAnsiChar; cdecl; export;


implementation


uses
  ib_util,
  Aurelius.Global.Utils,
  System.SysUtils,
  AnsiStrings;


{
DECLARE EXTERNAL FUNCTION GENGUID
RETURNS CSTRING(38) FREE_IT
ENTRY_POINT 'GenGuid' MODULE_NAME 'PMI_UDF.dll';
}


function GenGuid: PAnsiChar;
var
  sGUID: AnsiString;
  len  : integer;
begin
  sGUID := AnsiString( TUtils.NewSequentialGuid( TSequentialGuidMode.SequentialAsString ).ToString );
  Assert( SizeOf( sGUID[ 1 ] ) = SizeOf( byte ) );
  len    := Length( sGUID );
  Result := ib_util_malloc( len + 1 );
  AnsiStrings.StrPLCopy( Result, sGUID, len );
end;


end.

Again I seemed to have posted her to quickly :(  sorry to be such a nuisance Wagner.  There doesn't appear to be much wrong with the UDF it was a corrupt database.