VFP Tutorial - Databases

Table files

FoxPro stores its data as a collection of individual files which improves performance on small databases. Performance is better than Access because the program does not need to bring all the data from all the tables across the network just to retrieve a single item. Integrity is better because a network error or a power failure might corrupt a single table but all the rest will survive.

The disadvantage is that the individual files rely on each other. The header of the dbf file records the fact that it requires a cdx file for its index. It is not unknown for a careless user to delete the cdx file so that FoxPro cannot open the dbf; or to backup and restore nothing but the data in the dbf file so that the old index does not match the restored data.

These are minor issues that do not arise once users and administrators know of the file types involved.

The FoxPro data format has always been public. If you type help file structure then you will reach a series of pages which give the byte structure of all the types of file used by Visual FoxPro. You may go many years without needing this information but it is reassuring to know that it is available.

Database

The first versions of FoxPro up to FoxPro 2.6 used flat tables but Visual FoxPro added features which organised these tables into a relational database. The information about the links between tables, the relational integrity and the stored procedures are stored in a Database Container file with a .dbc extension. When a table is part of a database the Table Designer is extended with new controls which set the extra options:

[Database options in the VFP Table Designer]

This screen shot shows the extra validation available for each field on the Fields page of the Table Designer. The Table page includes validation for the record as a whole and triggers which run stored procedures when a record is added, altered or deleted.

Compatibility

The FoxPro data format changed when the database features were added because every dbf had to have an entry in its header holding the name of the database file. There are now two dbf formats, one for databases up to FoxPro version 2.6, the other for Visual FoxPro 3 onwards. Earlier versions of FoxPro do not recognise the new format but Visual FoxPro can use and create tables in the old format. Compatibility is complete and a Visual FoxPro system can run in parallel with an older system. It can share the same data files and the two systems respect the same record-locking strategies.

FoxPro is not restricted to using dbf files. You can use ODBC or OLE to connect to any database which has a suitable driver. Tables from these external databases respond to all the FoxPro data manipulation commands. If you prefer you can also call the ADO and DAO libraries from within FoxPro programs for tasks such as the maintenance of an Access database.


Introduction | Environment | Project | Tables | Forms | Navigation | Executable

MS Access technical tips

Visual FoxPro technical tips

General Tips

 

More tips from Alvechurch Data

Visual FoxPro Tutorial - The Goto statement

The truth about the FoxPro Goto statement

Read More

Visual FoxPro Tutorial - If ... Else ... EndIf

Using If EndIf to control program flow in Visual FoxPro

Read More

Visual FoxPro Tutorial - Navigation

Navigating between records in Visual FoxPro

Read More

Visual FoxPro Tutorial - Scan ... EndScan loop

Using a scan loop to control program flow in Visual FoxPro

Read More

Visual FoxPro Tutorial - Variables

Using variables in Visual FoxPro

Read More