Database statement processing method, device, system, electronic device and storage medium

By detecting and processing similarity of database SQL statements, the target tree structure statements are generated, which solves the problems of high repetition of SQL statements, difficulty in maintaining and high error rate, and achieves the effect of improving the readability and maintainability of SQL statements.

CN115080562BActive Publication Date: 2025-06-24HANGZHOU DBAPPSECURITY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210586846.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-27
Publication Date
2025-06-24
Estimated Expiration
2042-05-27

AI Technical Summary

Technical Problem

Due to the high structural repetition of existing database SQL statements, the readability is low, the maintenance is difficult and the error rate is high, and the existing technology is difficult to effectively solve these problems.

Method used

By obtaining the to-process tree structure statements and historical sub-statements, performing similarity detection, extracting statement elements and obtaining data labels, processing the tree structure based on this information, and generating the target tree structure statement.

Benefits of technology

It effectively reduces the repetition of SQL statements, improves the readability and maintainability of statements, and reduces the error rate.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115080562B_ABST
    Figure CN115080562B_ABST
Patent Text Reader

Abstract

The present application relates to a method, apparatus, system, electronic device, and storage medium for processing database statements. Among them, the method for processing database statements includes: obtaining a to-be-processed tree-structured statement including at least a sub-statement; obtaining a historical sub-statement, performing a similarity detection on the sub-statement and the historical sub-statement to obtain a statement similarity result; extracting statement elements in the sub-statement according to the statement similarity result, and obtaining a data label according to the statement elements; processing the tree structure according to the statement similarity result and the data label to obtain a target tree-structured statement. Through the present application, the problems of high repetition rate, large maintenance difficulty, and large error rate of SQL statements are solved, and the readability and maintainability of database SQL statements are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of database technology, and in particular, to a method, device, system, electronic device, and storage medium for processing database statements. Background Art

[0002] SQL (Structured Query Language) is a database language with various functions such as data manipulation and data definition. When executing SQL statements, for example, in the scenario of executing SQL statements for detecting database vulnerabilities, a large number of original database vulnerability detection SQL statements need to be corrected as the test progresses. In the maintenance of historical data, the original SQL statements are generally modified by appending statements. Therefore, during the modification process, SQL statements often append and write a large number of repetitive structures due to the modification of some parameters. Due to the extremely large number of such repetitive structures, a large number of nested structures have gradually accumulated in the SQL statements, resulting in a significant increase in the difficulty of reading and modifying SQL statements, and also an increase in the error rate during the maintenance process.

[0003] To solve the problem of low readability of existing database SQL statements due to structural repetition during maintenance, the prior art generates and parses an AST (Abstract Syntax Tree) object to obtain all abstract constituent elements in the SQL statement syntax for visual display. Although the prior art solves the problem of SQL statement structure visualization through the generation and data extraction of the AST syntax tree, it is still difficult to solve the problems of high maintenance difficulty and large error rate caused by high statement repetition.

[0004] Regarding the problems of high SQL statement repetition, high maintenance difficulty, and large error rate in the related art, no effective solution has been proposed yet. Summary of the Invention

[0005] In this embodiment, a method, device, system, electronic device, and storage medium for processing database statements are provided to solve the problems of high SQL statement repetition, high maintenance difficulty, and large error rate in the related art.

[0006] In a first aspect, in this embodiment, a method for processing database statements is provided, including:

[0007] Obtain a to-be-processed tree-structured statement including at least sub-statements;

[0008] Obtain historical sub-statements, perform similarity detection on the sub-statements and the historical sub-statements to obtain a statement similarity result; extract statement elements in the sub-statements according to the statement similarity result, and obtain data tags according to the statement elements;

[0009] Process the tree structure according to the statement similarity result and the data label to obtain a target tree structure statement.

[0010] In some of the embodiments, there is at least one historical sub-statement; the obtaining of the statement similarity result by performing similarity detection on the sub-statement and the historical sub-statement includes:

[0011] Obtain a preset edit distance and all current edit distances for the sub-statement and all the historical sub-statements.

[0012] In the case where all the current edit distances are greater than the preset edit distance, the statement similarity result is empty.

[0013] In the case where one of the current edit distances is less than or equal to the preset edit distance, the statement similarity result indicates that the historical sub-statement corresponding to the one current edit distance is a similar clause.

[0014] In the case where at least two of the current edit distances are less than or equal to the preset edit distance, the statement similarity result indicates that the historical sub-statement with the smallest current edit distance is a similar clause.

