version 1.5
You can create a context either by using a context definition dialog box or by executing a set of procedural statements. If you use the dialog box, 4D for Oracle generates the context definition statements for you.
Creating a Context Using a Dialog Box
You can use the Edit a Context dialog box to define a context that selects data on the Oracle server and relates it to data elements in 4th Dimension.
Creating a context
To open the Edit a Context dialog box:
1. Execute the OD Create context dialog function.
The Edit a Context dialog box appears:
Note: The dialog box may look different if you are using a nine inch screen. In this case, 4D for Oracle presents a simplified dialog box that includes the same functions.
Using the dialog box, you can do the following:
Define binds for the context,
Add clauses and options to the context,
Copy the code for the context definition to the Clipboard,
Save the context definition to a file,
Load the context definition from a file.
The Edit a Context dialog box allows you to select an Oracle column or expression and a 4th Dimension field, variable, or array, and bind the two together.
You can create multiple binds to associate multiple Oracle objects with multiple 4th Dimension objects. Each bind you create is listed in the Current Binds area.
Defining a bind
To define a bind between an Oracle object and a 4th Dimension object using the Edit a Context dialog box, follow these steps:
1. Select a column or expression from the list below the Oracle Table pop-up menu.
To display columns from a different table, choose the name of the table from the Oracle Table pop-up menu.
To display the names of expressions that you have previously defined, choose Expressions from the Oracle Table pop-up menu. You can define expressions by clicking the Expression button and typing the expression in the Edit a SQL Expression dialog box that appears.
2. Select a 4th Dimension field, variable, or array from the list below the 4th Dimension Table pop-up menu.
To display fields from a different table, choose the name of the table from the 4th Dimension Table pop-up menu.
To display the names of variables and arrays that you have previously defined, choose Variables from the 4th Dimension Table pop-up menu. You can define variables and arrays by clicking the Variable button and typing the name of the variable or array in the dialog box that appears.
You have now selected the Oracle object and the 4th Dimension object that you want to bind together. Before adding the bind to the context, you can select from among three options for the bind.
3. If desired, choose the Updatable, Sorted, or Primary Key option.
Updatable option: This option specifies that the Oracle column can be updated using the OD Insert in context or OD Update in context functions. This option applies only to a bind involving an Oracle column. You cannot update an expression.
Sorted option: This option specifies that the data in the column or expression should be sorted. When you choose this option, you can select whether the data should be sorted in ascending or descending order by clicking the sort arrow.
Primary Key option: This option specifies the columns that uniquely identify the rows in a table. You must specify a primary key to be able to update data in the context. The Primary Key option applies only to a bind involving an Oracle column. You cannot make an expression the primary key.
4. Click the Bind button.
You have now defined a bind in the context. The bind is not activated until you activate the context.
5. Repeat steps 14 to define additional binds for the context.
All binds are listed in the Current Binds area with a reminder of the options you set for the bind (Updatable, Sorted, or Primary Key). In the following figure, the ENAME column is linked to the Name field.
At any time, you can remove a bind by selecting it in the Current Binds area and clicking the Delete button.
Selecting Options for the Context
Before activating the context, you may want to specify options or clauses that affect the behavior of the context. To select options for the context:
1. Choose the option(s) for the context from the Select Options area.
Distinct option: Specifies that only distinct values should be returned. This prevents duplicate values from being returned.
For Update option: Prepares the selected rows to be updated by locking them to all other users.
No Wait option: Specifies that 4D for Oracle should not wait for the rows selected by the SELECT statement to become unlocked. If the rows are locked, the query is cancelled. You must select the For Update option before you can select the No Wait option.
Adding Clauses to the Context
To add a clause to the context:
1. Click the Select Clauses button.
The Edit a SQL Clause dialog box is displayed, allowing you to create clauses such as WHERE, GROUP BY, or CONNECT BY.
You can select the type of clause that you want to create by selecting it from the Clause pop-up menu.
To construct the clause, type it into the text area. To simplify the creation of a clause, you can select keywords, column names, and functions from the lists at the bottom of the dialog box.
To display columns from a different table in the center list, you can hold the mouse button down on the title bar of the list and choose a table name from the pop-up menu that appears, or you can scroll through the list of tables using the arrows on either side of the title bar.
Copying the Context Creation Statements
When you define a context using the Edit a Context dialog box, you can request that 4D for Oracle generate the 4D for Oracle statements equivalent to the context definition. Instead of redefining the context each time you need to use it, you can place the 4D for Oracle statements in a 4th Dimension database or project method, such as the database 'on startup' method.
To copy these statements to the Clipboard before activating the context:
1. Click the Copy Code button.
When you click the button, 4th Dimension asks you to name a 4th Dimension variable in which to store the context identifier.
2. Enter a variable name and click the OK button.
The statements are copied to the Clipboard. These statements can then be pasted into a 4th Dimension method.
Saving the Context Definition to a File
4D for Oracle allows you to save contexts to files. A context saved to a file can be loaded into the Edit a Context dialog box at a later time. A context saved to a file can also be loaded into memory using the OD Open context file function.
To save the context you have created to a file:
1. Click the Save As button.
A Save File dialog box appears, allowing you to specify a name and location for the file.
2. Click the Save button.
The file is saved.
Loading a Context from a File
You can load a context previously saved to a file.
To load a context saved to a file:
1. Click the Open button in the Edit a Context dialog box.
An Open File dialog box appears.
2. Select the file and then click the Open button.
The context is loaded and displayed in the Edit a Context dialog box.
You can also use a method to load a context using the OD Open context file function.
Creating a Context Using Procedural Statements
If you do not want to use the Edit a Context dialog box, you can define a context with a method, using 4D for Oracle commands and functions.
Here are the basic steps for using a method to create a context:
1. Initialize the context and retrieve the context identifier by executing the OD Create context function.
The context identifier is used to identify the context in all other context commands.
2. Define the context by executing a series of OD ADD TO CONTEXT statements.
The OD ADD TO CONTEXT command lets you bind Oracle objects with 4th Dimension objects and add the equivalents of the UPDATABLE, SORT, and PRIMARY KEY options. At this point, the SELECT statement being built by 4D for Oracle might be the following:
SELECT empno, ename, FROM emp
3. Add clauses to the context definition by executing a series of OD SET CLAUSE IN CONTEXT statements.
If you wish to see only employees from department 20, you could use the following statement:
OD SET CLAUSE IN CONTEXT (Context_ID;2;"DEPTNO=20")
Adding this line modifies the query as follows:
SELECT empno, ename, FROM emp WHERE DEPTNO=20
The WHERE keyword has been automatically added by 4D for Oracle.
You can later retrieve the clauses set for a context by executing a series of OD Get clause in context statements.
Activating a Context
To send the SELECT statement generated by the context definition, you must activate the context.
To activate a context:
1. Execute an OD Activate context statement.
The data corresponding to the context is selected on the server.
To use the selected data in 4th Dimension, you must load the data into the fields, variables, or arrays.