SQL (Structured Query Language) test method and device, equipment, medium and program product

By obtaining the variable value range and database mapping relationship in the target configuration file, multiple SQL statements are generated and executed, solving the problem of low accuracy in SQL testing in existing technologies and achieving higher testing accuracy and reliability.

CN121579338APending Publication Date: 2026-02-27CHINA CONSTRUCTION BANK +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511599218.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-04
Publication Date
2026-02-27

AI Technical Summary

Technical Problem

In existing technologies, the limited number of definite values ​​results in a small number of generated test SQL statements, which cannot cover various use cases and leads to low accuracy in SQL testing.

Method used

By obtaining the variable value range in the target configuration file, M SQL statements covering a wide range of use cases are generated. Each SQL statement is then parsed into a syntax tree to determine the mapping relationship between parameter nodes and data tables in the database. The SQL statements are then executed to determine if any problems exist.

Benefits of technology

It improves the accuracy and reliability of SQL testing, ensuring accurate execution of SQL in the database and covering more use cases and execution parameters.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121579338A_ABST
    Figure CN121579338A_ABST
Patent Text Reader

Abstract

The invention provides an SQL (Structured Query Language) testing method, device and equipment, a medium and a program product, relates to the technical field of computers, and can improve the accuracy of testing an SQL. According to the specific technical scheme, a test device can obtain a target configuration file comprising a target SQL, and sets values of corresponding variables in the target SQL according to the target configuration file, so that the test device can parse each generated SQL into a syntax tree, and the syntax tree is used for generating a syntax tree; respectively determining a data table corresponding to a parameter node included in each syntax tree in a database, respectively determining a mapping relationship of fields in the data table corresponding to parameters in one parameter node according to the first parameter node of each syntax tree and the data table corresponding to the first parameter node, and respectively determining the fields in the data table corresponding to the parameters in the parameter node according to each mapping relationship, and executing the corresponding SQL, and determining whether the target SQL has a problem or not according to the execution parameters of the M SQL. The method and the device are used in software testing scenes.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] Embodiments of the present application relate to the technical field of computer, and particularly, to a SQL testing method and device, equipment, medium and program product. BACKGROUND

[0002] At present, in the scene of testing software, a test device can set the value of a variable in a to-be-tested structured query language (SQL) in a configuration file to a determined value, generate a test SQL, and test the test SQL, so that whether the to-be-tested SQL has a problem can be determined according to a test result of testing the test SQL.

[0003] However, since the number of the determined values is small, the number of the generated test SQLs may be small, which cannot cover various use scenarios, and thus the accuracy of testing the SQL is low. SUMMARY

[0004] Embodiments of the present application provide a SQL testing method, device, equipment, medium and program product, which can improve the accuracy of testing the SQL.

[0005] To achieve the above object, embodiments of the present application adopt the following technical solutions: In a first aspect, the embodiments of the present application provide a SQL testing method, which includes that a test device can acquire a target configuration file, the target configuration file including a target SQL, the target SQL including N variables, N being a positive integer greater than 1, and respectively determining a variable value range of each variable in the N variables according to the target configuration file, each variable value range including at least one variable value, and respectively setting a value of a corresponding variable in the target SQL according to each variable value in each variable value range of each variable, generating one SQL, obtaining M SQLs, M being a positive integer. Thus, the test device can parse each SQL into a syntax tree respectively, each syntax tree including at least one parameter node, and respectively determine a data table in a database corresponding to a parameter node included in each syntax tree, and respectively determine a mapping relationship according to a first parameter node of each syntax tree and a data table corresponding to the first parameter node, the first parameter node being a parameter node corresponding to the data table. Each mapping relationship is a mapping relationship between a parameter in the first parameter node of each syntax tree and a field in the corresponding data table. Thus, the test device can execute the corresponding SQL according to each mapping relationship respectively, and determine whether the target SQL has a problem according to an execution parameter of the M SQLs.

[0006] According to the above, since the test device can determine the variable value range of each of the N variables in the target SQL in the target configuration file according to the target configuration file when the target configuration file is obtained, and set the value of the corresponding variable in the target SQL according to each variable value in each variable value range of each variable, i.e., use a large number of variable values to set the value of the corresponding variable in the target SQL, a large number of M SQLs covering a large number of use scenarios can be generated. Therefore, the test device can execute a large number of M SQLs covering a large number of use scenarios to obtain a large number of execution parameters covering a large number of use scenarios, so that the test device can accurately determine whether the target SQL has a problem according to the execution parameters covering a large number of use scenarios. In addition, since the test device can parse each SQL into a syntax tree and determine the data table corresponding to the parameter node in each syntax tree in the database, and determine a mapping relationship (i.e., a mapping relationship between the parameter in the first parameter node of each syntax tree and the field in the corresponding data table) according to the first parameter node of each syntax tree and the data table corresponding to the first parameter node, the test device can accurately determine the position of the field corresponding to each SQL in the database according to each mapping relationship, and accurately execute the corresponding SQL, avoiding the problem that the SQL cannot be accurately executed due to the inability to determine the position of the field corresponding to the SQL in the database, so that the test device can test the target SQL. In this way, the reliability of testing the SQL can be ensured, and the accuracy of testing the SQL can be improved.

[0007] In a possible implementation of the first aspect, the test device can obtain the logical expression corresponding to the target SQL from the first preset label in the target configuration file, and determine the variable value range of each variable from a plurality of first ranges according to the logical expression, wherein the plurality of first ranges include at least one of the following: a parameter range input by an external file associated with the target configuration file, and a value range obtained based on the code corresponding to the N variables.

[0008] Therefore, the test device can improve the accuracy of the variable value range determined by the test device, so that a plurality of M SQLs covering more use scenarios can be generated, and then the test device can execute the plurality of M SQLs covering more use scenarios respectively to obtain a plurality of execution parameters covering more use scenarios and in a large quantity, and accurately determine whether the target SQL has a problem according to the plurality of execution parameters covering more use scenarios and in a large quantity. In this way, the accuracy of the test on the SQL can be further improved.

[0009] In a possible implementation of the first aspect, the test device can execute the corresponding SQL according to each mapping relationship respectively, including: the test device can determine the field corresponding to each parameter in the first parameter node of the first syntax tree according to the first mapping relationship, the first mapping relationship being any one of the at least one mapping relationship; and obtain at least one data corresponding to each parameter from the data table corresponding to the first parameter node of the first syntax tree according to the field corresponding to each parameter respectively; and combine the at least one data corresponding to each parameter to obtain the combined data.

[0010] Therefore, the test device can determine the field corresponding to each parameter in the first parameter node of the first syntax tree according to any one of the mapping relationships (i.e., the first mapping relationship), and obtain at least one data from the data table corresponding to the first parameter node of the first syntax tree according to the field corresponding to each parameter in the first parameter node of the first syntax tree respectively, and combine the at least one data corresponding to each parameter, that is, the test device can accurately and completely execute the SQL corresponding to the first syntax tree, so that the test device can accurately execute the SQL corresponding to the first syntax tree according to the first mapping relationship, and the situation that the SQL corresponding to the first syntax tree cannot be executed can be avoided. In this way, the reliability of the test on the SQL can be further improved.

[0011] In a possible implementation manner of the first aspect, the above acquiring the at least one data from the data table corresponding to the first parameter node of the first syntax tree according to the field corresponding to each parameter respectively comprises: the test device can acquire the first at least one data with the largest statistical quantity from the data table corresponding to the first parameter node of the first syntax tree according to the first field corresponding to the first parameter, and acquire at least one data from the data table corresponding to the first parameter node of the first syntax tree according to the first field corresponding to the first parameter and according to the field associated with the first field, and the first parameter is any one of the parameters in the first parameter node of the first syntax tree, and the first field is the field corresponding to the first parameter.

