SQL statement accurate test analysis method and device, equipment and storage medium

By inserting an interceptor into the application to obtain SQL statement information and perform virtual testing, the problem that the existing technology cannot analyze and optimize SQL statements is solved, and precise testing and optimization of conditional branches and nested references of SQL statements is realized.

CN120029910APending Publication Date: 2025-05-23SHANGHAI FAIRYLAND INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510048733.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-13
Publication Date
2025-05-23

AI Technical Summary

Technical Problem

The prior art cannot analyze and optimize SQL statements on conditional branches or nested reference dimensions, and it is impossible to determine whether each conditional branch or nested reference is executed.

Method used

By inserting an interceptor into the application under test, obtain the statement information of the SQL statement to be executed, and use the file parsing library to parse the mapping configuration file, build a mapping configuration file tree, and perform virtual tests to obtain the test information of the SQL statement.

Benefits of technology

It implements the test information of SQL statements on the conditional branch or nested reference dimension, helps analyze and optimize SQL statements, and ensures whether each conditional branch or nested reference is executed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120029910A_ABST
    Figure CN120029910A_ABST
Patent Text Reader

Abstract

The invention provides an SQL statement accurate test analysis method, device and equipment and a storage medium, and belongs to the technical field of computers, the method comprises the following steps: obtaining statement information of a to-be-executed SQL statement by using an interceptor inserted into a tested application; the interceptor is used for analyzing the mapping configuration file of the to-be-executed SQL statement and intercepting execution of the to-be-executed SQL statement; and based on the statement information, performing a virtual test on the to-be-executed SQL statement and the clauses thereof to obtain test information of the to-be-executed SQL statement so as to determine the test information of the to-be-executed SQL statement. According to the method, the virtual test is carried out by utilizing the statement information of the SQL statement obtained by the interceptor, so that the test information of the SQL statement on the clause dimension, which cannot be obtained when the actual test of the SQL statement is executed, can be obtained, and whether each clause in the SQL statement is executed or not can be analyzed based on the test information on the clause dimension; the SQL statement is optimized by adding, deleting and modifying the clauses and the like.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method, device, equipment and storage medium for accurate testing and analysis of SQL statements. Background Art

[0002] In the process of application project development, SQL (Structured Query Language) statements are the bridge between the application and the database. Analyzing and testing SQL statements is an important step to ensure that application development meets expectations.

[0003] Currently, the method for analyzing and testing SQL statements is to execute the SQL statements using different test cases and perform analysis based on the test results obtained after executing the SQL statements.

[0004] However, there are cases where an SQL statement includes multiple conditional branches or nested references to other methods and functions. Simply analyzing the test results of the SQL statement cannot provide test information on whether each conditional branch or nested reference in the SQL statement has been executed, resulting in users being unable to analyze and optimize SQL statements based on the dimensions of conditional branches or nested references. Summary of the invention

[0005] The present invention provides a method, device, equipment and storage medium for accurate testing and analysis of SQL statements, which are used to solve the defect in the prior art that SQL statement testing cannot know whether each conditional branch or nested reference has been executed, and realize a technical solution for obtaining test information of SQL statements in the dimension of conditional branches or nested references to analyze and optimize SQL statements.

[0006] The present invention provides a method for accurate testing and analysis of SQL statements, comprising: using an interceptor inserted into a tested application to obtain statement information of a SQL statement to be executed; the interceptor is used to parse a mapping configuration file of the SQL statement to be executed and intercept the execution of the SQL statement to be executed; Based on the statement information, a virtual test of the SQL statement to be executed and its clauses is performed to obtain test information of the SQL statement to be executed.

[0007] According to a method for accurate testing and analysis of SQL statements provided by the present invention, the interceptor inserted into the application under test is used to obtain statement information of the SQL statement to be executed, including: Using the interceptor, calling the file parsing library to parse the mapping configuration file, and obtaining a definition tag and a condition tag; the definition tag is a tag in the mapping configuration file corresponding to the definition operation of the SQL statement to be executed; the condition tag is a tag in the mapping configuration file corresponding to the conditional selection operation of the SQL statement to be executed; Determine a root node of a mapping configuration file tree based on the definition tag and the statement identifier of the SQL statement to be executed; Determine a leaf node of the mapping configuration file tree based on the condition tag and the statement identifier of the SQL statement to be executed; Based on the root node and the leaf nodes, the mapping configuration file tree is obtained.

