Database statement detection method, device, processor and electronic device

CN119883858BActive Publication Date: 2026-09-18INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411941591.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-26
Publication Date
2026-09-18
Estimated Expiration
2044-12-26

AI Technical Summary

Technical Problem

但是,这样的检测方式往往需要支持业务功能测试

Benefits of technology

[0016] According to another aspect of the present invention, a computer program product is also provided, including a non-volatile computer-readable storage medium for storing a computer program, which, when executed by a processor, implements the database statement detection method of the present invention.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119883858B_ABST
    Figure CN119883858B_ABST
Patent Text Reader

Abstract

The application discloses a database statement detection method and device, a processor and electronic equipment, and relates to the field of big data. The method comprises the following steps: determining at least one initial query statement in an initial query statement set of a target database, wherein the initial query statement is used for representing a query statement to be subjected to statement detection; generating a check statement of the initial query statement; performing statement detection on the initial query statement by using the check statement to obtain a first initial detection result, and inputting the initial query statement into a target statement detection model to perform statement detection, thereby obtaining a second initial detection result; and determining a target detection result of the initial query statement based on the first initial detection result and the second initial detection result, wherein the target detection result is used for representing whether the initial query statement needs to be corrected. The application solves the technical problem of a large demand for patches.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of big data, and more specifically, to a method, apparatus, processor, and electronic device for detecting database statements. Background Technology

[0002] In the process of testing database queries, the actual installation of the package is often used to determine whether a patch is needed. However, this method often requires support for business function testing. Moreover, if the testing environment fails to intercept patched packages and they flow into production, it can lead to data contamination in the production environment, resulting in a large number of patch requirements.

[0003] There is currently no effective solution to the technical problem of the high demand for the aforementioned patches. Summary of the Invention

[0004] This invention provides a method, apparatus, processor, and electronic device for detecting database statements, in order to at least address the technical problem of a large demand for patches.

[0005] According to one aspect of the present invention, a method for detecting database statements is provided. The method includes: determining at least one initial query statement in an initial query statement set of a target database, wherein the initial query statement represents a query statement to be detected; generating a check statement for the initial query statement; performing statement detection on the initial query statement using the check statement to obtain a first initial detection result, and inputting the initial query statement into a target statement detection model for statement detection to obtain a second initial detection result, wherein the first initial detection result represents the relationship between the initial query statement and normal and abnormal query statements, the target statement detection model is obtained by training the initial statement detection model based on a sample query statement set, the sample query statement set including at least one sample query statement, the sample query statement representing a sample query statement to be detected, and the second initial detection result representing the probability that the initial query statement needs to be corrected; and determining a target detection result for the initial query statement based on the first and second initial detection results, wherein the target detection result represents whether the initial query statement needs to be corrected.

[0006] Optionally, generating a check statement for the initial query statement includes: determining the attribute information of the operation corresponding to the initial query statement, wherein the attribute information includes at least the structure and fields of the data table on which the operation is applied, and the target database includes data tables; and generating a check statement for the initial query statement based on the attribute information.

[0007] Optionally, determining the attribute information of the operation corresponding to the initial query statement includes: performing semantic analysis on the initial query statement to obtain the attribute information.

[0008] Optionally, based on the attribute information, a check statement is generated for the initial query statement, including: extracting the structure and fields from the attribute information; and generating a check statement that satisfies the structure and fields.

[0009] Optionally, based on the first initial detection result and the second initial detection result, the target detection result of the initial query statement is determined, including: in response to the first initial detection result indicating that the initial query statement is an abnormal query statement, and the probability level indicated by the second initial detection result being greater than or equal to the target probability level, determining that the target detection result is an initial query statement that needs to be corrected; in response to the first initial detection result indicating that the initial query statement is a normal query statement, and the probability level indicated by the second initial detection result being less than the target probability level, determining that the target detection result is an initial query statement that does not need to be corrected.

[0010] Optionally, the method further includes: in response to a first initial detection result indicating that the initial query statement is an abnormal query statement, and a second initial detection result indicating a probability level less than a target probability level, running the initial query statement and detecting the running state of the initial query statement; or, in response to a first initial detection result indicating that the initial query statement is a normal query statement, and a second initial detection result indicating a probability level greater than or equal to the target probability level, running the initial query statement and detecting the running state; in response to a detected running state being a normal running state, determining that the target detection result is that the initial query statement does not need to be corrected; in response to a detected running state being an abnormal running state, determining that the target detection result is that the initial query statement needs to be corrected.

[0011] According to one aspect of the present invention, a database statement detection apparatus is provided. The apparatus may include: a first determining unit, configured to determine at least one initial query statement in an initial query statement set of a target database, wherein the initial query statement represents a query statement to be detected; a generating unit, configured to generate a check statement for the initial query statement; a detection unit, configured to perform statement detection on the initial query statement using the check statement to obtain a first initial detection result, and input the initial query statement into a target statement detection model for statement detection to obtain a second initial detection result, wherein the first initial detection result represents the relationship between the initial query statement and normal and abnormal query statements, the target statement detection model is obtained by training the initial statement detection model based on a sample query statement set, the sample query statement set including at least one sample query statement, the sample query statement representing a sample query statement to be detected, and the second initial detection result representing the degree of probability that the initial query statement needs to be corrected; and a second determining unit, configured to determine a target detection result for the initial query statement based on the first initial detection result and the second initial detection result, wherein the target detection result represents whether the initial query statement needs to be corrected.

