Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
CodeDatabaseDelphiRAD Studio

Learn How To Use The Oracle Continuous Query Notification (CQN) Feature With Delphi FireDAC On Windows

The Oracle_CQN sample shows you how to use Continuous Query Notification with Oracle databases using FireDAC.

Location

You can find the Oracle_CQN project at:

  • Start | Programs | Embarcadero RAD Studio Sydney | Samples and then navigate to:
    • Object Pascal\Database\FireDAC\Samples\DBMS Specific\Oracle\CQN
  • Subversion Repository:
    • You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.

Description

To this end, this sample connects a client with CHANGE NOTIFICATION privilege to an Oracle database server and uses an event alerter to notify about database table data changes.

The implementation of this sample takes into account the following considerations listed in Oracle CQN section of the Data Change Notifications topic of FireDAC.

Files

File in DelphiContains
Oracle_CQN.dproj
Oracle_CQN.dpr
The project itself.
ChangeFrm.pas
ChangeFrm.dfm
The main form.

Implementation

Design Time

Before running the sample, the main components are configured at design time using the Object Inspector as follows:

  • Two TFDConnection objects named conOriginal and conChanges. These are the FireDAC connection objects that the sample use to connect to a DBMS. The sample sets the ConnectionDefName property of conOriginal to Oracle_Demo.

Notes:

  • You can change the ConnectionDefName property to connect to a different Oracle server using a valid user name and password.
  • The Params properties of conChanges are copied from conOriginal on run-time.
  • Two TFDQuery objects named qOriginal and qChanges. These component are used to implement datasets capable of executing SQL queries.
  • TFDEventAlerter object named eaChanges. This component is used to handle the database change notifications.
  • Three TDataSource objects named dsOriginaldsChanges and dsRemote. These components provide interfaces between a dataset component and data-aware controls on a form. In this sample, these objects are used to provide communication between the datasets and the grids where the datasets are displayed. To this end, the sample sets the following properties:
  • The DataSet property of dsOriginaldsChanges and dsRemote is set to qOriginalqChanges and mtRemote, respectively.
  • The DataSource property of grdOriginalgrdChanges and grdremote is set to dsOriginaldsChanges and dsRemote, respectively.

Run Time

When you run the application, you see the following components:

  • TButton called Open DB. When you click this button, the sample takes the following steps:
  1. Connects conOriginal and activates qOriginal.
  2. Connects conChanges with the same parameters than conOriginal
  3. Activates the eaChanges event alerter.
  4. Activates qOriginal.Note: As commented in the Description, you should activate TFDEventAlerter before executing the tracked TFDQuery.
  • TButton called Start TX. When you click this button, the sample starts the transaction.
  • TButton called Commit TX. When you click this button, the sample commits the transaction.
  • Three TGrids labeled as: Original dataChange View and “Remote” data. When you modify the data in the first grid, which contains the original data, it triggers a change in the second grid. The changes appear automatically on the second grid due to the event alerter. Moreover, the changes appear highligthed in yellow.
  • Two TComboBoxes labeled as Data mode and Refresh mode. You can use these comboboxes to choose between different modes.
  • Four TButtons above the third grid. Use these buttons to mergecommit and undo the changes.
  • TCheckBox labeled as Merge using stream. This check box allows you to emulate a remote data transfer.

Fore more information and official connections to other samples, follow the link below:

http://docwiki.embarcadero.com/CodeExamples/Sydney/en/FireDAC.Oracle_CQN_Sample


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES