CLIPPER 5.0 SUPPORT BULLETIN #9 BULLETIN REVISED: 22nd Jan, 1992 PRODUCT: Clipper 5.0 AFFECTED VERSIONS: 5.01 SUBJECT: Clipper File Structures DATABASE (.dbf) FILE FORMAT --------------------------- All numbers are expressed in decimal unless otherwise noted. (.dbf) HEADER STRUCTURE Offset Format Contents ------ ----------- -------------------------------------- 0 03 or 083h Signature Byte: 03--(.dbf) with no memo (.dbt) file 131 (083h)--(.dbf) with memo (.dbt) file 1 Year Last update year without century (1991 = 91) 2 01 to 12 Month of last update 3 01 to 31 Day of last update 4-7 long Number of records 8-9 word Location in file where data begins (START) 10-11 word Record length (field sizes plus 1) 12-31 N/A Reserved Field definitions begin at byte 32 and are 32 bytes long. The last field structure is followed by a constant 13 (0Dh) and a constant 0 (00h) indicating the end of the field structures. This is a deviation from the dBASE III+ format, which does not have the 0 (00h) byte. Each field structure is composed in the following manner: FIELD DEFINITION STRUCTURE (Repeat for each field) Offset Format Contents ------ ------------ ------------------------------------- 0-10 character Field Name (printable string; no spaces; NUL terminated; NUL padded) 11 character Field Type (Character, Logical, Memo, Numeric, or Date) 12-15 N/A Reserved 16 unsigned int Total length, including decimal for numerics (referred to in text as LENGTH) 17 unsigned int Number of decimal places 18-31 N/A Reserved At START (defined above), the record data begins. Each field is stored sequentially according to the order in the header. Before each record is a deleted flag which is either a space or an asterisk ("*"). If the deleted flag is an asterisk, the record is assumed to be deleted. The field length specified in the header includes the deleted flag. Below is a brief definition of each field type, and the method of storage employed. Character (Field Type = "C") Character fields may contain any ASCII character from 0 to 255, and are always of a static length (defined by LENGTH in the field structure definition). Note that the string is not NUL terminated. An empty character field contains all spaces (32, 20h). Numeric (Field Type = "N") Numerics are stored as character equivalents with the decimal included. There is no decimal character if the number of decimal places is zero. Empty numerics are padded with leading spaces, have a zero before the decimal point, and zero padding after the decimal point to the end of the field. An empty numeric of length 9 with 2 decimals would look like this: " 0.00". Logical (Field Type = "L") Logical fields are stored as a single character. "T" is stored for true. All other characters are assumed to equate to a false value (though "F" is most likely to be used). An empty logical contains an "F" character. Date (Field Type = "D") Date fields are exactly eight characters in length. A date field is stored in the format YYYYMMDD where YYYY = Year with century, MM = Month, and DD = Day. 10/20/82 would be stored as "19821020". Memo Fields (Field Type = "M") Memo fields are always ten bytes in length. The ten bytes hold a pointer to the first 512 byte block in a (.dbt) file that contains the memo text. The pointer is in ASCII--all spaces indicates that there is no memo text for that field. ---------------------------------------------------------- MEMO (.dbt) FILE FORMAT ----------------------- Clipper (.dbt) files are no different than dBASE III+ (.dbt) files. They are treated as if they are an integral part of the (.dbf) file. If the (.dbf) is moved, the (.dbt) is moved also, etc. Memo files are divided into 512 byte blocks. The first block is a header and has a very simple format: (.dbt) FILE HEADER STRUCTURE Offset Format Contents ------ ------ --------------------------------------- 0-3 Long Number of 512-byte blocks in the file, including the header 4-511 Unused Reserved The data blocks also have a simple format: they simply contain the data terminated by a Ctrl-Z (01Ah, 26 decimal). Memos may be up to 64K in length. If the memo field does not contain an even multiple of 512 bytes, the unused remainder of the block is padded to 512 bytes with spaces. ---------------------------------------------------------- INDEX (.ntx) FILE FORMAT ------------------------ Clipper uses a modified B+-Tree style index structure. Each file consists of pages that are 1024 bytes long. The first page is a header which has the following structure: INDEX (.ntx) FILE HEADER STRUCTURE Offset Format Contents ------ ------ ------------------------------------------ 0-1 Word Signature Byte 03 = Index file 2-3 Word Clipper indexing version number 4-7 Long Offset in file for first index page 8-11 Long Offset to an unused key page 12-13 Word Key size + 8 bytes (distance between key pages) 14-15 Word Key size 16-17 Word Number of decimals in key (if numeric) 18-19 Word Maximum entries per page 20-21 Word Minimum entries per page or half page (The first, or root page of an index has a minimum of 1 entry regardless of this value) 22-277 256 Key expression, followed by CHR(0) bytes 278 Byte 1 if index is unique, 0 if not. 279 744 Filler (pads to 1024) bytes Index key pages consist of the following structure: INDEX KEY PAGES Offset Format Contents --------- ------------- ------------------------------------ 0-1 Word Number of used entries on this page (this number will be between the Minimum and Maximums defined in the header unless it is the root page) 2 unsigned ptrs An array of unsigned longs begins here. The array length is equal to the maximum number of key entries per page +1. They contain offsets onto the page where the key values (ITEMS) are located. Remainder of page ITEM entries (described below) Following the array of unsigned pointers to offsets in the page are the key value entries. These so-called ITEM entries describe a key value and its record's position in the database. The key value is always stored as a character string, regardless of its type. ITEM Entry Structure Offset Format Contents ------ --------- ---------------------------------------- 0-1 Long Pointer to a page in the index file, containing keys that are prior to this key. 2-3 Long Record number in controlling database file. 4 Character Key value. This field begins at offset 4 and continues for the length of the key. Numerics are padded with leading zeros. For more information about traversing Clipper (.ntx) files, you may want to reference the following books: Spence, Rick. Clipper Programming Guide, Second Edition. (Microtrend Books, Slawson Communications, Inc.; ISBN 0-915391-41- 4) Tenenbaum, A.M. et al., Data Structures Using C. (Prentice-Hall). END: CLIPPER 5.0 SUPPORT BULLETIN #9