[0012] According to another aspect of the present invention, a processor is also provided. The processor is used to run a program, wherein the program, when run by the processor, executes the database statement detection method of the present invention.

[0013] According to another aspect of the embodiments of the present invention, an electronic device is also provided, comprising: a memory storing an executable program; and a processor for running the program, wherein the program executes the database statement detection method of various embodiments of the present invention during runtime.

[0014] According to another aspect of the present invention, a computer-readable storage medium is also provided. The computer-readable storage medium includes a stored program, wherein, when the program is executed, it controls the device where the computer-readable storage medium is located to execute the database statement detection method of the present invention.

[0015] According to another aspect of the present invention, a computer program product is also provided, the computer program product including a computer program, wherein the computer program, when executed by a processor, implements the database statement detection method of the present invention.

[0016] According to another aspect of the present invention, a computer program product is also provided, including a non-volatile computer-readable storage medium for storing a computer program, which, when executed by a processor, implements the database statement detection method of the present invention.

[0017] According to another aspect of the embodiments of the present invention, the embodiments of the present application also provide a computer program that, when executed by a processor, implements the database statement detection method in the above embodiments of the present invention.

[0018] In this embodiment of the invention, when detecting database statements, at least one initial query statement in the initial query statement set of the target database can be determined, along with a check statement that generates the initial query statement. Using the generated check statement, statement detection is performed on the initial query statement to obtain a first initial detection result. Furthermore, the initial query statement is input into the target statement detection model for statement detection to obtain a second initial detection result. Based on the determined first and second initial detection results, the target detection result of the initial query statement can be determined. This achieves the goal of avoiding data pollution in the production environment, thereby solving the technical problem of high patch requirements and ultimately reducing the number of patches needed. Attached Figure Description

[0019] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with their description, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings:

[0020] Figure 1 This is a hardware structure block diagram of a computer terminal for implementing a database statement detection method according to an embodiment of the present invention.

[0021] Figure 2 This is a flowchart of a database statement detection method according to an embodiment of the present invention;

[0022] Figure 3 This is a flowchart of a method for detecting whether a database statement needs to be modified according to an embodiment of the present invention;

[0023] Figure 4 This is a schematic diagram of a database statement detection device according to an embodiment of the present invention;

[0024] Figure 5 This is a structural block diagram of an electronic device according to an embodiment of this application. Detailed Implementation

[0025] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0026] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0027] According to an embodiment of the present invention, a method for detecting database statements is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.

[0028] The database statement detection method provided in this application embodiment can be executed on a mobile terminal, computer terminal or similar computing device. Figure 1 This is a hardware structure block diagram of a computer terminal (or mobile device) for implementing a database statement detection method according to an embodiment of the present invention. Figure 1 As shown, the computer terminal 10 (or mobile device) may include one or more processors 102 (shown as 102a, 102b, ..., 102n in the figure) 102 (processor 102 may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.), a memory 104 for storing data, and a transmission device 106 for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of a BUS bus), a network interface, a power supply, and / or a camera. Those skilled in the art will understand that... Figure 1The structure shown is for illustrative purposes only and does not limit the structure of the aforementioned electronic device. For example, computer terminal 10 may also include... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.

[0029] It should be noted that the aforementioned one or more processors 102 and / or other data processing circuits are generally referred to herein as "data processing circuits". These data processing circuits may be embodied, in whole or in part, in software, hardware, firmware, or any other combination thereof. Furthermore, the data processing circuits may be a single, independent processing module, or may be integrated, in whole or in part, into any other element within the computer terminal 10 (or mobile device). As involved in the embodiments of this application, the data processing circuits serve as a processor control mechanism (e.g., selection of a variable resistor termination path connected to an interface).

[0030] The memory 104 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the database statement detection method in this embodiment. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, thereby implementing the aforementioned database statement detection method. The memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the computer terminal 10 via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.

[0031] The transmission device 106 can be used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of the computer terminal 10. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 may be a Radio Frequency (RF) module used for wireless communication with the Internet.

[0032] The display can be, for example, a touchscreen liquid crystal display (LCD), which allows the user to interact with the user interface of the computer terminal 10 (or mobile device).

[0033] Under the aforementioned operating environment, this application provides the following: Figure 2 The database statement detection method is shown. Figure 2 This is a flowchart of a database statement detection method according to an embodiment of the present invention, which may include the following steps:

[0034] Step S201: Determine at least one initial query statement in the initial query statement set of the target database.

[0035] In the technical solution provided by step S201 of the present invention, the initial query statement can be used to represent the query statement to be detected. For example, the initial query statement can be defined according to Structured Query Language (SQL), which is only an example and not a specific limitation.

[0036] In this embodiment, at least one initial query statement is determined from the initial query statement set of the target database. Optionally, this embodiment uses code analysis tools or custom scripts to extract at least one initial query statement from the initial query statement set of the target database from the source code of the software project. The code analysis tool can be a static code analysis tool, and the custom script can be a script written using a programming language and libraries.

[0037] Step S202: Generate the check statement for the initial query statement.

