A database repair method and electronic device

By retrieving key field data from an SQLite database to generate a data table and automatically repairing corrupted database files, the problem of data loss caused by the vulnerability of SQLite databases is solved, thus improving the user experience.

CN114265722BActive Publication Date: 2026-01-02HUAWEI TECH CO LTD

Patent Information

Application Number
CN202010974792.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-09-16
Publication Date
2026-01-02
Estimated Expiration
2040-09-16

AI Technical Summary

Technical Problem

SQLite databases are susceptible to environmental damage. Once damaged, the entire database becomes inaccessible, and rebuilding the database results in data loss, leading to a poor user experience.

Method used

This paper provides a database repair method that generates a data table by obtaining predefined key field data, automatically repairs the damaged database file, backs up the database file to avoid data loss, and restores the data in a short time.

Benefits of technology

When the database is corrupted, it automatically retrieves critical data and generates data tables, reducing interference to users, preventing the loss of critical data, and improving user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114265722B_ABST
    Figure CN114265722B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a database repairing method and an electronic device. The method comprises: in the case that a first database file is damaged, obtaining data of at least one field in the first database file, and generating a first data table based on the data of the at least one field, the first data table existing in a second database file obtained by repairing. The at least one field can be predefined by an application. For example, the at least one field can be a field predefined for carrying data important to a user. Thus, in the case that a database file is damaged, part of data can be obtained from the damaged database file, and the database can be repaired by itself. Therefore, the interference and influence on the user can be avoided as much as possible, and the user experience can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of computers, and in particular to a database repair method and an electronic device. BACKGROUND

[0002] A SQLite (Structured Query Language Lite) database is a widely used database. It is a lightweight relational database suitable for mobile phones, personal digital assistants (PDAs), set-top boxes and other embedded devices. Many applications (APPs) use SQLite databases.

[0003] However, SQLite databases are relatively susceptible to environmental damage. Due to its lightweight nature, it does not provide a reliable repair mechanism. Once the database is damaged, even if only one table in the database is damaged, the entire data may not be accessible. Rebuilding the database will result in the loss of all original data. Therefore, the user may need to re-enter the lost data into the rebuilt database, which is not a good user experience. SUMMARY

[0004] Embodiments of the present application provide a database repair method and an electronic device to repair damaged database files, minimize user interference and impact, and improve user experience.

[0005] In a first aspect, a database repair method is provided. The method can be executed by an electronic device, or more specifically, by a processor in the electronic device. The electronic device can install one or more applications. Each application can store data through a corresponding database.

[0006] Specifically, the method includes: in the case of a damaged first database file, obtaining data of at least one field in the first database file; the at least one field is predefined by an application; generating a first data table based on the data of the at least one field; the first data table exists in a second database file obtained by repair.

[0007] It should be understood that the second database file is a database file obtained by self-repairing based on the damage of the first database file.

[0008] Based on the technical solution, the embodiment of the present application can obtain the data in the one or more fields by itself in the case of damaged database file, so that the important data in the damaged database file can be obtained, thereby reducing the impact on the user. At the same time, by obtaining the data by itself and generating the data table, the interference to the user can be reduced. Overall, the user experience can be improved.

[0009] In a possible design, the at least one field is a field defined based on the application and used to carry important data, which can be referred to as a key field. The database carried in the at least one field can be referred to as key data.

[0010] Based on such a design, the embodiment of the present application can obtain the key data by itself in the case of damaged database file, and then repair the database file. Thus, the loss of important data such as key data can be avoided, and the serious impact on the user's life and work can be avoided, which is beneficial to improve the user experience.

[0011] With reference to the first aspect, in some implementations of the first aspect, the method further includes: backing up the first database file to obtain a backup file of the first database file.

[0012] Specifically, the first database file can be directly stored as a backup file, and the file name of the backup file can be defined according to a predefined naming rule. For example, the file name of the first database file is “xxx.db”, and the file name of the backup file of the first database file is “xxx-corrupted.db”. Wherein, “xxx” can represent the database file name corresponding to the application, which can represent the file name of the first database file here, and “corrupted” represents damaged or damaged, so as to distinguish from the file name “xxx.db” of the first database file.

[0013] It should be understood that the backup file is only defined for the convenience of distinguishing from the first database file, and the file name of the backup file is only defined for the convenience of distinguishing from the file name of the damaged database file (such as the first database file), and these names should not constitute any limitation on the embodiment of the present application. The embodiment of the present application does not limit the file name.

[0014] By backing up the first database file, the risk of losing all data in the process of deleting the first database file can be avoided.

[0015] With reference to the first aspect, in some implementations of the first aspect, the data of the at least one field is obtained from the backup file of the first database file.

[0016] The data is obtained from the backup file of the first database file, and the time consumption is short, generally about 20 seconds, so the data can be recovered in a short time.

[0017] Optionally, the obtaining the data of the at least one field in the first database file comprises: obtaining the data of the at least one field from a second data table in the backup file of the first database file, when the second data table is not damaged, the second data table being a table used for storing the data of the at least one field.

[0018] It should be understood that the first data table and the second data table can both be understood as data tables used for carrying the data of the at least one field. When the at least one field is a key field, the first data table and the second data table can both be referred to as key data tables.

[0019] The difference is that the first data table is a table generated based on self-repair of the database, and the first data table exists in the second database file; and the second data table is a table existing in the backup file, that is, a table obtained by backing up from the first database file. In this implementation manner, if the second data table is not damaged, the data of the at least one field can be directly obtained from the second data table, and then the first data table is generated.

[0020] With reference to the first aspect, in some implementations of the first aspect, the data of the at least one field is obtained from a master table of the first database file, the master table storing statements and data used for generating the first database file.

[0021] The data of the at least one field is obtained from the master table, which is equivalent to executing the part of the statements (such as the statements of inserting the at least one field) of the second data table used for generating the first database file again. Compared with the previous implementation manner, the time consumption is longer, generally about 1 minute.

[0022] Optionally, the obtaining the data of the at least one field in the first database file comprises: obtaining the data of the at least one field from a master table, when a second data table in a backup file of the first database file is damaged, the second data table being a table used for storing the data of the at least one field.

[0023] It should be understood that the master table corresponds to the first database file, but does not necessarily exist in the same directory as the first database file. It should also be understood that the difference between the first data table and the second data table has been described above, and will not be repeated here for brevity.

[0024] Based on the above scheme, in the case of damage of the first database file, data can be obtained from the second data table of the first database file first, and if the second data table is damaged, data can be recovered from the main table. Thus, the duration of database repair can be shortened to the greatest extent.

[0025] In combination with the first aspect, in some implementations of the first aspect, the second database file is a database file created and repaired in the case of damage of the first database file.

[0026] That is, in the case of damage of the first database file, a new database file can be created. The new database file is a database file without stored data, and based on the repair, a second database file storing at least part of the data (such as the data of the at least one field) can be obtained.

[0027] Optionally, the second database file and the first database file have the same file name and the same structure.

[0028] In other words, the second database file is a database file obtained after repair and used to replace the first database file. After the repair of the database, if the user starts the application, the application can access the second database file by itself.

[0029] Optionally, the method further includes deleting the first database file.

[0030] Deleting the first database file can avoid access errors caused by the presence of two database files with the same file name (i.e., the first database file and the second database file) in subsequent access. One possible implementation is to delete the first database file after backing up the first database file; another possible implementation is to directly rename the first database file.

[0031] In a second aspect, a database repair apparatus is provided, which includes various modules or units for performing the method in any of the possible implementations of the first aspect. It should be understood that each of the modules or units described below can realize the corresponding function by executing a computer program. The computer program can be provided by an application, or the computer program can be provided by an electronic device installed with the application. The present application does not limit this.

[0032] Exemplarily, the apparatus includes an obtaining unit and a generating unit. The obtaining unit can be used to obtain data of at least one field in the first database file in the case of damage of the first database file; the at least one field is predefined by an application; and the generating unit can be used to generate a first data table based on the data of the at least one field, the first data table existing in a second database file obtained after repair.

[0033] With reference to the second aspect, in some implementations of the second aspect, the apparatus further includes a backup unit, configured to backup the first database file to obtain a backup file.

[0034] With reference to the second aspect, in some implementations of the second aspect, the data of the at least one field is obtained from a backup file of the first database file.

[0035] Optionally, the obtaining unit is specifically configured to obtain the data of the at least one field from a second data table in the backup file of the first database file, the second data table being a table for storing the data of the at least one field, in a case where the second data table is not damaged.

[0036] With reference to the second aspect, in some implementations of the second aspect, the data of the at least one field is obtained from a main table of the first database file, the main table storing a statement and data used to generate the first database file.

[0037] Optionally, the obtaining unit is specifically configured to obtain the data of the at least one field from the main table, in a case where a second data table in the backup file of the first database file is damaged, the second data table being a table for storing the data of the at least one field.

[0038] With reference to the second aspect, in some implementations of the second aspect, the second database file is a database file created and repaired in a case where the first database file is damaged.

[0039] Optionally, the second database file has the same file name and structure as the first database file.

[0040] Optionally, the apparatus further includes a deletion unit, configured to delete the first database file.

[0041] In a third aspect, an electronic device is provided, the electronic device is installed with an application, the application stores data through a corresponding database; the electronic device includes a memory and a processor. The memory is configured to store a computer program; the processor is configured to invoke the computer program in the memory, so that the electronic device executes the method in any possible implementation manner of the first aspect.