[0012] As can be seen, since the test device can acquire different data from the data table corresponding to the first parameter node of the first syntax tree according to the first field, it can be ensured that the test device can accurately execute the SQL corresponding to the first syntax tree, thereby improving the accuracy of the acquired execution parameters, and further ensuring that the test device can determine whether the target SQL has a problem according to the accurate execution parameters, so that the reliability of testing the SQL can be further improved.

[0013] In a possible implementation manner of the first aspect, the above setting the value of the corresponding variable in the target SQL according to each variable value in the variable value range of each variable comprises: the test device can combine each variable value in the variable value range of each variable and each variable value in the variable value range of other variables in the N variables except the each variable to obtain M value combinations, each value combination includes one variable value of each variable and one variable value of the other variable, and M is a positive integer; and the value of the corresponding variable in the target SQL is set according to each variable value in each value combination.

[0014] Therefore, the test device can combine each variable value of each variable in the variable value range of each variable and each variable value of other variables in the variable value range of the other variables except the each variable in the N variables, to obtain M value combinations, each value combination in the M value combinations includes one variable value of each variable and one variable value of other variables, that is, each value combination includes one possible value combination of the N variables, and the M value combinations include all possible value combinations of the N variables. The test device sets the value of the corresponding variable in the target SQL according to the variable value in each value combination in the M value combinations, respectively, and the values of the N variables in the M SQLs can cover all possible value combinations, that is, the M SQLs covering various use scenarios can be generated in a large number. Therefore, the test device can execute the M SQLs covering various use scenarios in a large number, respectively, to obtain execution parameters covering various use scenarios in a large number, so that the test device can accurately determine whether the target SQL has a problem according to the execution parameters covering various use scenarios in a large number. In this way, the accuracy of testing the SQL can be improved.

[0015] In a possible implementation form of the first aspect, the execution parameter includes at least one of: a time length for completing execution of the SQL; a total number of logical reads in a process of executing the SQL; and a total number of physical reads in the process of executing the SQL.

[0016] Therefore, the parameter related to the execution performance of the SQL (that is, at least one of the time length for completing execution of the SQL, the total number of logical reads in the process of executing the SQL, and the total number of physical reads in the process of executing the SQL) can be set as the execution parameter, so that the test device can obtain execution parameters of different dimensions and detect whether the target SQL has a problem according to the execution parameters of different dimensions. Therefore, the reliability of testing the SQL can be further improved.

[0017] In a possible implementation form of the first aspect, the determining, according to the execution parameters of the M SQLs, whether the target SQL has a problem includes: determining, by the test device, that the target SQL has a problem, when a parameter value of the execution parameter of any one of the M SQLs is greater than or equal to a parameter threshold; or determining, by the test device, that the target SQL does not have a problem, when the parameter value of the execution parameter of each of the M SQLs is less than the parameter threshold.

[0018] Therefore, the test device can accurately determine whether the target SQL has a problem according to the execution parameters of the M SQLs and the parameter threshold, so that the test device can obtain an accurate test result of testing the target SQL, and therefore, the reliability of testing the SQL can be improved.

[0019] In a second aspect, an embodiment of the present application provides a SQL testing device, the SQL testing device comprising: an obtaining module configured to obtain a target configuration file, the target configuration file comprising a target SQL, the target SQL comprising N variables, N being a positive integer greater than 1; a determining module configured to determine a variable value range of each of the N variables according to the target configuration file obtained by the obtaining module, each of the variable value ranges comprising at least one variable value; a generating module configured to set a value of a corresponding variable in the target SQL according to each of the variable values in each of the variable value ranges determined by the determining module, and generate one SQL to obtain M SQLs, M being a positive integer; a parsing module configured to parse each of the M SQLs generated by the generating module into a syntax tree, each of the syntax trees comprising at least one parameter node; and the determining module is further configured to determine a data table corresponding to each of the parameter nodes in each of the syntax trees in the parsing module, and determine a mapping relationship between a first parameter node in each of the syntax trees and a data table corresponding to the first parameter node, the first parameter node being a parameter node corresponding to the data table, each of the mapping relationships being a mapping relationship between a parameter in the first parameter node and a field in the data table corresponding to the parameter; and an executing module configured to execute each of the M SQLs according to each of the mapping relationships determined by the determining module; and the determining module is further configured to determine whether the target SQL has a problem according to execution parameters of the M SQLs executed by the executing module.

[0020] In a third aspect, an embodiment of the present application provides an electronic device, the method comprising: a memory and at least one processor. The memory is in communication connection with the processor. The memory is configured to store computer program code, the computer program code comprising computer instructions. When the processor executes the computer instructions, the electronic device executes the method of the first aspect and any possible implementation manner thereof.

[0021] In a fourth aspect, an embodiment of the present application provides a computer readable storage medium, the computer readable storage medium storing computer instructions. When the computer instructions are executed by a processor, the computer instructions are used to implement the method of the first aspect and any possible implementation manner thereof.

[0022] In a fifth aspect, an embodiment of the present application provides a computer program product, which, when executed on a computer / implemented by a processor of a computer, implements the method according to the first aspect and any possible implementation thereof. Wherein, the computer can be the electronic device according to the third aspect and any possible implementation thereof.

[0023] It can be understood that the beneficial effects achievable by the SQL testing apparatus according to the second aspect, the electronic device according to the third aspect, the computer readable storage medium according to the fourth aspect, and the computer program product according to the fifth aspect can refer to the beneficial effects of the first aspect and any possible implementation thereof, which will not be repeated here. BRIEF DESCRIPTION OF DRAWINGS

[0024] Figure 1 A flowchart of a SQL testing method according to an embodiment of the present application is shown in FIG. 1; Figure 2 A flowchart of another SQL testing method according to an embodiment of the present application is shown in FIG. 2; Figure 3 A flowchart of another SQL testing method according to an embodiment of the present application is shown in FIG. 3; Figure 4 A flowchart of another SQL testing method according to an embodiment of the present application is shown in FIG. 4; Figure 5 A flowchart of another SQL testing method according to an embodiment of the present application is shown in FIG. 5; Figure 6 A flowchart of another SQL testing method according to an embodiment of the present application is shown in FIG. 6; Figure 7 A flowchart of another SQL testing method according to an embodiment of the present application is shown in FIG. 7; Figure 8 A flowchart of another SQL testing method according to an embodiment of the present application is shown in FIG. 8; Figure 9 A flowchart of another SQL testing method according to an embodiment of the present application is shown in FIG. 9; Figure 10 A structural diagram of a SQL testing apparatus according to an embodiment of the present application is shown in FIG. 10; Figure 11 A structural diagram of an electronic device according to an embodiment of the present application is shown in FIG. 11. DETAILED DESCRIPTION

[0025] Hereinafter, the terms "first", "second", "third", etc. are used only for the purpose of description, and should not be construed as indicating or implying relative importance or indicating the number of the technical features indicated. Therefore, the features defined with "first", "second" can explicitly or implicitly include one or more of the features. In the description of the embodiments, unless otherwise stated, the meaning of "a plurality of" is two or more.

[0026] The exemplary embodiments will be described in detail below with reference to the drawings. In the following description, the same numbers are used to designate the same elements, unless otherwise stated, in different drawings. The embodiments described in the following exemplary embodiments do not represent all the embodiments consistent with the present application. Rather, they are merely examples of devices and methods consistent with some aspects of the present application, as detailed in the appended claims.

