ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / Managing databases / HFSQL / Managing replications / Universal replication
  • Overview
  • HFSQL Classic database: Setting up programmatic replication
  • Step 1: Programming local access to HFSQL Classic data files
  • Step 2: Replication description
  • Step 3: Programming replication
  • Step 4: Application deployment
  • HFSQL Client/Server database: Setting up programmed replication
  • Step 1: Programming local file access
  • Step 1 bis: Using non-HFSQL databases
  • Step 2: Replication description
  • Step 3: Programming replication
  • Step 4: Application deployment
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Overview
The assisted replication through programming is used to implement a replication on an existing application while controlling the synchronization in the application itself. The user starts the synchronization via the application directly, without using any external application.
The assisted replication through programming allows you to use all the available replication modes:
  • direct replication,
  • replication by server with immediate or periodic replica.
HFSQL Classic database: Setting up programmatic replication
WINDEVWEBDEV - Server codeHFSQL Classic

Step 1: Programming local access to HFSQL Classic data files

If an application uses the assisted universal replication, it accesses a local database containing the necessary data only. The main database (master database) is used during the synchronization only.
Therefore, the application must be modified in order to access the local data files. You must program:
WINDEVWEBDEV - Server codeHFSQL Classic

Step 2: Replication description

The description of the replication is performed in a ".WER" file created by ReplicEdit. ReplicEdit is used to:
WINDEVWEBDEV - Server codeHFSQL Classic

Step 3: Programming replication

The local database is initialized when the first synchronization is performed between the application and the master database. The master database is found in the WER file generated by ReplicEdit.
For a direct assisted replication: Example of code that can be used:
// Initialise la réplication en passant le numéro du département à prendre en compte
IF ReplicInfo("MaRéplication", replicInitialized) = False THEN
	ReplicInitialize("MaRéplication", 47012)
END

// Lance la synchronisation
ReplicSynchronize("MaRéplication")
The local database must be initialized once only by ReplicInitialize.
Then, a single data synchronization is required (ReplicSynchronize)
Case of assisted replication with replication server: If you're performing assisted replication with replication server, you need to use the ReplicOpen function before the ReplicInitialize function to specify the replication server parameters.. Example:
// Ouvre la réplication sur le serveur de réplication
ReplicOpen("MaRéplication", "", "ServeurReplication", "Florence", "motpasse")

// Initialise la réplication en passant le numéro du département à prendre en compte
IF ReplicInfo("MaRéplication", replicInitialized) = False THEN
	ReplicInitialize("MaRéplication", 47012)
END

// Lance la synchronisation
ReplicSynchronize("MaRéplication")
WINDEVWEBDEV - Server codeHFSQL ClassicOLE DB

Step 4: Application deployment

The setup program is prepared like for any standard application.
Important: When creating the installation program, you must not ask to install assisted replication (uncheck the "Install and configure assisted universal replication modules" option)..
Reminder: To create the installation program, under the "Project" pane, in the "Generation" group, pull down "Setup procedure" and select "Create Installation Procedure".
Direct assisted replication (without replication server) .WER file must be integrated into the files installed by the application. The .WER must contain all the characteristics of the paths to the master data files used by the application. The.WER file cannot be included in the library (WDL file).
If the location of the data files of the master database is unknown when creating the .WER file, it must be specified for each end-user computer installed. This operation can be performed:
  • on the end-user computer directly. To do so, ReplicEdit must be supplied to the user. However, the user will have access to all replication characteristics. This solution may cause security problems.
  • by the developer, once the path of the master database was specified by the end user. Then, the .WER is transmitted to the end user for update.
Assisted replication with replication server If you are using assisted replication with a replication server, the .WER file must be deployed on the replication server, along with all information concerning the master database. For more details, see Server for Assisted Universal Replication.
HFSQL Client/Server database: Setting up programmed replication
WINDEVWEBDEV - Server codeHFSQL Client/ServerOLE DBNative Connectors (Native Accesses)

Step 1: Programming local file access

If an application uses the assisted universal replication, it accesses a local database containing the necessary data only. The main database (master database) is used during the synchronization only.
Therefore, the application must be modified in order to access the local data files. You must program:
  • the creation (if necessary) of the local files.
  • the access to these local files.
The principle is straightforward:
  • Definition of connections at analysis level Connections must be described at analysis level. Each file is associated with a connection.
  • Configuring connections with ReplicEdit ReplicEdit tool allows you to configure these connections to access master databases.
  • Programming local file access The application code will simply switch each connection to an HFSQL Classic connection, allowing the files to be used locally.
Installation If your application uses data files that require one or more connections (HFSQL Client/Server, native access, OLE DB files, etc.), we recommend that you perform the following operations:
  • in the data model editor: if your files are not associated with connections, create as many test connections as you need. For example, if you are using HFSQL Client/Server data and Oracle data, two test connections must be defined in the analysis.
  • in your code, modify the connections associated with the files: simply modify the parameters of the test connections to manipulate local HFSQL Classic data files. For example, the following code defines a local connection to HFSQL data files:
    HOpenConnection("HF_local", "", "", "", "", hAccessHF7)
    HChangeConnection("*", "HF_local")