[0038] In the technical solution provided by step S202 of the present invention, after determining at least one initial query statement in the initial query statement set of the target database, a check statement for the initial query statement is generated. Optionally, based on determining at least one initial query statement, this embodiment can determine the operation corresponding to the initial query statement and the data table on which the operation operates. Based on the determined data table, a check statement for the initial query statement can be generated. That is, the structure and fields of the determined data table are used as the structure and fields required in the check statement.

[0039] Step S203: Using the inspection statement, perform statement detection on the initial query statement to obtain the first initial detection result, and input the initial query statement into the target statement detection model for statement detection to obtain the second initial detection result.

[0040] In the technical solution provided by step S203 of the present invention, the first initial detection result can be used to represent the relationship between the initial query statement and the normal query statement and the abnormal query statement.

[0041] In this embodiment, the target statement detection model can be obtained by training an initial statement detection model based on a sample query statement set. The sample query statement set can include at least one sample query statement, which can be used to represent the sample query statement to be detected.

[0042] In this embodiment, the aforementioned second initial detection result can be used to indicate the degree of likelihood that the initial query statement needs to be corrected.

[0043] In this embodiment, after generating the check statement for the initial query statement, the initial query statement is used to perform statement detection, obtaining a first initial detection result. The initial query statement is then input into the target statement detection model for statement detection, obtaining a second initial detection result. Optionally, based on the generated check statement, this embodiment uses the generated check statement to perform statement detection on the determined initial query statement, obtaining a first initial detection result, that is, the relationship between the initial query statement and normal and abnormal query statements. Simultaneously, the determined initial query statement is input into the target statement detection model for statement detection, obtaining a second initial detection result, that is, the degree of likelihood that the initial query statement needs correction.

[0044] Optionally, the generated check statement can be used to perform statement detection on the determined initial query statement to determine whether the structure and fields of the data table are found in the target database. If the structure and fields of the data table are found in the target database, the first initial detection result indicates that the initial query statement is a normal query statement; if the structure and fields of the data table are not found in the target database, the first initial detection result indicates that the initial query statement is an abnormal query statement.

[0045] Step S204: Based on the first initial detection result and the second initial detection result, determine the target detection result of the initial query statement.

[0046] In the technical solution provided by step S204 of the present invention, the target detection result can be used to indicate whether the initial query statement needs to be corrected.

[0047] In this embodiment, after using an inspection statement to perform statement detection on the initial query statement to obtain a first initial detection result, and inputting the initial query statement into a target statement detection model to obtain a second initial detection result, the target detection result of the initial query statement is determined based on the first and second initial detection results. Optionally, based on the first and second initial detection results, this embodiment can determine the target detection result of the initial query statement according to the content represented by the first and second initial detection results; that is, it can determine whether the initial query statement needs to be corrected.

[0048] Optionally, content extraction can be performed on the first initial detection result to obtain the content represented by the first initial detection result, and content extraction can be performed on the second initial detection result to obtain the content represented by the second initial detection result. If the content represented by the first initial detection result corresponds to the content represented by the second initial detection result, then the target detection result of the initial query statement can be determined as the target detection result corresponding to the content represented by the first initial detection result / the content represented by the second initial detection result.

[0049] Optionally, if the content represented by the first initial detection result does not correspond to the content represented by the second initial detection result, an initial query statement is executed, and the execution status of the initial query statement is detected. Based on the detected execution status, the target detection result of the initial query statement can be determined, that is, it can be determined whether the initial query statement needs to be corrected.

[0050] In steps S201 to S204 of this application, when detecting database statements, at least one initial query statement in the initial query statement set of the target database can be determined, along with a check statement that generates the initial query statement. Using the generated check statement, statement detection is performed on the initial query statement to obtain a first initial detection result. The initial query statement is then input into the target statement detection model for statement detection to obtain a second initial detection result. Based on the determined first and second initial detection results, the target detection result of the initial query statement can be determined. This achieves the goal of avoiding data pollution in the production environment, thereby solving the technical problem of high patch requirements and ultimately reducing the number of patches needed.

[0051] The method described in this embodiment will be further described below.

[0052] As an optional embodiment, step S202, generating a check statement for the initial query statement, includes: determining the attribute information of the operation corresponding to the initial query statement; and generating a check statement for the initial query statement based on the attribute information.

[0053] In this embodiment, the aforementioned attribute information may include at least the structure and fields of the data table on which the operation is performed, and the aforementioned target database may include data tables.

[0054] In this embodiment, the structure of the aforementioned data table may include: the name of the data table, the names of each field, the data type, the data length, whether nullables are allowed, whether there are default values, and whether it is a primary key or a foreign key, etc. For example, the structure of the data table may include: id (integer, primary key), username (string), email (string), and created_at (date and time), etc. This is only an example and is not a specific limitation.

[0055] In this embodiment, the fields of the aforementioned data table can be columns within the data table. Each field can include some type of data. In SQL statements, fields can be used to select data, insert data, update data, or delete data. For example, in the SQL statement `SELECT username, email FROM users WHERE id=1`, `username` and `email` are the fields being operated on, while `users` is the data table being operated on. This is merely an example and not a specific limitation.

[0056] In this embodiment, after determining at least one initial query statement in the initial query statement set of the target database, the attribute information of the operation corresponding to the initial query statement is determined. Optionally, based on determining at least one initial query statement, this embodiment can determine the operation corresponding to the initial query statement, and can also determine the attribute information of the operation, that is, it can at least determine the type, structure, and fields of the data table on which the operation is applied.

