Using Basic Database ActionsSetup and Operation of Search, 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 Action |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
When you drag the Search action icon from the Actions bar into an
application file, the search action editing window appears. The window
contains tabs for the three main groups of settings for a Search action:
Select, Criteria, and Results.
For details on the Joins tab, see xref. [working with joins, chap 18] Select TabYou use the Select options to select the type of search to perform, the columns to retrieve, and the ordering of the records returned. You can perform three main 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 drop-down list.
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 drop-down list, the Search action's Select window appears. Specify values for the parameters in the Select window as follows: |
||||||||||||||||||||||||||||||||||||||||||||||||||||
You can include columns from multiple tables; if you do, you must define joins to describe how the tables are related.
The order of the columns in the list determines the ordering hierarchy. For example, if the first order column is "state or province" and the second "customer name", the results are first ordered by state or province; customers in the same state or province are then ordered by name. The triangle to the left of the column name
determines whether the ordering is ascending ( |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
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 choose Summaries of Groups, the Search action's Select window appears.
The following table lists the available functions. To choose the function for a column, click the Function column and select the function from the drop-down list.
For example, if you are grouping by classification and selecting the maximum order amount, you can use group criteria to limit the returned rows to those customers whose maximum order amount is greater than $5,000. To specify group criteria, choose Show Group Criteria. The Select window expands to show the area for entering group criteria. Drag columns from either the Data Sources Workspace or the Select Columns list.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
Except for the function option, you specify group criteria just like normal criteria. 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 need to 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. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
You can also right click the field, and choose Edit from the context-sensitive menu. Then choose an operator from the drop-down list that appears. |
Click the row, then click the field to display a drop-down list to choose an operator from. The operators are and and or.
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
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
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 right click the field and choose Insert Meta Tag from the context-sensitive 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. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
You can also right click the field, and choose Edit from the context-sensitive menu. Then choose an operator from the drop-down list that appears. |
Click the row, then click the field to display a drop-down list to choose an operator from. Possible operators include:
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 drop-down list 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 drop-down list 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. |
||||||||||||||||||||||||||||||||||||||||||||||||||||
You can also right click the field, and choose Edit from the context-sensitive menu. Then choose a value from the drop-down list that appears. |
Click the row, then click the field to display a drop-down list to choose a value from. 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 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 right click the Incl. Empty field, and choose Insert Meta Tag 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. |
||||||||||||||||||||||||||||||||||||||||||||||||||||
You can also right click the field, and choose Edit from the context-sensitive menu. Then choose a value from the drop-down list that appears. |
Click the row, then click the field to display a drop-down list to choose a value from. 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 right click the Quote Value field, and choose Insert Meta Tag to enter many of the commonly used meta tags. Criteria Separators |
||||||||||||||||||||||||||||||||||||||||||||||||||||
You can also right click where you want to insert the criteria separator and choose Insert Criteria Separator from the context-sensitive menu that appears. |
To group criteria, select the position between the criteria you want to group and choose the Insert Criteria Separator command from the Edit menu. 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. Results TabIn the Results window, 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 retrieveTo 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. The following options are only available for the Normal search type. Start retrieval at row numberSelect 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 FROM customer c1; SELECT DISTINCT c1.cust_state,
c1.cust_zip FROM
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></@COL>", and "<@COLUMN>" in theMeta 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 Action |
||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
When you drag the Insert action icon from the Actions bar 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 right click the field and choose Insert Meta Tag from the context-sensitve 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 Action |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
When you drag the Update action icon from the Actions bar 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 right click the field and choose Insert Meta Tag from the context-sensitve 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 RecordThe 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 Action |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
To set up a Delete action
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 © 1998, Pervasive Software Inc. All rights reserved.