WINDEVWEBDEV - Server codeHFSQL Client/ServerOLE DBNative Connectors (Native Accesses)

Step 1 bis: Using non-HFSQL databases

To implement the assisted universal replication on different databases (Oracle, ...), a DateTime item must be created in each file taken into account by in the replication. This item will have to be updated by the application when modifying or adding a record.
If the databases use different time zones, we recommend that you use a universal format (GMT date and time for example).
Example: Managing a specific item for replication between an HFSQL database and a MySQL database:
A trigger is implemented in order to automatically fill the "Itm_DateTime" item found in the MySQL database:
  • Code of the trigger
    ResultatTrigger is boolean
    ResultatTrigger = HDescribeTrigger("*", "HAJOUTE,HMODIFIE,HSUPPRIME,HRAYE,HECRIT", "AjoutDateHeure", hTriggerBefore)
    IF ResultatTrigger = False THEN Error(HErrorInfo())
  • Procedure called by the trigger
    PROCEDURE AjoutDateHeure()
    TestReplic.Rub_DateHeure = DateSys() + TimeSys()
WINDEVWEBDEV - Server codeHFSQL Client/ServerOLE DBNative Connectors (Native Accesses)

Step 2: Replication description

The replication is described by ReplicEdit. This tool is used to:
  • define the files taken into account by the replication, the filters taken into account when updating the data. For more details, see Creating a replication with ReplicEdit.
  • configure the location of the master files. All you have to do is redefine the connections of the analysis. The list of connections is returned by "Replication .. Description of connections" from ReplicEdit. For more details, see Replication options defined in ReplicEdit.
This information is saved in a ".WER" file created by ReplicEdit.
WINDEVWEBDEV - Server codeWindowsHFSQL Client/ServerOLE DBNative Connectors (Native Accesses)

Step 3: Programming replication

The local database is initialized when the first synchronization is performed between the application and the master database. The connections to the master database are defined in the WER file generated by ReplicEdit.
For a direct assisted replication: Example of code that can be used:
// Initialise la réplication en passant le numéro du département 
// à prendre en compte
IF ReplicInfo("MaRéplication", replicInitialized) = False THEN
	ReplicInitialize("MaRéplication", 47012)
END

// Lance la synchronisation
ReplicSynchronize("MaRéplication")
The local database must be initialized once only by ReplicInitialize.
Then, a single data synchronization is required (ReplicSynchronize)
Case of assisted replication with replication server: If you are performing assisted replication with replication server, you need to use the ReplicOpen function before the ReplicInitialize function to specify replication server parameters.
// Ouvre la réplication sur le serveur de réplication
ReplicOpen("MaRéplication", "", "ServeurReplication", "Florence", "motpasse")

// Initialise la réplication en passant le numéro du département 
// à prendre en compte
IF ReplicInfo("MaRéplication", replicInitialized) = False THEN
	ReplicInitialize("MaRéplication", 47012)
END

// Lance la synchronisation
ReplicSynchronize("MaRéplication")
WINDEVWEBDEV - Server codeHFSQL Client/ServerOLE DBNative Connectors (Native Accesses)

Step 4: Application deployment

The setup program is prepared like for any standard application. The .WER file must be included in the list of files installed by the application. The .WER file must contain all the characteristics of the connections to the master databases used by the application.
Important: When creating the installation program, you must not ask to install assisted replication (uncheck the "Install and configure assisted universal replication modules" option)..
Reminder: To create the installation program, under the "Project" pane, in the "Generation" group, pull down "Setup procedure" and select "Create Installation Procedure".
Direct assisted replication (without replication server) .WER file must be integrated into the files installed by the application. The .WER must contain all the characteristics of the paths to the master data files used by the application. The.WER file cannot be included in the library (WDL file).
If the parameters for connecting to the master databases are unknown when crating the .WER file, they must be specified for each installed end-user computer. This operation can be performed:
  • on the end-user computer directly. To do so, ReplicEdit must be supplied to the user. However, the user will have access to all replication characteristics. This solution may cause security problems.
  • by the developer, once the path of the master database was specified by the end user. Then, the .WER is transmitted to the end user for update.
Assisted replication with replication server If you are running assisted replication with a replication server, the .WER file must be deployed on the replication server, along with all information concerning connections to the master databases. For more details, see Server for Assisted Universal Replication.
Related Examples:
WD Universal Replication Training (WINDEV): WD Universal Replication
[ + ] This examples explains how to use the universal replication to synchronize data of different sites.
The universal replication is used to synchronize the data of a site (master site) with the same data of one or more replicated sites (subscriber sites). The data structures are identical on each site but they can be exploited via different data managers. HFSQL Classic and Access will be used in this example.
The example presents the processes that must be included in your applications to allow the user, via a simple action (menu, button, ...), to:
- create a master replica,
- create one or more subscriber replicas,
- see and modify the data of these replicas,
- export the created or modified data to a site (portable replica),
- import the created or modified data into another site...
Minimum version required
  • Version 12
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 03/27/2025

Send a report | Local help