Subject UDF - reading BLOB length
Author Josef KokeŇ°
Hi!

What could possibly be wrong with the following UDF?

* Function *

type
TBlob = {packed} record
GetSegment: TISC_BlobGetSegment;
BlobHandle: PInt;
SegmentCount: LongInt;
MaxSegmentLength: LongInt;
TotalSize: LongInt;
PutSegment: TISC_BlobPutSegment;
end;
PBlob = ^TBlob;

function BLOBLEN(Value: PBlob): Integer; cdecl;
begin
if Value = nil then
Result := 0
else
Result := Value^.TotalSize;
end;

* Declaration *

DECLARE EXTERNAL FUNCTION BLOBLEN
BLOB
RETURNS INTEGER
ENTRY_POINT 'BLOBLEN' MODULE_NAME 'pwIBUDF';

* Usage *

SELECT BLOBLEN(someblobfield) FROM sometable

I expect to get a list of lengths of a particular BLOB field in the
table. In reality, I get an error on Firebird 1.5, 2.1 and 2.5. Error
log of FB 2.5 says:

The user defined function: BLOBLEN
referencing entrypoint: BLOBLEN
in module: pwIBUDF
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.

Which seems rather strange, considering that Firebird was supposed to
pass me a valid BLOB descriptor - and in fact, in a similar function
(but one which returns BLOB contents as a string) apparently does.

I'd welcome any pointers (no pun intended).

Thanks,

Josef