[0008] According to a method for accurate testing and analysis of SQL statements provided by the present invention, based on the statement information, a virtual test of the SQL statement to be executed and its clauses is performed to obtain the test information of the SQL statement to be executed, including: Based on the parameters of the clause of the SQL statement to be executed and the internal conditions of the conditional label of the leaf node corresponding to the clause, a virtual test of the clause is performed to obtain test information of the clause; the parameters of the clause are the statement information recorded by the interceptor when intercepting the execution of the SQL statement to be executed; Based on the test information of the clause, the test information of the SQL statement to be executed is determined.

[0009] According to a method for accurate testing and analyzing SQL statements provided by the present invention, the test information of the SQL statement to be executed is determined based on the test information of the clause, including: If the test information of all clauses of the SQL statement to be executed includes coverage success information, then determining that the test information of the SQL statement to be executed includes coverage success information; If the test information of any clause of the SQL statement to be executed includes coverage failure information, determining that the test information of the SQL statement to be executed includes coverage failure information; The coverage success information is determined when the parameters and the internal conditions of the clause pass the virtual test; the coverage failure information is determined when the parameters and the internal conditions of the clause fail to pass the virtual test.

[0010] According to a method for accurate testing and analyzing SQL statements provided by the present invention, when the clause includes a nested clause, the test information of the clause is determined based on the following method: If the test information of all nested clauses of the clause includes coverage success information, then determining that the test information of the clause includes coverage success information; If the test information of any nested clause of the clause includes coverage failure information, it is determined that the test information of the clause includes coverage failure information.

[0011] According to a method for accurate testing and analyzing SQL statements provided by the present invention, after determining the test information of the SQL statement to be executed based on the test information of the clause, the method further includes: According to the difference of the test information, different visual identifiers are allocated to the definition tag, the condition tag, the SQL statement to be executed and / or the clauses of the SQL statement to be executed.

[0012] According to a method for accurate testing and analysis of SQL statements provided by the present invention, the step of obtaining statement information of a SQL statement to be executed includes: The statement information of the SQL statement to be executed is read from a cache pool; the cache pool is used to temporarily store the statement information obtained by using the interceptor.

[0013] The present invention also provides a device for accurately testing and analyzing SQL statements, comprising: A statement information acquisition module, used to acquire statement information of a SQL statement to be executed by using an interceptor inserted into the application under test; the interceptor is used to parse a mapping configuration file of the SQL statement to be executed and intercept the execution of the SQL statement to be executed; The test information acquisition module is used to perform a virtual test on the SQL statement to be executed and its clauses based on the statement information to obtain the test information of the SQL statement to be executed.

[0014] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, wherein when the processor executes the computer program, the method for accurately testing and analyzing SQL statements as described above is implemented.

[0015] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the method for accurately testing and analyzing SQL statements as described above is implemented.

[0016] The SQL statement precise testing and analysis method, device, equipment and storage medium provided by the present invention insert an interceptor into the tested application, utilize the interceptor to parse the mapping configuration file of the SQL statement and the ability to intercept the execution of the SQL statement to obtain the statement information of the SQL statement, so as to use the statement information to perform a virtual test on the SQL statement and its clauses, obtain the test information of the SQL statement on the clause dimension that cannot be obtained when the SQL statement is actually tested and executed, and can analyze whether each clause in the SQL statement has been executed based on the test information on the clause dimension, so as to optimize the SQL statement by adding, deleting, modifying clauses, etc. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0018] Figure 1 It is a flowchart of the SQL statement accurate testing and analysis method provided by the present invention.

[0019] Figure 2 It is a structural schematic diagram of the SQL statement precise testing and analysis device provided by the present invention.

[0020] Figure 3 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0021] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0022] It should be noted that, in the description of the present invention, the term "include" or any other variant thereof is intended to cover non-exclusive inclusion, so that a 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. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances. In addition, "and / or" means at least one of the connected objects, and the character " / " generally indicates that the objects associated before and after are in an "or" relationship.

[0023] Combine the following Figure 1-Figure 3 The present invention describes the SQL statement accurate testing and analysis method, device, equipment and storage medium provided by the present invention.

