4D v13.4

Principles for searching in 4D

Home

 
4D v13.4
Principles for searching in 4D

Principles for searching in 4D  


 

 

Searching (or "querying") is one of the most common database operations. It is often the most convenient way to select the records with which you want to work. 

The term searching refers to finding a group of records in the database based on the contents of one or more fields. You perform a search by specifying a query. A query is the set of instructions that tells 4D which records to include in the new current selection, such as “Company Name is equal to 4D.”

A query always has three elements: field name, comparison operator, and value. The field name is from the current table or a related table. The comparison operator tells 4D how to compare the contents of the field to the value you specify (equal to, greater than, less than, and so forth). The value specifies the number, string, or other value to which each record is compared.
Suppose you want to see all the records for employees with salaries greater than $30,000. The query you would use is “Salary is greater than 30000.” “Salary” is the field, “is greater than” is the comparison operator, and “30000” is the value.
When you search a database, 4D compares the contents of the field in the query to the value you specify. The new current selection is made up of records that satisfy the rules stated in the query. The new current selection can be no records, one record, a group of records, or all the records in the table.

You can perform a query while you are using either an input or an output form. If you perform a query while you are using an input form, the first record in the new current selection is shown in the input form. You can view, modify, or print the record. 

If the new current selection consists of more than one record, you can move through the records using the navigation buttons (Previous Record, Next Record, First Record, Last Record). If you modify a record before pressing a navigation button, 4D will save the modifications to disk. In relational databases, you can search in fields from other tables, provided that a relation between the tables has been established.

If you do the query while using an output form, the new current selection is displayed in the output form. You can reset the current selection to all the records in the current table by choosing Show All from the Records menu. 

Note: If a field in the database structure is not used in the current database, the database designer can elect to hide the field by giving it the Invisible attribute. Only tables and fields which are visible appear in the Query editor. For more information about this property, refer to the “Attributes” sections of Table properties and UNREGISTER CLIENT.

4D provides several powerful editors for searching a database. You can use any of the search tools to create a query. Records that meet the condition become the new current selection.
You can choose any search method when you are using either an input or output form.

In the Design environment, the Records > Query menu as well as the menu associated with the Query button of the 4D tool bar provides four menu commands related to searching. Each menu command displays a different dialog box or window or provides different options. They differ in the types of queries they carry out and the way in which the current selection is displayed.

In the Application environment, the windows of these dialog boxes are available via language commands found in the “Queries” theme. 

These four menu commands represent four different search methods:

  • Query... (QUERY and QUERY SELECTION language commands): displays the Query editor of 4D. It is a general-purpose search dialog box that can be used to perform simple or compound queries. You can specify compound queries using the conjunctions. You can also save queries to disk and restrict the query to the current selection.
  • Query by Example... (QUERY BY EXAMPLE language command): displays the current input form for use as a search window. You specify a query by typing the values for which you want to search in the areas corresponding to the fields to be searched. You can specify compound queries by typing values into more than one area. The results of your query are displayed in the current output form.
  • Query and Modify...: identical to the Query by Example... menu command, the difference being that the first record of the selection from the query is loaded, ready to be modified. You can make changes and then browse among found records in order to modify them one by one.
  • Query by Formula... (QUERY BY FORMULA and QUERY SELECTION BY FORMULA language commands): displays the Formula editor of 4D. You use the Formula editor to construct a query that uses a formula as the query. For example, you can use Query by Formula to search on the last three digits of a six-digit part number. A valid formula returns a Boolean expression (TRUE or FALSE).

 
PROPERTIES 

Product: 4D
Theme: Searching records