CN115080562A - Database statement processing method, device and system, electronic device and storage medium - Google Patents

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

Info

Publication number
CN115080562A
CN115080562A CN202210586846.2A CN202210586846A CN115080562A CN 115080562 A CN115080562 A CN 115080562A CN 202210586846 A CN202210586846 A CN 202210586846A CN 115080562 A CN115080562 A CN 115080562A
Authority
CN
China
Prior art keywords
statement
sub
sentence
tree structure
processed
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210586846.2A
Other languages
Chinese (zh)
Inventor
叶子律
廖喜君
吴卓群
王欣
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
DBAPPSecurity Co Ltd
Original Assignee
DBAPPSecurity Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by DBAPPSecurity Co Ltd filed Critical DBAPPSecurity Co Ltd
Priority to CN202210586846.2A priority Critical patent/CN115080562A/en
Publication of CN115080562A publication Critical patent/CN115080562A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2246Trees, e.g. B+trees
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Mathematical Physics (AREA)
  • Computational Linguistics (AREA)
  • Software Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application relates to a database statement processing method, a device, a system, an electronic device and a storage medium, wherein the database statement processing method comprises the following steps: acquiring a tree structure statement to be processed at least comprising sub-statements; obtaining a historical sub-sentence, and carrying out similarity detection on the sub-sentence and the historical sub-sentence to obtain a sentence similarity result; extracting statement elements in the sub-statement according to the statement similarity result, and acquiring a data tag according to the statement elements; and processing the tree structure according to the statement similarity result and the data label to obtain a target tree structure statement. By the method and the device, the problems of high repeatability, high maintenance difficulty and high error rate of the SQL sentences are solved, and the readability and maintainability of the database SQL sentences are improved.

Description