[0024] Figure 1 It is a flowchart of the SQL statement accurate testing and analysis method provided by the present invention, such as Figure 1 As shown, the SQL statement accurate testing and analysis method includes but is not limited to step 101 and step 102.

[0025] It should be noted that the execution subject of the SQL statement precision testing and analysis method provided by the present invention can be a server, a computer device, such as a mobile phone, a tablet computer, a laptop computer, a PDA, a vehicle-mounted electronic device, a wearable device, an ultra-mobile personal computer (Ultra-Mobile Personal Computer, UMPC), a netbook or a personal digital assistant (Personal Digital Assistant, PDA), etc.

[0026] Step 101: Using the interceptor inserted into the application under test, obtain statement information of the SQL statement to be executed.

[0027] The interceptor is used to parse the mapping configuration file of the SQL statement to be executed and intercept the execution of the SQL statement to be executed.

[0028] The SQL statements to be executed are SQL statements that are not executed during the testing of the application under test.

[0029] Interceptors, also known as probes, are implemented based on a framework and extensible tools that can implement custom logic, intercept the execution of SQL statements, modify SQL statements, and other operations during the execution of SQL statements.

[0030] The mapping configuration file is a mapping configuration file provided by the framework and extensible tools in the process of implementing the interceptor based on the framework and extensible tools, and has a mapping relationship with the SQL statement to be executed.

[0031] For example, MyBatis provides the MyBatis Interceptor function, which can implement custom logic, intercept the execution of SQL statements, modify SQL statements, and other operations during the execution of SQL statements.

[0032] Therefore, the interceptor can be implemented based on the MyBatis Interceptor function provided by MyBatis, and the mapping configuration file at this time is the mapper.xml file.

[0033] Specifically, the interceptor is pre-programmed to determine the mapping configuration file for parsing the SQL statement to be executed in the interceptor, the custom logic for intercepting the execution of the SQL statement, etc. After the application under test is started, the pre-programmed interceptor is inserted into the application under test.

[0034] During the test, after the user triggers a database query of the application under test, the interceptor is triggered, and the statement information of the SQL statement to be executed is obtained by parsing the mapping configuration file of the SQL statement to be executed for the database query, intercepting the execution of the SQL statement to be executed, and recording the execution results of the SQL statement to be executed.

[0035] The statement information of the SQL statement to be executed includes but is not limited to at least one of the following information: a mapping configuration file tree, parameters of the SQL statement to be executed, a return result after the SQL statement to be executed, and a generated SQL statement after the SQL statement to be executed.

[0036] The mapping configuration file tree is a tree-shaped data table determined based on the mapping relationship between the mapping configuration file and the SQL statement to be executed after parsing the mapping configuration file.

[0037] It should be noted that the statement information of the SQL statement to be executed can be obtained by the test system located in the same terminal as the application under test, or by the remote background test system, and the present invention does not limit this.

[0038] Step 102: Based on the statement information, perform a virtual test on the SQL statement to be executed and its clauses to obtain test information of the SQL statement to be executed.

[0039] Specifically, after obtaining the statement information of the SQL statement to be executed, the statement information is used to perform virtual testing on the SQL statement to be executed and each conditional branch or nested reference clause in the SQL statement to be executed, to determine which conditional branches or nested reference clauses in the SQL statement to be executed have been executed, and to obtain test information of the SQL statement to be executed and its clauses, which can be used to analyze and optimize the SQL statement to be executed from the clause dimension.

[0040] The SQL statement precise testing and analysis method provided by the present invention inserts an interceptor into the tested application, utilizes the interceptor to parse the mapping configuration file of the SQL statement and the ability to intercept the execution of the SQL statement to obtain the statement information of the SQL statement, so as to utilize the statement information to perform a virtual test on the SQL statement and its clauses, obtain the test information of the SQL statement on the clause dimension that cannot be obtained when the SQL statement is actually tested and executed, and can analyze whether each clause in the SQL statement has been executed based on the test information on the clause dimension, so as to optimize the SQL statement by adding, deleting, modifying clauses, etc.

