Subject Size and conversion question
Author Salvatore Besso
hello,

first of all my best Season's Greetings for all of you.

Using Delphi 7 Pro and IBO 4.5Ag. In the attempt to achieve the fastest possible
sequential read over a lengthy table, I'm testing with raw fetching using
property BufferFields.BufferRow of TIB_Cursor, putting raw data into a record
structure. I have already seen how several data-types are stored into BufferRow
but I'm puzzled with the raw format (amd size) of a NUMERIC field.

Suppose this table:

CREATE TABLE TEST(
PK_ID INTEGER,
NAME VARCHAR(15),
AMOUNT NUMERIC(3, 2));

and a record structure like this:

TRawDataRec = packed record
Null1 : Smallint; // NULL ID
PK_ID : Integer; // PK, INTEGER
Null2 : Smallint; // NULL ID
Len1 : Smallint; // Length, next field is a VARCHAR
Name : array[0..14] of AnsiChar; // VARCHAR(15)
Null3 : Smallint; // NULL ID
Amount: Double // NUMERIC(3, 2)
end;

var
Buffer: TRawDataRec;

Then I use:

Cursor.APIFirst;
while not Cursor.Eof do
begin
Move(Cursor.BufferFields.RowBuffer^, Buffer,
Cursor.BufferFields.BufferLength);
Elaborate;
Cursor.APINext
end;

As you can easily verify, the size of my structure is 35 bytes, but if I inspect
BufferFields.BufferLength it says 29 bytes, that's to say 6 bytes less than my
structure. Inspecting the Buffer variable all fields up to Name show correctly.
I think this is due the format of raw data for the NUMERIC field. Is it variable
depending on length and decimal places and less than a Delphi Double?

What I'd like to know is how to get the correct size of such fields in BufferRow
to correctly form my data structure and a sample code to convert these raw
NUMERIC data into a Delphi Double, because I think that these raw data are not
directly assignable to a Delphi Double.

I have tried to give a look at the implementation of the various getter
functions that are bound to the As... properties, but I've lost myself in the
intricacy of the IBO code :-)

Thanks in advance
Salvatore