[0027] The technical solutions provided by the embodiments of the present application comply with the relevant legal regulations and do not violate public order and good customs in the processing of the collection, storage, use, processing, transmission, provision and disclosure of financial data or user data and other information.

[0028] It should be noted that in the embodiments of the present application, some software, components, models and other existing solutions in the industry may be mentioned, which should be considered as exemplary, and the purpose is only to illustrate the feasibility of the implementation of the technical solutions of the present application, but it does not mean that the applicant has or will necessarily use the solution.

[0029] Currently, in the scene of testing software, a test pyramid model is used, wherein the test content level involved in various test types in the test pyramid model from user interface (User Interface, UI) testing, interface testing to unit testing is increasing step by step, and the execution of SQL is mainly involved in UI testing and interface testing, and neither of the two ways has the ability to traverse the full amount of SQL, and the verification ability for complex SQL is limited.

[0030] Generally, in the related art, the test device usually tests the to-be-tested SQL in the configuration file in the following two ways: 1) setting the value of the variable in the to-be-tested Structured Query Language (Structured Query Language, SQL) in the configuration file to a determined value, generating a test SQL, and testing the test SQL, so that according to the test result of testing the test SQL, it can be determined whether the to-be-tested SQL has a problem; 2) setting the variable of the to-be-tested SQL through the test case in the test environment, executing and monitoring the generated test SQL, so as to determine whether the to-be-tested SQL has a problem according to the execution parameter in the execution process.

[0031] However, because the number of definite values ​​in method 1) above is small, the number of test SQLs generated will be small; the number of test cases in method 2) above is small, which will also result in a small number of test SQLs generated. Therefore, it is impossible to cover various use cases, resulting in low accuracy of SQL testing.

[0032] To address the aforementioned technical problems, embodiments of this application provide a method, apparatus, device, medium, and program product for testing SQL. The following detailed description, in conjunction with accompanying drawings and scenarios, illustrates the SQL testing method, apparatus, device, medium, and program product provided in this application.

[0033] The SQL testing method provided in this application can be applied to scenarios where software is being tested.

[0034] Figure 1 This diagram illustrates a flowchart of a SQL testing method provided in an embodiment of this application. Figure 1 As shown, the SQL testing method provided in this application embodiment may include the following steps 101 to 106.

[0035] Step 101: Test the device to obtain the target configuration file.

[0036] In this embodiment of the application, the target configuration file includes target SQL, which includes N variables, where N is a positive integer greater than 1.

[0037] In some embodiments of this application, the target SQL can be considered as the SQL to be tested. The target SQL can be an SQL statement in the target configuration file, and the number of target SQLs can be at least one.

[0038] In some embodiments of this application, the target configuration file is used to define the mapping relationship between target SQL and Java methods. This target configuration file includes, but is not limited to, database configuration files, database persistence configuration files, etc. The target configuration file can be in XML format, but other formats are also possible; this application does not limit the specific format used.

[0039] In some embodiments of this application, the testing device can obtain the target configuration file from the target object through the testing device's collector. The target object may include, but is not limited to, a fixed file directory, a Git repository, or any other place capable of storing files.

[0040] In some embodiments of the present application, in the case where the test device acquires the target configuration file, the test device can delete a specific attribute in a preset type of label in the target SQL, wherein the preset type can include but is not limited to an operation type, such as a select type of select label, and the specific attribute can include but is not limited to a parameterType attribute and a resultType attribute. It can be understood that deleting the specific attribute in the preset type of label can avoid the error of not finding the attribute in the project, so that all input and output objects in the target SQL can be represented by a map object.

[0041] In some embodiments of the present application, in the case where the test device acquires the target configuration file, the test device can perform an identification operation on the target SQL in the target configuration file to assign a unique identifier to the target SQL. The unique identifier can be represented by "domain name.id", and of course, the unique identifier can also be represented in other ways, which are not limited in the embodiments of the present application. It can be understood that performing the identification operation on the target SQL can avoid the case where the id of the SQL is the same in different files.

[0042] In some embodiments of the present application, in the case where the test device acquires the target configuration file, the test device can modify all references containing domain names in the reference label content in the target SQL to local references. It can be understood that through the above processing, it can be ensured that each reference label content is valid, and the error in generating SQL text (such as M SQL in the following embodiments) based on the target configuration file can be avoided.

[0043] In some instances, after modifying all references containing domain names in the reference label content in the target SQL to local references, the test device can determine whether the reference label content is cross-domain. If not, the test device can ignore the reference label content and directly process (extract the target SQL); or if it is cross-domain, the test device can determine whether the reference of the reference label content has been traversed, if yes, the test device can add a reference node to the reference label content and process (extract the target SQL), if not, the test device can wait until the reference node is traversed to add the reference label content and process (extract the target SQL).

[0044] For example, Figure 2 A flowchart of another SQL test method provided by the embodiments of the present application is shown. In the case where the test device acquires the target configuration file, as shown in Figure 2 The test device can perform the following steps: Step 1, reading a persistent configuration file.

[0045] It can be understood that the target configuration file is taken as an example of the persistent configuration file in step 1.

[0046] Step 2, processing interference attributes.

[0047] Specifically, the test device can delete specific attributes in the preset type of tags in the target SQL.

[0048] Step 3, defining unique identification.

[0049] Specifically, the test device can perform an identification operation on the target SQL.

[0050] Step 4, processing reference tag content.

[0051] Specifically, the test device can modify all references containing domain names in the reference tag content in the target SQL into local references.

[0052] Step 5, determining whether the reference tag content is cross-domain.

[0053] It can be understood that the test device can determine whether the modified reference tag content is cross-domain.

[0054] If not, step 6 is performed, and if yes, step 7 is performed.

[0055] Step 6, ignoring tags and directly processing.

[0056] It can be understood that the test device can ignore the tags and continue to perform the following step 10.

[0057] Step 7, determining whether the reference of the reference tag content has been traversed.

[0058] If yes, step 8 is performed, and if not, step 9 is performed.

[0059] Step 8, adding a reference node and processing.

[0060] Specifically, the test device can add a reference node to the reference tag content and continue to perform the following step 10.

[0061] Step 9, adding reference tag content and processing after traversing to the reference node.

[0062] Specifically, the test device can add a reference node after waiting to traverse to the reference node and continue to perform the following step 10.

[0063] Step 10, extracting all target SQLs with unique identification as granularity.

[0064] Step 102, the test device determines the variable value range of each variable in the N variables according to the target configuration file.

[0065] In some embodiments of the present application, each of the N variables has at least one variable value range.

[0066] In some embodiments of the present application, the test device can read the target configuration file through the collector and parse the target configuration file through the parser, so that the test device can determine the variable value range of each of the N variables according to the parsed data.

[0067] In some examples, before the test device parses the target configuration file through the parser, the test device can read all uniquely identified target SQLs in the target configuration file through the collector and determine the N variables according to the target SQLs.

[0068] In some embodiments of the present application, in combination with Figure 1 As shown in Figure 3 The step 102 can be implemented by the following steps 1021 and 1022.

[0069] In step 1021, the test device obtains the logical expression corresponding to the target SQL from the first preset label in the target configuration file.

[0070] In some examples, the first preset label can include but is not limited to the test label and the foreach label.

[0071] In some examples, the test device can read all uniquely identified target SQLs in the target configuration file through the collector and obtain the logical expression corresponding to the target SQL from the first preset label in the target configuration file through the extractor.