[0042] In a fourth aspect, a computer program product is provided, the computer program product includes a computer program (also referred to as code or instructions), when the computer program is executed, the electronic device executes the method in any possible implementation manner of the first aspect.

[0043] In a fifth aspect, a computer-readable storage medium is provided, which stores a computer program (also referred to as code or instructions). When the computer program is run, the electronic device is caused to perform the method in any possible implementation of the first aspect.

[0044] In some implementations, the database is a SQLite database.

[0045] It should be understood that the SQLite database is an example of a database, and should not be construed as limiting the embodiments of the present application. The database repair method provided by the present application can also be used for other databases, such as other databases that can be embedded in an application. For the sake of brevity, they are not listed one by one. BRIEF DESCRIPTION OF DRAWINGS

[0046] Figure 1 is a structural schematic diagram of an electronic device suitable for the database repair method provided by the embodiments of the present application;

[0047] Figure 2 is a software structure block diagram of an electronic device suitable for the database repair method provided by the embodiments of the present application;

[0048] Figure 3 is a schematic diagram of the architecture of the SQLite database provided by the embodiments of the present application;

[0049] Figure 4 is a schematic flowchart of the database repair method provided by the embodiments of the present application;

[0050] Figure 5 is a schematic diagram of the user interface (UI) presented by the electronic device in the case of an undamaged and damaged database file of "Contacts";

[0051] Figure 6 is a schematic diagram prompting that the database cannot be accessed;

[0052] Figure 7 is a schematic flowchart of the database repair method provided by another embodiment of the present application. DETAILED DESCRIPTION

[0053] The technical solutions in the present application will be described below with reference to the drawings.

[0054] For the sake of understanding the embodiments of the present application, the terms involved in the present application are first introduced.

[0055] 1、Database: a warehouse that organizes, stores and manages data according to data structure. Database stores data in a specific format, and users can add, modify, delete and query data in database.

[0056] In the embodiments of the present application, the database mainly refers to a database file. It should be understood that in addition to the database file, the database can also include interfaces and other components.

[0057] 2、Database file: can refer to a file that stores data in a database. The SQL database file can be identified by the extension "db", for example, "xxx.db". Wherein "xxx" is the database name, and "db" is the extension.

[0058] The data in the database is organized in units of data tables (for the sake of distinguishing from the data (data) table in the database file of the application "contact person" listed in the following embodiments, it is referred to as table here). The table exists in the database file. The table can be composed of a group of data records. For example, a table can be a group of related data arranged in rows. Each table can contain one or more data of the same type. Taking the database of "contact person" as an example, each row of the table can correspond to a contact person, and each row can include one or more data of the corresponding contact person's mobile phone number, fixed phone number, home address, call record, contact times, etc.

[0059] Each row in the table is called a record, which is composed of several fields. The data in the table can be modified by update, insert, delete, etc. structured query language (SQL) statements.

[0060] The field is also called the domain. Each column in the table can be called a field. Each field has corresponding description information, such as data type, data width, etc. According to the data type, data width, etc. specified by each field, a piece of data can be filled in.

[0061] In order to improve the efficiency of accessing the database, the database can be indexed. The index is a special type of table, which contains the values of the key fields and the pointers to the actual record positions. These values and pointers can be stored in a specific order, so that the required data record can be found at a faster speed. Among them, the values of the key fields and the specific order can be defined by the user.

[0062] 3. Database structure: the structure of a set of structured data stored on a storage device in a reasonable manner. A database structure can include tables, records, fields, filters, etc. The description of tables, records, and fields can be referred to the relevant description above, which will not be repeated here for brevity. A filter is a component of a database. It combines indexing and sorting to set conditions, and then outputs the required data according to the given conditions.

[0063] 4. View: a result set formed by combining one or more tables according to a certain condition. For example, the data in one or more tables can be rearranged according to the desired logical structure by code. In general, a view is controlled by filters and indexes. A view can also exist in a database file.

[0064] 5. SQLite database: a lightweight embedded database within a process. The SQLite database can be used directly without configuration in the system. The SQLite database does not need to purchase a separate database service, does not need a server process, and has almost zero configuration cost. SQLite3 database is a new version of SQLite database. For convenience of description, SQLite database and SQLite3 database are collectively referred to as SQLite database in this paper.

[0065] The SQLite database is a relational database. The format stored by the relational database can directly reflect the relationship between entities. The relational database can store data in a structured manner. Each data table must define the fields in advance (i.e., the structure of the table is defined in advance), and then store data according to the table structure. In this way, the form and content of the data are defined before the data is stored.

[0066] Most relational databases follow the structured query language (SQL) standard. Common operations include querying, adding, updating, deleting, summing, sorting, etc.

[0067] The database repair method provided in the embodiments of the present application can be applied to electronic devices such as mobile phones, tablet computers, wearable devices, vehicle-mounted devices, augmented reality (AR) / virtual reality (VR) devices, notebook computers, personal computers (PCs), ultra-mobile personal computers (UMPCs), netbooks, personal digital assistants (PDAs), distributed devices, and the like. The embodiments of the present application do not make any limitation on the specific type of electronic device.

[0068] In addition, the database described in the embodiments of the present application can support Linux, Android, Harmony Operating System (Harmony OS), Mac, iOS, Windows, and Internet of Things operating systems (such as LiteOS), and the like. The embodiments of the present application do not make any limitation on this.

[0069] Exemplarily, Figure 1 A structural schematic diagram of an electronic device 100 is shown. As shown in the figure, Figure 1 The electronic device 100 can include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a loudspeaker 170A, a receiver 170B, a microphone 170C, a headset interface 170D, a sensor module 180, a key 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, and the like. The sensor module 180 can include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, and the like.

[0070] It can be understood that the structure illustrated in the present application does not constitute a specific limitation on the electronic device 100. In other embodiments, the electronic device 100 can include more or fewer components than illustrated, or combine certain components, or split certain components, or different arrangement of components. The illustrated components can be implemented in hardware, software, or a combination of software and hardware.

[0071] The processor 110 can include one or more processing units, for example: the processor 110 can include one or more of an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and a neural-network processing unit (NPU), etc. Among them, different processing units can be independent devices, or can be integrated in one or more processors.

[0072] Among them, the application processor outputs sound signals through the audio module 170 (such as a speaker 170A, etc.), or displays images or videos through the display screen 194.

[0073] The controller can be the nerve center and command center of the electronic device 100. The controller can generate operation control signals according to instruction operation codes and timing signals to complete the control of fetching instructions and executing instructions.

[0074] The memory in the processor 110 can also be provided for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory can save instructions or data that the processor 110 has just used or repeatedly uses. If the processor 110 needs to use the instructions or data again, it can be directly called from the memory. Avoiding repeated access reduces the waiting time of the processor 110, thus improving the efficiency of the system.

[0075] The processor 110 can perform different operations to achieve different functions by executing instructions. The instructions may, for example, be instructions pre-stored in the memory before the device leaves the factory, or instructions read from an application (APP) after the user installs a new APP in the use process, and the embodiments of the present application do not make any limitation on this.

[0076] In some embodiments, the processor 110 can include one or more interfaces. The interfaces can include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.

[0077] The I2C interface is a bidirectional synchronous serial bus, including a serial data line (SDA) and a serial clock line (SCL). In some embodiments, the processor 110 can include multiple sets of I2C buses. The processor 110 can be coupled to the touch sensor 180K, the charger, the flash, the camera 193, etc. through different I2C bus interfaces, respectively. For example, the processor 110 can be coupled to the touch sensor 180K through an I2C interface, so that the processor 110 and the touch sensor 180K communicate through the I2C bus interface, and realize the touch function of the electronic device 100.

[0078] The I2S interface can be used for audio communication. In some embodiments, the processor 110 can include multiple sets of I2S buses. The processor 110 can be coupled to the audio module 170 through the I2S bus, and realize the communication between the processor 110 and the audio module 170. In some embodiments, the audio module 170 can deliver audio signals to the wireless communication module 160 through the I2S interface, and realize the function of answering the phone through the Bluetooth headset.

[0079] The PCM interface can also be used for audio communication, which samples, quantizes and encodes analog signals. In some embodiments, the audio module 170 and the wireless communication module 160 can be coupled through the PCM bus interface. In some embodiments, the audio module 170 can also deliver audio signals to the wireless communication module 160 through the PCM interface, and realize the function of answering the phone through the Bluetooth headset. Both the I2S interface and the PCM interface can be used for audio communication.

[0080] The UART interface is a universal serial bus for asynchronous communication. The bus can be a bidirectional communication bus. It converts the data to be transmitted between serial communication and parallel communication. In some embodiments, the UART interface is usually used to connect the processor 110 and the wireless communication module 160. For example, the processor 110 communicates with the Bluetooth module in the wireless communication module 160 through the UART interface to realize the Bluetooth function. In some embodiments, the audio module 170 can transmit audio signals to the wireless communication module 160 through the UART interface to realize the function of playing music through the Bluetooth headset.

[0081] The MIPI interface can be used to connect the processor 110 and peripheral devices such as the display screen 194 and the camera 193. The MIPI interface includes a camera serial interface (CSI), a display serial interface (DSI), etc. In some embodiments, the processor 110 and the camera 193 communicate through the CSI interface to realize the shooting function of the electronic device 100. The processor 110 and the display screen 194 communicate through the DSI interface to realize the display function of the electronic device 100.

