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: Implementing the replication through programming
  • Step 1: Programming the access to the HFSQL Classic files locally
  • Step 2: Describing the replication
  • Step 3: Programming the replication
  • Step 4: Deploying the application
  • HFSQL Client/Server database: Implementing the replication through programming
  • Step 1: Programming the access to the files locally
  • Step 1 bis: Using a database not in HFSQL format
  • Step 2: Describing the replication
  • Step 3: Programming the replication
  • Step 4: Deploying the application
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
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: Implementing the replication through programming
WINDEVWEBDEV - Server codeHFSQL Classic

Step 1: Programming the access to the HFSQL Classic files locally

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: Describing the replication

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 the 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:
// Initializes the replication by passing the zip code to take into account
IF RéplicInfo("MyReplication", replicInitialized) = False THEN
ReplicInitialize("MyReplication", 47012)
END

// Starts the synchronization
ReplicSynchronize("MyReplication")
The local database must be initialized once only by ReplicInitialize.
Then, a single data synchronization is required (ReplicSynchronize)
For an assisted replication with replication server: If you perform an assisted replication with replication server, ReplicOpen must be called before ReplicInitialize to specify the parameters of the replication server. Example:
// Starts the replication on the replication server
ReplicOpen("MyReplication", "", "ReplicationServer", "Flora", "password")

// Initializes the replication by passing the zip code to take into account
IF RéplicInfo("MyReplication", replicInitialized) = False THEN
ReplicInitialize("MyReplication", 47012)
END

// Starts the synchronization
ReplicSynchronize("MyReplication")
WINDEVWEBDEV - Server codeHFSQL ClassicOLE DB

Step 4: Deploying the application

The setup program is prepared like for any standard application.
Important: When creating the setup program, do not ask to install the assisted replication (uncheck "Install and configure the modules for assisted universal replication").
Reminder: To create the setup program, go to the "Project" tab, "Generation" group, expand "Setup procedure" and select "Create setup procedure".
Direct assisted replication (without replication server): The .WER file must be included in the list of 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 perform an assisted replication with replication server, the .WER file must be deployed on the replication server with all the information regarding the master database. For more details, see Server for Assisted Universal Replication.
HFSQL Client/Server database: Implementing the replication through programming
WINDEVWEBDEV - Server codeHFSQL Client/ServerOLE DBNative Connectors (Native Accesses)

Step 1: Programming the access to the files locally

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:
  • Defining the connections at analysis level: The connections must be described at analysis level. Each file is associated with a connection.
  • Configuring the connections with ReplicEdit: ReplicEdit is used to configure these connections in order to access the master databases.
  • Programming the access to the local files: The code of the application will be used to switch each connection to an HFSQL Classic connection in order to use the files locally.
Implementation: If your application uses data files that require or or more connections (HFSQL Client/Server, native accesses, OLE DB files, ...): we recommend that you perform the following operations:
  • in the data model editor: if your files are associated with no connection, create as many test connections as necessary. 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: all you have to do is modify the parameters of the test connections to handle the local HFSQL Classic files. For example, the following code is used to define a local connection on HFSQL files:
    HOpenConnection("HF_local", "", "", "", "", hAccessHF7)
    HChangeConnection("*", "HF_local")
WINDEVWEBDEV - Server codeHFSQL Client/ServerOLE DBNative Connectors (Native Accesses)

Step 1 bis: Using a database not in HFSQL format

To implement assisted universal replication on different databases (Oracle, etc.), a DateTime item must be created in each file taken into account by 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 the 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
    PROCÉDURE AjoutDateHeure()
    TestReplic.Rub_DateHeure = DateSys() + TimeSys()
WINDEVWEBDEV - Server codeHFSQL Client/ServerOLE DBNative Connectors (Native Accesses)

Step 2: Describing the replication

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 the 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:
// Initialize the replication by passing the zip code 
// to take into account
IF RéplicInfo("MyReplication", replicInitialized) = False THEN
ReplicInitialize("MyReplication", 47012)
END

// Starts the synchronization
ReplicSynchronize("MyReplication")
The local database must be initialized once only by ReplicInitialize.
Then, a single data synchronization is required (ReplicSynchronize)
For an assisted replication with replication server: If you perform an assisted replication with replication server, ReplicOpen must be called before ReplicInitialize to specify the parameters of the replication server.
// Starts the replication on the replication server
ReplicOpen("MyReplication", "", "ReplicationServer", "Flora", "password")

// Initialize the replication by passing the zip code 
// to take into account
IF RéplicInfo("MyReplication", replicInitialized) = False THEN
ReplicInitialize("MyReplication", 47012)
END

// Starts the synchronization
ReplicSynchronize("MyReplication")
WINDEVWEBDEV - Server codeHFSQL Client/ServerOLE DBNative Connectors (Native Accesses)

Step 4: Deploying the application

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 setup program, do not ask to install the assisted replication (uncheck "Install and configure the modules for assisted universal replication").
Reminder: To create the setup program, go to the "Project" tab, "Generation" group, expand "Setup procedure" and select "Create setup procedure".
Direct assisted replication (without replication server): The .WER file must be included in the list of 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.
For an assisted replication with replication server: If you are performing an assisted replication with replication server, the .WER file must be deployed on the replication server with the information regarding the 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: 06/23/2023

Send a report | Local help