[0015] In some of the embodiments, the extracting statement elements from the sub-statement according to the statement similarity result and obtaining a data label according to the statement elements includes:

[0016] Obtain a statement blacklist, delete the characters in the sub-statement that match the statement blacklist to obtain a filtered sub-statement.

[0017] According to the statement similarity result and the historical sub-statement, extract the part of the filtered sub-statement that is different from the historical sub-statement to obtain the statement elements.

[0018] Obtain a data label according to the statement elements in the to-be-processed tree structure statement.

[0019] In some of the embodiments, the processing the tree structure according to the statement similarity result and the data label to obtain a target tree structure statement includes:

[0020] According to the statement similarity result and the data label, compare all the left sub-trees and right sub-trees in the to-be-processed tree structure statement to obtain a comparison result.

[0021] According to the comparison result, delete or merge the to-be-processed tree structure statement to obtain the target tree structure statement.

[0022] In some of these embodiments, the obtaining at least includes obtaining a tree-structured statement to be processed including sub-statements, including:

[0023] Obtaining a statement to be processed and a preset constraint condition, splitting the statement to be processed according to the preset constraint condition to obtain statement blocks;

[0024] Converting the statement to be processed into the tree-structured statement to be processed according to an abstract syntax tree model and the statement blocks; wherein the tree-structured statement to be processed at least includes sub-statements.

[0025] In some of these embodiments, after obtaining the target tree-structured statement, it further includes:

[0026] Outputting the target tree-structured statement to a terminal device for display.

[0027] In a second aspect, a database statement processing apparatus is provided in this embodiment, including: an obtaining module, a comparing module, and a processing module;

[0028] The obtaining module is configured to obtain a tree-structured statement to be processed including at least sub-statements;

[0029] The comparing module is configured to obtain historical sub-statements, perform similarity detection on the sub-statements and the historical sub-statements to obtain a statement similarity result; extract statement elements from the sub-statements according to the statement similarity result, and obtain data tags according to the statement elements;

[0030] The processing module is configured to process the tree structure according to the statement similarity result and the data tags to obtain a target tree-structured statement.

[0031] In a third aspect, a database statement processing system is provided in this embodiment, which is characterized by including: a terminal device, a transmission device, and a server device; wherein, the terminal device is connected to the server device through the transmission device;

[0032] The server device is configured to execute the database statement processing method described in the first aspect above;

[0033] The transmission device is configured to transmit the target tree-structured statement to the terminal device;

[0034] The terminal device is configured to display the target tree-structured statement.

[0035] In a fourth aspect, an electronic device is provided in this embodiment, including a memory, a processor, and a computer program stored on the memory and executable on the processor, and when the processor executes the computer program, it implements the database statement processing method described in the first aspect above.

[0036] In a fifth aspect, in the present embodiment, a storage medium is provided, on which a computer program is stored, and when the program is executed by a processor, the database statement processing method described in the first aspect above is implemented.

[0037] Compared with the related art, in the database statement processing method, device, system, electronic device and storage medium provided in the present embodiment, by obtaining a to-be-processed tree-structured statement including at least a sub-statement; obtaining a historical sub-statement, performing a similarity detection on the sub-statement and the historical sub-statement to obtain a statement similarity result; extracting statement elements in the sub-statement according to the statement similarity result, and obtaining data tags according to the statement elements; processing the tree structure according to the statement similarity result and the data tags to obtain a target tree-structured statement, the problems of high SQL statement repetition rate, high maintenance difficulty and high error rate are solved, and the readability and maintainability of the database SQL statements are improved.

[0038] Details of one or more embodiments of the present application are set forth in the following drawings and description, so that the other features, objects, and advantages of the present application will become more apparent and understandable. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] The drawings described herein are used to provide a further understanding of the present application, and constitute a part of the present application. The illustrative embodiments and descriptions of the present application are used to explain the present application, and do not constitute an improper limitation of the present application. In the drawings:

[0040] Figure 1 It is a diagram of an application scenario of the database statement processing method in an embodiment;

[0041] Figure 2 It is a flowchart of the database statement processing method in an embodiment;

[0042] Figure 3 It is a flowchart of the database statement processing method in another embodiment;

[0043] Figure 4 It is a diagram of the AST extraction result in an embodiment;

[0044] Figure 5 It is a diagram of the sub-statement comparison result in an embodiment;

[0045] Figure 6 It is a diagram of the statement element extraction result in an embodiment;

[0046] Figure 7 It is a diagram of the structure optimization result in an embodiment;

