Skip to content

Database Command Group

The Database commands provide the facility to find, save, and delete records in tables, and to maintain relationships between and among records. You can read more about these commands in the DataFlex Language Reference.

Commands List

attach
file_mode
clear
fill_field
close
find
constrain
is_file_included
constrained_clear
open
constrained_find
relate
constraint_set
save
constraint_validate
saverecord
copy_db
sort
copy_records
vconstrain
declare_datafile
vfind
delete
zerofile
delete_db

Database Commands and the File List

The Database commands use information contained in the header of the data file and in the data file’s entry in the file list. The data file contains data on each table's number of columns, column length and type, decimal formatting on numeric columns, etc. All DataFlex operations can "look up" the values of these table parameters whenever needed. This precludes the necessity for each program to maintain table-specific data and substantially reduces application development time.

The open command is key among these commands. None of the other commands can be executed on any table that has not first been opened. The file_mode command affects the way in which the table is opened—whether for only one user, for read-only, or for reading and writing access by more than one user concurrently (the default). When a table has been made the argument of a close command, it is no longer open. The declare_datafile command permits program source code to address a table and its columns at a point above the point in source code where the table is actually opened. This permits optimization of the program's performance at run time.

Many of the commands can address database files by either the file's DataFlex name or by its number, both of which are defined in the file list. The chief reason for this facility is for purposes of addressing non-native files, which may lack some of the components making up the file.field format customary for native files.

Where the DataFlex name of the file is known, its number may be used by an easier means. The keyword file_number may be used appended to the DataFlex filename with a period (.). The number of the file accounts, for example, can be addressed as the system variable accounts.file_number. For this to work, the file must either have been declared with the declare_datafile command or opened at some point previous (in source code) to use of the system variable. It does not have to be open (it may be closed) at the time of use of the system variable in either case.

Many of the commands can act on up to nine tables explicitly named as arguments (separated by spaces) on the command line. However, some commands (clear, delete, and saverecord) affect only the table(s) named on their command lines, while the others (attach, relate, and save) reach up to the parent table(s) of the table(s) named on their command lines.

These remaining commands are inherently multi-user in nature, subject to the requirement mentioned above that no table is affected that is not open. Attach and save (which contains an attach) bring the values of columns in the open parent table(s) to which columns(s) in the table(s) named on the command line relate, while relate reaches all the way up the parentage chain to all open ancestors of each named table to find a record in each table whose column data matches the data in the columns of each child table on which the relationship is based.

Finding and constraining commands are of two basic types: fixed and variable. Those of the variable type have names beginning with "v." These variable commands can be dynamically bound to any table at run time. The fixed commands can be used only on the table for which each is programmed, using the mode (greater than, less than, equal to, etc.) programmed. The constraining commands provide a "filter" facility in which, while the constraints are in effect, only those records of a table whose data satisfied the constraints are "seen" by the program. This can greatly enhance performance in finding-intensive applications.

The following is a discussion of how the commands in that group can be used to manipulate the database in various ways.

In most real-life situations, the best way to utilize the database is to use program modules called views that contain one or more data-server objects to control access to the database, and one or more data-entry objects to provide an interface for users.

These objects deploy in your programs a sophisticated, extensive system to link the database to entry forms with numerous internal procedures, including a set of predefined accelerator-key procedures. They interconnect the screen buffer with the record buffer in a manner designed to maintain data integrity throughout sets of related tables.

The dynamics described in this section represent a subset of what must be done by any program that uses the database. Use this section to acquire an understanding of how programs use the database. Do not infer recommended coding techniques for real-life applications from the basic code examples shown.

See Also