Using Basic Database ActionsSearch, Insert, Update, and Delete ActionsTango includes several fundamental database actions that allow you to search (Search action), add (Insert action), modify (Update action), and delete (Delete action) database records. The topics covered in this chapter include setting up and executing Search, Insert, Update, and Delete actions. Searching a DatabaseSearch actions retrieve database records matching a given criteria. You use the Search action editing window to define what columns are selected, the order of the data retrieved, and the criteria that determine which rows are found.
You use the action's Results HTML to format the results of the search. Setting Up a Search ActionWhen you drag the Search action icon from the Actions palette into an application file, the Search action editing window appears. The window consists of four sections. The Select, Criteria, and Results sections are covered in this chapter. The Joins section is covered in Working With Joins. Select TabYou use the Select section to select the type of search to perform, the columns to retrieve, and the ordering of the records returned. You can perform three types of searches with a Search action: Normal, Summaries of Groups, and Summary of All Rows. Select which type of search you want to perform from the Select Type pop-up menu .
Normal SearchThe Normal type of search returns rows matching specified criteria. This is the most common type of search. When you select Normal from the Select Type pop-up menu, the Select section appears. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
Summaries of GroupsThe Summaries of Groups search type returns summaries for groups of rows with the same values in specified columns. For example, it allows you to find out the total sales for each sales region in an invoices table by selecting the sum of invoice amounts and grouping by sales region. When you select Summaries of Groups, the Select section appears.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
Summary of All RowsTo get a summary of all rows matching a specified criteria, use the Summary of All Rows search type. Only one summary row is returned. For example, you could use this search type to find the average amount of all orders in an orders table. As with the Summaries of Groups search type, each select column has an associated function that determines how that column is summarized. All the column values in the rows matching the criteria are aggregated using the specified function. Criteria TabThe Search action criteria determine which rows from the database are returned by the action. If no criteria are specified, all rows are returned; otherwise, each row in the database is compared to your criteria and only those meeting them are returned . To specify the criteria, drag columns from the Data Sources Workspace to the Criteria list. For each column, you must specify:
ColumnIn the Column field, specify the column whose value you want to compare. Drag the column from the Data Sources Workspace. Logical OperatorThe first field in the criteria list is the logical operator, which is either and or or. To specify the operator, do one of the following: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
The logical operator determines whether the current and previous criteria must be true for a record to be included in the result or whether a match on either the current or previous criterion causes a record to be included in the result. For example, if your criteria are:
cust_num = 5100
and cust_name Begins with A
only records matching both criteria are returned. If the logical operator is changed to or, records matching either one of the criteria are returned. There is an implied order of operation for logical operators. Criteria joined with the and logical operator are evaluated before those joined with the or logical operator. For example, in the following criteria:
cust_num = 5100
and cust_name Begins with A
and cust_state = NY
a match is made if both the second and third criteria are true or the first criterion is true. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
For more information about inserting meta tags in entry fields, see "Inserting Meta Tags". |
You can also use the Insert Meta Tag command to enter in the Criteria window entry fields many of the commonly used meta tags. To insert a meta tag, either click the field and choose Insert Meta Tag from the Edit menu, or control+click the field and choose Insert Meta Tag from the contextual menu that appears. |
||||||||||||||||||||||||||||||||||||||||||||||||||||
You can use criteria separators to control the order of criteria evaluation, regardless of this default logical operator hierarchy. OperatorIn the operator field (Oper.), specify the operator to use when comparing the field by doing one of the following: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
Text columns permit the use of any operator; for other columns, the Contains, Begins with, and Ends with operators are disabled. You can either specify a static operator or insert a meta tag to get the value at execution time. Using a variable operator allows you, for example, to put a pop-up menu on your Web page to let users choose the comparison operator. When using a variable to specify the criterion operator, Tango requires you to use special values to represent each of the operators. The following table lists these special values:
For example, to create an operator pop-up menu in an HTML form whose value you want to use as the operator in a search criterion, you could use HTML similar to the following: <SELECT NAME="cust_name_op"
SIZE=1> and set the operator in the Search action to The Is In operator needs some additional explanation. It matches records where a column value is in a list of values. For example, the following criteria: matches records in which the cust_num field has a value of 200, 300, or 400. The Is in operator can be thought of as a shortcut for a series of OR equals criteria: cust_num = 200 The value specified can be a single-column or single-row array (as would be returned by the <@ARG> tag with a type attribute of ARRAY, for example) or a comma-separated list of values. ValueIn the Value field, enter the value to use in the comparison. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
For more information about inserting meta tags in entry fields, see "Inserting Meta Tags". |
The value can also contain any value-returning Tango meta tags, which are substituted when the application file is executed. Use the Insert Meta Tag command to enter many of the commonly used meta tags. Include EmptyIn the Incl. Empty field, specify whether the criterion is included, even if the comparison value is empty, by doing one of the following:
The values appear as false and true. false omits the criterion if the value (after meta tag substitution) is empty; true includes the criterion regardless of the value's contents. This option is used mainly for columns whose search value is taken from a search form on a Web page. For example, you may have a search form that allows you to enter search values for several columns, but you want the search done only on the columns you enter values for. To do this, set the Incl. Empty option for each of the corresponding Search action criteria to false. There are cases where you do want a criterion included, even if the value is empty. For example, suppose you have a Web page that asks for a user name and password, and a corresponding Search action that finds the user in a users' database. In the Search action, you probably want to set the Incl. Empty option for each of the values to true. If you do not, and the user leaves both fields empty, the Search action omits both criteria and returns all user records. |
||||||||||||||||||||||||||||||||||||||||||||||||||||
For more information about inserting meta tags in entry fields, see "Inserting Meta Tags". |
You can control+click the Incl. Empty field, and choose Insert Meta Tag from the contextual menu that appears to enter many of the commonly used meta tags. Quote ValueIn the Quote Value field, specify whether Tango puts quotation mark characters around the value in the SQL it generates for this criterion by doing one of the following:
The values appear as false and true. For text, date, time, and timestamp columns, you should set this option to true. For date, time, and timestamp columns, this option has special meaning. true converts the specified value from the default Tango format to the format required by the database server; false passes the value specified as is to the database server. If you want to use an expression that the database server evaluates (instead of a literal Tango-supplied value), set the Quote Value option to false and enter the expression in the Value field. For numeric and Boolean types, you should set the Quote Value option to false. |
||||||||||||||||||||||||||||||||||||||||||||||||||||
For more information about inserting meta tags in entry fields, see "Inserting Meta Tags". |
You can control+click the Quote Value field, and choose Insert Meta Tag from the contextual menu that appears to enter many of the commonly used meta tags.
Criteria SeparatorsTo group criteria, select the position between the criteria you want to group and do one of the following:
Only the logical operator cell can be edited for separator items . Upon execution, the criteria before the separator are combined with the criteria after the separator using the logical operator specified in the separator line in the criteria list. Executing a FileMaker Pro Script in a Search Action
If you are using a FileMaker Pro data source with your Search action, you can execute a FileMaker Pro script in the Criteria section. (The Criteria section is different for FileMaker Pro data sources; it contains a field where you can enter the name of a FileMaker Pro script.) To use a FileMaker Pro script |
||||||||||||||||||||||||||||||||||||||||||||||||||||
You can
also execute a FileMaker Pro script directly in a Direct DBMS action; see
"Executing a FileMaker Pro Script (Direct
DBMS Action)". |
The scripts in the pop-up menu are the scripts that are defined in the FileMaker Pro data source you are connected to. The script to be executed can also be specified by entering the name manually in the field provided. The script you specify executes when the Search action is executed and the found set at the end of the script's execution determines which records are returned. When using a FileMaker Pro script to print, your script must first bring FileMaker Pro to the front. FileMaker Pro does not print if it is in the background (even if the "Perform without dialog option" is set for the command). Use a Perform AppleScript command in the ScriptMaker and specify activate application "FileMaker Pro 3.0" (replace the value in quotes with the exact name of your FileMaker Pro application) as the script text. When printing is complete, restore your Web server to the foreground by using the same command, but with the name of the Web server application. Results Tab
In the Results section, you specify the maximum number of records to retrieve from the data source, at which result record number retrieval begins, and whether Tango gets the count of matching records . Number of rows to retrieve
To return all matching records, select No Maximum. To limit how many records you want the search to return, select Limit To and enter the maximum number of records to retrieve. Start retrieval at row number
Select this option if you want to skip some of the matching records. Specify the row number you want the Search action to start retrieval at. The default is "1". When the value is other than "1", the Search action returns records starting at that number, skipping any records before it. This option is most useful when you use a variable (such as <@SEARCHARG start>) for the starting record number. |
||||||||||||||||||||||||||||||||||||||||||||||||||||
For more information, see "Show Multiple Pages If Limit Exceeded".. |
For an example of how to use this option to provide results paging for large result sets, look at the Search action in a Search Builder-generated file created with the Show Multiple Pages If Limit Exceeded option selected. Retrieve distinct rows onlyIf you select this option, Tango Server adds the DISTINCT keyword after the SELECT keyword in the generated SQL. The DISTINCT keyword specifies whether duplicate rows are to be eliminated from the result set. For example, SELECT c1.cust_state, c1.cust_zip SELECT DISTINCT c1.cust_state, c1.cust_zip Get total number of matching rowsYou use this option to retrieve the number of records matching the search criteria, irrespective of how many records are actually retrieved. Using this option, you can access the value in the Search action's Results HTML by using the <@TOTALROWS> meta tag.
Executing a Search ActionWhen Tango Server executes a Search action, the search is performed against the associated data source. The result rowset is automatically stored as an array in the local variable resultSet. The Results HTML for the Search action is then processed. |
||||||||||||||||||||||||||||||||||||||||||||||||||||
For more information, see "<@ROWS> </@ROWS>", "<@COL>", and "<@COLUMN>" in the Meta Tags and Configuration Variables manual. |
The HTML in the <@ROWS><@/ROWS> block, if any, is processed once for each record in the results. Use <@COLUMN> or <@COL> meta tags to include field values. If the Search action generates no results, and you have specified No Results HTML for the action, that HTML is processed instead of the Results HTML. Adding Records to a DatabaseThe Insert action adds a record to a table in a database. Setting Up an Insert ActionWhen you drag the Insert action icon from the Actions palette into an application file, the Insert action editing window appears. To set up an Insert action
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
For more information about inserting meta tags in entry fields, see "Inserting Meta Tags". |
To insert a meta tag, either click the field and choose Insert Meta Tag from the Edit menu, or control+click the field and choose Insert Meta Tag from the contextual menu that appears. |
||||||||||||||||||||||||||||||||||||||||||||||||||||
The Quote Value option operates the same as it does in search criteria. Executing an Insert ActionWhen Tango Server executes an Insert action, a record is added to the database with the column values specified. The Insert action returns no results. Modifying a Database RecordThe Update action modifies database records matching specified criteria. Setting Up an Update ActionWhen you drag the Update action icon from the Actions palette into an application file, the Update action editing window appears. To set up an Update action |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
For more information about inserting meta tags in entry fields, see "Inserting Meta Tags". |
To insert a meta tag, either click the field and choose Insert Meta Tag from the Edit menu, or control+click the field and choose Insert Meta Tag from the contextual menu that appears. If you always want to update a column with a fixed value, simply enter that value. |
||||||||||||||||||||||||||||||||||||||||||||||||||||
The Quote Value option operates in the same way it does in search criteria.
Executing an Update ActionWhen Tango Server executes an Update action, Tango searches for records matching the specified criteria and updates them with the specified column values. The Update action returns no results. Removing a Database Record |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
The Delete action removes database records that match the specified criteria. You edit the criteria list the same way you edit the Search action's criteria list. Setting Up a Delete ActionTo set up a Delete action
Delete actions using FileMaker Pro data sources allow fields from any number of layouts. You must specify at least one criterion for the Delete action to be valid.
Executing a Delete ActionWhen Tango Server executes a Delete action, records matching the specified criteria are deleted. The Delete action returns no results. Adding Custom Columns to Database ActionsA custom column entry lets you enter any text as the column reference. You can use custom columns wherever Tango accepts columns dragged from the Data Sources Workspace. Make sure the text entered makes sense in the database action. For example, in a Search action, you could enter the following calculation as a Select column: To add a custom column to a database action
|
Copyright © 1999, Pervasive Software. All rights reserved.