Creating a Context

4D - Documentation   Français   English   German   English   4D for Oracle, Command Theme List   4D for Oracle, Command Alphabetical List   Back   Previous   Next

version 1.5


After you execute the Connection method, you are connected to the Oracle server.

To work with Oracle data, you bind a 4th Dimension table to one of SCOTT's tables. The easiest way to do this is to use contexts. When you are working with contexts, you can link 4th Dimension objects such as fields, variables, or arrays with Oracle columns.

To create a context

In this section, you will execute a method that allows you define a context using a dialog box. After the context is defined, the method automatically loads the rows and displays them in a 4th Dimension table.

1. In the Design environment, open the ContextDemo method.

This method loads a set of data from an Oracle table and saves it to a 4th Dimension table.

      `ARRAY STRING(30;tLocation;0)
      `ARRAY STRING(30;tJob;0)
      `ARRAY REAL(tSalaries;0)
   If (OD Login state (ID_Login)>0)   `Verify that the connection is valid
      ID_Context:=OD Create context dialog (ID_Login;"SCOTT.EMP"; Table(»[Employees])
            `Display Edit a Context dialog box
      If (ID_Context>0)   `If a context was defined
         $rc:=OD Activate context (ID_Login;ID_Context)
            `Activate the context
         ALL RECORDS ([Employees])
         DELETE SELECTION ([Employees])
         $n:=OD Load rows context (ID_Context)   `Load rows selected by the context
         ALL RECORDS ([Employees])
         ORDER BY ([Employees];[Employees]Num;>)   `Sort records
         OD DEACTIVATE CONTEXT (ID_Context}
         OD DROP CONTEXT (ID_Context)
      End if 
   End if 

The OD Create context dialog function displays a dialog box that lets you create binds between 4th Dimension and Oracle objects. OD Create context dialog returns a positive context identifier if you do not click the Cancel button and if the operation is successful. This context identifier is used in subsequent commands.

The context you have created defines the binds between 4th Dimension and Oracle objects. You call the OD Activate context function to activate the context. OD Activate context creates a selection cursor and causes 4D for Oracle to execute the SELECT statement it builds from the information entered in the Edit a Context dialog box.

Note: The connection identifier supplied to the Edit a Context dialog box is useful only in retrieving the table and column names from the Oracle server. You can use a different connection identifier during context activation as long as the tables specified during the definition of the context are accessible from the connection used for activation.

The OD Load rows context function sends the contents of the SCOTT.EMP table to the 4th Dimension [Employees] table. Before transferring the data, the DELETE SELECTION command is used to ensure that only the newly transferred records are in the Table.

The OD DEACTIVATE CONTEXT command closes the cursor opened by OD Activate context. The links defined by the context become inactive. You can reactivate them with the OD Activate context command.

The OD DROP CONTEXT command frees the memory used by the context. After this call, you cannot reuse the context unless you redefine and reactivate the context.

2. Enter the User environment and execute the ContextDemo method.

The Edit a Context dialog box appears.

The pop-up menus at the top of the dialog box allow you to choose the Oracle table and the 4th Dimension table on which you want to work.

SCOTT.EMP and [Employees] were specified as the default Oracle table and 4th Dimension Table in the call to OD Create context dialog. This causes the lists to be pre-filled with the columns in the SCOTT.EMP table and the fields in the [Employees] Table.

In this example, you will request the Updatable option for each association.

3. Select the EMPNO column and EmpNumber field.

4. Click the Updatable and Sorted check boxes.

By clicking the Updatable check box, you are indicating that you want to update the values in the EMPNO column. 4D for Oracle locks the values in this column if you set the For Update option. You will learn how to update data later in this tutorial in the section Adding and Modifying Data on the Server.

By clicking the Sorted check box, you are specifying that the data in the EMPNO column should be sorted. The default sort order is ascending. You can change the sort order to descending by clicking the arrow to the right of the Sorted check box.

5. Click the Bind button to bind the EMPNO column and EmpNumber field.

The bind is listed in the Current Binds area.

6. Bind the rest of the columns to the corresponding fields in the [Employees] table, selecting the Updatable check box for each bind.

The dialog box should now appear as follows:

7. Click the Save As button to save this context to a file.

You will be asked to enter a filename.

Your context is now saved on disk. You will use the context you have saved later in this tutorial.

8. Click the OK button in the Edit a Context dialog box to validate the context.

4D for Oracle activates the context and loads the rows of the SCOTT.EMP table into the [Employees] table.

You can now use 4th Dimension to search, sort, or create reports or labels using the data from Oracle.


4D - Documentation   Français   English   German   English   4D for Oracle, Command Theme List   4D for Oracle, Command Alphabetical List   Back   Previous   Next