Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable length records

Status
Not open for further replies.

delphidestructor

Programmer
Oct 20, 2000
67
What would be the proper (or best) way to set up field definitions on a Btrieve file with variable length records? The file contains, base size 12, packed records with 3 – 4 byte integer fields and an array {1 – 1000} of 10 byte packed records containing an 8 byte double and a 2 byte unsigned integer. Basically, how should I define the 10,000 bytes after the base 12, short of res1,stat1,res2,stat2,res3,...? The indexes obviously are all on the 4-byte integers and no queries will be executed on the array values. Any thoughts would be greatly appreciated.
 
I suggest you create your file with the 3 integer fields, plus a LongVarBinary. From a Btrieve perspective, this will make your fixed record length 20, and Variable=Yes. This accommodates 4 bytes for each integer, plus an 8-byte field for the longvarbinary.

If you are using the Btrieve API to insert data, you would structure your data buffer as
int1 integer;
int2 integer;
int3 integer;
lvblength integer;
lvboffset integer;
lvbdata byte array of 10000;

When inserting data, you would set lvblength = 10000, or, if you only plan on filling in part of the 10000 bytes, you can set it to a smaller number. You would set lvboffset = 20, since the lvbdata always starts at offset 20 in this example.

If you want to do multiple LongVarBinary fields, you need an 8-byte place holder (for length & offset) in the fixed portion of the record for each lvb field. You need to set the lengths & offsets accordingly to match the data segments in the variable portion.

I suggest you do a little test via PCC. Create a table with the following SQL Statement:
CREATE TABLE lvbtest using 'lvbtest.dat'
(int1 integer not null,
int2 integer not null,
int3 integer not null,
lvb longvarbinary not null)

Then, insert a couple of rows:
insert into lvbtest values(1, 2, 3, '12345')
insert into lvbtest values(4, 5, 6, '1234567890123456')

Use Function Executor to look at the resulting Btrieve records. For the first one, you should see the following 23 hex bytes (remember about all the byte swapping...):
01 00 00 00 02 00 00 00 03 00 00 00 03 00 00 00
14 00 00 00 01 23 45

The first 12 bytes correspond to the three integers. Then, you have the next four bytes set to the value 3 representing the longvarbinary length. Then the next four bytes are set to the value 20 (0x14) representing the 0-based offset for the start of the longvarbinary. Then, you have three bytes of longvarbinary data. Your Btrieve application would need to simulate this same behavior.

 
Thank you for taking the time to help Linda. I will start working on this. Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top