[0057] In this embodiment, after determining the attribute information of the operation corresponding to the initial query statement, a check statement for the initial query statement is generated based on the attribute information. Optionally, this embodiment can generate a check statement for the initial query statement based on the determined attribute information and the type, structure, and fields of the data table in the aforementioned attribute information. That is, the determined type, structure, and fields of the aforementioned data table are used as the type, structure, and fields required in the check statement.

[0058] As an optional implementation method, determining the attribute information of the operation corresponding to the initial query statement includes: performing semantic analysis on the initial query statement to obtain the attribute information.

[0059] In this embodiment, after determining at least one initial query statement in the initial query statement set of the target database, semantic analysis is performed on the initial query statement to obtain attribute information. Optionally, based on determining at least one initial query statement, this embodiment performs semantic analysis on the initial query statement to obtain attribute information. For example, it can obtain the type, structure, and fields of the data table to which the operation corresponding to the initial query statement is applied. This is only an example and is not specifically limited.

[0060] As an optional implementation method, the check statement for generating the initial query statement is based on the attribute information, including: extracting the structure and fields from the attribute information; and generating a check statement that satisfies the structure and fields.

[0061] In this embodiment, after determining the attribute information of the operation corresponding to the initial query statement, the structure and fields are extracted from the attribute information. Optionally, based on the determined attribute information, this embodiment can extract the type, structure, and fields of the data table affected by the operation corresponding to the initial query statement from the determined attribute information.

[0062] In this embodiment, after extracting the structure and fields from the attribute information, a check statement that satisfies the structure and fields is generated. Optionally, based on the extracted structure and fields, this embodiment uses the structure and fields of the data table affected by the operation corresponding to the initial query statement as the content that the check statement needs to satisfy, thereby generating a check statement that satisfies the above structure and fields.

[0063] Optionally, based on the extracted type, structure, and fields, the type, structure, and fields of the data table affected by the operation corresponding to the initial query statement are used as the content that the check statement needs to satisfy, thereby generating a check statement that satisfies the above type, structure, and fields. This is only an example and is not specifically limited.

[0064] As an optional embodiment, step S204, based on the first initial detection result and the second initial detection result, determines the target detection result of the initial query statement, including: in response to the first initial detection result indicating that the initial query statement is an abnormal query statement, and the probability level indicated by the second initial detection result is greater than or equal to the target probability level, determining that the target detection result is an initial query statement that needs to be corrected; in response to the first initial detection result indicating that the initial query statement is a normal query statement, and the probability level indicated by the second initial detection result is less than the target probability level, determining that the target detection result is an initial query statement that does not need to be corrected.

[0065] In this embodiment, after using an inspection statement to perform statement detection on the initial query statement to obtain a first initial detection result, and inputting the initial query statement into a target statement detection model to obtain a second initial detection result, in response to the first initial detection result indicating that the initial query statement is an abnormal query statement, and the probability level indicated by the second initial detection result being greater than or equal to the target probability level, the target detection result is determined to be an initial query statement that needs correction. Optionally, based on obtaining the first and second initial detection results, if the first initial detection result indicates that the initial query statement is an abnormal query statement, and the probability level indicated by the second initial detection result is greater than or equal to the target probability level, then it is stated that the content of the initial query statement indicated by the first initial detection result as an abnormal query statement corresponds to the content of the content indicated by the second initial detection result as having a probability level greater than or equal to the target probability level, thereby determining that the target detection result is an initial query statement that needs correction.

[0066] In this embodiment, after using an inspection statement to perform statement detection on the initial query statement to obtain a first initial detection result, and inputting the initial query statement into a target statement detection model to obtain a second initial detection result, in response to the first initial detection result indicating that the initial query statement is a normal query statement, and the probability level indicated by the second initial detection result being less than the target probability level, the target detection result is determined to be that the initial query statement does not need to be corrected. Optionally, based on obtaining the first and second initial detection results, if the first initial detection result indicates that the initial query statement is a normal query statement, and the probability level indicated by the second initial detection result is less than the target probability level, then it is said that the content of the initial query statement indicated by the first initial detection result as a normal query statement corresponds to the content of the content indicated by the second initial detection result as having a probability level less than the target probability level, thereby determining that the target detection result does not need to be corrected.

[0067] As an optional embodiment, the method further includes: in response to a first initial detection result indicating that the initial query statement is an abnormal query statement, and a second initial detection result indicating a probability level less than a target probability level, running the initial query statement and detecting the running state of the initial query statement; or, in response to a first initial detection result indicating that the initial query statement is a normal query statement, and a second initial detection result indicating a probability level greater than or equal to the target probability level, running the initial query statement and detecting the running state; in response to a detected running state being a normal running state, determining that the target detection result is that the initial query statement does not need to be corrected; in response to a detected running state being an abnormal running state, determining that the target detection result is that the initial query statement needs to be corrected.

[0068] In this embodiment, in response to a first initial detection result indicating that the initial query statement is an abnormal query statement, and a second initial detection result indicating a probability level less than a target probability level, the initial query statement is executed, and the execution status of the initial query statement is detected. Optionally, based on the first and second initial detection results, if the first initial detection result indicates that the initial query statement is an abnormal query statement, and the second initial detection result indicating a probability level less than a target probability level, then it is indicated that the content of the initial query statement indicating an abnormal query statement as indicated by the first initial detection result does not correspond to the content indicating a probability level less than a target probability level as indicated by the second initial detection result. The initial query statement is then executed, and the execution status of the initial query statement is detected.

[0069] In this embodiment, in response to a first initial detection result indicating that the initial query statement is a normal query statement, and a second initial detection result indicating a probability level greater than or equal to the target probability level, the initial query statement is executed, and the execution status is detected. Optionally, based on the first and second initial detection results, if the first initial detection result indicates that the initial query statement is a normal query statement, and the second initial detection result indicating a probability level greater than or equal to the target probability level, then it is determined that the content of the initial query statement indicating a normal query statement as indicated by the first initial detection result does not correspond to the content of the content indicating a probability level greater than or equal to the target probability level as indicated by the second initial detection result. In this case, the initial query statement is executed, and the execution status of the initial query statement is detected.

[0070] In this embodiment, after detecting the operating status, in response to the detected operating status being a normal operating status, the target detection result is determined to be that the initial query statement does not need to be corrected. Optionally, based on the detected operating status, this embodiment judges the relationship between the detected operating status and the normal operating status and abnormal operating status. If it is determined that the detected operating status is a normal operating status, then the target detection result can be determined to be that the initial query statement does not need to be corrected.

[0071] In this embodiment, after detecting the operating status, in response to the detected operating status being an abnormal operating status, the target detection result is determined to be an initial query statement that needs to be corrected. Optionally, based on the detected operating status, this embodiment judges the relationship between the detected operating status and the normal operating status and the abnormal operating status. If it is determined that the detected operating status is an abnormal operating status, then the target detection result can be determined to be an initial query statement that needs to be corrected.

[0072] In this embodiment of the invention, when detecting database statements, at least one initial query statement in the initial query statement set of the target database can be determined, along with a check statement that generates the initial query statement. Using the generated check statement, statement detection is performed on the initial query statement to obtain a first initial detection result. Furthermore, the initial query statement is input into the target statement detection model for statement detection to obtain a second initial detection result. Based on the determined first and second initial detection results, the target detection result of the initial query statement can be determined. This achieves the goal of avoiding data pollution in the production environment, thereby solving the technical problem of high patch requirements and ultimately reducing the number of patches needed.

[0073] The technical solutions of the embodiments of the present invention will be illustrated below with reference to preferred embodiments.

[0074] In the process of testing database queries, the actual installation of the package is often used to determine whether a patch is needed. However, this method often requires support for business function testing. Moreover, if the testing environment fails to intercept patched packages and they flow into production, it can lead to data contamination in the production environment, resulting in a large number of patch requirements.

[0075] To address the aforementioned technical problems, this invention proposes a database statement detection method. Based on identifying at least one initial query statement in the target database's initial query statement set, a check statement is generated for that statement. Using the generated check statement, the initial query statement is detected to obtain a first initial detection result. Furthermore, the initial query statement is input into a target statement detection model for statement detection to obtain a second initial detection result. Based on these two detection results, the target detection result for the initial query statement can be determined. This achieves the goal of avoiding data pollution in the production environment, thus solving the technical problem of high patch requirements and ultimately reducing the number of patches needed.

[0076] In this embodiment, the need to modify the initial query statement can be determined by detecting whether the database statement needs to be modified. For example, Figure 3 This is a flowchart of a method for detecting whether a database statement needs to be modified according to an embodiment of the present invention, such as... Figure 3 As shown, the method may include the following steps:

[0077] Step S301: By performing semantic analysis on the SQL statement, the structure and fields of the data table operated by the SQL statement can be parsed out, and a check statement for the SQL statement can be generated.

[0078] In the technical solution provided by step S301 of the present invention, the structure and fields of the data table operated by the SQL statement are parsed out. For example, the structure of the data table operated by the INSERT statement is parsed out, or the field name of the SET keyword in the data table operated by the UPDATE statement is parsed out. This is only an example and is not specifically limited.

[0079] After generating the SQL statement check statement, proceed to steps S302 and S303. Based on the generated check statement, perform statement detection on the initial query statement to obtain the first initial detection result. Also, input the SQL statement into the target statement detection model generated by artificial intelligence for statement detection to obtain the degree of probability that the SQL statement needs to be corrected.

[0080] In the technical solution provided by step S302 of the present invention, the obtained first initial detection result can determine whether there is a data table structure and fields in the specified database that meet the conditions. That is, if the first initial detection result indicates that the initial query statement is a normal query statement, it can be determined that there is a data table structure and fields in the specified database that meet the conditions; if the first initial detection result indicates that the initial query statement is an abnormal query statement, it can be determined that there is no data table structure and fields in the specified database that meet the conditions.

[0081] In this embodiment, while determining whether there is a data table structure and fields in the specified database that meet the conditions, the method extends to detect the data type in the updated field and detect whether the type of the corresponding field in the database matches.

[0082] After obtaining the first initial detection result and the probability of needing to modify the SQL statement, proceed to step S304, and determine the target detection result of the initial query statement based on the obtained first initial detection result and probability.

[0083] In the technical solution provided by step S304 of the present invention, if the first initial detection result is that the initial query statement is an abnormal query statement and the probability is greater than or equal to the target probability, then the target detection result of the initial query statement can be determined to be that the initial query statement needs to be corrected; if the first initial detection result is that the initial query statement is a normal query statement and the probability is less than the target probability, then the target detection result of the initial query statement can be determined to be that the initial query statement does not need to be corrected.

[0084] In this embodiment, when detecting database statements, at least one initial query statement in the initial query statement set of the target database can be determined, along with a check statement that generates the initial query statement. Using the generated check statement, statement detection is performed on the initial query statement to obtain a first initial detection result. The initial query statement is then input into the target statement detection model for statement detection to obtain a second initial detection result. Based on the determined first and second initial detection results, the target detection result of the initial query statement can be determined. This achieves the goal of avoiding data pollution in the production environment, thereby solving the technical problem of high patch requirements and ultimately reducing the number of patches needed.

[0085] According to embodiments of the present invention, a database statement detection device is also provided. It should be noted that this database statement detection device can be used to execute a database statement detection method according to one of the embodiments.

[0086] Figure 4 This is a schematic diagram of a database statement detection device according to an embodiment of the present invention. Figure 4 As shown, the database statement detection device 400 may include: a first determining unit 401, a generating unit 402, a detecting unit 403, and a second determining unit 404.

[0087] The first determining unit 401 is used to determine at least one initial query statement in the initial query statement set of the target database, wherein the initial query statement is used to represent the query statement to be detected.

[0088] The generation unit 402 is used to generate the check statement for the initial query statement.

[0089] The detection unit 403 is used to perform statement detection on the initial query statement using the check statement to obtain a first initial detection result, and input the initial query statement into the target statement detection model for statement detection to obtain a second initial detection result. The first initial detection result is used to represent the relationship between the initial query statement and normal and abnormal query statements. The target statement detection model is obtained by training the initial statement detection model based on a sample query statement set. The sample query statement set includes at least one sample query statement, which is used to represent the sample query statement to be detected. The second initial detection result is used to represent the degree of probability that the initial query statement needs to be corrected.

[0090] The second determining unit 404 is used to determine the target detection result of the initial query statement based on the first initial detection result and the second initial detection result, wherein the target detection result is used to indicate whether the initial query statement needs to be modified.

[0091] Optionally, the generation unit 402 may include: a first determining module, used to determine the attribute information of the operation corresponding to the initial query statement, wherein the attribute information includes at least the structure and fields of the data table to which the operation is applied, and the target database includes data tables; and a generation module, used to generate a check statement for the initial query statement based on the attribute information.

[0092] Optionally, the first determining module may include an analysis submodule, used to perform semantic analysis on the initial query statement to obtain attribute information.

[0093] Optionally, the generation module may include: an extraction submodule for extracting the structure and fields from the attribute information; and a generation submodule for generating check statements that satisfy the structure and fields.

[0094] Optionally, the second determining unit 404 may include: a second determining module, configured to determine that the target detection result is an initial query statement that needs to be corrected in response to the first initial detection result indicating that the initial query statement is an abnormal query statement and the probability level indicated by the second initial detection result is greater than or equal to the target probability level; and a third determining module, configured to determine that the target detection result is an initial query statement that does not need to be corrected in response to the first initial detection result indicating that the initial query statement is a normal query statement and the probability level indicated by the second initial detection result is less than the target probability level.

[0095] Optionally, the database statement detection device 400 may further include: a first detection unit, configured to run the initial query statement and detect its running state in response to a first initial detection result indicating that the initial query statement is an abnormal query statement and a second initial detection result indicating that the probability level is less than the target probability level; or, to run the initial query statement and detect its running state in response to a first initial detection result indicating that the initial query statement is a normal query statement and a second initial detection result indicating that the probability level is greater than or equal to the target probability level; a third determination unit, configured to determine that the target detection result is that the initial query statement does not need to be corrected in response to a detected running state being a normal running state; and a fourth determination unit, configured to determine that the target detection result is that the initial query statement needs to be corrected in response to a detected running state being an abnormal running state.

[0096] In this embodiment, the database statement detection device includes the following units: a first determining unit, configured to determine at least one initial query statement from the initial query statement set of the target database, wherein the initial query statement represents the query statement to be detected; a generating unit, configured to generate a checking statement for the initial query statement; and a detection unit, configured to perform statement detection on the initial query statement using the checking statement to obtain a first initial detection result, and input the initial query statement into a target statement detection model for statement detection to obtain a second initial detection result, wherein the first initial detection result represents the relationship between the initial query statement and normal and abnormal query statements, and the target statement detection model... The method is based on a sample query statement set, which is used to train an initial statement detection model. The sample query statement set includes at least one sample query statement, which represents the sample query statement to be detected. The second initial detection result is used to indicate the probability that the initial query statement needs to be corrected. The second determining unit is used to determine the target detection result of the initial query statement based on the first initial detection result and the second initial detection result. The target detection result is used to indicate whether the initial query statement needs to be corrected. This achieves the goal of avoiding data pollution in the production environment, thereby solving the technical problem of large patch requirements and reducing the number of patches required.

[0097] It should be noted that the first determining unit 401, generating unit 402, detecting unit 403, and second determining unit 404 mentioned above correspond to steps S201 to S204 in the embodiments. The four units and the corresponding steps implement the same instances and application scenarios, but are not limited to the content disclosed in the above embodiments. It should be noted that the above modules or units can be hardware components or software components stored in memory (e.g., memory 104) and processed by one or more processors (e.g., processors 102a, 102b, ..., 102n). The above modules can also be part of the device and run in the computer terminal 10 provided in Embodiment 1.

[0098] Embodiments of this application may provide an electronic device. Figure 5 This is a structural block diagram of an electronic device according to an embodiment of this application. Figure 5 As shown, the electronic device 500 may include: one or more ( Figure 5 (Only one is shown) processor 502, memory 504, memory controller 506, and peripheral interface 508, wherein peripheral interface 508 is connected to radio frequency module 5101, audio module 5102 and display 5103.

[0099] The memory can be used to store software programs and modules, such as the program instructions / modules corresponding to the methods and apparatus in the embodiments of this application. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, thereby implementing the above-described methods. The memory may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include memory remotely located relative to the processor, and these remote memories can be connected to the terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.

[0100] The processor can invoke information and application programs stored in memory via a transmission device to perform the following steps: determining at least one initial query statement in the initial query statement set of the target database, wherein the initial query statement represents the query statement to be detected; generating a check statement for the initial query statement; using the check statement to perform statement detection on the initial query statement to obtain a first initial detection result, and inputting the initial query statement into a target statement detection model for statement detection to obtain a second initial detection result, wherein the first initial detection result represents the relationship between the initial query statement and normal and abnormal query statements, the target statement detection model is obtained by training the initial statement detection model based on a sample query statement set, the sample query statement set including at least one sample query statement, the sample query statement represents the sample query statement to be detected, and the second initial detection result represents the degree of probability that the initial query statement needs to be corrected; and determining a target detection result for the initial query statement based on the first and second initial detection results, wherein the target detection result represents whether the initial query statement needs to be corrected.

[0101] The processor can also invoke information and application programs stored in memory via a transmission device to perform the following steps: determine the attribute information of the operation corresponding to the initial query statement, wherein the attribute information includes at least the structure and fields of the data table on which the operation is applied, and the target database includes data tables; and generate a check statement for the initial query statement based on the attribute information.

[0102] The processor can also access information and applications stored in memory via a transmission device to perform the following steps: semantic analysis of the initial query statement to obtain attribute information.

[0103] The processor can also call information and applications stored in memory via a transmission device to perform the following steps: extracting the structure and fields from the attribute information; generating check statements that satisfy the structure and fields.

[0104] The processor can also invoke information and application programs stored in the memory via the transmission device to perform the following steps: in response to a first initial detection result indicating that the initial query statement is an abnormal query statement, and a second initial detection result indicating a probability level greater than or equal to the target probability level, determine that the target detection result is an initial query statement that needs to be corrected; in response to a first initial detection result indicating that the initial query statement is a normal query statement, and a second initial detection result indicating a probability level less than the target probability level, determine that the target detection result is an initial query statement that does not need to be corrected.

[0105] The processor can also invoke information and application programs stored in the memory via a transmission device to perform the following steps: in response to a first initial detection result indicating that the initial query statement is an abnormal query statement, and a second initial detection result indicating a probability level less than the target probability level, run the initial query statement and detect the running state of the initial query statement; or, in response to a first initial detection result indicating that the initial query statement is a normal query statement, and a second initial detection result indicating a probability level greater than or equal to the target probability level, run the initial query statement and detect the running state; in response to a detected running state being a normal running state, determine that the target detection result is that the initial query statement does not need to be corrected; in response to a detected running state being an abnormal running state, determine that the target detection result is that the initial query statement needs to be corrected.

[0106] In this embodiment of the invention, when detecting database statements, at least one initial query statement in the initial query statement set of the target database can be determined, along with a check statement that generates the initial query statement. Using the generated check statement, statement detection is performed on the initial query statement to obtain a first initial detection result. Furthermore, the initial query statement is input into the target statement detection model for statement detection to obtain a second initial detection result. Based on the determined first and second initial detection results, the target detection result of the initial query statement can be determined. This achieves the goal of avoiding data pollution in the production environment, thereby solving the technical problem of high patch requirements and ultimately reducing the number of patches needed.

[0107] Figure 5 This is a structural block diagram of an electronic device according to an embodiment of this application. Those skilled in the art will understand that... Figure 5 The structure shown is for illustrative purposes only. Electronic devices can also be smartphones (such as Android phones, iOS phones, etc.), tablets, PDAs, mobile internet devices (MIDs), PADs, and other terminal devices. Figure 5 This does not limit the structure of the aforementioned electronic device. For example, electronic devices may also include components that are more... Figure 5 The more or fewer components shown (such as network interfaces, display devices, etc.), or having the same Figure 5 The different configurations shown.

[0108] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing the hardware related to the terminal device. The program can be stored in a computer-readable storage medium, which may include: flash drive, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.

[0109] According to an embodiment of the present invention, a processor is also provided for running a program, wherein the program is executed by the processor to perform the database statement detection method in the embodiment.

[0110] According to an embodiment of the present invention, an electronic device is also provided, comprising: a memory storing an executable program; and a processor for running the program, wherein the program executes the database statement detection method in the embodiment during runtime.

[0111] According to another aspect of the present invention, a computer-readable storage medium is also provided. The computer-readable storage medium includes a stored program, wherein, when the program is executed, it controls the device where the computer-readable storage medium is located to execute the database statement detection method of the embodiment.

[0112] According to an embodiment of the present invention, a computer program product is also provided, the computer program product including a computer program, wherein when the computer program is executed by a processor, it implements the database statement detection method in the embodiment.

[0113] According to an embodiment of the present invention, a computer program product is also provided, including a non-volatile computer-readable storage medium for storing a computer program, which, when executed by a processor, implements the database statement detection method in the embodiment.

[0114] According to an embodiment of the present invention, a computer program is also provided, which, when executed by a processor, implements the deployment method of task instances in a disaster recovery environment as described in the embodiment.

[0115] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.

[0116] In the above embodiments of the present invention, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0117] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units can be a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual couplings, direct couplings, or communication connections may be through some interfaces; indirect couplings or communication connections between units or modules may be electrical or other forms.

