What is the fastest way to ...

NDzubiel

Member²
get a text form a long ?

I am storing text > 256K in a long field within
Oracle. What is the fastest way to get
this back from Oracle into a String ?

Thanks for your help

Nils
 
I assume this is a LONG field, and not a CLOB field? If so, you can execute a select statement through a TOracleQuery to select the field, and use TOracleQuery.GetLongField to fetch it. To quote the manual:
If you know the internal structure of a Long or Long Raw, you may also exactly know its size and can fetch exactly what you need with a minimum of network roundtrips. The GetLongField method can help you with this:

Code:
GetLongField(FieldId: Integer; Buffer: Pointer; Offset, Length: Integer): Integer
If for example you know that a Long Raw column is a 16-color bitmap, you know the width and height is stored at positions 18 and 22. If you first fetch these two integers, you can determine the size of the bitmap and fetch the rest:

Code:
var wh: TPoint;
    Size: Integer;
    Bitmap: Pointer;
begin
  Query.GetLongField(BmpField, @wh, 18, SizeOf(wh));
  Size := ((wh.x * wh.y) div 2) + 70;
  GetMem(Bitmap, Size);
  Query.GetLongField(BmpField, Bitmap, 0, Size);
  ...
end;
 
The problem is, that the long contains pure text from a TMemoField. So there is size informationen.

So what's the fastest way to load it back ?

Nils
 
You can either store the length information so that you can reload it in one piece, or do incremental reads. The GetLongField function has an Offset and Length parameter that allows you to fetch a specific piece of the long value. It returns the number of bytes read, so that you know when you have reached the end. Within this loop you need to concatenate the results.

The fastest method is to store the length though.
 
Back
Top