SQL (Structured Query Language) statement restoration method based on database operation and related device

By generating an SQL statement tree and parsing and correcting syntax errors, and combining operation logs and database restore commands, high-precision restoration of multiple SQL statement operations in a relational database is achieved, solving the problem that existing technologies cannot restore specific SQL statements individually.

CN120994690APending Publication Date: 2025-11-21HANG ZHOU LING XIN SHU KE XIN XI JI SHU YOU XIAN GONG SI
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511108783.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-08
Publication Date
2025-11-21

AI Technical Summary

Technical Problem

Existing technologies cannot individually restore specific statements among multiple SQL statements in relational database operations, especially when the execution result of a certain SQL statement does not meet expectations, it is impossible to restore only that statement and its related statements.

Method used

By generating an SQL statement tree, parsing and correcting syntax errors, generating an operation log, and matching the SQL statement to be restored in the database restore command with the statement tree, the restoration of the specified SQL statement can be achieved.

Benefits of technology

It enables high-precision restoration of a specified SQL statement after multiple SQL statement operations, ensuring clear logical relationships in database operations and facilitating the subsequent restoration process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120994690A_ABST
    Figure CN120994690A_ABST
Patent Text Reader

Abstract

The invention discloses a database operation-based SQL (Structured Query Language) statement restoration method and a related device, and the method comprises the following steps: a relational database performs data operation processing according to at least one SQL statement contained in an SQL operation instruction sent by a client, and feeds back a data operation result to the client; the relational database receives a database restoration instruction fed back by the client based on the data operation result, and obtains a to-be-restored SQL statement contained in the database restoration instruction by analyzing the database restoration instruction; the relational database obtains a database operation node corresponding to a to-be-restored SQL statement contained in the database restoration instruction; and the relational database carries out restoration processing on the database operation by utilizing the to-be-restored SQL statement contained in the database restoration instruction based on the database operation node. In the embodiment of the invention, the restoration of the SQL statement after the database operation is realized, and the restoration precision is relatively high.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of database technology, and in particular to a method and related apparatus for restoring SQL statements based on database operations. Background Technology

[0002] Operations on relational databases are generally performed using SQL statements. After performing operations on a relational database using SQL statements, if the results are not as expected, these operations need to be undone. This can be achieved directly through SQL restore using backups. However, if an operation command contains multiple SQL statements, and the execution result of one of the SQL statements is not as expected, then it is necessary to restore all the SQL statements in the entire operation command. It is not possible to restore only the SQL statement with the unexpected execution result and its related SQL statements individually. Summary of the Invention

[0003] The purpose of this invention is to overcome the shortcomings of the prior art. This invention provides a method and related apparatus for restoring SQL statements based on database operations, which realizes the restoration of a specified SQL statement after database operations on multiple SQL statements, and has high restoration accuracy.

[0004] To address the aforementioned technical problems, embodiments of the present invention provide a method for restoring SQL statements based on database operations, the method comprising:

[0005] The relational database performs data manipulation based on at least one SQL statement contained in the SQL operation instruction sent by the client, and feeds back the data manipulation results to the client.

[0006] The relational database receives a database restore command from the client based on the data operation result, and obtains the SQL statement to be restored contained in the database restore command by parsing the database restore command.

[0007] The relational database obtains the database operation node corresponding to the SQL statement to be restored contained in the database restoration instruction;

[0008] The relational database uses the database operation node to perform database operation restoration processing using the SQL statement to be restored contained in the database restoration instruction.

[0009] Optionally, the relational database performs data manipulation based on at least one SQL statement contained in the SQL operation instruction sent by the client, including:

[0010] The relational database extracts at least one SQL statement contained in the SQL operation instruction and generates an SQL statement tree corresponding to at least one SQL statement according to the tree relationship, wherein the tree relationship is with the relational database before execution as the root node of the tree and the execution order of at least one SQL statement as the child nodes of the tree.

[0011] Each SQL statement in the SQL statement tree is parsed to obtain the parsing result corresponding to each SQL statement in the SQL statement tree;