[0118] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0119] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0120] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, in essence, or the part that contributes to related technologies, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause 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 the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.

[0121] The above are merely preferred embodiments of the present invention. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.

Claims

1. A method for detecting database statements, characterized in that, The detection method, applied to version correction scenarios in a test environment, includes: Determine at least one initial query statement in the initial query statement set of the target database, wherein the initial query statement is used to represent the query statement to be detected; The check statement for generating the initial query statement includes: determining the attribute information of the operation corresponding to the initial query statement, wherein the attribute information includes at least the structure and fields of the data table to which the operation is applied, and the target database includes the data table; and generating the check statement for the initial query statement based on the attribute information. Using the aforementioned inspection statement, the initial query statement is subjected to statement detection to obtain a first initial detection result. The initial query statement is then input into a target statement detection model for statement detection to obtain a second initial detection result. The first initial detection result represents the relationship between the initial query statement and normal and abnormal query statements. The target statement detection model is obtained by training the initial statement detection model based on a sample query statement set. The sample query statement set includes at least one sample query statement, which represents the sample query statement to be detected. The second initial detection result represents the degree of likelihood that the initial query statement needs correction. Based on the first initial detection result and the second initial detection result, the target detection result of the initial query statement is determined, wherein the target detection result is used to indicate whether the initial query statement needs to be corrected.

2. The method according to claim 1, characterized in that, Determine the attribute information of the operation corresponding to the initial query statement, including: The initial query statement is semantically analyzed to obtain the attribute information.

3. The method according to claim 1, characterized in that, Based on the attribute information, a check statement is generated for the initial query statement, including: Extract the structure and the fields from the attribute information; Generate the check statement that satisfies the structure and the fields.

4. The method according to claim 1, characterized in that, Based on the first initial detection result and the second initial detection result, the target detection result of the initial query statement is determined, including: In response to the first initial detection result indicating that the initial query statement is the abnormal query statement, and the probability level indicated by the second initial detection result being greater than or equal to the target probability level, the target detection result is determined to be that the initial query statement needs to be corrected; In response to the first initial detection result indicating that the initial query statement is the normal query statement, and the probability level indicated by the second initial detection result being less than the target probability level, it is determined that the target detection result is that the initial query statement does not need to be corrected.

5. The method according to claim 4, characterized in that, The method further includes: In response to the first initial detection result indicating that the initial query statement is the abnormal query statement, and the probability level indicated by the second initial detection result being less than the target probability level, the initial query statement is executed, and the execution status of the initial query statement is detected; or, In response to the first initial detection result indicating that the initial query statement is the normal query statement, and the probability level indicated by the second initial detection result being greater than or equal to the target probability level, the initial query statement is executed, and the running status is detected; In response to the detected operating state being a normal operating state, the target detection result is determined to be that the initial query statement does not need to be corrected; In response to the detected abnormal operating state, the target detection result is determined to indicate that the initial query statement needs to be corrected.

6. A database statement detection device, characterized in that, For version correction scenarios applied in a test environment, the detection device includes: The first determining unit is used to determine at least one initial query statement in the initial query statement set of the target database, wherein the initial query statement is used to represent the query statement to be detected. A generation unit is used to generate a check statement for the initial query statement, including: determining the attribute information of the operation corresponding to the initial query statement, wherein the attribute information includes at least the structure and fields of the data table to which the operation is applied, and the target database includes the data table; and generating a check statement for the initial query statement based on the attribute information. The detection unit is used to perform statement detection on the initial query statement using the inspection statement to obtain a first initial detection result, and input the initial query statement into the target statement detection model for statement detection to obtain a second initial detection result. The first initial detection result is used to represent the relationship between the initial query statement and normal and abnormal query statements. The target statement detection model is obtained by training the initial statement detection model based on a sample query statement set. The sample query statement set includes at least one sample query statement, which represents the sample query statement to be detected. The second initial detection result is used to represent the degree of probability that the initial query statement needs to be corrected. The second determining unit is used to determine the target detection result of the initial query statement based on the first initial detection result and the second initial detection result, wherein the target detection result is used to indicate whether the initial query statement needs to be corrected.

7. A processor, characterized in that, The processor is used to run a program, wherein the program is executed by the processor to perform the database statement detection method according to any one of claims 1 to 5.

8. An electronic device, characterized in that, include: Memory, which stores executable programs; A processor for running the program, wherein the program, when running, executes the database statement detection method according to any one of claims 1 to 5.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored executable program, wherein, when the executable program is executed, it controls the device where the storage medium is located to execute the database statement detection method of any one of claims 1 to 5.

Citation Information

Patent Citations

  • AST-based source code anomaly detection method and device

    CN115146282A

  • Structured query statement detection method and device, equipment and medium

    CN117216095A