[0047] Figure 8It is a structural block diagram of a database statement processing device in an embodiment;

[0048] Figure 9 It is an internal structure diagram of a computer device in an embodiment. Specific implementation manners

[0049] To understand the purpose, technical solution and advantages of the present application more clearly, the present application will be described and explained below in conjunction with the accompanying drawings and embodiments.

[0050] Unless otherwise defined, the technical terms or scientific terms involved in the present application shall have the general meanings understood by those with ordinary skills in the technical field to which the present application belongs. In the present application, words such as "a", "one", "a kind of", "the", "these" and the like do not indicate a limitation in quantity, and they can be singular or plural. The terms "including", "comprising", "having" and any variants thereof involved in the present application are intended to cover non-exclusive inclusion; for example, a process, method, system, product or device including a series of steps or modules (units) is not limited to the listed steps or modules (units), but may include unlisted steps or modules (units), or may include other steps or modules (units) inherent in these processes, methods, products or devices. The terms "connected", "coupled" and the like involved in the present application are not limited to physical or mechanical connections, but may include electrical connections, whether directly or indirectly connected. The term "plurality" involved in the present application means two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" may represent: A exists alone, A and B exist simultaneously, and B exists alone. Usually, the character " / " indicates that the objects associated before and after are in an "or" relationship. The terms "first", "second", "third" and the like involved in the present application are only used to distinguish similar objects and do not represent a specific order for the objects.

[0051] The database statement processing method provided by the present application can be applied to, for example Figure 1In the application environment shown. Among them, the terminal device 102 communicates with the server device 104 through the network. The server device 104 obtains a tree-structured statement to be processed that at least includes sub-statements; the server device 104 obtains historical sub-statements, performs similarity detection on the sub-statement and the historical sub-statement to obtain a statement similarity result; extracts statement elements in the sub-statement according to the statement similarity result, and obtains data tags according to the statement elements; the server device 104 processes the tree structure according to the statement similarity result and the data tag to obtain a target tree-structured statement. Among them, the terminal device 102 can be, but is not limited to, various personal computers, laptop computers, smart phones, tablet computers, and portable wearable devices, and the server device 104 can be implemented by an independent server or a server cluster composed of multiple servers.

[0052] In this embodiment, a method for processing database statements is provided. Figure 2 It is a flowchart of the method for processing database statements in this embodiment, as Figure 2 shown, and the process includes the following steps:

[0053] Step S202, obtain a tree-structured statement to be processed that at least includes sub-statements.

[0054] Step S204, obtain historical sub-statements, perform similarity detection on the sub-statement and the historical sub-statement to obtain a statement similarity result; extract statement elements in the sub-statement according to the statement similarity result, and obtain data tags according to the statement elements.

[0055] Among them, the similarity detection is used to compare whether the current sub-statement to be processed is similar to any of the historical sub-statements processed in the history to obtain a statement similarity result; if the statement similarity result indicates that there is no historical sub-statement similar to the current sub-statement, add the current sub-statement to the database of historical sub-statements, and label the sub-statement with a new data tag; if the statement similarity result indicates that there is a statement in the database of historical sub-statements that is similar to the current sub-statement, label the historical sub-statement as the current similar clause, and obtain data tags according to the current similar clause; the data tag refers to the number of the historical sub-statement corresponding to the statement element, and the data tag is used to indicate that the statement element in the sub-statement is a key field.

[0056] Step S206, process the tree structure according to the statement similarity result and the data tag to obtain a target tree-structured statement.

[0057] It should be noted that the above database statement processing method can be applied to database statement processing scenarios that require filtering characters or numbers, such as database vulnerability detection statement processing or database condition filtering statement processing, etc.

[0058] Through the above steps, the similarity between the sub-statement and the historical sub-statement is detected to obtain a statement similarity result, and a data label is obtained according to the similarity result. Then, the statement to be processed in the tree structure is processed according to the similarity result and the data label to obtain the target tree structure statement. The statement similarity result can be obtained from the statement to be processed in the tree structure, and further a data label indicating the keyword fields of the statement elements in the sub-statement can be obtained. Then, the keyword fields in the tree structure to be processed are processed according to the statement similarity result and the data label to obtain a target tree structure statement with a simple structure, solving the problems of high SQL statement repetition, high maintenance difficulty, and high error rate.

[0059] In some of the embodiments, there is at least one historical sub-statement; the detecting the similarity between the sub-statement and the historical sub-statement to obtain a statement similarity result includes:

[0060] Obtaining a preset edit distance and all current edit distances for the sub-statement and all the historical sub-statements;

[0061] In the case where all the current edit distances are greater than the preset edit distance, the statement similarity result is empty;

[0062] In the case where one of the current edit distances is less than or equal to the preset edit distance, the statement similarity result indicates that the historical sub-statement corresponding to the one current edit distance is a similar clause;

[0063] In the case where at least two of the current edit distances are less than or equal to the preset edit distance, the statement similarity result indicates that the historical sub-statement with the smallest current edit distance is a similar clause.

[0064] Among them, the preset edit distance is determined according to the similarity requirement in the actual application. The smaller the preset edit distance, the higher the similarity and the fewer the number of the matched historical sub-statements; all the current edit distances for the sub-statement and all the historical sub-statements are determined by the edit distance algorithm; the edit distance algorithm is also called the Levenshtein Distance algorithm, which is an algorithm for calculating the similarity between two strings in the field of statistical learning. The Levenshtein distance between two strings refers to the minimum number of single-character edits (insertions, deletions, or replacements) required to change one string into the other string.

[0065] Specifically, in this embodiment, the preset edit distance is taken as 10. When all current edit distances are greater than 10, the statement similarity result is empty, indicating that there are no similar historical sub-statements at present, and the current sub-statement is added to the database of historical sub-statements; when one of the current edit distances is less than or equal to 10, the statement similarity result indicates that the historical sub-statement corresponding to this current edit distance is a similar clause; when at least two of the current edit distances are less than or equal to 10, the statement similarity result indicates that the historical sub-statement with the smallest current edit distance is the similar clause.

[0066] Through the above steps, the edit distances of the sub-statement and all historical sub-statements are compared, so as to update the database of historical sub-statements, or find the historical sub-statement with the smallest edit distance as the similar clause, thereby obtaining the statement similarity result. The tree-structured statement to be processed can be processed according to the similar clause, solving the problems of high SQL statement repetition, large maintenance difficulty and high error rate, and improving the readability and maintainability of the database SQL statements.

[0067] In some of the embodiments, extracting statement elements from the sub-statement according to the statement similarity result, and obtaining data tags according to the statement elements includes:

[0068] Obtain a statement blacklist, delete the characters in the sub-statement that match the statement blacklist, and obtain a filtered sub-statement;

[0069] According to the statement similarity result and the historical sub-statement, extract the parts of the filtered sub-statement that are different from the historical sub-statement to obtain the statement elements;

[0070] Obtain data tags according to the statement elements in the tree-structured statement to be processed.

[0071] Among them, the statement blacklist is used to match meaningless characters in the statement, including space characters and other potential special characters; the statement elements refer to the different parts of two similar statements, and there are no statement elements in the filtered sub-statement that is exactly the same as the similar clause; it should be noted that after obtaining the data tags, the data tags are matched and marked with the statement elements; the data tags refer to the numbers of the historical sub-statements corresponding to the statement elements, and the data tags are used to indicate that the statement elements in the sub-statement are key fields.

[0072] Through the above steps, by deleting meaningless characters and obtaining data tags, the tree structure is processed to obtain the target tree structure statement, and data tags for indicating the keyword fields of statement elements in the sub-statement can be obtained, resulting in a target tree structure statement with a simple structure, solving the problems of high repetition, high maintenance difficulty, and high error rate of SQL detection statements, and improving the readability and maintainability of database SQL statements.

[0073] In some of these embodiments, processing the tree structure according to the statement similarity result and the data tag to obtain the target tree structure statement includes:

[0074] Comparing all the left subtrees and right subtrees in the tree structure statement to be processed according to the statement similarity result and the data tag to obtain a comparison result;

[0075] Deleting or merging the tree structure statement to be processed according to the comparison result to obtain the target tree structure statement.

[0076] Among them, all the left subtrees and right subtrees refer to all the left subtrees and all the right subtrees of all non-leaf nodes in the tree structure statement to be processed; the comparison result refers to whether the left subtree and the right subtree of any leaf node have similar structures and the same data tags at the same time.

[0077] Specifically, in the case where the comparison result indicates that the left subtree and the right subtree of any leaf node in the tree structure statement to be processed have similar structures and the same data tags at the same time, add, delete, and modify operations are performed according to the number range indicated by the statement element, such as deleting redundant statements and merging intervals, etc., so as to obtain the target tree structure statement.