[0082] The GPIO interface can be configured by software. The GPIO interface can be configured as a control signal or as a data signal. In some embodiments, the GPIO interface can be used to connect the processor 110 and the camera 193, the display screen 194, the wireless communication module 160, the audio module 170, the sensor module 180, etc. The GPIO interface can also be configured as an I2C interface, an I2S interface, a UART interface, a MIPI interface, etc.

[0083] The USB interface 130 is an interface that meets the USB standard specification, which can be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc. The USB interface 130 can be used to connect a charger to charge the electronic device 100, or to transmit data between the electronic device 100 and a peripheral device. It can also be used to connect a headset to play audio through the headset. The interface can also be used to connect other electronic devices, such as AR devices, etc.

[0084] It can be understood that the interface connection relationship between the modules illustrated in the present application is only illustrative and does not constitute a structural limitation of the electronic device 100. In other embodiments, the electronic device 100 can also use different interface connection methods or combinations of multiple interface connection methods in the above embodiments.

[0085] The charging management module 140 is configured to receive charging input from a charger. The charger can be a wireless charger or a wired charger. In some embodiments with wired charging, the charging management module 140 can receive charging input from a wired charger through the USB interface 130. In some embodiments with wireless charging, the charging management module 140 can receive wireless charging input through a wireless charging coil of the electronic device 100. The charging management module 140 can charge the battery 142 and power the electronic device through the power management module 141.

[0086] The power management module 141 is configured to connect the battery 142, the charging management module 140, and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140 to power the processor 110, the internal memory 121, the external memory, the display 194, the camera 193, and the wireless communication module 160, etc. The power management module 141 can also be configured to monitor parameters such as battery capacity, battery cycle count, battery health status (leakage, impedance), etc. In some other embodiments, the power management module 141 can also be disposed in the processor 110. In some other embodiments, the power management module 141 and the charging management module 140 can also be disposed in the same device.

[0087] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor, and the baseband processor, etc.

[0088] The antenna 1 and the antenna 2 are configured to transmit and receive electromagnetic wave signals. Each antenna in the electronic device 100 can be configured to cover a single or multiple communication frequency bands. Different antennas can also be multiplexed to improve the utilization of the antennas. For example, the antenna 1 can be multiplexed as a diversity antenna for a wireless local area network. In some other embodiments, the antennas can be used in combination with a tuning switch.

[0089] The mobile communication module 150 can provide a solution for wireless communication including 2G / 3G / 4G / 5G, etc. applied to the electronic device 100. The mobile communication module 150 can include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves by the antenna 1, and perform filtering, amplification, etc. on the received electromagnetic waves, and transfer to a modem processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modem processor, and radiate as electromagnetic waves through the antenna 1. In some embodiments, at least part of the functional modules of the mobile communication module 150 can be disposed in the processor 110. In some embodiments, at least part of the functional modules of the mobile communication module 150 can be disposed in the same device as at least part of the modules of the processor 110.

[0090] The modem processor can include a modulator and a demodulator. The modulator is configured to modulate a low-frequency baseband signal to be transmitted into a medium-high frequency signal. The demodulator is configured to demodulate a received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. The low-frequency baseband signal processed by the baseband processor is transmitted to the application processor. The application processor outputs a sound signal through an audio device (not limited to the speaker 170A, the microphone 170B, etc.), or displays an image or a video through the display screen 194. In some embodiments, the modem processor can be a separate device. In other embodiments, the modem processor can be independent of the processor 110, and disposed in the same device as the mobile communication module 150 or other functional modules.

[0091] The wireless communication module 160 can provide a solution for wireless communication including wireless local area networks (WLAN) (e.g., wireless fidelity (Wi-Fi) network), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR) technology, etc. applied to the electronic device 100. The wireless communication module 160 can be one or more devices that integrate at least one communication processing module. The wireless communication module 160 receives an electromagnetic wave via the antenna 2, frequency-modulates and filters the electromagnetic wave signal, and transmits the processed signal to the processor 110. The wireless communication module 160 can also receive a signal to be transmitted from the processor 110, frequency-modulate it, amplify it, and radiate it as an electromagnetic wave via the antenna 2.

[0092] In some embodiments, the antenna 1 and the mobile communication module 150 of the electronic device 100 are coupled, and the antenna 2 and the wireless communication module 160 are coupled, so that the electronic device 100 can communicate with a network and other devices through wireless communication technology. The wireless communication technology can include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), wideband code division multiple access (WCDMA), time-division code division multiple access (TD-SCDMA), long term evolution (LTE), 5th generation (5G) communication system, BT, GNSS, WLAN, NFC, FM, and / or IR technology, etc. The GNSS can include global positioning system (GPS), global navigation satellite system (GLONASS), BeiDou navigation satellite system (BDS), quasi-zenith satellite system (QZSS), and / or satellite based augmentation systems (SBAS).

[0093] The electronic device 100 can implement a display function through a GPU, a display screen 194, and an application processor, etc. The GPU is a microprocessor for image processing, which is connected to the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 can include one or more GPUs, which execute program instructions to generate or change display information.

[0094] The display screen 194 is configured to display images, videos, and the like. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flex light-emitting diode (FLED), a Mini LED, a Micro LED, a Micro-OLED, a quantum dot light emitting diodes (QLED), or the like. In some embodiments, the electronic device 100 can include one or more display screens 194.

[0095] The electronic device 100 can implement the photographing function through the ISP, the camera 193, the video codec, the GPU, the display screen 194, and the application processor.

[0096] The ISP is configured to process the data fed back by the camera 193. For example, when taking a photo, the shutter is opened, the light is transmitted to the camera photosensitive element through the lens, the light signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to the ISP for processing to convert it into an image visible to the naked eye. The ISP can also optimize the algorithm for noise, brightness, and skin color of the image. The ISP can also optimize the exposure, color temperature, and other parameters of the shooting scene. In some embodiments, the ISP can be disposed in the camera 193.

[0097] The camera 193 is configured to capture still images or videos. An object generates an optical image through a lens and projects it onto a photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, and then transmits the electrical signal to the ISP to convert it into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV, or the like format. In some embodiments, the electronic device 100 can include one or more cameras 193.

[0098] The digital signal processor is used to process digital signals, in addition to being able to process digital image signals, it can also process other digital signals. For example, when the electronic device 100 selects a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy, etc.

[0099] The video codec is used to compress or decompress digital video. The electronic device 100 can support one or more video codecs. In this way, the electronic device 100 can play or record videos in multiple encoding formats, such as: moving picture experts group (MPEG) 1, MPEG 2, MPEG 3, MPEG 4, etc.

[0100] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to realize data storage functions. For example, files such as music and videos are saved in the external memory card.

[0101] The internal memory 121 can be used to store computer executable program codes, which include instructions. The processor 110 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. The internal memory 121 can include a program storage area and a data storage area. The program storage area can store an operating system, at least one application program required by a function (such as a sound playing function, an image playing function, etc.), etc. The data storage area can store data created during the use of the electronic device 100 (such as audio data, a phone book, etc.), etc. In addition, the internal memory 121 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, a universal flash storage (UFS), etc.

[0102] The electronic device 100 can realize audio functions through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the earphone interface 170D, and the application processor, etc. For example, music playing, recording, etc.

[0103] The audio module 170 is used to convert digital audio information into analog audio signals, and is also used to convert analog audio input into digital audio signals. The audio module 170 can also be used to encode and decode audio signals. In some embodiments, the audio module 170 can be arranged in the processor 110, or some functional modules of the audio module 170 can be arranged in the processor 110.

[0104] The speaker 170A, also called a "loudspeaker", is used to convert an audio electrical signal into a sound signal. The electronic device 100 can listen to music or listen to a hands-free call through the speaker 170A.

[0105] The receiver 170B, also called a "earpiece", is used to convert an audio electrical signal into a sound signal. When the electronic device 100 answers a call or a voice message, the receiver 170B can be held close to a human ear to listen to the voice.

[0106] The microphone 170C, also called a "microphone", "sound collector", is used to convert a sound signal into an electrical signal. When making a call or sending a voice message, a user can speak into the microphone 170C through the human mouth to input a sound signal into the microphone 170C. The electronic device 100 can be provided with at least one microphone 170C. In other embodiments, the electronic device 100 can be provided with two microphones 170C, in addition to collecting sound signals, noise reduction functions can also be realized. In other embodiments, the electronic device 100 can also be provided with three, four or more microphones 170C, in addition to collecting sound signals, noise reduction, it can also identify the source of the sound, realize the function of directional recording, etc.

[0107] The earphone interface 170D is used to connect a wired earphone. The earphone interface 170D can be a USB interface 130, or a 3.5mm open mobile terminal platform (OMTP) standard interface, a cellular telecommunications industry association of the USA (CTIA) standard interface.

[0108] The software system of the electronic device 100 can adopt a layered architecture, an event-driven architecture, a microkernel architecture, a microservice architecture, or a cloud architecture. This application takes the Android system with a layered architecture as an example to illustrate the software structure of the electronic device 100. The type of operating system of the electronic device is not limited in this application. For example, Android system, Hongmeng OS, etc.