[0012] The relational database performs database operations based on the parsing results of each SQL statement in the SQL statement tree, according to the logical relationship of the tree structure.

[0013] Optionally, the step of parsing each SQL statement in the SQL statement tree to obtain the parsing result corresponding to each SQL statement in the SQL statement tree includes:

[0014] The syntax of each SQL statement in the SQL statement tree is checked and processed, and the SQL statements with syntax errors are corrected according to semantics to obtain each SQL statement in the SQL statement tree after correction.

[0015] Each SQL statement in the corrected SQL statement tree is transformed according to the recognition rules of the relational database to form the parsing result corresponding to each SQL statement in the SQL statement tree.

[0016] Optionally, when the relational database performs database operations based on the parsing results corresponding to each SQL statement in the SQL statement tree according to the logical relationship of the tree structure, it further includes:

[0017] When performing database operations according to the logical relationship of the tree structure, for each SQL statement database operation, an SQL statement operation log corresponding to the SQL statement is generated. The SQL statement operation log contains backups of the data corresponding to the operation target data of the corresponding SQL statement before the operation was performed.

[0018] The SQL statement operation log is then associated with and stored in relation to the child nodes corresponding to the tree relationship.

[0019] Optionally, obtaining the SQL statement to be restored contained in the database restore instruction by parsing the database restore instruction includes:

[0020] The relational database parses the database restore command and extracts the SQL statement to be restored contained in the database restore command through the parsing result.

[0021] Optionally, the relational database obtains the database operation node corresponding to the SQL statement to be restored contained in the database restore instruction, including:

[0022] The relational database uses the SQL statement to be restored contained in the database restoration instruction to match the SQL statement corresponding to each node in the SQL statement tree to obtain the matching result;

[0023] The child node corresponding to the SQL statement that matches the SQL statement to be restored in the matching results is taken as the database operation node corresponding to the SQL statement to be restored.

[0024] Optionally, the relational database performs database operation restoration processing based on the database operation node using the SQL statement to be restored contained in the database restoration instruction, including:

[0025] The relational database obtains the corresponding SQL statement operation logs based on the child nodes corresponding to the tree relationship of the database operation nodes.

[0026] The database operation is restored using the SQL statement to be restored contained in the database restore command and the SQL statement operation log.

[0027] In addition, embodiments of the present invention also provide an SQL statement restoration device based on database operations, the device comprising:

[0028] Data manipulation module: Used by relational database to perform data manipulation based on at least one SQL statement contained in the SQL operation instruction sent by the client, and to feed back the data manipulation results to the client;

[0029] Instruction receiving module: used to receive the database restore instruction from the client based on the data operation result, and to obtain the SQL statement to be restored contained in the database restore instruction by parsing the database restore instruction;

[0030] The acquisition module is used by the relational database to obtain the database operation node corresponding to the SQL statement to be restored contained in the database restoration instruction.

[0031] The restore operation module is used by the relational database to restore the database operation based on the database operation node using the SQL statement to be restored contained in the database restore instruction.

[0032] In addition, embodiments of the present invention also provide an electronic device, including a processor and a memory, wherein the processor runs a computer program or code stored in the memory to implement the SQL statement restoration method as described in any of the above.

[0033] In addition, embodiments of the present invention also provide a computer-readable storage medium for storing a computer program or code, which, when executed by a processor, implements the SQL statement restoration method as described in any of the above-described embodiments.

[0034] In this embodiment of the invention, after the relational database receives a database restore instruction, it parses and obtains the SQL statement to be restored contained in the database restore instruction; then it obtains the database operation node corresponding to the SQL statement to be restored contained in the database restore instruction; finally, it uses the database operation node to restore the database operation using the SQL statement to be restored contained in the database restore instruction; thus, it realizes the restoration of a specified SQL statement after multiple SQL statements have been used to restore the database, and has high restoration accuracy. Attached Figure Description

[0035] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0036] Figure 1 This is a flowchart illustrating the SQL statement restoration method based on database operations in an embodiment of the present invention.