[0041] Based on the above embodiment, as an optional embodiment, the method of obtaining statement information of the SQL statement to be executed by using the interceptor inserted into the application under test includes: Using the interceptor, calling the file parsing library to parse the mapping configuration file, and obtaining a definition tag and a condition tag; the definition tag is a tag in the mapping configuration file corresponding to the definition operation of the SQL statement to be executed; the condition tag is a tag in the mapping configuration file corresponding to the conditional selection operation of the SQL statement to be executed; Determine a root node of a mapping configuration file tree based on the definition tag and the statement identifier of the SQL statement to be executed; Determine a leaf node of the mapping configuration file tree based on the condition tag and the statement identifier of the SQL statement to be executed; Based on the root node and the leaf nodes, the mapping configuration file tree is obtained.

[0042] Specifically, when the statement information of the SQL statement to be executed is obtained as a mapping configuration file tree, the interceptor inserted into the application under test calls the file parsing library to parse the mapping configuration file, obtain the label corresponding to the definition operation of the SQL statement to be executed in the mapping configuration file as the definition label, and obtain the label corresponding to the conditional selection operation of the SQL statement to be executed in the mapping configuration file as the condition label. Further, according to the definition label and the statement identifier of the SQL statement to be executed, the root node corresponding to the definition label is determined, and the root node is set with a unique node identifier; according to the condition label and the statement identifier of the SQL statement to be executed, the leaf node corresponding to the condition label is determined, and the leaf node is set with a unique node identifier. According to the definition label and the condition label obtained by parsing the mapping configuration file, the root node and the leaf node of the mapping configuration file tree are determined, so as to construct the mapping configuration file tree.

[0043] Taking the mapping configuration file as mapper.xml file as an example, the following code line is an excerpt from a mapper.xml file: <select id="”countAgencyDepositCount”" parametertype="”map”" resulttype="”java.lang.Integer”"> #{objectSubjCode, jdbcType=VARCHAR}and bal.object_code=#{objectCode, jdbcType=VARCHAR}< / select> .

[0044] As shown in the above code line, <select>Belong to definition tags, and belong to condition tags. In the mapper.xml file based on MyBatis, definition tags also include but are not limited to,,, and other tags, and condition tags also include but are not limited to,,, and other tags.

[0045] Optionally, before calling the file parsing library to parse the mapping configuration file and obtain the definition tags and condition tags, it also includes: according to the file format of the mapping configuration file of the SQL statement to be executed, determine the file parsing library used to parse the mapping configuration file.

[0046] For example, in the case where the mapping configuration file is a mapper.xml file, the file parsing library is an XML file parsing library, which can be any one of the XML file parsing libraries such as DOM (Document Object Model), SAX (Simple API for XML) or StAX (Streaming API for XML).

[0047] The SQL statement precise testing and analysis method provided by the present invention uses the interceptor inserted into the application under test to call the file parsing library to parse the mapping configuration file, and constructs a mapping configuration file tree according to the definition tags and condition tags obtained by parsing, so as to realize the decomposition of the SQL statement in the clause dimension during the application test, and provide a basis for obtaining the test information of whether each clause in the SQL statement to be executed has been executed through virtual testing in the subsequent process.

[0048] Based on the above embodiment, as an optional embodiment, the virtual test of the SQL statement to be executed and its clauses is performed based on the statement information to obtain the test information of the SQL statement to be executed, including: performing a virtual test of the clause based on the parameters of the clause of the SQL statement to be executed and the internal conditions of the conditional label of the leaf node corresponding to the clause to obtain the test information of the clause; the parameters of the clause are the statement information recorded by the interceptor when intercepting the execution of the SQL statement to be executed; based on the test information of the clause, the test information of the SQL statement to be executed is determined.

[0049] Specifically, after obtaining the statement information including the mapping configuration file tree and the parameters of the SQL statement to be executed, for a clause of the SQL statement to be executed, according to the unique identifier of the root node corresponding to the SQL statement to be executed to which the clause belongs in the mapping configuration file tree, the parameters on which the clause depends are determined from the statement information, the internal conditions of the conditional label of the child node corresponding to the clause in the mapping configuration file tree are determined, and the virtual test of the clause is performed to obtain the test information of the clause. By performing virtual testing on all clauses under the SQL statement to be executed, test information of all clauses can be obtained, thereby determining the test information of the SQL statement to be executed.