[0109] Figure 2 is a software structure block diagram of an electronic device suitable for the database repair method provided in the embodiments of the present application. As shown in Figure 2 The layered architecture divides the software into several layers, and 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 four layers, from top to bottom, the application layer, the application framework layer, the Android runtime and the system library, and the kernel layer.

[0110] The application layer can include a series of application packages. As shown in Figure 2 the application packages can include camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, game, shopping, travel, instant messaging (such as short message, etc.), smart home, device control, and the like.

[0111] Among them, the smart home application can be used to control or manage home devices with networking function. For example, the home devices can include electric lamp, television and air conditioner. For another example, the home devices can also include anti-theft door lock, sound box, sweeping robot, socket, body fat scale, table lamp, air purifier, refrigerator, washing machine, water heater, microwave oven, electric rice cooker, curtain, fan, television, set-top box, door and window, etc.

[0112] The application framework layer provides application programming interface (API) and programming framework for the applications of the application layer. The application framework layer includes some pre-defined functions. As shown in Figure 2 the application framework layer can include input manager service (IMS). Of course, the application framework layer can also include display policy service, power manager service (PMS), display manager service (DMS), activity manager, resource manager, content provider, view system, phone manager, notification manager, window manager, etc. The embodiments of the present application do not make any limitation in this regard.

[0113] The window manager is used to manage window programs. The window manager can acquire the size of the display screen, judge whether there is a status bar, lock the screen, intercept the screen, etc.

[0114] The content provider is used to store and acquire data, and make the data accessible by the application. The data can include video, image, audio, dialed and received phone, browsing history and bookmark, phone book, etc.

[0115] The view system includes visual controls, such as controls for displaying text, controls for displaying pictures, etc. The view system can be used to build application. The display interface can be composed of one or more views. For example, the display interface including short message notification icon can include view for displaying text and view for displaying picture.

[0116] The phone manager is used to provide the communication function of the electronic device 100. For example, the management of call state (including call connection, call hang-up, etc.).

[0117] The resource manager provides applications access to various resources, such as localized strings, icons, pictures, layout files, video files, and so on.

[0118] The notification manager enables applications to display notification information in the status bar, which can be used to convey a message of the notification type, and can automatically disappear after a short stay without user interaction. For example, the notification manager is used to notify the completion of a download, a message reminder, and so on. The notification manager can also be a notification in the form of a chart or a scroll bar text appearing in the system top status bar, such as a notification of an application running in the background, and can also be a notification in the form of a dialog window appearing on the screen. For example, a text information is prompted in the status bar, a prompt sound is emitted, the electronic device vibrates, the indicator light flashes, and so on.

[0119] The Android runtime can include a core library and a virtual machine. The Android runtime is responsible for the scheduling and management of the Android system.

[0120] The core library can include two parts: one part is a function function that the java language needs to call, and the other part is the core library of the Android system.

[0121] The application layer and the application framework layer run in the virtual machine. The virtual machine executes the java files of the application layer and the application framework layer into binary files. The virtual machine is used to perform the management of the object life cycle, the management of the stack, the management of the thread, the management of the security and the exception, and the garbage collection and the like.

[0122] The system library can include a plurality of function modules. For example: a state monitoring service, a surface manager, media libraries, a three-dimensional graphics processing library (for example, OpenGLES), a two-dimensional (2 dimensions, 2D) graphics engine (for example, SGL), and the like.

[0123] The state monitoring service is used to determine the specific orientation of the mobile phone, the physical state of the flexible screen, and the like according to the monitoring data reported by the kernel layer. The surface manager is used to manage the display subsystem, and provides a fusion of 2D and three-dimensional (3 dimensions, 3D) layers for a plurality of applications. The media library supports a plurality of commonly used audio, video format playback and recording, and static image files, and the like. The media library can support a plurality of audio and video encoding formats, such as MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, and the like. The three-dimensional graphics processing library is used to realize three-dimensional graphics drawing, image rendering, synthesis, and layer processing, and the like. The 2D graphics engine is a drawing engine for 2D drawing.

[0124] In the embodiments of the present application, the system library can also include a database, such as the SQLite database described above. The SQLite database is an embedded database, which is a main component of an application program and can run directly in the process of the application program. The architecture of the SQLite database will be described below, and for the sake of brevity, will not be described here in detail. Figure 3

[0125] The kernel layer is a layer between hardware and software. The kernel layer at least includes display drivers, camera drivers, audio drivers, sensor drivers, and the like. The embodiments of the present application do not make any limitation on this.

[0126] As shown in FIG. 1, the system library and the kernel layer and the like below the application framework layer can be referred to as an underlying system. The underlying system includes an underlying display system for providing display services, for example, the underlying display system includes display drivers in the kernel layer and surface managers in the system library and the like. Figure 2

[0127] It can be understood that the structure illustrated in the present application does not constitute a specific limitation on the electronic device 100. In other embodiments, the electronic device 100 can include more or fewer components than illustrated, or combine certain components, or split certain components, or different component arrangements. The illustrated components can be implemented in hardware, software, or a combination of software and hardware.

[0128] Figure 3 FIG. 2 is a schematic diagram of the architecture of the SQLite database provided in the embodiments of the present application. Figure 3 FIG. 2 shows components in the SQLite database and mutual operations. The SQLite database includes a core, a compiler, and a backend. The core includes an interface, a SQL command processor, and a virtual machine. The compiler includes a tokenizer, a parser, and a code generator. The backend includes a B-tree, a page cache (pager), and an operating system interface (OS interface). The SQLite database can also include accessories, which can include utilities and test code. The components will be described in detail below.

[0129] The workflow of SQLite mainly compiles SQL text into byte code, and then runs the byte code on a virtual machine.

[0130] ​​Specifically, the interface can refer to a C language interface. The interface is composed of SQLite API. Programs, script languages or library files can interact with the SQLite database through the interface. For example, the interface can send SQL text from the outside to the SQL command processor.

[0131] When an SQL text is to be compiled, the SQL command processor first sends it to the compiler. In the compiler, the lexical analyzer and the syntax analyzer can perform syntax checking on the SQL statement, and then convert it into a layered data structure (i.e., a syntax tree) that can be more conveniently processed at the bottom. Illustratively, the lexical analyzer can decompose the SQL text into words, and then send them one by one to the syntax analyzer. The syntax analyzer can give it semantics according to its context. The syntax analyzer converts the words into a syntax tree, and sends it to the code generator. The code generator analyzes the syntax tree, and generates byte code that conforms to the SQL function. The byte code output by the code generator is finally executed by the virtual machine.

[0132] The B-tree and the page cache jointly manage the data. The main function of the B-tree is indexing, which maintains complex relationships between various pages, facilitating fast finding of required data. The page cache can transfer pages between the B-tree and the disk through the OS interface.

[0133] The OS interface is also the interface of system calls. In order to provide cross-operating system portability, SQLite uses an abstract object named virtual file system (VFS). Each VFS provides methods for opening, closing and reading and writing disk files, as well as other operating system-specific functions, such as setting a random seed for a pseudo-random number generator at the current time, etc. For example, SQLite currently provides VFS for unix and windows.

[0134] Utilities, which can also be referred to as general libraries, can be used to implement memory allocation, string comparison routines, portable string-to-number conversion routines, etc.

[0135] In the src folder, the files starting with test are test codes, which are not included in the standard library version.

[0136] It should be understood that the above is combined with Figure 3 The architecture of the SQLite database is briefly introduced. However, this is only shown for ease of understanding, and should not constitute any limitation on the embodiments of the present application.

[0137] As mentioned above, each application database file can include one or more tables and one or more views. A view can be a combination of data from one or more tables. When accessing a database file, an application can generate different views according to different commands. The views are usually generated from multiple associated tables according to the logical structure corresponding to the command. If a table in the database file is damaged, the view cannot be generated. In other words, partial data damage in the database file can result in the whole data being unable to be normally accessed.

[0138] When a user opens an application to access a database file, the background usually generates a view based on multiple associated tables according to user operations, and then presents relevant data on a user interface. If the data in the database file is damaged, the view cannot be generated, and the user cannot read the data in the database file.

[0139] SQLite databases are prone to damage due to environmental factors, such as file synchronization failure, file system damage, storage exception, insufficient space, memory out-of-bounds, power failure, third-party application access and writing to the database (for example, due to the openness of SQLite databases, third-party application access can be supported, and concurrent problems can be caused by multiple applications accessing simultaneously), and the like, resulting in SQLite database damage. It should be understood that database damage can usually refer to database file damage. For example, part or all of the tables therein are damaged. Correspondingly, repairing a database can refer to repairing a database file.

[0140] SQLite databases themselves do not provide a reliable repair mechanism. Once damaged, even if only a table therein is damaged, the whole data cannot be accessed. When the user starts, the originally stored data cannot be accessed.

[0141] If the database is rebuilt, the originally saved data, even if not damaged, will be deleted, resulting in the loss of all data in the database. The user can need to re-input the data originally saved in the application. For example, if the SQLite database of the application "Contacts" is damaged, the user can need to re-input the lost data, such as the names of contacts and contact information. This not only brings unnecessary workload to the user, but also the loss of data can seriously affect the user's life and work, and the user experience is not good.

[0142] Embodiments of the present application provide a database repair method and an electronic device. In order to avoid the bad user experience caused by reconstruction in the case of database damage, the present application proposes the idea of obtaining key data and repairing the database file based on the key data. Thus, when the database is damaged, the key data can be recovered as much as possible, thereby avoiding unnecessary repeated operations of the user, reducing the impact on the user's life and work, and further improving the user experience.