[0037] Figure 2 This is a flowchart illustrating a method for restoring SQL statements based on database operations according to another embodiment of the present invention.

[0038] Figure 3 This is a schematic diagram of the structural composition of the SQL statement restoration device based on database operations in an embodiment of the present invention;

[0039] Figure 4 This is a schematic diagram of the structural composition of the electronic device in an embodiment of the present invention. Detailed Implementation

[0040] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0041] Example 1, please refer to Figure 1 , Figure 1 This is a flowchart illustrating the SQL statement restoration method based on database operations in an embodiment of the present invention.

[0042] like Figure 1 As shown, a method for restoring SQL statements based on database operations is provided, the method comprising:

[0043] S101: The relational database performs data manipulation based on at least one SQL statement contained in the SQL operation instruction sent by the client, and feeds back the data manipulation result to the client;

[0044] In a specific implementation of this invention, the relational database performs data operation processing based on at least one SQL statement contained in the SQL operation instruction sent by the client. This includes: the relational database extracts at least one SQL statement contained in the SQL operation instruction and generates an SQL statement tree corresponding to at least one SQL statement based on a tree-like relationship, wherein the tree-like relationship has the relational database before execution as the root node of the tree and the execution order of the at least one SQL statement as the child nodes of the tree; each SQL statement in the SQL statement tree is parsed to obtain a parsing result corresponding to each SQL statement in the SQL statement tree; and the relational database performs database operation processing according to the logical relationship of the tree-like relationship based on the parsing result corresponding to each SQL statement in the SQL statement tree.

[0045] Furthermore, the step of parsing each SQL statement in the SQL statement tree to obtain the parsing result corresponding to each SQL statement in the SQL statement tree includes: checking the syntax of each SQL statement in the SQL statement tree, and correcting SQL statements with syntax errors according to semantics to obtain each SQL statement in the SQL statement tree after correction; and converting each SQL statement in the SQL statement tree after correction according to the recognition rules of the relational database to form the parsing result corresponding to each SQL statement in the SQL statement tree.

[0046] Furthermore, when the relational database performs database operations according to the logical relationship of the tree relation based on the parsing result corresponding to each SQL statement in the SQL statement tree, it further includes: when performing database operations according to the logical relationship of the tree relation, for each SQL statement database operation, generating an SQL statement operation log corresponding to the SQL statement, wherein the SQL statement operation log backs up the data corresponding to the operation target data of the corresponding SQL statement before it is operated; and associating the SQL statement operation log with the child nodes corresponding to the tree relation for storage.

[0047] Specifically, relational databases need to execute database operations based on SQL operation instructions sent by the client. That is, an SQL operation instruction generally contains at least one SQL statement, and the relationship between these SQL statements may be parallel or have a tree-like relationship. If it is a parallel relationship, the database operations executed between these parallel SQL statements are independent of each other. If it is a tree-like relationship, the execution of the SQL statement of the parent node in the tree-like relationship is related to the SQL statements of its child nodes; that is, the SQL statement of the parent node must be executed before the SQL statement of the child node can be executed.

[0048] After receiving an SQL operation instruction, the relational database parses the instruction to obtain at least one SQL statement. It then generates an SQL statement tree corresponding to this instruction, using a tree structure where the tree is rooted at the state before the relational database execution and the execution order of the at least one SQL statement is used as child nodes. Each SQL statement in the tree is then parsed to obtain its corresponding parsing result. Finally, the relational database executes the database operation based on the parsing results of each SQL statement in the tree, following the logical relationships within the tree structure. This allows for database operations on instructions containing at least one SQL statement, clearly defining the logical relationships between these statements and facilitating the subsequent reconstruction of a single SQL statement without requiring the reconstruction of all SQL statements in the instruction.