Database statement processing method, device and system, electronic device and storage medium
Technical Field
The present application relates to the field of database technologies, and in particular, to a database statement processing method, apparatus, system, electronic apparatus, and storage medium.
Background
Sql (structured Query language), a structured Query language, is a database language with multiple functions such as data manipulation and data definition. When the SQL statement is executed, for example, in the scenario of executing the SQL statement for detecting the database bug, the original database bug detection SQL statement needs to be modified in a large amount as the test progresses. In the maintenance of the historical data, the original SQL statement is generally modified by means of an additional statement, so that in the modification process, the SQL statement is often additionally written into a repetitive structure in a large amount due to partial parameter modification. Because the number of the repetitive structures is extremely large, and a large number of nested structures are gradually accumulated in the SQL statement, the difficulty of reading and modifying the SQL statement is greatly improved, and the error rate in the maintenance process is also improved.
In order to solve the problem of low readability caused by structural repeatability in the maintenance of the existing database SQL statement, the existing technology generates and analyzes an AST (Abstract Syntax Tree) object to obtain all Abstract composition elements in the SQL statement Syntax so as to perform visual display. In the prior art, the visualization problem of the SQL statement structure is solved through the AST syntax tree generation and data extraction, but the problems of high maintenance difficulty and high error rate caused by high statement repeatability are still difficult to solve.
Aiming at the problems of high SQL statement repeatability, high maintenance difficulty and high error rate in the related technology, no effective solution is provided at present.
Disclosure of Invention
The embodiment provides a database statement processing method, a database statement processing device, a database statement processing system, an electronic device and a storage medium, so as to solve the problems of high repeatability, high maintenance difficulty and high error rate of SQL statements in the related art.
In a first aspect, in this embodiment, a database statement processing method is provided, including:
acquiring a tree structure statement to be processed at least comprising sub-statements;
acquiring a history sub-sentence, and carrying out similarity detection on the sub-sentence and the history sub-sentence to obtain a sentence similarity result; extracting statement elements in the sub-statements according to the statement similarity result, and acquiring data tags according to the statement elements;
and processing the tree structure according to the statement similarity result and the data label to obtain a target tree structure statement.
In some of these embodiments, the history sub-statement has at least one; the performing similarity detection on the sub-sentences and the historical sub-sentences to obtain sentence similarity results includes:
acquiring a preset editing distance and all current editing distances of the sub-sentences and all the historical sub-sentences;
under the condition that all the current editing distances are greater than the preset editing distance, the sentence similarity result is null;
under the condition that one current editing distance is smaller than or equal to the preset editing distance, the sentence similarity result indicates that the history sub-sentence corresponding to the current editing distance is a similar sub-sentence;
and under the condition that at least two current editing distances are smaller than or equal to the preset editing distance, the sentence similarity result indicates that the history sub-sentence with the minimum current editing distance is a similar sub-sentence.
In some embodiments, the extracting statement elements in the sub-statement according to the statement similarity result, and obtaining data tags according to the statement elements includes:
obtaining a statement blacklist, deleting characters matched with the statement blacklist in the sub-statements, and obtaining filtering sub-statements;
extracting the part of the filtering sub-statement, which is different from the historical sub-statement, according to the statement similarity result and the historical sub-statement to obtain the statement element;
and acquiring a data tag in the to-be-processed tree structure statement according to the statement element.
In some embodiments, the processing the tree structure according to the statement similarity result and the data tag to obtain a target tree structure statement includes:
comparing all left subtrees and all right subtrees in the to-be-processed tree-structure statement according to the statement similarity result and the data label to obtain a comparison result;
and deleting or combining the to-be-processed tree structure sentences according to the comparison result to obtain the target tree structure sentences.
In some embodiments, the obtaining a tree structure statement to be processed including at least a sub-statement includes:
obtaining a sentence to be processed and a preset constraint condition, and dividing the sentence to be processed according to the preset constraint condition to obtain a sentence block;
converting the statement to be processed into the tree-shaped structure statement to be processed according to an abstract syntax tree model and the statement block; wherein the tree structure statement to be processed comprises at least a sub-statement.
In some embodiments, after the obtaining the target tree structure statement, the method further includes:
and outputting the target tree structure sentence to terminal equipment for displaying.
In a second aspect, in this embodiment, there is provided a database statement processing apparatus including: the device comprises an acquisition module, a comparison module and a processing module;
the acquisition module is used for acquiring the to-be-processed tree structure sentence at least comprising the sub-sentences;
the comparison module is used for acquiring historical sub-sentences and carrying out similarity detection on the sub-sentences and the historical sub-sentences to obtain sentence similarity results; extracting statement elements in the sub-statements according to the statement similarity result, and acquiring data tags according to the statement elements;
and the processing module is used for processing the tree structure according to the statement similarity result and the data tag to obtain a target tree structure statement.
In a third aspect, in this embodiment, there is provided a database statement processing system, including: a terminal device, a transmission device and a server device; the terminal equipment is connected with the server equipment through the transmission equipment;
the server device is configured to execute the database statement processing method according to the first aspect;
the transmission equipment is used for transmitting the target tree structure statement to the terminal equipment;
and the terminal equipment is used for displaying the target tree structure sentence.
In a fourth aspect, in this embodiment, there is provided an electronic apparatus, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and when the processor executes the computer program, the database statement processing method according to the first aspect is implemented.
In a fifth aspect, in the present embodiment, there is provided a storage medium having stored thereon a computer program which, when executed by a processor, implements the database statement processing method according to the first aspect described above.
Compared with the related art, the database statement processing method, the database statement processing device, the database statement processing system, the electronic device and the storage medium provided by the embodiment obtain the to-be-processed tree structure statement at least comprising the sub-statements; acquiring a history sub-sentence, and carrying out similarity detection on the sub-sentence and the history sub-sentence to obtain a sentence similarity result; extracting statement elements in the sub-statement according to the statement similarity result, and acquiring a data tag according to the statement elements; and processing the tree structure according to the sentence similarity result and the data tag to obtain a target tree structure sentence, so that the problems of high repeatability, high maintenance difficulty and high error rate of the SQL sentence are solved, and the readability and maintainability of the database SQL sentence are improved.
The details of one or more embodiments of the application are set forth in the accompanying drawings and the description below to provide a more thorough understanding of the application.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the application and together with the description serve to explain the application and not to limit the application. In the drawings:
FIG. 1 is a diagram illustrating an exemplary scenario for implementing a database statement processing method;
FIG. 2 is a flowchart illustrating a method for processing database statements in one embodiment;
FIG. 3 is a flowchart illustrating a database statement processing method according to another embodiment;
FIG. 4 is a diagram illustrating the AST extraction result according to an embodiment;
FIG. 5 is a diagram illustrating the result of a sub-sentence comparison in one embodiment;
FIG. 6 is a diagram illustrating the sentence element extraction result in one embodiment;
FIG. 7 is a diagram illustrating the results of structural optimization in one embodiment;
FIG. 8 is a block diagram showing the structure of a database statement processing apparatus according to an embodiment;
FIG. 9 is a diagram illustrating an internal structure of a computer device according to an embodiment.
Detailed Description
For a clearer understanding of the objects, aspects and advantages of the present application, reference is made to the following description and accompanying drawings.
Unless defined otherwise, technical or scientific terms used herein shall have the same general meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The use of the terms "a" and "an" and "the" and similar referents in the context of this application do not denote a limitation of quantity, either in the singular or the plural. The terms "comprises," "comprising," "has," "having," and any variations thereof, as referred to in this application, are intended to cover non-exclusive inclusions; for example, a process, method, and system, article, or apparatus that comprises a list of steps or modules (elements) is not limited to the listed steps or modules, but may include other steps or modules (elements) not listed or inherent to such process, method, article, or apparatus. Reference throughout this application to "connected," "coupled," and the like is not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. Reference to "a plurality" in this application means two or more. "and/or" describes an association relationship of associated objects, meaning that three relationships may exist, for example, "A and/or B" may mean: a exists alone, A and B exist simultaneously, and B exists alone. In general, the character "/" indicates a relationship in which the objects associated before and after are an "or". The terms "first," "second," "third," and the like in this application are used for distinguishing between similar items and not necessarily for describing a particular sequential or chronological order.
The database statement processing method provided by the application can be applied to the application environment shown in fig. 1. Wherein the terminal device 102 communicates with the server device 104 via a network. The server device 104 acquires a to-be-processed tree structure sentence at least including a sub-sentence; the server device 104 acquires the historical sub-sentences, and performs similarity detection on the sub-sentences and the historical sub-sentences to obtain sentence similarity results; extracting statement elements in the sub-statement according to the statement similarity result, and acquiring a data tag according to the statement elements; the server device 104 processes the tree structure according to the statement similarity result and the data tag, so as to obtain a target tree structure statement. The terminal device 102 may be, but not limited to, various personal computers, notebook computers, smart phones, tablet computers, and portable wearable devices, and the server device 104 may be implemented by an independent server or a server cluster formed by a plurality of servers.
In this embodiment, a database statement processing method is provided, and fig. 2 is a flowchart of the database statement processing method in this embodiment, as shown in fig. 2, the flowchart includes the following steps:
step S202, obtaining a to-be-processed tree structure statement at least comprising sub-statements.
Step S204, acquiring a history sub-sentence, and carrying out similarity detection on the sub-sentence and the history sub-sentence to obtain a sentence similarity result; and extracting statement elements in the sub-statement according to the statement similarity result, and acquiring the data tags according to the statement elements.
The similarity detection is used for comparing whether the sub-sentence to be processed currently has similarity with any history sub-sentence processed in history or not to obtain a sentence similarity result; if the sentence similarity result indicates that the historical sub-sentence and the current sub-sentence are not similar, adding the current sub-sentence into a database of the historical sub-sentence, and marking the sub-sentence as a new data tag; if the sentence similarity result indicates that a sentence which has similarity with the current sub-sentence exists in the database of the historical sub-sentence, marking the historical sub-sentence as the current similar sub-sentence, and acquiring a data label according to the current similar sub-sentence; the data tag refers to a number of a history sub-statement corresponding to the statement element, and the data tag is used for indicating that the statement element in the sub-statement is a key field.
And step S206, processing the tree structure according to the statement similarity result and the data label to obtain a target tree structure statement.
It should be noted that the database statement processing method may be applied to a database statement processing scenario in which characters or numbers need to be filtered, for example, processing a database bug detection statement or processing a database conditional filtering statement.
Through the steps, the sub-sentence and the historical sub-sentence are subjected to similarity detection to obtain a sentence similarity result, and the data tag is obtained according to the similarity result, so that the tree structure sentence to be processed is processed according to the similarity result and the data tag to obtain the target tree structure sentence.
In some of these embodiments, there is at least one of the history sub-statements; the similarity detection of the sub-sentence and the historical sub-sentence is performed to obtain a sentence similarity result, which includes:
acquiring a preset editing distance and all current editing distances of the sub-sentences and all the historical sub-sentences;
under the condition that all the current editing distances are greater than the preset editing distance, the sentence similarity result is null;
when the current editing distance is smaller than or equal to the preset editing distance, the sentence similarity result indicates that the history sub-sentence corresponding to the current editing distance is a similar sub-sentence;
and under the condition that at least two current editing distances are smaller than or equal to the preset editing distance, the sentence similarity result indicates that the history sub-sentence with the minimum current editing distance is a similar sub-sentence.
The preset editing distance is determined according to the similarity requirement in practical application, and the smaller the preset editing distance is, the higher the similarity and the smaller the number of the matched historical sub-sentences are; determining all current edit distances for the sub-sentence and all the historical sub-sentences through an edit distance algorithm; the edit Distance algorithm is also called as a Levenshtein Distance algorithm, and is an algorithm for calculating the similarity of two character strings in the field of statistical learning, and the Levenshtein Distance between two character strings refers to the minimum number of times of single character editing (insertion, deletion or replacement) required for changing one character string into another character string.
Specifically, in this embodiment, the preset edit distance is 10 as an example, and in a case that all the current edit distances are greater than 10, the sentence similarity result is null, so as to indicate that there is no similar historical sub-sentence currently, and add the current sub-sentence into the database of historical sub-sentences; under the condition that one current editing distance is smaller than or equal to 10, the sentence similarity result indicates that the history sub-sentence corresponding to the current editing distance is a similar sub-sentence; in the case that at least two of the current edit distances are less than or equal to 10, the sentence similarity result indicates that the history sub-sentence with the minimum edit distance is a similar sub-sentence.
Through the steps, the sub-sentences are compared with all the historical sub-sentences according to the editing distance, so that the historical sub-sentence database is updated, or the historical sub-sentence with the minimum editing distance is found as the similar sub-sentence, so that the sentence similarity result is obtained, the to-be-processed tree structure sentence can be processed according to the similar sub-sentence, the problems of high SQL sentence repeatability, high maintenance difficulty and high error rate are solved, and the readability and maintainability of the database SQL sentence are improved.
In some embodiments, the extracting the statement element in the sub-statement according to the statement similarity result, and obtaining the data tag according to the statement element includes:
obtaining a statement blacklist, deleting characters matched with the statement blacklist in the sub-statement, and obtaining a filtering sub-statement;
extracting the part of the filtering sub-statement, which is different from the historical sub-statement, according to the statement similarity result and the historical sub-statement to obtain the statement element;
and acquiring a data tag in the to-be-processed tree structure statement according to the statement element.
Wherein the statement blacklist is used for matching meaningless characters in the statement, including space characters and other potential special characters; the statement element refers to different parts in two similar statements, and the filtering sub-statement which is completely the same as the similar sub-statement does not have any statement element; it should be noted that, after the data tag is obtained, the data tag is matched and labeled with the statement element; the data tag refers to the number of the history sub-statement corresponding to the statement element, and the data tag is used for indicating that the statement element in the sub-statement is a key field.
Through the steps, the tree structure is processed by deleting the meaningless characters and acquiring the data labels, the target tree structure statement is obtained, the data labels used for indicating the statement element key fields in the sub statements can be obtained, the target tree structure statement with a simple structure is obtained, the problems of high repeatability, high maintenance difficulty and high error rate of SQL detection statements are solved, and the readability and maintainability of database SQL statements are improved.
In some embodiments, the processing the tree structure according to the statement similarity result and the data tag to obtain a target tree structure statement includes:
comparing all left subtrees and right subtrees in the to-be-processed tree structure statement according to the statement similarity result and the data label to obtain a comparison result;
and deleting or merging the to-be-processed tree structure statements according to the comparison result to obtain the target tree structure statement.
Wherein, all the left subtrees and all the right subtrees refer to all the left subtrees and all the right subtrees of all the non-leaf nodes in the to-be-processed tree structure statement; the comparison result is to compare whether the left sub-tree and the right sub-tree of any one of the leaf nodes have similar structures and the same data label at the same time.
Specifically, when the comparison result indicates that the left sub-tree and the right sub-tree of any one of the leaf nodes in the to-be-processed tree-structure statement have a similar structure and the same data tag at the same time, an add/delete operation, such as deleting a redundant statement and merging an interval, is performed according to the number range indicated by the statement element, so as to obtain the target tree-structure statement.
Through the steps, the data tags are used for carrying out addition and deletion modification on the tree-shaped structure statement to be processed, the tree-shaped structure statement to be processed can be simplified, so that the target tree-shaped structure statement with a simple structure is obtained, the problems of high repeatability, high maintenance difficulty and high error rate of SQL detection statements are solved, and the readability and maintainability of the database SQL statement are improved.
In some embodiments, the obtaining a tree structure statement to be processed including at least a sub-statement comprises:
obtaining a sentence to be processed and a preset constraint condition, and dividing the sentence to be processed according to the preset constraint condition to obtain a sentence block;
converting the statement to be processed into the tree-shaped structure statement to be processed according to the abstract syntax tree model and the statement block; wherein the tree structure statement to be processed comprises at least a sub-statement.
Wherein, the tree structure sentence to be processed also comprises a father sentence; the Abstract Syntax Tree model (AST) is an Abstract representation of a source code Syntax structure, the Syntax structure of a programming language is represented in a Tree form, each node on the Tree represents one structure in a source code, and the Abstract Syntax Tree model is used for automatically converting a statement to be processed with a linear structure into a Tree structure according to statement logic and a segmented statement block to obtain the statement to be processed with the Tree structure.
Through the steps, the linear statements to be processed are converted into the tree-structure statements to be processed with the tree structure, the efficiency of obtaining the target tree-structure statements can be improved, the problems of high repeatability, high maintenance difficulty and high error rate of SQL detection statements are solved, and the readability and maintainability of the SQL statements of the database are improved.
In some embodiments, after the obtaining the target tree structure statement, the method further includes:
and outputting the target tree structure sentence to the terminal equipment for displaying.
The target tree structure statement may be directly displayed on the terminal device 102, or the target tree structure may be converted into a linear SQL statement structure and displayed on the terminal device 102.
Through the steps, the processed target tree-shaped structural statement can be visually displayed, the problems of high repeatability, high maintenance difficulty and high error rate of the SQL detection statement are solved, and the readability and maintainability of the database SQL statement are improved.
Taking the processing of the database vulnerability detection SQL statement as an example, the embodiment also provides a database statement processing method. Fig. 3 is a flowchart of another database statement processing method according to this embodiment, and as shown in fig. 3, the flowchart includes the following steps:
step S302, a sentence to be processed is input. The statement to be processed is obtained automatically, and at least one statement to be processed is obtained. Specifically, one to-be-processed vulnerability query statement is: select 1from table _1where (select a from table _ a where a >0) and (select b from table _ b) are or (select a from table _ a where a >0) and (select b from table _ b) 1).
Step S304, AST extraction. Acquiring a preset constraint condition, and dividing the statement to be processed according to the preset constraint condition to obtain a statement block; converting the statement to be processed into the tree-shaped structure statement to be processed according to the abstract syntax tree model and the statement block; wherein the tree structure statement to be processed comprises at least a sub-statement. Specifically, the AST extraction result for the to-be-processed vulnerability query statement is shown in fig. 4; fig. 4 is a schematic diagram illustrating the AST extraction result in the present embodiment, in fig. 4, an or is a parent node, and its child nodes are two and; the left subtree of the parent node or is connected with two selection statements in parallel, wherein the condition of one left subtree selection statement is that a is greater than 0, and the condition of the other left subtree selection statement is that b is 1; the right subtree of the parent node or is connected with two selection statements in parallel, wherein the condition of one right subtree selection statement is that a is less than 0, and the condition of the other right subtree selection statement is that b is 1.
Step S306, inputting at least one sub-sentence.
Step S308, sub-sentence comparison. And acquiring a preset editing distance, and carrying out similarity detection on the sub-sentence and the historical sub-sentence according to all current editing distances of the sub-sentence and all historical sub-sentences to obtain a sentence similarity result.
Step S310, determining whether the current edit distance is greater than a preset edit distance. If all the current editing distances are greater than the preset editing distance, the sentence similarity result is null, and step S312 is executed to add the sub-sentence to the historical sub-sentence database; when the current editing distance is smaller than or equal to the preset editing distance, the sentence similarity result indicates that the history sub-sentence corresponding to the current editing distance is a similar sub-sentence; and under the condition that at least two current editing distances are smaller than or equal to the preset editing distance, the sentence similarity result indicates that the history sub-sentence with the minimum current editing distance is a similar sub-sentence. Specifically, the result of comparing the sub-sentences of the to-be-processed tree structure sentence is shown in fig. 5; the history sub-sentence database stores database sentences A: select a from table _ a where a is 1, and database statement B: (select b from table _ b) ═ 1; fig. 5 is a schematic diagram illustrating the result of sentence comparison in this embodiment, in fig. 5, a similar clause with a left sub-tree selection clause condition of a >0 is the history clause with the number a, a similar clause with a left sub-tree selection clause condition of B ═ 1 is the history clause with the number B, a similar clause with a right sub-tree selection clause condition of a < ═ 0 is the history clause with the number a, and a similar clause with a right sub-tree selection clause condition of B ═ 1 is the history clause with the number B.
Step S314, sentence element extraction. Obtaining a statement blacklist, deleting characters matched with the statement blacklist in the sub-statement, and obtaining a filtering sub-statement; extracting the part of the filtering sub-statement, which is different from the historical sub-statement, according to the statement similarity result and the historical sub-statement to obtain statement elements; and acquiring a data tag in the to-be-processed tree structure statement according to the statement element. Specifically, the sentence element extraction result for the to-be-processed tree structure sentence is shown in fig. 6; fig. 6 is a schematic diagram of the statement element extraction result in this embodiment, and in fig. 6, if the element extraction result of the left sub-tree selection statement condition a >0 is "> 0", the data tag is: history sub-statement number a, and element list "> 0"; since the sub-statement with the left sub-tree selection statement condition of B being 1 is the same as the history sub-statement B, the element extraction result is null, and the data tag is: the history sub-sentence number B; similarly, the data tag of the right subtree selection statement with the condition that a < ═ 0 is: the history sub-statement number a, and the element list "< ═ 0", the right sub-tree selection statement condition is that the data tag of b ═ 1 is: the history sub-sentence number B.
Step S316, determine whether to traverse all the sub-sentences. If not, skipping to execute the step S306 to obtain the data label of the next sub-statement; in the case of yes, step S318 is executed.
And step S318, structure optimization. Comparing all left subtrees and right subtrees in the to-be-processed tree structure statement according to the statement similarity result and the data label to obtain a comparison result; and deleting or merging the to-be-processed tree structure statements according to the comparison result to obtain target tree structure statements. Specifically, the structure optimization result for the to-be-processed tree structure statement is shown in fig. 7; fig. 7 is a schematic diagram of a structural optimization result in this embodiment, where "> 0" and "< ═ 0" are complementary intervals, and after they are combined, they are real number sets, and since the value of a is a real number set, the real number set condition is a redundancy condition, and a conditional statement about a is deleted; meanwhile, the condition of (select b from table _ b) ═ 1 is merged, so that the target tree structure statement described in fig. 7 is obtained.
Step S320, combining and outputting the target tree structure statement. The target tree structure statement is directly output to the terminal device 102 for display, or the target tree structure is converted into a linear SQL statement structure and displayed on the terminal device 102. Specifically, in a case that the target tree structure is converted into a linear SQL statement structure and displayed on the terminal device 102, the SQL output result of the database vulnerability detection statement is: select 1from table _1where (select b from table _ b) is 1.
Step S322, determine whether all the statements to be processed are traversed. If yes, the execution of the database statement processing method steps is ended; if not, the step S302 is skipped to, and a next to-be-processed statement is obtained and a next to-be-processed tree structure statement is obtained until all to-be-processed tree structure statements are processed.
It should be noted that, after step S312 is executed, a new number may be directly matched to the sub-statement that is not matched in the history sub-statement database, the new number is used as the data tag of the sub-statement, the sub-statement and the new data tag are stored in the history sub-statement database, and step S322 is executed to obtain the next to-be-processed statement.
Through the steps, the sub-sentence and the historical sub-sentence are subjected to similarity detection to obtain a sentence similarity result, and the data tag is obtained according to the similarity result, so that the tree structure sentence to be processed is processed according to the similarity result and the data tag to obtain the target tree structure sentence.
It should be understood that although the various steps in the flow charts of fig. 2-3 are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least some of the steps in fig. 2-3 may include multiple sub-steps or multiple stages that are not necessarily performed at the same time, but may be performed at different times, and the order of performance of the sub-steps or stages is not necessarily sequential, but may be performed in turn or alternating with other steps or at least some of the sub-steps or stages of other steps.
In this embodiment, a database statement processing apparatus is further provided, and the apparatus is used to implement the foregoing embodiments and preferred embodiments, and the description already made is omitted. The terms "module," "unit," "subunit," and the like as used below may implement a combination of software and/or hardware for a predetermined function. Although the means described in the embodiments below are preferably implemented in software, an implementation in hardware, or a combination of software and hardware is also possible and contemplated.
Fig. 8 is a block diagram showing the structure of the database statement processing apparatus according to the present embodiment, and as shown in fig. 8, the apparatus includes: the device comprises an acquisition module 10, a comparison module 20 and a processing module 30;
the obtaining module 10 is configured to obtain a to-be-processed tree structure statement that at least includes a sub-statement;
the comparing module 20 is configured to obtain a history sub-sentence, and perform similarity detection on the sub-sentence and the history sub-sentence to obtain a sentence similarity result; extracting statement elements in the sub-statement according to the statement similarity result, and acquiring a data tag according to the statement elements;
the processing module 30 is configured to process the tree structure according to the statement similarity result and the data tag, so as to obtain a target tree structure statement.
For specific limitations of the database statement processing apparatus, reference may be made to the above limitations on the database statement processing method, which is not described in detail herein. The modules in the database statement processing device can be wholly or partially realized by software, hardware and a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
In this embodiment, a database statement processing system is further 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;
the server device 104 is configured to execute the steps in the database statement processing method embodiment;
the transmission device is used for transmitting the target tree structure statement to the terminal device;
the terminal device 102 is configured to display the target tree structure sentence.
There is also provided in this embodiment an electronic device comprising a memory having a computer program stored therein and a processor arranged to run the computer program to perform the steps of any of the above method embodiments.
Optionally, the electronic apparatus may further include a transmission device and an input/output device, wherein the transmission device is connected to the processor, and the input/output device is connected to the processor.
Optionally, in this embodiment, the processor may be configured to execute the following steps by a computer program:
s1, obtaining the tree structure sentence to be processed at least including the sub-sentence.
S2, acquiring a history sub-sentence, and carrying out similarity detection on the sub-sentence and the history sub-sentence to obtain a sentence similarity result; and extracting statement elements in the sub-statement according to the statement similarity result, and acquiring the data tags according to the statement elements.
And S3, processing the tree structure according to the sentence similarity result and the data label to obtain a target tree structure sentence.
It should be noted that, for specific examples in this embodiment, reference may be made to the examples described in the foregoing embodiments and optional implementations, and details are not described again in this embodiment.
In addition, in combination with the database statement processing method provided in the foregoing embodiment, a storage medium may also be provided in this embodiment to implement the database statement processing method. The storage medium having stored thereon a computer program; the computer program, when executed by a processor, implements any one of the database statement processing methods in the above embodiments.
In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as shown in fig. 9. The computer device includes a processor, a memory, a network interface, and a database connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile 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 an operating system and computer programs in the non-volatile storage medium. The database of the computer device is used for storing historical sub-sentence data. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement a database statement processing method.
Those skilled in the art will appreciate that the architecture shown in fig. 9 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing devices to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in the embodiments provided herein may include non-volatile and/or volatile memory, among others. Non-volatile memory can include read-only memory (ROM), Programmable ROM (PROM), Electrically Programmable ROM (EPROM), Electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
It should be understood that the specific embodiments described herein are merely illustrative of this application and are not intended to be limiting. All other embodiments, which can be derived by a person skilled in the art from the examples provided herein without any inventive step, shall fall within the scope of protection of the present application.
It is obvious that the drawings are only examples or embodiments of the present application, and it is obvious to those skilled in the art that the present application can be applied to other similar cases according to the drawings without creative efforts. Moreover, it should be appreciated that in the development of any such actual implementation, as in any engineering or design project, numerous implementation-specific decisions must be made to achieve the developers' specific goals, such as compliance with system-related and business-related constraints, which may vary from one implementation to another.
The term "embodiment" is used herein to mean that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the present application. The appearances of such phrases in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. It is to be expressly or implicitly understood by one of ordinary skill in the art that the embodiments described in this application may be combined with other embodiments without conflict.
The above-mentioned embodiments only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the patent protection. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present application shall be subject to the appended claims.