[0143] The method provided by the embodiments of the present application will be described in detail below with reference to the accompanying drawings. It should be understood that the method embodiments shown below can be executed by an electronic device, for example. Specifically, the corresponding computer program (or code or instruction) can be executed by calling the processor in the electronic device. The electronic device can be an electronic device installed with an application, which can use a database (such as a SQLite database) to save data. The above computer program can be provided by the application, such as by the application developer. After the application is installed on the electronic device, the above computer program can be saved in the storage space corresponding to the application in the memory of the electronic device. Alternatively, the above computer program can also be pre-stored in the electronic device, such as provided by the electronic device manufacturer. When the processor in the electronic device executes the above computer program to implement the repair of the database file of a certain application, the relevant parameters in the application can be called, and then the repair can be made for the database of different applications; or the application can request to send the relevant parameters to the processor in the electronic device to make the repair according to the relevant parameters. The above relevant parameters can include, for example, the definition of the key field, the naming rule of the database file, the storage address of the database file, and the like. The embodiments of the present application are not limited thereto.

[0144] Hereinafter, for the convenience of description, the specific process of the method embodiments is described taking the electronic device as the execution subject.

[0145] Figure 4 is a schematic flowchart of the database repair method 400 provided by the embodiments of the present application. As shown in Figure 4 the method 400 can include steps 410 to 440. The details of each step in the method 400 will be described below.

[0146] In step 410, it is determined that the database file is damaged.

[0147] As described above, each application can use a database to save data. One or more tables and one or more views can be saved in the database of each application, and these tables and views exist in the database file. Once a certain table therein is damaged, for example, part or all of the data in a certain table is damaged, the entire database file cannot be normally accessed.

[0148] One possibility is that when a user launches an application, the processor in the electronic device can access data from that database through its interface. However, if the data in the database is corrupted, it cannot be accessed normally. In this case, the electronic device can determine that the database is corrupted. The user may not be able to find the previously saved data after launching the application.

[0149] Figure 5 a) and b) in the diagram show the user interface presented by the electronic device when the "Contacts" database file is intact and corrupted, respectively. Figure 5 As shown in a), assuming the database file is not corrupted, the "Contacts" section stores data for 71 contacts, and the user interface displays "71 Contacts"; Figure 5 As shown in b), if the database file is corrupted, all contact data saved in "Contacts" will be lost, and the user interface will display "0 contacts".

[0150] Another possibility is that the database files of each application can be checked when the system is idle. For example, management software (such as a phone manager) can be used to check the database files in each application's database. The phone management software can access the database of each application. If the phone management software cannot access the data normally when calling data through the database interface of each application, it can be determined that the database file is corrupted.

[0151] Another possibility is that the database file can be opened using database management software or database access tools. If the database file is corrupted, a prompt may appear reminding the user that the database cannot be accessed.

[0152] Figure 6 This example illustrates a database access failure message. When a user connects their phone to a computer and attempts to open a corrupted database file using database management software, they may encounter a "database disk image is malformed" message, preventing access to the database.

[0153] It can be understood that the process by which management software and access tools detect or access the database files of various applications is the process by which the electronic device (specifically, the processor in the electronic device) that has the management software or access tools installed executes the corresponding code to implement the corresponding function.

[0154] It should be understood that the above-listed scenarios for determining database file corruption are merely examples and should not be construed as limiting the scope of this application. Electronic devices can determine database file corruption using methods found in the prior art. For the sake of brevity, detailed examples are not provided here.

[0155] In the following, for the convenience of distinguishing and explaining, the damaged database file is referred to as a first database file.

[0156] In the current technology, after determining that the database file is damaged, the electronic device can perform database reconstruction. That is, the electronic device can delete the first database file, and then newly create a database file based on the structure of the first database file. The newly created database file can have the same database structure as the first database file, and have the same file name. That is, when the user accesses the database after the database reconstruction, the accessed database is the newly created database file, rather than the damaged database. However, it can be understood that the newly created database file is empty, and all the data originally saved in the damaged database file has been completely lost. The user can complete the reconstruction of the database file by later manual input.

[0157] In the embodiments of the present application, the electronic device can back up the first database file, so as to avoid directly deleting the first database file and causing all the data to be lost.

[0158] That is, optionally, the method further includes step 420 of backing up the damaged database file (i.e., the first database file) to obtain a backup file.

[0159] In an implementation manner, the electronic device can directly rename the first database file. For example, the first database file is named as “xxx-corrupted.db”. Wherein, “xxx” can represent the database file name corresponding to the application, and in the embodiments of the present application, represents the name of the first database file. “corrupted” represents damaged, damaged, so as to be distinguished from the file name “xxx.db” of the first database file. The renamed database file is the backup of the first database file, i.e., the backup file.

[0160] In another implementation manner, the electronic device can copy the first database file, and the copied database file is the backup file. The backup file can also be named in the above manner, so as to be distinguished from the first database file.

[0161] It should be understood that the backup file can also be defined with other names, and the embodiments of the present application do not make any limitation thereon. As long as the name can distinguish the backup file from the damaged database file.

[0162] The backup of the first database file is to avoid directly deleting the first database file due to the database reconstruction, so as to cause all the data in the first database file to be lost. In the subsequent process, the electronic device can acquire part of the data from the backup file in the case that part of the data is not damaged.

[0163] After the backup of the first database file, the electronic device can also delete the first database file (i.e., the file with the name "xxx.db") and rebuild a new database file according to the processing manner of the prior art. The rebuilt database file is used for subsequent database repair (see step 440 below for details).

[0164] Since the application can have defined in advance which database file to access, or the electronic device can specify which database file to access after installing an application, and can specify the path to access the database file, the rebuilt database file can be named according to the name of the first database file (for example, it can be named "xxx.db"), that is, the rebuilt database file replaces the first database file. The rebuilt database file can be saved in the same directory as the first database file. Subsequently, if the database with the name "xxx.db" is accessed, that is, the rebuilt database file is accessed, or the repaired database file is accessed.

[0165] In step 430, data of at least one field in the damaged database file (i.e., the first database file) is obtained.

[0166] The data of at least one field in the first database file, that is, part of the data in the first database file. In a possible design, the data of the at least one field can be important data, or data that users pay more attention to.

[0167] For example, for the application "Contacts", the key data is usually the name and the phone number; for the application "Short Message", the key data is usually the chat record; for the application "Schedule", the key data is usually the to-do list, and so on. For brevity, they are not listed one by one here.

[0168] For ease of understanding and description, the data of the at least one field is referred to as key data in the following, the at least one field can be referred to as a key field, and the table for storing the key data can be referred to as a key data table. It can be understood that the key data table includes one or more key fields, and the key fields carry the key data.

[0169] The following embodiments will take the key data as an example of the data of the at least one field to explain steps 430 and 440 in detail. However, it should be understood that the data of the at least one field can also be other data, which can be defined by the application, user-defined, or the like. The embodiments of the present application are not limited in this regard.

[0170] The key data can be defined, for example, based on the settings of the database structure. In one implementation, the application can define which fields in which table in the database store the key data. Correspondingly, the fields can be referred to as key fields, and the table storing the key data can be referred to as a key data table. It can be understood that there can be one or more key fields, and there can be one or more key data tables.

[0171] In one possible design, the key fields can be pre-configured before the electronic device is shipped, or before the application is put on the application market by the developer of the application, and can not be adjusted later. When the database file of the application is repaired, the electronic device installed with the application can automatically execute a corresponding program to read the data in the key fields, i.e., the key data.

[0172] The key fields can be determined, for example, based on the definition of the data type and / or data width of each field in the database structure. For example, a field with a larger data width can be defined as a key field to avoid the adverse user experience caused by repeated filling of the data by the user in the case of database file damage. For another example, the key fields can be defined based on the data type of each field in combination with the different functions of the application and the data most concerned by the user, such as the key data corresponding to different users listed above, and the fields corresponding to the key data are defined as the key fields.

[0173] In another possible design, the key fields can also be defined by the user during the use of the application to meet different needs of different users. For example, the user can be prompted by the application to set the key data through a user interface (UI) when the application is started for the first time. According to the setting of the user, the application can record the fields storing the key data, and the key fields can be defined. Alternatively, the user can adjust the key data according to the change of the needs during the subsequent use to redefine the key fields.

[0174] There can be multiple possible cases of database damage. Taking the key data as an example, in one possible case, the table storing the key data in the backup file (i.e., the key data table) is not damaged, and the key data in the table is still retained. In another possible case, the table storing the key data in the backup file (i.e., the key data table) is damaged, but the key data in the table is not damaged, and the key data is still retained. In yet another possible case, the table storing the key data in the backup file (i.e., the key data table) is damaged, and the key data in the table is also damaged, and the key data is lost.

[0175] Based on whether the key data is retained, the electronic device can obtain the key data in different ways. Alternatively, step 430 specifically includes:

[0176] Step 4301, determining whether the key data in the backup file of the first database file is damaged;

[0177] Step 4302, in the case where the key data in the backup file is not damaged, obtaining the key data from the backup file;

[0178] Step 4303, in the case where the key data in the backup file is damaged, obtaining the key data from the master table.

