posted 15 years ago
Just started on my assignment ( Bodgitt & Scraper ) and wanted to make sure I have understood the relationship between the �Data file Format� and �Database Schema� Below is the contents:-
Data file Format
================
The format of data in the database file is as follows:
Start of file
4 byte numeric, magic cookie value identifies this as a data file
4 byte numeric, offset to start of record zero
2 byte numeric, number of fields in each record
Schema description section.
Repeated for each field in a record:
2 byte numeric, length in bytes of field name
n bytes (defined by previous entry), field name
2 byte numeric, field length in bytes
end of repeating block
Data section. (offset into file equal to "offset to start of record zero" value)
Repeat to end of file:
2 byte flag. 00 implies valid record, 0x8000 implies deleted record
Record containing fields in order specified in schema section, no separators between fields, each field fixed length at maximum specified in schema information
End of file
All numeric values are stored in the header information use the formats of the DataInputStream and DataOutputStream classes. All text values, and all fields (which are text only), contain only 8 bit characters, null terminated if less than the maximum length for the field. The character encoding is 8 bit US ASCII.
Database schema
===============
The database that Bodgitt and Scarper uses contains the following fields:
Field name field name length description
----------------------------------------------------------------
Subcontractor name 32 name of subcontractor.
City location 64 locality
Types of work specialties 64 list of work type
Staff Number size 6 workers available at booking
Hourly charge rate 8 Charge per hour
Customer Id owner 8 Customer id
PS I have summarise the schema.
Given above, my understanding is that the schema defines the contents of each record and each record will contain the fields � size in bytes in brackets � name(32),location(64),specialties(64),size(6),rate(8) and owner(8). Therefore, each record will occupy 182 bytes.
My view of the database file contents is shown below. The first column is address offset, in decimal, relative to the beginning of the file.
0000 4 bytes � magic cookie
0004 4 bytes � offset to start of record zero
0008 2 bytes � number of fields in each record. This should be
six ( name, location,specialties, size, rate, owner )
0010 2 bytes � name field length. This will be set to 32.
( This is start of record zero )
0012 32 bytes � number of bytes for name field
0044 2 bytes � location field length. This will be set to 64.
0046 64 bytes � number of bytes for location field
0110 2 bytes � specialties field length. This will be set to 64.
0112 64 bytes � number of bytes for specialties field
0176 2 bytes � size field length. This will be set to 6.
0178 6 bytes � number of bytes for size field
0184 2 bytes � rate field length. This will be set to 8.
0186 8 bytes � number of bytes for rate field
0194 2 bytes � owner field length. This will be set to 8.
0196 8 bytes � number of bytes for owner field
0204 2 bytes � name field length. This will be set to 32.
( This is start of record ONE )
0206 32 bytes � number of bytes for name field
0238 2 bytes � location field length. This will be set to 64.
0240 64 bytes � number of bytes for location field
0304 2 bytes � specialties field length. This will be set to 64.
0306 64 bytes � number of bytes for specialties field
0370 2 bytes � size field length. This will be set to 6.
0372 6 bytes � number of bytes for size field
0378 2 bytes � rate field length. This will be set to 8.
0380 8 bytes � number of bytes for rate field
0388 2 bytes � owner field length. This will be set to 8.
0390 8 bytes � number of bytes for owner field
398 2 bytes � name field length. This will be set to 32.
( This is start of record TWO )
1) Please confirm or correct my understanding above.
2) Also, can you explain the following snippet from the Data File format :-
�Data section. (offset into file equal to "offset to start of record zero" value)
Repeat to end of file:
2 byte flag. 00 implies valid record, 0x8000 implies deleted record�
3) Finally, the 4 byte cookie value, is that fixed in the data file and what is its purpose ?
Thank you for your help.
Pete