14. Creating a Frame at Runtime : How You Can Build a Frame Dynamically : How You Can Create the Script : How You Can Select Tables for the Option Field
 
Share this page                  
How You Can Select Tables for the Option Field
The starting frame lets the user pick a table from a list of tables presented in an option field. The initialize block contains the code that fills in the list of table choices. The DynamicFrame frame lets the user select from any table owned by the user or the database's DBA (which are available to any user with the necessary permissions).
The following statements from the sample application retrieve the name of the database's DBA from the iidbconstants catalog and release the lock taken by the select statement:
/* Get the dba name for finding the tables */
select dba_name as :dbaname
from iidbconstants;
commit;
Note:  The table iidbconstants is a view in the Ingres Standard Catalog Interface that has two columns. One column holds the name of the current user and the other holds the name of the DBA of the current database.
Before loading the table names selected at runtime into the option field, the starting frame clears any previous values from the option field. This step is necessary because you must give a value to the option field when you create it in OpenROAD Workbench. The following statement clears the option field in the example frame:
field(table_choices).ValueList.ChoiceItems.Clear();
ValueList is the attribute of the OptionField class that contains the values that appear in the list. Its data type is ChoiceList. One attribute of ChoiceList is ChoiceItems, which is an array of class ChoiceItem. It is the ChoiceItems array that actually contains the values displayed in the option field. For a more detailed explanation of loading values into the option field, see How You Can Load Values into a ChoiceField Object (see How You Can Load Values into a ChoiceField Object).
After clearing the option field of values, the starting frame uses a select loop to retrieve the new values to be loaded into the option field. The retrieved values are the names of all the tables that are owned by the DBA. The table names are retrieved from iitables (an Ingres Standard Catalog Interface view). The selected tables are returned one at a time and processed by the select loop. The select loop places each table name into the option field's ValueList.
The following code is an example of the select loop discussed in the previous paragraph:
i = 1;
select distinct table_name as :tmp_table_name
    from iitables
    where table_owner = :dbaname
begin
    field(table_choices).ValueList.ChoiceItems[i]
    EnumText = tmp_table_name;
    field(table_choices).ValueList.ChoiceItems[i]
    EnumValue = i;
    i = i + 1;
end;
The following section, How You Can Load Values into a ChoiceField Object (see How You Can Load Values into a ChoiceField Object), explains the syntax used to load values into the table_choices option field.