[0179] The above steps will be described in detail below.

[0180] In step 4301, one possible implementation of determining whether the key data in the backup file of the first database file is damaged is to determine whether the key data table in the backup file is damaged. For the sake of distinguishing and description, the key data table in the backup file is referred to as a second data table. It can be understood that the second data table can be obtained by backing up the first database file. Therefore, the damage of the key data in the backup file means the damage of the key data in the first database file; the damage of the key data table (i.e., the second data table) in the backup file means the damage of the key data table in the first database file.

[0181] One possible case is that if the second data table in the backup file of the first database file is damaged, the data in the second data table cannot be read, and thus it can be considered that the key data in the backup file is damaged, or lost. In step 4302, the electronic device can obtain the key data from the backup file in the case where the key data table in the backup file of the first database file is not damaged.

[0182] As an example of step 4301 and step 4302, the electronic device can find the second data table in the backup file by executing a select statement by itself. If the second data table is not damaged, the second data table can be found; if the second data table is damaged, an error can be returned, and the data in the second data table cannot be read.

[0183] After the electronic device finds the second data table in the backup file, the electronic device can execute a select statement by itself again to find the key data from the key field of the second data table. In this way, the key data can be obtained from the backup file.

[0184] It should be understood that the above description of determining whether the key data is damaged based on whether the key data table (i.e., the second data table) in the backup file is damaged, and obtaining the key data from the key data table, in connection with step 4301 and step 4302, is only one possible implementation, and should not constitute any limitation on the present application.

[0185] In another possible implementation, the electronic device can also directly search for the key data, such as by automatically running a query statement. If the key data is not damaged, the key data can be searched for; if the key data is damaged, an error can be returned, and the key data cannot be read.

[0186] In step 4303, the key data in the backup file is damaged, and it is possible that the key data table (i.e., the second data table described above) cannot be accessed, or that the key data table (i.e., the second data table) in the backup file is partially or entirely damaged, and the damaged data includes the key data. In this case, the key data can be obtained from the master table.

[0187] Here, the master indicates a file saved in a directory different from the first database file and its backup file in the database. The master table can save all information in the first database file, such as all table information, and statements for creating a table, inserting, and the like.

[0188] An example of a SQL statement obtained from the master table is shown below.

[0189] CREATE TABLE data (_id INTEGER PRIMARY KEY AUTOINCREMENT, package_id INTEGER REFERENCES package (_id), mimetype_id INTEGER REFERENCES mimetype (_id) NOT NULL, raw_contact_id INTEGER REFERENCES raw_contacts (_id) NOT NULL, hash_id TEXT, is_read_only INTEGER NOT NULL DEFAULT 0, is_primary INTEGER NOT NULL DEFAULT 0, is_super_primary INTEGER NOT NULL DEFAULT 0, data_version INTEGER NOT NULL DEFAULT 0, data1 TEXT, data2 TEXT, data3 TEXT, data4 TEXT, data5 TEXT, data6 TEXT, data7 TEXT, data8 TEXT, data9 TEXT, data10 TEXT, data11 TEXT, data12 TEXT, data13 TEXT, data14 TEXT, data15 TEXT, data_sync1 TEXT, data_sync2 TEXT, data_sync3 TEXT, data_sync4 TEXT, carrier_presence INTEGER NOT NULL DEFAULT 0);

