Fields, Strings and Dates

Chapter Updated 04/28/23




The main objective of this chapter is to provide basic information regarding various field types supported by the library.

Field names can be up to ten bytes in length and can contain characters, numbers or special characters in the name. The field methods are used to manipulate the data in a record of a data file. There are several types of fields.

Field Types

TypeSizeAllowable ValuesSchema Value
Numeric0 - 17(include sign and decimal point+ - . 0 through 9XB_NUMERIC_FLD
Character0 - 254AnythingXB_CHAR_FLD
Date8CCYYMMDDXB_DATE_FLD
Floating Point0 - 17 (includes sign and decimal point+ - . 0 through 9XB_FLOAT_FLD
Logical1? Y y N n T t F f (? - uninitialized)XB_LOGICAL_FLD
MemoFixed length portion - 10
Variable length 0 - 32760
Type III - Text
Type IV - Anything
XB_MEMO_FLD


Field names, types and lengths are defined when a data file is created. After the file is created, the field characteristics can not be changed. To change field characteristics, a new database table must be defined with the new field requirements.

Memo Fields

Memo fields are variable length data fields which are stored in two parts. This first part is a ten byte field which is stored in the fixed length record of the .DBF file. The variable data is stored in a seperate .DBT file in 512 byte blocks. The ten byte field in the fixed length portion of the record points to a .DBT block number.

There are two versions of memo data files type III and type IV. Type IV is more advanced in that released space can be reused and it also supports BLOB data. The type III file is older technology, does not support dynamic space reclamation and only supports string data. See method xbDbf::SetVersion for controlling which version type you are using.

To utilize memo fields, the application program must allocate a buffer which is large enough to handle the memo data.

Fields and Field Numbers

The Xbase routines can access field data via using field names or field numbers. Field numbers are numbered 0-n where the first field in a datafile is field 0 going through the last field n. Accessing fields by number is slightly more efficient than accessing by name.

Strings

Xbase64 includes support for a string class xbString. The xbString class interface was originally derived from the Draft Standard C++ Library by P.J. Plauger and modified. If you are familiar with other string classes, this one should be similar. Strings can be used to manage strings of character data.

Date Fields

All dates are stored in the .DBF files as Gregorian dates with format CCYYMMDD.

The library date routines work with dates formated with the same CCYYMMDD format.

Null Dates

Date fields in the database stored as eight spaces are considered null dates.

Leap Years

A leap year is a year having 366 days, which can be evenly divisible by 4 and not by 100 or divisible by 400. There are also leap centuries. Leap centuries are years which are evenly divisible by 400.

Julian Dates

The Julian date routines calculate a Julian date as the number of days since 01/01/0001 with an offset of 1721425L.

Julian dates are useful for doing date arithmetic such as determining the difference between two dates or calculating a future or past date.

To determine the difference between two dates, convert both dates to a Julian date and subtract one from the other.

To calculate a future or past date, convert the base date to a Julian date, add (or subtract) the number of days necessary to (from) it and convert the Julian date back to a Gregorian date.