Execution method and device of database test script, equipment and storage medium
Through Java programs, SQL statements and meta commands in database test scripts are identified and routed, and automatic execution is used by JDBC interface, which solves the problem that test scripts cannot be automatically executed in the existing technology and improves the efficiency of database function testing.
Patent Information
- Application Number
- CN202411311943.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-19
- Publication Date
- 2024-12-03
AI Technical Summary
Existing database functional test scripts cannot be automatically executed, especially for scenarios where database interactions through the JDBC protocol, resulting in inefficient testing.
The route of SQL statements and metacommands is determined through Java programs, and the automatic execution of test scripts is achieved using the JDBC interface, including identifying the SQL statement type and metacommand, calling the corresponding JDBC interface to execute, and outputting the execution results to the result file.
It realizes that the database test script is automatically executed without modifying the test script, which improves the efficiency and automation of database functional testing.
Smart Images

Figure CN119066114A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of database function testing, and in particular to a method, device, equipment and storage medium for executing a database test script. Background Art
[0002] Database functional testing is a key step to ensure that the database system can correctly and effectively perform the expected functions of the database in actual applications.
[0003] The test scripts for database functional testing are usually written in Structured Query Language (SQL), and the SQL test scripts are executed using the SQL command line execution tool that comes with the database, the SQL editor of the image management tool, etc. The SQL command line execution tool cannot cover the scenario of interacting with the database through JDBC (Java Database Connectivity); the SQL editor cannot understand the meta-commands in the script, resulting in the inability to automatically execute the test script, requiring manual rewriting of the test script, and low test script execution efficiency.
[0004] Therefore, for databases that use JDBC as the SQL statement execution interface, there is an urgent need to provide a solution for automatically executing test scripts to improve the efficiency of database testing. Summary of the invention
[0005] The present application provides a method, apparatus, device and storage medium for executing a database test script, which implements an automated script execution strategy for determining the routing of SQL statements and meta-commands by a Java program and executing commands by JDBC, thereby improving the efficiency of database testing.
[0006] In a first aspect, the present application provides a method for executing a database test script, comprising:
[0007] For a database test script executed by a command line tool or a graphical management tool provided by the database, a first Java program is used to determine the type of SQL statement in the database test script, and a JDBC interface corresponding to the type is called to execute the SQL statement, and after obtaining the execution result, the execution result is output to a result file;
[0008] Using a second Java program to identify meta-commands in the database test script based on regular expression matching;
[0009] The Java program corresponding to the identified meta-command is used to call the JDBC interface to execute the meta-command, and after obtaining the execution result, the execution result is output to the result file.
[0010] Optionally, using a Java program corresponding to the identified meta-command to call a JDBC interface to execute the meta-command includes:
[0011] If the identified meta-command is a database switching meta-command, the database switching Java program is used to call the JDBC connection interface of the current database and the JDBC connection interface of the target database, and the database switching meta-command is executed to switch the current database to the target database.
[0012] Optionally, the Java program using the identified meta-command to call a JDBC interface to execute the meta-command further includes:
[0013] If the identified meta-command is a table structure query meta-command, a table structure query Java program is used to call a JDBC metadata library interface to execute the table structure query meta-command to obtain table structure metadata corresponding to the meta-command.
[0014] Optionally, using a first Java program to determine the type of SQL statement in the database test script includes:
[0015] Using the first Java program, reading the keywords of the SQL statements in the database test script;
[0016] Based on the keyword, the type of the SQL statement is determined.
[0017] Optionally, the method further includes:
[0018] If there is a PLSQL code block in the database test script, the PLSQL code block is parsed based on a PLSQL parser to obtain an executable PLSQL statement block;
[0019] The third Java program is used to call the interface of the stored procedure corresponding to JDBC to execute the executable PLSQL statement block.
[0020] Optionally, the method further includes:
[0021] Using a fourth Java program to read the result file and the expected file line by line, and comparing the read lines;
[0022] If the content of the same line of the read result file is different from that of the expected file, the comparison result will be output to the test report.
[0023] In a second aspect, the present application provides a database test script execution device, comprising:
[0024] A statement classification execution module is used to use a first Java program to determine the type of SQL statement in a database test script executed by a command line tool or a graphical management tool provided by the database, call a JDBC interface corresponding to the type to execute the SQL statement, and output the execution result to a result file after obtaining the execution result;
[0025] A meta-command identification module, used to use a second Java program to identify meta-commands in the database test script based on regular expression matching;
[0026] The meta-command execution module is used to use the Java program corresponding to the identified meta-command to call the JDBC interface to execute the meta-command, and output the execution result to the result file after obtaining the execution result.
[0027] In a third aspect, the present application provides an electronic device, comprising: a processor, and a memory communicatively connected to the processor;
[0028] The memory stores computer-executable instructions;
[0029] The processor executes the computer-executable instructions stored in the memory to implement the method provided in the first aspect of the present application.
[0030] 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 method provided in the first aspect of the present application.
[0031] In a fifth aspect, the present application provides a computer program product, including a computer program, which implements the method provided in the first aspect of the present application when executed by a processor.
[0032] The execution method, device, equipment and storage medium of the database test script provided by the present application are for SQL test scripts that were originally executed by the command line tool or graphical management tool that comes with the database. In order to adapt to the database of the JDBC protocol, the automatic execution of the test script is realized by using a Java program to identify the type of SQL statement and meta-command in the script, call the JDBC interface corresponding to the type of SQL statement, realize the automatic execution of SQL statement, and call the corresponding JDBC interface through the Java program corresponding to the meta-command to realize the automatic execution of the meta-command, and output the execution result to the result file at the same time, so as to feedback the test result of the database. It is realized that there is no need to modify the SQL test script, and the routing of SQL statements and meta-commands in the script is determined by the Java program, and their automatic execution is realized, which improves the efficiency of test script execution and thus improves the efficiency of database function testing. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] 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.
[0034] Figure 1 A schematic diagram of an application scenario provided in an embodiment of the present application;
[0035] Figure 2 A flowchart of a method for executing a database test script provided in an embodiment of the present application;
[0036] Figure 3 A flowchart of another method for executing a database test script provided in an embodiment of the present application;
[0037] Figure 4 A flowchart of another method for executing a database test script provided in an embodiment of the present application;
[0038] Figure 5 A schematic diagram of the structure of a database test script execution device provided in an embodiment of the present application;
[0039] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.
[0040] 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
[0041] 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.
[0042] First, some of the terms involved in this application are explained:
[0043] JDBC: is a set of APIs (Application Programming Interface) in Java language, used to connect and operate databases. JDBC provides a standard method for Java programs to interact with databases.
[0044] Meta-command: A command that is different from the standard SQL syntax and is provided by a specific database management system or command line tool. It is used to manage database sessions, display database information, or perform other auxiliary functions. It usually starts with a special prefix, such as a backslash "\" or a dot "`".
[0045] PLSQL code block: PLSQL (Procedural Language Structured Query Language) is a programming language that combines SQL and Oracle. PLSQL code block is the basic structure in PLSQL language, which is used to write and execute specific tasks or operations. PLSQL code block consists of three parts: declaration part, executable command part and exception handling part. The declaration part usually starts with the "declare" keyword, followed by a list of variable and cursor definitions. The executable command part starts with "begin".
[0046] In order to ensure the security and effectiveness of database operation, it is necessary to perform functional testing on the database, including but not limited to basic CRUD operation testing, data integrity testing, stored procedure testing and trigger testing. Basic CRUD operations include basic database operations such as create (Create), read (Read), update (Update) and delete (Delete).
[0047] In Java development, object-oriented programming is a mainstream development method. However, when it comes to interacting with relational databases, there is a mismatch between object-oriented programming and database operations. In order to solve this problem, the concept of Object-Relational Mapping (ORM) came into being. The ORM framework realizes the association between Java objects and database operations, simplifies database operations, and improves the efficiency and maintainability of database function development.
[0048] The ORM framework usually needs to access the database through the JDBC interface to implement corresponding database functions.
[0049] Figure 1 A schematic diagram of an application scenario provided in an embodiment of the present application, such as Figure 1 As shown, during database functional testing, the database test script can be executed by using the SHELL command or Python language to call the SQL command line tool that comes with the database. This test method is suitable for scenarios that interact with the database through specific protocols, such as the TCP (Transmission Control Protocol) protocol, but cannot cover scenarios that interact with the database through the JDBC protocol.
[0050] If you want to access the database by calling the JDBC interface through the mainstream ORM framework, the programmer needs to manually rewrite the test script to implement database functional testing, which leads to low efficiency of database functional testing.
[0051] In some embodiments, database test scripts can be executed through a database graphical management tool. Although this testing method can partially cover the scenarios of interacting with the database through the JDBC protocol, there is a problem of being unable to parse the meta-commands in the script, resulting in the script being unable to execute automatically. Programmers are still required to rewrite the test script, which is time-consuming and labor-intensive.
[0052] In order to solve the above problems, the present application provides a method for executing a database test script, which is based on a Java program including a first Java program and a second Java program, determines the type of SQL statement in the script and identifies the meta-commands in the script, and has a Java program to determine the routing of SQL statements and meta-commands. The script is automatically executed by calling the JDBC interface, and there is no need to manually rewrite the database test script, thereby improving the automation and efficiency of script execution, and thereby improving the efficiency of data function library testing.
[0053] 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.
[0054] Figure 2 A flowchart of a method for executing a database test script provided in an embodiment of the present application is provided. The method for executing the database test script can be executed by an electronic device having corresponding data processing capabilities, such as a front-end device connected to a database, such as Figure 2 As shown, the execution method of the database test script includes the following steps:
[0055] Step S201, for a database test script executed by a command line tool or a graphical management tool provided by the database, use a first Java program to determine the type of SQL statement in the database test script, call a JDBC interface corresponding to the type to execute the SQL statement, and output the execution result to a result file after obtaining the execution result.
[0056] The database test script is a script written in SQL language, which may include one or more SQL statements, meta-commands, and PLSQL code blocks.
[0057] After obtaining the database test script, you can use the database's own command line tool or graphical management tool to execute the test script. During the execution process, use the first Java program to determine the routing of the SQL statement in the test script, that is, determine the JDBC interface corresponding to the SQL statement, and call the corresponding JDBC interface to automatically execute the SQL statement.
[0058] Specifically, the first Java program can be used to extract the value of the SQL preset field, determine the type of the SQL statement based on the value of the preset field, and then call the JDBC interface matching the type to execute the SQL statement, thereby achieving automatic execution of the SQL statement.
[0059] The types of SQL statements may include query type and execution type. The execution type may be further divided into deletion type, addition type, update type, etc. according to different execution actions. Query type SQL statements may include SELECT statement, READ statement, etc., deletion type SQL statements may include DELETE statement, DROP statement, TRUNCATE statement, etc., addition type SQL statements may include INSERT statement, CREATE statement, etc., and update type SQL statements may include UPDATE statement.
[0060] Step S202: using a second Java program to identify meta-commands in the database test script based on regular expression matching.
[0061] The meta-commands in the database test script are different from the aforementioned SQL statements. They are used for daily management and maintenance of the database, such as database switching meta-commands and table structure query meta-commands.
[0062] For meta-commands in the database test script, the JDBC driver cannot directly process them. Then, a second Java program can be used to identify the meta-commands in the database test script by matching regular expressions.
[0063] Exemplarily, all statements in the database test script that begin with a backslash and are not enclosed in quotation marks may be regarded as a meta-command, and the meta-command may be identified by a corresponding regular expression.
[0064] Step S203: Use the Java program corresponding to the identified meta-command to call the JDBC interface to execute the meta-command, and output the execution result to the result file after obtaining the execution result.
[0065] Corresponding meta-commands, after identifying the meta-command, the type of meta-command can be further determined based on the meta-command keywords, and the function of the meta-command can be implemented through a Java program that matches the type of the meta-command. For example, a database switching meta-command, after identifying the database switching meta-command, uses the corresponding Java program to change the connected database, including closing the current database connection and establishing a new database connection. The creation and closing of database connections can be implemented through the JDBC connection interface.
[0066] For the SQL statements and meta-commands in the database test script, after obtaining the execution results of the SQL statements or meta-commands, the execution results are output to the result file, so that the results of the database function test can be consulted through the result file.
[0067] The execution method of the database test script provided in this embodiment is aimed at the SQL test script that was originally executed by the command line tool or graphical management tool provided by the database. In order to adapt to the database of the JDBC protocol, the automatic execution of the test script is realized by using a Java program to identify the type of SQL statement and meta-command in the script, call the JDBC interface corresponding to the type of SQL statement, realize the automatic execution of the SQL statement, and call the corresponding JDBC interface through the Java program corresponding to the meta-command to realize the automatic execution of the meta-command, and output the execution result to the result file at the same time, so as to feedback the test result of the database. It is realized that the routing of the SQL statement and meta-command in the script is determined by the Java program without modifying the SQL test script, and its automatic execution is realized, which improves the efficiency of the test script execution, and further improves the efficiency of the database function test.
[0068] Figure 3 A flowchart of another method for executing a database test script provided in an embodiment of the present application is provided in this embodiment. Figure 2 Based on the embodiment shown, step S201 and step S203 are further refined as follows: Figure 3 As shown, for a database test script executed by using a command line tool or a graphical management tool provided by the database, the execution method of the database test script provided in this embodiment may specifically include the following steps:
[0069] Step S301: Use the first Java program to read the keywords of the SQL statements in the database test script.
[0070] In some embodiments, keywords in the SQL statement may be read by performing fuzzy matching of LIKE keywords and wildcards.
[0071] In other embodiments, keywords in SQL statements may be read by regular expression matching.
[0072] Step S302: Determine the type of the SQL statement based on the keyword.
[0073] The keywords of the SQL language can be classified in advance to obtain the types corresponding to the keywords. During the database function test, the types corresponding to the keywords of the read SQL statements are determined to be the types of the SQL statements, such as query type, execution type, etc.
[0074] Step S303, calling the JDBC interface corresponding to the type to execute the SQL statement, and outputting the execution result to a result file after obtaining the execution result.
[0075] Step S304: using a second Java program to identify meta-commands in the database test script based on regular expression matching.
[0076] Step S305, if the identified meta-command is a database switching meta-command, the database switching Java program is used to call the JDBC connection interface of the current database and the JDBC connection interface of the target database, execute the database switching meta-command, switch the current database to the target database, and output the execution result to the result file.
[0077] The database switching meta-command is a meta-command used to switch databases, specifically switching the current database to a target database.
[0078] Exemplarily, the structure of the database switching meta-command may be: \c+name of the target database.
[0079] For the identified database switching meta-command, the database switching function can be implemented through the database switching Java program. Specifically, the database switching Java program reads the current database and the target database in the database switching meta-command, calls the close() method in the JDBC connection interface of the current database to close the connection with the current database, and then calls the JDBC connection interface of the target database to connect to the target database, implement database switching, that is, implement the execution of the database switching meta-command, and output the switching result, such as whether the switching is successful, that is, the execution result of the database switching meta-command, to the result file.
[0080] Step S306, if the identified meta-command is a table structure query meta-command, use the table structure query Java program to call the JDBC metadata library interface, execute the table structure query meta-command to obtain the table structure metadata corresponding to the meta-command, and output the execution result to a result file.
[0081] The query table structure meta-command is a meta-command for viewing the data table in the database, for example: \d statement, \dt+ statement, etc.
[0082] For the query table structure meta-command, the table structure query Java program can be used to call the JDBC meta-database interface to realize the automatic execution of the query table structure meta-command, and output the execution result to the result file.
[0083] JDBC's metadata library interface, namely DatabaseMetaData interface, is used to obtain metadata in the database, including table structure, column data types, stored procedure parameters, etc. Therefore, for meta commands for querying column data types and stored procedure parameters, the corresponding Java program can also be used to call JDBC's metadata library interface to implement the execution of such meta commands.
[0084] This embodiment uses the database switching meta-command and the query table structure meta-command as examples for explanation. Other meta-commands can also be executed in a similar manner, that is, by calling the JDBC interface required to execute the meta-command through a pre-written Java program to implement the parsing and execution of this type of meta-command.
[0085] In some embodiments, step S305 and step S306 may be performed in parallel, or step S306 may be performed first and then step S307, which is not limited in the present application.
[0086] Step S307: Use the fourth Java program to read the result file and the expected file line by line, and compare the read lines.
[0087] The expected results corresponding to each test in the database test script are recorded in the expected file.
[0088] In some embodiments, after the database test script is executed, a fourth Java program is used to read the result file and the expected file line by line to obtain each line in the result file and the expected file, and compare the same line in the result file and the expected file to determine whether the two lines are consistent.
[0089] In other embodiments, after a new line is added to the result file, a fourth Java program is used to read the new line in the result file and the corresponding line in the expected file, i.e., the line with the same line number, and compare whether the contents of the two read lines are consistent.
[0090] Step S308: If the content of the same line of the read result file is different from that of the expected file, the comparison result is output to the test report.
[0091] If the comparison result shows that the content of the same line of the result file and the expected file is the same, continue to read the next line; if the comparison result shows that the content of the same line of the result file and the expected file is different, the corresponding line number and the comparison result are output to the test report.
[0092] In some embodiments, when the comparison result is that the content of the same line of the result file and the expected file is different, only the line number of the compared line can be output to the test report.
[0093] In this embodiment, SQL statements are classified through keywords, the classification logic is simple and the accuracy is high, different types of SQL statements are routed to different JDBC interfaces by Java programs for execution, and JDBC path coverage of SQL statements is achieved; at the same time, two execution strategies for meta-commands, data switching and table structure query, are provided, which solves the problem that such meta-commands cannot be directly executed through graphical interface tools; automatic comparison of execution results is achieved through Java programs, which is efficient, low-cost and highly accurate compared to manual verification.
[0094] Furthermore, the database test script may also include a PLSQL code block (Block); the SQL editor and command line execution tool in the database graphical management tool are usually unable to directly execute the PLSQL code block. In order to realize the automatic execution of the PLSQL code block, the execution method of the aforementioned database test script may also include the following steps:
[0095] If there is a PLSQL code block in the database test script, the PLSQL code block is parsed based on the PLSQL parser to obtain an executable PLSQL statement block; a third Java program is used to call the interface of the stored procedure corresponding to JDBC to execute the executable PLSQL statement block.
[0096] Specifically, the third Java program can be used to identify the PLSQL code block according to the start mark of the PLSQL code block, such as BEGIN. Then, for the identified PLSQL code block, the PLSQL parser is used to parse out the PLSQL statement block to be executed in the PLSQL code block starting from the start mark, and the interface corresponding to the JDBC for executing the database stored procedure is called to execute the parsed executable PLSQL statement block, thereby realizing the automatic execution of the PLSQL code block.
[0097] Figure 4 A flowchart of another method for executing a database test script provided in an embodiment of the present application is shown in FIG. Figure 4 As shown, the execution method of the database test script mainly includes the following steps:
[0098] Get the database test script;
[0099] Parsing database test scripts: SQL statements in database test scripts, such as DML statements and DDL statements, can be parsed by query parser and execution parser respectively. Meta-commands and PLSQL code blocks in database test scripts can be parsed by meta-command parser and PLSQL parser respectively. Through parsing, the routes of SQL statements corresponding to SQL statements, meta-commands and PLSQL code blocks can be obtained, that is, the JDBC interface required for execution;
[0100] Call the corresponding interface in the JDBC driver to realize the automatic execution of the database test script;
[0101] The corresponding interface of the JDBC driver interacts with the database through P (Parse), B (Bind), E (Execute), D (Describe), and S (Sync) messages in turn, so as to send SQL commands to the database for execution through the JDBC driver;
[0102] Generate a test report based on the execution results.
[0103] The query parser and the execution parser are parsers generated based on the first Java program, and the meta-command parser is a parser generated based on the second Java program.
[0104] Corresponding to the execution method of the database test script provided in the aforementioned embodiment, the embodiment of the present application also provides a corresponding device. Figure 5 A schematic diagram of a structure of a database test script execution device provided in an embodiment of the present application, such as Figure 5 As shown, the execution device of the database test script includes: a statement classification execution module 510, a meta-command identification module 520 and a meta-command execution module 530.
[0105] Among them, the statement classification execution module 510 is used to use the first Java program to determine the type of SQL statement in the database test script executed by the command line tool or graphical management tool provided by the database, call the JDBC interface corresponding to the type to execute the SQL statement, and output the execution result to the result file after obtaining the execution result; the meta-command identification module 520 is used to use the second Java program to identify the meta-commands in the database test script based on regular expression matching; the meta-command execution module 530 is used to use the Java program corresponding to the identified meta-command to call the JDBC interface to execute the meta-command, and output the execution result to the result file after obtaining the execution result.
[0106] Optionally, the meta-command execution module 530 is specifically used to:
[0107] If the identified meta-command is a database switching meta-command, the database switching Java program is used to call the JDBC connection interface of the current database and the JDBC connection interface of the target database, and the database switching meta-command is executed to switch the current database to the target database.
[0108] Optionally, the meta-command execution module 530 is further configured to:
[0109] If the identified meta-command is a table structure query meta-command, a table structure query Java program is used to call a JDBC metadata library interface to execute the table structure query meta-command to obtain table structure metadata corresponding to the meta-command.
[0110] Optionally, the statement classification execution module 510 is specifically used to:
[0111] The first Java program is used to read keywords of SQL statements in a database test script; and based on the keywords, the type of the SQL statement is determined.
[0112] Optionally, the execution device of the database test script also includes a PLSQL parsing module, which is used to:
[0113] If there is a PLSQL code block in the database test script, the PLSQL code block is parsed based on the PLSQL parser to obtain an executable PLSQL statement block; a third Java program is used to call the interface of the stored procedure corresponding to JDBC to execute the executable PLSQL statement block.
[0114] Optionally, the execution device of the database test script further includes a result automatic comparison module, which is used to:
[0115] The fourth Java program is used to read the result file and the expected file line by line, and the read lines are compared; if the contents of the same line of the read result file and the expected file are different, the comparison result is output to the test report.
[0116] The database test script execution device provided in the embodiment of the present application can be used to execute the technical solution of the database test script execution method provided in any of the above embodiments of the present application. Its implementation principle and technical effect are similar, and this embodiment will not be repeated here.
[0117] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 6As shown, the electronic device of this embodiment may include: at least one processor 601; and a memory 602 communicatively connected to the at least one processor; wherein the memory 602 stores instructions executable by the at least one processor 601, and the instructions are executed by the at least one processor 601 so that the electronic device executes the method described in any of the above embodiments.
[0118] Optionally, the memory 602 may be independent or integrated with the processor 601 .
[0119] When the memory 602 is independently provided, the device further includes a bus for connecting the memory 602 and the processor 601 .
[0120] The implementation principle and technical effects of the electronic device provided in this embodiment can be found in the aforementioned embodiments and will not be described in detail here.
[0121] An embodiment of the present application further provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, the method provided in any of the aforementioned embodiments can be implemented.
[0122] An embodiment of the present application also provides a computer program product, including a computer program, which implements the method provided in any of the above embodiments when executed by a processor.
[0123] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation, such as multiple modules can be combined or integrated into another system, or some features can be ignored or not executed.
[0124] The above-mentioned integrated module implemented in the form of a software function module can be stored in a computer-readable storage medium. The above-mentioned software function module is stored in a storage medium, including a number of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to perform some steps of the method described in each embodiment of the present application.
[0125] It should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the application may be directly implemented as being executed by a hardware processor, or may be implemented by a combination of hardware and software modules in the processor.
[0126] The memory may include a high-speed memory, and may also include a non-volatile memory, such as at least one disk memory, and may also be a USB flash drive, a mobile hard disk, a read-only memory, a magnetic disk, or an optical disk.
[0127] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.
[0128] The storage medium may be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory, electrically erasable programmable read-only memory, erasable programmable read-only memory, programmable read-only memory, read-only memory, magnetic memory, flash memory, magnetic disk or optical disk. The storage medium may be any available medium that can be accessed by a general or special purpose computer.
[0129] An exemplary storage medium is coupled to the processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be an integral part of the processor. The processor and the storage medium can be located in a dedicated integrated circuit. Of course, the processor and the storage medium can also exist as discrete components in the electronic device or the control device of the vehicle sentry mode.
[0130] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0131] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0132] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods provided in each embodiment of the present application.
[0133] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0134] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A method for executing a database test script, characterized in that: include: For a database test script executed by a command line tool or a graphical management tool provided by the database, a first Java program is used to determine the type of SQL statement in the database test script, and a JDBC interface corresponding to the type is called to execute the SQL statement, and after obtaining the execution result, the execution result is output to a result file; Using a second Java program to identify meta-commands in the database test script based on regular expression matching; The Java program corresponding to the identified meta-command is used to call the JDBC interface to execute the meta-command, and after obtaining the execution result, the execution result is output to the result file.
2. The method according to claim 1, characterized in that: Using a Java program corresponding to the identified meta-command to call a JDBC interface to execute the meta-command includes: If the identified meta-command is a database switching meta-command, the database switching Java program is used to call the JDBC connection interface of the current database and the JDBC connection interface of the target database, and the database switching meta-command is executed to switch the current database to the target database.
3. The method according to claim 2, characterized in that The Java program using the identified meta-command calls the JDBC interface to execute the meta-command, further comprising: If the identified meta-command is a table structure query meta-command, a table structure query Java program is used to call a JDBC metadata library interface to execute the table structure query meta-command to obtain table structure metadata corresponding to the meta-command.
4. The method according to claim 1, characterized in that: Using a first Java program, determining the type of an SQL statement in the database test script includes: Using the first Java program, reading the keywords of the SQL statements in the database test script; Based on the keyword, the type of the SQL statement is determined.
5. The method according to claim 1, characterized in that The method further comprises: If there is a PLSQL code block in the database test script, the PLSQL code block is parsed based on a PLSQL parser to obtain an executable PLSQL statement block; The third Java program is used to call the interface of the stored procedure corresponding to JDBC to execute the executable PLSQL statement block.
6. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: Using a fourth Java program to read the result file and the expected file line by line, and comparing the read lines; If the content of the same line of the read result file is different from that of the expected file, the comparison result will be output to the test report.
7. A database test script execution device, characterized in that: include: A statement classification execution module is used to use a first Java program to determine the type of SQL statement in a database test script executed by a command line tool or a graphical management tool provided by the database, call a JDBC interface corresponding to the type to execute the SQL statement, and output the execution result to a result file after obtaining the execution result; A meta-command identification module, used to use a second Java program to identify meta-commands in the database test script based on regular expression matching; The meta-command execution module is used to use the Java program corresponding to the identified meta-command to call the JDBC interface to execute the meta-command, and output the execution result to the result file after obtaining the execution result.
8. 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 6.
9. 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 6 when executed by a processor.
10. A computer program product, characterized in that The method comprises a computer program, wherein when the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
JDBC driving method and device for hardware database
CN110990425A
Database testing method and device, terminal equipment and storage medium
CN111309596A
Heterogeneous library communication method, terminal equipment and storage medium
CN112818051A
Interface testing method and device
CN113407449A
Method for accessing memory database based on SQL (Structured Query Language)
CN117648329A