[0190] INSERT INTO data VALUES(3,NULL,5,3,'log6TBlQUmRdA1ls4SasINToeWg=',0,0,0,1,'13298364512','2',NULL,'+861329836 4512',NULL,'Zhengzhou, Henan',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0); INSERT INTO data VALUES(4, NULL,7,3,'sSHRM2Se /

[0191] As can be seen, the master table contains statements for creating the data table and statements for inserting data into that data table. It should be understood that the above is merely an example and should not be construed as limiting this application. Those skilled in the art will understand that only a portion of the statements in the master table are shown above, and not all statements in the master table are represented. The number of statements in the master table varies depending on the size of the data stored in the database. This application's embodiments do not impose any limitations on this.

[0192] For example, an electronic device can retrieve key data from the master table. However, it's understood that the relationships between this data are not explicit. The application can then generate new key data tables based on the SQL statements recorded in the master table used to create the key data tables in the first database file. It should be noted that these newly generated key data tables are based on the data retrieved from master, and do not refer to the second data table found in the backup file mentioned above, or the key data tables in the first database file. However, it's understood that these key data tables all contain the same key data.

[0193] In practical implementation, electronic devices can, for example, automatically execute lookup statements and set filter conditions to retrieve data from key data tables; then, they can execute create table statements to create the key data tables. It should be understood that executing create table statements to create key data tables essentially means re-executing the relevant statements in the master table.

[0194] It should be understood that the electronic device can acquire all the data in the key data table or only acquire the key data in the key data table. The present application does not limit this. However, it should be understood that the process of acquiring data from the master table and creating a table is a time-consuming process, and the time consumption can be reduced as much as possible by reducing the amount of data. Therefore, it is preferable to acquire the key data in the key data table.

[0195] In the present embodiment, the key data table can be saved in the same directory as the master table.

[0196] It should be noted that the backup file and the master table are database files of the same application and can be saved in the same database, such as in different directories of the same database.

[0197] It should be understood that steps 4301 to 4303 are described in combination with whether the key data in the backup file is damaged. Therefore, it is not necessary to perform all of steps 4301 to 4303.

[0198] In step 440, the acquired data (e.g., key data) of at least one field is inserted into the newly created database file to obtain a repaired database file.

[0199] Here, the newly created database file can be a database file reconstructed by the electronic device after determining that the first database file is damaged. As mentioned in step 420, the step of reconstructing the new database file can be performed after backing up the first database file in step 420, for example, can be performed simultaneously with step 430, or before or after step 430, and the present embodiment does not limit this. It should be understood that the newly created database file is created based on the structure corresponding to the first database file. The definition of the data type and data size of each field in each table can refer to the structure of the damaged database file. The newly created database file and the first database file have the same file name, such as the example "xxx.db" mentioned above, and can be saved in the same directory.

[0200] Thereafter, the electronic device can insert the obtained data of at least one field (e.g., the key data as listed above) into the newly created database file. For example, the electronic device can insert the key data into the corresponding key field in the newly created key data table by automatically executing an insert statement, to obtain a repaired key data table. For the sake of distinction and illustration, the repaired key data table is referred to as the first data table. Thus, when the user opens the application, the user can still see the key data. For example, the key data of the application "Contacts" is the name and the phone number. If the database file of the application is repaired by the electronic device, when the user opens the application "Contacts", the user can still see the name and the phone number of the previously saved contact.

[0201] Thereafter, the electronic device can also generate other tables related to the application. For example, the electronic device can generate tables related to the user interface of the application "Contacts", such as but not limited to, a table for displaying account information, a table for displaying nickname, a table for displaying avatar, a table for displaying the group to which the contact belongs, a table for speeding up the search (e.g., containing the pinyin for sorting), a table for displaying the ringtone, etc. The electronic device can also generate tables related to third-party applications, such as but not limited to, a table for storing the WeChat ID, the QQ ID, etc. For the sake of brevity, the above tables are not listed one by one. The electronic device can also automatically associate the contact and the phone number in the key data table with other tables, for example, by using the raw_contact_id, so as to display more comprehensive information about the contact through the user interface. Thus, the repaired database file can be obtained. It should be understood that the process of generating other tables related to the application and associating the key data with other tables by the electronic device can refer to the specific implementation in the prior art, and for the sake of brevity, the details are not described herein. It should be understood that the tables generated by the electronic device are not limited to the above tables, and the above tables are only examples and should not be construed as limiting the embodiments of the present application.

[0202] Based on the above repair, the repaired database can be obtained. In the present embodiment, for the sake of distinction and illustration, the repaired database file is referred to as the second database file. It should be understood that the second database file is obtained by repairing the newly created database file. The above first data table can exist in the second database file. Of course, the second database file can also include other tables (which can be referred to above) generated by the electronic device. The embodiments of the present application do not limit this.

[0203] Of course, the electronic device can further obtain data for creating other tables from the master table, and obtain statements and insert statements for creating other tables from the master table, and complete the creation of other tables in the database file. In comparison, it is more time-saving to automatically create other tables, and it is more time-consuming to recreate other tables from the data in the master table.

[0204] The electronic device can even obtain all information in the first database file, such as all table information and data, statements, etc. for creating tables, directly from the master table in the case of determining that the first database file is damaged, and restore the first database file.

[0205] If the user fills in other data at a later time, such as adding new contacts, or supplementing the data of existing contacts, etc., it can be achieved by updating the database file.

[0206] Through experiments, it can be known that if the key data is directly obtained from the backup file, and then the repaired database file is automatically generated, the time consumption can be only about 20 seconds. If the key data is obtained from the master table, and then the repaired database file is generated, the time consumption can also be only about 1 minute.

[0207] It should be understood that the master table described above is only a possible name of a file for saving all data in a database file, and should not constitute any limitation on the present application. The present application does not exclude the possibility of using other files that can be used to save all data in a database file to restore key data.

[0208] It should also be understood that the above is only for the convenience of understanding and description, and the specific process of the embodiments is described by taking the key data as an example. However, this should not constitute any limitation on the present application. The key data is only an example, and the electronic device can obtain the data of at least one field predefined in the damaged database file by the above method process. For the sake of brevity, no further examples are given.

[0209] Based on the above technical solutions, the embodiments of the present application obtain part of the data in the database file, such as key data, and repair part of the data table in the database file, such as the key data table, and then repair the database file in the case of damage. The time consumption for repairing the data table is short, but it is of great significance for repairing the database file. Although the database file is damaged, the user can still obtain part of the data in a short time, without having to repeatedly input, at least without having to repeatedly input all the data originally saved in the database. The subsequent process of repairing the database file is almost imperceptible to the user, and can avoid interference in the process of using the electronic device by the user. Overall, the user experience is greatly improved.

[0210] In order to better understand the embodiments of the present application, the following takes the application of "contact" as an example to illustrate the method provided by the embodiments of the present application.

[0211] The database file of the application "contact" can include a data (data) table, a contacts table and a raw_contacts table. The data table can save all the information of all the created contacts. Each row in the table stores a specific type of information, such as name, phone number, E-mail, address, etc. Each row can be identified by a mime type id (i.e. mimetype_id) field to identify what type of data the row stores. The field refers to the mimetype table, which stores commonly used data types.

[0212] For example, all the information of the contacts in the data table can be saved in columns data1 to data15, and the content saved in each column is different according to the mimetype_id. For example, the row with mimetype_id = 5 can save the phone number, in which the data1 column can save the number; the data2 column can save the number type (such as mobile number, home number or work number, etc.), for example, data2 = 2 represents mobile number; the data6 column can save the number's place of origin. For another example, the row with mimetype_id = 7 can save the name.

[0213] In addition, each row of the data table can also be identified by a raw_contact_id field to identify the data stored in the row corresponds to the id in the raw_contact table. In the data table, multiple rows of data with the same id in the raw_contact_id field can correspond to the same contact. For example, the row with mimetype = 7 records the name of the contact, and the row with mimetype = 5 records the phone number of the contact. By associating the two rows with the same raw_contact_id, the association relationship between the name and the phone number of the same contact can be determined, or in other words, the phone number can be mapped to the name of its contact.

[0214] Table 1 shows an example of the data table in the case that the database file of the "contacts" is not damaged. It should be understood that the data table is a key data table in the database file. The data table shown in Table 1 is a part of the columns of the data table in the database file of the "contacts", and does not show all the columns of the data table. The data table further includes, for example, a hash_id column, an is_read_only column, a data_version column, and data3 to data5 columns, data7 to data15 columns, and the like. For brevity, they are not listed here. Since these columns are not involved in the embodiments of the present application, they are not shown in the table. In addition, the data table shown in Table 1 is only an example, and in some operating systems, the structure of the data table is as shown in Table 1 or can be obtained by equivalent transformation of Table 1; in other operating systems, the data table can also have other structures. The present application does not limit this.

[0215] Table 1

[0216] mimetype_id raw_contact_id data1 data2 …… data6 …… 7 1 Hu Wen 5 1 13******512 2 Zhengzhou, Henan 7 2 Zhang Li 5 2 13******455 2 Zhengzhou, Henan 7 3 Bai Xiaoyan 5 3 18******629 2 Xi'an, Shaanxi 7 4 Ding Ding 5 4 15******012 2 Xi'an, Shaanxi

[0217] It can be seen that each two rows of the raw_contact_id of 1, 2, 3, and 4 can correspond to a contact. For example, the association relationship of the two rows of the raw_contact_id of 1 can determine that the mobile phone number of the contact Hu Wen is 13******512, and the home of the mobile phone number is Zhengzhou, Henan.

[0218] In combination with the above description that the key data of the "contacts" is the name and the phone number, it can be found that the key data in the data table is mainly in the data1 column.

[0219] On the other hand, the name and the phone number are inserted in two rows in the data table, and the contact and the phone number need to be associated through the raw_contact_id, so for the key data table such as Table 1, the key data can include the raw_contact_id, the name, and the phone number. That is, the key fields include the raw_contact_id field and the data1 field.

[0220] In combination with the above embodiments, in the case that Table 1 is not damaged, the key data such as the data of the raw_contact_id field and the data1 field in Table 1 can be directly obtained from Table 1; in the case that Table 1 is damaged, the key data can be obtained from the master table.

[0221] Thereafter, the electronic device can insert the key data into the newly created database to obtain a repaired key data table, and further obtain a repaired database.

[0222] In addition, since the database can be accessed by a third party, there is also a risk of tampering. In order to ensure the authenticity and correctness of the key data in the key data table, the key data can be further verified in combination with the RawContacts table in the database. In this case, the key data table can include the data and the RawContacts table.

[0223] For example, when the application reads the key data from the data table, or after obtaining the key data, it can be determined whether the RawContacts table stores the same data as the raw_contact_id read from the data table. In this example, the raw_contact_id read from the data table includes 1, 2, 3, and 4. If the RawContacts table stores these data, it means that the key data is correct. If the RawContacts table does not store some data, for example, the data of raw_contact_id 1, it means that the data of raw_contact_id 1 can be incorrect.

[0224] Table 2 shows an example of the RawContacts table. It should be understood that the RawContacts table shown in Table 2 is only an example, and only some columns of the table are shown, and not all columns. The RawContacts table shown in Table 2 is a part of the RawContacts table in the database file of "contacts", and not all columns of the RawContacts table are shown. As shown in Table 2, the RawContacts table, for example, the contact_id column, the display_name column, the custom_ringtone column, the send_to_voicemail column, the x_time_contacts column, and the like, although not shown in the table, the RawContacts table can also include the x_last_time_contact column, and the like. For brevity, they are not listed here. In addition, the RawContacts table shown in Table 2 is only an example, and in some operating systems, the structure of the RawContacts table can be as shown in Table 2, or can be equivalent to the transformation of Table 2; in other operating systems, the RawContacts table can also have other structures. This application does not limit this.

[0225] Table 2

[0226] contact_id display_name custom_ringtone send_to_voicemail x_time_contacts 2 Li Li 0 2 3 Xiaoyan 0 3 4 Ding Ding 0 1

[0227] In this case, the raw_contact_id in the data table and the contact_id in the RawContacts table are equal for the same contact. For example, raw_contact_id=2 in Table 1 and contact_id=2 in Table 2 correspond to the same contact. This contact is "Zhang Li", and the display name is "Lili".

[0228] As can be seen, Table 2 only contains data with contact_id = 2, 3, and 4, but not data with contact_id = 1. In this case, the data with raw_contact_id = 1 read from the data table can be considered not critical data. The subsequently generated critical data table may not contain the data corresponding to raw_contact_id = 1.

[0229] It should be understood that the above embodiments are for ease of understanding and explanation only, using "contact person" as an example to illustrate the specific process, but this should not constitute any limitation on this application. This application does not limit the application to which the above database repair method is applicable. Based on the same concept, the above method can be used in different applications to achieve self-repair of the database.

[0230] It should also be understood that the above text, in combination with... Figure 4 The described process is merely one possible implementation of the method provided in this application and should not be construed as limiting the scope of this application. In another implementation, the electronic device can, after obtaining key data (i.e., an example of data in at least one field) from the master table and generating a key data table, back up the key data table as a corrupted database file to obtain a new backup file. Then, it is determined whether the key data in the new backup file is corrupted. Since the key data table recovered from the master table is saved as a new backup file, it can be determined that the key data in the backup file is not corrupted, and then the database file can be repaired according to the process described in steps 4302 and 440 above. The following is in conjunction with... Figure 7 Let me briefly explain the specific process.

[0231] Figure 7 This is a schematic flowchart of a database repair method 700 provided in another embodiment of this application. Figure 7 As shown, the method 700 may include steps 710 to 770.

[0232] In step 710, it is determined that the database file is corrupted.

[0233] In step 720, the corrupted database file is backed up to obtain a backup file.

[0234] In step 730, it is determined whether the critical data in the backup file is corrupted.

[0235] In step 740, if the key data in the backup file is not damaged, the key data is obtained from the backup file.

[0236] It should be understood that the specific processes of steps 710 to 740 can refer to the relevant descriptions of steps 410, 420, 4301 and 4302 in method 400 above, which will not be repeated here for brevity.

[0237] For the sake of distinction, the damaged database file mentioned in step 710 is referred to as the first database file. It should be noted that when the electronic device first performs step 720 after determining the first database file in step 710, the backup file is obtained from the damaged database file, which is different from the backup file in step 760. For the sake of distinction and understanding, the backup file obtained when step 720 is first performed is referred to as backup file 1, and the backup file obtained by performing step 760 is referred to as backup file 2. It can be understood that the backup file 1 is a backup file obtained based on the damaged first database file.

[0238] In step 750, if the key data in the backup file (i.e. backup file 1) is damaged, the key data is obtained from the master table.

[0239] In step 760, a key data table is generated based on the key data obtained from the master table, and the key data table is backed up to obtain a backup file (i.e. backup file 2).

[0240] That is, the key data table generated from the key data obtained from the master table can also be backed up to the directory of the backup file 1 obtained in step 720, and saved as a new backup file. It should be noted that before obtaining the backup file 2 in step 760, the backup file 1 has been deleted because it is determined in step 730 that the key data in the backup file 1 is damaged. In other words, the backup file 2 replaces the backup file 1.

[0241] In another implementation, the key data table generated from the master table obtaining the key data can be understood as a damaged database file. It should be noted that the damaged database file obtained here is not the first database file mentioned in step 710, but the damaged database file recovered from the master table. The electronic device can again perform step 720 to backup the damaged database file, obtain a backup file, and delete the damaged database file. Thus, the old backup file is replaced by the new backup file. Although not shown in the figure, it can be understood that the above two implementation manners can achieve the same purpose, that is, to obtain a new backup file (i.e., backup file 2). The present application does not limit the specific implementation of obtaining a new backup file.

[0242] Thereafter, the electronic device can repeatedly perform step 730, and in the case that the backup file is not damaged, continue to perform step 740 to obtain the key data from the backup file.

[0243] It can be understood that when the electronic device performs step 730 and step 740 this time, the backup file is backup file 2.

[0244] In step 770, the key data is inserted into the newly created database file to obtain a repaired database file.

[0245] The repaired database file can be denoted as a second database file. The second database file and the first database file can have the same file name and the same format. In other words, the second database file replaces the first database file.

[0246] It should be understood that the specific process of step 770 can refer to the related description of step 440 in method 400 above, and for the sake of brevity, it will not be repeated here.

[0247] It should also be understood that steps 730 to 760 are described in combination with whether the key data in the backup file is damaged. Therefore, it is not necessary to perform all of steps 730 to 760.

[0248] It should also be understood that the above only serves to facilitate understanding and description, and the specific process of the embodiment is described by taking obtaining key data as an example. However, this should not constitute any limitation on the present application. The key data is only an example, and the electronic device can obtain the data of at least one field in the damaged database file by the above method process. For the sake of brevity, no further examples are given here.

[0249] Based on the technical solution, in the case of database file damage, part of the data, such as key data, is obtained by the electronic device, and part of the data table, such as the key data table, in the database file is repaired, so as to repair the database file. The time consumption of repairing the data table is short, but it is of great significance to the repair of the database file. Although the database file is damaged, the user can still obtain part of the data in a short time without repeated input, at least without repeated input of all the data originally saved in the database. The subsequent process of repairing the database file is almost imperceptible to the user, and interference in the use of the electronic device by the user can be avoided. Overall, the user experience is greatly improved.

[0250] A possible scenario is that the databases of various applications are detected when the system is idle. When it is detected that the database file of an application is damaged, the key data can be obtained by executing the method in the method 400 or the method 700, and then the key data is inserted into the newly created database file, so as to realize the self-repair of the database file. The repair process is short, and the user is not aware of the entire repair process.

[0251] It should be understood that each step of the above method can be completed by integrated logic circuits of hardware in the processor or instructions in the form of software. The steps of the method disclosed in combination with the embodiments of the present application can be directly embodied as execution completed by a hardware processor, or executed by a combination of hardware and software modules in the processor. The software module can be located in a mature storage medium in the field, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and combines the hardware to complete the steps of the above method. To avoid repetition, it will not be described in detail here.

[0252] The present application also provides a database repair device. The repair device can include various modules or units for executing the processes of the above method embodiments. It should be understood that these modules or units can realize corresponding functions by executing computer programs (also known as codes or instructions). The computer program can be provided by an application, or the computer program can be provided by an electronic device installed with the application. The present application does not limit this.

[0253] The present application also provides an electronic device, which is installed with an application that can store data through a corresponding database. The electronic device can include a memory and a processor. The memory can be used to store computer programs, and the processor can be used to call the computer programs in the memory to make the electronic device execute Figure 4 or Figure 7 the method of any one of the embodiments shown.

[0254] The present application also provides a computer program product, comprising a computer program (also referred to as code or instructions), which, when executed by an electronic device, causes the electronic device to perform the method of any one of the embodiments shown in the specification. Figure 4 or Figure 7 the method of any one of the embodiments shown in the specification.

[0255] The present application also provides a computer readable storage medium storing a computer program (also referred to as code or instructions). When the computer program is executed, it causes an electronic device to perform the method of any one of the embodiments shown in the specification. Figure 4 or Figure 7 the method of any one of the embodiments shown in the specification.

[0256] It should be understood that the processor in the embodiments of the present application can be an integrated circuit chip with signal processing capability. In the implementation process, each step of the method embodiments described above can be completed by integrated logic circuits or instructions in the form of software in the processor. The processor described above can be a general processor, a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. Each method, step and logic block diagram disclosed in the embodiments of the present application can be implemented or executed. The general processor can be a microprocessor or the processor can be any conventional processor. The steps of the method disclosed in conjunction with the embodiments of the present application can be directly embodied as a hardware code processor for execution, or a combination of hardware and software modules in the code processor for execution. The software module can be located in a random access memory, a flash memory, a read only memory, a programmable read only memory or an electrically erasable programmable memory, a register or other mature storage medium in the art. The storage medium is located in the memory, and the processor reads the information in the memory and combines the hardware to complete the steps of the above method.

[0257] It should also be understood that the memory in the embodiments of the present application can be a volatile memory or a nonvolatile memory, or can include both volatile and nonvolatile memory. Among them, the nonvolatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically EPROM (EEPROM) or flash memory. The volatile memory can be random access memory (RAM) used as an external cache. By way of example, and not limitation, many forms of RAM can be used, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchlink DRAM (SLDRAM), and direct rambus RAM (DRAM). It should be noted that the memory of the system and method described herein is intended to include, but not be limited to, these and any other suitable types of memory.

[0258] The terms "unit", "module" and the like used in the specification can be used to represent a computer-related entity, hardware, firmware, a combination of hardware and software, software, or software in execution.

[0259] Those of skill would further appreciate that the various illustrative logical blocks, modules, circuits, and steps described in connection with the embodiments disclosed herein can be implemented as electronic hardware, computer software, or combinations of both. The choice of hardware or software, or combinations of both, would be dependent on the specific application and design constraints imposed on the overall system. Skilled artisans can implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application. In several embodiments provided in the present application, it will be apparent that the disclosed devices, apparatuses, and methods can be implemented in other ways. For example, the described device embodiments are merely illustrative, and the division into units is merely a logical function division, and actual implementation can have another division, for example, multiple units or components can be combined or integrated into another system, or some features can be omitted or not implemented. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some interfaces, devices or units, and can be electrical, mechanical or other forms.

[0260] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, i.e. can be located in one place or can be distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiments.

[0261] In addition, the functional units in each embodiment of the present application can be integrated into one processing unit, or each unit can be physically present separately, or two or more units can be integrated into one unit.

[0262] In the above embodiments, the functions of the various functional units can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented in software, the functions can be implemented in the form of one or more computer programs that run on a computer. When the computer programs are run, the processes or functions described in the embodiments of the present application are wholly or partially generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable apparatus. The computer programs can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer programs can be transmitted from one website, computer, server or data center to another website, computer, server or data center through wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.) manner. The computer-readable storage medium can be any available medium accessible by a computer or a data storage device such as a server, data center, etc. that includes one or more available media. The available media can be a magnetic medium (for example, floppy disk, hard disk, magnetic tape), an optical medium (for example, DVD), or a semiconductor medium (for example, solid state disk (SSD)) and the like.