[0049] In parsing SQL statements, the syntax of each SQL statement in the SQL statement tree needs to be checked first to obtain the detection results. If there are syntax errors in the detection results, the SQL statements with syntax errors will be corrected according to semantics to obtain each SQL statement in the corrected SQL statement tree. Finally, each SQL statement in the corrected SQL statement tree will be transformed according to the recognition rules of relational databases to form the parsing result corresponding to each SQL statement in the SQL statement tree.

[0050] When performing operations, that is, when performing database operations according to the logical relationship of the tree structure, for each SQL statement database operation, an SQL statement operation log is generated corresponding to the SQL statement. The SQL statement operation log contains backups of the target data of the corresponding SQL statement before the operation was performed. Then, the SQL statement operation log is associated with the child nodes corresponding to the tree structure and stored.

[0051] S102: The relational database receives a database restore instruction from the client based on the data operation result, and obtains the SQL statement to be restored contained in the database restore instruction by parsing the database restore instruction;

[0052] In a specific implementation of the present invention, obtaining the SQL statement to be restored contained in the database restoration instruction by parsing the database restoration instruction includes: the relational database parses the database restoration instruction and extracts the SQL statement to be restored contained in the database restoration instruction through the parsing result.

[0053] Specifically, the relational database will receive the database restore command sent by the client, which is generated based on the data operation results. Then, it will parse the database restore command to obtain the parsing result. Finally, it will use the parsing result to extract the SQL statement to be restored contained in the database restore command.

[0054] S103: The relational database obtains the database operation node corresponding to the SQL statement to be restored contained in the database restoration instruction;

[0055] In a specific implementation of the present invention, the relational database obtains the database operation node corresponding to the SQL statement to be restored contained in the database restoration instruction, including: the relational database performs matching processing on the SQL statement to be restored contained in the database restoration instruction and the SQL statement corresponding to each node in the SQL statement tree to obtain a matching result; and takes the child node corresponding to the SQL statement that matches the SQL statement to be restored in the matching result as the database operation node corresponding to the SQL statement to be restored.

[0056] Specifically, at this point, the relational database will use the SQL statement to be restored contained in the database restore instruction to match the SQL statement corresponding to each node in the SQL statement tree, thereby obtaining the matching result; then the child node corresponding to the SQL statement that matches the SQL statement to be restored in the matching result can be used as the database operation node corresponding to the SQL statement to be restored.

[0057] S104: The relational database performs database operation restoration processing based on the database operation node using the SQL statement to be restored contained in the database restoration instruction.

[0058] In a specific implementation of the present invention, the relational database performs database operation restoration processing based on the database operation node using the SQL statement to be restored contained in the database restoration instruction, including: the relational database obtains the corresponding SQL statement operation log based on the child nodes corresponding to the tree relationship of the database operation node; and performs database operation restoration processing using the SQL statement to be restored contained in the database restoration instruction and the SQL statement operation log.

[0059] Specifically, relational databases will obtain the corresponding SQL statement operation logs based on the child nodes of the tree relationship according to the database operation nodes; then, they will use the SQL statement to be restored and the SQL statement operation logs contained in the database restore command to restore the database operations.

[0060] In this embodiment of the invention, after the relational database receives a database restore instruction, it parses and obtains the SQL statement to be restored contained in the database restore instruction; then it obtains the database operation node corresponding to the SQL statement to be restored contained in the database restore instruction; finally, it uses the database operation node to restore the database operation using the SQL statement to be restored contained in the database restore instruction; thus, it realizes the restoration of a specified SQL statement after multiple SQL statements have been used to restore the database, and has high restoration accuracy.

[0061] Example 2, please refer to Figure 2 , Figure 2This is a flowchart illustrating a SQL statement restoration method based on database operations according to another embodiment of the present invention.

[0062] like Figure 2 As shown, a method for restoring SQL statements based on database operations is provided, the method comprising:

[0063] S201: The relational database performs data manipulation based on at least one SQL statement contained in the SQL operation instruction sent by the client, and feeds back the data manipulation result to the client;

[0064] S202: The relational database receives a database restore instruction from the client based on the data operation result, and obtains the SQL statement to be restored contained in the database restore instruction by parsing the database restore instruction;