[0072] In some examples, when the test device obtains the logical expression, the test device can process the logical expression through the extractor, for example, in the case that the logical expression has external object references, the test device can redefine the external object references to point to local objects. It can be understood that the test device redefines the external object references to point to local objects, which can avoid the situation that SQL cannot be generated or executed due to the absence of external reference objects in subsequent steps.

[0073] In step 1022, the test device determines the variable value range of each variable from the plurality of first ranges according to the logical expression.

[0074] In some embodiments of the present application, the plurality of first ranges include at least one of the following: a parameter range input by an external file associated with the target configuration file, a value range obtained based on the codes corresponding to the N variables.

[0075] In some examples, in a case where the plurality of first ranges include a parameter range of the external file input associated with the target configuration file and a value range obtained based on the code corresponding to the N variables, the test device can determine the parameter range of the external file input as the variable value range by the extractor, and then determine the value range obtained based on the code corresponding to the N variables as the variable value range by the extractor.

[0076] It should be noted that the determined variable value range satisfies full traversal of the logical expression.

[0077] Optionally, in a case where the plurality of first ranges include a value range obtained based on the code corresponding to the N variables, the test device can read a fixed value corresponding to each variable in the code, and then determine the fixed value as one critical value and a sum or difference value between the fixed value and a numerical value corresponding to the logical expression as another critical value according to the logical expression, to obtain the variable value range.

[0078] Table 1 shows the relationship between the logical expression and the variable value range. As shown in Table 1: Table 1

[0079] For example, in a case where one variable is taken as an example, if an expression of the variable in the logical expression is variable = character fixed value, one critical value of the variable value range corresponding to the variable can be the character fixed value, and another critical value can be the character fixed value + "1". If the expression of the variable in the logical expression is variable >= number fixed value, one critical value of the variable value range corresponding to the variable can be the number fixed value, and another critical value can be the number fixed value - 1, and so on.

[0080] As can be seen, since the test device can obtain the logical expression corresponding to the target SQL from the preset tag (i.e., the first preset tag) in the target configuration file, and accurately determine the variable value range of each variable from the parameter range of the external file input associated with the target configuration file and / or the value range obtained based on the code corresponding to the N variables according to the logical expression, the accuracy of the variable value range determined by the test device can be improved, so that a larger number of M SQLs covering more use scenarios can be generated, and then the test device can execute the larger number of M SQLs covering more use scenarios respectively to obtain a larger number of execution parameters covering more use scenarios, and accurately determine whether the target SQL has a problem according to the larger number of execution parameters covering more use scenarios, so that the accuracy of testing the SQL can be further improved.

[0081] Step 103: The testing equipment sets the value of the corresponding variable in the target SQL according to the possible values ​​of each variable in the variable value range, generates an SQL, and obtains M SQLs.

[0082] In the embodiments of this application, M is a positive integer.

[0083] In some embodiments of this application, each of the M SQL statements can be regarded as an SQL text, that is, an SQL text extracted from the target configuration file.

[0084] In some embodiments of this application, combined with Figure 1 ,like Figure 4 As shown, step 103 can be implemented through steps 1031 and 1032 as described below.

[0085] Step 1031: The testing equipment combines each possible value of each variable within its variable value range with each possible value of the other variables among the N variables, excluding the variable itself, to obtain M value combinations.

[0086] In this embodiment of the application, each of the above M value combinations includes one possible value for each variable and one possible value for other variables.

[0087] In some embodiments of this application, for each of the above N variables, the testing device can first determine a possible value 1 for that variable from the variable's value range, and then determine a possible value 2 for each variable from the variable's value range of each of the N variables excluding that variable. The device can then combine the possible value 1 with the N-1 possible values ​​2 to obtain a value combination. Furthermore, the testing device can determine another possible value 1 for that variable from the variable's value range, and then determine another possible value 2 for each variable from the variable's value range of each of the N variables excluding that variable. The device can then combine the other possible value 1 with another N-1 possible values ​​2 to obtain another value combination, and so on.

[0088] The following will use specific examples to illustrate the specific scheme for combining the possible values ​​of each variable in the embodiments of this application.

[0089] Assume the above N variables include variable 1, variable 2, and variable 3. The value range of variable 1 is [0,1], the value range of variable 2 is [0,2], and the value range of variable 3 is [0,1]. The possible values ​​of variable 1, variable 2, and variable 3 are shown in Table 2. Table 2

[0090] wherein the variable of the variable 1 can take values including 0 and 1, the variable of the variable 2 can take values including 0, 1 and 2, and the variable of the variable 3 can take values including 0 and 1.

[0091] In this case, the M value combinations are shown in Table 3: Table 3

[0092] wherein the numbers in Table 3 are used to indicate the serial numbers of the value combinations in the M value combinations, and the expressions in Table 3 are used to indicate the serial numbers of the value combinations in the M value combinations. For example, in the case of the number being 0, the variable of the variable 1 can take the value of 0, the variable of the variable 2 can take the value of 0, and the variable of the variable 3 can take the value of 0, and in this value, the variable of the variable 1, the variable of the variable 2 and the variable of the variable 3 can take values to combine to obtain the expression of the value combination, which can be 0*2*3+0*2+0, and the serial number of the value combination can be understood as 0.

[0093] It can be understood that through the combination of the 12 value ranges, all scenarios of SQL branches can be fully covered.

[0094] In some embodiments of the present application, in the case of obtaining M value combinations, the test device can further perform deduplication processing on the M value combinations. It can be understood that, since in the case of setting the value of the corresponding variable in the target SQL according to the variable of each value combination in the M value combinations, the execution logic of some SQLs may be repeated, therefore, the M value combinations need to be deduplicated to avoid unnecessary time waste.

[0095] In step 1032, the test device sets the value of the corresponding variable in the target SQL according to the variable of each variable in each value combination.

[0096] In some embodiments of the present application, for each value combination in the M value combinations, the test device can set the variable of each variable in one value device to the value of the corresponding variable in the target SQL, generate one SQL, and set the variable of each variable in another value device to the value of the corresponding variable in the target SQL, generate another SQL, and so on, to generate M SQLs.

[0097] Therefore, the test device can set the value of the corresponding variable in the target SQL according to the variable value in each of the M value combinations, and the values of the N variables in the M SQLs can cover all possible value combination cases, that is, a large number of M SQLs covering various use scenarios can be generated. Therefore, the test device can execute the large number of M SQLs covering various use scenarios respectively to obtain a large number of execution parameters covering various use scenarios, so that the test device can accurately determine whether the target SQL has a problem according to the execution parameters covering various use scenarios and in a large number, and thus the accuracy of testing the SQL can be improved.

[0098] For example, Figure 5 A flowchart of another SQL testing method provided by an embodiment of the present application is shown. After extracting all target SQLs uniquely identified as granularities, as shown in Figure 5 the test device can perform the following steps: Step 11, reading a target configuration file corresponding to the target SQL.

[0099] Specifically, after the collector extracts all target SQLs uniquely identified as granularities, the test device can read the target configuration file corresponding to the target SQL through the extractor.

[0100] Step 12, obtaining and processing a logical expression.

[0101] Specifically, the test device can obtain the logical expression corresponding to the target SQL from the first preset tag in the target configuration file through the extractor, and determine the variable value range of each variable from the plurality of first ranges according to the logical expression.

[0102] Step 13, parameter traversal combination.