[0078] Through the above steps, adding, deleting, and modifying the tree structure statement to be processed using data tags can simplify the tree structure statement to be processed and thus obtain a target tree structure statement with a simple structure, solving the problems of high repetition, high maintenance difficulty, and high error rate of SQL detection statements, and improving the readability and maintainability of database SQL statements.

[0079] In some of these embodiments, obtaining the tree structure statement to be processed that at least includes sub-statements includes:

[0080] Obtaining the statement to be processed and the preset constraint conditions, and splitting the statement to be processed according to the preset constraint conditions to obtain statement blocks;

[0081] Converting the statement to be processed into the tree structure statement to be processed according to the abstract syntax tree model and the statement blocks; where the tree structure statement to be processed at least includes sub-statements.

[0082] Among them, the statement of the tree structure to be processed further includes a parent statement; the abstract syntax tree model (AST, Abstract Syntax Tree) is an abstract representation of the source code syntax structure, which presents the syntax structure of a programming language in a tree-like form. Each node on the tree represents a structure in the source code and is used to automatically convert the statement of the linear structure to be processed into a tree structure according to the statement logic and the segmented statement block, so as to obtain the statement of the tree structure to be processed.

[0083] Through the above steps, the linear statement to be processed is converted into a statement of the tree structure to be processed, which can improve the efficiency of obtaining the target statement of the tree structure, solve the problems of high repetition rate, large maintenance difficulty and large error rate of the SQL detection statement, and improve the readability and maintainability of the database SQL statement.

[0084] In some of these embodiments, after obtaining the target statement of the tree structure, it further includes:

[0085] Output the target statement of the tree structure to a terminal device for display.

[0086] Among them, the target statement of the tree structure can be directly displayed on the terminal device 102, or the target statement of the tree structure can be converted into a linear SQL statement structure and displayed on the terminal device 102.

[0087] Through the above steps, the processed target statement of the tree structure can be visually displayed, solving the problems of high repetition rate, large maintenance difficulty and large error rate of the SQL detection statement, and improving the readability and maintainability of the database SQL statement.

[0088] Taking the processing of the database vulnerability detection SQL statement as an example, this embodiment also provides a method for processing database statements. Figure 3 It is a flowchart of another method for processing database statements in this embodiment, as Figure 3 shown. The process includes the following steps:

[0089] Step S302, input a statement to be processed. The statement to be processed is automatically obtained, and there is at least one statement to be processed. Specifically, a statement for querying vulnerabilities to be processed is: select 1 from table_1 where ((select a from table_a where a>0) and ((select b from table_b)=1)) or ((select a from table_a where a<=0) and ((select b from table_b)=1)).

[0090] Step S304, AST extraction. Obtain preset constraint conditions, split the statement to be processed according to the preset constraint conditions to obtain statement blocks; according to the abstract syntax tree model and the statement blocks, convert the statement to be processed into the statement of the to-be-processed tree structure; wherein the statement of the to-be-processed tree structure includes at least sub-statements. Specifically, the AST extraction result for the above-mentioned vulnerability query statement to be processed is as Figure 4 shown; Figure 4 is the schematic diagram of the AST extraction result in this embodiment, Figure 4 in which, or is the parent node, and its child nodes are two ands; the left subtree of the parent node or is connected in parallel with two selection statements, where the condition of one left subtree selection statement is a > 0, and the condition of the other left subtree selection statement is b = 1; the right subtree of the parent node or is connected in parallel with two selection statements, where the condition of one right subtree selection statement is a <= 0, and the condition of the other right subtree selection statement is b = 1.

[0091] Step S306, input at least one sub-statement.

[0092] Step S308, sub-statement comparison. Obtain the preset edit distance and all current edit distances for the sub-statement and all historical sub-statements, and perform similarity detection on the sub-statement and the historical sub-statements to obtain a statement similarity result.

[0093] Step S310, determine whether the current edit distance is greater than the preset edit distance. In the case where all the current edit distances are greater than the preset edit distance, the statement similarity result is empty, and execute Step S312 to add the sub-statement to the historical sub-statement database; in the case where one of the current edit distances is less than or equal to the preset edit distance, the statement similarity result indicates that the historical sub-statement corresponding to the one current edit distance is a similar clause; in the case where at least two of the current edit distances are less than or equal to the preset edit distance, the statement similarity result indicates that the historical sub-statement with the smallest current edit distance is a similar clause. Specifically, the sub-statement comparison result for the statement of the to-be-processed tree structure is as Figure 5 shown; the historical sub-statement database stores database statement A: select a from table_a where a = 1, and database statement B: (select b from table_b) = 1; Figure 5 is the schematic diagram of the sub-statement comparison result in this embodiment, Figure 5 in which, the similar clause for the left subtree selection statement with the condition a > 0 is the historical sub-statement numbered A, the similar clause for the left subtree selection statement with the condition b = 1 is the historical sub-statement numbered B, the similar clause for the right subtree selection statement with the condition a <= 0 is the historical sub-statement numbered A, and the similar clause for the right subtree selection statement with the condition b = 1 is the historical sub-statement numbered B.