[0065] S203: The relational database uses the SQL statement to be restored contained in the database restoration instruction to match the SQL statement corresponding to each node in the SQL statement tree to obtain the matching result;

[0066] S204: The child node corresponding to the SQL statement that matches the SQL statement to be restored in the matching result is taken as the database operation node corresponding to the SQL statement to be restored;

[0067] S205: The relational database obtains the corresponding SQL statement operation log based on the child nodes corresponding to the tree relationship of the database operation node;

[0068] S206: Perform database operation restoration using the SQL statement to be restored contained in the database restoration instruction and the SQL statement operation log.

[0069] For details on the specific implementation of this embodiment, please refer to the above embodiments, which will not be repeated here.

[0070] Example 3, please refer to Figure 3 , Figure 3 This is a schematic diagram of the structure of the SQL statement restoration device based on database operations in an embodiment of the present invention.

[0071] like Figure 3 As shown, an SQL statement restoration device based on database operations includes:

[0072] Data operation module 301: Used for relational databases to perform data operation processing based on at least one SQL statement contained in the SQL operation instruction sent by the client, and to feed back the data operation results to the client;

[0073] In a specific implementation of this invention, the relational database performs data operation processing based on at least one SQL statement contained in the SQL operation instruction sent by the client. This includes: the relational database extracts at least one SQL statement contained in the SQL operation instruction and generates an SQL statement tree corresponding to at least one SQL statement based on a tree-like relationship, wherein the tree-like relationship has the relational database before execution as the root node of the tree and the execution order of the at least one SQL statement as the child nodes of the tree; each SQL statement in the SQL statement tree is parsed to obtain a parsing result corresponding to each SQL statement in the SQL statement tree; and the relational database performs database operation processing according to the logical relationship of the tree-like relationship based on the parsing result corresponding to each SQL statement in the SQL statement tree.

[0074] Furthermore, the step of parsing each SQL statement in the SQL statement tree to obtain the parsing result corresponding to each SQL statement in the SQL statement tree includes: checking the syntax of each SQL statement in the SQL statement tree, and correcting SQL statements with syntax errors according to semantics to obtain each SQL statement in the SQL statement tree after correction; and converting each SQL statement in the SQL statement tree after correction according to the recognition rules of the relational database to form the parsing result corresponding to each SQL statement in the SQL statement tree.

[0075] Furthermore, when the relational database performs database operations according to the logical relationship of the tree relation based on the parsing result corresponding to each SQL statement in the SQL statement tree, it further includes: when performing database operations according to the logical relationship of the tree relation, for each SQL statement database operation, generating an SQL statement operation log corresponding to the SQL statement, wherein the SQL statement operation log backs up the data corresponding to the operation target data of the corresponding SQL statement before it is operated; and associating the SQL statement operation log with the child nodes corresponding to the tree relation for storage.

[0076] Specifically, relational databases need to execute database operations based on SQL operation instructions sent by the client. That is, an SQL operation instruction generally contains at least one SQL statement, and the relationship between these SQL statements may be parallel or have a tree-like relationship. If it is a parallel relationship, the database operations executed between these parallel SQL statements are independent of each other. If it is a tree-like relationship, the execution of the SQL statement of the parent node in the tree-like relationship is related to the SQL statements of its child nodes; that is, the SQL statement of the parent node must be executed before the SQL statement of the child node can be executed.

[0077] After receiving an SQL operation instruction, the relational database parses the instruction to obtain at least one SQL statement. It then generates an SQL statement tree corresponding to this instruction, using a tree structure where the tree is rooted at the state before the relational database execution and the execution order of the at least one SQL statement is used as child nodes. Each SQL statement in the tree is then parsed to obtain its corresponding parsing result. Finally, the relational database executes the database operation based on the parsing results of each SQL statement in the tree, following the logical relationships within the tree structure. This allows for database operations on instructions containing at least one SQL statement, clearly defining the logical relationships between these statements and facilitating the subsequent reconstruction of a single SQL statement without requiring the reconstruction of all SQL statements in the instruction.

[0078] In parsing SQL statements, the syntax of each SQL statement in the SQL statement tree needs to be checked first to obtain the detection results. If there are syntax errors in the detection results, the SQL statements with syntax errors will be corrected according to semantics to obtain each SQL statement in the corrected SQL statement tree. Finally, each SQL statement in the corrected SQL statement tree will be transformed according to the recognition rules of relational databases to form the parsing result corresponding to each SQL statement in the SQL statement tree.

[0079] When performing operations, that is, when performing database operations according to the logical relationship of the tree structure, for each SQL statement database operation, an SQL statement operation log is generated corresponding to the SQL statement. The SQL statement operation log contains backups of the target data of the corresponding SQL statement before the operation was performed. Then, the SQL statement operation log is associated with the child nodes corresponding to the tree structure and stored.

[0080] Instruction receiving module 302: Used for the relational database to receive the database restore instruction from the client based on the data operation result, and to obtain the SQL statement to be restored contained in the database restore instruction by parsing the database restore instruction;

[0081] In a specific implementation of the present invention, obtaining the SQL statement to be restored contained in the database restoration instruction by parsing the database restoration instruction includes: the relational database parses the database restoration instruction and extracts the SQL statement to be restored contained in the database restoration instruction through the parsing result.

[0082] Specifically, the relational database will receive the database restore command sent by the client, which is generated based on the data operation results. Then, it will parse the database restore command to obtain the parsing result. Finally, it will use the parsing result to extract the SQL statement to be restored contained in the database restore command.

[0083] Module 303: Used for the relational database to obtain the database operation node corresponding to the SQL statement to be restored contained in the database restoration instruction;

[0084] In a specific implementation of the present invention, the relational database obtains the database operation node corresponding to the SQL statement to be restored contained in the database restoration instruction, including: the relational database performs matching processing on the SQL statement to be restored contained in the database restoration instruction and the SQL statement corresponding to each node in the SQL statement tree to obtain a matching result; and takes the child node corresponding to the SQL statement that matches the SQL statement to be restored in the matching result as the database operation node corresponding to the SQL statement to be restored.

[0085] Specifically, at this point, the relational database will use the SQL statement to be restored contained in the database restore instruction to match the SQL statement corresponding to each node in the SQL statement tree, thereby obtaining the matching result; then the child node corresponding to the SQL statement that matches the SQL statement to be restored in the matching result can be used as the database operation node corresponding to the SQL statement to be restored.

[0086] Restoration operation module 304: used by the relational database to restore the database operation based on the database operation node using the SQL statement to be restored contained in the database restoration instruction.

[0087] In a specific implementation of the present invention, the relational database performs database operation restoration processing based on the database operation node using the SQL statement to be restored contained in the database restoration instruction, including: the relational database obtains the corresponding SQL statement operation log based on the child nodes corresponding to the tree relationship of the database operation node; and performs database operation restoration processing using the SQL statement to be restored contained in the database restoration instruction and the SQL statement operation log.

[0088] Specifically, relational databases will obtain the corresponding SQL statement operation logs based on the child nodes of the tree relationship according to the database operation nodes; then, they will use the SQL statement to be restored and the SQL statement operation logs contained in the database restore command to restore the database operations.

[0089] In this embodiment of the invention, after the relational database receives a database restore instruction, it parses and obtains the SQL statement to be restored contained in the database restore instruction; then it obtains the database operation node corresponding to the SQL statement to be restored contained in the database restore instruction; finally, it uses the database operation node to restore the database operation using the SQL statement to be restored contained in the database restore instruction; thus, it realizes the restoration of a specified SQL statement after multiple SQL statements have been used to restore the database, and has high restoration accuracy.

