Data synchronization method, device and equipment
By directly synchronizing data between electronic devices through an end-to-end data synchronization method, the problems of insecure user privacy data and low synchronization efficiency in traditional methods are solved, and secure and efficient cross-device data access is achieved.
Patent Information
- Application Number
- CN202310859384.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-12
- Publication Date
- 2025-01-14
Smart Images

Figure CN119311764A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and more specifically, to a data synchronization method, apparatus and device. Background Art
[0002] Data synchronization technology refers to ensuring the data consistency of data copies stored in different electronic devices by synchronizing data copies distributed in different electronic devices.
[0003] In the conventional technology, data synchronization is achieved by using a cloud server-based method. In this implementation method, electronic device A uploads the locally stored data to be synchronized to the cloud server. After the cloud server receives the synchronization request from electronic device B, the cloud server sends the locally stored data to be synchronized sent by electronic device A to electronic device B. After electronic device B obtains the data to be synchronized sent by the cloud server, it updates the local data of electronic device B according to the data to be synchronized, so as to achieve the purpose of synchronizing the data stored in electronic device A with electronic device B. In the above data synchronization process, the data stored locally in different electronic devices is kept consistent with the data stored in the cloud server, so as to achieve the purpose of synchronizing the data stored in different electronic devices. In the above implementation process, the user's privacy data (i.e., the data to be synchronized in electronic device A) needs to be uploaded to the cloud server, resulting in the problem of insecurity of the user's privacy data. At the same time, in the above implementation process, the cloud server needs to be used as a data transfer device, resulting in the problem of low data synchronization efficiency in this method.
[0004] Therefore, there is an urgent need to provide a data synchronization method to improve the efficiency of data synchronization while protecting the security of user privacy data. Summary of the invention
[0005] The present application provides a data synchronization method, apparatus and device, which can improve data synchronization efficiency while protecting the security of user privacy data.
[0006] In a first aspect, an embodiment of the present application provides a data synchronization method, which is applied to a first electronic device including a first application, the method comprising: generating a synchronization request for the first application, the synchronization request being used to request that target data in a second database in a second electronic device be backed up to a first database in the first electronic device, the second database being associated with a second application of the second electronic device, and the first database being associated with the first application; sending the synchronization request to the second electronic device; receiving the target data from the second electronic device; and updating the first database using the target data to obtain an updated first database, the data in the second database being the same as the data in the updated first database.
[0007] It should be understood that the database mode of the first database in the first electronic device is a slave database, and the database mode of the second database in the second electronic device is master data. Specifically, the first database is a slave database of the second database, and the second database is a master database of the first database. Based on this, the first electronic device is also called a slave device for data synchronization, and the second electronic device is also called a master device for data synchronization.
[0008] It should be understood that the updated first database and the first database have the same database identifier, the difference is that the data stored in the updated first database and the data stored in the first database are not completely the same. It should also be understood that the database mode of the updated first database is a slave database.
[0009] In the above technical solution, the first electronic device and the second electronic device are connected in an end-to-end manner, so that the first electronic device synchronizes the target data in the second database associated with the second application of the second electronic device requested by the first synchronization request to the first database associated with the first application of the first electronic device, and obtains the updated first database, so that the data in the second database is the same as the data in the updated first database. In the interaction process between the above-mentioned first electronic device and the second electronic device, there is no need for the participation of the cloud server, and there is no need to convert the format of the data to be synchronized (i.e., the target data) in the second database, that is, this method can improve the efficiency of data synchronization while protecting the security of user privacy data.
[0010] In one possible implementation, before generating a synchronization request for the first application, it includes: sending a modification request to the second electronic device, the modification request is used to request the second electronic device to perform a modification operation on a third database within the second electronic device to obtain the second database, the third database is associated with the second application, the data in the third database is the same as the data in the first database, wherein the target data is data associated with the modification operation.
[0011] It should be understood that the third database is a database having a master data schema, and the third database is a master database of the first database.
[0012] It should be understood that the modification operation performed on the third database may be a write operation (eg, a delete operation or a modification operation, etc.) performed on the data in the third database, or may be inserting new data into the third database.
[0013] In the above technical solution, in the scenario where the data in the first database in the first electronic device and the data in the third data in the second electronic device are the same, the first electronic device sends a modification request generated by itself to the second electronic device, so that the second electronic device can perform a modification operation on the third database as the master database of the first database according to the modification request to obtain the second database. Thereafter, the first electronic device synchronizes the target data associated with the modification request in the second database in the second electronic device to the first database in the first electronic device by sending a synchronization request to the second electronic device, and obtains the updated first database. That is to say, in the above technical solution, on the basis of the master-slave synchronization mode, the first electronic device as a slave device can perform a modification operation on the first database in the first electronic device according to its own modification requirements, wherein the first database in the first electronic device is a slave database of the third database in the second electronic device as the master device. In the above-mentioned interaction process between the first electronic device and the second electronic device, there is no need for the participation of the cloud server, and there is no need to convert the format of the data to be synchronized (i.e., the target data) in the second database, so that the user's privacy data security can be protected, and at the same time, the data synchronization efficiency can be improved.
[0014] In another possible implementation, before sending the synchronization request to the second electronic device, the method also includes: receiving a notification message from the second electronic device, wherein the notification message is used to indicate that the second electronic device has successfully performed the modification operation on the third database according to the modification request.
[0015] Exemplarily, in some implementations, the first electronic device further includes a first synchronization service and a first database access framework. Based on this, in the above-mentioned step of the first electronic device executing the step of receiving a notification message from the second electronic device, it is exemplary included: the first synchronization service receives a notification message from the second electronic device; the first synchronization service sends the notification message to the first application through the first database access framework, so that the first application obtains the notification message.
[0016] In the above technical solution, when the second electronic device performs a modification operation on the third database in the second electronic device according to the modification request, the first electronic device can obtain the notification message sent by the second electronic device, so that the first electronic device knows that the second electronic device has successfully performed the modification request on the third database in the second electronic device according to the modification request sent by the first electronic device. Thereafter, if the first electronic device sends a second synchronization request to the second electronic device, this is conducive to improving the efficiency and success rate of data synchronization.
[0017] In another possible implementation manner, the modification request includes an identifier of the second electronic device, an identifier of the second application, an identifier of the third database, and the modification operation.
[0018] In another possible implementation, the first electronic device includes a first synchronization service and a first database engine; sending the synchronization request to the second electronic device includes: the first synchronization service sends the synchronization request obtained from the first application to the second electronic device; receiving the target data from the second electronic device includes: the first synchronization service receives the target data; the method also includes: the first synchronization service sends the target data to the first database engine; updating the first database using the target data to obtain an updated first database includes: the first database engine writes the target data into the first database to obtain the updated first database.
[0019] In the above implementation, the method for the first database engine to obtain the target data from the first synchronization service is not specifically limited. For example, the target data obtained by the first database engine from the first synchronization service may be obtained by the first database engine and the first synchronization service through the first database access framework included in the first electronic device, so that the first database engine obtains the target data from the first synchronization service. For another example, the target data obtained by the first database engine from the first synchronization service may also be obtained by the first database engine and the first synchronization service directly interacting with each other, so that the first database engine obtains the target data from the first synchronization service.
[0020] In another possible implementation, after updating the first database using the target data to obtain an updated first database, the method further includes: when a database version of a fourth database in the first electronic device is different from a database version of the updated first database, updating the database version of the updated first database to obtain a fifth database, the database version of the fifth database being the same as the database version of the fourth database, wherein the fourth database is associated with the first application, and the fourth database is used to store data generated by the first application.
[0021] In the above technical scheme, when the first electronic device determines that the database of the fourth database is different from the database of the updated first database, the first electronic device can update the database version of the updated first database to obtain the fourth and fifth databases, so that the database version of the fourth database is the same as the database version of the fifth database. This is conducive to improving the efficiency of subsequent data queries on the fourth database and the fifth database.
[0022] In another possible implementation, the first electronic device includes a first database engine, and when the database version of the fourth database in the first electronic device is different from the database version of the updated first database, the database version of the updated first database is updated to obtain a fifth database, including: when the first application determines that the database version of the fourth database is different from the database version of the updated first database, the first application sends version update information to the first database engine, and the version update information is used to indicate that the database version of the updated first database is updated to the database version of the fourth database; the first database engine updates the database version of the updated first database according to the version update information to obtain the fifth database.
[0023] The manner in which the first application sends the update information to the first database engine in the above steps is not specifically limited. For example, the first application may send the update information to the first database engine through the first database access framework included in the first electronic device. For another example, the first application may directly send the update information to the first database engine.
[0024] In another possible implementation, when the database version of the fourth database in the first electronic device is different from the database version of the updated first database, the database version of the updated first database is updated to obtain the fifth database, and the method further includes: generating a query statement; and performing query processing on the fourth database and the fifth database according to the query statement to obtain a query result.
[0025] In the above technical solution, when the database version of the fourth database is consistent with the database version of the fifth database, the first electronic device can use one query statement to query the data in the fourth database and the data in the fifth database, thereby improving the efficiency of data query.
[0026] In another possible implementation, the synchronization request includes an identifier of the second electronic device, an identifier of the second application, an identifier of the second database, and a first synchronization sequence number; wherein the first synchronization sequence number is used to indicate a first position in the second database, and the first position is used to determine the target data.
[0027] In another possible implementation, the target data is transmitted via a transmission protocol, and the transmission protocol is also used to transmit data associated with multiple applications different from the second application.
[0028] In the above technical solution, the transmission protocol for transmitting the target data can also be used to transmit data generated by other applications different from the second application. In other words, the target data is transmitted based on a universal transmission protocol, that is, before the first electronic device obtains the target data, the second electronic device does not need to use the specific protocol format associated with the second application to encapsulate the target data. In this way, the universality of the data synchronization method provided in the embodiment of the present application can be guaranteed, and at the same time, the efficiency of data synchronization can be improved.
[0029] In another possible implementation manner, the first database and the second database are embedded databases.
[0030] In a second aspect, a data synchronization method is provided, which is applied to a second electronic device, and the method includes: receiving a synchronization request from a first application of a first electronic device, the synchronization request being used to request that target data in a second database within the second electronic device be backed up to a first database within the first electronic device, the second database being associated with a second application of the second electronic device, and the first database being associated with the first application; obtaining the target data from the second database according to the synchronization request; sending the target data to the first electronic device, so that the first electronic device updates the first database using the target data to obtain an updated first database, the data in the second database being the same as the data in the updated first database.
[0031] It should be understood that the database mode of the first database in the first electronic device is a slave database, and the database mode of the second database in the second electronic device is master data. Specifically, the first database is a slave database of the second database, and the second database is a master database of the first database. Based on this, the first electronic device is also called a slave device for data synchronization, and the second electronic device is also called a master device for data synchronization.
[0032] It should be understood that the updated first database and the first database have the same database identifier, the difference is that the data stored in the updated first database and the data stored in the first database are not completely the same. It should also be understood that the database mode of the updated first database is a slave database.
[0033] In the above technical solution, the second electronic device and the first electronic device communicate with each other in an end-to-end manner, so that the first electronic device synchronizes the target data in the second database associated with the second application of the second electronic device requested by the first synchronization request to the first database associated with the first application of the first electronic device, and obtains a third database, so that the data in the third database is the same as the data in the second database. In the above-mentioned interaction process between the second electronic device and the first electronic device, there is no need for the participation of the cloud server, and the second electronic device does not involve the format conversion of the data to be synchronized (i.e., the target data) in the second database. In this way, the user's privacy data security can be protected, and at the same time, the efficiency of data synchronization can be improved.
[0034] In one possible implementation, before receiving a synchronization request for a first application from a first electronic device, the method further includes: receiving a modification request from the first electronic device, the modification request being used to request the second electronic device to perform a modification operation on a third database within the second electronic device to obtain the second database, the third database being associated with the second application of the second electronic device, the data in the third database being the same as the data in the first database, wherein the target data is data associated with the modification operation; and performing a modification operation on the third database according to the modification request to obtain the second database.
[0035] It should be understood that the third database is a database having a master data schema, and the third database is a master database of the first database.
[0036] It should be understood that the modification operation performed on the third database may be a write operation (eg, a delete operation or a modification operation, etc.) performed on the data in the third database, or may be inserting new data into the third database.
[0037] In the above technical solution, the second electronic device can perform a modification operation on the third database in the second electronic device as the master database of the first database according to the modification requirements (i.e., modification request) of the first electronic device on the first database with the slave database mode in the first electronic device, and obtain the second database. Thereafter, after the second electronic device receives the synchronization request of the first electronic device, the data in the second database requested by the synchronization request (i.e., target data) can be sent to the first electronic device, so that the first electronic device updates the first database according to the acquired target data, so that the data in the updated first database is the same as the data in the second database. That is to say, in the above technical solution, on the basis of the master-slave synchronization mode, the second electronic device as the master device can perform a modification operation on the third database in the second electronic device according to the modification requirements of the first electronic device itself as the slave device to obtain the second database, and synchronize the target data associated with the modification operation in the second database to the first database in the first electronic device. In the above-mentioned interaction process between the first electronic device and the second electronic device, there is no need for the participation of the cloud server, and there is no need for the format conversion of the data to be synchronized (i.e., the second data) in the second database, so that the user's privacy data security can be protected, and at the same time, the data synchronization efficiency can be improved.
[0038] In another possible implementation manner, the modification request includes an identifier of the second electronic device, an identifier of the second application, an identifier of the third database, and the modification operation.
[0039] In another possible implementation, after performing the modification operation on the third database according to the modification request and obtaining the second database, the method further includes: sending a notification message to the first electronic device, wherein the notification message is used to indicate that the second electronic device has successfully performed the modification operation on the third database according to the modification request.
[0040] In the above technical solution, when the second electronic device performs a modification operation on the third database in the second electronic device according to the modification request, the second electronic device sends a notification message to the first electronic device, so that the first electronic device can know that the second electronic device has successfully performed the modification operation requested by the modification request on the third database in the second electronic device according to the modification request sent by the first electronic device. Thereafter, the first electronic device sends a synchronization request to the second electronic device, which is conducive to improving the efficiency and success rate of data synchronization.
[0041] In another possible implementation, after performing a modification operation on the third database according to the modification request to obtain the second database, the method further includes:
[0042] The log file in the second electronic device is updated to obtain an updated log file, wherein the updated log file records the modification operation.
[0043] It should be understood that the log file in the second electronic device is a log file of the third database in the second electronic device. In other words, the log file in the second electronic device is used to record write operations (eg, modification, deletion or insertion) performed on the third database.
[0044] In the above technical solution, after the second electronic device performs a modification operation on the third database to obtain the second database, the second electronic device updates the log file of the third database. In this way, the consistency of the obtained second database and the updated log file can be guaranteed, which is conducive to ensuring the accuracy of the results of subsequent data synchronization of the data in the second database.
[0045] In another possible implementation, the second electronic device includes a second synchronization service and a second database engine, and the receiving of a synchronization request from a first application of the first electronic device includes: the second synchronization service receiving the synchronization request; the obtaining of the target data from the second database according to the synchronization request includes: the second synchronization service sending indication information to the second database engine according to the synchronization request, and the indication information is used to instruct the second database engine to obtain the target data from the second database; the method also includes: the second database engine sending the target data to the second synchronization service; the sending of the target data to the first electronic device includes: the second synchronization service sending the target data to the first electronic device.
[0046] Exemplarily, in some implementations, the second electronic device further includes a second database access framework. Based on this, in the implementation, the second synchronization service sends indication information to the second database engine according to the synchronization request, including: the second synchronization service generates the indication information according to the synchronization request; the second synchronization service sends the indication information to the second database engine through the second database access framework.
[0047] In another possible implementation, the indication information carries the first synchronization sequence number included in the synchronization request, and the first synchronization sequence number is used to indicate the first position in the second database; after the second synchronization service sends the indication information to the second database engine according to the synchronization request, the method also includes: if the first position and the second position in the second database are the same, the second database engine determines the data in the second database located at the first position and the data located after the first position as the target data, and the second position is the position in the second database indicated by the second synchronization sequence number of the second electronic device; if the first position and the second position are different, the second database engine determines the data in the second database located from the first position to the second position as the target data.
[0048] It should be understood that the data from the first position to the second position includes the following data: data at the first position, data at a position between the first position and the second position, and data at the second position.
[0049] In another possible implementation, the target data is transmitted via a transmission protocol, and the transmission protocol is also used to transmit data associated with multiple applications different from the second application.
[0050] In the above technical solution, the transmission protocol used by the second electronic device to transmit the target data can also be used to transmit data generated by other applications different from the second application. In other words, the target data is transmitted based on a universal transmission protocol, that is, before the second electronic device sends the target data to the first electronic device, the second electronic device does not need to use the specific protocol format associated with the second application to encapsulate the target data. In this way, the universality of the data synchronization method provided in the embodiment of the present application can be guaranteed, and at the same time, the efficiency of data synchronization can be improved.
[0051] In another possible implementation manner, the first database and the second database are embedded databases.
[0052] In a third aspect, the present application provides a data synchronization method, which is applied to a data synchronization system including a first electronic device and a second electronic device, the method comprising: the first electronic device generates a synchronization request for a first application of the first electronic device, the synchronization request is used to request to back up target data in a second database in the second electronic device to a first database in the first electronic device, the second database is associated with the second application of the second electronic device, and the first database is associated with the first application; the first electronic device sends the synchronization request to the second electronic device; the second electronic device obtains the target data from the second database according to the synchronization request; the second electronic device sends the target data to the first electronic device; the first electronic device updates the first database using the target data to obtain an updated first database, and the data in the second database is the same as the data in the updated first database.
[0053] In a fourth aspect, the present application provides a data synchronization device, which is applied to a first electronic device including a first application, the device including a processing unit, and the processing unit is used to: generate a synchronization request for the first application, the synchronization request is used to request to back up target data in a second database in a second electronic device to a first database in the first electronic device, the second database is associated with a second application of the second electronic device, and the first database is associated with the first application; send the synchronization request to the second electronic device; receive the target data from the second electronic device; use the target data to update the first database to obtain an updated first database, the data in the second database is the same as the data in the updated first database.
[0054] In a fifth aspect, the present application provides a data synchronization device, which is applied to a second electronic device, and the device includes a processing unit, and the processing unit is used to: receive a synchronization request from a first application of a first electronic device, the synchronization request is used to request to back up target data in a second database in the second electronic device to a first database in the first electronic device, the second database is associated with the second application of the second electronic device, and the first database is associated with the first application; according to the synchronization request, obtain the target data from the second database; send the target data to the first electronic device, so that the first electronic device updates the first database using the target data to obtain an updated first database, and the data in the second database is the same as the data in the updated first database.
[0055] In a sixth aspect, the present application provides a data synchronization system, the system comprising a first electronic device and a second electronic device, the first electronic device being used to generate a synchronization request for a first application of the first electronic device, the synchronization request being used to request that target data in a second database within the second electronic device be backed up to a first database within the first electronic device, the second database being associated with a second application of the second electronic device, and the first database being associated with the first application; the first electronic device being further used to send the synchronization request to the second electronic device; the second electronic device being used to obtain the target data from the second database according to the synchronization request; the second electronic device being further used to send the target data to the first electronic device; the first electronic device being further used to update the first database using the target data to obtain an updated first database, the data in the second database being the same as the data in the updated first database.
[0056] It can be understood that the beneficial effects of the third to sixth aspects mentioned above can be found in the relevant descriptions of the first and second aspects mentioned above, and will not be repeated here.
[0057] In a seventh aspect, an electronic device is provided, comprising a unit for executing any one of the data synchronization methods in the first aspect or the second aspect. The device may be a terminal device or a chip in the terminal device. The device may include an input unit and a processing unit.
[0058] When the device is a terminal device, the processing unit may be a processor, and the input unit may be a communication interface; the terminal device may also include a memory, which is used to store computer program code. When the processor executes the computer program code stored in the memory, the terminal device executes any one of the data synchronization methods in the first aspect or the second aspect.
[0059] When the device is a chip in a terminal device, the processing unit may be a processing unit inside the chip, and the input unit may be an output interface, a pin or a circuit, etc.; the chip may also include a memory, which may be a memory inside the chip (for example, a register, a cache, etc.) or a memory located outside the chip (for example, a read-only memory, a random access memory, etc.); the memory is used to store computer program code, and when the processor executes the computer program code stored in the memory, the chip executes any one of the data synchronization methods in the first aspect or the second aspect.
[0060] In one possible implementation, a memory is used to store computer program code; a processor executes the computer program code stored in the memory, and when the computer program code stored in the memory is executed, the processor is used to execute any one of the data synchronization methods in the first aspect or the second aspect.
[0061] In an eighth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program code. When the computer program code is executed by a data synchronization device, the data synchronization device executes any one of the data synchronization methods in the first to third aspects.
[0062] In a ninth aspect, a computer program product is provided, the computer program product comprising: a computer program code, when the computer program code is executed by a data synchronization device, the data synchronization device executes any one of the data synchronization methods in the first to third aspects. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] Figure 1 It is a schematic diagram of an application scenario suitable for the data synchronization method provided in an embodiment of the present application.
[0064] Figure 2 It is a schematic diagram of a specific application scenario applicable to the data synchronization method provided in the embodiment of the present application.
[0065] Figure 3 It is a schematic diagram of an architecture of a first electronic device and a second electronic device that execute the data synchronization method provided in an embodiment of the present application.
[0066] Figure 4 It is a schematic diagram of a software system of an electronic device that executes the data synchronization method provided in an embodiment of the present application.
[0067] Figure 5 It is a schematic diagram of another architecture of a first electronic device and a second electronic device for executing the data synchronization method provided in an embodiment of the present application.
[0068] Figure 6 It is a schematic diagram of another architecture of a first electronic device and a second electronic device for executing the data synchronization method provided in an embodiment of the present application.
[0069] Figure 7 It is a schematic diagram of a data synchronization method provided in an embodiment of the present application.
[0070] Figure 8 yes Figure 7 A schematic diagram of a database in a first electronic device and a database in a second electronic device involved in a data synchronization method is provided.
[0071] Fig. 9 yes Figure 7 A schematic diagram of a database in a first electronic device and a database in a second electronic device involved in a data synchronization method is provided.
[0072] Fig.10 yes Figure 7 A schematic diagram of a specific example of a data synchronization method is provided.
[0073] Fig.11 yes Figure 7 A schematic diagram of another specific example of a data synchronization method is provided.
[0074] Fig.12 It is a schematic diagram of another data synchronization method provided in an embodiment of the present application.
[0075] Fig.13 yes Fig.12 A schematic diagram of a database in a first electronic device and a database in a second electronic device involved in a data synchronization method is provided.
[0076] Fig.14 yes Fig.12 A schematic diagram of a specific example of a data synchronization method is provided.
[0077] Fig.15 yes Fig.12 A schematic diagram of a specific example of a data synchronization method is provided.
[0078] Fig.16 It is a schematic diagram of the data query method provided in an embodiment of the present application.
[0079] Fig.17 yes Fig.16 A schematic diagram of a database in a first electronic device and a database in a second electronic device involved in the method provided.
[0080] Fig.18 It is a schematic diagram of a graphical user interface displayed by a first electronic device provided in an embodiment of the present application.
[0081] Fig.19 It is a schematic diagram of a data synchronization device provided in an embodiment of the present application.
[0082] Fig. 20 It is a schematic diagram of the structure of an electronic device provided by the present application. DETAILED DESCRIPTION
[0083] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0084] First, the application scenarios of the data synchronization method provided in the embodiments of the present application are introduced with reference to the accompanying drawings.
[0085] Figure 1 It is a schematic diagram of an application scenario suitable for the data synchronization method provided in an embodiment of the present application.
[0086] For example, see Figure 1 The application scenario shown includes a first electronic device 110 and at least one second electronic device 120. The first electronic device 110 and the second electronic device 120 can communicate with each other through an end-to-end communication method. The communication connection between the first electronic device 110 and the second electronic device 120 can be a short-range communication connection, such as a Wi-Fi point-to-point connection or a Bluetooth connection, etc.; the communication connection between the first electronic device 110 and the second electronic device 120 can also be a long-range communication connection, such as an Internet connection, etc., and no limitation is imposed on the specific type of the end-to-end communication method.
[0087] In the embodiment of the present application, there is no limitation on the device type of any one of the first electronic device 110 and the second electronic device 120. For example, any one of the first electronic device 110 and the second electronic device 120 may be a terminal device such as a mobile phone, a tablet computer, and a notebook computer, or may be a non-terminal device such as a server.
[0088] For example, see Figure 2 The specific schematic diagram of the application scenario provided by the embodiment of the present application is shown, and the application scenario includes a mobile phone 210 as the first electronic device 110, and a tablet 220 as the second electronic device 120. The communication connection between the mobile phone 210 and the tablet 220 can be a Wi-Fi point-to-point connection.
[0089] Based on the communication connection between the first electronic device 110 and the second electronic device 120, the first electronic device 110 can synchronize the application data generated by the application of the second electronic device 120 to the local storage space of the first electronic device 110, so that the first electronic device 110 can access the application data generated by the application of the second electronic device 120 in the local storage space to achieve cross-device data access. It can be understood that the data generated by the application of the second electronic device 120 is stored in the local storage space of the second electronic device 120.
[0090] Similarly, the second electronic device 120 can also synchronize the application data generated by the application of the first electronic device 110 to the local storage space of the second electronic device 120 to achieve cross-device data access. It is understandable that the application data generated by the application of the first electronic device 110 is stored in the local storage space of the first electronic device 110.
[0091] In the embodiments of the present application, the data types accessed across devices described above are not specifically limited. For example, the data accessed across devices may be media data, such as video, audio, and pictures. For another example, the data accessed across devices may also be file data, such as PDF.
[0092] For example, in some application scenarios, Figure 2 The picture data stored in the gallery application of the tablet 220 is synchronized with the gallery application of the mobile phone 210 , so that the user can access the pictures stored in the gallery application of the tablet 220 by browsing the gallery application of the mobile phone 210 .
[0093] It should be understood that Figure 1 and Figure 2 The application scenarios shown are for illustration only and do not constitute any limitation on the application scenarios to which the data synchronization method provided in the embodiments of the present application is applicable.
[0094] Next, based on the above Figure 1 The application scenario shown, combined with the accompanying drawings, introduces the relevant module units within the electronic device involved when the electronic device executes the data synchronization method provided by the embodiment of the present application.
[0095] For example, see Figure 3 The first electronic device 110 includes a first application 111, a first database synchronization service 112, a first database engine 113, and a database in the first electronic device 110. The second electronic device 120 includes a second application 121, a second database synchronization service 122, a second database engine 123, and a database in the second electronic device 120.
[0096] Next, each module unit in the first electronic device 110 is introduced.
[0097] The first application 111 is an application program running in the first electronic device 110. The application data generated by the first application 111 can be stored in the first electronic device 110. The type of the first application 111 is not specifically limited. For example, the first application 111 can be a gallery application, and the application data generated by the first application 111 can be a picture or a video. For another example, the first application 111 can be a table application, and the application data generated by the first application 111 can be a two-dimensional data table.
[0098] The database in the first electronic device 110 is a local database of the first electronic device 110. The database in the first electronic device 110 is a database associated with the first application 111 in the first electronic device 110, that is, the first application 111 can access the database in the first electronic device 110.
[0099] See also Figure 3 , the database in the first electronic device 110 includes a first database 114. The database mode of the first database 114 is a slave database mode, and the first database 114 is used to back up the data in the second database 124 in the second electronic device 120 obtained by the first electronic device 110 to the first database 114, and obtain the updated first database ( Figure 3 (not shown) so that the data in the second database 124 is the same as the data in the updated first database, so that the purpose of data synchronization between the updated first database in the first electronic device and the second database 124 in the second electronic device can be achieved.
[0100] It should be understood that the updated first database and the first database 114 are the same database, that is, the updated first database and the first database 114 have the same database identifier, the difference is that the data stored in the updated first database and the data stored in the first database 114 are not completely the same.
[0101] In some other implementations, the database in the first electronic device 110 may also include: Figure 3 The fifth database 115 is shown by a dotted line. The database mode of the fifth database 115 is a master database mode, and the fifth database 115 is used to store application data generated by the first application 111.
[0102] In the embodiment of the present application, the type of the database in the first electronic device 110 is not specifically limited. In some implementations, the database in the first electronic device 110 is an embedded database embedded in the first application 111. In this implementation, the database in the first electronic device 110 can specifically be a file stored in the memory space of the first electronic device 110, and the first application 111 can access the memory space. For example, the embedded database corresponding to the first application 111 can be, but is not limited to, a lightweight database SQLite. In other implementations, the database in the first electronic device 110 is a non-embedded database. In this implementation, the database in the first electronic device 110 can specifically be a database stored in the disk space of the first electronic device 110, and the first application 111 can access the disk space. For example, the non-embedded database can be, but is not limited to, MySQL.
[0103] The first database synchronization service 112 is used to send data (eg, synchronization request) to the second electronic device 120 , and receive data (eg, data stored in the second database 124 ) sent from the second electronic device 120 to the first electronic device 110 .
[0104] The first database engine 113 is used to perform operations (eg, query operations or update operations, etc.) on the database in the first electronic device 110 .
[0105] For example, the first database engine 113 performs an update operation on the first database 114 based on the structured update statement sent by the first application 111 to obtain the updated first database. For another example, the first database engine 113 performs a query operation on the first database 114 based on the structured query statement sent by the first application 111, and returns the obtained query result to the first application 111.
[0106] Next, each module unit in the second electronic device 120 is introduced.
[0107] The second application 121 is an application program running in the second electronic device 120. When the second electronic device 120 runs the second application 121, application data of the second application 121 will be generated. There is no specific limitation on the application type of the second application 121, and it can be selected according to actual usage requirements. For example, when the second application 121 is a gallery application, the application data generated by the second application 121 can be a picture or a video. For another example, when the second application 121 is a table application, the application data generated by the second application 121 can be a two-dimensional data table.
[0108] The database in the second electronic device 120 is a local database of the second electronic device 120. The database in the second electronic device 120 is specifically a database associated with the second application 121 in the second electronic device 120, that is, the second application 121 can access the database in the second electronic device 120.
[0109] See also Figure 3 The database in the second electronic device 120 includes a second database 124. The database mode of the second database 124 is a master database mode, and the second database 124 is used to store application data generated by the second application 121.
[0110] In some other implementations, the database in the second electronic device 120 may also include a database other than the second database 124 ( Figure 3 (not shown in the figure), the database other than the second database 124 can be a database associated with the second application 121, and the database mode of the database other than the second database 124 is a slave database mode. The database other than the second database 124 backs up the data in the fifth database 115 in the first electronic device 110 obtained by the second electronic device 120 to the database other than the second database 124.
[0111] The second database synchronization service 122 is used to send data (eg, data to be synchronized in the second database 123 ) to the first electronic device 110 , and receive data (eg, synchronization request) sent by the first electronic device 110 to the second electronic device 120 .
[0112] The second database engine 123 is used to perform operations (eg, query operations or update operations) on the database in the second electronic device 120 .
[0113] For example, the second database engine 123 performs an update operation on the second database 124 based on the structured update statement sent by the second application 121 to obtain an updated second database. For another example, the second database engine 123 performs a query operation on the second database 124 based on the structured query statement sent by the second application 121, and returns the obtained query result to the second application 121.
[0114] In the embodiment of the present application, the type of the database in the second electronic device 120 is not specifically limited. In some implementations, the database in the second electronic device 120 is an embedded database embedded in the second application 121, and the second application 121 can access the data in the database corresponding to the second application 121 through an API. In this implementation, the database in the second electronic device 120 can specifically be a file stored in the memory space of the second electronic device 120, and the second application 121 can access the memory space. For example, the embedded database corresponding to the second application 121 can be, but is not limited to, a lightweight database SQLite. In other implementations, the database in the second electronic device 120 is a non-embedded database. In this implementation, the database in the second electronic device 120 can specifically be a database stored in the disk space of the second electronic device 120, and the second application 121 can access the disk space. For example, the non-embedded database can be, but is not limited to, MySQL.
[0115] In some other implementations, the first electronic device 110 may further include: Figure 3 The first database access framework 116 is shown by the dotted line. The second electronic device 120 may also include Figure 3 The second database access framework 125 is shown in dashed lines.
[0116] In the above implementation, the first application 111 in the first electronic device 110 can implement data interaction with the first database synchronization service 112 through the first database access framework 116, and the first application 111 can implement access to the fifth database 115 through the first database access framework 116 and the first database engine 113. It should be understood that the first database synchronization service 112 can also implement data interaction with the first database engine 113 through the first database access framework 116.
[0117] In the above implementation, the second application 121 in the second electronic device 120 can implement data interaction with the second database synchronization service 123 through the second database access framework 125, and the second application 121 can implement access to the second database 124 through the second database access framework 125 and the second database engine 123. It should be understood that the second database synchronization service 123 can also implement data interaction with the second database engine 123 through the second database access framework 125.
[0118] It should be understood that the above Figure 3 The first electronic device 110 and the second electronic device 120 shown are for illustration only and do not constitute any limitation on the first electronic device and the second electronic device that execute the data synchronization method provided in the embodiment of the present application.
[0119] As mentioned above, the data synchronization method provided in the embodiment of the present application can be applied to at least two electronic devices. The software structure of the electronic device is described in detail below in conjunction with the accompanying drawings. It can be understood that the following Figure 4 The software architecture of the electronic device shown may be the software architecture of each of the at least two electronic devices that execute the data synchronization method provided in the embodiment of the present application.
[0120] For example, Figure 4 A schematic diagram of a software system of an electronic device is shown. Figure 4 , the software system adopts a layered architecture. The layered architecture divides the software into several layers, each layer has a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into five layers, from top to bottom, respectively, an application layer 410, an application framework layer 420, an Android runtime (Android Runtime) and a core library layer 430, a hardware abstract layer (HAL) 440, and a kernel layer 450.
[0121] The application layer 410 may include a series of application packages. For example, the application package may include applications such as camera, gallery, chat, call, map, navigation, calendar, Bluetooth, music, video, etc.
[0122] Each of the above-mentioned application programs may include more specific functional modules. For example, a gallery may include a business module and a notification module.
[0123] The above-mentioned various application programs may be used to generate application data. For example, the gallery is used to generate photo data.
[0124] The application framework layer 420 provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer 420 includes some predefined functions.
[0125] like Figure 4 As shown, the application framework layer 420 may include a window manager, a notification manager, an activity manager, an input manager, a view system, a content provider, a resource manager, and the like.
[0126] The window manager provides window management services (WMS). WMS can be used for window management, window animation management, surface management, and as a transfer station for the input system.
[0127] Content providers are used to store and retrieve data and make it accessible to applications. This data can include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0128] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.
[0129] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0130] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.
[0131] The activity manager can provide activity management services (AMS), which can be used to start, switch, and schedule system components (such as activities, services, content providers, and broadcast receivers) as well as manage and schedule application processes.
[0132] The input manager can provide input management services (IMS), which can be used to manage system input, such as touch screen input, key input, sensor input, etc. IMS takes events from input device nodes and distributes them to appropriate windows through interaction with WMS.
[0133] Android Runtime includes core libraries and virtual machines. Android Runtime is responsible for scheduling and management of the Android system.
[0134] The core library consists of two parts: one part is the function that the programming language (for example, Java language) needs to call, and the other part is the Android core library.
[0135] The application layer 410 and the application framework layer 420 run in a virtual machine. The virtual machine executes the programming files (e.g., java files) of the application layer 410 and the application framework layer 420 as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.
[0136] The core library layer 430 may include multiple functional modules, such as surface manager, media framework, libc, SQLite, OpenGL ES, Webkit, etc.
[0137] The surface manager is used to manage the display subsystem and provides the fusion of two-dimensional (2D) and three-dimensional (3D) layers for multiple applications.
[0138] The media framework supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0139] The hardware abstraction layer (HAL) 440 is an interface layer located between the operating system kernel and the upper software, and its purpose is to abstract the hardware. The hardware abstraction layer is an abstract interface driven by the device kernel, which is used to implement the application programming interface that provides access to the underlying device to the higher-level Java API framework. HAL contains multiple library modules, such as camera HAL, Vendor warehouse, display, Bluetooth, audio, etc. Each library module implements an interface for a specific type of hardware component. It can be understood that the camera HAL can provide an interface for the camera FWK to access hardware components such as cameras. The Vendor warehouse can provide an interface for the media FWK to access hardware components such as encoders. When the system framework layer API requires access to the hardware of the portable device, the Android operating system will load the library module for the hardware component.
[0140] The kernel layer 450 is the foundation of the Android operating system, and the final functions of the Android operating system are all completed through the kernel layer. The kernel layer may include display drivers, camera drivers, audio drivers, and sensor drivers.
[0141] It should be noted that the application provides Figure 4The software structure diagram of the electronic device shown is only an example and does not limit the specific module division in different layers of the Android operating system. For details, please refer to the introduction of the Android operating system software structure in conventional technology. In addition, the shooting method provided in this application can also be implemented based on other operating systems (for example, IOS or Hongmeng, etc.), and this application will not give examples one by one.
[0142] Next, the above Figure 4 The software architecture of the electronic device is shown as Figure 3 The software architecture of the first electronic device 110 and the second electronic device 120 shown in FIG. Figure 5 , introduce the above Figure 3 The first electronic device 110 and the second electronic device 120 include various module units and Figure 4 Shows the relationship between software architectures.
[0143] For example, see Figure 5 , the above Figure 3 The application of the first electronic device 110 , the application of the second electronic device, the first database access framework 116 , the second database access framework 125 , the first database synchronization service 112 , and the second database synchronization service 122 all belong to module units in the application layer 410 .
[0144] like Figure 5 As shown, the applications of the first electronic device 110 include a file manager, a media application and a distributed gallery, wherein the applications of the first electronic device 110 are Figure 3 A specific example of the first application 111 is shown.
[0145] The first database access framework 116 is integrated into the application in the form of a binary archive file (Android Archive, AAr) package of an Android library project. Figure 5 The first database access framework 116 includes configuration management, connection management, structured query language (SQL) statement management, transaction management and synchronization management modules.
[0146] Next, the functions of each module in the first database access framework 116 are introduced. It should be understood that Figure 5 The functions of the various modules included in the second database access framework 125 shown can refer to the description of the various modules in the first database access framework 116 below.
[0147] Configuration management is used to configure the properties of the database in the first electronic device 110. For example, the configuration management is used to configure the mode of the database in the first electronic device to be a master database mode or a slave database mode.
[0148] The connection management is used to manage the connection with the first database engine 113. In practical applications, if a connection has been established between the application of the first electronic device 110 and the first database engine 113, the connection can be stored in the connection management, so that the connection can be directly obtained from the connection management next time.
[0149] The sql statement management is used to encapsulate sql statements. For example, the sql statement management is used to encapsulate sql statements for executing insert operations, delete operations, modify operations or query operations on the database in the first electronic device 110.
[0150] Transaction management is used to manage the start, end or rollback of a transaction. Rollback refers to the act of restoring a program or data to its last correct state when a program or data processing error occurs. For example, rollback includes program rollback and data rollback.
[0151] Synchronization management is used to provide an interface for the application of the first electronic device 110 to obtain the database in the first electronic device 110, and to make a callback when the synchronization data is completed. In other words, the synchronization management in the first database access framework 116 is a bridge used to connect the first database access framework 116 and the first database synchronization service 112.
[0152] The first database synchronization service 112 is mainly used for data transmission and reception across devices. The first database synchronization service 112 may be a system application package of the first electronic device 110. Figure 5 The first database synchronization service 112 includes access management, synchronization management and data transmission and reception.
[0153] Access management is the authentication and verification of application requests.
[0154] Synchronization management is to encapsulate the message requesting synchronization and parse the received files.
[0155] The data transmission and reception is used to send data to the second electronic device, or receive data from the second electronic device.
[0156] Figure 5The first database engine 113 shown belongs to the core library layer of the first electronic device 110. In some implementations, the first database engine 113 runs in an Android application package (apk) in the form of a dynamic library file (so).
[0157] See also Figure 5 The first database engine 113 includes a storage component and a database log component. Next, the functions of each module included in the first database engine 113 are introduced. It should be understood that Figure 5 The functions of the modules included in the second database engine 123 shown can refer to the description of the modules in the first database engine 113 below.
[0158] The storage component is used to store the database in the first electronic device 110. In some implementations, the database in the first electronic device 110 includes: Figure 3 In the case of the first database 114 shown, the first database 114 may be a database associated with an application of the first electronic device 110 , that is, the first database is used to store application data generated by the associated application.
[0159] The database operation log component is used to store structured query language for performing operations (eg, inserting, deleting, or rewriting operations, etc.) on the database in the first electronic device 110 .
[0160] It should be understood that Figure 5 The first database engine 113 shown may also include other modules, and the second database engine 123 may also include other modules. Among them, the other modules included in the first database engine 113 are associated with the database type of the database in the first electronic device 110 stored by the storage component in the first database engine 113. The other modules included in the second database engine 123 are associated with the database type of the database in the second electronic device 120 stored by the storage component in the second database engine 123.
[0161] The kernel layer includes the kernel layer of the first electronic device 110 and the kernel layer of the second electronic device 120 .
[0162] In the embodiment of the present application, there is no specific limitation on the operating system type of the first electronic device 110 and the operating system type of the second electronic device 120. For example, the operating system of the first electronic device 110 may be Android, and the operating system of the second electronic device 120 may be Windows. For another example, the operating system of the first electronic device 110 and the operating system of the second electronic device 120 may both be Android systems.
[0163] Below, based on Figure 5 The first electronic device and the second electronic device are shown, taking the application of the first electronic device as a media application and the application of the second electronic device as a computer manager as an example, Figure 6 describe Figure 5 A specific example of the first electronic device and the second electronic device is shown.
[0164] See also Figure 6 The first electronic device 110 includes a media application, a first database synchronization service 112 , a first database engine 113 and a first database access framework 116 .
[0165] The media application of the first electronic device 110 is an application program running in the first electronic device 110 , and the media application can generate media data.
[0166] Figure 6 The functions of the various modules included in the first database synchronization service 112 shown in FIG. Figure 5 The functions of the various modules included in the first database synchronization service 112 are not described in detail here.
[0167] The first database engine 113 includes a database operation log component, a storage component, an interface, a compiler, a virtual database engine (VDBE), a B-Tree, a pager, and a virtual file system (VFS). Figure 6 In the case where the first database 114 in the storage component shown is a SQLite database, the first database engine 113 may include an interface, a compiler, a virtual database engine (VDBE), a B-Tree, a pager, and a virtual file system (VFS).
[0168] The role of the database operation log component included in the first database engine 113 is the same as the above Figure 5 The database operation log shown has the same function. For details not described in detail here, please refer to the above Figure 5 In some implementations, the database operation log component included in the first database engine 113 may specifically be a binary log (binlog) component module.
[0169] The storage components included in the first database engine 113 have the same functions as those mentioned above. Figure 5 The functions of the storage components shown are the same, and the contents not described in detail here can be found in the above Figure 5Related description in .
[0170] The interface is provided by the database engine to the outside world and is mainly used for calls by the database access framework layer.
[0171] The compiler is the way SQLite interprets and executes SQL statements, checking and compiling them through a lexical analyzer and a syntax analyzer.
[0172] VDBE shields information related to the operating system platform of the first electronic device 110, so that the media application of the first electronic device 110 only needs to generate target code (bytecode) running on the virtual machine to run on different operating system platforms.
[0173] B-Tree is a data structure. SQLite database uses B-Tree to store data in the database. Specifically, B-Tree is used to store data stored in the database as a tree structure. B-Tree organizes the data in the database in a tree structure, which highly optimizes the index and search mechanism.
[0174] Pager is the smallest unit of database transaction on the file system. Pager is responsible for reading, writing and caching these data blocks, and provides transaction rollback, transaction commit, and management of data file locks. B-Tree requests specific pages from Pager, and B-Tree will also notify Pager when it needs to modify a page, commit or rollback the current modification.
[0175] VFS is used to provide a unified file system interface to user processes.
[0176] See also Figure 6 , Figure 6 The database operation log components shown include storage management, version management, synchronization management, upper limit management and reliability management. It should be understood that Figure 6 The database log component shown is Figure 5 A specific example of a database operation log component is shown.
[0177] Storage management is used to store the relevant content of the modification of the database log files.
[0178] Version management is used to manage the version of the database log files. For example, every time the database log is deleted, the version management will regenerate a new version number of the database log.
[0179] Synchronization management is used to manage the operation of full export or incremental export when requesting synchronization.
[0180] Upper limit management is used to limit the total amount of data stored in the database log. For example, when the data written in the database log file exceeds 100 megabytes, the database log file can be cleaned up through upper limit management.
[0181] Reliability management is used to ensure the consistency of the first database 114 and the log file of the first database 114. In some implementations, when backing up the data in the second database 124 to the first database 114 to obtain an updated first database, reliability management is also used to perform integrity verification on the updated first database to verify whether the data in the updated first database as a slave database is consistent with the data in the second database 124 as a master database.
[0182] See also Figure 6 The second electronic device 120 includes a computer manager, a second database synchronization service 122 , a second database engine 123 and a second database access framework 125 .
[0183] in, Figure 6 The functions of the second database synchronization service 122 and the second database access framework 125 shown in FIG. 1 and FIG. 1 include the functions of the modules. Figure 5 The description of each module included in the second database synchronization service 122 and the second database access framework 125 is given in FIG. Figure 6 The functions of the various modules included in the second database engine 123 shown in FIG. Figure 6 A description of each module included in the first database engine 113 is given in FIG.
[0184] Above, combined Figures 1 to 6 The application scenarios applicable to the data synchronization method provided in the embodiment of the present application and the architecture of the electronic device included in the application scenarios are described in detail.
[0185] As mentioned above, in order to solve the problems existing in the traditional technology, the technical solution of the data synchronization method provided by the present application is as follows: based on the end-to-end cross-device method between the first electronic device and the second electronic device, the data to be synchronized (i.e., target data) in the second database associated with the second application of the second electronic device can be synchronized to the first database associated with the first application of the first electronic device to obtain the updated first database, so that the data in the second database is the same as the data in the updated first database. Among them, the first database is a local database of the first electronic device, the second database is a local database of the second electronic device, and the first database is the slave data of the second database. In the above data synchronization process, there is no need for the participation of the cloud server, but the data transmission is realized through an end-to-end cross-device method, so that the data synchronization efficiency can be improved while protecting the security of user privacy data. In addition, in the above data synchronization process, it does not involve the use of a transmission protocol associated with the application type to convert the format of the data to be synchronized (i.e., target data) in the second database, so that the versatility of the data synchronization method provided in the embodiment of the present application can be guaranteed.
[0186] Figure 7 Schematic diagram of a data synchronization method provided in an embodiment of the present application. The data synchronization method provided in an embodiment of the present application can be executed by at least two electronic devices, and any one of the at least two electronic devices can be implemented as software, or a combination of software and hardware. Exemplarily, the at least two electronic devices that execute the data synchronization method provided in an embodiment of the present application can be, but are not limited to, Figure 1 A first electronic device 110 and a second electronic device 120 in the embodiment.
[0187] like Figure 7 As shown, the data synchronization method provided in the embodiment of the present application includes S710 to S750. S710 to S750 are described in detail below.
[0188] S710, the first electronic device generates a synchronization request for the first application, the synchronization request is used to request to back up the target data in the second database in the second electronic device to the first database in the first electronic device, the second database is associated with the second application of the second electronic device, and the first database is associated with the first application.
[0189] In the above step S710, the synchronization request is used to request to back up the target data in the second database in the second electronic device to the first database in the first electronic device, that is, the first database is a slave database, and the second database is a master database. Based on this, the data synchronization method between the first electronic device and the second electronic device is also called a master-slave mode data synchronization method, the first electronic device is also called a slave device of data synchronization, and the second electronic device is also called a master device of data synchronization.
[0190] Next, the first database in the first electronic device associated with the synchronization request described in step S710, the association between the first database and the first application, the second database in the second electronic device, and the association between the second database and the second application are introduced.
[0191] The first database in the first electronic device is used to store the target data backed up from the second database in the second electronic device. It should be understood that the first database in the first electronic device is a local database of the first electronic device, that is, the first electronic device can access the data stored in the first database without accessing any other electronic device.
[0192] The association between the first database and the first application means that the first application can perform read operations (e.g., query operations or copy operations, etc.) and write operations on the second database. Among them, the first application can perform write operations on the second database, which means the operation of writing data (e.g., target data) in the second database to be synchronized to the first database into the first database. The first application performs read operations and write operations on the first database, which can be the first application performing read operations and write operations on the first database through the database engine in the first electronic device.
[0193] The second database in the second electronic device is used to store application data (e.g., photos or data tables, etc.) generated by the second application. It should be understood that the second database in the second electronic device is a local database of the second electronic device, that is, the second electronic device can access the data stored in the second database without accessing any other electronic device.
[0194] The second database is associated with the second application of the second electronic device, which means that the second application can perform read operations (for example, query operations or copy operations, etc.) and write operations (for example, modification operations, deletion operations, or insertion operations, etc.) on the second database. The second application performs read operations and write operations on the second database, which can be the second application performing read operations and write operations on the second database through a database engine in the second electronic device. It should be understood that the second database in the second electronic device is a master database, that is, the second electronic device can perform modification operations (for example, deletion operations, rewrite operations, or insertion operations, etc.) on the second database according to modification requirements.
[0195] In the embodiment of the present application, the database types of the first database and the second database are not specifically limited. In some implementations, the first database and the second database may be embedded databases (such as SQLite databases). In other implementations, the first database and the second database may be non-embedded databases (such as MySQL databases).
[0196] For example, when the first database is an embedded database, the first database may be a database embedded in the first application, that is, the first database is a part of the first application. Similarly, when the second database is an embedded database, the second database may be a database embedded in the second application, that is, the second database is a part of the second application.
[0197] In the above step S710, the synchronization request is used to request to back up the target data in the second database in the second electronic device to the first database in the first electronic device, that is, the target data is the data to be synchronized from the second database to the first database. In the embodiment of the present application, the target data in the second database is not specifically limited, and the target data can be determined by comparing the data in the first database with the data in the second database.
[0198] In some implementations, the target data is all the data included in the second database. In this implementation, the synchronization request is used to request to back up all the data in the second database in the second electronic device to the first database in the first electronic device. This data synchronization method is also called full data synchronization.
[0199] For example, see Figure 8 In (1), in the first electronic device, the database associated with the first application includes a first database, and the first database is an empty database, that is, no data is stored in the first database; in the second electronic device, the second database associated with the second application stores table A. Based on Figure 8 In (1), the synchronization request sent by the first electronic device to the second electronic device is used to request that all data in the second database in the second electronic device (i.e., table A) be backed up to the first database in the first electronic device. This data synchronization process is a full data synchronization process.
[0200] In some other implementations, the target data is part of the data in the second database, and this part of the data is part of the data where there is a difference between the first database and the second database. In this implementation, the synchronization request is to request to back up part of the data in the second database in the second electronic device to the first database in the first electronic device. This data synchronization method is also called incremental data synchronization.
[0201] For example, see Fig. 9 In (1), in the first electronic device, a first database associated with a first application stores table A; in the second electronic device, a second database associated with a second application stores table B, wherein the part of data that differs between table A and table B is the row of data with ID 004 in table B. Based on Fig. 9In (1), the synchronization request sent by the first electronic device to the second electronic device is used to request to back up part of the data in the second database in the second electronic device (i.e., the row of data with ID 004 recorded in Table B) to the first database in the first electronic device. This data synchronization process is an incremental data synchronization process.
[0202] It should be noted that the above description is based on the example that the database associated with the first application of the first electronic device includes a first database, and the database associated with the second application of the second electronic device includes a second database. In some other implementations, the database associated with the first application may also include a fourth database in addition to the first database, wherein the fourth database is used to store application data generated by the first application. In some other implementations, the database associated with the second application also includes a database other than the second database, and the database other than the second database is used to store data for backing up the data in the fourth database, thereby achieving data synchronization between the database other than the second database and the fourth database.
[0203] In the above step S710, exemplarily, the synchronization request includes an identifier of the second electronic device, an identifier of the second application, an identifier of the second database and a first synchronization sequence number; wherein the first synchronization sequence number is used to indicate a first position in the second database, and the first position is used to determine the target data.
[0204] In the above implementation, the identifier of the second electronic device is used to identify the second electronic device, the identifier of the second application is used to represent the second application, and the identifier of the second database is used to identify the second electronic device. In the embodiment of the present application, the type of any identifier is not specifically limited.
[0205] For example, the identifier of the second electronic device may be, but is not limited to, an identity document (ID) of the second electronic device or a media access control (MAC) address of the second electronic device. For example, the identifier of the second application may be, but is not limited to, an application ID of the second application. For example, the identifier of the second database may be, but is not limited to, a database name of the second database.
[0206] In the above implementation, the first synchronization sequence number may be a synchronization sequence number recorded in a log file in the first electronic device, and the log file in the first electronic device is a log file of a first database in the first electronic device. In some implementations, the log file of the first database includes a header, an index page, and a data page, and the first synchronization sequence number may specifically be a sequence number recorded in an index page of the log file of the first database.
[0207] In an embodiment of the present application, before the first electronic device executes the above step S710, the first electronic device may also execute the step of generating a synchronization request. In some implementations, the synchronization request may be a request generated by a first application of the first electronic device. For example, the first application may generate a synchronization request according to an instruction input by a user.
[0208] In the embodiments of the present application, the types of the first application and the second application are not specifically limited. In some implementations, the first application and the second application may be applications of the same type. For example, the first application and the second application may be, but are not limited to, any of the following types of applications: a spreadsheet software application, a gallery application, a video application, or a text message application, etc. In other implementations, the first application and the second application are applications of different types. For example, the first application is a gallery application, and the second application is a computer manager application.
[0209] S720: The first electronic device sends a synchronization request to the second electronic device. Correspondingly, the second electronic device receives the synchronization request from the first electronic device.
[0210] In the above step S720, the first electronic device sends a synchronization request to the second electronic device, which can be understood as the first electronic device directly sending the synchronization request to the second electronic device. In other words, the first electronic device and the second electronic device communicate based on an end-to-end (also called point-to-point) manner, and in this data transmission process, the synchronization request sent by the first electronic device to the second electronic device does not need to be forwarded by an intermediate device.
[0211] In the above step S720, the first electronic device sends the synchronization request to the second electronic device, which means that the first electronic device encapsulates the synchronization request data based on a universal transmission protocol and then sends the encapsulated synchronization request to the second electronic device.
[0212] For example, data interaction can be implemented between the first electronic device and the second electronic device based on a point-to-point protocol. Based on this, the first electronic device uses the point-to-point protocol to encapsulate the synchronization request and sends the encapsulated synchronization request to the second electronic device.
[0213] S730: The second electronic device obtains target data from the second database according to the synchronization request.
[0214] Executing the above step S730, that is, the second electronic device obtains the target data from the second database according to the synchronization request, includes: the second electronic device determines certain data in the second database as target data according to the synchronization request; the second electronic device reads the determined target data in the second database.
[0215] Next, a method for the second electronic device to determine target data in the second database according to a synchronization request is introduced.
[0216] In one implementation, the synchronization request includes a first synchronization sequence number, and in the step of determining the target data by the second electronic device, exemplarily, includes: if the first position indicated by the first synchronization sequence number and the second position in the second database are the same, the second electronic device determines the data located at the first position and the data located after the first position in the second database as the target data, and the second position is the position in the second database indicated by the second synchronization sequence number of the second electronic device; if the first position and the second position are different, the second electronic device determines the data located from the first position to the second position in the second database as the target data.
[0217] The second synchronization sequence number may be a synchronization sequence number recorded in a log file in the second electronic device, and the log file in the second electronic device is a log file of a second database in the second electronic device. In some implementations, the log file of the second database includes a header, an index page, and a data page, and the second synchronization sequence number may specifically be a sequence number recorded in an index page of the log file of the second database.
[0218] The data from the first position to the second position includes data at the first position, data at a position between the first position and the second position, and data at the second position.
[0219] In the embodiment of the present application, the value of the second synchronization sequence number and the value of the first synchronization sequence number may be the same or different, and there is no specific limitation on this.
[0220] S740: The second electronic device sends target data to the first electronic device. Correspondingly, the first electronic device receives the target data from the second electronic device.
[0221] The purpose of the second electronic device executing the above step S740 is that the second electronic device sends the target data to the first electronic device so that the first electronic device updates the first database using the target data to obtain an updated first database, and the data in the updated first database is the same as the data in the second database.
[0222] In the above step S740, the second electronic device sends the target data to the first electronic device, which means that the second electronic device directly sends the target data to the first electronic device. In other words, the data transmission between the first electronic device and the second electronic device is based on an end-to-end (also called point-to-point) method, that is, the target data sent by the second electronic device to the first electronic device does not need to be forwarded by an intermediate device.
[0223] In the above-mentioned step S740, the second electronic device sends the target data to the first electronic device, which means that the second electronic device encapsulates the target data based on the transmission protocol and sends the encapsulated target data to the second electronic device. Among them, the target data is transmitted through a transmission protocol, and the transmission protocol is also used to transmit data associated with multiple applications different from the second application. It should be understood that there are differences in the data formats of application data generated by different applications. In this implementation, the transmission protocol for the second electronic device to transmit the target data generated by the second application can also be used to transmit data of other types of applications. In other words, the second electronic device does not need to encapsulate the target data generated by the second application in a specific protocol format (i.e., the format of the transmission protocol corresponding to the application type), so that the versatility of the data synchronization method provided in the embodiment of the present application and the efficiency of data synchronization can be guaranteed.
[0224] For example, data interaction can be implemented between the first electronic device and the second electronic device based on a point-to-point protocol. Based on this, the second electronic device encapsulates the target data using the point-to-point protocol and sends the encapsulated target data to the second electronic device.
[0225] S750: The first electronic device updates the first database using the target data to obtain an updated first database, wherein the data in the updated first database is the same as the data in the second database.
[0226] The first database and the updated first database have the same database identifier, that is, the first database and the updated first database are the same database, and the difference is that there are differences between the data in the first database and the data in the updated first database.
[0227] The following describes the data stored in the first database, the second database, and the updated first database in the above step S750 by example. It should be understood that the following examples are only for illustration and do not constitute any limitation on the amount and / or type of data stored in the first database, the second database, and the updated first database involved in the embodiments of the present application.
[0228] For example, Figure 8 Taking the first database and the second database shown in (1) as an example, the updated first database in the above step S750 is as follows: Figure 8 The updated first database in the first electronic device shown in (2) above, the second database in the above step S750 is as follows Figure 8 The second database in the second electronic device shown in (2) of FIG. Figure 8 As can be seen from (2) in the figure, the data in the updated first database in the first electronic device is the same as the data in the second database in the second electronic device.
[0229] For example, Fig. 9 Taking the first database and the second database shown in (1) as an example, the updated first database in the first electronic device in the above step S750 is as follows: Fig. 9 The updated first database in the first electronic device shown in (2) of FIG. 1 is as follows. Fig. 9 The second database in the second electronic device shown in (2) of FIG. Fig. 9 As can be seen from (2) in the figure, the data in the updated first database in the first electronic device is the same as the data in the second database in the second electronic device.
[0230] It should be understood that in the above-mentioned step S750, the updated first database in the first electronic device is a slave database of the second database in the second electronic device. In order to ensure that the data stored in the updated first database is the same as the data stored in the second database, in an embodiment of the present application, the first application cannot directly modify the data in the updated first database according to its own modification requirements.
[0231] In the embodiment of the present application, after the first electronic device executes the above step S750, the first electronic device may also perform an integrity check on the updated first database to verify whether the data in the updated first database as the slave database is completely consistent with the data in the second database as the master database. If the first electronic device performs an integrity check on the updated first database and determines that the data in the updated first database is not completely consistent with the data in the second database as the master database, the first electronic device may also re-execute the above steps S710 to S750.
[0232] It should be understood that the above Figure 7 The data synchronization method provided is only for illustration and does not constitute any limitation on the data synchronization method provided in the embodiments of the present application. Figure 7 In the data synchronization method provided, the data synchronization process is described by taking the database in the first electronic device and the database in the second electronic device storing a two-dimensional data table as an example. Optionally, the database in the first electronic device and the database in the second electronic device may also store other types of data, for example, other types of data may be but are not limited to photo data or PDF data. For example, in the above Figure 7 In the data synchronization method provided, the data synchronization principle provided by the embodiment of the present application is described by taking the synchronization of data in the second database in the second electronic device to the first database in the first electronic device as an example. Figure 7The data synchronization principle shown can also synchronize the data in the fourth database in the first electronic device to the sixth database in the second electronic device. In this implementation, the fourth database is the master database of the sixth database, the first electronic device is the master device for data synchronization, and the second electronic device is the slave device for data synchronization.
[0233] In an embodiment of the present application, the first electronic device and the second electronic device synchronize the target data in the second database associated with the second application of the second electronic device requested by the first synchronization request to the first database associated with the first application of the first electronic device, and obtain an updated first database, so that the data in the second database is the same as the data in the updated first database. In the above-mentioned interaction process between the first electronic device and the second electronic device, there is no need for the participation of the cloud server, and there is no need to convert the format of the data to be synchronized (i.e., the target data) in the second database. In this way, the user's privacy data security can be protected, and at the same time, the data synchronization efficiency can be improved.
[0234] Above, combined Figure 7 The interaction steps between the first electronic device and the second electronic device involved in the data synchronization method provided by the present application are described. Figure 7 The data synchronization method shown is combined with the accompanying drawings to introduce the internal interaction steps of the first electronic device and the internal interaction steps of the second electronic device provided by the present application.
[0235] Fig.10 is a schematic diagram of another data synchronization method provided in an embodiment of the present application. It should be understood that Fig.10 The data synchronization method shown is as follows Figure 7 A specific embodiment of the data synchronization method is shown. Fig.10 The data synchronization method provided in the embodiment of the present application is performed by a first electronic device and a second electronic device, wherein the first electronic device includes a first application, a first database engine and a first synchronization service, and the second electronic device includes a second synchronization service and a second database engine. It should be understood that the second electronic device also includes a second application ( Fig.10 (not shown in the figure). For example, Fig.10 The first electronic device shown may be Figure 3 The first electronic device 110 is shown. Fig.10 The second electronic device shown may be Figure 3 The second electronic device 120 is shown. It should be understood that Fig.10 The first synchronization service shown is Figure 3 The first database synchronization service 112 is shown. Fig.10 The second synchronization service shown is Figure 3 A second database synchronization service 122 is shown.
[0236] like Fig.10 As shown, the data synchronization method includes S1001 to S1009. S1001 to S1009 are described in detail below.
[0237] S1001, a first application of a first electronic device generates a synchronization request for the first application (ie Figure 7 A specific example of S710 is shown).
[0238] In the above step S1001, the synchronization request is used to request to back up the target data in the second database in the second electronic device to the first database in the first electronic device, the second database is associated with the second application of the second electronic device, and the first database is associated with the first application.
[0239] The above step S1001 is a specific example of the above step S710, except that the execution subject described in step S1001 is the first application of the first electronic device, and the execution subject described in S710 is the first electronic device. For the contents not described in detail in step S1001, please refer to the above description of step S710.
[0240] S1002: A first application of a first electronic device sends a synchronization request to a first synchronization service.
[0241] There is no specific limitation on the manner in which the first application sends the synchronization request to the first synchronization service.
[0242] In some implementations, the first synchronization service and the first application need to implement data interaction through a first database framework included in the first electronic device. Based on this, in the step of executing S1002, exemplarily, it includes: the first application sends a synchronization request to the first synchronization service through the first database access framework, so that the first synchronization service obtains the synchronization request from the first application.
[0243] In some other implementations, the first synchronization service and the first application may directly interact with each other over data. In this implementation, the first application directly sends a synchronization request to the first synchronization service.
[0244] S1003: The first synchronization service of the first electronic device sends a synchronization request (i.e., Figure 7 (a specific example of S720 is shown in FIG. 1 ). Accordingly, the second synchronization service of the second electronic device receives the synchronization request.
[0245] The above step S1003 is a specific example of the above step S720, the difference being that the execution subject described in S1003 is the first synchronization service of the first electronic device, and the execution subject described in step S720 is the first electronic device. For the contents not described in detail in step S1003, please refer to the relevant description of step S720 above.
[0246] S1004: The second synchronization service of the second electronic device sends indication information to the second database engine according to the synchronization request, where the indication information is used to instruct the second database engine to obtain target data from the second database.
[0247] There is no specific limitation on the manner in which the second synchronization service of the second electronic device sends the indication information to the second database engine according to the synchronization request.
[0248] In some implementations, the second electronic device in the above S1004 also includes a second database access framework. Based on this, in the step of executing S1004, it exemplarily includes: the second synchronization service generates indication information according to the synchronization request; the second synchronization service sends the indication information to the second database engine through the second database access framework.
[0249] In some other implementations, the step of executing S1004 exemplarily includes: the second synchronization service generates indication information according to the synchronization request; and the second synchronization service sends the indication information to the second database engine.
[0250] S1005: The second synchronization service of the second electronic device obtains the target data (i.e. Figure 7 A specific example of S730 is shown).
[0251] The above step S1005 is a specific example of the above step S730, the difference being that the execution subject described in S1005 is the second synchronization service of the second electronic device, and the execution subject described in step S730 is the second electronic device. For the contents not described in detail in step S1005, please refer to the above description of step S730.
[0252] S1006: The second database engine of the second electronic device sends the target data to the second synchronization service.
[0253] There is no specific limitation on the manner in which the second database engine sends the target data to the second synchronization service.
[0254] In some implementations, the second synchronization service and the second database engine need to implement data interaction through a second database framework included in the first electronic device. Based on this, in the step of executing S1006, exemplarily, it includes: the second database engine sends the target data to the second synchronization service through the second database access framework, so that the second synchronization service obtains the target data from the second database engine.
[0255] In some other implementations, the second synchronization service and the second database engine may directly exchange data. In this implementation, the second database engine directly sends the target data to the second synchronization service.
[0256] S1007, the second synchronization service of the second electronic device sends the target data (ie Figure 7 ) Accordingly, the first synchronization service of the first electronic device receives the target data from the second electronic device.
[0257] The above step S1007 is a specific example of the above step S740, the difference being that the execution subject described in S1007 is the second synchronization service of the second electronic device, and the execution subject described in step S740 is the second electronic device. For the contents not described in detail in step S1007, please refer to the above description of step S740.
[0258] S1008: The first synchronization service of the first electronic device sends target data to the first database engine of the first electronic device.
[0259] There is no specific limitation on the manner in which the first synchronization service sends the target data to the first database engine.
[0260] In some implementations, the first synchronization service and the first database engine need to implement data interaction through a first database framework included in the first electronic device. Based on this, in the step of executing S1008, exemplarily, it includes: the first synchronization service sends the target data to the first database engine through the first database access framework, so that the first database engine obtains the target data from the first synchronization service.
[0261] In some other implementations, the first synchronization service and the first database engine may directly interact with each other over data. In this implementation, the first synchronization service directly sends target data to the first database engine.
[0262] S1009: The first database engine of the first electronic device writes the target data into the first database, and obtains an updated first database (i.e. Figure 7 A specific example of S750 is shown).
[0263] The above step S1009 is a specific example of the above step S750. For the contents not described in detail in step S1009, please refer to the relevant description of step S750 above.
[0264] It should be understood that the above Fig.10 The data synchronization method provided is for illustration only and does not constitute any limitation to the data synchronization method provided in the embodiments of the present application.
[0265] Below, based on Figure 7 The data synchronization method shown is combined with the accompanying drawings to introduce another internal interaction step of a first electronic device and an internal interaction step of a second electronic device provided by the present application.
[0266] Fig.11 It is a schematic diagram of another data synchronization method provided in an embodiment of the present application. It should be understood that Fig.11 The data synchronization method shown is as follows Figure 7 A specific embodiment of the data synchronization method is shown. Fig.11 , the database synchronization provided by the embodiment of the present application is performed by a first electronic device and a second electronic device, wherein the first electronic device includes a first application, a first database access framework, a first database engine and a first synchronization service, and the second electronic device includes a second synchronization service, a second database engine and a second database access framework. It should be understood that the second electronic device also includes a second application ( Fig.11 (not shown in the figure). For example, Fig.11 The first electronic device shown may be Figure 3 The first electronic device 110 is shown. Fig.11 The second electronic device shown may be Figure 3 The second electronic device 120 is shown. Fig.11 As shown, the data synchronization method includes S1100 to S1118. S1100 to S1118 are described in detail below.
[0267] S1100: A first application of a first electronic device generates a synchronization request for the first application.
[0268] The above step S1100 is a specific example of the above step S710. For the contents not described in detail here, please refer to the relevant description in the above step S710.
[0269] S1101: A first application of a first electronic device sends a synchronization request to a first database access framework of the first electronic device. Correspondingly, the first database access framework receives the synchronization request sent by the first application.
[0270] In the embodiment of the present application, after the first database access framework of the first electronic device receives the synchronization request from the first application, it triggers the first database access framework to execute S1102 to S1104.
[0271] Next, S1102 to S1104 are described in detail.
[0272] S1102: A first database access framework in the first electronic device instructs a first database engine in the first electronic device to create a first database in a slave database mode.
[0273] The first database created in the above step S1102 may be an empty database, that is, no data is stored in the first database. Specifically, the first database may be a SQLite database.
[0274] S1103: A first database engine in the first electronic device creates a first database.
[0275] S1104: The first database access framework in the first electronic device sends a synchronization request to the first synchronization service in the first electronic device. Correspondingly, the first synchronization service receives the synchronization request sent by the first database access framework.
[0276] In the embodiment of the present application, the purpose of the first electronic device executing S1001 to S1104 is that the first application in the first electronic device sends a synchronization request so that the first synchronization service obtains the synchronization request sent by the first application. At the same time, a first database is created in the first electronic device, and the first database is used to store the data requested by the synchronization request.
[0277] S1105: The first synchronization service in the first electronic device sends a synchronization request to the second electronic device. Correspondingly, the second synchronization service receives the synchronization request from the first electronic device.
[0278] The above step S1105 is the above Figure 7 A specific example of step S720 is provided. For contents not described in detail here, please refer to the relevant description in S720.
[0279] The triggering condition for the first synchronization service in the first electronic device to execute S1105 is not specifically limited. For example, after the first synchronization service obtains the synchronization request, it immediately sends the synchronization request to the second electronic device. For another example, after the first synchronization service obtains the synchronization request, after a period of time, the first synchronization service sends the synchronization request to the second electronic device.
[0280] In the embodiment of the present application, after the first synchronization service executes S1105, the second synchronization service receives a synchronization request from the first electronic device, and thereafter, the second synchronization service may execute steps S1106 and S1107.
[0281] S1106 , the second synchronization service in the second electronic device creates an empty database file 1 .
[0282] The empty database file 1 is an empty file, that is, no data is stored in the empty database file 1. It is understandable that after the first electronic device creates the empty database file 1, a read operation can be performed on the empty database file 1.
[0283] S1107 , the second synchronization service in the second electronic device generates indication information according to the synchronization request, where the indication information is used to instruct to write the target data in the second database into the empty database file 1 corresponding to the file handle 1 .
[0284] It should be understood that the instruction information in the above step S1107 is the above Figure 7 A specific example of the instructions in the provided method.
[0285] File handle 1 is the file handle of the empty database file, that is, file handle 1 is used to identify the empty database file 1. The file handle of the empty database file 1 can be, but is not limited to, an integer or a pointer.
[0286] S1108: The second synchronization service in the second electronic device sends indication information to the second database access framework in the second electronic device. Correspondingly, the second database access framework receives the indication information from the second synchronization service.
[0287] S1109: The second database access framework in the second electronic device sends indication information to the second database engine in the second electronic device. Correspondingly, the second database engine receives the indication information from the second database access framework.
[0288] In the embodiments of the present application, Fig.11 In the method shown, the second synchronization service and the second database engine cannot directly exchange data. The purpose of executing the above S1108 and S1109 is to implement data interaction between the second synchronization service and the second database engine through the second database access framework.
[0289] S1110, the second database engine writes the target data in the second database into the empty database file 1 corresponding to the file handle 1 according to the instruction information, so that the second synchronization service obtains the database file 1 including the target data.
[0290] Execute S1110, that is, the second database engine in the second electronic device writes the application data generated by the second application to the empty database file 1 corresponding to the file handle 1, so that the second synchronization service obtains the database file 1, including: the second database engine determines the storage address of the empty database file 1 according to the file handle 1; the second database engine writes the application data generated by the second application obtained from the second database to the storage address of the empty database file 1, so that the empty database file 1 is updated to the database file 1, so that the second synchronization service obtains the database file 1.
[0291] S1111, the second synchronization service in the second electronic device sends the database file 1 to the first electronic device. Accordingly, the first synchronization service in the first electronic device receives the database file 1 sent by the second synchronization service in the second electronic device.
[0292] The above step S1111 is a specific example of the above step S740, wherein the database file 1 in the above step S1111 is a specific example of the target data in the above step S740. For the contents not described in detail here, please refer to the relevant description in the above step S740.
[0293] S1112: The second synchronization service in the first electronic device sends the file handle 2 of the database file 1 to the first database access framework in the first electronic device.
[0294] The file handle 2 is the file handle of the database file 1, and the file handle 2 is used to identify the database file 2. The database file 2 stored in the first electronic device can be obtained through the file handle 2.
[0295] It should be noted that the second synchronization service and the first database access framework are located in different processes, so the second synchronization service and the first database access framework need to implement the transmission of corresponding database files in the form of file handles.
[0296] S1113, the first database access framework in the first electronic device sends a file handle 2 to the first database engine in the first electronic device.
[0297] Execute S1112 and S1113, that is, send the file handle 2 of the database file 1 sent by the first synchronization service to the first database engine. Since the first database engine and the first synchronization service cannot interact directly, the first database engine and the first synchronization service need to implement data interaction through the first database access framework.
[0298] S1114, the first database engine in the first electronic device writes the target data included in the database file 1 into the first database according to the file handle 2, and obtains the updated first database, so as to achieve the purpose of consistency between the data in the updated first database and the data in the second database.
[0299] Execute S1114, that is, the first database engine in the first electronic device writes the target data included in the database file 1 into the first database according to the file handle 2, and obtains the updated first database, including: the first database engine determines the storage address of the database file 1 stored in the first electronic device according to the file handle 2; the first database engine writes the target data stored in the storage address of the database file 1 into the first database, and obtains the updated first database.
[0300] S1115, the first database engine in the first electronic device performs an integrity check on the updated first database to obtain an integrity check result, and updates the first synchronization sequence number to obtain an updated first synchronization sequence number.
[0301] The purpose of executing S1115 is that the first database engine in the first electronic device performs integrity check on the data in the updated first database to verify the integrity of the data stored in the updated first database.
[0302] In the embodiment of the present application, the method for performing integrity verification on the updated data in the first database is not specifically limited and can be set according to actual needs.
[0303] For example, the integrity check of the data in the updated first database can be implemented by using a length check method. In this check method, it can be checked whether the length of the field (i.e., the attribute of the table) in the updated first database meets the requirements, and if it does not meet the requirements, an error message is returned.
[0304] For example, a value range check method can be used to implement integrity check of the data in the updated first database. In this check method, it can be checked whether the value of the field (i.e., the attribute of the table) in the updated first database is within a specified range, and an error message is returned if it is not within the specified range.
[0305] The updated first synchronization sequence number is used to indicate the third position in the second database, and the third position is used to determine the to-be-synchronized data in the second database that needs to be synchronized to the updated first database during the next data synchronization after executing S1100 to S1114.
[0306] S1116: The first database engine in the first electronic device sends the integrity check result to the first database access framework in the first electronic device. Correspondingly, the first database access framework receives the integrity check result sent by the first database engine.
[0307] After executing step S1116, if the integrity check result indicates that the check is successful, after executing S1116, execute S1117; if the integrity check result indicates that the check fails, after executing S1116, execute S1118.
[0308] Next, S1117 and S1118 are introduced in detail.
[0309] S1117: The first database access framework in the first electronic device sends a synchronization completion notification to the first application in the first electronic device.
[0310] After the first database access framework executes step S1117, the first application may know that the updated first database has successfully synchronized the target data in the second database requested by the synchronization request.
[0311] S1118: The first database access framework in the first electronic device sends a synchronization request to the first synchronization service in the first electronic device.
[0312] After executing S1118, if the integrity check result indicates that the check failed, S1118 is executed. That is, in this implementation, after executing S1101 to S1114, the updated first database in the first electronic device fails to successfully synchronize the data in the second database requested by the synchronization request. Thereafter, the first electronic device needs to re-initiate the synchronization request.
[0313] It should be noted that in the data synchronization method provided in the present application, when a write operation (such as but not limited to operations such as inserting, rewriting, and deleting) is performed on the database, an update operation corresponding to the write operation will be performed on the database and the database log file. In the case of a read operation on the database, the database and the database log file will not be updated. The execution of the above S1101 to S1118 only involves the process of performing a read operation on the data in the second database in the second electronic device. The read operation on the second database does not require modification of the log file of the second database and the data stored in the second database. In other words, the above implementation process does not involve the update operation of the second database in the second electronic device and the log file of the second database.
[0314] It should be understood that Fig.11 The data synchronization method shown is for illustration only and does not constitute any limitation to the data synchronization method provided in this application.
[0315] In the above, first combine Figure 7 A data synchronization method provided by an embodiment of the present application is introduced. Figure 7 The data synchronization method shown is combined with Fig.10 and Fig.11 They also introduced Figure 7 Two specific embodiments of the data synchronization method are shown. Figure 7 The data synchronization method shown in the figure, in some application scenarios, at the initial moment before the first electronic device executes S710 to S750, the database in the first electronic device includes a sixth database, the sixth database is associated with the first application, and the database in the second electronic device includes a third database, the third database is associated with the second application. Among them, the sixth database is a slave database, and the third database is a master database. Based on this, before the first electronic device executes S710 to S750, the first electronic device and the second electronic device can also be based on Figure 7 The data synchronization principle of the data synchronization method shown is to implement the first electronic device sending a synchronization request 1 to the second electronic device, and the synchronization request 1 is used to request to back up the target data 1 in the third database in the second electronic device to the sixth database in the first electronic device, so as to obtain the first database in the above-mentioned step S710. The data in the first database is the same as the data in the third database, and the first database is a backup database of the third database. For ease of description, hereinafter, the data synchronization process performed before executing S710 to S750 will be referred to as the first data synchronization process. Figure 7 The data synchronization process performed from S710 to S750 shown is called the second data synchronization process.
[0316] In the case where the data in the first database and the data in the third database in the first electronic device are the same (i.e. before the first electronic device executes the above step S710), there is a case where the first electronic device needs to perform a modification operation on the first database according to its own needs. Since the first database is a slave database of the third database (i.e. the data in the first database needs to be consistent with the data in the third database), the first electronic device cannot directly perform a modification operation on the first database according to its own needs.
[0317] In order to solve the above problem, before the first electronic device executes the above step S710, that is, before the first electronic device generates a synchronization request for the first application, the first electronic device may also perform the following steps: send a modification request to the second electronic device, the modification request is used to request the second electronic device to perform a modification operation on a third database within the second electronic device to obtain a second database, the third database is associated with the second application, the data in the third database is the same as the data in the first database, wherein the target data is data associated with the modification operation.
[0318] In the above implementation, the data in the third database being the same as the data in the first database means that the data in the first database is obtained by backing up the data in the third database, and the first database is a slave database of the third database.
[0319] In the above implementation, exemplarily, the modification request includes the identifier of the second electronic device, the identifier of the second application, the identifier of the third database, and the modification operation. The identifier of the second electronic device is used to represent the second electronic device, the identifier of the second application is used to represent the second application, the identifier of the third database is used to represent the third database, and the modification operation is used to represent the modification method for modifying the third database.
[0320] Exemplarily, below, the modification operation performed on the third database is described by taking the data type stored in the third database in the above implementation as a two-dimensional data table as an example.
[0321] Table 1
[0322] ID Name 001 Li Er 002 Zhang San
[0323] Table 2
[0324] ID Name 001 Li Er 002 Zhang San 003 Wang Er
[0325] Table 3
[0326] ID Name 001 Li Er
[0327] Table 4
[0328] ID Name 001 Li Er 002 Liu Er
[0329] For example, the third database in the above implementation can store the above Table 1, and performing a modification operation on the third database can be inserting a new data into Table 1 included in the third database to obtain the content shown in the above Table 2, that is, the second database obtained after performing the modification operation on the third database stores the above Table 2. In this implementation, performing a modification operation on the third database specifically refers to performing an insert operation on the third database (that is, inserting new data into the third database).
[0330] For another example, the third database in the above implementation can store the above Table 1, and performing a modification operation on the third database can be to delete the row of data with ID 002 in Table 1 included in the third database, and obtain the content shown in the above Table 3, that is, the second database obtained after performing a modification operation on the third database stores the above Table 3. In this implementation, performing a modification operation on the third database specifically refers to performing a deletion operation on the data in the third database.
[0331] For another example, the third database in the above implementation can store the above Table 1, and performing a modification operation on the third database can be to rewrite the row of data with ID 002 in Table 1 included in the third database to obtain the content shown in the above Table 4, that is, the second database obtained after performing the modification operation on the third database stores the above Table 4. In this implementation, performing a modification operation on the third database specifically refers to performing a rewrite operation on the data in the third database.
[0332] In the above implementation, the target data is data associated with the modification operation. That is, the target data is related to the modification mode of the modification operation. Below, the target data is described by combining the modification operation performed on the third database.
[0333] In some implementations, the modification operation is an operation to modify at least part of the data in the third database, and the target data is data obtained after performing the modification operation on at least part of the data. For example, a row of a two-dimensional data table included in the third database has the following content: "ID: 002, name: Zhang San, gender: male, age: 20", and the age value of the row with ID 002 recorded in the third database is modified, and the target data obtained is "ID: 002, name: Zhang San, gender: male, age: 21".
[0334] In other implementations, the modification operation is to delete at least part of the data in the third database, and the target data may be all the data in the updated first database, or the target data may be data associated with at least part of the deleted data. For example, the third database stores a data table including multiple rows, and the modification operation is to delete a row in the data table. In this method, the target data may be all the data included in the updated first database. For example, the third database stores multiple image data, and the modification operation is to perform a deletion operation on part of the content of one image data among the multiple image data. In this method, the target data may be the result obtained after performing the deletion operation on part of the content of the one image data.
[0335] In some other implementations, the modification operation is to add a piece of data to the third database, and the added piece of data is the target data. For example, the third database stores an image, and the modification operation is to add a piece of image data to the third database. In this method, the target data is the added piece of image data.
[0336] In the embodiment of the present application, after the first electronic device executes the step of sending a modification request to the second electronic device, the second electronic device will perform a modification operation on the third database according to the modification request to obtain the second database. Thereafter, the second electronic device may also execute the step of sending a notification message to the first electronic device, wherein the notification message is used to indicate that the second electronic device has successfully performed a modification operation on the third database according to the modification request.
[0337] Exemplarily, Table 5 below shows the update status of the database in the first electronic device and the database in the second electronic device after the first electronic device and the second electronic device perform the first data synchronization process, the data modification process and the second data synchronization process.
[0338] Table 5
[0339] Database in the first electronic device The database in the second electronic device Initial moment The sixth database The third database After performing the first data synchronization First Database The third database After performing data modification operations First Database Second database After performing the second data synchronization Updated first database Second database
[0340] The following describes in detail the interaction steps between the first electronic device and the second electronic device when the first electronic device and the second electronic device perform the above-mentioned first data synchronization process, data modification process and second data synchronization process in conjunction with the accompanying drawings.
[0341] Fig.12 is a schematic diagram of another data synchronization method provided in an embodiment of the present application. Fig.12 As shown, the data synchronization method includes S1210 to S1234. S1210 to S1234 are described in detail below.
[0342] S1210, the first electronic device generates a synchronization request 1 for the first application, and the synchronization request 1 is used to request to back up the target data 1 in the third database in the second electronic device to the sixth database in the first electronic device, the third database is associated with the second application of the second electronic device, and the sixth database is associated with the first application.
[0343] For example, the sixth database and the third database in the above step S1210 can be respectively referred to Fig.13 The sixth database in the first electronic device shown in (1), and the third database in the second electronic device.
[0344] S1211, the first electronic device sends a synchronization request 1 to the second electronic device. Correspondingly, the second electronic device receives the synchronization request 1 from the first electronic device.
[0345] S1212: The second electronic device obtains target data 1 from the third database according to the synchronization request 1.
[0346] S1213: The second electronic device sends target data 1 to the first electronic device.
[0347] S1214, the first electronic device updates the sixth database using the target data 1 to obtain a first database, wherein the data in the first database is the same as the data in the third database.
[0348] Continue with Fig.13 For example, the first database in the above step S1214 can refer to Fig.13 The first database within the first electronic device shown in (2).
[0349] It should be understood that the above S1210 to S1214 are interactive steps of the first electronic device and the second electronic device performing the first data synchronization process. The principle of data synchronization between the first electronic device and the second electronic device performing S1210 to S1214 is the same as the above Figure 7 The principle of data synchronization performed by the first electronic device and the second electronic device in S710 to S750 is similar, and the contents not described in detail here can be understood based on the contents described in the above steps S710 to S750.
[0350] It should be understood that after the first electronic device and the second electronic device execute S1210 to S1214, the sixth database in the first electronic device is updated to the first database, that is, after executing S1210 to S1214, the database in the first electronic device is the first database, and the database in the second electronic device is the third database.
[0351] S1220: The first electronic device generates a modification request for the first application.
[0352] The modification request is used to request the second electronic device to perform a modification operation on a third database in the second electronic device to obtain a second database, the third database is associated with the second application, the data in the third database is the same as the data in the first database, and the target data is the data associated with the modification operation. For a description of the modification request, please refer to the relevant description above, which will not be repeated here.
[0353] For example, the first electronic device may generate the modification request in the following manner: in response to a modification instruction input by a user, the first application generates the modification request. In another example, the first electronic device generates the modification request according to its own needs.
[0354] S1221: The first electronic device sends a modification request to the second electronic device. Correspondingly, the second electronic device receives the modification request from the first electronic device.
[0355] S1222: The second electronic device performs a modification operation on the third database according to the modification request to obtain a second database.
[0356] Continue with Fig.13For example, the second database in the above step S1222 can refer to Fig.13 The second database within the second electronic device shown in (3).
[0357] It should be understood that the above S1220 to S1222 are interactive steps of the first electronic device and the second electronic device performing a data modification process.
[0358] It should be understood that after the first electronic device and the second electronic device execute S1220 to S1222, the third database in the second electronic device is updated to the second database. That is, after executing S1220 to S1222, the database in the first electronic device is the first database, and the database in the second electronic device is the second database.
[0359] Optionally, in some other implementations, the second electronic device may also execute Fig.12 S1223 is shown by the dotted line.
[0360] S1223: The second electronic device sends a notification message to the first electronic device. Correspondingly, the first electronic device receives the notification message from the second electronic device.
[0361] The notification message is used to indicate that the second electronic device has successfully performed a modification operation on the third database according to the modification request.
[0362] S1230, the first electronic device generates a synchronization request 1 for the first application, the synchronization request 1 is used to request to back up the target data 1 in the third database in the second electronic device to the sixth database in the first electronic device, the third database is associated with the second application of the second electronic device, and the sixth database is associated with the first application.
[0363] Among them, step S1230 and the above Figure 7 The S710 step shown is the same, and the contents not described in detail here can refer to the relevant description in the above S710 step.
[0364] S1231: The first electronic device sends a synchronization request to the second electronic device. Correspondingly, the second electronic device receives the synchronization request from the first electronic device.
[0365] Among them, step S1231 and the above Figure 7 The S720 step shown is the same, and the contents not described in detail here can refer to the relevant description in the above S720 step.
[0366] S1232: The second electronic device obtains target data from the third database according to the synchronization request.
[0367] Among them, step S1232 and the above Figure 7The S730 step shown is the same, and the contents not described in detail here can refer to the relevant description in the above S730 step.
[0368] S1233: The second electronic device sends the target data to the first electronic device. Correspondingly, the first electronic device receives the target data from the second electronic device.
[0369] Among them, step S1233 and the above Figure 7 The S740 step shown is the same, and the contents not described in detail here can refer to the relevant description in the above S740 step.
[0370] S1234, the first electronic device updates the first database using the target data to obtain an updated first database, wherein the data in the updated first database is the same as the data in the third database.
[0371] Continue with Fig.13 For example, the updated first database in the above step S1234 can refer to Fig.13 (3) shows the updated first database in the first electronic device.
[0372] Among them, step S1234 and the above Figure 7 The S750 step shown is the same, and the contents not described in detail here can refer to the relevant description in the above S750 step.
[0373] It should be understood that the above S1230 to S1234 are interactive steps for the first electronic device and the second electronic device to perform the second data synchronization process.
[0374] It should be understood that after the first electronic device and the second electronic device execute S1230 to S1234, the first database in the first electronic device is updated to the updated first database. That is, after executing S1230 to S1234, the database in the first electronic device is the updated first database, and the database in the second electronic device is the second database.
[0375] In an embodiment of the present application, in a scenario where the data in the first database in the first electronic device and the data in the third data in the second electronic device are the same, the first electronic device sends a modification request generated by itself to the second electronic device, so that the second electronic device can perform a modification operation on the third database as the master database of the first database according to the modification request to obtain the second database. Thereafter, the first electronic device synchronizes the target data associated with the modification request in the second database in the second electronic device to the first database in the first electronic device by sending a synchronization request to the second electronic device, and obtains the updated first database. That is to say, in the above technical solution, on the basis of the master-slave synchronization mode, the first electronic device as a slave device can perform a modification operation on the first database in the first electronic device according to its own modification requirements, wherein the first database in the first electronic device is a slave database of the third database in the second electronic device as the master device. In the above-mentioned interaction process between the first electronic device and the second electronic device, there is no need for the participation of the cloud server, and there is no need to convert the format of the data to be synchronized (i.e., the target data) in the second database, so that the user's privacy data security can be protected, and at the same time, the data synchronization efficiency can be improved.
[0376] Fig.14 It is a schematic diagram of another data synchronization method provided in an embodiment of the present application. It should be understood that Fig.14 The data synchronization method shown above is Fig.12 A specific embodiment of the data synchronization method is shown. Fig.14 The data synchronization method provided in the embodiment of the present application is performed by a first electronic device and a second electronic device, wherein the first electronic device includes a first application, a first database engine and a first synchronization service, and the second electronic device includes a second synchronization service and a second database engine. It should be understood that the second electronic device also includes a second application ( Fig.14 (not shown in the figure). For example, Fig.14 The first electronic device shown may be Figure 3 The first electronic device 110 is shown. Fig.14 The second electronic device shown may be Figure 3 The second electronic device 120 is shown. It should be understood that Fig.14 The first synchronization service shown is Figure 3 The first database synchronization service 112 is shown. Fig.14 The second synchronization service shown is Figure 3 A second database synchronization service 122 is shown.
[0377] like Fig.14 As shown, the data synchronization method includes S1400 to S1413. S1410 to S1413 are described in detail below.
[0378] S1400: A first application of a first electronic device generates a modification request.
[0379] The above step S1400 is a specific example of the above step S1220. For the contents not described in detail here, please refer to the description in the above step S1220.
[0380] S1401: A first application of a first electronic device sends a modification request to a first synchronization service of the first electronic device.
[0381] There is no specific limitation on the manner in which the first application sends the modification request to the first synchronization service.
[0382] In some implementations, the first synchronization service and the first application need to implement data interaction through a first database framework included in the first electronic device. Based on this, exemplarily, executing S1401 may include the following steps: the first application sends a first synchronization request to the first synchronization service through the first database access framework.
[0383] In some other implementations, the first synchronization service and the first application may directly interact with each other over data. In this implementation, the first application directly sends a modification request to the first synchronization service.
[0384] S1402: The first synchronization service of the first electronic device sends a modification request to the second electronic device. Correspondingly, the second synchronization service of the second electronic device receives the modification request from the first electronic device.
[0385] The above step S1402 is a specific example of the above step S1221. For the contents not described in detail in step S1402, please refer to the relevant description of step S1221 above.
[0386] S1403: The second synchronization service of the second electronic device sends a modification request to the second database engine of the second electronic device.
[0387] There is no specific limitation on the manner in which the second synchronization service sends the modification request to the second database engine.
[0388] In some implementations, the second database engine and the second synchronization service need to implement data interaction through a second database framework included in the second electronic device. Based on this, exemplary, executing S1403 may include the following steps: the second synchronization service sends a modification request to the second database engine through the second database access framework.
[0389] In some other implementations, the second database engine and the second synchronization service may directly interact with each other regarding data. In this implementation, the second synchronization service directly sends a modification request to the second database engine.
[0390] S1404: The second database engine of the second electronic device performs a modification operation on the third database according to the modification request to obtain a second database.
[0391] The above step S1404 is a specific example of the above step S1220. For the contents not described in detail in step S1404, please refer to the relevant description of step S1220 above.
[0392] S1405: A first application of the first electronic device generates a synchronization request.
[0393] S1406: The first application of the first electronic device sends a synchronization request to the first synchronization service of the first electronic device.
[0394] There is no specific limitation on the manner in which the first application sends the synchronization request to the first synchronization service.
[0395] In some implementations, the first synchronization service and the first application need to implement data interaction through a first database framework included in the first electronic device. Based on this, exemplary, executing S1406 may include the following steps: the first application sends a first synchronization request to the first synchronization service through the first database access framework.
[0396] In some other implementations, the first synchronization service and the first application may directly interact with each other over data. In this implementation, the first application directly sends a synchronization request to the first synchronization service.
[0397] S1407: The first synchronization service of the first electronic device sends a synchronization request to the second electronic device. Correspondingly, the second synchronization service of the second electronic device receives the synchronization request from the first electronic device.
[0398] S1408: The second synchronization service of the second electronic device sends indication information to the second database engine of the second electronic device.
[0399] Execute S1408, that is, the second synchronization service sends indication information to the second database engine according to the synchronization request.
[0400] There is no specific limitation on the manner in which the second synchronization service of the second electronic device sends the indication information to the second database engine according to the synchronization request.
[0401] In some implementations, the second electronic device in the above S1408 also includes a second database access framework. Based on this, in the step of executing S1408, it exemplarily includes: the second synchronization service generates indication information according to the synchronization request; the second synchronization service sends the indication information to the second database engine through the second database access framework.
[0402] In some other implementations, the step of executing S1408 exemplarily includes: the second synchronization service generates indication information according to the synchronization request; and the second synchronization service sends the indication information to the second database engine.
[0403] S1409: The second database engine of the second electronic device obtains the target data from the second database according to the instruction information.
[0404] S1410: A second database engine of the second electronic device sends target data to a second synchronization service of the second electronic device.
[0405] There is no specific limitation on the manner in which the second database engine sends the target data to the second synchronization service.
[0406] In some implementations, the second synchronization service and the second database engine need to implement data interaction through a second database framework included in the second electronic device. Based on this, exemplary, executing S1410 may include the following steps: the second database engine sends target data to the second synchronization service through the second database access framework.
[0407] In some other implementations, the second synchronization service and the second database engine, in this implementation, the second database engine directly sends the target data to the second synchronization service.
[0408] S1411, the second synchronization service of the second electronic device sends target data to the first electronic device. Correspondingly, the first synchronization service of the first electronic device receives the target data from the second electronic device.
[0409] S1412: The first synchronization service of the first electronic device sends target data to the first database engine of the first electronic device.
[0410] There is no specific limitation on the manner in which the first synchronization service sends the target data to the first database engine.
[0411] In some implementations, the first synchronization service and the first database engine need to implement data interaction through a first database framework included in the first electronic device. Based on this, exemplary, executing S1412 may include the following steps: the second database engine sends target data to the first synchronization service through the first database access framework.
[0412] In some other implementations, the first synchronization service and the first database engine, in this implementation, the first database engine directly sends the target data to the first synchronization service.
[0413] S1413, the first database engine of the first electronic device writes the target data into the first database to obtain an updated first database, and the data in the second database is the same as the data in the updated first database.
[0414] It is understood that the contents not described in detail in the above steps S1405 to S1413 can be referred to in the above Fig.10 S1001 to S1009 are shown.
[0415] It should be understood that the above Fig.14 The data synchronization method provided in the embodiment of the present application is only for illustration and does not constitute any limitation to the embodiment of the present application.
[0416] Fig.15 It is a schematic diagram of another data synchronization method provided in an embodiment of the present application. It should be understood that Fig.15 The data synchronization method shown above is Fig.12 A specific embodiment of the data synchronization method is shown. Fig.15 The data synchronization method provided in the embodiment of the present application is performed by a first electronic device and a second electronic device, wherein the first electronic device includes a first application, a first database engine and a first synchronization service, and the second electronic device includes a second synchronization service and a second database engine. It should be understood that the second electronic device also includes a second application ( Fig.15 (not shown in the figure). For example, Fig.15 The first electronic device shown may be Figure 3 The first electronic device 110 is shown. Fig.15 The second electronic device shown may be Figure 3 The second electronic device 120 is shown. It should be understood that Fig.15 The first synchronization service shown is Figure 3 The first database synchronization service 112 is shown. Fig.15 The second synchronization service shown is Figure 3 A second database synchronization service 122 is shown.
[0417] like Fig.15 As shown, the data synchronization method includes S1500 to S1516. S1501 to S1516 are described in detail below.
[0418] S1500: A first application of a first electronic device generates a modification request.
[0419] The modification request in the above step S1500 is the same as the modification request in the above step S1220. For the contents not described in detail here, please refer to the relevant description in the above step S1220.
[0420] S1501: A first application in a first electronic device sends a modification request to a first database access framework in the first electronic device. Correspondingly, the first database access framework receives the modification request sent by the first application.
[0421] S1502: The first database access framework in the first electronic device sends a modification request to the first database engine in the first electronic device. Correspondingly, the first database engine receives the modification request sent by the first database access framework.
[0422] Execute the above S1501 and S1502, that is, Fig.15 The first database engine and the first application shown cannot directly exchange data, and the first database engine and the first application need to implement data exchange through a first database access framework.
[0423] S1503, the first database engine in the first electronic device determines that the third database in the second electronic device to be modified by the modification request is the master database of the sixth database in the first electronic device, and generates a modification operation file, the modification operation file including the modification request.
[0424] S1504: The first database engine in the first electronic device sends a modification operation file to the first database access framework in the first electronic device. Correspondingly, the first database access framework receives the modification operation file sent by the first database engine.
[0425] S1505: The first database access framework in the first electronic device sends a file handle 3 for modifying the operation file to the first synchronization service in the first electronic device. Correspondingly, the first synchronization service receives the file handle 3 sent by the first database engine.
[0426] The file handle 3 of the modification operation file is used to indicate the file path of the modification operation file located in the first electronic device. In other words, the access to the modification operation file can be achieved through the file handle 3.
[0427] It should be understood that in the embodiment of the present application, the first application, the first database access framework and the first database engine are in the same process. The process in which the first synchronization service is located is different from the process in which the first application, the first database access framework and the first database engine are located. Since the first database access framework and the first synchronization service are in different processes, it is necessary to achieve the purpose of transmitting the modification operation file corresponding to the file handle 3 in the form of transmitting the file handle 3.
[0428] In an embodiment of the present application, the first electronic device executes S1504 and S1505, that is, the first database engine and the first synchronization service cannot directly exchange data, and need to use the first database access framework as a data transfer device to indirectly achieve the purpose of exchanging data between the first database engine and the first synchronization service.
[0429] S1506: The first synchronization service in the first electronic device stores the file handle 3 in the sandbox file 1. The sandbox file 1 is a file that the first synchronization service can access.
[0430] Sandbox file 1 is a file that can be accessed by the first synchronization service. That is to say, no module in the first electronic device other than the first synchronization service can access the data in sandbox file 1. In this way, the security of the data stored in sandbox file 1 can be guaranteed. Sandbox file 1 can also be considered as a storage space in the first electronic device, and this storage space is only accessible by the first synchronization service.
[0431] In the embodiment of the present application, the first electronic device performs the purpose of S1500 to S1506, that is, the first application in the first electronic device sends the modification request generated by the first application, so that the first synchronization service obtains the modification operation file including the modification request.
[0432] S1507, the first synchronization service in the first electronic device sends a modification operation message 1 corresponding to the modification request to the second electronic device, and the modification operation message 1 includes a modification operation file. Correspondingly, the second synchronization service of the second electronic device receives the modification operation message 1 sent by the first synchronization service.
[0433] It should be understood that the modification operation message 1 in the above step S1507 is a specific example of the encapsulation result obtained after the modification request in the above step S1221 is encapsulated using the transmission protocol.
[0434] It should be understood that the above step S1507 is a specific example of the above step S1221.
[0435] S1508, the second synchronization service in the second electronic device sends the file handle 4 of the modification operation file to the second database access framework in the second electronic device. Correspondingly, the second database access framework receives the file handle 4 of the modification operation file sent by the second synchronization service.
[0436] In the embodiment of the present application, the second application, the second database access framework and the second database engine are in the same process. The process in which the second synchronization service is located is different from the process in which the second application, the second database access framework and the second database engine are located. Since the second database access framework and the second synchronization service are in different processes, it is necessary to achieve the purpose of transmitting the modification operation file corresponding to the file handle 4 in the form of transmitting the file handle 4.
[0437] S1509: The second database access framework in the second electronic device sends a file handle 4 to the second database engine in the second electronic device. Correspondingly, the second database engine receives the file handle 4 sent by the second database access framework.
[0438] In an embodiment of the present application, the second electronic device executes S1508 and S1509, that is, the second database engine and the second synchronization service cannot directly exchange data, and need to use the second database access framework as a data transfer device to indirectly achieve the purpose of the second database engine and the second synchronization service exchanging data.
[0439] S1510, the second database engine in the second electronic device updates the third database according to the file handle 4 to obtain the second database; and stores the SQL statement of the modification operation message 1 corresponding to the file handle 4 into the log file of the third database to obtain the updated log file.
[0440] The step of executing S1510 by the second database engine involves the step of updating the main database (i.e., the third database). Therefore, the second database engine also needs to update the log file of the main database (i.e., the third database) so that the SQL statement for executing the update on the main database (i.e., the third database) is recorded in the log file of the updated main database.
[0441] S1511: The second database engine in the second electronic device sends a notification message to the second database access framework in the second electronic device. Correspondingly, the second database access framework receives the notification message sent by the second database engine.
[0442] The notification message in the above step S1511 indicates that the second electronic device has successfully performed a modification operation on the third database according to the modification request.
[0443] S1512: The second database access framework in the second electronic device sends a notification message to the second synchronization service in the second electronic device. Correspondingly, the second synchronization service receives the notification message sent by the second database access framework.
[0444] In an embodiment of the present application, the second electronic device executes S1511 and S1512, that is, the second database engine and the second synchronization service cannot directly exchange data, and need to use the second database access framework as a data transfer device to indirectly achieve the purpose of the second database engine and the second synchronization service exchanging data.
[0445] In the embodiment of the present application, the purpose of the second electronic device executing S1508 to S1512 is that the second electronic device performs a modification operation on the third database according to the modification operation message 1 to obtain the second database, and sends a notification message to the second synchronization service.
[0446] S1513, the second synchronization service in the second electronic device sends a notification message to the first electronic device. Correspondingly, the first synchronization service of the first electronic device receives the notification message sent by the second synchronization service.
[0447] S1514: The first synchronization service in the first electronic device sends a notification message to the first database access framework in the first electronic device. Correspondingly, the first database access framework receives the notification message sent by the first synchronization service.
[0448] S1515: The first database access framework in the first electronic device sends a notification message to the first application in the first electronic device. Correspondingly, the first application receives the notification message sent by the first database access framework.
[0449] S1516: The first electronic device and the second electronic device execute Fig.11 The data synchronization method shown is used to back up the target data in the second database in the second electronic device to the first database.
[0450] The first electronic device and the second electronic device perform step S1516, which can be seen in the above Fig.11 The relevant descriptions in the provided data synchronization method will not be repeated here in detail.
[0451] It should be understood that Fig.15 The data synchronization method shown is for illustration only and does not constitute any limitation to the data synchronization method provided in this application.
[0452] Based on the above Figure 7 In some implementations of the data synchronization method shown, in the first electronic device, the database associated with the first application also includes a fourth database, the fourth database is associated with the first application, and the fourth database is used to store application data generated by the first application. In this scenario, the above Figure 7 After S710 to S750 shown, there is a step in which the first application needs to perform data query on the fourth database and the updated first database.
[0453] That is, after executing S710 to S750, the above Figure 7 The first electronic device shown can also perform the following steps: when the database version of the fourth database in the first electronic device is different from the database version of the updated first database, the database version of the updated first database is updated to obtain a fifth database, the database version of the fifth database is the same as the database version of the fourth database, wherein the fourth database is associated with the first application, and the fourth database is used to store data generated by the first application; generate a query statement; and according to the query statement, perform query processing on the fourth database and the fifth database to obtain a query result.
[0454] In the above implementation, when the database version of the fourth database in the first electronic device is different from the database version of the updated first database, the database version of the updated first database can be updated so that the database version of the obtained fifth database is the same as the version of the fourth database. In this way, the first electronic device can use one query statement to query the data in the fifth database and the data in the fourth database, which can improve data query efficiency.
[0455] It should be understood that if the updated database version of the first database is the same as the database version of the fourth database, there is no need to perform the above operation of updating the updated database version of the first database. In other words, in this implementation, one query statement can be used directly to query the data in the updated first database and the data in the fourth database.
[0456] The following describes an example of a method in which the first electronic device updates the updated database version of the first database. It should be understood that the method for updating the updated database version of the first database described below is only for illustration and does not constitute any limitation to the embodiments of the present application.
[0457] In some implementations, the fourth database includes a first data table having M attributes and attribute values of the M attributes, and the updated first database includes a second data table having N attributes and attribute values of the N attributes, M and N are positive integers, and M and N are different; when the database version of the fourth database is different from the database version of the updated first database, the database version of the updated first database is updated, and the step of obtaining the fifth database exemplarily includes: updating the N attributes in the second data table to the M attributes in the first data table, obtaining the third data table, and obtaining the fifth database; wherein the fifth database includes a third data table, the third data table includes attribute values of (MN) attributes and attribute values of the N attributes recorded in the second data table, the (MN) attributes are attributes other than the N attributes in the M attributes, and the attribute value of any one of the (MN) attributes is empty.
[0458] In other implementations, when the updated database version of the first database is different from the database version of the fourth database, the first electronic device may not need to update the updated database version of the first database. In this implementation, the first electronic device may use two query statements to query the updated first database and the fourth database respectively to obtain the query results of the updated first database and the query results of the fourth database. The attribute fields corresponding to the two query statements are not exactly the same.
[0459] Next, combine Fig.16 A schematic diagram of a data query method provided by an embodiment of the present application is introduced. Fig.16 The method includes S1610 to S1660. S1610 to S1660 are described in detail below.
[0460] S1610, when the first application of the first electronic device determines that the database version of the fourth database is different from the data version of the updated first database, the first application sends version update information to the first database engine, and the version update information is used to instruct the first database engine to update the database version of the updated first database to obtain a fifth database, and the database version of the fifth database is the same as the database version of the fourth database.
[0461] In some implementations, the first electronic device further includes a first database access framework, based on which the step S1610 is executed, exemplarily including: the first application sends version update information to the first database engine through the first database access framework.
[0462] The fourth database and the updated first database in the above step S1610 are described below by way of example.
[0463] For example, the fourth database in the above step S1610 and the updated first database can be respectively referred to as Fig.17 The fourth database in the first electronic device and the updated first database are shown. Fig.17 , Table B in the fourth database includes 4 attributes and attribute values of 4 attributes, namely "ID", "name", "gender" and "age". The updated Table A of the first database shown by the dotted line includes 3 attributes, namely "ID", "name" and "gender". It can be seen that, Fig.17 The table structure of the table A in the fourth database shown is different from the table structure of the table B in the updated first database shown by the dotted line, that is, the database version of the fourth database is different from the database version of the updated first database.
[0464] S1620: The first database engine of the first electronic device updates the updated first database according to the version update information to obtain a fifth database.
[0465] Continue with Fig.17 For example, the fifth database obtained by executing S1620 can be found in Fig.17 A fifth database in the first electronic device is shown. Fig.17 The table in the fifth database includes all the contents of the table in the first database, and the table in the fifth database also includes newly added attributes, and the attribute value corresponding to the newly added attribute is empty.
[0466] S1630: A first application of the first electronic device generates a query statement.
[0467] In step S1630, the first electronic device can use a query statement to query the data stored in the fourth database and the data stored in the fifth database. Specifically, this query statement is used to query the attribute values of four attributes recorded in the tables in the fourth database and the fifth database, and the four attributes are "ID", "name", "gender" and "age".
[0468] Exemplarily, the query statement in the above step S1630 can be an SQL query statement, which is used to query the first row of data in the table in the fourth database, and to query the first row of data in the table in the fifth database, and the SQL query statement includes the following attribute fields: "ID", "Name", "Gender" and "Age".
[0469] S1640: The first application of the first electronic device sends a query statement to the first database engine of the first electronic device.
[0470] In some implementations, the first electronic device further includes a first database access framework, based on which, the step S1640 is executed, exemplarily including: the first electronic device sends a query statement to the first database engine through the first database access framework.
[0471] S1650: The first database engine of the first electronic device performs query processing on the fourth database and the fifth database according to the query statement to obtain a query result.
[0472] Exemplarily, if the query statement in the above step S1630 is used to query the first row of data in the table in the fourth database and the first row of data in the table in the fifth database, the query results in the above step S1650 include query result 1 and query result 2, wherein query result 1 is "ID: 001; Name: Zhang San; Gender: Male; Age: 20", and query result 2 is "ID: 001; Name: Zhang San; Gender: Male; Age: Empty".
[0473] S1660: The first database engine of the first electronic device sends the query result to the first application of the first electronic device.
[0474] In some implementations, the first electronic device further includes a first database access framework, based on which, the step S1660 is executed, exemplarily including: the first database engine sends a query statement to the first application through the first database access framework.
[0475] It should be understood that Fig.16 The data query method shown is for illustration only and does not constitute any limitation on the data query method applicable after the data synchronization provided in the embodiment of the present application is executed.
[0476] Above, combined Figures 7 to 17 The data synchronization method and data query method provided by the embodiment of the present application are introduced. Next, the graphical user interface (GUI) displayed by the electronic device when the data synchronization method provided by the embodiment of the present application is applied in the electronic device is introduced in conjunction with the accompanying drawings.
[0477] Fig.18 The desktop 1810 of the first electronic device 1800 is shown. When the first electronic device detects that the user clicks on the icon 1811 of the gallery application (application, APP) on the desktop 1810, the gallery application can be started and the following information can be displayed: Fig.18 The gallery interface 1820 is shown. The gallery interface 1820 may include a search box 1821, the device (ie, the first electronic device 1800), other electronic devices, and all photos included in the device.
[0478] In one example, if the user needs to access data in a gallery application of another electronic device, the user can click on another electronic device on the gallery interface 1820. When another electronic device in the gallery interface 1820 is selected, the following information can be displayed: Fig.18 The desktop 1830 is shown, and other electronic devices including the second electronic device are displayed in the desktop 1830. By clicking the second electronic device in the desktop 1830, the user can make the first electronic device 1800 and the second electronic device execute the data synchronization method provided in the embodiment of the present application to back up the data in the gallery application of the second electronic device to the gallery application of the first electronic device, so that the purpose of displaying the data in the gallery application of the second electronic device on the interface of the present device can be achieved.
[0479] In another example, if the gallery application of the present device (i.e., the first electronic device 1800) has successfully backed up the data in the gallery application of the second electronic device, if the user wants to find the photos of a certain day saved in the gallery applications of the present device and the second electronic device, the user can search for the photos of a certain day saved in the gallery applications of the present device and the second electronic device. Fig.18 The query information is input into the search box 1831 on the desktop 1830 shown. For example, the query information may be photos taken on June 1, 2023 in the present device and the second electronic device to obtain the following information: Fig.18 The desktop 1840 shown shows that the present device has found 5 photos and the second electronic device has found 3 photos. Further, by clicking the more button on the right side of "the present device has found 5 photos" on the desktop 1840, the 5 photos found in the present device can be browsed. Similarly, by clicking the more button on the right side of "the second electronic device has found 3 photos" on the desktop 1840, the 3 photos found in the second electronic device can be browsed.
[0480] Combination of the above Figures 1 to 18 , describes in detail the application scenarios applicable to the embodiments of the present application, the structure of the electronic device, the data synchronization method of the embodiments of the present application, and the user interface displayed when the electronic device executes the data synchronization method provided by the embodiments of the present application. Fig.19 and Fig. 20 , describes in detail the data synchronization device and electronic device embodiments of the present application. It should be understood that the data synchronization device and electronic device in the embodiments of the present application can execute the various data synchronization methods in the aforementioned embodiments of the present application, that is, the specific working processes of the following various products can refer to the corresponding processes in the aforementioned method embodiments.
[0481] Corresponding to the data synchronization method provided in the embodiment of the present application, the present application also provides a data synchronization device.
[0482] Fig.19 is a schematic diagram of a data synchronization device provided in an embodiment of the present application. Fig.19 , the device includes a processing unit 1910.
[0483] In some implementations, Fig.19 The data synchronization device shown is applied to a first electronic device including a first application, the first electronic device being the Figure 7 In the data synchronization method shown, the first electronic device, in this implementation, the processing unit 1910 is used to execute the steps of the method performed by the first electronic device in each method provided in the embodiments of the present application.
[0484] In other implementations, Fig.19 The data synchronization device shown is applied to a second electronic device, the second electronic device being the Figure 7 In the data synchronization method shown, the second electronic device, in this implementation, the processing unit 1910 is used to execute the steps of the method performed by the second electronic device in each method provided in the embodiments of the present application.
[0485] For example, a "unit" may be a software program, a hardware circuit, or a combination of the two that implements the above functions. The hardware circuit may include an application specific integrated circuit (ASIC), an electronic circuit, a processor (e.g., a shared processor, a dedicated processor, or a group processor, etc.) and a memory for executing one or more software or firmware programs, a combined logic circuit, and / or other suitable components that support the described functions.
[0486] Therefore, the units of each example described in the embodiments of the present application can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present application.
[0487] Corresponding to the data synchronization method provided in the embodiment of the present application, the present application also provides an electronic device.
[0488] Fig. 20 It is a schematic diagram of the structure of an electronic device provided by the present application. Fig. 20 The dotted line in the figure indicates that the unit or the module is optional. The electronic device 2000 can be used to execute the steps of the method performed by the first electronic device or the second electronic device in each method provided in the embodiments of the present application.
[0489] The electronic device 2000 includes one or more processors 2001, which can support the electronic device 2000 to implement the method steps performed by the first electronic device or the second electronic device in the above data synchronization method embodiment. The processor 2001 can be a general-purpose processor or a special-purpose processor. For example, the processor 2001 can be a central processing unit (CPU), a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, such as discrete gates, transistor logic devices or discrete hardware components.
[0490] The processor 2001 can be used to control the electronic device 2000, execute the software program, and process the data of the software program. The electronic device 2000 can also include a communication unit 2005 to implement the input (reception) and output (transmission) of signals.
[0491] For example, the electronic device 2000 may be a chip, the communication unit 2005 may be an input and / or output circuit of the chip, or the communication unit 2005 may be a communication interface of the chip, and the chip may be a component of a terminal device or other electronic devices.
[0492] For another example, the electronic device 2000 may be a terminal device, and the communication unit 2005 may be a transceiver of the terminal device, or the communication unit 2005 may be a transceiver circuit of the terminal device.
[0493] The electronic device 2000 may include one or more memories 2002, on which a program 2004 is stored. The program 2004 can be executed by the processor 2001 to generate instructions 2003, so that the processor 2001 executes the steps of the method performed by the first electronic device or the second electronic device in each method provided in the embodiments of the present application according to the instructions 2003.
[0494] Optionally, data may be stored in the memory 2002. Optionally, the processor 2001 may read data stored in the memory 2002. The data may be stored at the same storage address as the program 2004, or may be stored at a different storage address than the program 2004.
[0495] The processor 2001 and the memory 2002 may be provided separately or integrated together; for example, integrated on a system on chip (SOC) of a terminal device.
[0496] Exemplarily, the memory 2002 can be used to store the related program 2004 of the data synchronization method provided in the embodiments of the present application, and the processor 2001 can be used to call the related program 2004 of the data synchronization method stored in the memory 2002 to execute the steps of the method executed by the first electronic device or the second electronic device in each method provided in the embodiments of the present application.
[0497] The present application also provides a computer program product, which, when executed by the processor 2001, executes the steps of the method performed by the first electronic device or the second electronic device in each method provided in the embodiments of the present application.
[0498] The computer program product may be stored in the memory 2002 , for example, a program 2004 , which is converted into an executable target file that can be executed by the processor 2001 after preprocessing, compiling, assembling, linking and other processing processes.
[0499] The present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a computer, the steps of the method performed by the first electronic device or the second electronic device in each method provided in the embodiments of the present application are performed. The computer program can be a high-level language program or an executable target program.
[0500] The computer-readable storage medium is, for example, memory 2002. Memory 2002 may be a volatile memory or a nonvolatile memory, or memory 2002 may include both a volatile memory and a nonvolatile memory. Among them, the nonvolatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct rambus RAM (DR RAM).
[0501] The present application also provides a data synchronization system, which includes a first electronic device and a second electronic device, wherein the first electronic device is used to execute the steps of the method performed by the first electronic device in each method provided in the embodiments of the present application, and the second electronic device is used to execute the steps of the method performed by the second electronic device in each method provided in the embodiments of the present application.
[0502] In this application, "at least one" means one or more, and "more than one" means two or more. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b, or c can be represented by: a, b, c, ab, ac, bc, or abc, where a, b, c can be single or multiple.
[0503] It should be understood that in the various embodiments of the present application, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0504] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0505] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0506] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic; for example, the division of the units is only a logical function division, and there may be other division methods in actual implementation; for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0507] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0508] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0509] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A data synchronization method, characterized in that: Applied in a first electronic device including a first application, the method includes: generating a synchronization request for the first application, the synchronization request being used to request to back up target data in a second database in a second electronic device to a first database in the first electronic device, the second database being associated with a second application of the second electronic device, and the first database being associated with the first application; sending the synchronization request to the second electronic device; receiving the target data from the second electronic device; The first database is updated using the target data to obtain an updated first database, and the data in the second database is the same as the data in the updated first database.
2. The method according to claim 1, characterized in that Before generating the synchronization request of the first application, the method further includes: A modification request is sent to the second electronic device, wherein the modification request is used to request the second electronic device to perform a modification operation on a third database within the second electronic device to obtain the second database, wherein the third database is associated with the second application, and the data in the third database is the same as the data in the first database, wherein the target data is data associated with the modification operation.
3. The method according to claim 2, characterized in that Before sending the synchronization request to the second electronic device, the method further includes: A notification message is received from the second electronic device, where the notification message is used to indicate that the second electronic device has successfully performed the modification operation on the third database according to the modification request.
4. The method according to claim 2 or 3, characterized in that: The modification request includes the identifier of the second electronic device, the identifier of the second application, the identifier of the third database, and the modification operation.
5. The method according to any one of claims 1 to 4, characterized in that: The first electronic device includes a first synchronization service and a first database engine; The sending the synchronization request to the second electronic device includes: The first synchronization service sends the synchronization request obtained from the first application to the second electronic device; The receiving the target data from the second electronic device comprises: The first synchronization service receives the target data; the method further includes: The first synchronization service sends the target data to the first database engine; The step of updating the first database by using the target data to obtain an updated first database includes: The first database engine writes the target data into the first database to obtain the updated first database.
6. The method according to any one of claims 1 to 5, characterized in that: After the first database is updated by using the target data to obtain an updated first database, the method further includes: When the database version of the fourth database in the first electronic device is different from the database version of the updated first database, the database version of the updated first database is updated to obtain a fifth database, the database version of the fifth database is the same as the database version of the fourth database, wherein the fourth database is associated with the first application, and the fourth database is used to store data generated by the first application.
7. The method according to claim 6, characterized in that The first electronic device comprises a first database engine, When the database version of the fourth database in the first electronic device is different from the database version of the updated first database, updating the database version of the updated first database to obtain a fifth database includes: When the first application determines that the database version of the fourth database is different from the database version of the updated first database, the first application sends version update information to the first database engine, where the version update information is used to indicate that the database version of the updated first database is updated to the database version of the fourth database; The first database engine updates the database version of the updated first database according to the version update information to obtain the fifth database.
8. The method according to claim 6 or 7, characterized in that: In a case where the database version of the fourth database in the first electronic device is different from the database version of the updated first database, after updating the database version of the updated first database to obtain the fifth database, the method further includes: Generate query statements; According to the query statement, query processing is performed on the fourth database and the fifth database to obtain query results.
9. The method according to any one of claims 1 to 8, characterized in that: The synchronization request includes an identifier of the second electronic device, an identifier of the second application, an identifier of the second database, and a first synchronization sequence number; wherein the first synchronization sequence number is used to indicate a first position in the second database, and the first position is used to determine the target data.
10. The method according to any one of claims 1 to 9, characterized in that: The target data is transmitted via a transmission protocol, and the transmission protocol is also used to transmit data associated with multiple applications different from the second application.
11. The method according to any one of claims 1 to 10, characterized in that: The first database and the second database are embedded databases.
12. A data synchronization method, characterized in that: Applied in a second electronic device, the method includes: receiving a synchronization request from a first application of a first electronic device, the synchronization request being used to request that target data in a second database in the second electronic device be backed up to a first database in the first electronic device, the second database being associated with a second application of the second electronic device, and the first database being associated with the first application; According to the synchronization request, acquiring the target data from the second database; The target data is sent to the first electronic device, so that the first electronic device updates the first database using the target data to obtain an updated first database, and the data in the second database is the same as the data in the updated first database.
13. The method according to claim 12, characterized in that Before receiving the synchronization request of the first application from the first electronic device, the method further includes: receiving a modification request from the first electronic device, the modification request being used to request the second electronic device to perform a modification operation on a third database in the second electronic device to obtain the second database, the third database being associated with a second application of the second electronic device, the data in the third database being the same as the data in the first database, wherein the target data is data associated with the modification operation; According to the modification request, a modification operation is performed on the third database to obtain the second database.
14. The method according to claim 13, characterized in that The modification request includes the identifier of the second electronic device, the identifier of the second application, the identifier of the third database, and the modification operation.
15. The method according to claim 13 or 14, characterized in that After performing a modification operation on the third database according to the modification request to obtain the second database, the method further includes: A notification message is sent to the first electronic device, where the notification message is used to indicate that the second electronic device has successfully performed the modification operation on the third database according to the modification request.
16. The method according to any one of claims 13 to 15, characterized in that After performing a modification operation on the third database according to the modification request to obtain the second database, the method further includes: The log file in the second electronic device is updated to obtain an updated log file, wherein the updated log file records the modification operation.
17. The method according to any one of claims 12 to 16, characterized in that: The second electronic device includes a second synchronization service and a second database engine, The receiving a synchronization request from a first application of a first electronic device includes: The second synchronization service receives the synchronization request; The acquiring the target data from the second database according to the synchronization request includes: The second synchronization service sends instruction information to the second database engine according to the synchronization request, wherein the instruction information is used to instruct the second database engine to obtain the target data from the second database; the method further includes: The second database engine sends the target data to the second synchronization service; The sending the target data to the first electronic device includes: The second synchronization service sends the target data to the first electronic device.
18. The method according to claim 17, characterized in that The indication information carries a first synchronization sequence number included in the synchronization request, where the first synchronization sequence number is used to indicate a first position in the second database; After the second synchronization service sends the indication information to the second database engine according to the synchronization request, the method further includes: If the first position is the same as the second position in the second database, the second database engine determines the data in the second database located at the first position and the data located after the first position as the target data, and the second position is the position in the second database indicated by the second synchronization sequence number of the second electronic device; If the first position and the second position are different, the second database engine determines the data in the second database located from the first position to the second position as the target data.
19. The method according to any one of claims 12 to 18, characterized in that The target data is transmitted via a transmission protocol, and the transmission protocol is also used to transmit data associated with multiple applications different from the second application.
20. The method according to any one of claims 12 to 19, characterized in that The first database and the second database are embedded databases.
21. A data synchronization method, characterized in that: Applied to a data synchronization system including a first electronic device and a second electronic device, the method includes: The first electronic device generates a synchronization request for a first application of the first electronic device, the synchronization request being used to request to back up target data in a second database in the second electronic device to a first database in the first electronic device, the second database being associated with a second application of the second electronic device, and the first database being associated with the first application; The first electronic device sends the synchronization request to the second electronic device; The second electronic device acquires the target data from the second database according to the synchronization request; The second electronic device sends the target data to the first electronic device; The first electronic device updates the first database using the target data to obtain an updated first database, and the data in the second database is the same as the data in the updated first database.
22. A data synchronization device, characterized in that: Applied in a first electronic device including a first application, the apparatus includes a processing unit, and the processing unit is used to: generating a synchronization request for the first application, the synchronization request being used to request to back up target data in a second database in a second electronic device to a first database in the first electronic device, the second database being associated with a second application of the second electronic device, and the first database being associated with the first application; sending the synchronization request to the second electronic device; receiving the target data from the second electronic device; The first database is updated using the target data to obtain an updated first database, and the data in the second database is the same as the data in the updated first database.
23. A data synchronization device, characterized in that: Applied in a second electronic device, the device includes a processing unit, and the processing unit is used to: receiving a synchronization request from a first application of a first electronic device, the synchronization request being used to request that target data in a second database in the second electronic device be backed up to a first database in the first electronic device, the second database being associated with a second application of the second electronic device, and the first database being associated with the first application; According to the synchronization request, acquiring the target data from the second database; The target data is sent to the first electronic device, so that the first electronic device updates the first database using the target data to obtain an updated first database, and the data in the second database is the same as the data in the updated first database.
24. A data synchronization system, characterized in that: The system includes a first electronic device and a second electronic device. The first electronic device is used to: generate a synchronization request for a first application of the first electronic device, the synchronization request is used to request to back up target data in a second database in the second electronic device to a first database in the first electronic device, the second database is associated with a second application of the second electronic device, and the first database is associated with the first application; The first electronic device is further used to: send the synchronization request to the second electronic device; The second electronic device is used to: obtain the target data from the second database according to the synchronization request; The second electronic device is further used to: send the target data to the first electronic device; The first electronic device is further used to: update the first database using the target data to obtain an updated first database, and the data in the second database is the same as the data in the updated first database.
25. An electronic device, characterized in that: The electronic device includes a processor and a memory, the memory is used to store a computer program, and the processor is used to call and run the computer program from the memory, so that the electronic device executes the data synchronization method described in any one of claims 1 to 11 or claims 12 to 20.
26. A computer storage medium, characterized in that include: Computer instructions; when the computer instructions are executed on an electronic device, the electronic device executes the method according to any one of claims 1 to 11 or claims 12 to 20.