Claims (10)

1. A database statement processing method, comprising:
acquiring a tree structure statement to be processed at least comprising sub-statements;
acquiring a history sub-sentence, and carrying out similarity detection on the sub-sentence and the history sub-sentence to obtain a sentence similarity result; extracting statement elements in the sub-statements according to the statement similarity result, and acquiring data tags according to the statement elements;
and processing the tree structure according to the statement similarity result and the data label to obtain a target tree structure statement.
2. The database statement processing method according to claim 1, characterized in that at least one of the history sub-statements; the performing similarity detection on the sub-sentences and the historical sub-sentences to obtain sentence similarity results includes:
acquiring a preset editing distance and all current editing distances of the sub-sentences and all the historical sub-sentences;
under the condition that all the current editing distances are greater than the preset editing distance, the sentence similarity result is null;
under the condition that one current editing distance is smaller than or equal to the preset editing distance, the sentence similarity result indicates that the history sub-sentence corresponding to the current editing distance is a similar sub-sentence;
and under the condition that at least two current editing distances are smaller than or equal to the preset editing distance, the sentence similarity result indicates that the history sub-sentence with the minimum current editing distance is a similar sub-sentence.
3. The database statement processing method according to claim 1, wherein the extracting statement elements in the sub-statement according to the statement similarity result and obtaining data tags according to the statement elements includes:
obtaining a statement blacklist, deleting characters matched with the statement blacklist in the sub-statements, and obtaining filtering sub-statements;
extracting parts of the filtering sub-sentences different from the historical sub-sentences according to the sentence similarity result and the historical sub-sentences to obtain the sentence elements;
and acquiring a data tag in the to-be-processed tree structure statement according to the statement element.
4. The database statement processing method according to claim 1, wherein the processing the tree structure according to the statement similarity result and the data tag to obtain a target tree structure statement comprises:
comparing all left subtrees and all right subtrees in the to-be-processed tree-structure statement according to the statement similarity result and the data label to obtain a comparison result;
and deleting or merging the to-be-processed tree structure statements according to the comparison result to obtain the target tree structure statement.
5. The database statement processing method according to claim 1, wherein said acquiring a tree structure statement to be processed including at least a sub-statement comprises:
obtaining a sentence to be processed and a preset constraint condition, and dividing the sentence to be processed according to the preset constraint condition to obtain a sentence block;
converting the statement to be processed into the tree-shaped structure statement to be processed according to an abstract syntax tree model and the statement block; wherein the tree structure statement to be processed comprises at least a sub-statement.
6. The database statement processing method according to any one of claims 1 to 5, further comprising, after said obtaining of the target tree structure statement:
and outputting the target tree structure sentence to terminal equipment for displaying.
7. A database statement processing apparatus, comprising: the device comprises an acquisition module, a comparison module and a processing module;
the acquisition module is used for acquiring the to-be-processed tree structure sentence at least comprising the sub-sentences;
the comparison module is used for acquiring historical sub-sentences and carrying out similarity detection on the sub-sentences and the historical sub-sentences to obtain sentence similarity results; extracting statement elements in the sub-statements according to the statement similarity result, and acquiring data tags according to the statement elements;
and the processing module is used for processing the tree structure according to the statement similarity result and the data tag to obtain a target tree structure statement.
8. A database statement processing system, comprising: a terminal device, a transmission device and a server device; the terminal equipment is connected with the server equipment through the transmission equipment;
the server device is used for executing the database statement processing method of any one of claims 1 to 6;
the transmission equipment is used for transmitting the target tree structure statement to the terminal equipment;
and the terminal equipment is used for displaying the target tree structure sentence.
9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute the computer program to perform the database statement processing method according to any one of claims 1 to 6.
10. A computer-readable storage medium on which a computer program is stored, the computer program, when being executed by a processor, implementing the steps of the database statement processing method according to any one of claims 1 to 6.
CN202210586846.2A 2022-05-27 2022-05-27 Database statement processing method, device and system, electronic device and storage medium Pending CN115080562A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210586846.2A CN115080562A (en) 2022-05-27 2022-05-27 Database statement processing method, device and system, electronic device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210586846.2A CN115080562A (en) 2022-05-27 2022-05-27 Database statement processing method, device and system, electronic device and storage medium