[0090] This invention provides a computer-readable storage medium storing a computer program. When executed by a processor, this program implements the SQL statement restoration method of any of the above embodiments. The computer-readable storage medium includes, but is not limited to, any type of disk (including floppy disk, hard disk, optical disk, CD-ROM, and magneto-optical disk), ROM (Read-Only Memory), RAM (Random Access Memory), EPROM (Erasable Programmable Read-Only Memory), EEPROM (Electrically Erasable Programmable Read-Only Memory), flash memory, magnetic cards, or optical cards. In other words, the storage device includes any medium that stores or transmits information in a readable form by a device (e.g., a computer, a mobile phone), and can be a read-only memory, a disk, or an optical disk, etc.

[0091] This invention also provides a computer application running on a computer, which is used to execute the SQL statement restoration method of any of the above embodiments.

[0092] also, Figure 4 This is a schematic diagram of the structural composition of the electronic device in an embodiment of the present invention.

[0093] This invention also provides an electronic device, such as... Figure 4 As shown. The electronic device includes components such as a processor 402, a memory 403, an input unit 404, and a display unit 405. Those skilled in the art will understand that... Figure 4 The structural components of the illustrated electronic device do not constitute a limitation on all devices and may include more or fewer components than illustrated, or combine certain components. Memory 403 can be used to store application program 401 and various functional modules. Processor 402 runs application program 401 stored in memory 403, thereby performing various functional applications and data processing of the device. Memory can be internal memory or external memory, or both. Internal memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), flash memory, or random access memory. External memory may include hard disks, floppy disks, ZIP disks, USB flash drives, magnetic tapes, etc. The memory disclosed in this invention includes, but is not limited to, these types of memory. The memory disclosed in this invention is only an example and not a limitation.

[0094] Input unit 404 is used to receive signal input and user-input keywords. Input unit 404 may include a touch panel and other input devices. The touch panel can collect user touch operations on or near it (such as operations performed by the user using a finger, stylus, or any suitable object or accessory on or near the touch panel) and drive the corresponding connection device according to a pre-set program; other input devices may include, but are not limited to, one or more of physical keyboards, function keys (such as play control buttons, power buttons, etc.), trackballs, mice, joysticks, etc. Display unit 405 can be used to display user-input information or information provided to the user, as well as various menus of the terminal device. Display unit 405 may be in the form of a liquid crystal display, organic light-emitting diode, etc. Processor 402 is the control center of the terminal device, connecting various parts of the entire device through various interfaces and lines, performing various functions and processing data by running or executing software programs and / or modules stored in memory 403, and calling data stored in memory.

[0095] As one embodiment, the electronic device includes: one or more processors 402, a memory 403, and one or more application programs 401, wherein the one or more application programs 401 are stored in the memory 403 and configured to be executed by the one or more processors 402, and the one or more application programs 401 are configured to execute the SQL statement restoration method corresponding to any of the embodiments described above.

[0096] In this embodiment of the invention, after the relational database receives a database restore instruction, it parses and obtains the SQL statement to be restored contained in the database restore instruction; then it obtains the database operation node corresponding to the SQL statement to be restored contained in the database restore instruction; finally, it uses the database operation node to restore the database operation using the SQL statement to be restored contained in the database restore instruction; thus, it realizes the restoration of a specified SQL statement after multiple SQL statements have been used to restore the database, and has high restoration accuracy.

[0097] Furthermore, the above provides a detailed description of the SQL statement restoration method and related apparatus based on database operations provided by the embodiments of the present invention. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.

Claims

1. A method for restoring SQL statements based on database operations, characterized by, The method comprises: The relational database performs data operation processing according to at least one SQL statement contained in the SQL operation instruction sent by the client, and feeds back the data operation result to the client; The relational database receives the database restoration instruction fed back by the client based on the data operation result, and obtains the to-be-restored SQL statement contained in the database restoration instruction by analyzing the database restoration instruction; The relational database obtains the database operation node corresponding to the to-be-restored SQL statement contained in the database restoration instruction; The relational database performs restoration processing on the database operation based on the database operation node and the to-be-restored SQL statement contained in the database restoration instruction.

