CN115687399A - Syntax parsing method and device for SQL (structured query language) statements - Google Patents
Syntax parsing method and device for SQL (structured query language) statements Download PDFInfo
- Publication number
- CN115687399A CN115687399A CN202211468137.0A CN202211468137A CN115687399A CN 115687399 A CN115687399 A CN 115687399A CN 202211468137 A CN202211468137 A CN 202211468137A CN 115687399 A CN115687399 A CN 115687399A
- Authority
- CN
- China
- Prior art keywords
- sql
- syntax
- parsing
- syntax tree
- sql statement
- 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
Links
Images
Landscapes
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The application provides a syntax parsing method and a syntax parsing device of SQL statements, wherein the method comprises the following steps: acquiring an SQL statement and an object to be removed; analyzing the SQL statement to obtain a morpheme sequence; determining nodes of a grammar tree based on the morpheme sequence; and under the condition of ignoring the object to be removed, performing node connection on nodes of the syntax tree based on the SQL syntax to obtain the SQL syntax tree. Therefore, by implementing the implementation mode, the specified subtree can be removed in the SQL grammar parsing process, so that the SQL language parsing efficiency is improved.
Description
Technical Field
The application relates to the technical field of data security, in particular to a syntax parsing method and device for SQL statements.
Background
Currently, the SQL language is applied to various industries and plays a great role. However, with the complexity of the use scenario, the nesting use frequency of the SQL syntax starts to increase continuously, so that the resolution complexity of the SQL syntax is directly enhanced, and the resolution efficiency of the SQL syntax is greatly reduced.
Disclosure of Invention
The embodiments of the present application provide a method and an apparatus for parsing a SQL statement, which can remove a designated sub-tree in a SQL syntax parsing process, thereby improving the efficiency of SQL language parsing.
A first aspect of the embodiments of the present application provides a syntax parsing method for an SQL statement, including:
acquiring an SQL statement and an object to be removed;
analyzing the SQL statement to obtain a morpheme sequence;
determining syntax tree nodes based on the morpheme sequence;
and under the condition of neglecting the object to be removed, performing node connection on the nodes of the syntax tree based on the SQL syntax to obtain the SQL syntax tree.
In the implementation process, the method can preferentially acquire the SQL statement and the object to be removed; therefore, in order to reduce the analysis pressure and improve the analysis efficiency, the method selects the removable object which does not influence the analysis effect in advance, and uses the removable object as the object to be removed in the SQL statement, so that the SQL statement can be focused and ignored in the analysis, and the selective grammar analysis effect based on the SQL statement can be realized. Then, the method analyzes the SQL statement based on the condition to obtain a morpheme sequence, and determines a syntax tree node based on the morpheme sequence; therefore, the method can determine the nodes of the syntax tree based on the morphemes in the SQL sentences, and simultaneously, the object to be removed is regarded as the subtree in the syntax tree, so that the method can clearly distinguish the relation tree of the object to be removed at the position, and is convenient for ignoring the analysis of the relation tree in the follow-up process. Based on the result, the method can perform node connection on the nodes of the syntax tree based on the SQL syntax under the condition of ignoring the object to be removed, so as to obtain the SQL syntax tree. Therefore, the method can realize the syntax analysis of the SQL statement on the basis of ignoring the object to be removed to obtain a simple and complete SQL syntax tree, thereby realizing the effect of high-efficiency syntax analysis. Specifically, the object to be removed in the method may be a where module corresponding to a where sub-tree, and the where sub-tree is omitted from the method, so that the where module does not participate in parsing, the syntax parsing process is more efficient, and the result is not inferior to the conventional parsing result.
Further, the step of acquiring the SQL statement and the object to be removed includes:
and acquiring the SQL statement and the object to be removed, and initializing the memory space.
In the implementation process, the method can receive a complete SQL statement through the interface and initialize the memory space at the same time, so that the memory space required by syntax analysis is reserved for the complete SQL statement, the SQL statement can be accurately analyzed conveniently, a plurality of SQL statements can be analyzed synchronously, and mutual interference can be avoided.
Further, the step of analyzing the SQL statement to obtain a morpheme sequence includes:
analyzing the SQL statement to obtain a character stream;
and filtering related characters of the sentences in the character stream to obtain a morpheme sequence.
In the implementation process, the method can analyze the SQL statement preferentially to obtain the character stream in the process of analyzing the SQL statement to obtain the morpheme sequence; therefore, the method can indiscriminately acquire all the characters, and filter the sentence related characters in the character stream, so that the morpheme sequence without related characters such as annotations is obtained, and the analysis precision of the SQL sentence is improved.
Further, the step of performing node connection on the syntax tree nodes based on the SQL syntax to obtain the SQL syntax tree under the condition that the object to be removed is ignored includes:
identifying the object to be removed in the morpheme sequence, and determining the beginning and end positions of the object to be removed in the morpheme sequence;
and under the condition that the objects to be removed are ignored based on the starting and ending positions, carrying out node connection on the nodes of the syntax tree based on the SQL syntax to obtain the SQL syntax tree.
In the implementation process, the method can perform node connection on nodes of the syntax tree based on the SQL syntax under the condition of ignoring the object to be removed, so that in the process of obtaining the SQL syntax tree, the object to be removed can be preferentially identified in the morpheme sequence, and the start and end positions of the object to be removed in the morpheme sequence are determined; therefore, the method can preferentially identify a plurality of objects to be removed with low actual usability, such as where and the like, in the morpheme sequence, and then further identify the start and end positions of the objects to be removed in the morpheme sequence, so that the method is convenient for performing comprehensive neglected removal on the objects to be removed subsequently. Specifically, the method may ignore the object to be removed based on the start and end positions, and perform node connection on nodes of the syntax tree based on the SQL syntax, thereby obtaining the SQL syntax tree from which the object to be removed is removed.
Further, the step of performing node connection on the syntax tree nodes based on the SQL syntax to obtain the SQL syntax tree includes:
analyzing the syntactic structure of the syntactic tree nodes based on SQL grammar and a top-down recursive descent algorithm to obtain a syntactic structure analysis result;
and performing node connection on the nodes of the syntax tree based on the structural analysis result to obtain the SQL syntax tree.
In the implementation process, the method can perform node connection on syntax tree nodes based on SQL syntax to obtain an SQL syntax tree, and preferentially performs syntax structure analysis on the syntax tree nodes based on the SQL syntax and a top-down recursive descent algorithm to obtain a syntax structure analysis result; and then performing node connection on nodes of the syntax tree based on the structural analysis result to obtain the SQL syntax tree. Therefore, the method can generate the SQL syntax tree according to the ground, thereby more accurately realizing the analysis of the SQL statement.
Further, the method further comprises:
performing data desensitization on data to be desensitized according to the SQL syntax tree to obtain desensitization statements;
sending the desensitization statement to a server for submission to obtain a submission result; wherein, the submission result is used for indicating whether the data to be desensitized is desensitized successfully or not.
In the implementation process, after the SQL syntax tree is obtained, data desensitization is carried out on the data to be desensitized according to the SQL syntax tree, and a desensitization statement is obtained; then, sending the desensitization statement to a server for submission to obtain a submission result; wherein, the sending result is used for indicating whether the data to be desensitized is desensitized successfully. Therefore, the method can be based on the big data leakage prevention system, and the SQL syntax analysis of the where subtree is removed is realized, so that the SQL syntax analysis efficiency can be improved, the influence of irrelevant data can be reduced, and the pressure of the data leakage prevention system is reduced.
A second aspect of the embodiments of the present application provides a syntax parsing apparatus for an SQL statement, where the syntax parsing apparatus for the SQL statement includes:
the acquisition unit is used for acquiring the SQL statement and the object to be removed;
the analysis unit is used for analyzing the SQL statement to obtain a morpheme sequence;
a determining unit, configured to determine a syntax tree node based on the morpheme sequence;
and the generating unit is used for performing node connection on the nodes of the syntax tree based on the SQL syntax under the condition of neglecting the object to be removed to obtain the SQL syntax tree.
Further, the obtaining unit is specifically configured to obtain the SQL statement and the object to be removed, and initialize the memory space.
Further, the parsing unit includes:
the analysis subunit is used for analyzing the SQL statement to obtain a character stream;
and the filtering subunit is used for filtering the sentence related characters in the character stream to obtain a morpheme sequence.
Further, the generation unit includes:
the recognition subunit is used for recognizing the object to be removed in the morpheme sequence and determining the beginning and end positions of the object to be removed in the morpheme sequence;
and the generation subunit is used for performing node connection on the nodes of the syntax tree based on the SQL syntax to obtain the SQL syntax tree under the condition that the objects to be removed are ignored based on the starting and ending positions.
Further, the generating subunit includes:
the syntax analysis module is used for carrying out syntax structure analysis on the syntax tree nodes based on SQL syntax and a top-down recursive descent algorithm to obtain a syntax structure analysis result;
and the node connection module is used for performing node connection on the nodes of the syntax tree based on the structural analysis result to obtain the SQL syntax tree.
Further, the syntax parsing apparatus of the SQL statement further includes:
the desensitization unit is used for performing data desensitization on data to be desensitized according to the SQL syntax tree to obtain desensitization statements;
the submission unit is used for sending the desensitization statement to a server for submission to obtain a submission result; wherein, the submission result is used for indicating whether the data to be desensitized is desensitized successfully or not.
A third aspect of the embodiments of the present application provides an electronic device, including a memory and a processor, where the memory is used to store a computer program, and the processor runs the computer program to enable the electronic device to execute the syntax parsing method of an SQL statement according to any one of the first aspect of the embodiments of the present application.
A fourth aspect of the present embodiment provides a computer-readable storage medium, which stores computer program instructions, where the computer program instructions, when read and executed by a processor, perform the syntax parsing method for SQL statements according to any one of the first aspect of the present embodiment.
Drawings
To more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are required to be used in the embodiments of the present application will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered as limiting the scope, and that those skilled in the art can also obtain other related drawings based on the drawings without inventive efforts.
Fig. 1 is a schematic flowchart of a syntax parsing method of an SQL statement according to an embodiment of the present application;
fig. 2 is a schematic flowchart of a syntax parsing method of an SQL statement according to an embodiment of the present application;
fig. 3 is a schematic structural diagram of a syntax parsing apparatus for SQL statements according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of a syntax parsing apparatus for SQL statements according to an embodiment of the present application;
fig. 5 is a schematic flowchart illustrating an example syntax parsing method of an SQL statement according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be described below with reference to the drawings in the embodiments of the present application.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined or explained in subsequent figures. Meanwhile, in the description of the present application, the terms "first", "second", and the like are used only for distinguishing the description, and are not to be construed as indicating or implying relative importance.
Example 1
Referring to fig. 1, fig. 1 is a flow chart illustrating a syntax parsing method of an SQL statement according to this embodiment. The syntax parsing method of the SQL statement comprises the following steps:
s101, obtaining an SQL statement and an object to be removed.
In this embodiment, the method provides an SQL syntax parsing method for a removable where sub-tree based on ANTLR.
In this embodiment, this step may receive a single SQL statement through the interface.
S102, analyzing the SQL statement to obtain a morpheme sequence.
In this embodiment, the method may disassemble a complete SQL statement from the beginning through a lexical analyzer; wherein the generated morpheme sequence is used as a node required for generating a grammar tree.
And S103, determining nodes of the syntax tree based on the morpheme sequence.
In this embodiment, the method may link the nodes from top to bottom based on the association defined by the grammar parser.
And S104, under the condition of ignoring the object to be removed, performing node connection on the nodes of the syntax tree based on the SQL syntax to obtain the SQL syntax tree.
In this embodiment, the method may perform skipping operation when the syntax analyzer encounters all nodes of the where module based on the algorithm for determining the where module, and finally generate a syntax parsing tree for removing the where module, thereby completing the SQL syntax parsing for removing the where module.
In this embodiment, the present application provides an ANTLR-based SQL syntax parsing method for a removable where sub-tree, which may directly modify recognition of relevant syntax of a where sub-tree to implement removal of a corresponding module.
In this embodiment, the execution subject of the method may be a computing device such as a computer and a server, and is not limited in this embodiment.
In this embodiment, an execution subject of the method may also be an intelligent device such as a smart phone and a tablet computer, which is not limited in this embodiment.
In this embodiment, it is considered that the current method can perform syntax parsing on a received single segment of SQL statement to obtain an AST syntax parsing tree; then, traversing the AST syntax parsing tree, matching the AST syntax parsing tree with a metadata base, and extracting information of nodes in the AST syntax parsing tree; and finally, deforming the AST syntax parse tree according to the formulated constraint condition to obtain the deformed AST syntax parse tree. However, in practical application, the complexity of the syntax tree is relatively high, and the current method cannot improve the analysis efficiency to a large extent; when the SQL sentences which are nested more and have higher complexity are faced, the hidden danger of incomplete grammar exists in the method; meanwhile, in many SQL application areas, such as: the database access control is relevant, the actual usability of the where module in the SQL statement is not high, and relevant syntax analysis can be directly skipped. Therefore, the present application provides a method capable of adding a special processing of the where module before the syntax tree of the ANTLR is generated, so as to generate a syntax parse tree without containing the where node in a manner of not parsing the where module. Therefore, the efficient analysis of the SQL grammar is realized, and if the where module needs to be normally analyzed under special conditions, the method can also close the flow of removing the where module, so that the method can analyze the complete SQL sentence traditionally, and further improve the use flexibility of the method.
Therefore, by implementing the syntax parsing method of the SQL statement described in this embodiment, the parsing efficiency of the SQL syntax can be improved, the influence of irrelevant data is reduced, and the pressure of a data leakage prevention system is reduced; meanwhile, the method can be applied to various SQL languages, and the portability of the SQL languages is improved; in addition, the method can perform syntax parsing based on ANTLR, and the ANTLR can support multiple languages, so that the method can easily achieve cross-platform/language support; finally, the method can be linked with other products, so that the method is more universal.
Example 2
Referring to fig. 2, fig. 2 is a flow chart illustrating a syntax parsing method of an SQL statement according to this embodiment. The syntax parsing method of the SQL statement comprises the following steps:
s201, obtaining an SQL statement and an object to be removed, and initializing a memory space.
S202, analyzing the SQL statement to obtain a character stream.
S203, filtering the sentence related characters in the character stream to obtain a morpheme sequence.
And S204, determining nodes of the grammar tree based on the morpheme sequence.
S205, identifying the object to be removed in the morpheme sequence, and determining the beginning and end positions of the object to be removed in the morpheme sequence.
S206, under the condition that the objects to be removed are ignored based on the beginning and end positions, carrying out syntactic structure analysis on nodes of the syntactic tree based on the SQL grammar and a top-down recursive descent algorithm to obtain a syntactic structure analysis result.
And S207, performing node connection on nodes of the syntax tree based on the structural analysis result to obtain the SQL syntax tree.
And S208, performing data desensitization on the data to be desensitized according to the SQL syntax tree to obtain desensitization statements.
S209, sending the desensitization statement to a server for submission to obtain a submission result; wherein, the sending result is used for indicating whether the data to be desensitized is desensitized successfully.
In this embodiment, the method is exemplified as follows based on fig. 5:
(1) In the process of system initialization, a complete SQL statement can be received through an interface, and a memory space is initialized;
(2) ANTLR has compiled the lexical file corresponding to SQL and generates a corresponding lexical analyzer. The interface reads in the input character stream by using the lexical analyzer, filters the related characters such as comments in the input SQL, generates a mark sequence and submits the mark sequence to the grammar analyzer for use;
(3) ANTLR has compiled the corresponding grammar file of SQL and generates the corresponding parser. The interface receives the symbol string provided by the lexical analyzer by using the syntax analyzer, and performs syntactic structure analysis by using a top-down recursive descent LL (—) algorithm according to the corresponding SQL syntax;
(4) In the process of syntactic structure analysis, when encountering a sign 'where', the syntactic analyzer calls a where module algorithm to obtain the starting position and the ending position of the complete where module in the SQL statement, records the number of nested layers, ensures that the whole where module is skipped when the SQL is analyzed, finally generates a syntactic parse tree for removing the where module, and completes the SQL syntactic parse for removing the where module.
In this embodiment, the execution subject of the method may be a computing device such as a computer and a server, and is not limited in this embodiment.
In this embodiment, an execution subject of the method may also be an intelligent device such as a smart phone and a tablet computer, which is not limited in this embodiment.
For example, the method can be applied to the design of a protocol analysis engine of a big data leakage prevention system, and particularly, the method can realize the SQL syntax analysis effect of a removable where sub-tree based on the big data leakage prevention system, so that the SQL syntax analysis efficiency is improved, the influence of irrelevant data is reduced, and the pressure of the data leakage prevention system is reduced.
Among them, according to the method described in the detailed description of the present application, the method can be specifically exemplified as follows:
(1) The system receives SQL sentences which are sent by a client and need to be submitted;
(2) The syntax parsing device parses the SQL statement to generate a corresponding syntax parsing tree with the where subtree removed;
(3) The system carries out data desensitization operation on the module needing desensitization according to the generated syntax parse tree, and sends the desensitized SQL statement to a server for censoring;
(4) Data desensitization was successful by submission.
By implementing the implementation mode, the grammar parser can enter a where module algorithm when encountering a where symbol and the current position is the beginning position of the where module in the process of sequentially reading the symbol stream; at the same time, the symbol stream read pointer is moved, completing the removal. Reading the symbol stream in sequence, counting if the brackets are met, and ending the where module when the semicolon is met or the left bracket number is larger than the right bracket number, wherein the current position is the where module ending position. When the syntax parser generates the syntax tree, the pointer skips the relative nodes in the where module, and the original SQL syntax structure is not changed.
In the embodiment, the method can be used for solving the problem that the complex SQL statement cannot realize optimized analysis because the efficiency optimization degree of the existing SQL grammar analysis is low; the method can also be used for modifying the conventional SQL grammar and solving the problem of hidden danger of incomplete grammar when the SQL sentence with higher complexity is processed. On the basis, the multiple where subtrees are removed, the SQL syntax parsing efficiency is improved, and the syntax parsing efficiency is realized; the integrity of the analysis result is improved by a method for keeping the integrity of the SQL grammar without modifying the SQL grammar; the portability and the universality are improved by configuring and using various SQL languages; and then flexibly adjusting the filling of opening removal and closing removal according to the requirements, thereby meeting two requirements of high-efficiency analysis and complete analysis and further improving the flexibility of grammar analysis.
Therefore, by implementing the syntax parsing method of the SQL statement described in this embodiment, the parsing efficiency of the SQL syntax can be improved, the influence of irrelevant data is reduced, and the pressure of a data leakage prevention system is reduced; meanwhile, the method can be applied to various SQL languages, and the portability of the SQL languages is improved; in addition, the method can be used for carrying out grammar analysis based on ANTLR, and the ANTLR can support multiple languages, so that the method can easily realize cross-platform/language support; finally, the method can be linked with other products, so that the method is more universal.
Example 3
Referring to fig. 3, fig. 3 is a schematic structural diagram of a syntax parsing apparatus for SQL statements provided in this embodiment. As shown in fig. 3, the syntax parsing apparatus for SQL statements includes:
an obtaining unit 310, configured to obtain an SQL statement and an object to be removed;
the parsing unit 320 is configured to parse the SQL statement to obtain a morpheme sequence;
a determining unit 330, configured to determine a syntax tree node based on the morpheme sequence;
the generating unit 340 is configured to perform node connection on syntax tree nodes based on the SQL syntax to obtain the SQL syntax tree, under the condition that the object to be removed is ignored.
In this embodiment, for the explanation of the syntax parsing apparatus for the SQL statement, reference may be made to the description in embodiment 1 or embodiment 2, and details are not repeated in this embodiment.
Therefore, the device can optimize the efficiency of the existing SQL grammar analysis to a lower degree, and solves the problem that the complex SQL sentences can not be optimized and analyzed; the method can also be used for modifying the conventional SQL grammar and solving the problem of hidden danger of incomplete grammar when the SQL sentence with higher complexity is processed. On the basis, the multiple where subtrees are removed, the SQL syntax parsing efficiency is improved, and the syntax parsing efficiency is realized; the integrity of the analysis result is improved by a method for keeping the integrity of the SQL grammar without modifying the SQL grammar; the portability and the universality are improved by configuring and using various SQL languages; and then flexibly adjusting the filling of opening removal and closing removal according to the requirements, thereby meeting two requirements of high-efficiency analysis and complete analysis and further improving the flexibility of grammar analysis.
Therefore, by implementing the syntax parsing device for the SQL statement described in the embodiment, the parsing efficiency of the SQL statement can be improved, the influence of irrelevant data can be reduced, and the pressure of a data leakage prevention system can be reduced; meanwhile, the method can be applied to various SQL languages, and the portability of the SQL languages is improved; in addition, the method can be used for carrying out grammar analysis based on ANTLR, and the ANTLR can support multiple languages, so that the method can easily realize cross-platform/language support; finally, the method can be linked with other products, so that the method is more universal.
Example 4
Referring to fig. 4, fig. 4 is a schematic structural diagram of a syntax parsing apparatus for SQL statements provided in this embodiment. As shown in fig. 4, the syntax parsing apparatus for SQL statements includes:
an obtaining unit 310, configured to obtain an SQL statement and an object to be removed;
the parsing unit 320 is configured to parse the SQL statement to obtain a morpheme sequence;
a determining unit 330, configured to determine a syntax tree node based on the morpheme sequence;
the generating unit 340 is configured to perform node connection on syntax tree nodes based on the SQL syntax to obtain the SQL syntax tree, under the condition that the object to be removed is ignored.
As an optional implementation manner, the obtaining unit 310 is specifically configured to obtain the SQL statement and the object to be removed, and initialize the memory space.
As an optional implementation manner, the parsing unit 320 includes:
the parsing subunit 321 is configured to parse the SQL statement to obtain a character stream;
and a filtering subunit 322, configured to filter the sentence-related characters in the character stream to obtain a morpheme sequence.
As an optional implementation manner, the generating unit 340 includes:
an identifying subunit 341, configured to identify an object to be removed in the morpheme sequence, and determine a start position and a end position of the object to be removed in the morpheme sequence;
the generating subunit 342 is configured to, when the object to be removed is ignored based on the start and end positions, perform node connection on nodes of the syntax tree based on the SQL syntax, so as to obtain the SQL syntax tree.
As an alternative embodiment, the generating subunit 342 includes:
the syntax analysis module is used for carrying out syntax structure analysis on syntax tree nodes based on SQL syntax and a top-down recursive descent algorithm to obtain a syntax structure analysis result;
and the node connection module is used for performing node connection on the nodes of the syntax tree based on the structural analysis result to obtain the SQL syntax tree.
As an optional implementation manner, the syntax parsing apparatus for SQL statements further includes:
the desensitization unit 350 is configured to perform data desensitization on data to be desensitized according to the SQL syntax tree to obtain a desensitization statement;
the submission unit 360 is used for sending the desensitization statement to the server for submission to obtain a submission result; wherein, the sending result is used for indicating whether the data to be desensitized is desensitized successfully.
In this embodiment, the description in embodiment 1 or embodiment 2 may be referred to for the explanation of the syntax parsing apparatus for the SQL statement, and details are not repeated in this embodiment.
Therefore, by implementing the syntax parsing device for the SQL statement described in the embodiment, the parsing efficiency of the SQL statement can be improved, the influence of irrelevant data can be reduced, and the pressure of a data leakage prevention system can be reduced; meanwhile, the method can be applied to various SQL languages, and the portability of the SQL languages is improved; in addition, the method can be used for carrying out grammar analysis based on ANTLR, and the ANTLR can support multiple languages, so that the method can easily realize cross-platform/language support; finally, the method can be linked with other products, so that the method is more universal.
The embodiment of the present application provides an electronic device, which includes a memory and a processor, where the memory is used to store a computer program, and the processor runs the computer program to make the electronic device execute a syntax parsing method of an SQL statement in embodiment 1 or embodiment 2 of the present application.
An embodiment of the present application provides a computer-readable storage medium, which stores computer program instructions, where the computer program instructions, when read and executed by a processor, perform a syntax parsing method for an SQL statement in embodiment 1 or embodiment 2 of the present application.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method can be implemented in other ways. The apparatus embodiments described above are merely illustrative, and for example, the flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
In addition, functional modules in the embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
The functions, if implemented in the form of software functional modules and sold or used as a stand-alone product, may be stored in a computer-readable storage medium. Based on such understanding, the technical solution of the present application or portions thereof that substantially contribute to the prior art may be embodied in the form of a software product stored in a storage medium and including instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The above description is only an example of the present application and is not intended to limit the scope of the present application, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, improvement and the like made within the spirit and principle of the present application shall be included in the protection scope of the present application. It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
The above description is only for the specific embodiments of the present application, but the scope of the present application is not limited thereto, and any person skilled in the art can easily think of the changes or substitutions within the technical scope of the present application, and shall be covered by the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.
It should be noted that, in this document, relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrases "comprising a," "8230," "8230," or "comprising" does not exclude the presence of additional like elements in a process, method, article, or apparatus that comprises the element.
Claims (10)
1. A syntax parsing method of SQL statements is characterized by comprising the following steps:
acquiring an SQL statement and an object to be removed;
analyzing the SQL statement to obtain a morpheme sequence;
determining syntax tree nodes based on the morpheme sequence;
and under the condition of neglecting the object to be removed, performing node connection on the nodes of the syntax tree based on the SQL syntax to obtain the SQL syntax tree.
2. The syntax parsing method of SQL statement according to claim 1, wherein the step of acquiring the SQL statement and the object to be removed comprises:
and acquiring the SQL statement and the object to be removed, and initializing the memory space.
3. The method for parsing the syntax of an SQL statement according to claim 1, wherein the step of parsing the SQL statement to obtain a morpheme sequence comprises:
analyzing the SQL sentence to obtain a character stream;
and filtering related characters of the sentences in the character stream to obtain a morpheme sequence.
4. The method for parsing a syntax of an SQL statement according to claim 1, wherein the step of performing node connection on the syntax tree nodes based on an SQL syntax to obtain an SQL syntax tree under the condition that the object to be removed is ignored comprises:
identifying the object to be removed in the morpheme sequence, and determining the beginning and end positions of the object to be removed in the morpheme sequence;
and under the condition that the objects to be removed are ignored based on the starting and ending positions, carrying out node connection on the nodes of the syntax tree based on the SQL syntax to obtain the SQL syntax tree.
5. The method for parsing an SQL statement according to claim 1, wherein the step of performing node connection on the nodes of the syntax tree based on an SQL syntax to obtain an SQL syntax tree comprises:
carrying out syntactic structure analysis on the syntactic tree nodes based on SQL grammar and a top-down recursive descent algorithm to obtain a syntactic structure analysis result;
and performing node connection on the nodes of the syntax tree based on the structural analysis result to obtain the SQL syntax tree.
6. The syntax parsing method of an SQL statement according to claim 1, wherein the method further comprises:
carrying out data desensitization on data to be desensitized according to the SQL syntax tree to obtain desensitization statements;
sending the desensitization statement to a server for submission to obtain a submission result; wherein, the submission result is used for indicating whether the data to be desensitized is desensitized successfully or not.
7. A syntax parsing apparatus for SQL statements, comprising:
the acquisition unit is used for acquiring the SQL statement and the object to be removed;
the analysis unit is used for analyzing the SQL statement to obtain a morpheme sequence;
a determining unit, configured to determine a syntax tree node based on the morpheme sequence;
and the generating unit is used for carrying out node connection on the nodes of the syntax tree based on the SQL syntax under the condition of ignoring the object to be removed so as to obtain the SQL syntax tree.
8. The apparatus for parsing an SQL statement according to claim 7, wherein the apparatus for parsing an SQL statement further comprises:
the desensitization unit is used for performing data desensitization on data to be desensitized according to the SQL syntax tree to obtain desensitization statements;
the submission unit is used for sending the desensitization statement to a server for submission to obtain a submission result; wherein, the submission result is used for indicating whether the data to be desensitized is desensitized successfully or not.
9. An electronic device, comprising a memory for storing a computer program and a processor for executing the computer program to cause the electronic device to perform the syntax parsing method of the SQL statement according to any of claims 1 to 6.
10. A readable storage medium having stored therein computer program instructions which, when read and executed by a processor, perform the syntax parsing method of SQL statements according to any one of claims 1 to 6.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211468137.0A CN115687399A (en) | 2022-11-22 | 2022-11-22 | Syntax parsing method and device for SQL (structured query language) statements |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211468137.0A CN115687399A (en) | 2022-11-22 | 2022-11-22 | Syntax parsing method and device for SQL (structured query language) statements |
Publications (1)
Publication Number | Publication Date |
---|---|
CN115687399A true CN115687399A (en) | 2023-02-03 |
Family
ID=85054040
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202211468137.0A Pending CN115687399A (en) | 2022-11-22 | 2022-11-22 | Syntax parsing method and device for SQL (structured query language) statements |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN115687399A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117370377A (en) * | 2023-12-05 | 2024-01-09 | 子亥科技(成都)有限公司 | Three-dimensional scene management method and device based on structured query language |
-
2022
- 2022-11-22 CN CN202211468137.0A patent/CN115687399A/en active Pending
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117370377A (en) * | 2023-12-05 | 2024-01-09 | 子亥科技(成都)有限公司 | Three-dimensional scene management method and device based on structured query language |
CN117370377B (en) * | 2023-12-05 | 2024-02-06 | 子亥科技(成都)有限公司 | Three-dimensional scene management method and device based on structured query language |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN107451153B (en) | Method and device for outputting structured query statement | |
KR102230661B1 (en) | SQL review methods, devices, servers and storage media | |
CN110502227B (en) | Code complement method and device, storage medium and electronic equipment | |
US20110202331A1 (en) | Method and software for extracting chemical data | |
US7779049B1 (en) | Source level optimization of regular expressions | |
CN102439590A (en) | System and method for automatic semantic labeling of natural language texts | |
CN111176650B (en) | Parser generation method, search method, server, and storage medium | |
CN115687399A (en) | Syntax parsing method and device for SQL (structured query language) statements | |
CN112732743B (en) | Data analysis method and device based on Chinese natural language | |
JP2022105474A (en) | Method for verifying vulnerabilities of network devices using cve entries | |
CN113032371A (en) | Database grammar analysis method and device and computer equipment | |
CN112948419A (en) | Query statement processing method and device | |
CN108008947B (en) | Intelligent prompting method and device for programming statement, server and storage medium | |
CN113032366A (en) | SQL syntax tree analysis method based on Flex and Bison | |
CN114020898B (en) | Man-machine automatic dialogue method, device, electronic equipment and storage medium | |
CN109923538B (en) | Text search device, text search method, and computer program | |
CN114089980A (en) | Programming processing method, device, interpreter and nonvolatile storage medium | |
CN111859929B (en) | Data visualization method and device and related equipment thereof | |
CN114282529A (en) | Grammar inquiry method, system and computer storage medium | |
KR20100080345A (en) | System and method for prompting an end user with a preferred sequence of commands which performs an activity in a least number of inputs | |
CN111522554A (en) | Method and system for linear generalized LL recognition and context-aware parsing | |
CN114510922B (en) | Text matching method and device | |
CN111381814A (en) | Method and device for generating syntax tree of code file and electronic equipment | |
CN117785884B (en) | Graph logic execution plan generation method of graph query statement, data processing method and device | |
CN114661917B (en) | Text augmentation method, system, computer device and readable storage medium |
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 |