[0050] It can be understood that the test information obtained by virtual testing of the SQL statement to be executed is consistent with the test information obtained during actual execution.Taking the code line excerpt of the mapper.xml file provided above as an example, according to the unique identifier "countAgencyDepositCount" of the SQL statement to be executed in the mapping configuration file, it is judged that the clause of the SQL statement to be executed depends on the parameter "objectCode" when executing, so the "objectCode" and<if test> The internal conditions for "objectCode" and<if test>

[0052] It can be understood that, based on the acquired mapping configuration file tree, the parameters of the SQL statement to be executed, the return result after the SQL statement to be executed, the generated SQL statement after the SQL statement to be executed, etc., the virtual test of the clause can be performed in a variety of known ways based on the parameters of the clause and the internal conditions of the conditional tags of the leaf nodes corresponding to the clause, and combined with the relevant statement information, and the virtual test of the clause can be performed in combination with the relevant statement information. The present invention does not limit this.

[0053] The SQL statement accurate test and analysis method provided by the present invention obtains the test information of the SQL statement on the clause dimension that cannot be obtained during the actual test execution of the SQL statement by performing a virtual test based on the parameters of the clause in the acquired statement information and the internal conditions of the conditional tags of the child nodes in the mapping configuration file tree. Based on the test information on the clause dimension, it can analyze whether each clause in the SQL statement has been executed, so as to optimize the SQL statement by adding, deleting, modifying clauses, etc.

[0054] Based on the above embodiment, as an optional embodiment, the test information of the SQL statement to be executed is determined based on the test information of the clause, including: if the test information of all clauses of the SQL statement to be executed includes coverage success information, then it is determined that the test information of the SQL statement to be executed includes coverage success information; if the test information of any clause of the SQL statement to be executed includes coverage failure information, then it is determined that the test information of the SQL statement to be executed includes coverage failure information; the coverage success information is determined when the parameters and the internal conditions of the clause pass the virtual test; the coverage failure information is determined when the parameters and the internal conditions of the clause fail to pass the virtual test.

[0055] Specifically, a virtual test is performed based on the parameters of the clause in the acquired statement information and the internal conditions of the conditional labels of the child nodes in the mapping configuration file tree. If the virtual test passes, it means that the conditional branch corresponding to the clause has been executed during the test, and the test information of the clause includes coverage success information; if the virtual test fails, it means that the conditional branch corresponding to the clause of the conditional branch has not been executed during the test, and the test information of the clause includes coverage failure information.

[0056] Further, if the test information of all clauses of the SQL statement to be executed includes coverage success information, it means that the conditional branches corresponding to all clauses of the SQL statement to be executed have been executed during the test, and at this time, it is determined that the test information of the SQL statement to be executed includes coverage success information; if the test information of any clause of the SQL statement to be executed includes coverage failure information, it means that the SQL statement to be executed has a conditional branch that has not been executed during the test, and at this time, it is determined that the test information of the SQL statement to be executed includes coverage failure information.

[0057] The SQL statement precise testing and analysis method provided by the present invention determines that the test information of the SQL statement to be executed includes coverage success information only when the virtual test of all clauses of the conditional branches of the SQL statement to be executed passes, so as to help application testers quickly determine the SQL statements with unexecuted conditional branches, so as to help application testers further optimize these SQL statements with unexecuted conditional branches.

[0058] Based on the above embodiment, as an optional embodiment, in the case where the clause includes a nested clause, the test information of the clause is determined based on the following method: if the test information of all the nested clauses of the clause includes coverage success information, it is determined that the test information of the clause includes coverage success information; if the test information of any nested clause of the clause includes coverage failure information, it is determined that the test information of the clause includes coverage failure information.

[0059] Specifically, when a clause is virtually tested, if the clause has several nested clauses that reference other function methods, in the case where the test information of all the nested clauses of the clause includes coverage success information, it is determined that the test information of the clause includes coverage success information; and in the case where the test information of any nested clause of the clause includes coverage failure information, it is determined that the test information of the clause includes coverage failure information.

[0060] The SQL statement precise testing and analysis method provided by the present invention can help application testers quickly determine the conditional branches with nested references that have not been executed, by determining that the test information of the clause includes coverage success information only when the virtual tests of the nested clauses of the clauses of a certain conditional branch have all passed, so as to help application testers further optimize the SQL statements with these unexecuted nested references.