[0103] Specifically, the test device can combine each variable value in the variable value range of each variable and each variable value in the variable value range of the other variable except the each variable in the N variables to obtain M value combinations through the extractor.

[0104] Step 14, checking whether the rule is satisfied.

[0105] Specifically, the test device can determine whether the determined variable value range satisfies full traversal of the logical expression through the extractor, and perform deduplication processing on the M value combinations.

[0106] Step 15, generating a SQL text list.

[0107] Specifically, the test device can set the value of the corresponding variable in the target SQL according to the variable value in each of the M value combinations through the extractor, generate one SQL, obtain M SQLs, and generate a SQL text list according to the M SQLs. The SQL text list can include the M SQLs.

[0108] Step 104, the test device parses each SQL into a syntax tree respectively.

[0109] In the embodiments of the present application, each syntax tree includes at least one parameter node.

[0110] In some embodiments of the present application, the test device can parse each SQL into a syntax tree respectively through the executor, and each syntax tree includes at least one parameter node.

[0111] Step 105, the test device determines the data table corresponding to the parameter node included in each syntax tree in the database respectively, and determines a mapping relationship according to the first parameter node of each syntax tree and the data table corresponding to the first parameter node respectively.

[0112] In the embodiments of the present application, the first parameter node is the parameter node corresponding to the data table, and each mapping relationship is the mapping relationship between the parameter in the first parameter node of each syntax tree and the field in the corresponding data table.

[0113] In some embodiments of the present application, the test device can determine all nodes experienced from the parameter node to the root node in each syntax tree as at least one parameter node included in the each syntax tree through the executor.

[0114] In some embodiments of the present application, part of the at least one parameter node included in each syntax tree has a corresponding data table in the database.

[0115] In some embodiments of the present application, the test device can obtain the table name and alias list of the data table corresponding to the at least one parameter node included in each syntax tree in the database, wherein the table name can be a physical table name, and when there is a subtable, the table name in the subtable is extracted. The table name and alias list represent all physical table information that the parameter node can reference. Thus, the test device can determine one or more optional tables according to the table name and alias list.

[0116] In some embodiments of this application, the testing device may first determine that at least one parameter node in each syntax tree corresponds to at least one parameter node in a data table in the database, and then take the processable node closest to the parameter in each syntax tree as the first parameter node.

[0117] For example, suppose the logical expression corresponding to a SQL statement is trim(users.name) = trim(concat(?,'a')). Although the closest node to the parameter is "concat", it cannot express the information of the field. Only the node "=" contains the information of the database table users.name. Therefore, the node "=" can be determined as the first parameter node in the syntax tree corresponding to this SQL statement.

[0118] It should be noted that the selection here requires iterating through the following types of expressions: SELECT field expressions, FROM expressions, JOIN expressions, and WHERE expressions. This is because parameters may exist in any of these expressions, and the depth of the hierarchy is uncertain.

[0119] In some instances, during the process of determining a mapping relationship based on the first parameter node of each syntax tree and the corresponding data table, the following situations may occur: 1. Fixed values, such as parameters in `limit` being set to fixed values; expressions like `?=1` can be set to either 1 or 0; 2. Corresponding to one or more fields; SQL allows fields to be used directly without table names, as long as the data is repeated in different tables, the database parser will automatically determine the specific table name. Since the database connection has not yet been established, multiple fields may exist.

[0120] It is understandable that interaction with the database is required in steps 104 and 105 above. (As above) Figure 5 As shown, a list of SQL texts has been generated, containing M SQL statements, meaning M complete SQL statements have been obtained. However, the parameter values ​​for these SQL statements have not been obtained. These parameter values ​​cannot be determined solely from these M SQL statements. During project development, these parameters are generated through user input or program assembly. However, the underlying logic in this application lacks these inputs and must be constructed manually from the database. Therefore, this underlying logic can be constructed using steps 104 to 105 above, enabling the test device to execute the M SQL statements based on the mapping relationship.

[0121] In the embodiments of the present application, in order to avoid the situation that the generated SQL cannot be executed due to the variable value setting of the corresponding variable in the target SQL (because the test device cannot determine the mapping relationship between the parameters in the parameter nodes in the syntax tree corresponding to the SQL and the data in the database, so it cannot obtain the data from the database according to the SQL), the embodiments of the present application can perform the above steps 104 and 105 to determine the above mapping relationship, thereby ensuring that the test device can accurately execute the M SQLs in the subsequent steps.

[0122] Step 106, the test device executes each corresponding SQL according to each mapping relationship, and determines whether the target SQL has a problem according to the execution parameters of the M SQLs.

[0123] In some embodiments of the present application, the execution parameters include at least one of the following: the time length of completing the execution of the SQL; the total number of logical reads in the process of executing the SQL; the total number of physical reads in the process of executing the SQL.

[0124] In some examples, the test device can input the data in the process of executing each SQL into a first model to output the execution parameters through the first model, wherein the first model can be an AI model.

[0125] Optionally, in the case where the execution parameters include the time length of completing the execution of the SQL, the first model can include a fixed time length analysis model; and the data in the process of executing each SQL can include time data (such as the time of starting to execute the SQL, the time of completing the execution of the SQL, etc.).

[0126] Optionally, in the case where the execution parameters include at least one of the total number of logical reads in the process of executing the SQL and the total number of physical reads in the process of executing the SQL, the first model can include an execution plan analysis model; and the data in the process of executing each SQL can include the execution plan when the SQL is executed.

[0127] As can be seen, since the parameters related to the execution performance of the SQL (i.e., at least one of the time length of completing the execution of the SQL, the total number of logical reads in the process of executing the SQL, and the total number of physical reads in the process of executing the SQL) can be set as the execution parameters, the test device can obtain execution parameters of different dimensions, and detect whether the target SQL has a problem according to the execution parameters of different dimensions, so the reliability of testing the SQL can be further improved.

[0128] In some embodiments of the present application, the test device can execute the corresponding SQL according to each mapping relationship respectively through the executor.

[0129] In some embodiments of the present application, in combination with Figure 1 As shown in Figure 6 The step 106 can be implemented through the following steps 1061 to 1063.

[0130] The step 1061 comprises determining, by the test device, a field corresponding to each parameter in a first parameter node of a first syntax tree corresponding to a first mapping relationship according to the first mapping relationship.

[0131] In the embodiments of the present application, the first mapping relationship is any one of the at least one mapping relationship.

[0132] The at least one mapping relationship can be all the mapping relationships determined in the step 105.

[0133] The step 1062 comprises obtaining, by the test device, at least one data from a data table corresponding to the first parameter node of the first syntax tree according to a field corresponding to each parameter.

[0134] Optionally, in combination with Figure 6 As shown in Figure 7 The step 1062 can be implemented through at least one of the following steps 1062a to 1062c.

[0135] The step 1062a comprises obtaining, by the test device, at least one data with the largest statistical quantity from the data table corresponding to the first parameter node of the first syntax tree according to a first field corresponding to a first parameter.

[0136] In the embodiments of the present application, the first parameter is any one of the parameters in the first parameter node, and the first field is a field corresponding to the first parameter.

[0137] For example, the test device can obtain at least one data with the largest statistical quantity from the data table according to a first field corresponding to a first parameter based on a TOP model. The TOP model can be an artificial intelligence AI model.

[0138] The step 1062b comprises obtaining, by the test device, at least one data from the data table corresponding to the first parameter node of the first syntax tree according to a first field corresponding to a first parameter.

[0139] In the embodiments of the present application, the first parameter is any one of the parameters in the first parameter node of the first syntax tree, and the first field is a field corresponding to the first parameter.

[0140] Exemplarily, the test device can randomly obtain at least one data from the data table corresponding to the first parameter node of the first syntax tree according to the first field corresponding to the first parameter based on a random model.

[0141] In step 1062c, the test device obtains at least one data from the data table according to the first field corresponding to the first parameter and the field associated with the first field.

[0142] In the embodiments of the present application, the first parameter is any one of the parameters in the first parameter node, and the first field is the field corresponding to the first parameter.

[0143] Exemplarily, the field associated with the first field can be a field in the field corresponding to the first parameter, or a field corresponding to another parameter.

[0144] Exemplarily, the test device can obtain at least one data from the data table according to the first field corresponding to the first parameter and the field associated with the first field based on an association model.

[0145] As can be seen, since the test device can obtain a plurality of different data from the data table corresponding to the first parameter node of the first syntax tree according to the first field, it can ensure that the test device can accurately execute the SQL corresponding to the first syntax tree, thereby improving the accuracy of the obtained execution parameters, and further ensuring that the test device can determine whether the target SQL has a problem according to the accurate execution parameters. Therefore, the reliability of testing the SQL can be further improved.

[0146] In step 1063, the test device combines at least one data corresponding to each parameter to obtain combined data, and determines whether the target SQL has a problem according to the execution parameters of the M SQLs.

[0147] Optionally, the test device can combine at least one data in a random order or in a predefined order to obtain combined data. The predefined order can include, but is not limited to, the order of time of obtaining, etc.

[0148] Therefore, the test device can accurately and completely execute the SQL corresponding to the first syntax tree according to the first mapping relationship, so that the test device can accurately execute the SQL corresponding to the first syntax tree according to the first mapping relationship, and the situation that the SQL corresponding to the first syntax tree cannot be executed is avoided, and thus the reliability of the test on the SQL is further improved.

[0149] For example, Figure 8 A flowchart of another method for testing an SQL provided by an embodiment of the present application is shown. After the above SQL text list is generated, as shown in Figure 8 The test device can perform the following steps. Step 16, reading one SQL and parsing it into a syntax tree.

[0150] Step 17, obtaining all parameter node paths.

[0151] Specifically, the test device can determine all nodes experienced from a parameter node to a root node in each syntax tree as at least one parameter node included in the each syntax tree by an executor.

[0152] Step 18, obtaining a table name and alias list for each parameter node.

[0153] Specifically, the test device can obtain a table name and alias list of a data table in a database corresponding to at least one parameter node included in each syntax tree, wherein the table name can be a physical table name, and when there is a sub-table, a table name in the sub-table is extracted, and the table name and alias list represent all physical table information that can be referenced by the parameter node. Therefore, the test device can determine one or more optional tables according to the table name and alias list.

[0154] Step 19, selecting a parameter processing node.

[0155] Specifically, the above parameter processing node can be the above first parameter node. The test device can first determine that there is at least one parameter node corresponding to a data table in a database in at least one parameter node included in each syntax tree, and then determine a processing node closest to a parameter in the at least one parameter node in each syntax tree as a first parameter node.

[0156] Step 20, mapping a parameter and a database field relationship.

[0157] Specifically, in the process of determining a mapping relationship based on the first parameter node of each syntax tree and the corresponding data table, the following situations may occur: 1. Fixed values, such as parameters in `limit` being set to fixed values; expressions like `?=1` can be set to either 1 or 0; 2. Corresponding to one or more fields; SQL allows fields to be used directly without table names, as long as the data is repeated in different tables, the database parser will automatically determine the specific table name. Since the database connection has not yet been established, multiple fields may exist.

[0158] In some embodiments of this application, combined with Figure 1 ,like Figure 9 As shown, step 106 can be implemented through step 1064 or step 1065 as described below.

[0159] Step 1064: The test device executes the corresponding SQL according to each mapping relationship, and if the parameter value of the execution parameter of any SQL in the M SQLs is greater than or equal to the parameter threshold, it is determined that the target SQL has a problem.

[0160] In some instances, the testing equipment can use an analyzer to determine the relationship between the parameter values ​​and parameter thresholds of the execution parameters of M SQL statements. Thus, if the parameter value of the execution parameter of any of the M SQL statements is greater than or equal to the parameter threshold, the testing equipment can use the analyzer to determine that there is a problem with the target SQL statement.

[0161] Step 1065: The test device executes the corresponding SQL according to each mapping relationship, and if the parameter value of the execution parameter of each SQL in the M SQLs is less than the parameter threshold, it is determined that the target SQL has no problem.

[0162] In some instances, the testing equipment can use an analyzer to determine the relationship between the parameter values ​​and parameter thresholds of the execution parameters of M SQL statements. Thus, if the parameter value of the execution parameter of each of the M SQL statements is less than the parameter threshold, the testing equipment can use the analyzer to determine that the target SQL statement does not have a problem.

[0163] Thus, it can be seen that since the testing equipment can determine whether the target SQL has a problem if the parameter value of the execution parameter of any SQL in the M SQLs is greater than or equal to the parameter threshold, or determine that the target SQL does not have a problem if the parameter value of the execution parameter of each SQL in the M SQLs is less than the parameter threshold, the testing equipment can accurately determine whether the target SQL has a problem based on the execution parameters and parameter thresholds of the M SQLs. This allows the testing equipment to obtain accurate test results for the target SQL, thereby improving the reliability of SQL testing.

[0164] The embodiment of the present application provides a test method of SQL, a test device can acquire a target configuration file, the target configuration file includes a target SQL, the target SQL includes N variables, N is a positive integer greater than 1, and according to the target configuration file, the variable value range of each variable in the N variables is determined respectively, each variable value range includes at least one variable value, and according to each variable value in the variable value range of each variable, the value of the corresponding variable in the target SQL is set, one SQL is generated, M SQLs are obtained, and M is a positive integer, so that the test device can parse each SQL into a syntax tree respectively, each syntax tree includes at least one parameter node, and the data table corresponding to the parameter node in each syntax tree in the database is determined respectively, and according to the first parameter node of each syntax tree and the data table corresponding to the first parameter node, a mapping relationship is determined, the first parameter node is the parameter node corresponding to the data table, and each mapping relationship is the mapping relationship between the parameter in the first parameter node of each syntax tree and the field in the corresponding data table. So the test device can execute the corresponding SQL according to each mapping relationship respectively, and determine whether the target SQL has a problem according to the execution parameters of the M SQLs. Because the test device can determine the variable value range of each variable in the N variables in the target SQL according to the target configuration file when the target configuration file is acquired, and set the value of the corresponding variable in the target SQL according to each variable value in the variable value range of each variable, that is, use a large number of variable values to set the value of the corresponding variable in the target SQL, so a large number of M SQLs covering a large number of use scenarios can be generated, therefore, the test device can execute a large number of M SQLs covering a large number of use scenarios respectively, obtain a large number of execution parameters covering a large number of use scenarios, so that the test device can accurately determine whether the target SQL has a problem according to the large number of execution parameters covering a large number of use scenarios. Moreover, the test device can parse each SQL into a syntax tree respectively, and determine the data table corresponding to the parameter node in each syntax tree in the database, and determine a mapping relationship (that is, the mapping relationship between the parameter in the first parameter node of a syntax tree and the field in the corresponding data table) according to the first parameter node of each syntax tree and the data table corresponding to the first parameter node, so that the test device can accurately know the position of the field corresponding to each SQL in the database according to each mapping relationship, and accurately execute the corresponding SQL, avoiding the problem that the SQL cannot be accurately executed because the position of the field corresponding to the SQL in the database cannot be determined, so it can be ensured that the test device can test the target SQL. In this way, the reliability of testing the SQL can be ensured, and the accuracy of testing the SQL can be improved.

