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 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 dbf 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 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 fields:

[Visual FoxPro Table Designer for a database table]

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. A Visual FoxPro system can run in parallel with an older system and share the same data files and respect the same record-locking strategies.

You can use ODBC or OLE to connect to any database with a suitable driver. 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


Hints & tips

The textbox class in Visual FoxPro 9 has a new Autocomplete property which shows the user the previous values that have been entered in that textbox.
Autocomplete in VFP 9

Your Access database will look more impressive if you add custom toolbars...
Custom toolbars

FoxPro has always had functions to read and write files at a low level...
Foxpro low level file functions

More...
More pages of hints and tips for users of Microsoft FoxPro and Access databases.

Site Map