[0061] Optionally, after obtaining the statement information, performing a virtual test on the SQL statement to be executed and its clauses, and obtaining the test information of the SQL statement to be executed, the test information is stored in a pre-designed data structure based on a database table, a memory cache, etc.

[0062] Wherein, the pre-designed data structure includes but is not limited to the unique identification field ID of the node (including the root node and the leaf node) of the mapping configuration file tree, the type field Type of the node (such as SELECT, INSERT, etc.), the unique identification field MappedStatementID of the MappedStatement associated with the node; the test information field Covered (Boolean value, 1 for successful coverage information, 0 for failed coverage information) of whether the SQL statement corresponding to the node is executed, the timestamp LastExecutionTime of the last execution of the SQL statement corresponding to the node, the application unique identification field SystemID of the application under test, the number of times the SQL statement corresponding to the node is executed, etc.

[0063] Optionally, after the virtual test of the SQL statement to be executed and its clauses is performed based on the statement information to obtain the test information of the SQL statement to be executed, it also includes: according to a preset period, based on the data stored in the pre-designed data structure, statistical analysis of the coverage information of the SQL statement to be executed and its clauses is performed to obtain the conditional branch data corresponding to the clauses that are not executed during multiple tests, the clauses where the nested reference is located, or the SQL statement is frequently used but the nested clause itself is not executed.

[0064] Based on the above embodiment, as an optional embodiment, after determining the test information of the SQL statement to be executed based on the test information of the clause, it also includes: assigning different visual identifiers to the definition tag, the condition tag, the SQL statement to be executed and / or the clause of the SQL statement to be executed according to the difference of the test information.

[0065] Wherein, different visual identifiers include but are not limited to different shapes, colors, display modes, etc.

[0066] For example, on the visual display interface, for the test information including the nested clauses, clauses, SQL statements to be executed and their corresponding definition tags and condition tags, etc. that cover the successful information, a visual identifier with a green background color is assigned; for the test information including the nested clauses, clauses, SQL statements to be executed and their corresponding definition tags and condition tags, etc. that cover the failed information, a visual identifier with a red background color is assigned.

[0067] The visual display interface can be an interface for displaying the SQL statement to be executed, or an interface for displaying the mapping configuration file corresponding to the SQL statement to be executed.

[0068] The SQL statement precise testing and analysis method provided by the present invention helps application testers to intuitively and quickly determine the execution coverage of SQL statements by assigning different visual identifiers to definition tags, condition tags, SQL statements to be executed and / or clauses of SQL statements to be executed on a visual interface according to different test information, so as to help application testers to further optimize SQL statements with unexecuted conditional branches and nested references.

[0069] Based on the above embodiment, as an optional embodiment, the obtaining of statement information of the SQL statement to be executed includes: reading the statement information of the SQL statement to be executed from a cache pool; the cache pool is used to temporarily store the statement information obtained by the interceptor.

[0070] Specifically, after obtaining statement information including a mapping configuration file tree, parameters of the SQL statement to be executed, etc. by using the interceptor, the statement information is temporarily stored in the cache pool corresponding to the mapping configuration file. When performing a virtual test based on the statement information, the corresponding statement information is read from the corresponding cache pool.

[0071] Optionally, the number of cache pools is determined based on the business type and number of the application under test. One business corresponds to one cache pool, and one cache pool corresponds to one mapping configuration file.

[0072] The SQL statement precise testing and analysis method provided by the present invention can improve the speed of obtaining statement information during virtual testing by temporarily storing the statement information obtained by the interceptor in the cache pool, thereby speeding up the acquisition of SQL statement test information and improving the user experience of application testing users.

[0073] In general, the present invention provides a method for accurate testing and analysis of SQL statements. By designing an interceptor to intercept the execution of SQL statements and record the statement information when the SQL statements are executed, and combining the file parsing library to parse the mapping configuration file to obtain the mapping configuration file number, the SQL statement and its conditional branches, the coverage information of the clauses of the nested references and other test information are obtained through virtual testing, and it is possible to determine whether the nodes and conditional branches have been used, and a data structure is designed to store the test information in multiple test processes. By analyzing the test information stored in the data structure, it is possible to obtain the conditional branch data corresponding to the clauses that have not been executed in multiple test processes, the clauses where the nested references are located, or the SQL statement is frequently used but the nested clauses themselves are not executed, etc. Based on these test data, a visual identifier is assigned on the visual interface or an analysis report is generated, so that the analysis results can be intuitively and quickly displayed to the application test user, so as to facilitate the application test user to optimize the SQL statement.

