SQL statement auditing processing method and device, computer equipment and storage medium
By obtaining SQL statements from multiple sources and auditing according to multiple preset rules, the shortcomings of existing tools in terms of SQL statement types and audit rules coverage are solved, and better audit results are achieved.
Patent Information
- Application Number
- CN202411310198.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-19
- Publication Date
- 2025-02-11
AI Technical Summary
The existing SQL statement review tools lack in handling SQL statement types and audit rules coverage, resulting in poor audit results.
The first and second audit results are generated by obtaining the collection of SQL statements to be reviewed from multiple sources and auditing them in sequence according to multiple preset statement rules and collection rules.
It improves the coverage of SQL statements and the diversity of audit rules, increases the coverage of the rules, and ensures better audit results.
Smart Images

Figure CN119415148A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a SQL statement audit processing method, device, computer equipment and readable storage medium. Background Art
[0002] SQL (Structured Query Language) statement auditing is an important part of database management and related application development. Effective SQL statement auditing can improve database applications in many aspects, such as code specification compliance, code quality assurance, security verification, performance optimization, etc.
[0003] At present, there are many commercial or open source SQL statement auditing tools, but the existing products are slightly lacking in terms of the types of SQL statements they process; in terms of auditing rules, each product is based on its own experience, and the coverage of the rules varies, which cannot guarantee better auditing results. Summary of the invention
[0004] In view of this, the present application provides a SQL statement audit processing method, apparatus, computer device and readable storage medium.
[0005] In a first aspect, an embodiment of the present application provides a SQL statement audit processing method, including:
[0006] Acquire a set of SQL statements to be reviewed from multiple sources, wherein the set of SQL statements includes multiple SQL statements;
[0007] Reviewing the SQL statements in the SQL statement set in sequence according to a plurality of preset statement rules to generate a first review result;
[0008] After all SQL statements in the SQL statement set are reviewed, the SQL statement set is reviewed according to a preset set rule to generate a second review result.
[0009] In a second aspect, an embodiment of the present application provides a SQL statement audit processing device, including:
[0010] A statement acquisition module, used to acquire a set of SQL statements to be reviewed from multiple sources, wherein the set of SQL statements includes multiple SQL statements;
[0011] A first review module, configured to review the SQL statements in the SQL statement set in sequence according to a plurality of preset statement rules, and generate a first review result;
[0012] The second audit module is used to audit the SQL statement set according to preset set rules after all SQL statements in the SQL statement set have been audited, and generate a second audit result.
[0013] In a third aspect, an embodiment of the present application provides a computer device, which includes a processor and a memory, wherein the memory stores programs or instructions that can be executed on the processor, and when the programs or instructions are executed by the processor, the steps of the method of the first aspect are implemented.
[0014] In a fourth aspect, an embodiment of the present application provides a readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, the steps of the method of the first aspect are implemented.
[0015] In a fifth aspect, an embodiment of the present application provides a chip, which includes a processor and a communication interface, wherein the communication interface and the processor are coupled, and the processor is used to run programs or instructions to implement the method of the first aspect.
[0016] In a sixth aspect, an embodiment of the present application provides a computer program product, which is stored in a storage medium and is executed by at least one processor to implement the method of the first aspect.
[0017] In an embodiment of the present application, a set of SQL statements to be reviewed is obtained from multiple sources. First, the SQL statements in the set of SQL statements are reviewed in sequence according to multiple preset statement rules. After all the SQL statements in the set of SQL statements have been reviewed, the set of SQL statements is reviewed according to the preset set rules. The present application obtains SQL statements from multiple sources, thereby improving the coverage of SQL statements. By reviewing through multiple statement rules and set rules, the diversity of review rules is improved, the coverage of rules is increased, and a better review effect is ensured.
[0018] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0020] Figure 1 One of the flow diagrams of the SQL statement audit processing method according to the embodiment of the present application is shown;
[0021] Figure 2 A schematic diagram showing an audit rule interface of an embodiment of the present application is shown;
[0022] Figure 3 The second flowchart of the SQL statement audit processing method according to the embodiment of the present application is shown;
[0023] Figure 4 The third flowchart of the SQL statement audit processing method according to the embodiment of the present application is shown;
[0024] Figure 5 A structural block diagram of a SQL statement audit processing device according to an embodiment of the present application is shown;
[0025] Figure 6 A structural block diagram of a computer device according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0026] The following will be combined with the drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the present application belong to the scope of protection of this application.
[0027] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.
[0028] The following, in conjunction with the accompanying drawings, describes in detail the SQL statement audit processing method, apparatus, computer device and readable storage medium provided in the embodiments of the present application through specific embodiments and their application scenarios.
[0029] The present application embodiment provides a SQL statement audit processing method, such as Figure 1 As shown, the method includes:
[0030] Step 101: Obtain a set of SQL statements to be reviewed from multiple sources, where the set of SQL statements includes multiple SQL statements.
[0031] In this step, one or more SQL statement sets to be reviewed are obtained from multiple sources. A SQL statement set is a group of SQL statements. Each SQL statement set includes multiple SQL statements. The multiple SQL statements included in each SQL statement set are related. For example, the multiple SQL statements included in a SQL statement set can jointly implement a matter.
[0032] In one embodiment of the present application, a set of SQL statements to be reviewed is obtained from multiple sources, including: obtaining a set of SQL statements to be reviewed from multiple sources, wherein the multiple sources include at least two of the following: Java program files, Mybatis configuration files, SQL statement files, database history cache, and MySQL slow logs.
[0033] In this embodiment, flexible acquisition of SQL statements is achieved, and SQL statements can be obtained from multiple sources such as program source code, Mybatis configuration files, SQL statement files, database history cache, MySQL slow logs, etc., thereby improving the coverage of SQL statements.
[0034] Specifically, the present application can extract the embedded SQL statement text by analyzing the Java program source file. In particular, the spliced SQL statements can also be extracted and the variables therein can be automatically replaced under the premise of ensuring the grammatical correctness. For example, for the following statement:
[0035] String SQL2="SELECT A,B FROM USER.TAB"+"WHERE ID=1AND"+"NAME='"+username+"'";
[0036] The extracted SQL statement is:
[0037] SELECT A,B FROM USER.TAB WHERE ID=1AND NAME='auto_1'
[0038] You can analyze the configuration files of different versions of Mybatis and extract SQL statements from them. In particular, the dynamic conditions in the Mybatis configuration files can be automatically spliced into the SQL statement body for review. The dynamic conditions in the Mybatis configuration files mainly refer to the SQL statements dynamically constructed according to different conditions through specific tags and syntax in the Mybatis mapping files (mapper XML files). This method makes the writing of SQL statements more flexible and can adapt to different query requirements.
[0039] This application supports reading SQL statements from SQL statement files in plain text or Excel format for auditing. This application can directly read statements in the Oracle database historical SQL cache. This application can directly extract SQL statements from MySQL slow logs.
[0040] In one embodiment of the present application, a set of SQL statements to be reviewed is obtained from multiple sources, including: in response to a target instruction, a set of SQL statements to be reviewed is obtained from multiple sources, wherein the target instruction includes any one of an instruction in a programming language development environment, a command line call instruction, and an API call instruction.
[0041] In this embodiment, lightweight deployment is adopted, and multiple ways of triggering SQL statement auditing are provided, including: IDEA plug-in instructions (that is, instructions in the programming language development environment), command line call instructions, API call instructions, etc. Users can audit SQL statements through the user interface at different stages, including during development, operation or system management.
[0042] For example, in response to the review needs of developers, this application provides an IDEA plug-in for optional use. In the IDEA development environment, you can directly select SQL statements for review through the right-click menu of the mouse, or you can directly scan the SQL statements in the entire project for review.
[0043] For a single SQL statement or multiple SQL statements that have been obtained, a command line call method is provided, which can flexibly perform audits without the help of any dependent tools.
[0044] In most enterprises, there are often various comprehensive audit platforms. Although platform deployment is conducive to centralized management, it is slightly lacking in flexibility. This application provides a complete API call interface, which can be easily used by other applications in a library-dependent manner. It can be directly embedded in the corresponding existing platform to achieve auditing without building a platform, which reduces costs and improves the flexibility of auditing.
[0045] The embodiments of the present application can take into account the audit requirements of SQL statements at different stages, and can adopt lightweight deployment without the need to build a platform, thereby improving the flexibility of the audit.
[0046] Step 102: review the SQL statements in the SQL statement set in sequence according to a plurality of preset statement rules to generate a first review result.
[0047] In this step, the audit engine audits each SQL statement in the SQL statement set in turn according to a plurality of preset statement rules to obtain an audit result of the SQL statement, that is, a first audit result.
[0048] In one embodiment of the present application, the SQL statements in the SQL statement set are reviewed in sequence according to a plurality of preset statement rules to generate a first review result, including:
[0049] For any SQL statement in the SQL statement set, multiple preset statement rules are reviewed in sequence to generate a first review result; wherein the multiple preset statement rules include expression rules, syntax tree rules, and execution plan rules, the expression rules include using regular expressions to determine whether there are strings that do not comply with writing specifications in the SQL statement to be reviewed, the syntax tree rules include determining whether there are strings that do not comply with grammatical specifications in the SQL statement to be reviewed based on the syntax tree, and the execution plan rules include determining whether the SQL statement to be reviewed satisfies the regular expression.
[0050] In this embodiment, the plurality of preset statement rules may include expression rules, syntax tree rules, execution plan rules, etc., and the order of reviewing the plurality of preset statement rules is not specifically limited. Through the expression rules, it is possible to use regular expressions to determine whether there are strings that do not conform to the writing specifications in the SQL statement to be reviewed, through the syntax tree rules, it is possible to determine whether there are strings that do not conform to the syntax specifications in the SQL statement to be reviewed according to the syntax tree, and through the execution plan rules, it is possible to determine whether the SQL statement to be reviewed satisfies the regular expression.
[0051] The embodiment of the present application can audit the expression rules, syntax tree rules, and execution plan rules of SQL statements to ensure comprehensive auditing and better results.
[0052] In one embodiment, a unified audit rule interface Rule is defined, and different sub-interfaces of the audit rule interface represent different types of statement rules. Figure 2 As shown, the syntax tree rule inherits the subinterface ASTRule of the audit rule interface Rule, the expression rule inherits another subinterface PatternRule, and the execution plan rule inherits another subinterface ExplainRule. In other words, in addition to supporting expression rules and syntax tree rules, this application also supports connecting to the database to obtain the execution plan and using ExplainRule to audit the execution plan. Its main purpose is to analyze the performance of SQL statements.
[0053] This application implements statement rule review of SQL statements based on the form of defined interfaces, without the need to build a platform, thereby improving the flexibility of the review.
[0054] When conducting an audit, depending on the audit rules, the audit can be offline or static. Offline and static mean that the audit engine can conduct the audit without connecting to any database, such as expression rules and syntax tree rules. It can also be actively connected to a target database to perform corresponding operations, and the operation results or the operation results are used as an aid, that is, online, such as executing plan rules. This application supports both offline and online audits.
[0055] Step 103: After all SQL statements in the SQL statement set have been reviewed, the SQL statement set is reviewed according to a preset set rule to generate a second review result.
[0056] In this step, after all SQL statements in the SQL statement set are audited, the audit engine audits the SQL statement set according to the preset set rules to generate an audit result of the SQL statement set, that is, a second audit result.
[0057] In one embodiment of the present application, the SQL statement set is audited according to a preset set rule to generate a second audit result, including: determining the execution result corresponding to the SQL statement set, auditing the execution result, and generating a second audit result.
[0058] In this embodiment, the preset set rule refers to auditing the execution results corresponding to the SQL statement set to complete the overall audit of the SQL statement set. For example, multiple SQL statements in a set of SQL statements may be for completing one thing, such as the first SQL statement is to create a table, the second SQL statement adds a foreign key to the table, and the third SQL statement adds a comment to the table. The preset set rule is to audit the execution results of this set of SQL statements. For example, it can be determined whether the primary key is set for the table after the three statements are executed. In the above manner, the SQL statement set can be audited as a whole, the audit types are increased, and the audit effect is improved.
[0059] In the embodiment of the present application, a set of SQL statements to be reviewed is obtained from multiple sources. First, the SQL statements in the set of SQL statements are reviewed in sequence according to multiple preset statement rules. After all the SQL statements in the set of SQL statements are reviewed, the set of SQL statements is reviewed according to the preset set rules. The present application obtains SQL statements from multiple sources, thereby improving the coverage of SQL statements. By reviewing through multiple statement rules and set rules, the diversity of review rules is improved, the coverage of rules is increased, and a better review effect is ensured.
[0060] The SQL statement auditing solution of this application can not only improve the security, performance and code quality of the database, but also facilitate troubleshooting and accountability, and support business decision-making.
[0061] As a refinement and extension of the above embodiment, the embodiment of the present invention provides another SQL statement audit processing method, such as Figure 3 As shown, the method includes:
[0062] Step 301, obtaining a database type, and creating a syntax tree parser according to the database type, the syntax tree parser is used to convert an SQL statement into a syntax tree when performing syntax tree rule review on the SQL statement;
[0063] Step 302, loading a plurality of preset statement rules and preset set rules into a configuration file;
[0064] Step 303, obtaining a set of SQL statements to be reviewed from multiple sources, wherein the set of SQL statements includes multiple SQL statements;
[0065] Step 304, reviewing the SQL statements in the SQL statement set in sequence according to a plurality of preset statement rules, and generating a first review result;
[0066] Step 305: After all SQL statements in the SQL statement set have been reviewed, the SQL statement set is reviewed according to a preset set rule to generate a second review result.
[0067] In this embodiment, if Figure 4 As shown, the database type is obtained and a syntax tree parser is created accordingly, and then audit rules such as statement rules and collection rules are loaded from the configuration file. The configuration file can be specified again during execution, and the initialization of the audit engine is completed. Furthermore, SQL statements can be obtained from multiple sources and audited.
[0068] This application supports different databases, can use corresponding syntax trees for parsing, and can set different audit rules for auditing. It currently supports Oracle, MySQL, Postgresql, Gauss and other database products.
[0069] The metadata information of all audit rules is saved in the configuration file (rule.cfg). The metadata of each audit rule includes: rule name, rule category, alarm level, whether to enable, rule personalized parameters and other configuration items. It should be noted that for each audit, you can set whether each rule is enabled or not. These can be written in the configuration file, passed in through command line parameters, and can be modified as needed at runtime.
[0070] In one embodiment of the present application, the method further includes:
[0071] Define an audit rule interface, the audit rule interface includes a first sub-interface and a second sub-interface;
[0072] Creating a syntax tree rule based on the first sub-interface, and creating an expression rule based on the second sub-interface;
[0073] The creating of the syntax tree rule based on the first sub-interface includes: when adding the syntax tree rule, creating a target class to implement the first sub-interface of the audit rule interface; and packaging the target class, and placing the packaged target class into the class path of the audit engine;
[0074] Creating an expression rule based on the second sub-interface includes: when adding the expression rule, adding a configuration item corresponding to the expression rule in the configuration file.
[0075] In this embodiment, a unified audit rule interface Rule is defined, and different sub-interfaces of the audit rule interface represent different types of statement rules. The syntax tree rule inherits the sub-interface ASTRule (i.e., the first sub-interface) of the audit rule interface Rule, and the expression rule inherits another sub-interface PatternRule (i.e., the second sub-interface).
[0076] If you need to add a new syntax tree rule, create a target class to implement the first sub-interface, package the target class to obtain a jar package, and then place the jar package in the class path of the audit engine. If you need to add a new expression rule, add the configuration item corresponding to the expression rule in the configuration file.
[0077] The embodiment of the present application can add audit rules in real time through configuration, achieving flexible customization of rules without requiring a long development and implementation cycle.
[0078] Furthermore, as a specific implementation of the above-mentioned SQL statement audit processing method, the embodiment of the present application provides a SQL statement audit processing device. Figure 5 As shown, the SQL statement audit processing device 500 includes: a statement acquisition module 501, a first audit module 502 and a second audit module 503.
[0079] The statement acquisition module 501 is used to acquire a set of SQL statements to be reviewed from multiple sources, wherein the set of SQL statements includes multiple SQL statements;
[0080] A first review module 502 is used to review the SQL statements in the SQL statement set in sequence according to a plurality of preset statement rules to generate a first review result;
[0081] The second review module 503 is used to review the SQL statement set according to a preset set rule after all SQL statements in the SQL statement set have been reviewed, and generate a second review result.
[0082] In the embodiment of the present application, a set of SQL statements to be reviewed is obtained from multiple sources. First, the SQL statements in the set of SQL statements are reviewed in sequence according to multiple preset statement rules. After all the SQL statements in the set of SQL statements are reviewed, the set of SQL statements is reviewed according to the preset set rules. The present application obtains SQL statements from multiple sources, thereby improving the coverage of SQL statements. By reviewing through multiple statement rules and set rules, the diversity of review rules is improved, the coverage of rules is increased, and a better review effect is ensured.
[0083] Furthermore, the statement acquisition module 501 is specifically used to: acquire a set of SQL statements to be reviewed from multiple sources, wherein the multiple sources include at least two of the following: Java program files, Mybatis configuration files, SQL statement files, database history cache, and MySQL slow logs.
[0084] Furthermore, the statement acquisition module 501 is specifically used to: in response to a target instruction, acquire a set of SQL statements to be reviewed from multiple sources, wherein the target instruction includes any one of an instruction in a programming language development environment, a command line call instruction, and an API call instruction.
[0085] Furthermore, the first audit module 502 is specifically used to: audit any SQL statement in the SQL statement set in sequence according to multiple preset statement rules to generate a first audit result; wherein the multiple preset statement rules include expression rules, syntax tree rules, and execution plan rules, the expression rules include using regular expressions to determine whether there are any strings that do not comply with the writing specifications in the SQL statement to be audited, the syntax tree rules include determining whether there are any strings that do not comply with the grammatical specifications in the SQL statement to be audited based on the syntax tree, and the execution plan rules include determining whether the SQL statement to be audited satisfies the regular expression.
[0086] Furthermore, the second audit module 503 is specifically used to determine the execution result corresponding to the SQL statement set, audit the execution result, and generate a second audit result.
[0087] Furthermore, the device also includes: a loading module, which is used to:
[0088] Before reviewing the SQL statement, the database type is obtained, and a syntax tree parser is created according to the database type. The syntax tree parser is used to convert the SQL statement into a syntax tree when reviewing the syntax tree rules of the SQL statement.
[0089] Load multiple preset statement rules and preset collection rules in the configuration file.
[0090] Furthermore, the device also includes: a rule creation module, which is used to:
[0091] Define an audit rule interface, the audit rule interface includes a first sub-interface and a second sub-interface;
[0092] Creating a syntax tree rule based on the first sub-interface, and creating an expression rule based on the second sub-interface;
[0093] The creating of the syntax tree rule based on the first sub-interface includes: when adding the syntax tree rule, creating a target class to implement the first sub-interface of the audit rule interface; and packaging the target class, and placing the packaged target class into the class path of the audit engine;
[0094] Creating an expression rule based on the second sub-interface includes: when adding the expression rule, adding a configuration item corresponding to the expression rule in the configuration file.
[0095] The SQL statement audit processing device 500 in the embodiment of the present application can be a computer device, or a component in a computer device, such as an integrated circuit or a chip. Figure 1 , Figure 3 and Figure 4 To avoid repetition, the various processes implemented in the SQL statement audit processing method embodiment are not described here.
[0096] The present application also provides a computer device, such as Figure 6 As shown, the computer device 600 includes a processor 601 and a memory 602. The memory 602 stores programs or instructions that can be executed on the processor 601. When the program or instruction is executed by the processor 601, the various steps of the above-mentioned SQL statement audit processing method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0097] The memory 602 can be used to store software programs and various data. The memory 602 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, an application program or instructions required for at least one function (such as a sound playback function, an image playback function, etc.), etc. In addition, the memory 602 may include a volatile memory or a non-volatile memory, or the memory 602 may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), a static random access memory (SRAM), a dynamic random access memory (DRAM), a synchronous dynamic random access memory (SDRAM), a double data rate synchronous dynamic random access memory (DDRSDRAM), an enhanced synchronous dynamic random access memory (ESDRAM), a synchronous link dynamic random access memory (SLDRAM) and a direct memory bus random access memory (DRRAM). The memory 602 in the embodiment of the present application includes but is not limited to these and any other suitable types of memory.
[0098] The processor 601 may include one or more processing units; optionally, the processor 601 integrates an application processor and a modem processor, wherein the application processor mainly processes operations related to an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communication signals, such as a baseband processor. It is understandable that the modem processor may not be integrated into the processor 601.
[0099] The embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by the processor, each process of the above-mentioned SQL statement audit processing method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0100] An embodiment of the present application also provides a chip, which includes a processor and a communication interface. The communication interface and the processor are coupled, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned SQL statement audit processing method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0101] It should be understood that the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.
[0102] The embodiment of the present application also provides a computer program product, which is stored in a storage medium. The program product is executed by at least one processor to implement the various processes of the above-mentioned SQL statement audit processing method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0103] It should be noted that, in this article, the terms "comprise", "include" or any other variant thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise one..." do not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved, for example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.
[0104] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
Claims
1. A SQL statement audit processing method, characterized in that: include: Acquire a set of SQL statements to be reviewed from multiple sources, wherein the set of SQL statements includes multiple SQL statements; Reviewing the SQL statements in the SQL statement set in sequence according to a plurality of preset statement rules to generate a first review result; After all SQL statements in the SQL statement set are reviewed, the SQL statement set is reviewed according to a preset set rule to generate a second review result.
2. The method according to claim 1, characterized in that The SQL statement set to be reviewed is obtained from multiple sources, including: A set of SQL statements to be reviewed is obtained from multiple sources, wherein the multiple sources include at least two of the following: Java program files, Mybatis configuration files, SQL statement files, database history cache, and MySQL slow logs.
3. The method according to claim 1, characterized in that The SQL statement set to be reviewed is obtained from multiple sources, including: In response to target instructions, a set of SQL statements to be reviewed is obtained from multiple sources, wherein the target instructions include any one of instructions in a programming language development environment, command line call instructions, and API call instructions.
4. The method according to claim 1, characterized in that: The step of reviewing the SQL statements in the SQL statement set in sequence according to a plurality of preset statement rules to generate a first review result includes: Reviewing any SQL statement in the SQL statement set in sequence according to a plurality of preset statement rules to generate the first review result; Among them, multiple preset statement rules include expression rules, syntax tree rules, and execution plan rules. The expression rules include using regular expressions to determine whether there are strings that do not comply with writing specifications in the SQL statement to be reviewed. The syntax tree rules include determining whether there are strings that do not comply with grammatical specifications in the SQL statement to be reviewed based on a syntax tree. The execution plan rules include determining whether the SQL statement to be reviewed satisfies the regular expression.
5. The method according to claim 1, characterized in that The step of reviewing the SQL statement set according to a preset set rule to generate a second review result includes: Determine the execution result corresponding to the SQL statement set, review the execution result, and generate the second review result.
6. The method according to claim 1, characterized in that The method further comprises: Before auditing the SQL statement, obtaining a database type, and creating a syntax tree parser according to the database type, wherein the syntax tree parser is used to convert the SQL statement into a syntax tree when performing syntax tree rule audit on the SQL statement; A plurality of the preset statement rules and the preset set rules are loaded into a configuration file.
7. The method according to claim 4, characterized in that The method further comprises: Defining an audit rule interface, wherein the audit rule interface includes a first sub-interface and a second sub-interface; Creating a syntax tree rule based on the first sub-interface, and creating an expression rule based on the second sub-interface; The step of creating a syntax tree rule based on the first sub-interface includes: when adding a syntax tree rule, creating a target class to implement the first sub-interface of the audit rule interface; and packaging the target class, and placing the packaged target class into the class path of the audit engine; The creating of the expression rule based on the second sub-interface includes: when adding the expression rule, adding a configuration item corresponding to the expression rule in the configuration file.
8. A SQL statement audit processing device, characterized in that: include: A statement acquisition module, used to acquire a set of SQL statements to be reviewed from multiple sources, wherein the set of SQL statements includes multiple SQL statements; A first review module, configured to review the SQL statements in the SQL statement set in sequence according to a plurality of preset statement rules, and generate a first review result; The second audit module is used to audit the SQL statement set according to preset set rules after all SQL statements in the SQL statement set have been audited, and generate a second audit result.
9. A computer device, characterized in that: The method comprises a processor and a memory, wherein the memory stores a program or instruction running on the processor, and when the program or instruction is executed by the processor, the steps of the SQL statement audit processing method according to any one of claims 1 to 8 are implemented.
10. A readable storage medium having a program or instruction stored thereon, characterized in that: When the program or instruction is executed by a processor, the steps of the SQL statement audit processing method according to any one of claims 1 to 8 are implemented.