Publications (1)

Publication Number Publication Date
CN115080562A true CN115080562A (en) 2022-09-20

Family

ID=83248971

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210586846.2A Pending CN115080562A (en) 2022-05-27 2022-05-27 Database statement processing method, device and system, electronic device and storage medium

Country Status (1)

Country Link
CN (1) CN115080562A (en)

Similar Documents

Publication Publication Date Title
CN111581976B (en) Medical term standardization method, device, computer equipment and storage medium
US10698937B2 (en) Split mapping for dynamic rendering and maintaining consistency of data processed by applications
CN108536745B (en) Shell-based data table extraction method, terminal, equipment and storage medium
WO2015009297A1 (en) Systems and methods for extracting table information from documents
CN112181489B (en) Code migration method, device, computer equipment and storage medium
CN112052138A (en) Service data quality detection method and device, computer equipment and storage medium
CN107608951B (en) Report generation method and system
US10699112B1 (en) Identification of key segments in document images
US20170024439A1 (en) Accelerated detection of matching patterns
CN110334326A (en) A kind of method and system for identifying recipe file and being converted into XML file
CN109657803B (en) Construction of machine learning models
CN111666087A (en) Operation rule updating method and device, computer system and readable storage medium
US20200034724A1 (en) Risk analysis support device, risk analysis support method, and risk analysis support program
US20240037084A1 (en) Method and apparatus for storing data
US9563635B2 (en) Automated recognition of patterns in a log file having unknown grammar
WO2021047327A1 (en) Method and apparatus for constructing target concept map, computer device, and storage medium
CN112148343B (en) Rule issuing method and device and terminal equipment
CN111984659B (en) Data updating method, device, computer equipment and storage medium
CN113760891A (en) Data table generation method, device, equipment and storage medium
CN111752958A (en) Intelligent associated label method, device, computer equipment and storage medium
CN116955856A (en) Information display method, device, electronic equipment and storage medium
CN115080562A (en) Database statement processing method, device and system, electronic device and storage medium
CN115544007A (en) Label preprocessing method and device, computer equipment and storage medium
CN114089980A (en) Programming processing method, device, interpreter and nonvolatile storage medium
Schlie et al. Reengineering variants of matlab/simulink software systems

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination