Subject Manipulating BLOBs in a x64 UDF compiled with Delphi XE2
Author Josef Kokeš
Hi!

Having bought Delphi XE2, I tried to compile my old (well, very old) UDF
in a 64bit mode. I expected a total fail, because the UDF was written in
Delphi 5 for Interbase 6.0, but after I fixed string types, the UDF
actually works with Firebird 2.1 x64. With one exception - a function
which converts VARCHAR to BLOB causes an Access Violation in the server.
I suspect this might have something to do with the fact that x64
pointers are 64 bits long, which causes the blob record to be of
incorrect lenght, but I would like to get a confirmation (possibly even
a solution :-)) from people more experienced with UDF writing that I am.

The SQL declaration:

DECLARE EXTERNAL FUNCTION STRBLOB
CSTRING(32765), BLOB
RETURNS PARAMETER 2
ENTRY_POINT 'STRBLOB' MODULE_NAME 'pwIBUDF';

The function:

function STRBLOB(Value: PAnsiChar; Dest: PBlob): PBlob;
begin
Result := Dest;
Dest^.PutSegment(Dest^.BlobHandle, Value, StrLen(Value))
end;

The blob record (probably wrong for x64):

TISC_BlobGetSegment = function(BlobHandle: PInt;
Buffer: PAnsiChar;
BufferSize: LongInt;
var ResultLength: LongInt): SmallInt; cdecl;
TISC_BlobPutSegment = procedure(BlobHandle: PInt;
Buffer: PAnsiChar;
BufferLength: SmallInt); cdecl;
TBlob = record
GetSegment: TISC_BlobGetSegment;
BlobHandle: PInt;
SegmentCount: LongInt;
MaxSegmentLength: LongInt;
TotalSize: LongInt;
PutSegment: TISC_BlobPutSegment;
end;
PBlob = ^TBlob;

Did anyone try to work with BLOBs in a x64 UDF already?

Thanks,

Josef Kokes