[0165] Figure 10 A structural schematic diagram of a test device of an SQL is provided for an embodiment of the present application. As shown in the figure, the test device of the SQL 200 can include an acquisition module 201, a determination module 202, a generation module 203, an analysis module 204, and an execution module 205. Figure 10

[0166] The acquisition module 201 is configured to acquire a target configuration file, the target configuration file including a target SQL, the target SQL including N variables, N being a positive integer greater than 1. The determination module 202 is configured to determine a variable value range of each variable in the N variables according to the target configuration file acquired by the acquisition module 201, each variable value range including at least one variable value. The generation module 203 is configured to set a value of a corresponding variable in the target SQL according to each variable value in each variable value range of each variable determined by the determination module 202, generate an SQL, and obtain M SQLs, M being a positive integer. The analysis module 204 is configured to analyze each SQL generated by the generation module 203 into a syntax tree, each syntax tree including at least one parameter node. The determination module 202 is further configured to determine a data table corresponding to a parameter node included in each syntax tree obtained by the analysis module 204 in the database, and determine a mapping relationship according to a first parameter node of each syntax tree and a data table corresponding to the first parameter node, the first parameter node being a parameter node corresponding to the data table, each mapping relationship being a mapping relationship between a parameter in the first parameter node of each syntax tree and a field in the corresponding data table. The execution module 205 is configured to execute a corresponding SQL according to each mapping relationship determined by the determination module 202. The determination module 202 is further configured to determine whether the target SQL has a problem according to an execution parameter of the M SQLs executed by the execution module 205.

[0167] ​The SQL testing device provided in the embodiments of the present application can determine the variable value range of each variable in the N variables in the target SQL in the target configuration file, and set the value of the corresponding variable in the target SQL according to each variable value in the variable value range of each variable, i.e., use a large number of variable values to set the value of the corresponding variable in the target SQL, so that a large number of M SQLs covering a large number of use scenarios can be generated. Therefore, the SQL testing device can execute the large number of M SQLs covering a large number of use scenarios to obtain a large number of execution parameters covering a large number of use scenarios, so that the SQL testing device can accurately determine whether the target SQL has a problem according to the large number of execution parameters covering a large number of use scenarios. In addition, the SQL testing device can parse each SQL into a syntax tree, determine the data table corresponding to the parameter node in each syntax tree in the database, and determine a mapping relationship (i.e., the mapping relationship between the parameter in the first parameter node of each syntax tree and the field in the corresponding data table) according to the first parameter node of each syntax tree and the data table corresponding to the first parameter node. Therefore, the SQL testing device can accurately determine the position of the field corresponding to each SQL in the database according to each mapping relationship, and accurately execute the corresponding SQL, thereby avoiding the problem that the SQL cannot be accurately executed due to the inability to determine the position of the field corresponding to the SQL in the database. Therefore, it can be ensured that the SQL testing device can test the target SQL. In this way, the reliability of testing the SQL can be ensured, and the accuracy of testing the SQL can be improved.

[0168] In some embodiments, the determining module 202 is specifically configured to: obtain the logical expression corresponding to the target SQL from the first preset tag in the target configuration file; and determine the variable value range of each variable from the plurality of first ranges according to the logical expression, wherein the plurality of first ranges include at least one of the following: the parameter range input by the external file associated with the target configuration file, and the value range obtained based on the code corresponding to the N variables.

[0169] In some embodiments, the execution module 205 is specifically configured to: determine the field corresponding to each parameter in the first parameter node of the first syntax tree corresponding to the first mapping relationship according to the first mapping relationship, wherein the first mapping relationship is any one of the at least one mapping relationship; obtain at least one data from the data table corresponding to the first parameter node of the first syntax tree according to the field corresponding to each parameter; and combine the at least one data corresponding to each parameter to obtain the combined data.

[0170] In some embodiments, the execution module 205 is specifically configured to perform at least one of the following: obtaining, from the data table corresponding to the first parameter node of the first syntax tree, at least one data with the largest statistical quantity according to the first field corresponding to the first parameter; randomly obtaining, from the data table corresponding to the first parameter node of the first syntax tree, at least one data according to the first field corresponding to the first parameter; and obtaining, from the data table corresponding to the first parameter node of the first syntax tree, at least one data according to the first field corresponding to the first parameter and a field associated with the first field, wherein the first parameter is any one of the first parameter nodes of the first syntax tree, and the first field is a field corresponding to the first parameter.

[0171] In some embodiments, the generation module 203 is specifically configured to combine, according to each variable value in the variable value range of each variable, a variable value of the each variable and a variable value of another variable in the variable value range of the other variable except the each variable in the N variables, to obtain M value combinations, each of which includes the variable value of the each variable and the variable value of the other variable; and set, according to each variable value in each value combination, a value of a corresponding variable in the target SQL.

[0172] In some embodiments, the execution parameter includes at least one of the following: a time length for completing execution of the SQL; a total number of logical reads in a process of executing the SQL; and a total number of physical reads in the process of executing the SQL.

[0173] In some embodiments, the determination module 202 is specifically configured to determine that the target SQL has a problem in any of the following cases: a parameter value of an execution parameter of any one of the M SQLs is greater than or equal to a parameter threshold; and a parameter value of an execution parameter of each of the M SQLs is less than a parameter threshold.

[0174] Figure 11 A structural schematic diagram of an electronic device is provided in embodiments of the present application. As shown in the figure, the electronic device can include a memory 301 and at least one processor 302. Figure 11

[0175] The memory 301 is configured to store computer program code including computer instructions. The computer instructions run in the electronic device described above to implement the method shown in the method embodiments described above. For example, the memory can include a high-speed random access memory (RAM), and can also include a non-volatile memory (NVM), such as at least one disk memory, and can also be a U disk, a mobile hard disk, a read-only memory, a magnetic disk or an optical disk, etc. ​

[0176] The processor 302 can be a general processor, including a central processing unit (CPU), a network processor (NP), etc. The processor 302 can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic device, a discrete gate or transistor logic component, a discrete hardware component. The processor 302 can also be other general processors. The general processor can be a microprocessor or the processor can also be any conventional processor.

[0177] The memory 301 and the processor 302 are communicatively connected. For example, the memory 301 can be connected with the processor 302 through a system bus and complete mutual communication. The system bus can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, an industry standard architecture (ISA) bus, etc. The system bus can be divided into an address bus, a data bus, a control bus, etc. For the convenience of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or only one type of bus.

[0178] Optionally, the memory 301 can be independent or integrated with the processor 302. When the memory 301 is independently arranged, the memory 301 and the processor 302 are connected through a system bus.

[0179] The embodiment of the present application further provides a chip for running instructions, which is used for executing the technical solutions of the SQL test method in the above embodiment.

[0180] The embodiment of the present application further provides a computer readable storage medium, which stores computer instructions. When the computer instructions are executed by a processor, the technical solutions of the SQL test method in the above embodiment are implemented. Specifically, when the computer instructions are executed by the processor, the above electronic device can execute the technical solutions of the SQL test method in the above embodiment.

[0181] The embodiment of the present application further provides a computer program product, which comprises a computer program stored in a computer readable storage medium, at least one processor can read the computer program from the computer readable storage medium, and the at least one processor can implement the technical solution of the SQL testing method in the above embodiment when executing the computer program.