[0074] FIG2 is a structural schematic diagram of the SQL statement accurate testing and analysis device provided by the present invention, and the SQL statement accurate testing and analysis device includes but is not limited to a statement information acquisition module 201 and a test information acquisition module 202.

[0075] A statement information acquisition module 201 is used to acquire statement information of a SQL statement to be executed by using an interceptor inserted into the application under test; the interceptor is used to parse a mapping configuration file of the SQL statement to be executed and intercept the execution of the SQL statement to be executed.

[0076] A test information acquisition module 202 is used to perform a virtual test of the SQL statement to be executed and its clauses based on the statement information to obtain test information of the SQL statement to be executed.

[0077] It should be noted that the SQL statement precision testing and analysis device provided by the present invention can execute the SQL statement precision testing and analysis method described in any of the above embodiments during specific operation, which will not be described in detail in this embodiment.

[0078] The SQL statement precision testing and analysis device provided by the present invention inserts an interceptor into the application under test, and uses the interceptor to parse the mapping configuration file of the SQL statement and intercept the execution of the SQL statement to obtain the statement information of the SQL statement, so as to use the statement information to perform a virtual test on the SQL statement and its clauses, and obtain the test information of the SQL statement on the clause dimension that cannot be obtained during the actual test execution of the SQL statement, and can analyze whether each clause in the SQL statement has been executed based on the test information on the clause dimension, so as to optimize the SQL statement by adding, deleting, modifying clauses, etc.

[0079] FIG3 is a schematic diagram of the structure of the electronic device provided by the present invention. As shown in FIG3, the electronic device may include: a processor 310, a communication interface 320, a memory 330 and a communication bus 340, wherein the processor 310, the communication interface 320 and the memory 330 communicate with each other through the communication bus 340. The processor 310 may call the logic instructions in the memory 330 to execute the SQL statement precision test and analysis method provided by any of the above embodiments, and the SQL statement precision test and analysis method includes but is not limited to the following steps: using an interceptor inserted into the application under test to obtain the statement information of the SQL statement to be executed; the interceptor is used to parse the mapping configuration file of the SQL statement to be executed and intercept the execution of the SQL statement to be executed; based on the statement information, the virtual test of the SQL statement to be executed and its clauses is performed to obtain the test information of the SQL statement to be executed.

[0080] In addition, the logic instructions in the memory 330 may be implemented in the form of a software functional unit and may be stored in a computer-readable storage medium when sold or used as an independent product. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc., various media that can store program codes.

[0081] On the other hand, the present invention also provides a computer program product, which includes a computer program, and the computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the SQL statement precision testing and analysis method provided in any of the above embodiments, and the SQL statement precision testing and analysis method includes but is not limited to the following steps: using an interceptor inserted into the application under test to obtain statement information of the SQL statement to be executed; the interceptor is used to parse the mapping configuration file of the SQL statement to be executed and intercept the execution of the SQL statement to be executed; based on the statement information, perform a virtual test of the SQL statement to be executed and its clauses to obtain the test information of the SQL statement to be executed.

[0082] In another aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the SQL statement precision test and analysis method provided in any of the above embodiments, wherein the SQL statement precision test and analysis method includes but is not limited to the following steps: using an interceptor inserted into the application under test to obtain statement information of the SQL statement to be executed; the interceptor is used to parse the mapping configuration file of the SQL statement to be executed and intercept the execution of the SQL statement to be executed; based on the statement information, a virtual test of the SQL statement to be executed and its clauses is performed to obtain the test information of the SQL statement to be executed.

[0083] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. A person of ordinary skill in the art may understand and implement the present invention without creative labor. Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be realized by means of software plus the necessary general hardware platform, and of course can also be realized by hardware. Based on such understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, an optical disk, etc., including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in some parts of each embodiment or the embodiment.Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them. Although the present invention has been described in detail with reference to the aforementioned embodiments, it should be understood by those skilled in the art that the technical solutions described in the aforementioned embodiments can still be modified, or some of the technical features can be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.< / select>

