Query objects are the center of the data model. In most cases, if you want to access a table, you must use a Query object.

Note

Alternatively, you could use a StoredProc object that returns a rowset from an SQL database, or a DataModRef object that points to a data module containing the appropriate data access code, including at least a Query or StoredProc object.

The Query object’s main job is to house two important properties: SQL and rowset.

SQL property

The SQL property’s value is an SQL statement that describes the data to be obtained from the table. For example,

select * from BIOLIFE

The * means all the fields and BIOLIFE is the name of the table, so that statement would get all the fields from the BIOLIFE table.

The SQL statement specifies which tables to access, any tables to join, which fields to return, the sort order, and so on. This information is what many people think of when they hear the word query, but in dBASE Plus, SQL statements are only one of many properties of the Query object.

SQL is a standard, portable language designed to be used in other language products to access databases. When you use the Form and Report wizards or drag a table from the dBASE Plus Navigator, dBASE Plus builds the SQL statement for you. Once a table has been accessed by the SQL statement, you can do almost anything you want with dBASE Plus’s data objects, including navigating, searching, editing, adding, and deleting.

Although knowing SQL is useful for initially configuring data objects for your databases, once these are complete and saved as custom components or in data modules, they can be reused without modification. Then others can create complete Windows database applications without knowing a word of SQL.

rowset property

A Query object is activated when its active property is set to true. When this happens, the SQL statement in the sql property is executed. The SQL statement generates a result: a set of rows, or rowset.

A rowset represents some or all the rows of a table or group of related tables.

Each Query object generates only one rowset, but you can add multiple Query objects to a form to use multiple rowsets from the same table, or for different tables. Using multiple Query objects also allows you to take advantage of dBASE Plus’s built-in master-detail linking.

The Query object’s rowset property refers to the Rowset object that represents the query’s results.