2. The SQL statement restoration method of claim 1, wherein, The relational database performs data operation processing according to at least one SQL statement contained in the SQL operation instruction sent by the client, comprising: The relational database extracts at least one SQL statement contained in the SQL operation instruction, and generates an SQL statement tree corresponding to at least one SQL statement according to a tree relationship, wherein the tree relationship is that the relational database before being executed is taken as a root node of the tree, and the execution order of at least one SQL statement is taken as a child node of the tree; Each SQL statement in the SQL statement tree is parsed and processed to obtain a parsing result corresponding to each SQL statement in the SQL statement tree; The relational database performs operation processing of the database according to the parsing result corresponding to each SQL statement in the SQL statement tree according to the logical relationship of the tree relationship.

3. The SQL statement restoration method of claim 2, wherein, The parsing and processing of each SQL statement in the SQL statement tree to obtain a parsing result corresponding to each SQL statement in the SQL statement tree comprises: The syntax of each SQL statement in the SQL statement tree is checked and processed, and the SQL statement with syntax error is corrected according to the semantics to obtain each SQL statement in the SQL statement tree after correction processing; Each SQL statement in the SQL statement tree after correction processing is converted according to the recognition rule of the relational database to form a parsing result corresponding to each SQL statement in the SQL statement tree.

4. The SQL statement restoration method of claim 2, wherein, When the relational database performs operation processing of the database according to the parsing result corresponding to each SQL statement in the SQL statement tree according to the logical relationship of the tree relationship, it further comprises: When performing operation processing of the database according to the logical relationship of the tree relationship, for the database operation of each SQL statement, a SQL statement operation log corresponding to the SQL statement is generated, wherein the operation target data of the corresponding SQL statement before being operated is backed up in the SQL statement operation log; And the SQL statement operation log and the child node corresponding to the tree relationship are associated and stored.

5. The SQL statement restoration method of claim 1, wherein, The to-be-restored SQL statement contained in the database restoration instruction is obtained by analyzing the database restoration instruction, comprising: The relational database parses the database restoration instruction, and extracts a to-be-restored SQL statement contained in the database restoration instruction through a parsing result.

6. The SQL statement restoration method of claim 1, wherein, The relational database obtains a database operation node corresponding to the to-be-restored SQL statement contained in the database restoration instruction. The relational database performs matching processing on the to-be-restored SQL statement contained in the database restoration instruction and a SQL statement corresponding to each node in the SQL statement tree, and obtains a matching result; A sub-node corresponding to the SQL statement matched with the to-be-restored SQL statement in the matching result is taken as the database operation node corresponding to the to-be-restored SQL statement.

7. The SQL statement restoration method of claim 1, wherein, The relational database performs restoration processing on a database operation based on the database operation node and the to-be-restored SQL statement contained in the database restoration instruction. The relational database obtains a corresponding SQL statement operation log based on the database operation node and a sub-node corresponding to a tree-shaped relationship; The to-be-restored SQL statement contained in the database restoration instruction and the SQL statement operation log are used to perform restoration processing on a database operation.

8. A device for restoring SQL statements based on database operations, characterized in that, The device comprises: A data operation module configured to perform data operation processing on at least one SQL statement contained in a SQL operation instruction sent by a client by a relational database, and feed back a data operation result to the client; An instruction receiving module configured to receive, by the relational database, a database restoration instruction fed back by the client based on the data operation result, and obtain a to-be-restored SQL statement contained in the database restoration instruction by parsing the database restoration instruction; An obtaining module configured to obtain, by the relational database, a database operation node corresponding to the to-be-restored SQL statement contained in the database restoration instruction; A restoration operation module configured to perform restoration processing on a database operation based on the database operation node and the to-be-restored SQL statement contained in the database restoration instruction by the relational database.

9. An electronic device comprising a processor and a memory, characterized in that The processor runs a computer program or code stored in the memory, and implements the SQL statement restoration method in any one of claims 1 to 7.

10. A computer readable storage medium for storing a computer program or code, characterized in that, When the computer program or code is executed by the processor, the SQL statement restoration method in any one of claims 1 to 7 is implemented.