[0094] Step S314, statement element extraction. Obtain the statement blacklist, delete the characters in the sub-statement that match the statement blacklist to obtain a filtered sub-statement; according to the statement similarity result and the historical sub-statement, extract the part of the filtered sub-statement that is different from the historical sub-statement to obtain statement elements; obtain data tags according to the statement elements in the to-be-processed tree-structured statement. Specifically, the statement element extraction result for the to-be-processed tree-structured statement is as Figure 6 shown; Figure 6 This is a schematic diagram of the statement element extraction result in this embodiment. Figure 6 In it, for the left subtree selection statement condition a > 0, the element extraction result is ">0", and its data tag is: historical sub-statement number A, and the element list ">0"; since the sub-statement with the left subtree selection statement condition b = 1 is the same as the historical sub-statement B, its element extraction result is empty, and its data tag is: historical sub-statement number B; similarly, the data tag for the right subtree selection statement condition a <= 0 is: historical sub-statement number A, and the element list "<=0", and the data tag for the right subtree selection statement condition b = 1 is: historical sub-statement number B.

[0095] Step S316, determine whether to traverse all sub-statements. If the answer is no, jump to execute Step S306 to obtain the data tag of the next sub-statement; if the answer is yes, execute Step S318.

[0096] Step S318, structure optimization. According to the statement similarity result and the data tag, compare all the left subtrees and right subtrees in the to-be-processed tree-structured statement to obtain a comparison result; according to the comparison result, delete or merge the to-be-processed tree-structured statement to obtain a target tree-structured statement. Specifically, the structure optimization result for the to-be-processed tree-structured statement is as Figure 7 shown; Figure 7 This is a schematic diagram of the structure optimization result in this embodiment. ">0" and "<=0" are complementary intervals. After merging them, it is the set of real numbers. Since the value range of a itself is the set of real numbers, this real number set condition is a redundant condition, and the conditional statement about a is deleted; at the same time, the conditions of (select b from table_b) = 1 are merged, thereby obtaining Figure 7 the target tree-structured statement described above.

[0097] Step S320, combine and output the target tree structure statement. Output the target tree structure statement directly to the terminal device 102 for display, or convert the target tree structure into a linear SQL statement structure and display it on the terminal device 102. Specifically, when converting the target tree structure into a linear SQL statement structure and displaying it on the terminal device 102, the SQL output result of the above database vulnerability detection statement is: select 1 from table_1 where (select b from table_b) = 1.

[0098] Step S322, determine whether all statements to be processed have been traversed. If so, the steps of the database statement processing method are completed; if not, jump to step S302 to obtain the next statement to be processed and get the next tree structure statement to be processed until all tree structure statements to be processed are completed.

[0099] It should be noted that after executing step S312, a new number can be directly assigned to the sub-statement that cannot be matched in the historical sub-statement database. This new number is used as the data label of the sub-statement, and the sub-statement and the new data label are stored in the historical sub-statement database, and then step S322 is executed to obtain the next statement to be processed.

[0100] Through the above steps, the similarity between the sub-statement and the historical sub-statement is detected to obtain the statement similarity result, and the data label is obtained according to the similarity result. Then, according to the similarity result and the data label, the tree structure statement to be processed is processed to obtain the target tree structure statement. The statement similarity result can be obtained from the tree structure statement to be processed, and further the data label indicating the original sentence element keyword field in the sub-statement can be obtained. Then, according to the statement similarity result and the data label, the keyword field in the tree structure to be processed is processed to obtain a target tree structure statement with a simple structure, which solves the problems of high repetition rate, large maintenance difficulty and large error rate of SQL detection statements.

[0101] It should be understood that although Figure 2-3 the steps in the flowchart are shown in sequence according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise clearly stated in this article, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 2-3At least some of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed and completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed alternately or in turn with at least some of the sub-steps or stages of other steps or other steps.

