Search

CN-122019399-A - Database test scene playback method, device, equipment, storage medium and program product

CN122019399ACN 122019399 ACN122019399 ACN 122019399ACN-122019399-A

Abstract

The application provides a database test scene playback method, a device, equipment, a storage medium and a program product, and relates to the technical field of database test. The method comprises the steps of obtaining a target database log in the database, replacing a binding variable in the SQL statement with a corresponding parameter value in the database log under the condition that a Structured Query Language (SQL) statement bound with the binding variable exists in the target database log to obtain a target SQL statement with complete semantics, sorting the target SQL statement to obtain an executable SQL file, and playing back a test environment according to the SQL file. The method is used for achieving the effects of improving playback efficiency and testing result reliability.

Inventors

  • LI DANDAN
  • RUAN QINGSONG

Assignees

  • 中电科金仓(北京)科技股份有限公司

Dates

Publication Date
20260512
Application Date
20251229

Claims (11)

  1. 1. A database test scene playback method, the method comprising: obtaining a target database log in the database; under the condition that a Structured Query Language (SQL) statement with binding variables is bound in the target database log, replacing the binding variables in the SQL statement with corresponding parameter values in the database log to obtain a target SQL statement with complete semantics; Sorting the target SQL sentences to obtain executable SQL files; And playing back the testing environment according to the SQL file.
  2. 2. The method according to claim 1, wherein, in the case that there is a structured query language SQL statement bound with a variable statement in the target database log, replacing a bound variable in the SQL statement with a corresponding parameter value in the database log to obtain a target SQL statement with complete semantics, including: Analyzing SQL sentences in the target database log to identify a binding variable identifier; extracting a parameter value corresponding to the binding variable identifier from the target database log; and replacing the binding variable identifier with the parameter value to obtain the target SQL statement containing the actual parameter value.
  3. 3. The method of claim 1, wherein the obtaining a target database log in the database comprises: Acquiring full-journal data in the database based on a test request, wherein the test request comprises a database mode, a database name and/or a user name, and the database mode refers to a logic structure of an object; screening the full-log data according to the test request to obtain a target database log; the parsing the SQL statement in the target database log includes: filtering the target database according to preset keywords to obtain the SQL sentence; And analyzing the SQL statement.
  4. 4. The method of claim 3, wherein prior to parsing the SQL statement, further comprising: Identifying a block statement in the SQL statement, and adding a block statement mark; And adding a sentence separator after the corresponding SQL sentence is identified by the block sentence, wherein the sentence separator is a symbol for separating independent SQL sentences.
  5. 5. The method according to any one of claims 1-4, wherein the sorting the target SQL statement to obtain an executable SQL file comprises: and performing de-duplication, filling and marking, special symbol replacement and/or transcoding on the target SQL sentence to obtain the executable SQL file.
  6. 6. The method of any of claims 1-4, wherein after the obtaining the target database log in the database, further comprising: Executing a logical backup restoring operation to generate a logical backup restoring file; the playback of the test environment according to the SQL file comprises the following steps: Performing database restoration operation on the test system by using the logical backup restoration file; And operating the SQL file on the test system to obtain an execution result.
  7. 7. The method of any of claims 1-4, wherein the replacing binding variables in the SQL statement with corresponding parameter values in the database log comprises: And replacing the binding variable of the SQL statement with an actual parameter value by combining with a key field parameters in the target database log.
  8. 8. A database test scene playback apparatus comprising: The acquisition module is used for acquiring a target database log in the database; the replacing module is used for replacing the binding variable in the SQL statement with the corresponding parameter value in the database log under the condition that the Structured Query Language (SQL) statement with the binding variable is bound in the target database log, so as to obtain a target SQL statement with complete semantics; The sorting module is used for sorting the target SQL sentences to obtain executable SQL files; And the playback module is used for playing back the test environment according to the SQL file.
  9. 9. An electronic device comprising a processor and a memory communicatively coupled to the processor; The memory stores computer-executable instructions; the processor executes computer-executable instructions stored in the memory to implement the method of any one of claims 1 to 7.
  10. 10. A computer readable storage medium having stored therein computer executable instructions which when executed by a processor are adapted to carry out the method of any one of claims 1 to 7.
  11. 11. A computer program product comprising a computer program which, when executed by a processor, implements the method of any one of claims 1 to 7.

Description

Database test scene playback method, device, equipment, storage medium and program product Technical Field The present application relates to the field of database testing technologies, and in particular, to a method, an apparatus, a device, a storage medium, and a program product for playing back a database testing scene. Background In the development and operation process of a database system, the system functions and performances need to be tested, and a database log file is used as a core data source for recording the operation behaviors of the database. Based on the playback of the database log file in the test environment, the actual function and performance of the system can be detected. Thus, database test scene playback is critical. At present, the existing database test scene playback method is mainly based on playback of a database log capturing load. The method requires a tester to reproduce the traffic load (such as SQL statement, transaction operation, etc.) in the production environment in the test environment through a playback tool. However, the existing database test scene playback method relies on manual intervention, so that the playback efficiency of the existing database test scene playback method is low and the test result is poor. Disclosure of Invention The application provides a database test scene playback method, a device, equipment, a storage medium and a program product, which are used for achieving the effects of improving playback efficiency and test result reliability. In a first aspect, the present application provides a method for playing back a database test scene, including: obtaining a target database log in the database; under the condition that a Structured Query Language (SQL) statement with binding variables is bound in the target database log, replacing the binding variables in the SQL statement with corresponding parameter values in the database log to obtain a target SQL statement with complete semantics; Sorting the target SQL sentences to obtain executable SQL files; And playing back the testing environment according to the SQL file. In a possible implementation manner, in the case that there is a structured query language SQL statement bound with a variable statement in the target database log, replacing a bound variable in the SQL statement with a corresponding parameter value in the database log to obtain a target SQL statement with complete semantics, including: Analyzing SQL sentences in the target database log to identify a binding variable identifier; extracting a parameter value corresponding to the binding variable identifier from the target database log; and replacing the binding variable identifier with the parameter value to obtain the target SQL statement containing the actual parameter value. In a possible implementation manner, the obtaining the target database log in the database includes: Acquiring full-journal data in the database based on a test request, wherein the test request comprises a database mode, a database name and/or a user name, and the database mode refers to a logic structure of an object; screening the full-log data according to the test request to obtain a target database log; the parsing the SQL statement in the target database log includes: filtering the target database according to preset keywords to obtain the SQL sentence; And analyzing the SQL statement. In a possible implementation manner, before the parsing the SQL statement, the method further includes: Identifying a block statement in the SQL statement, and adding a block statement mark; And adding a sentence separator after the corresponding SQL sentence is identified by the block sentence, wherein the sentence separator is a symbol for separating independent SQL sentences. In a possible implementation manner, the sorting the target SQL statement to obtain an executable SQL file includes: and performing de-duplication, filling and marking, special symbol replacement and/or transcoding on the target SQL sentence to obtain the executable SQL file. In one possible implementation manner, after the obtaining the target database log in the database, the method further includes: Executing a logical backup restoring operation to generate a logical backup restoring file; the playback of the test environment according to the SQL file comprises the following steps: Performing database restoration operation on the test system by using the logical backup restoration file; And operating the SQL file on the test system to obtain an execution result. In one possible implementation manner, the replacing the binding variable in the SQL statement with the corresponding parameter value in the database log includes: And replacing the binding variable of the SQL statement with an actual parameter value by combining with a key field parameters in the target database log. In a second aspect, the present application provides a database test scene playback apparatus, including: The acquisiti