Relational database testing method and device, electronic equipment, medium and product
By generating structured query framework statements and data object relationship rules, and combining structured query test statements, the problem of inaccurate test results in the existing technology is solved and more accurate database test results are achieved.
Patent Information
- Application Number
- CN202411709953.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-26
- Publication Date
- 2025-02-28
AI Technical Summary
When the test statements generated by the existing relational database testing method execute tests on the database, the test results obtained are inaccurate and cannot accurately reflect the characteristics of the database.
By generating structured query framework statements based on the test objectives of the database to be tested, obtaining data element information, and generating data object relationship rules; combining structured query test statements based on the framework statement and relationship rules, and sending them to the database to perform tests.
Improve the accuracy of database test results, so that the test results can better reflect the real characteristics of the database.
Smart Images

Figure CN119537241A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of database testing, and in particular to a relational database testing method, device, electronic equipment, medium and product. Background Art
[0002] In scenarios such as database application migration and database application launch, the database needs to be tested to ensure database performance and integrity and verify the true capabilities of the database and the application system.
[0003] At present, some relational database testing methods directly generate structured query test statements based on the grammatical rules of structured query statements; however, when the test statements generated by this method are used to test the database, the test results obtained are inaccurate and cannot accurately reflect the characteristics of the database. Summary of the invention
[0004] The present application provides a relational database testing method, device, electronic device, medium and product to improve the accuracy of database testing results.
[0005] In a first aspect, the present application provides a relational database testing method, the method comprising: generating a structured query framework statement based on the grammatical rules of the structured query statement according to the test target of the database to be tested; obtaining data metadata information of the database to be tested, and generating data object relationship rules of the database to be tested based on the data metadata; the data object relationship rules represent the hierarchical relationship between data objects; according to the structured query framework statement and the data object relationship rules, a structured query test statement is generated by combining; the structured query test statement is sent to the database to be tested to execute the test and generate a test result.
[0006] In a possible implementation, a structured query framework statement is generated according to a test objective of a database to be tested, including: generating keywords and non-keywords in the structured query statement according to a grammatical rule of the structured query statement; parsing non-keywords step by step according to the test objective to obtain a main framework of the structured query statement; and combining keywords in the structured query statement based on the main framework of a structured query language to obtain a structured query framework statement.
[0007] In a possible implementation, the non-keyword tag in the structured query framework statement is consistent with the data tag of the data object relationship rule; based on the structured query framework statement and the data object relationship rule, a structured query test statement is generated in combination, specifically including: if the structured query framework statement is a selection query statement, a first processing flow is executed; the first processing flow includes: determining the non-keyword tag that needs to be filled in the selection query statement; based on the non-keyword tag that needs to be filled in the selection query statement, selecting the data object under the data tag that is consistent with the non-keyword tag in the data object relationship rule to fill in the non-keyword tag part.
[0008] In a possible implementation, according to the non-keyword tag that needs to be filled in the selection query statement, the data objects under the data tags consistent with the non-keyword tags in the data object relationship rules are selected and filled into the non-keyword tag part, including: if the selection query statement contains multiple data table tags, the data table with a foreign key relationship in the data object relationship rule is preferentially selected for filling; if there is no foreign key relationship, the data table containing the same data type column name is selected for filling; if the selection query statement does not contain multiple data table tags, any data architecture pattern node in the data object relationship rule is selected, and the data object consistent with the non-keyword tag of the structured query framework statement under the architecture pattern node is selected to fill into the non-keyword tag; if the selected data architecture pattern node contains a data table tag, the data object under the data table tag node is selected to fill into the non-keyword tag.
[0009] In a possible implementation, the method also includes: if the selection query statement includes a filter statement, and the clause of the filter statement contains a first actual value label, then according to the database to be tested, a value corresponding to the number of first actual value labels is selected and filled into the corresponding first actual value label; if the clause of the non-filter statement in the selection query statement contains a second actual value label, then according to the column name label type preceding the second actual value label, a random value corresponding to the number of second actual value labels is generated by a random function and filled into the second actual value label.
[0010] In a possible implementation, a value corresponding to the first actual value label quantity is selected according to the database to be tested, including: generating a query statement according to the data table label and the filter statement of the selection query statement; sending the query statement to the database to be tested, executing the data query, and obtaining the query result; and randomly selecting a value corresponding to the first actual value label quantity in the query result.
[0011] In a possible implementation, a structured query test statement is generated based on a structured query framework statement and a data object relationship rule, specifically including: if the structured query framework statement is a creation statement, a first processing flow is executed for a clause of a selection query statement in the creation statement, and a second processing flow is executed for other statements in the creation statement; the second processing flow includes: randomly generating a data object according to the data object relationship rule, and filling the obtained data object into the non-keyword tag part in the structured query framework statement.
[0012] In a possible implementation, a structured query test statement is generated based on a structured query framework statement and a data object relationship rule, which specifically includes: if the structured query framework statement is neither a selection query statement nor a creation statement, a third processing flow is executed; the third processing flow includes selecting a data object under any data architecture pattern node in the data object relationship rule and filling it into the non-keyword tag part.
[0013] In one possible implementation, a query statement is selected to include non-keyword tags at different levels; the method also includes: for non-keyword tags at the same level, selecting data objects to be filled in the non-keyword tags from data objects under corresponding data level nodes in data object relationship rules.
[0014] In a possible implementation, the structured query test statement is saved to a specified file.
[0015] In a possible implementation, the method further includes: correcting the grammatical rules of the structured query statement according to the test result.
[0016] In a second aspect, the present application provides a relational database testing device, which includes: a generation module, which is used to generate a structured query framework statement based on the grammatical rules of the structured query statement according to the test target of the database to be tested; the generation module is also used to obtain data metadata information of the database to be tested, and generate data object relationship rules of the database to be tested based on the data metadata; the data object relationship rules represent the hierarchical relationship between data objects; a combination module, which is used to combine and generate a structured query test statement based on the structured query framework statement and the data object relationship rules; and a test module, which is used to send the structured query test statement to the database to be tested to execute the test and generate a test result.
[0017] In a third aspect, the present application provides an electronic device, comprising: a processor, and a memory communicatively connected to the processor; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory to implement the above method.
[0018] In a fourth aspect, the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the above method.
[0019] In a fifth aspect, the present application provides a computer program product, including a computer program, which is used to implement the above method when executed by a processor.
[0020] In the relational database testing method, device, electronic device, medium and product provided by the present application, a structured query framework statement is generated based on the grammatical rules of the structured query statement according to the test target of the database to be tested; data meta information of the database to be tested is obtained, and data object relationship rules of the database to be tested are generated based on the data meta information; wherein the data object relationship rules represent the hierarchical relationship between data objects; a structured query test statement is generated by combining the structured query framework statement and the data object relationship rules; the structured query test statement is sent to the database to be tested to perform the test and generate the test result. The scheme of the present application is based on combining the real data objects of the database with the structured framework statement, so that the generated structured test statement is more accurate, and the test result obtained by using the structured test statement to perform the test on the database is more accurate, and the test result can more accurately reflect the characteristics of the database. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0022] Figure 1 A schematic diagram of a relational data testing method is shown in FIG.
[0023] Figure 2 This is a schematic diagram of the processing flow of the relational database testing method of this application;
[0024] Figure 3 This is a schematic diagram of data object relationship rules as an example;
[0025] Figure 4 The figure is a flow chart showing a relational database testing method by way of example;
[0026] Figure 5 Generate rule diagrams for the structured query test statements applied for;
[0027] Figure 6 A schematic diagram of the structure of a relational database testing device is shown in FIG.
[0028] Figure 7A structural schematic diagram of an electronic device is exemplarily shown in FIG.
[0029] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0030] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0031] It should be noted that the brief description of the terms in this application is only for the convenience of understanding the implementation methods described below, and is not intended to limit the implementation methods of this application. Unless otherwise specified, these terms should be understood according to their ordinary and usual meanings. The terms "first", "second", etc. in the specification and claims and the above-mentioned drawings in this application are used to distinguish similar or similar objects or entities, and do not necessarily mean to limit a specific order or sequence, unless otherwise indicated. It should be understood that the terms used in this way can be interchangeable where appropriate, for example, they can be implemented in an order other than those given in the diagram or description of the embodiment of this application. The terms "including" and "having" in the specification and claims and the above-mentioned drawings in this application and any of their variations are intended to cover but not exclude inclusion, for example, a product or device containing a series of components is not necessarily limited to those components clearly listed, but may include other components that are not clearly listed or inherent to these products or devices. The term "module" used in this application refers to any known or later developed hardware, software, firmware, artificial intelligence, fuzzy logic or a combination of hardware or / and software code that can perform functions related to the element.
[0032] In scenarios such as database application migration and database application launch, in most scenarios, real business data already exists in the database. Since the data in the database determines the actual performance of the application system, in order to ensure the performance and integrity of the database and verify the true capabilities of the database and the application system, the database needs to be tested.
[0033] At present, some relational database testing methods directly generate structured query test statements based on the grammatical rules of structured query statements; since all the final filling except the keyword part is based on a fixed list of database objects and data values, the structured query test statements generated by this method are structured query test statements for specific data, feature object names and feature object relationships. The data objects and grammatical rules of structured query statements that can be covered are relatively fixed and have no relevance to the data in the database, which is insufficient in scenarios such as database application migration and database capability verification. However, when the test statements generated by this method are used to test the database, the test results obtained are inaccurate, cannot accurately reflect the characteristics of the database, and cannot fully test the database.
[0034] The technical content provided by the present application is intended to solve some technical problems of related technologies such as those mentioned above. In the relational database testing method, device, electronic device, medium and product of the present application, according to the test target of the database to be tested, a structured query framework statement is generated based on the grammatical rules of the structured query statement; the data metadata information of the database to be tested is obtained, and the data object relationship rules of the database to be tested are generated based on the data metadata; wherein the data object relationship rules represent the hierarchical relationship between data objects; according to the structured query framework statement and the data object relationship rules, a structured query test statement is combined and generated; the structured query test statement is sent to the database to be tested to perform the test and generate the test result. The scheme of the present application is based on combining the real data objects of the database with the structured framework statement, so that the generated structured test statement is more accurate, and the test result obtained by using the structured test statement to perform the test on the database is more accurate, and the database test result can more accurately reflect the characteristics of the database.
[0035] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0036] Embodiment 1
[0037] Figure 1 A flow chart of a relational data testing method is shown in FIG. Figure 1 As shown, the method includes:
[0038] Step 101: Generate a structured query framework statement based on the grammatical rules of the structured query statement according to the test target of the database to be tested;
[0039] Step 102: Obtain data meta information of the database to be tested, and generate data object relationship rules of the database to be tested based on the data meta information; the data object relationship rules represent the hierarchical relationship between data objects;
[0040] Step 103: generating a structured query test statement based on the structured query framework statement and the data object relationship rule;
[0041] Step 104: Send the structured query test statement to the database to be tested to execute the test and generate the test result.
[0042] The test object of this example is a relational database, and this example does not limit the specific type of the relational database. Figure 2 Schematic diagram of the process flow of the relational database testing method of this application; Figure 2 As shown, an SQL framework statement is generated according to the grammatical rules in a fixed structured query statement (SQL) grammar rule file; the data object relationship rules of the database are generated by querying metadata in the database to be tested to obtain relevant data information; an SQL test statement is generated according to the combination of the SQL framework statement and the data object relationship rules, and the SQL test statement is sent to the database to be tested to execute the test and return the test result.
[0043] Specifically, first, according to the test objectives of the database to be tested and the syntax rules of the structured query statements (SQL) supported by the database to be tested, the SQL framework statements are generated. In practical applications, the test objectives of database testing usually include database functional testing, performance testing, security testing, data integrity testing, data consistency testing, data recovery testing, compatibility testing, regression testing, etc.; the test objectives can be one or more.
[0044] The framework statement generated according to the grammatical rules of SQL includes two main parts, namely keyword tags and non-keyword tags; among them, the keyword part is usually generated according to the specific test objectives, and the generated keyword tags are still used as keyword parts in subsequent SQL test statements; for the non-keyword tag part of the SQL framework statement in this example, the tag under this position is retained and no specific data object is filled, that is, the tag of the data information required under the non-keyword is retained.
[0045] Furthermore, the data objects of the database to be tested are obtained by obtaining the data metadata information of the database to be tested. In one example, the data object information can be obtained through the SDK (Software Development Kit) interface provided by the database; wherein the SDK interface includes but is not limited to standard interfaces such as JDBC and ODBC. Taking the JDBC interface as an example, JDBC obtains the relevant information of specific data tables in the database through the MetaData (data metadata) interface, and can query the database for information such as which tables, which fields, and the attributes of the fields. In MetaData, a series of GETXXX (get) functions are used to extract data, and the data information is stored in ResultSet (result set, which is a collection of data information returned by the database query operation, an object representing the database query result), and then returned to the user. Specifically, a series of information such as data tables, primary keys of data tables, and foreign keys can be obtained.
[0046] In practical applications, the primary key of a data table is a field or combination of fields used to uniquely identify each row of records in the data table; a data table can only have one primary key, but the primary key can be composed of one or more fields; the primary key ensures that each row of records in the data table is unique, and duplicate primary key values are not allowed; the value of the primary key field cannot be empty; the database usually automatically creates an index for the primary key to improve query efficiency. The foreign key of a data table is a field or combination of fields in a data table used to establish a relationship with other tables; a data table can have multiple foreign keys, each of which points to the primary key or unique key of another table; through foreign keys, an association relationship between two tables can be established, such as a one-to-one, one-to-many, or many-to-many relationship; foreign keys ensure that the referenced data exists in another table, thereby maintaining data integrity; in some database systems, foreign keys can also be configured to automatically update or delete the data in the referenced table when the data in the referenced table is updated or deleted. The relationship between the primary key and the foreign key is mainly reflected in the reference relationship: the foreign key references the primary key of another table to establish an association between the two tables. In addition, the data information of the database can also be obtained by executing SQL query statements to query the corresponding system tables or system views; this application does not limit the method of obtaining database data information. At the same time, the data object relationship rules of the database to be tested are generated based on the data metadata information; the data object relationship rules are used to represent the hierarchical relationship between data objects; by obtaining the data metadata information of the database to be tested or the system table of the database, the existing database objects of the database to be tested and the relationship between each data object are obtained.
[0047] A relational database system usually includes information about relational database objects such as databases, data tables, data columns, data types, indexes, primary keys, foreign keys, constraints, stored procedures, functions, and triggers. At the same time, data-related statistical information is also saved in relevant meta-information files. The data information of the database is divided according to the hierarchical relationship to find the data level where the data object is located and the relationship between each data object; Figure 3 It is a schematic diagram of the relationship rules of sample data objects; for example Figure 3 As shown, a database can include multiple data schema modes (<schema)), and each schema mode includes specific data table names, data view names, trigger names, function names, etc.; it should be noted that Figure 3 This is only a way to display the hierarchical relationship of data object relationship rules, and this application does not limit the display form of data object relationship rules.
[0048] In practical applications, according to the non-keyword tag information required by the SQL framework statement obtained based on the test target, the corresponding tag information in the data object relationship rules of the database to be tested can be found and filled. The obtained SQL framework statement and data object rules are combined according to the test target to generate an SQL test statement for testing; the SQL test statement is sent to the database side to execute relevant tests; as an example, the SQL test statement is sent to the database to be tested through the SDK interface related to the database to execute the test and generate a test result. Subsequently, based on the test result and information such as the running state of the database during the execution of the SQL test statement, it is judged whether the database can correctly run the request of the relevant SQL statement.
[0049] In this example, an SQL test statement for testing the database is generated by combining the SQL framework statement and the data object relationship rules of the database to be tested, and the generated SQL test statement is sent to the database to be tested for execution to obtain a test result. The solution of this application generates an SQL test statement for testing by combining the actual data in the actual test scenario, making the generated SQL test statement more suitable for the test scenario and the test result more accurate. At the same time, after generating the SQL test statement, it can automatically execute sending the SQL statement to the database to be tested for automatic testing, which also improves the test efficiency.
[0050] Furthermore, it is necessary to generate a structured query framework statement according to the syntax rules of the structured query statement; correspondingly, as an example, Figure 4 An exemplary flowchart of a relational database testing method is shown; based on any example, step 101 specifically includes:
[0051] Step 201: Generate keywords and non-keywords in the structured query statement according to the grammatical rules of the structured query statement;
[0052] Step 202: According to the test target, the non-keywords are parsed step by step to obtain the main framework of the structured query statement;
[0053] Step 203: Based on the main framework of the structured query language, keywords in the structured query statement are combined to obtain a structured query framework statement.
[0054] Specifically, according to the syntax rules of SQL statements, the keywords and non-keyword parts in the SQL statements are generated; in practical applications, keywords usually include CREATE (create statement): used to create a database or database object; DROP (delete statement): used to delete a database or database object; ALTER (modify statement): used to modify the structure of a database object, such as the modification of a table structure; SELECT (select query statement): used to retrieve data from a database table; INSERT INTO (insert statement): used to insert new rows into a table, and some other statements for specific operations. The non-keyword part involves specific data objects that need to be filled into the SQL framework statement, including the labels of a series of data objects such as the aforementioned data table, data column index name, etc. According to the test objectives, the non-keyword part is parsed and expanded step by step to obtain a SQL framework body, and the framework body is traversed to generate the SQL framework body rule tree. In this example, according to the specific test objectives of the library to be tested, the recursive nesting depth when generating SQL statements can be controlled through the relevant configuration of the syntax rules of SQL statements. Specifically, the recursive nesting depth indicates the number of nesting levels of a recursive function during execution; a recursive function refers to a function that calls itself inside a function. In this way, recursion can simplify the structure of the program, making the code more concise and clear. In practical applications, controlling the recursive nesting depth according to the test objectives helps prevent stack overflow, improve performance, ensure the correctness of the algorithm, enhance the readability and maintainability of the code, and adapt to different computing environments. According to the main framework of the generated structured query language, according to the grammatical rules of the SQL statement, the keyword part is combined to generate a structured query framework statement. In this example, according to the grammatical rules of the structured query statement, the keywords are parsed, the non-keywords are expanded step by step, and the recursive nesting depth is controlled, which can ensure the comprehensiveness of the generated structured framework statement; by controlling the recursive nesting depth, work efficiency is improved; while ensuring the accuracy of the generated SQL test statement, the efficiency of SQL test statement generation is improved; and the test efficiency of database testing is further improved.
[0055] A structured query test statement for testing is generated based on the structured framework statement generated above and the data object relationship rules of the database to be tested. Based on any example, the non-keyword tags in the structured query framework statement are consistent with the data tags in the data object relationship rules; step 103 specifically includes:
[0056] If the structured query framework statement is a selection query statement, the first processing flow is executed; the first processing flow includes: determining the non-keyword tags that need to be filled in the selection query statement; according to the non-keyword tags that need to be filled in the selection query statement, selecting the data objects under the data tags consistent with the non-keyword tags in the data object relationship rules to fill in the non-keyword tag part.
[0057] Specifically, the non-keyword part of the structured query framework statement in this example is filled with specific data objects. Each node of the data relationship object rule of the database includes a corresponding data label, and the data label node contains specific data objects; the data label under the data relationship object rule is consistent with the non-keyword label of the structured query framework statement, so that the actual data objects that are subsequently filled are filled in accordance with the corresponding data labels. In one example, the SQL framework statement contains <tablename>The label needs to be replaced with the real data table name. In the data object relationship rule of the corresponding database to be tested, the data table label node will be marked <tablename>, the specific form is <tablename>testtable. On the premise that the non-keyword label of the structured query framework statement is consistent with the data object label under the data object relationship rule node, a structured query test statement is generated based on the structured query framework statement and the data object relationship rule; specifically: first determine whether the structured query framework statement is a select query (SELECT) statement, if the structured query framework statement is a SELECT statement, then execute the first processing flow; the first processing flow is: determine what the specific non-keyword label that needs to be filled in the SQL framework statement is, and then select the data object under the data label consistent with the non-keyword label in the corresponding data object relationship rule according to the non-keyword label in the SQL query framework statement to fill it into the non-keyword label in the SQL statement.
[0058] Further, according to the non-keyword tag to be filled in the selection query statement, the data object under the data tag consistent with the non-keyword tag in the data object relationship rule is selected and filled into the non-keyword tag part, including:
[0059] If the query statement contains multiple data table labels, the data table with foreign key relationship in the data object relationship rule will be selected for filling; if there is no foreign key relationship, the data table with column names of the same data type will be selected for filling;
[0060] If the selected query statement does not contain multiple data table tags, select any data architecture pattern node in the data object relationship rule, and select the data object under the architecture pattern node that is consistent with the non-keyword tag of the structured query framework statement to fill in the non-keyword tag; if the selected data architecture pattern node contains a data table tag, select the data object under the data table tag node to fill in the non-keyword tag.
[0061] When it is determined that the structured query framework statement is a SELECT statement, it is further determined whether the SELECT statement contains multiple data table tags. In other words, whether the non-keyword tag part of the structured query statement that needs to be replaced and filled includes multiple data tables that need to be replaced; when the SELECT statement contains multiple data table tags, the data table tag with a foreign key relationship in the data relationship object rule is preferentially selected, and the data table under the data table tag is selected for filling. If it does not contain a data table tag with a foreign key relationship, the data table containing the column name of the same data type is selected for filling. When the SELECT statement does not include multiple data table tags, that is, when it is detected that the non-keyword tag part in the SELECT statement does not need to be filled with multiple data table tags, a data architecture pattern in the data object relationship rule is randomly selected. <schemaname>The data objects under the node are filled into the non-keyword label. Specifically, the data objects consistent with the non-keyword label also need to be selected for filling; if the selected data architecture mode node contains a data table label node, the data objects under the data table label node are selected for filling.
[0062] Furthermore, the method for generating a structured query test statement according to the structured query framework statement and the data object relationship rules of the database also includes:
[0063] If the selection query statement includes a filter statement, and the clause of the filter statement includes a first actual value tag, then according to the database to be tested, a value corresponding to the number of first actual value tags is selected and filled into the corresponding first actual value tag;
[0064] If the clause of the non-filtering statement in the selection query statement contains the second actual value label, then according to the column name label type preceding the second actual value label, a random value corresponding to the number of second actual value labels is generated by a random function to fill the second actual value label.
[0065] Specifically, if the structured query statement is a select query statement, and the select query statement contains a WHERE (filter) statement, and the clause of the where statement includes the first actual value that needs to be filled with actual data <value>Tag; then according to the database to be tested, select the database that needs to be filled in the SELECT statement <value>The same number of data values are filled into the <value>Under the label; if the non-WHERE clause in the SELECT statement also includes the second actual value that needs to be filled, then the second actual value is prefixed <colname>The data type of the column name is randomly generated. <colname>(column name) data type uniform random values are filled under the label of this second actual value.
[0066] Further, based on the above example, according to the database to be tested, the value corresponding to the number of first actual value tags is selected, including:
[0067] Generate a query statement based on the data table label and filter statement of the selection query statement;
[0068] Send the query statement to the database to be tested, execute the data query, and obtain the query results;
[0069] Randomly select a value in the query result that corresponds to the first actual value label quantity.
[0070] Specifically, a query statement is generated based on the data table label and filter statement of the select query statement.
[0071]
[0072]
[0073]
[0074] <value>part, generated by random functions, specifically <value> The value type is the same as the preceding< / value> < / value>
[0075]
[0076]
[0077]
[0078]
[0079] The label and the clause of the filter (WHERE) statement (column name) information, generate an SQL statement, which is only used as a query statement for querying the first actual value, send this query statement to the database to be tested to execute data query, and obtain query results. This query result includes specific data values that need to be filled; randomly select data values corresponding to the number of first actual values in the returned query results for filling. In the above example, when the structured query framework statement is a selection query statement, the non-keyword tags to be filled are selected according to the selection rules to select the corresponding data objects in the data object rules for non-keyword tag filling. The non-keyword tags of the structured query framework statement are filled according to the actual data, and the obtained structured query test statement is more consistent with the database to be tested. When the test is executed, the test results are more accurate. The database to be tested is subsequently corrected according to the accurate test results to ensure the stability of the database. On the basis of any of the above examples, a structured query test statement is generated in combination according to a structured query framework statement and a data object relationship rule, which specifically includes: if the structured query framework statement is a create statement, the first processing flow is executed for the clauses of the select query statement in the create statement, and the second processing flow is executed for other statements in the create statement; the second processing flow includes: randomly generating data objects according to the data object relationship rule, and filling the obtained data objects into the non-keyword label part of the structured query framework statement. Specifically, if the structured query framework statement is a create (CREAT) statement, the first processing flow is executed for the SELECT statement part in the create statement, and the second processing flow is executed for other statements in the create statement; specifically, the second processing flow includes: randomly generating data objects according to the data object relationship rule, and filling the obtained data objects into the non-keyword label part of the structured query statement. In one example, if the structured query statement is a CREAT statement, and the CREAT statement does not include a SELECT part, then according to the data object rule, a data object is randomly generated and filled into the non-keyword label part of the SQL framework statement; for The type is consistent. According to the specific data system, the corresponding random function is selected to generate a specific data value. This application does not limit the type of random function. In this example, when the structured framework statement is a create statement, the SQL test statement corresponding to the create statement is generated according to the corresponding create statement combination rule, which improves the accuracy of generating SQL test statements and improves the accuracy of database test results. On the basis of the foregoing example, in an example, a structured query test statement is generated in combination according to a structured query framework statement and a data object relationship rule, and specifically also includes: if the structured query framework statement is neither a select query statement nor a create statement, a third processing flow is executed; the third processing flow includes selecting a data object under any data architecture pattern node in the data object relationship rule to fill in the non-keyword label part. Specifically, if the SQL framework statement generated according to the grammatical rule of the structured query statement is neither a SELECT statement nor a CREAT statement, the third processing flow is executed according to the corresponding combination rule; the third processing flow is to select any one of the data object relationship rules of the database<schema name> The data objects under the node are filled into the non-keyword tag part of the SQL framework statement. Specifically, the filled data tags are consistent with the non-keyword tags of the SQL framework statement. In this example, when the SQL framework statement is neither a SELECT statement nor a CREAT statement, the combination of SQL test statements is generated according to the corresponding rules. When generating, the data objects with consistent data tags in the database to be tested are selected to fill the non-keyword tags of the SQL framework statement, so that the generated SQL test statement is more accurate, and when the database is tested, the test results obtained are more comprehensive and accurate. On the basis of the above example, in one example, the selection query statement includes non-keyword tags at different levels; the method also includes: for non-keyword tags at the same level, the data objects to be filled into the non-keyword tags are selected from the data objects under the corresponding data level nodes in the data object relationship rules. Specifically, for the selection query statement, the non-keyword tags are divided into different levels, and the data tags in the corresponding data object relationship rules are also divided according to the corresponding hierarchical relationships; for non-keyword tags at the same level, the required data objects are selected from the data objects under the data level nodes finally corresponding to the data object relationship rules and filled into the non-keyword tags. In one example, for the index name, constraint name, primary key name, foreign key name and other table-related object names involved in the selection query statement, select the data object relationship rules corresponding to the non-keyword tags. The data objects under the node are filled in; for object names such as function names, stored procedure names, trigger names, synonyms, aliases, etc., select the data object relationship rules corresponding to the non-keyword labels.
[0080] Figure 5 Figure 5
[0081]
[0082]
[0083]
[0084]
[0085]
[0086]
[0087] Figure 5 Figure 5
[0088]
[0089]
[0090]
[0091]
[0092]
[0093]
[0094]
[0095]
[0096]
[0097]
[0098]
[0099]
[0100]
[0101]
[0102]
[0103] <tablename>The label needs to be replaced with the real data table name. In the data object relationship rule of the corresponding database to be tested, the data table label node will be marked <tablename>, the specific form is <tablename>testtable. On the premise that the non-keyword label of the structured query framework statement is consistent with the data object label under the data object relationship rule node, a structured query test statement is generated based on the structured query framework statement and the data object relationship rule; specifically: first determine whether the structured query framework statement is a select query (SELECT) statement, if the structured query framework statement is a SELECT statement, then execute the first processing flow; the first processing flow is: determine what the specific non-keyword label that needs to be filled in the SQL framework statement is, and then select the data object under the data label consistent with the non-keyword label in the corresponding data object relationship rule according to the non-keyword label in the SQL query framework statement to fill it into the non-keyword label in the SQL statement.
[0104] Further, according to the non-keyword tag to be filled in the selection query statement, the data object under the data tag consistent with the non-keyword tag in the data object relationship rule is selected and filled into the non-keyword tag part, including:
[0105] If the query statement contains multiple data table labels, the data table with foreign key relationship in the data object relationship rule will be selected for filling; if there is no foreign key relationship, the data table with column names of the same data type will be selected for filling;
[0106] If the selected query statement does not contain multiple data table tags, select any data architecture pattern node in the data object relationship rule, and select the data object under the architecture pattern node that is consistent with the non-keyword tag of the structured query framework statement to fill in the non-keyword tag; if the selected data architecture pattern node contains a data table tag, select the data object under the data table tag node to fill in the non-keyword tag.
[0107] When it is determined that the structured query framework statement is a SELECT statement, it is further determined whether the SELECT statement contains multiple data table tags. In other words, whether the non-keyword tag part of the structured query statement that needs to be replaced and filled includes multiple data tables that need to be replaced; when the SELECT statement contains multiple data table tags, the data table tag with a foreign key relationship in the data relationship object rule is preferentially selected, and the data table under the data table tag is selected for filling. If it does not contain a data table tag with a foreign key relationship, the data table containing the column name of the same data type is selected for filling. When the SELECT statement does not include multiple data table tags, that is, when it is detected that the non-keyword tag part in the SELECT statement does not need to be filled with multiple data table tags, a data architecture pattern in the data object relationship rule is randomly selected. <schemaname>The data objects under the node are filled into the non-keyword label. Specifically, the data objects consistent with the non-keyword label also need to be selected for filling; if the selected data architecture mode node contains a data table label node, the data objects under the data table label node are selected for filling.
[0108] Further, the combination module 22 is also specifically used for: if the selection query statement includes a filter statement, and the clause of the filter statement includes a first actual value label, then according to the database to be tested, selecting a value corresponding to the number of first actual value labels, and filling the corresponding first actual value label;
[0109] If the clause of the non-filtering statement in the selection query statement contains the second actual value label, then according to the column name label type preceding the second actual value label, a random value corresponding to the number of second actual value labels is generated by a random function to fill the second actual value label.
[0110] Specifically, if the structured query statement is a select query statement, and the select query statement contains a WHERE (filter) statement, and the clause of the where statement includes the first actual value that needs to be filled with actual data <value>Tag; then according to the database to be tested, select the database that needs to be filled in the SELECT statement <value>The same number of data values are filled into the <value>Under the label; if the non-WHERE clause in the SELECT statement also includes the second actual value that needs to be filled, then the second actual value is prefixed <colname>The data type of the column name is randomly generated. <colname>(column name) data type uniform random values are filled under the label of this second actual value.
[0111] Further, based on the above example, according to the database to be tested, the value corresponding to the number of first actual value tags is selected, including:
[0112] Generate a query statement based on the data table label and filter statement of the selection query statement;
[0113] Send the query statement to the database to be tested, execute the data query, and obtain the query results;
[0114] Randomly select a value in the query result that corresponds to the first actual value label quantity.
[0115] Specifically, a query statement is generated based on the data table label and filter statement of the select query statement.< / colname> < / colname> < / value> < / value> < / value> < / schemaname> < / tablename> < / tablename> < / tablename> The node is located<schema name> The data objects under the node are filled. In this example, the data objects under the corresponding level in the data relationship rules are selected according to different levels and filled into the non-keyword tags in the corresponding framework statements, so that the generated test statements are more accurate and the test results obtained by executing the test are more accurate. Correspondingly, the replacement and filling are performed according to the hierarchical relationship, so that the efficiency of generating test statements is higher, and the test efficiency of the database is further improved. In combination with the above examples, a schematic diagram of the structured query test statement generation rule for the application is provided; a flowchart showing the complete combination rule of the SQL test statement applied for, according to the SQL framework statement and the data object relationship rule, first determine whether the SQL framework statement is SELECT, if it is a SELECT statement, then execute the processing flow related to the SELECT statement; if it is determined that it is not a SELECT statement but a CREAT statement, then further execute the relevant processing flow of the CREAT statement; if it is neither a SELECT statement nor a CREAT statement, then further execute the relevant processing flow. Based on any of the above examples, in one example, the method also includes: saving the structured query test statement to a specified file. Specifically, according to the SQL test statement generated by the above example, the relevant database test is executed, and the test results obtained can be used to evaluate the status of the database, and the SQL test statement can also be saved to a specified file for other purposes. Specifically, for example, it can be used as a performance benchmark test of the database to be tested: the retained SQL statements can be used for performance benchmark tests to evaluate the performance of the database under different loads. By comparing the performance of different versions of databases or different configurations, the performance of the database can be optimized. In this example, in addition to being used as a test statement for the database, the SQL test statement can also be retained in a specified file for other purposes, further ensuring the accuracy of the test results and improving the test efficiency. Further, in an example, the method also includes: correcting the grammatical rules of the structured query statement according to the test results of this time. Specifically, according to the current test results, the grammatical rules for generating SQL statements can be corrected; for example, the test scope for the test library can be expanded or narrowed; the next test is performed according to the grammatical rules after the corrected test scope, so that the test results are more accurate; at the same time, the database can also be corrected for errors according to the test results. Based on the above results, the database is continuously corrected until the test results do not return a test error prompt, and a complete and comprehensive database is obtained.In the relational database testing method provided in this embodiment, a structured query framework statement is generated based on the grammatical rules of the structured query statement according to the test target of the database to be tested; data metadata information of the database to be tested is obtained, and data object relationship rules of the database to be tested are generated based on the data metadata; the data object relationship rules represent the hierarchical relationship between data objects; according to the structured query framework statement and the data object relationship rules, a structured query test statement is generated by combination; the structured query test statement is sent to the database to be tested to perform the test and generate the test result. The scheme of the present application is based on combining the real data objects of the database with the structured framework statement, so that the generated structured test statement is more accurate, and the test result obtained by using the structured test statement to perform the test on the database is more accurate, and the database test result can more accurately reflect the characteristics of the database. In the second embodiment, a schematic diagram of the structure of a relational database testing device is exemplified; as shown, the device includes: a generation module 21: used to generate a structured query framework statement based on the grammatical rules of the structured query statement according to the test target of the database to be tested; the generation module 21: is also used to obtain the data metadata information of the database to be tested, and generate the data object relationship rules of the database to be tested based on the data metadata; the data object relationship rules represent the hierarchical relationship between data objects; a combination module 22: based on the structured query framework statement and the data object relationship rules, a structured query test statement is generated by combination; a test module 23: is used to send the structured query test statement to the database to be tested to perform the test and generate the test result. The test object of this example is a relational database, and this example does not limit the specific type of the relational database. Specifically, first, according to the test target of the database to be tested and the grammatical rules of the structured query statement (SQL) supported by the database to be tested, a SQL framework statement is specifically generated. In practical applications, the test objectives of database testing usually include database functional testing, performance testing, security testing, data integrity testing, data consistency testing, data recovery testing, compatibility testing, regression testing, etc.; the test objectives can be one or more. The framework statement generated according to the grammatical rules of SQL includes two main parts, namely keyword tags and non-keyword tags; among them, the keyword part is usually generated according to the specific test objectives, and the generated keyword tags are still used as keyword parts in subsequent SQL test statements; for the non-keyword tag part of the SQL framework statement in this example, the tag under this position is retained and no specific data object is filled, that is, the tag of the data information required under the non-keyword is retained.Furthermore, the data objects of the database to be tested are obtained by obtaining the data metadata information of the database to be tested; in one example, the data object information can be obtained through the SDK (Software Development Kit) interface provided by the database; wherein the SDK interface includes but is not limited to standard interfaces such as JDBC and ODBC. Taking the JDBC interface as an example, JDBC obtains the relevant information of specific data tables in the database through the MetaData (data metadata) interface, and can query the information such as which tables are in the database, which fields are in the table, and the attributes of the fields. In MetaData, a series of GETXXX (get) functions are used to extract data, and the data information is stored in ResultSet (result set, which is a collection of data information returned by the database query operation, and an object representing the database query result), and then returned to the user. Specifically, a series of information such as data tables, primary keys of data tables, and foreign keys can be obtained. In practical applications, the primary key of a data table is a field or combination of fields used to uniquely identify each row of records in the data table; a data table can only have one primary key, but the primary key can be composed of one or more fields; the primary key ensures that each row of records in the data table is unique, and duplicate primary key values are not allowed; the value of the primary key field cannot be empty; the database usually automatically creates an index for the primary key to improve query efficiency. The foreign key of a data table is a field or combination of fields in a data table used to establish a relationship with other tables; a data table can have multiple foreign keys, each of which points to the primary key or unique key of another table; through foreign keys, an association relationship between two tables can be established, such as a one-to-one, one-to-many, or many-to-many relationship; foreign keys ensure that the referenced data exists in another table, thereby maintaining data integrity; in some database systems, foreign keys can also be configured to automatically update or delete the data in the referenced table when the data in the referenced table is updated or deleted. The relationship between the primary key and the foreign key is mainly reflected in the reference relationship: the foreign key references the primary key of another table to establish an association between the two tables. In addition, the data information of the database can also be obtained by executing SQL query statements to query the corresponding system tables or system views; this application does not limit the method of obtaining database data information. At the same time, the data object relationship rules of the database to be tested are generated based on the data metadata information; the data object relationship rules are used to represent the hierarchical relationship between data objects; by obtaining the data metadata information of the database to be tested or the system tables of the database, the existing database objects of the database to be tested and the relationship between each data object are obtained. A relational database system usually includes relational database object information such as databases, data tables, data columns, data types, indexes, primary keys, foreign keys, constraints, stored procedures, functions, triggers, etc., and data-related statistical information is also saved in related metadata files.The data information of the database is divided according to the hierarchical relationship, and the data hierarchy where the data object is located and the relationship between each data object are found; in actual application, the corresponding label information in the data object relationship rule of the database to be tested can be found according to the non-keyword label information required by the SQL framework statement obtained based on the test target, and filled. The obtained SQL framework statement and the data object rule are combined according to the test target to generate an SQL test statement for testing; the SQL test statement is sent to the database end to perform relevant tests; as an example, the SQL test statement is sent to the database to be tested through the database-related SDK interface to perform the test and generate the test result. Subsequently, according to the test results and the operating status of the database in the process of executing the SQL test statement, it is judged whether the database can correctly run the request of the relevant SQL statement. This example generates an SQL test statement for testing the database according to the SQL framework statement and the data object relationship rule composition of the generated database to be tested, and sends the generated SQL test statement to the database end to be tested to perform the test and obtain the test result. The scheme of the present application generates an SQL test statement for testing by combining the actual data in the actual test scenario, so that the generated SQL test statement is more suitable for the test scenario and the test result is more accurate. At the same time, after the SQL test statement is generated, the SQL statement can be automatically executed and sent to the database end to be tested to perform automatic testing, which also improves the test efficiency. Further, it is necessary to generate a structured query framework statement according to the grammatical rules of the structured query statement. Correspondingly, as an example, the generation module 21 is specifically used to: generate keywords and non-keywords in the structured query statement according to the grammatical rules of the structured query statement; parse the non-keywords step by step according to the test target to obtain the main frame of the structured query statement; based on the main frame of the structured query language, combine the keywords in the structured query statement to obtain the structured query framework statement. Specifically, according to the grammatical rules of the SQL statement, the keywords and non-keyword parts in the SQL statement are generated; in actual applications, keywords usually include CREATE (create statement): used to create a database or database object; DROP (delete statement): used to delete a database or database object; ALTER (modify statement): used to modify the structure of a database object, such as the modification of a table structure; SELECT (select query statement): used to retrieve data from a database table; INSERT INTO (insert statement): used to insert new rows into a table, and some other statements for specific operations. The non-keyword part involves specific data objects that need to be filled into the SQL framework statement, including the aforementioned data table, data column index name and other data object labels. According to the test objectives, the non-keyword part is parsed and expanded step by step to obtain a SQL framework body, which is traversed to generate the SQL framework body rule tree.In this example, the recursive nesting depth when generating SQL statements can be controlled according to the test objectives of the specific library to be tested through the relevant configuration of the grammatical rules of SQL statements. Specifically, the recursive nesting depth indicates the number of nesting levels of a recursive function during execution; a recursive function refers to a function that calls itself inside a function. In this way, recursion can simplify the structure of the program and make the code more concise and clear. In practical applications, controlling the recursive nesting depth according to the test objectives helps prevent stack overflow, improve performance, ensure the correctness of the algorithm, enhance the readability and maintainability of the code, and adapt to different computing environments. According to the main framework of the generated structured query language, according to the grammatical rules of the SQL statement, the keyword part is combined to generate a structured query framework statement. In this example, according to the grammatical rules of the structured query statement, the keywords are parsed, the non-keywords are expanded step by step, and the recursive nesting depth is controlled, which can ensure the comprehensiveness of the generated structured framework statement; by controlling the recursive nesting depth, the work efficiency is improved; while ensuring the accuracy of the generated SQL test statement, the efficiency of the SQL test statement generation is improved; and the test efficiency of the database test is further improved. A structured query test statement for testing is generated according to the structured framework statement generated above and the data object relationship rules of the database to be tested. The non-keyword tags in the structured query framework statement are consistent with the data tags of the data object relationship rules; accordingly, as an example, the combination module 22 is specifically used for: if the structured query framework statement is a selection query statement, the first processing flow is executed; the first processing flow includes: determining the non-keyword tags that need to be filled in the selection query statement; according to the non-keyword tags that need to be filled in the selection query statement, the data objects under the data tags that are consistent with the non-keyword tags in the data object relationship rules are selected and filled into the non-keyword tag part. Specifically, the non-keyword part of the structured query framework statement in this example is filled with specific data objects, and each node of the data relationship object rule of the database includes a corresponding data tag, and the data tag node contains a specific data object; the data tag under the data relationship object rule is consistent with the non-keyword tag of the structured query framework statement, so that the subsequent filling of the actual data objects is consistent with the corresponding data tags. In one example, the SQL framework statement contains.
[0116]
[0117]
[0118] <value>part, generated by random functions, specifically <value> The value type is the same as the preceding< / value> < / value>
[0119]
[0120]
[0121]
[0122] The label and the clause of the filter (WHERE) statement (column name) information, generate an SQL statement, which is only used as a query statement for querying the first actual value, send this query statement to the database to be tested to execute data query, and obtain query results. This query result includes specific data values that need to be filled; randomly select data values corresponding to the number of first actual values in the returned query results for filling. In the above example, when the structured query framework statement is a selection query statement, the non-keyword tags to be filled are selected according to the selection rules to select the corresponding data objects in the data object rules for non-keyword tag filling. The non-keyword tags of the structured query framework statement are filled according to the actual data, and the obtained structured query test statement is more consistent with the database to be tested. When the test is executed, the test results are more accurate. The database to be tested is subsequently corrected according to the accurate test results to ensure the stability of the database. On the basis of any of the foregoing examples, the combination module 22 is also specifically used for: if the structured query framework statement is a create statement, then the first processing flow is executed for the clauses of the select query statement in the create statement, and the second processing flow is executed for other statements in the create statement; the second processing flow includes: randomly generating data objects according to data object relationship rules, and filling the obtained data objects into the non-keyword label part of the structured query framework statement. Specifically, if the structured query framework statement is a create (CREAT) statement, then the foregoing first processing flow is executed for the SELECT statement part in the create statement, and the second processing flow is executed for other statements in the create statement; specifically, the second processing flow includes: randomly generating data objects according to data object relationship rules, and filling the obtained data objects into the non-keyword label part of the structured query statement. In one example, if the structured query statement is a CREAT statement, and the CREAT statement does not include a SELECT part, then according to the data object rules, a data object is randomly generated and filled into the non-keyword label part of the SQL framework statement; for The type is consistent. According to the specific data system, the corresponding random function is selected to generate a specific data value. The present application does not limit the type of random function. In this example, when the structured framework statement is a create statement, the SQL test statement corresponding to the create statement is generated according to the corresponding create statement combination rule, which improves the accuracy of generating SQL test statements and improves the accuracy of database test results. On the basis of the foregoing example, in one example, the combination module 22 is also specifically used for: if the structured query framework statement is neither a select query statement nor a create statement, a third processing flow is executed; the third processing flow includes selecting a data object under any data architecture pattern node in the data object relationship rule to fill in the non-keyword label part. Specifically, if the SQL framework statement generated according to the grammatical rules of the structured query statement is neither a SELECT statement nor a CREAT statement, the third processing flow is executed according to the corresponding combination rule; the third processing flow is to select any one of the data object relationship rules of the database<schema name> The data objects under the node are filled into the non-keyword label part of the SQL framework statement. Specifically, the filled data label is consistent with the non-keyword label of the SQL framework statement. In this example, when the SQL framework statement is neither a SELECT statement nor a CREAT statement, the combination of SQL test statements is generated according to the corresponding rules. When generating, the data objects with consistent data labels in the database to be tested are selected to fill the non-keyword labels of the SQL framework statement, so that the generated SQL test statement is more accurate, and when the database is tested, the test results obtained are more comprehensive and accurate. On the basis of the above example, in one example, the query statement is selected to include non-keyword labels at different levels; for non-keyword labels at the same level, the data objects to be filled into the non-keyword labels are selected from the data objects under the corresponding data level nodes in the data object relationship rules. Specifically, for the selection query statement, the non-keyword labels are divided into different levels, and the data labels in the corresponding data object relationship rules are also divided according to the corresponding hierarchical relationships; for non-keyword labels at the same level, the required data objects are selected from the data objects under the data level nodes that the data object relationship rules finally correspond to and are filled into the non-keyword labels. In one example, for the index name, constraint name, primary key name, foreign key name and other table-related object names involved in the selection query statement, select the data object relationship rules corresponding to the non-keyword tags. The data objects under the node are filled in; for object names such as function names, stored procedure names, trigger names, synonyms, aliases, etc., select the data object relationship rules corresponding to the non-keyword labels.
[0123]
[0124]
[0125]
[0126]
[0127]
[0128]
[0129] Figure 6
[0130]
[0131]
[0132]
[0133]
[0134]
[0135]
[0136]
[0137]
[0138]
[0139]
[0140]
[0141]
[0142]
[0143]
[0144]
[0145] The node is located<schema name> The data objects under the node are filled. In this example, the data objects under the corresponding level in the data relationship rules are selected according to different levels and filled into the non-keyword tags in the corresponding framework statements, so that the generated test statements are more accurate and the test results obtained by executing the test are more accurate. Correspondingly, the replacement and filling are performed according to the hierarchical relationship, so that the efficiency of generating test statements is higher, and the test efficiency of the database is further improved. On the basis of any of the above examples, in one example, the present application also includes a saving module 24, and the saving module 24 is used to: save the structured query test statement to a specified file. Specifically, according to the SQL test statement generated by the above example, the relevant database test is executed, and the test results obtained can be used to evaluate the status of the database, and the SQL test statement can also be saved to a specified file for other purposes. Specifically, for example, it can be used as a performance benchmark test of the database to be tested: the retained SQL statement can be used for performance benchmark testing to evaluate the performance of the database under different loads. By comparing the performance of different versions of databases or different configurations, the performance of the database can be optimized. In this example, in addition to being used as a test statement for the database, the SQL test statement can also be retained in a specified file for other purposes, further ensuring the accuracy of the test results and improving the test efficiency. On the basis of any of the above examples, in one example, the present application further includes a correction module 25, which is used to: correct the grammatical rules of the structured query statement according to the test results of this time. Specifically, according to the current test results, the grammatical rules for generating SQL statements can be corrected; for example, the test scope of the test library can be expanded or reduced; the next test is performed according to the grammatical rules after the corrected test scope, so that the test results are more accurate; at the same time, the database can also be corrected according to the test results. Based on the above results, the database is continuously corrected until the test results do not return a test error prompt, and a complete and comprehensive database is obtained. The relational database testing device provided in this embodiment generates a structured query framework statement based on the grammatical rules of the structured query statement according to the test target of the database to be tested; obtains the data meta information of the database to be tested, and generates the data object relationship rules of the database to be tested based on the data meta information; the data object relationship rules represent the hierarchical relationship between data objects; according to the structured query framework statement and the data object relationship rules, a structured query test statement is generated in combination; the structured query test statement is sent to the database to be tested to perform the test and generate the test result. The solution of the present application is based on a combination of real data objects of a database and structured framework statements, so that the generated structured test statements are more accurate. By using the structured test statements to test the database, the test results obtained are more accurate, and the test results can more accurately reflect the characteristics of the database.In the third embodiment, a schematic diagram of the structure of an electronic device is exemplified, and the device includes: a processor (processor) 291, and the device also includes a memory (memory) 292; it can also include a communication interface (Communication Interface) 293 and a bus 294. Among them, the processor 291, the memory 292, the communication interface 293, can communicate with each other through the bus 294. The communication interface 293 can be used for information transmission. The processor 291 can call the logic instructions in the memory 292 to execute the method of the above example. In addition, the logic instructions in the above-mentioned memory 292 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when it is sold or used as an independent product. The memory 292, as a computer-readable storage medium, can be used to store software programs, computer executable programs, such as program instructions / modules corresponding to the method in the embodiment of the present application. The processor 291 executes functional applications and data processing by running the software programs, instructions and modules stored in the memory 292, that is, implementing the method in the above method example. The memory 292 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the terminal device, etc. In addition, the memory 292 may include a high-speed random access memory, and may also include a non-volatile memory. The embodiment of the present application also provides a computer-readable storage medium, in which a computer-executable instruction is stored, and the computer-executable instruction is used to implement the method in any embodiment when executed by a processor. The embodiment of the present application also provides a computer program product, including a computer program, which is used to implement the method in any embodiment when executed by a processor. It should be noted that for the aforementioned method embodiments, for the sake of simple description, they are all expressed as a series of action combinations, but those skilled in the art should know that the present application is not limited to the described action sequence, because according to the present application, some steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present application. It should be further noted that although the steps in the flowchart are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order limitation for the execution of these steps, and these steps may be executed in other orders.Moreover, at least a part of the steps in the flowchart may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed in the same time period, but can be executed in different time periods, and the execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps. It should be understood that the above-mentioned device embodiments are only schematic, and the device of the present application can also be implemented in other ways. For example, the division of units / modules in the above-mentioned embodiments is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units, modules or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, unless otherwise specified, each functional unit / module in each embodiment of the present application can be integrated into one unit / module, or each unit / module can exist physically separately, or two or more units / modules can be integrated together. The above-mentioned integrated unit / module can be implemented in the form of hardware or in the form of a software program module. If the integrated unit / module is implemented in the form of hardware, the hardware can be a digital circuit, an analog circuit, etc. The physical implementation of the hardware structure includes but is not limited to transistors, memristors, etc. If not specifically stated, the processor may be any appropriate hardware processor, such as CPU, GPU, FPGA, DSP, and ASIC, etc. If not specifically stated, the storage unit may be any appropriate magnetic storage medium or magneto-optical storage medium, such as Resistive Random Access Memory (RRAM), Dynamic Random Access Memory (DRAM), Static Random Access Memory (SRAM), Enhanced Dynamic Random Access Memory (EDRAM), High-Bandwidth Memory (HBM), Hybrid Memory Cube (HMC), etc. If the integrated unit / module is implemented in the form of a software program module and sold or used as an independent product, it may be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a memory and includes a number of instructions for enabling a computer device (which may be a personal computer, server or network device, etc.) to execute all or part of the steps of the methods of each embodiment of the present application.The aforementioned memory includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program code. In the above embodiments, the description of each embodiment has its own emphasis. For the part that is not described in detail in a certain embodiment, refer to the relevant description of other embodiments. The technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, all possible combinations of the technical features in the above embodiments are not described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification. After considering the specification and practicing the invention disclosed here, those skilled in the art will easily think of other implementation schemes of the present application. This application is intended to cover any variation, use or adaptive change of the present application, which follows the general principles of the present application and includes common knowledge or conventional technical means in the technical field that are not disclosed in the present application. The description and embodiments are only regarded as exemplary. It should be understood that the present application is not limited to the precise structure described above and shown in the drawings, and various modifications and changes can be made without departing from its scope. Finally, it should be noted that those skilled in the art will readily conceive of other embodiments of the present invention after considering the specification and practicing the invention disclosed herein. The present invention is intended to cover any variation, use or adaptation of the present invention, which follows the general principles of the present invention and includes common knowledge or conventional techniques in the art not disclosed by the present invention, is not limited to the precise structure described above and shown in the drawings, and may be modified and changed in various ways without departing from the scope thereof. < / colname> < / colname> < / value> < / value> < / value> < / schemaname> < / tablename> < / tablename> < / tablename>
Claims
1. A relational database testing method, characterized in that: The method comprises: According to the test objectives of the database to be tested, a structured query framework statement is generated based on the grammatical rules of the structured query statement; Acquire data meta information of the database to be tested, and generate data object relationship rules of the database to be tested based on the data meta information; the data object relationship rules represent the hierarchical relationship between data objects; Combining and generating a structured query test statement according to the structured query framework statement and the data object relationship rule; The structured query test statement is sent to the database to be tested to execute the test and generate a test result.
2. The method according to claim 1, characterized in that The step of generating a structured query framework statement according to the test target of the database to be tested includes: Generating keywords and non-keywords in the structured query statement according to the grammatical rules of the structured query statement; According to the test target, the non-keywords are parsed step by step to obtain the main framework of the structured query statement; Based on the main framework of the structured query language, the keywords in the structured query statement are combined to obtain the structured query framework statement.
3. The method according to claim 1, characterized in that The non-keyword tag in the structured query framework statement is consistent with the data tag of the data object relationship rule; and the structured query framework statement and the data object relationship rule are combined to generate a structured query test statement, specifically comprising: If the structured query framework statement is a selection query statement, a first processing flow is executed; the first processing flow includes: determining the non-keyword tags that need to be filled in the selection query statement; according to the non-keyword tags that need to be filled in the selection query statement, selecting the data objects under the data tags consistent with the non-keyword tags in the data object relationship rules to fill in the non-keyword tag part.
4. The method according to claim 3, characterized in that The step of selecting a data object under a data tag consistent with the non-keyword tag in a data object relationship rule and filling the data object into the non-keyword tag part according to the non-keyword tag to be filled in the selection query statement includes: If the select query statement contains multiple data table tags, the data table with a foreign key relationship in the data object relationship rule is preferentially selected for filling; if there is no foreign key relationship, the data table containing the column name of the same data type is selected for filling; If the selection query statement does not contain multiple data table tags, then any data architecture pattern node in the data object relationship rule is selected, and the data object under the architecture pattern node that is consistent with the non-keyword tag of the structured query framework statement is selected and filled into the non-keyword tag; if the selected data architecture pattern node contains a data table tag, then the data object under the data table tag node is selected and filled into the non-keyword tag.
5. The method according to claim 4, characterized in that The method further comprises: If the selection query statement includes a filter statement, and the clause of the filter statement includes a first actual value tag, then according to the database to be tested, a value corresponding to the number of first actual value tags is selected and filled into the corresponding first actual value tag; If the clause of the non-filtering statement in the selection query statement contains a second actual value label, then according to the column name label type preceding the second actual value label, a random value corresponding to the number of second actual value labels is generated by a random function to fill the second actual value label.
6. The method according to claim 5, characterized in that The step of selecting a value corresponding to the first actual value tag quantity according to the database to be tested includes: Generate a query statement according to the data table label of the selection query statement and the screening statement; Send the query statement to the database to be tested, execute data query, and obtain query results; A value corresponding to the first actual value label quantity is randomly selected in the query result.
7. The method according to claim 3, characterized in that The step of generating a structured query test statement based on the structured query framework statement and the data object relationship rule may further include: If the structured query framework statement is a creation statement, the first processing flow is executed for the clauses of the selection query statement in the creation statement, and the second processing flow is executed for other statements in the creation statement; the second processing flow includes: randomly generating data objects according to the data object relationship rules, and filling the obtained data objects into the non-keyword tag part in the structured query framework statement.
8. The method according to claim 3, characterized in that The step of generating a structured query test statement based on the structured query framework statement and the data object relationship rule may further include: If the structured query framework statement is neither a select query statement nor a create statement, a third processing flow is executed; the third processing flow includes selecting a data object under any data architecture pattern node in the data object relationship rule and filling it into the non-keyword tag part.
9. The method according to claim 3, characterized in that: The selection query statement includes non-keyword tags at different levels, and the method further includes: For non-keyword tags at the same level, data objects to be filled into the non-keyword tags are selected from data objects under corresponding data level nodes in the data object relationship rule.
10. The method according to claim 1, characterized in that The method further comprises: Save the structured query test statement to a specified file.
11. The method according to any one of claims 1 to 10, characterized in that: The method further comprises: According to the test results, the grammatical rules of the structured query statement are revised.
12. A relational database testing device, characterized in that: The device comprises: A generation module, used to generate a structured query framework statement based on the grammatical rules of the structured query statement according to the test target of the database to be tested; The generating module is further used to obtain data meta information of the database to be tested, and generate data object relationship rules of the database to be tested based on the data meta information; the data object relationship rules represent the hierarchical relationship between data objects; A combination module, used for combining and generating a structured query test statement according to the structured query framework statement and the data object relationship rule; The test module is used to send the structured query test statement to the database to be tested to perform the test and generate the test result.
13. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 11.
14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 11 when executed by a processor.
15. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 11 when being executed by a processor.