[0102] In this embodiment, a database statement processing device is also provided. This device is used to implement the above embodiments and preferred implementation manners, and those that have been described will not be repeated here. The following terms "module", "unit", "sub-unit", etc. can be a combination of software and / or hardware that can achieve a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation in hardware, or a combination of software and hardware is also possible and contemplated.

[0103] Figure 8 is a structural block diagram of the database statement processing device of this embodiment, as Figure 8 shown, the device includes: an acquisition module 10, a comparison module 20, and a processing module 30;

[0104] The acquisition module 10 is used to acquire a tree-structured statement to be processed that at least includes sub-statements;

[0105] The comparison module 20 is used to acquire historical sub-statements, perform similarity detection on the sub-statements and the historical sub-statements to obtain a statement similarity result; extract statement elements in the sub-statements according to the statement similarity result, and obtain data tags according to the statement elements;

[0106] The processing module 30 is used to process the tree structure according to the statement similarity result and the data tags to obtain a target tree-structured statement.

[0107] For the specific limitations on the database statement processing device, reference can be made to the limitations on the database statement processing method in the above text, which will not be repeated here. Each module in the above database statement processing device can be implemented in whole or in part by software, hardware, and their combination. The above modules can be embedded in the processor in the computer device in hardware form or be independent of it, or can be stored in the memory in the computer device in software form, so that the processor can call and execute the operations corresponding to the above modules.

[0108] In this embodiment, a database statement processing system is also provided, including: a terminal device 102, a transmission device, and a server device 104; wherein, the terminal device 102 is connected to the server device 104 through the transmission device;

[0109] The server device 104 is used to execute the steps in the embodiment of the above database statement processing method;

[0110] The transmission device is used to transmit the target tree - structured statement to the terminal device;

[0111] The terminal device 102 is used to display the target tree - structured statement.

[0112] In this embodiment, an electronic device is further provided, which includes a memory and a processor. A computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any of the above - mentioned method embodiments.

[0113] Optionally, the above - mentioned electronic device may further include a transmission device and an input / output device. Among them, the transmission device is connected to the above - mentioned processor, and the input / output device is connected to the above - mentioned processor.

[0114] Optionally, in this embodiment, the above - mentioned processor may be configured to execute the following steps through a computer program:

[0115] S1, obtain a tree - structured statement to be processed that at least includes sub - statements.

[0116] S2, obtain historical sub - statements, perform similarity detection on the sub - statement and the historical sub - statements to obtain a statement similarity result; extract statement elements in the sub - statement according to the statement similarity result, and obtain data tags according to the statement elements.

[0117] S3, process the tree - structured statement according to the statement similarity result and the data tags to obtain a target tree - structured statement.

[0118] It should be noted that specific examples in this embodiment can refer to the examples described in the above - mentioned embodiment and optional implementation manners, and will not be elaborated in this embodiment.

[0119] In addition, in combination with the database statement processing method provided in the above - mentioned embodiment, a storage medium can also be provided to implement it in this embodiment. A computer program is stored on the storage medium; when the computer program is executed by a processor, any of the above - mentioned database statement processing methods in the embodiment is implemented.

[0120] In one embodiment, a computer device is provided. The computer device can be a server, and its internal structure diagram can be as Figure 9As shown. The computer device includes a processor, a memory, a network interface, and a database connected via a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store historical sub-statement data. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, it implements a database statement processing method.

[0121] Those skilled in the art can understand that Figure 9 the structure shown in is only a block diagram of some structures related to the solution of this application, and does not constitute a limitation on the computer device to which the solution of this application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0122] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, storage, database, or other medium used in the embodiments provided in this application can include non-volatile and / or volatile memories. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or an external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0123] It should be understood that the specific embodiments described here are only used to explain this application, rather than to limit it. According to the embodiments provided in this application, all other embodiments obtained by those of ordinary skill in the art without creative efforts fall within the protection scope of this application.

[0124] Obviously, the accompanying drawings are only some examples or embodiments of the present application. For those of ordinary skill in the art, the present application can also be applied to other similar situations based on these drawings without creative efforts. Additionally, it can be understood that although the work done during the development process here may be complex and time-consuming, for those of ordinary skill in the art, certain design, manufacturing, or production changes based on the technical content disclosed in the present application are only routine technical means and should not be regarded as insufficient disclosure of the present application.

[0125] The term "embodiment" in the present application means that the specific features, structures, or characteristics described in connection with the embodiment may be included in at least one embodiment of the present application. The phrase appears at various positions in the specification and does not necessarily mean the same embodiment, nor does it mean being independent or alternative to other embodiments and mutually exclusive. Those of ordinary skill in the art can clearly or implicitly understand that the embodiments described in the present application can be combined with other embodiments without conflict.

