5. Working with a Database : How Programming for Multiple Sessions Works : How You Can Switch Database Sessions : How You Can Switch Sessions in an Event Block
 
Share this page                  
How You Can Switch Sessions in an Event Block
To change to another session only for one operation in a specific event block, set the DBSession attribute of the frame's FrameExec object in the event block. For example, the following event block switches to another session if the specified condition is true:
on add_customer =
begin
    /* If customer is rejoining the club, switch
    ** to session connected to the archived
    ** customer database. */
    if old_customer = TRUE
        CurFrame.DBsession = second_session;
    ...
    /* Switch back before exiting event block */
    CurFrame.DBsession = first_session;
end;
It is not necessary to switch back to the original session before the event block completes. Event block execution can begin in one session and end in another. However, if your frame has event blocks defined for any database events, the frame receives these events only when the application is running in the same session in which you registered the events for the frame. If you switch sessions in an event block to perform a task, be sure to switch back to the session in which the database events are expected.
For example, assume that session1 has registered for a database event and the current event block has changed sessions to session2. If a database event arrives while session2 is active, session1 does not receive the event.
For more information about database events, see Inter-Frame Communication Techniques (see Inter-Frame Communication Techniques).
If you open a new database session for the current frame in an event block, you must explicitly switch the current frame to the newly opened session. The following example opens a connection to the videos database and switches to the session for the current frame:
on click chg_session_btn =
begin
    status = videos_session.Connect (database =
            'videos');
    Curframe.DBsession = videos_session;
end;