PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Overview
  • HFSQL Classic database: Implementing the replication by 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 by 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/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Overview
The assisted replication by 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 by programming allows you to use all the available replication modes:
  • direct replication,
  • replication by server with immediate or periodic replica.
Note: From version 19, HFSQL is the new name of HyperFileSQL.
HFSQL Classic database: Implementing the replication by programming
WINDEVWEBDEV - Server codeWindows MobileHFSQL

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 codeWindows MobileHFSQL

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 codeWindows MobileHFSQL

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 ReplicInfo("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 ReplicInfo("MyReplication", replicInitialized) = False THEN
ReplicInitialize("MyReplication", 47012)
END

// Starts the synchronization
ReplicSynchronize("MyReplication")
WINDEVWEBDEV - Server codeWindows MobileHFSQLOLE 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, select "Workshop .. Create the setup procedure". Reminder: To create the setup program, on the "Project" pane, in the "Generation" group, expand "Setup procedure" and select "Create the 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 the characteristics of the replication. 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. See Server for Assisted Universal Replication for more details.
HFSQL Client/Server database: Implementing the replication by programming
WINDEVWEBDEV - Server codeWindows MobileHFSQL Client/ServerOLE DBNative 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 a HFSQL Classic connection in order for the files to be used locally.
Implementation: If your application is using 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 codeWindows MobileHFSQL Client/ServerOLE DBNative Accesses

Step 1 bis: Using a database not in HFSQL format

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 the replication between a 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
    TriggerResult is boolean
    TriggerResult = HDescribeTrigger("*", "HADD,HMODIFY,HDELETE,HCROSS,HWRITE", ...
    "AddDateTime", hTriggerBefore)
    IF TriggerResult = False THEN Error(HErrorInfo())
  • Procedure called by the trigger
    PROCEDURE AddDateTime()
    TestReplic.Itm_DateTime = DateSys()+TimeSys()
WINDEVWEBDEV - Server codeWindows MobileHFSQL Client/ServerOLE DBNative 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. See Creating a replication with ReplicEdit for more details.
  • 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. See Replication options defined in ReplicEdit for more details.
This information is saved in a ".WER" file created by ReplicEdit.
WINDEVWEBDEV - Server codeWindowsWindows MobileHFSQL Client/ServerOLE DBNative 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:
// Initializes the replication by passing the zip code
// to take into account
IF ReplicInfo("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")

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

// Starts the synchronization
ReplicSynchronize("MyReplication")
WINDEVWEBDEV - Server codeWindows MobileHFSQL Client/ServerOLE DBNative 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, select "Workshop .. Create the setup procedure". Reminder: To create the setup program, on the "Project" pane, in the "Generation" group, expand "Setup procedure" and select "Create the 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 the characteristics of the replication. 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. See Server for Assisted Universal Replication for more details.
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 required version
  • Version 12
This page is also available for…
Comments
Click [Add] to post a comment