[0126] The above-described embodiments merely represent several implementation manners of the present application. The description is relatively specific and detailed, but it should not be construed as a limitation on the scope of patent protection. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present application, several modifications and improvements can still be made, and these all fall within the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the appended claims.

Claims

1. A method for processing database statements, characterized in that, Including: Obtain a to-be-processed tree-structured statement including at least sub-statements; Obtain historical sub-statements, perform similarity detection on the sub-statements and the historical sub-statements, and obtain a statement similarity result; Extract statement elements in the sub-statements according to the statement similarity result, and obtain data tags according to the statement elements; wherein, the statement elements refer to the different parts in two similar statements; Process the tree structure according to the statement similarity result and the data tags to obtain a target tree-structured statement, including: Compare all the left sub-trees and right sub-trees in the to-be-processed tree-structured statement according to the statement similarity result and the data tags to obtain a comparison result; Delete or merge the to-be-processed tree-structured statement according to the comparison result to obtain the target tree-structured statement.

2. The database statement processing method according to claim 1, wherein There is at least one historical sub-statement; the performing similarity detection on the sub-statements and the historical sub-statements to obtain a statement similarity result includes: Obtain a preset edit distance and all current edit distances for the sub-statements and all the historical sub-statements; In the case where all the current edit distances are greater than the preset edit distance, the statement similarity result is empty; In the case where one of the current edit distances is less than or equal to the preset edit distance, the statement similarity result indicates that the historical sub-statement corresponding to the one current edit distance is a similar clause; In the case where at least two of the current edit distances are less than or equal to the preset edit distance, the statement similarity result indicates that the historical sub-statement with the smallest current edit distance is a similar clause.

3. The database statement processing method according to claim 1, wherein The extracting statement elements in the sub-statements according to the statement similarity result and obtaining data tags according to the statement elements includes: Obtain a statement blacklist, delete the characters in the sub-statements that match the statement blacklist to obtain a filtered sub-statement; Extract the parts in the filtered sub-statement that are different from the historical sub-statements according to the statement similarity result and the historical sub-statements to obtain the statement elements; Obtain data tags according to the statement elements in the to-be-processed tree-structured statement.

4. The database statement processing method according to claim 1, wherein The obtaining a to-be-processed tree-structured statement including at least sub-statements includes: Obtain a to-be-processed statement and preset constraint conditions, divide the to-be-processed statement according to the preset constraint conditions to obtain statement blocks; Convert the to-be-processed statement into the to-be-processed tree-structured statement according to an abstract syntax tree model and the statement blocks; wherein the to-be-processed tree-structured statement includes at least sub-statements.

5. The database statement processing method according to any one of claims 1 to 4, characterized in that After obtaining the target tree-structured statement, it further includes: Output the target tree-structured statement to a terminal device for display.

6. A database statement processing device, characterized in that, Including: An obtaining module, a comparing module and a processing module; The obtaining module is used to obtain a to-be-processed tree-structured statement including at least sub-statements; The comparing module is used to obtain historical sub-statements, perform similarity detection on the sub-statements and the historical sub-statements, and obtain a statement similarity result; Extract statement elements in the sub-statements according to the statement similarity results, and obtain data tags according to the statement elements; wherein, the statement elements refer to different parts in two similar statements. The processing module is configured to process the tree structure according to the statement similarity results and the data tags to obtain a target tree structure statement, including: Compare all the left sub-trees and right sub-trees in the tree structure statement to be processed according to the statement similarity results and the data tags to obtain a comparison result; Delete or merge the tree structure statement to be processed according to the comparison result to obtain the target tree structure statement.

7. A database statement processing system, characterized in that Including: A terminal device, a transmission device, and a server device; wherein, the terminal device is connected to the server device through the transmission device; The server device is configured to execute the database statement processing method according to any one of claims 1 to 5; The transmission device is configured to transmit the target tree structure statement to the terminal device; The terminal device is configured to display the target tree structure statement.

8. An electronic device, comprising a memory and a processor, characterized in that, A computer program is stored in the memory, and the processor is configured to run the computer program to execute the database statement processing method according to any one of claims 1 to 5.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, the steps of the database statement processing method according to any one of claims 1 to 5 are implemented.

Citation Information

Patent Citations

  • Text Information Extraction Methods and Systems

    CN102298642A

  • File retrieval method and device

    CN112148701A