[0182] The computer readable storage medium can be realized by any type of volatile or nonvolatile storage devices or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk or optical disk. The computer readable storage medium can be any available medium that can be accessed by a general or special purpose computer.

[0183] An exemplary computer readable storage medium is coupled to the processor, so that the processor can read information from the storage medium and write information to the computer readable storage medium. Of course, the computer readable storage medium can also be an integral part of the processor. The processor and the computer readable storage medium can be located in an application specific integrated circuit (ASIC). Of course, the processor and the computer readable storage medium can also exist as discrete components in an electronic control unit or a host device, and the embodiment of the present application does not limit this.

[0184] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative, for example, the division of the modules is only a logical function division, and actual implementation can have another division manner, for example, a plurality of modules can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the displayed or discussed ones can be indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.

[0185] The modules described as separate components may or may not be physically separate, and the components shown as modules may or may not be physical units, i.e., may be located in one place, or may be distributed to multiple network units. Part or all of the modules can be selected according to actual needs to implement the embodiments of the present application.

[0186] In addition, the functional modules in each embodiment of the present application can be integrated in one processing unit, or each module can be physically present alone, or two or more modules can be integrated in one unit. The unit formed by the above modules can be realized in the form of hardware or in the form of hardware plus software functional units.

[0187] The integrated modules realized in the form of software functional modules can be stored in a computer readable storage medium. The software functional modules stored in a storage medium include a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to execute part of the steps of the method of each embodiment of the present application.

[0188] It should be understood that the steps of the method disclosed in the embodiments of the present application can be directly embodied as hardware processor execution, or executed by a combination of hardware and software modules in the processor.

[0189] Those of ordinary skill in the art can understand that all or part of the steps of the above-mentioned method embodiments can be completed by program instruction related hardware. The aforementioned program can be stored in a computer readable storage medium. The program, when executed, executes steps including the above-mentioned method embodiments; and the aforementioned storage medium includes ROM, RAM, magnetic or optical disk, and various media that can store program codes.

[0190] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit them; although the present application has been described in detail with reference to the above embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the above embodiments, or make equivalent replacements for part or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A SQL testing method, applied to testing equipment, characterized in that, include: Obtain the target configuration file, which includes the target structured query language (SQL) and the target SQL includes N variables, where N is a positive integer greater than 1; Based on the target configuration file, determine the value range of each of the N variables, with each variable's value range including at least one possible value. Based on the possible values ​​of each variable in the variable value range of each variable, set the value of the corresponding variable in the target SQL, generate an SQL, and obtain M SQL, where M is a positive integer; Each SQL statement is parsed into a syntax tree, and each syntax tree includes at least one parameter node. Each syntax tree includes a parameter node that corresponds to a data table in the database. Based on the first parameter node of each syntax tree and the data table corresponding to the first parameter node, a mapping relationship is determined. The first parameter node is the parameter node that corresponds to a data table. Each mapping relationship is the mapping relationship between the parameter in the first parameter node of each syntax tree and the field in the corresponding data table. For each mapping relationship, execute the corresponding SQL, and determine whether the target SQL has any problems based on the execution parameters of the M SQL statements.

2. The method according to claim 1, characterized in that, The step of determining the value range of each of the N variables according to the target configuration file includes: Obtain the logical expression corresponding to the target SQL from the first preset tag in the target configuration file; Based on the logical expression, the range of values ​​for each variable is determined from multiple first ranges respectively; The plurality of first ranges include at least one of the following: the parameter range of the external file input associated with the target configuration file, and the value range obtained based on the code corresponding to the N variables.

3. The method according to claim 1, characterized in that, The step of executing the corresponding SQL based on each mapping relationship includes: Based on the first mapping relationship, determine the field corresponding to each parameter in the first parameter node of the first syntax tree corresponding to the first mapping relationship, wherein the first mapping relationship is any one of at least one mapping relationship; Based on the field corresponding to each parameter, at least one piece of data is obtained from the data table corresponding to the first parameter node in the first syntax tree; Combine at least one piece of data corresponding to each parameter to obtain combined data.

4. The method according to claim 3, characterized in that, The step of retrieving at least one piece of data from the data table corresponding to the first parameter node in the first syntax tree based on the field corresponding to each parameter includes at least one item: Based on the first field corresponding to the first parameter, retrieve at least one data point with the largest statistic from the data table corresponding to the first parameter node of the first syntax tree; Based on the first field corresponding to the first parameter, at least one piece of data is randomly obtained from the data table corresponding to the first parameter node of the first syntax tree; Based on the first field corresponding to the first parameter, and based on the field associated with the first field, at least one piece of data is obtained from the data table corresponding to the first parameter node in the first syntax tree; Wherein, the first parameter is any parameter in the first parameter node of the first syntax tree, and the first field is the field corresponding to the first parameter.

5. The method according to claim 1, characterized in that, The step of setting the value of the corresponding variable in the target SQL according to each possible value of the variable in the variable value range of each variable includes: M value combinations are obtained by combining each possible value of each variable in the variable value range of each variable and each possible value of the other variables in the N variables excluding each variable. Each value combination includes one possible value of each variable and one possible value of the other variables. Based on the possible values ​​of each variable in each value combination, set the value of the corresponding variable in the target SQL.

6. The method according to claim 1, characterized in that, The execution parameters include at least one of the following: The time taken to complete the SQL execution; Total number of logical reads during SQL execution; Total number of physical reads during SQL execution.

7. The method according to claim 1 or 6, characterized in that, Determining whether the target SQL has a problem based on the execution parameters of the M SQL statements includes any of the following: If the parameter value of the execution parameter of any of the M SQL statements is greater than or equal to the parameter threshold, the target SQL statement is determined to have a problem. If the parameter value of the execution parameter of each of the M SQL statements is less than the parameter threshold, it is determined that the target SQL statement does not have a problem.

8. A test apparatus for SQL, characterized in that, include: The acquisition module is used to acquire the target configuration file, which includes the target SQL, and the target SQL includes N variables, where N is a positive integer greater than 1; The determining module is used to determine the variable value range of each of the N variables based on the target configuration file obtained by the obtaining module, wherein each variable value range includes at least one possible value for the variable; The generation module is used to set the value of the corresponding variable in the target SQL according to the possible values ​​of each variable in the variable value range determined by the determining module, and generate an SQL, resulting in M ​​SQLs, where M is a positive integer; The parsing module is used to parse each SQL generated by the generation module into a syntax tree, and each syntax tree includes at least one parameter node; The determining module is further configured to determine the data table in the database corresponding to the parameter node of each syntax tree parsed by the parsing module, and to determine a mapping relationship based on the first parameter node of each syntax tree and the data table corresponding to the first parameter node. The first parameter node is a parameter node corresponding to a data table, and each mapping relationship is a mapping relationship between the parameter in the first parameter node of each syntax tree and the field in the corresponding data table. The execution module is used to execute the corresponding SQL according to each mapping relationship determined by the determining module; The determining module is further configured to determine whether the target SQL has a problem based on the execution parameters of the M SQL statements executed by the execution module.

9. An electronic device, characterized in that, include: A memory and at least one processor; the memory is communicatively connected to the processor; the memory is used to store computer program code, the computer program code including computer instructions; when the processor executes the computer instructions, the electronic device performs the method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed by a processor, are used to implement the method as described in any one of claims 1 to 7.

11. A computer program product, characterized in that, When the computer program product is run on a computer / executed by the computer's processor, it implements the method as described in any one of claims 1 to 7.