[0263] The functions, if implemented in the form of software functional units and sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the present application essentially or the part that contributes to the prior art or part of the technical solutions can be embodied in the form of a software product, which is stored in a storage medium and includes a number of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods described in the embodiments of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various media that can store program codes.

[0264] 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 can easily think of changes or replacements within the technical scope disclosed in the present application, which should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A method of repairing a database, characterized by, Comprise: In the case of damage to a first database file, backing up the first database file to obtain a backup file of the first database file; Obtaining data of at least one field in the first database file; The at least one field is predefined by an application; the data of the at least one field is part of the data in the first database file; Based on the data of the at least one field, a first data table is generated, and the first data table exists in a second database file obtained by repairing; The obtaining of the data of the at least one field in the first database file comprises: In the case of damage to a second data table in the backup file of the first database file, obtaining the data of the at least one field from a main table; The second data table is a table for storing the data of the at least one field; the main table stores statements and data used to generate the first database file.

2. The method of claim 1, wherein, The obtaining of the data of the at least one field in the first database file comprises: In the case that the second data table is not damaged, obtaining the data of the at least one field from the second data table.

3. The method of claim 1 or 2, wherein, The second database file is a database file created and repaired in the case of damage to the first database file.

4. The method of claim 3, wherein, The second database file has the same file name and structure as the first database file.

5. The method of any one of claims 1-2, 4, wherein, The method further comprises: Deleting the first database file.

6. The method of any one of claims 1-2, 4, wherein, The database is a SQLite database with a light structure.

7. The method of any one of claims 1-2, 4, wherein, A computer program for implementing the method is provided by an application.

8. The method of any one of claims 1-2, 4, wherein, A computer program for implementing the method is provided by an electronic device installing the application.

9. An electronic device, comprising: The electronic device is installed with an application, and the application stores data through a corresponding database; The electronic device comprises: A memory for storing a computer program; A processor for calling the computer program in the memory to enable the electronic device to execute the method in any one of claims 1 to 8.

10. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to enable the electronic device to execute the method in any one of claims 1 to 8.

Citation Information

Patent Citations

  • Method and system for synchronizing data base

    CN101038591A

  • Database restoration method and device

    CN107193871A

  • Method and apparatus for data recovery

    US6970890B1

Cited By

  • Database repair method and electronic device

    WO2022057567A1