Claims

1. A method for accurate testing and analysis of SQL statements, characterized in that: include: Use the interceptor inserted into the application under test to obtain the statement information of the SQL statement to be executed; The interceptor is used to parse the mapping configuration file of the SQL statement to be executed and intercept the execution of the SQL statement to be executed; Based on the statement information, a virtual test of the SQL statement to be executed and its clauses is performed to obtain test information of the SQL statement to be executed.

2. The SQL statement accurate testing and analysis method according to claim 1 is characterized in that: The method of obtaining statement information of the SQL statement to be executed by using the interceptor inserted into the application under test includes: Using the interceptor, calling the file parsing library to parse the mapping configuration file, and obtaining a definition tag and a condition tag; the definition tag is a tag in the mapping configuration file corresponding to the definition operation of the SQL statement to be executed; the condition tag is a tag in the mapping configuration file corresponding to the conditional selection operation of the SQL statement to be executed; Determine a root node of a mapping configuration file tree based on the definition tag and the statement identifier of the SQL statement to be executed; Determine a leaf node of the mapping configuration file tree based on the condition tag and the statement identifier of the SQL statement to be executed; Based on the root node and the leaf nodes, the mapping configuration file tree is obtained.

3. The SQL statement accurate testing and analysis method according to claim 2 is characterized in that: The step of performing a virtual test on the SQL statement to be executed and its clauses based on the statement information to obtain the test information of the SQL statement to be executed includes: Based on the parameters of the clause of the SQL statement to be executed and the internal conditions of the conditional label of the leaf node corresponding to the clause, a virtual test of the clause is performed to obtain test information of the clause; the parameters of the clause are the statement information recorded by the interceptor when intercepting the execution of the SQL statement to be executed; Based on the test information of the clause, the test information of the SQL statement to be executed is determined.

4. The SQL statement accurate testing and analysis method according to claim 3 is characterized in that: The step of determining the test information of the SQL statement to be executed based on the test information of the clause includes: If the test information of all clauses of the SQL statement to be executed includes coverage success information, then determining that the test information of the SQL statement to be executed includes coverage success information; If the test information of any clause of the SQL statement to be executed includes coverage failure information, determining that the test information of the SQL statement to be executed includes coverage failure information; The coverage success information is determined when the parameters and the internal conditions of the clause pass the virtual test; the coverage failure information is determined when the parameters and the internal conditions of the clause fail to pass the virtual test.

5. The SQL statement accurate testing and analysis method according to claim 4 is characterized in that: In the case where the clause includes nested clauses, the test information for the clause is determined based on: If the test information of all nested clauses of the clause includes coverage success information, then determining that the test information of the clause includes coverage success information; If the test information of any nested clause of the clause includes coverage failure information, it is determined that the test information of the clause includes coverage failure information.

6. The SQL statement accurate testing and analysis method according to claim 4 is characterized in that: After determining the test information of the SQL statement to be executed based on the test information of the clause, the method further includes: According to the difference of the test information, different visual identifiers are allocated to the definition tag, the condition tag, the SQL statement to be executed and / or the clauses of the SQL statement to be executed.

7. The SQL statement accurate testing and analysis method according to claim 1 is characterized in that: The step of obtaining statement information of the SQL statement to be executed includes: The statement information of the SQL statement to be executed is read from a cache pool; the cache pool is used to temporarily store the statement information obtained by using the interceptor.

8. A device for accurate testing and analysis of SQL statements, characterized in that: include: A statement information acquisition module is used to obtain statement information of the SQL statement to be executed by using the interceptor inserted into the application under test; The interceptor is used to parse the mapping configuration file of the SQL statement to be executed and intercept the execution of the SQL statement to be executed; The test information acquisition module is used to perform a virtual test on the SQL statement to be executed and its clauses based on the statement information to obtain the test information of the SQL statement to be executed.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the computer program, the method for accurate testing and analysis of SQL statements as described in any one of claims 1 to 7 is implemented.

10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for accurate testing and analysis of SQL statements as claimed in any one of claims 1 to 7 is implemented.