version 1.5
In this tutorial, you will use the Context database supplied with 4D for Oracle to learn the basics of using contexts to manage data. Its structure is similar to that of the EMP table supplied as an example by Oracle. The following tutorial assumes that the example Oracle table is on the server.
To install and open the tutorial database
Follow these steps to install and open the Context database.
1. Copy the folder/directory called Context from the example disk to your hard disk.
2. Install 4D for Oracle in the Context database.
3. Open the database with 4th Dimension or 4D Server.
The structure is displayed.
This database contains two tables, [Employees] and [Interface], and several pre-defined forms. It also includes 4th Dimension methods to which you will add 4D for Oracle statements.
You will use this 4th Dimension database to examine data from the example table for the Oracle user "SCOTT".
To Establish a Connection
You must now establish a connection between the 4th Dimension and Oracle databases. The connection method has been written for you.
1. Choose Methods from the Design menu.
2. Open the Connection method.
The Connection method is displayed in the 4th Dimension Method editor. The commands and functions added to the language by 4D for Oracle are grouped into categories at the end of the Routines list.
You can verify that the 4D for Oracle routines are present by scrolling to the end of the Routines list. All 4D for Oracle routines begin with the letters "OD".
The OD Login dialog function presents a standard dialog box that allows you to choose the server to which you want to connect and to enter your user name and password. This function can be found in the Login category in the Routines list.
3. Enter the User environment and execute the Connection method.
The Connect to an Oracle Server dialog box appears.
4. From the Server pop-up menu, choose the server to which you want to connect.
The Server pop-up menu contains the servers listed in the TNSNAMES.ORA file. That file is contained in the 'Orawin/Network/admin' directory under windows or in 'Oracle home:network:admin' folder under MacOs. See your Oracle documentation for details on the format of the TNSNAMES.ORA file. If you are using 4D for Oracle with OCI 6 under MacOs the servers list comes from the config.ora file in the oracle home folder.
5. Type "SCOTT" as the user name.
6. Type SCOTT's password in the Password box.
SCOTT's password will be "tiger" if you have not made changes to the original installation of the Oracle server.
4D for Oracle will remember your user name if you check the Save Name check box. You can do the same for your password. Your name and password are saved in a preference file in your System folder and will be presented to you for use the next time you connect.
Note: If other users have access to your computer, they can find out your name and password if you select the Save Name and Save Password check boxes. If security is a concern, do not use these options.
7. When you are done, click OK to connect to the Oracle server.
Click Cancel if you do not want to complete the connection.
If no errors occur, OD Login dialog returns a connection identifier in the ID_Login variable. You will use this connection identifier later when you create a context.
If a connection error occurs, the function returns -1. If you click Cancel, the function returns 0.
You can create several connections to the same server and the same user account. A different connection identifier is returned for each connection. In this case, you may want to ensure that the user logs on only once. You can rewrite the Connection method as the following to prevent multiple connections:
If (OD Login state (ID_Login)]]0)
ALERT ("You are already connected !")
Else
ID_Login:=OD Login dialog
End if
The OD Login state function returns the status of a connection. You could have tested if the connection identifier, ID_Login, was positive (connected) or not (disconnected). However, using OD Login state is more reliable since the connection identifier is not updated when a connection is dropped.
You can also write a method to check if you are connected to a server before you try to disconnect.
8. Enter the Design environment and open the Disconnection method.
The following method is used to close a connection to the server:
If (OD Login state (ID_Login)=0)
ALERT ("You are not connected!")
Else
OD LOGOUT (ID_Login)
End if
4D for Oracle automatically closes all connections to the server when you quit 4th Dimension.