Database statement detection method and device, processor and electronic equipment
By detecting the initial query statement of the database and combining with the target statement detection model, the data pollution problem in production environment caused by database query statement detection in the prior art is solved, and the effect of reducing patch demand is achieved.
Patent Information
- Application Number
- CN202411941591.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-26
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2044-12-26
AI Technical Summary
When detecting database query statements, the existing technology needs to support business function testing, and the test environment fails to intercept version packages that need to be corrected, resulting in data pollution in the production environment and causing problems with high patch demand.
By determining the initial query statement of the target database, a check statement is generated, the initial query statement is detected, and it is input into the target statement detection model. Combining the first initial detection result and the second initial detection result, it is determined whether the initial query statement needs to be corrected.
It effectively avoids data pollution in production environment, reduces the demand for patches, and improves the accuracy and efficiency of database query statement detection.
Smart Images

Figure CN119883858A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of big data, and in particular to a method, device, processor and electronic device for detecting database statements. Background Art
[0002] In the process of checking database query statements, actual installation is often used to check whether the version package needs to be revised. However, such a detection method often needs to support business function testing. Moreover, if the test environment fails to intercept the version package that needs to be revised and allows the version package to flow into production, it will cause data pollution in the production environment, resulting in a large number of technical problems such as the demand for patches.
[0003] With respect to the technical problem of the high demand for the above-mentioned patches, no effective solution has been proposed yet. Summary of the invention
[0004] The embodiments of the present invention provide a method, device, processor and electronic device for detecting a database statement, so as to at least solve the technical problem of a large number of patches required.
[0005] According to one aspect of an embodiment of the present invention, a method for detecting database statements is provided, the method comprising: determining at least one initial query statement in an initial query statement set of a target database, wherein the initial query statement is used to represent a query statement to be subjected to statement detection; 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 is used to represent a relationship between the initial query statement and normal query statements and abnormal query statements, the target statement detection model is obtained by training an initial statement detection model based on a sample query statement set, the sample query statement set includes at least one sample query statement, the sample query statement is used to represent a sample query statement to be subjected to statement detection, and the second initial detection result is used to represent a degree of possibility that the initial query statement needs to be corrected; determining 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 is used to represent whether the initial query statement needs to be corrected.
[0006] Optionally, generating a check statement for the initial query statement includes: determining 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 acts, and the target database includes the data table; based on the attribute information, generating a check statement for the initial query statement.
[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, generating a check statement of the initial query statement includes: extracting a structure and a field from the attribute information; and generating a check statement that satisfies the structure and the field.
[0009] Optionally, based on the first initial detection result and the second initial detection result, a 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 possibility degree indicated by the second initial detection result is greater than or equal to the target possibility degree, determining that the target detection result is that the initial query statement 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 possibility degree indicated by the second initial detection result is less than the target possibility degree, determining that the target detection result is that the initial query statement does not need to be corrected.
[0010] Optionally, the method also includes: in response to the first initial detection result indicating that the initial query statement is an abnormal query statement, and the second initial detection result indicating a degree of possibility less than a target degree of possibility, running the initial query statement and detecting a running state of the initial query statement; or, in response to the first initial detection result indicating that the initial query statement is a normal query statement, and the second initial detection result indicating a degree of possibility greater than or equal to a target degree of possibility, running the initial query statement and detecting a running state; in response to the 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 the 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 an embodiment of the present invention, a database statement detection device is provided, and the device may include: a first determination unit, used to determine at least one initial query statement in an initial query statement set of a target database, wherein the initial query statement is used to represent a query statement to be subjected to statement detection; a generation unit, used to generate a check statement of the initial query statement; a detection unit, 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 a target statement detection model for statement detection to obtain a second initial detection result, wherein the first initial detection result is used to represent a relationship between the initial query statement and normal query statements and abnormal query statements, and the target statement detection model is obtained by training an initial statement detection model based on a sample query statement set, the sample query statement set includes at least one sample query statement, the sample query statement is used to represent a sample query statement to be subjected to statement detection, and the second initial detection result is used to represent a possibility that the initial query statement needs to be corrected; a second determination unit, used to determine 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 to represent whether the initial query statement needs to be corrected.
[0012] According to another aspect of an embodiment of the present invention, a processor is provided, which is used to run a program, wherein when the program is run by the processor, the method for detecting a database statement in an embodiment of the present invention is executed.
[0013] According to another aspect of an embodiment of the present invention, there is further provided an electronic device, comprising: a memory storing an executable program; and a processor for running the program, wherein when the program is running, the method for detecting database statements in various embodiments of the present invention is executed.
[0014] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute the database statement detection method in the present invention.
[0015] According to another aspect of an embodiment of the present invention, a computer program product is provided. The computer program product includes a computer program. When the computer program is executed by a processor, the method for detecting a database statement in an embodiment of the present invention is implemented.
[0016] According to another aspect of an embodiment of the present invention, a computer program product is provided, including a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium is used to store a computer program, and when the computer program is executed by a processor, the method for detecting database statements in an embodiment of the present invention is implemented.
[0017] According to another aspect of an embodiment of the present invention, an embodiment of the present application further provides a computer program, which implements the database statement detection method in the above-mentioned embodiment of the present invention when the computer program is executed by a processor.
[0018] In an embodiment of the present invention, when detecting a database statement, at least one initial query statement in the initial query statement set of the target database can be determined, and a check statement for the initial query statement can be generated. The generated check statement is used to perform statement detection on the initial query statement, and a first initial detection result can be obtained. The initial query statement is input into the target statement detection model for statement detection, and a second initial detection result can be obtained. Based on the determined first initial detection result and the second initial detection result, a target detection result of the initial query statement can be determined, thereby achieving the purpose of avoiding data pollution in the production environment, thereby solving the technical problem of a large number of patches required, and further achieving the technical effect of reducing the number of patches required. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0020] Figure 1 is a hardware structure block diagram of a computer terminal for implementing a method for detecting a database statement according to an embodiment of the present invention;
[0021] Figure 2 is a flow chart of a method for detecting a database statement according to an embodiment of the present invention;
[0022] Figure 3 is a flow chart of a method for detecting whether a database statement needs to be corrected according to an embodiment of the present invention;
[0023] Figure 4 is a schematic diagram of a database statement detection device according to an embodiment of the present invention;
[0024] Figure 5 It is a structural block diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0025] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only embodiments of a part of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work 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 and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[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 of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0028] The database statement detection method provided in the embodiment of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Figure 1 1 is a hardware structure block diagram of a computer terminal (or mobile device) for implementing a method for detecting a database statement according to an embodiment of the present invention. Figure 1 As shown, the computer terminal 10 (or mobile device) may include one or more (102a, 102b, ..., 102n are used to illustrate) processors 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), 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 the BUS bus), a network interface, a power supply and / or a camera. It can be understood by those skilled in the art that Figure 1The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.
[0029] It should be noted that the one or more processors 102 and / or other data processing circuits described above may generally be referred to herein as "data processing circuits". The data processing circuits may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuit may be a single independent processing module, or may be incorporated in whole or in part into any of the other components in the computer terminal 10 (or mobile device). As described in the embodiments of the present application, the data processing circuit acts as a processor control (e.g., selection of a variable resistor terminal 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 detection method of the database statement in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, that is, the detection method of the database statement described above is realized. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the computer terminal 10 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0031] The transmission device 106 can be used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the computer terminal 10. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0032] The display may be, for example, a touch screen liquid crystal display (LCD), which enables a user to interact with a user interface of the computer terminal 10 (or mobile device).
[0033] Under the above operating environment, this application provides Figure 2 The detection method of the database statement is shown. Figure 2 1 is a flowchart of a method for detecting a database statement according to an embodiment of the present invention. The method may include the following steps:
[0034] Step S201: determining at least one initial query statement in an initial query statement set of a target database.
[0035] In the technical solution provided in 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 the Structured Query Language (SQL), which is only used as an example and is not specifically limited.
[0036] In this embodiment, at least one initial query statement in the initial query statement set of the target database is determined. Optionally, this embodiment uses a code analysis tool or a custom script to extract at least one initial query statement in the initial query statement set of the target database from the source code of the software project. The code analysis tool may be a static code analysis tool, and the custom script may be a script written using a programming language and a library.
[0037] Step S202: Generate a check statement for the initial query statement.
[0038] In the technical solution provided in the above 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 of 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 acts. Based on the determined data table, a check statement of the initial query statement can be generated. In other words, the structure and fields of the determined data table are used as the structure and fields required to be used in the check statement.
[0039] Step S203, using the check statement, performing statement detection on the initial query statement to obtain a first initial detection result, and inputting the initial query statement into the target statement detection model to perform statement detection to obtain a second initial detection result.
[0040] In the technical solution provided in the above step S203 of the present invention, the above 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 sentence detection model may be obtained by training an initial sentence detection model based on a sample query sentence set, wherein the sample query sentence set may include at least one sample query sentence, and the sample query sentence may be used to represent a sample query sentence to be subjected to sentence detection.
[0042] In this embodiment, the second initial detection result may be used to indicate the possibility that the initial query statement needs to be corrected.
[0043] In this embodiment, after generating a check statement for the initial query statement, the check statement is used to perform statement detection on the initial query statement to obtain a first initial detection result, and the initial query statement is input into the target statement detection model for statement detection to obtain a second initial detection result. Optionally, based on the generation of the check statement in this embodiment, the generated check statement is used to perform statement detection on the determined initial query statement to obtain a first initial detection result, that is, the relationship between the initial query statement and the normal query statement and the abnormal query statement can be obtained. At the same time, the determined initial query statement is input into the target statement detection model for statement detection to obtain a second initial detection result, that is, the degree of possibility that the initial query statement needs to be corrected can be obtained.
[0044] Optionally, by using the generated check statement, the determined initial query statement is subjected to statement detection 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 may indicate 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 may indicate that the initial query statement is an abnormal query statement.
[0045] Step S204: determining a target detection result of the initial query statement based on the first initial detection result and the second initial detection result.
[0046] In the technical solution provided in the above step S204 of the present invention, the above target detection result can be used to indicate whether the initial query statement needs to be corrected.
[0047] In this embodiment, after using the check statement to perform sentence detection on the initial query statement to obtain a first initial detection result, and inputting the initial query statement into the target sentence detection model to perform sentence detection to obtain a second initial detection result, the target detection result of the initial query statement is determined based on the first initial detection result and the second initial detection result. Optionally, based on the first initial detection result and the second initial detection result, this embodiment can determine the target detection result of the initial query statement according to the content represented by the first initial detection result and the content represented by the second initial detection result, that is, it can determine whether the initial query statement needs to be corrected.
[0048] Optionally, content extraction is performed on the first initial detection result to obtain the content represented by the first initial detection result, and content extraction is 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, it can be determined that the target detection result of the initial query statement is 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, the initial query statement is run to detect the running state of the initial query statement. According to the detected running state, the target detection result of the initial query statement can be determined, that is, whether the initial query statement needs to be corrected can be determined.
[0050] In the above steps S201 to S204 of the present application, when detecting database statements, at least one initial query statement in the initial query statement set of the target database can be determined, and a check statement of the initial query statement can be generated. The generated check statement is used to perform statement detection on the initial query statement, and a first initial detection result can be obtained, and the initial query statement is input into the target statement detection model for statement detection, and a second initial detection result can be obtained, and based on the determined first initial detection result and the second initial detection result, the target detection result of the initial query statement can be determined, thereby achieving the purpose of avoiding data pollution in the production environment, thereby solving the technical problem of a large number of patches required, and further achieving the technical effect of reducing the number of patches required.
[0051] The above method of this embodiment is further introduced below.
[0052] As an optional implementation manner, step S202, generating a check statement for the initial query statement, includes: determining attribute information of an 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 attribute information may at least include the structure and fields of the data table on which the operation is performed, and the target database may include a data table.
[0054] In this embodiment, the structure of the data table may include: the name of the data table, the name of each field, the type of data, the length of data, whether it is allowed to be empty, whether there is a default value, 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 type), email (string type) and created_at (date time type) and other attribute information, which is only used as an example and is not specifically limited.
[0055] In this embodiment, the fields of the above data table can be columns in the data table. Each field can include a certain type of data. In an SQL statement, a field 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, and users is the data table being operated. This is only an example and is not specifically limited.
[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 field of the data table on which the operation acts.
[0057] In this embodiment, after determining the attribute information of the operation corresponding to the initial query statement, a check statement of the initial query statement is generated based on the attribute information. Optionally, based on the determined attribute information, the embodiment can generate a check statement of the initial query statement according to the type, structure and field of the data table in the attribute information. In other words, the determined type, structure and field of the data table are used as the type, structure and field required to be used in the check statement.
[0058] As an optional implementation manner, 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, the type, structure and field of the data table on which the operation corresponding to the initial query statement acts can be obtained, which is only an example and not specifically limited here.
[0060] As an optional implementation manner, generating a check statement of the initial query statement based on the attribute information includes: 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 field are extracted from the attribute information. Optionally, based on determining the attribute information, this embodiment can extract the type, structure and field of the data table acted on 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 acted upon by the operation corresponding to the initial query statement as the content that needs to be satisfied by the check statement, thereby generating a check statement that satisfies the above structure and fields.
[0063] Optionally, based on the extracted types, structures and fields, the types, structures and fields of the data table acted upon 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 types, structures and fields. This is only an example and is not specifically limited.
[0064] As an optional implementation method, step S204 determines a target detection result of the initial query statement based on the first initial detection result and the second initial detection result, including: in response to the first initial detection result indicating that the initial query statement is an abnormal query statement, and the possibility degree indicated by the second initial detection result is greater than or equal to the target possibility degree, determining that the target detection result is that the initial query statement 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 possibility degree indicated by the second initial detection result is less than the target possibility degree, determining that the target detection result is that the initial query statement does not need to be corrected.
[0065] In this embodiment, after using the check statement to perform sentence detection on the initial query statement to obtain the first initial detection result, and inputting the initial query statement into the target sentence detection model for sentence detection to obtain the 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 degree of possibility indicated by the second initial detection result is greater than or equal to the target degree of possibility, it is determined that the target detection result is that the initial query statement needs to be corrected. Optionally, in this embodiment, based on obtaining the first initial detection result and the second initial detection result, if the first initial detection result indicates that the initial query statement is an abnormal query statement, and the degree of possibility indicated by the second initial detection result is greater than or equal to the target degree of possibility, then 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 degree of possibility indicated by the second initial detection result being greater than or equal to the target degree of possibility, thereby determining that the target detection result is that the initial query statement needs to be corrected.
[0066] In this embodiment, after using the check statement to perform sentence detection on the initial query statement to obtain the first initial detection result, and inputting the initial query statement into the target sentence detection model for sentence detection to obtain the 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 degree of possibility indicated by the second initial detection result is less than the target degree of possibility, it is determined that the target detection result is that the initial query statement does not need to be corrected. Optionally, in this embodiment, based on obtaining the first initial detection result and the second initial detection result, if the first initial detection result indicates that the initial query statement is a normal query statement, and the degree of possibility indicated by the second initial detection result is less than the target degree of possibility, then 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 degree of possibility indicated by the second initial detection result being less than the target degree of possibility, thereby determining that the target detection result is that the initial query statement does not need to be corrected.
[0067] As an optional implementation mode, the method also includes: in response to the first initial detection result indicating that the initial query statement is an abnormal query statement, and the second initial detection result indicates that the possibility degree is less than the target possibility degree, running the initial query statement and detecting the running status of the initial query statement; or, in response to the first initial detection result indicating that the initial query statement is a normal query statement, and the second initial detection result indicates that the possibility degree is greater than or equal to the target possibility degree, running the initial query statement and detecting the running status; in response to the detected running status being a normal running status, determining that the target detection result is that the initial query statement does not need to be corrected; in response to the detected running status being an abnormal running status, determining that the target detection result is that the initial query statement needs to be corrected.
[0068] In this embodiment, in response to the first initial detection result indicating that the initial query statement is an abnormal query statement, and the second initial detection result indicating that the degree of possibility is less than the target degree of possibility, the initial query statement is run, and the running state of the initial query statement is detected. Optionally, in this embodiment, based on obtaining the first initial detection result and the second initial detection result, if the first initial detection result indicates that the initial query statement is an abnormal query statement, and the degree of possibility indicated by the second initial detection result is less than the target degree of possibility, it means that the content of the initial query statement indicated by the first initial detection result as an abnormal query statement does not correspond to the content of the degree of possibility indicated by the second initial detection result less than the target degree of possibility, and the initial query statement is run, and the running state of the initial query statement is detected.
[0069] In this embodiment, in response to the first initial detection result indicating that the initial query statement is a normal query statement, and the second initial detection result indicating that the degree of possibility is greater than or equal to the target degree of possibility, the initial query statement is run, and the running state is detected. Optionally, in this embodiment, based on obtaining the first initial detection result and the second initial detection result, if the first initial detection result indicates that the initial query statement is a normal query statement, and the degree of possibility indicated by the second initial detection result is greater than or equal to the target degree of possibility, it means that the content of the initial query statement indicated by the first initial detection result as a normal query statement does not correspond to the content of the degree of possibility indicated by the second initial detection result as greater than or equal to the target degree of possibility, the initial query statement is run, and the running state of the initial query statement is detected.
[0070] In this embodiment, after detecting the running state, in response to the detected running state being a normal running state, it is determined that the target detection result is that the initial query statement does not need to be modified. Optionally, based on the detected running state, the embodiment determines the relationship between the detected running state and the normal running state and the abnormal running state. If it is determined that the detected running state is a normal running state, it can be determined that the target detection result is that the initial query statement does not need to be modified.
[0071] In this embodiment, after detecting the running state, in response to the detected running state being an abnormal running state, it is determined that the target detection result is that the initial query statement needs to be corrected. Optionally, based on the detected running state, the embodiment determines the relationship between the detected running state and the normal running state and the abnormal running state. If it is determined that the detected running state is an abnormal running state, it can be determined that the target detection result is that the initial query statement needs to be corrected.
[0072] In an embodiment of the present invention, when detecting a database statement, at least one initial query statement in the initial query statement set of the target database can be determined, and a check statement for the initial query statement can be generated. The generated check statement is used to perform statement detection on the initial query statement, and a first initial detection result can be obtained. The initial query statement is input into the target statement detection model for statement detection, and a second initial detection result can be obtained. Based on the determined first initial detection result and the second initial detection result, a target detection result of the initial query statement can be determined, thereby achieving the purpose of avoiding data pollution in the production environment, thereby solving the technical problem of a large number of patches required, and further achieving the technical effect of reducing the number of patches required.
[0073] The technical solution of the embodiment of the present invention is illustrated below in conjunction with preferred implementation modes.
[0074] In the process of checking database query statements, actual installation is often used to check whether the version package needs to be revised. However, such a detection method often needs to support business function testing. Moreover, if the test environment fails to intercept the version package that needs to be revised and allows the version package to flow into production, it will cause data pollution in the production environment, resulting in a large number of technical problems such as the demand for patches.
[0075] In order to solve the above technical problems, an embodiment of the present invention proposes a method for detecting database statements. On the basis of determining at least one initial query statement in the initial query statement set of the target database, a check statement of the statement is generated, and the initial query statement is detected using the generated check statement to obtain a first initial detection result, and 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 above two detection results, the target detection result of the initial query statement can be determined, thereby achieving the purpose of avoiding data pollution in the production environment, thereby solving the technical problem of a large demand for patches, and further achieving the technical effect of reducing the demand for patches.
[0076] In this embodiment, by detecting whether the database statement needs to be modified, it can be determined whether the initial query statement needs to be modified. For example, Figure 3 is a flow chart of a method for detecting whether a database statement needs to be corrected according to an embodiment of the present invention. 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, and a check statement for the SQL statement can be generated.
[0078] In the technical solution provided in the above step S301 of the present invention, the structure and fields of the data table operated by the SQL statement are parsed, for example, the structure of the data table operated by the insert (INSERT) statement is parsed, or the field name of the set (SET) keyword in the data table operated by the update (UPDATE) statement is parsed. This is only an example for illustration and is not specifically limited.
[0079] After generating the check statement of the SQL statement, proceed to step S302 and step S303, perform statement detection on the initial query statement according to the generated check statement to obtain a first initial detection result, and input the SQL statement into a target statement detection model generated based on artificial intelligence for statement detection, so as to obtain the possibility of needing to correct the SQL statement.
[0080] In the technical solution provided in the above step S302 of the present invention, it can be determined from the obtained first initial detection result whether there are structures and fields of data tables that meet the conditions in the specified database. 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 are structures and fields of data tables that meet the conditions in the specified database, and if the first initial detection result indicates that the initial query statement is an abnormal query statement, it can be determined that there are structures and fields of data tables that do not meet the conditions in the specified database.
[0081] In this embodiment, while determining whether there is a data table structure and fields that meet the conditions in the specified database, it is extended to detect the data type in the update field and detect whether the type of the corresponding field in the database matches.
[0082] After obtaining the first initial detection result and the possibility that the SQL statement needs to be corrected, the process proceeds to step S304 to determine the target detection result of the initial query statement based on the obtained first initial detection result and the possibility.
[0083] In the technical solution provided in the above step S304 of the present invention, if the first initial detection result obtained is that the initial query statement is an abnormal query statement, and the degree of possibility is greater than or equal to the target degree of possibility, it can be determined that the target detection result of the initial query statement is that the initial query statement needs to be corrected; if the first initial detection result obtained is that the initial query statement is a normal query statement, and the degree of possibility is less than the target degree of possibility, it can be determined that the target detection result of the initial query statement is 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, and a check statement of the initial query statement can be generated. The generated check statement is used to perform statement detection on the initial query statement, and a first initial detection result can be obtained. The initial query statement is input into the target statement detection model for statement detection, and a second initial detection result can be obtained. According to the determined first initial detection result and the second initial detection result, the target detection result of the initial query statement can be determined, thereby achieving the purpose of avoiding data pollution in the production environment, thereby solving the technical problem of a large number of patches required, and further achieving the technical effect of reducing the number of patches required.
[0085] According to an embodiment of the present invention, a database statement detection device is also provided. It should be noted that the database statement detection device can be used to execute a database statement detection method in the embodiment.
[0086] Figure 4 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 determination unit 401 , a generation unit 402 , a detection unit 403 and a second determination unit 404 .
[0087] The first determining unit 401 is configured to determine at least one initial query statement in an initial query statement set of a target database, wherein the initial query statement is used to represent a query statement to be detected.
[0088] The generating unit 402 is used to generate a checking statement of the initial query statement.
[0089] The detection unit 403 is used to use the check statement to perform statement detection on the initial query 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, wherein the first initial detection result is used to represent the relationship between the initial query statement and the normal query statement and the abnormal query statement, 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, the sample query statement is used to represent the sample query statement to be subjected to statement detection, and the second initial detection result is used to represent the possibility that the initial query statement needs to be corrected.
[0090] The second determining unit 404 is configured to determine 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 to indicate whether the initial query statement needs to be modified.
[0091] Optionally, the generation unit 402 may include: a first determination module, used to determine the attribute information of the operation corresponding to the initial query statement, wherein the attribute information at least includes the structure and fields of the data table on which the operation acts, and the target database includes the data table; a generation module, used to generate a check statement for the initial query statement based on the attribute information.
[0092] Optionally, the first determination module may include: an analysis submodule, configured to perform semantic analysis on the initial query statement to obtain attribute information.
[0093] Optionally, the generation module may include: an extraction submodule, used to extract the structure and fields from the attribute information; and a generation submodule, used to generate a check statement that satisfies the structure and fields.
[0094] Optionally, the second determination unit 404 may include: a second determination module, used to determine that the target detection result is that the initial query statement 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 possibility degree represented by the second initial detection result is greater than or equal to the target possibility degree; a third determination module, used to determine that the target detection result is that the initial query statement 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 possibility degree represented by the second initial detection result is less than the target possibility degree.
[0095] Optionally, the database statement detection device 400 may also include: a first detection unit, used to run the initial query statement and detect the running status of the initial query statement in response to the first initial detection result indicating that the initial query statement is an abnormal query statement, and the possibility degree indicated by the second initial detection result is less than the target possibility degree; or, in response to the first initial detection result indicating that the initial query statement is a normal query statement, and the possibility degree indicated by the second initial detection result is greater than or equal to the target possibility degree, run the initial query statement and detect the running status; a third determination unit, used to determine that the target detection result is that the initial query statement does not need to be corrected in response to the detected running status being a normal running status; a fourth determination unit, used to determine that the target detection result is that the initial query statement needs to be corrected in response to the detected running status being an abnormal running status.
[0096] In this embodiment, the following units are deployed in the detection device of the database statement: a first determination unit, 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 tested; a generation unit, used to generate a check statement of the initial query statement; a detection unit, used to use the check statement to perform statement detection on the initial query 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, wherein the first initial detection result is used to represent the relationship between the initial query statement and the normal query statement and the abnormal query statement, and the target statement detection model The invention is obtained by training an initial statement detection model based on a sample query statement set, wherein the sample query statement set includes at least one sample query statement, the sample query statement is used to represent the sample query statement to be detected, and the second initial detection result is used to represent the possibility of correcting the initial query statement; the second determination 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 represent whether the initial query statement needs to be corrected, thereby achieving the purpose of avoiding data pollution in the production environment, thereby solving the technical problem of a large demand for patches, and further achieving the technical effect of reducing the demand for patches.
[0097] It should be noted that the first determination unit 401, the generation unit 402, the detection unit 403 and the second determination unit 404 correspond to steps S201 to S204 in the embodiment, and the four units and the corresponding steps implement the same examples and application scenarios, but are not limited to the contents disclosed in the above embodiment. It should be noted that the above modules or units can be hardware components or software components stored in a memory (e.g., memory 104) and processed by one or more processors (e.g., processors 102a, 102b, ..., 102n), and the above modules can also be part of the device and can be run in the computer terminal 10 provided in the first embodiment.
[0098] An embodiment of the present application may provide an electronic device, Figure 5 is a structural block diagram of an electronic device according to an embodiment of the present application. Figure 5 As shown, the electronic device 500 may include: one or more ( Figure 5 (only one is shown) processor 502, memory 504, storage controller 506, and peripheral interface 508, wherein the peripheral interface 508 is connected to the RF module 5101, the audio module 5102 and the display 5103.
[0099] Among them, the memory can be used to store software programs and modules, such as program instructions / modules corresponding to the methods and devices in the embodiments of the present application, and the processor executes various functional applications and data processing by running the software programs and modules stored in the memory, that is, realizing the above-mentioned method. The memory may include a high-speed random access memory, and may also include a 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 a memory remotely arranged relative to the processor, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0100] The processor can call the information and application stored in the memory through the transmission device to perform the following steps: 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 subjected to statement detection; generate a check statement for the initial query statement; use the check statement to perform statement detection on the initial query 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 is used to represent the relationship between the initial query statement and the normal query statement and the abnormal query statement, and the target statement detection model is obtained by training the initial statement detection model based on the sample query statement set, the sample query statement set includes at least one sample query statement, the sample query statement is used to represent the sample query statement to be subjected to statement detection, and the second initial detection result is used to represent the possibility that the initial query statement needs to be corrected; 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.
[0101] The processor can also call the information and application stored in the memory through the transmission device to perform the following steps: determine the attribute information of the operation corresponding to the initial query statement, wherein the attribute information at least includes the structure and fields of the data table on which the operation acts, and the target database includes the data table; based on the attribute information, generate a check statement for the initial query statement.
[0102] The processor may also call the information and application programs stored in the memory through the transmission device to execute the following steps: semantically analyzing the initial query statement to obtain attribute information.
[0103] The processor can also call the information and application program stored in the memory through the transmission device to perform the following steps: extracting the structure and field from the attribute information; and generating a check statement that satisfies the structure and field.
[0104] The processor can also call the information and application stored in the memory through the transmission device to perform the following steps: in response to the first initial detection result indicating that the initial query statement is an abnormal query statement, and the second initial detection result indicates that the possibility degree is greater than or equal to the target possibility degree, determine that the target detection result is that the initial query statement 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 second initial detection result indicates that the possibility degree is less than the target possibility degree, determine that the target detection result is that the initial query statement does not need to be corrected.
[0105] The processor can also call the information and application stored in the memory through the transmission device to perform the following steps: in response to the first initial detection result indicating that the initial query statement is an abnormal query statement, and the second initial detection result indicates that the possibility degree is less than the target possibility degree, run the initial query statement and detect the running status of the initial query statement; or, in response to the first initial detection result indicating that the initial query statement is a normal query statement, and the second initial detection result indicates that the possibility degree is greater than or equal to the target possibility degree, run the initial query statement and detect the running status; in response to the detected running status being a normal running status, determine that the target detection result is that the initial query statement does not need to be corrected; in response to the detected running status being an abnormal running status, determine that the target detection result is that the initial query statement needs to be corrected.
[0106] In an embodiment of the present invention, when detecting a database statement, at least one initial query statement in the initial query statement set of the target database can be determined, and a check statement for the initial query statement can be generated. The generated check statement is used to perform statement detection on the initial query statement, and a first initial detection result can be obtained. The initial query statement is input into the target statement detection model for statement detection, and a second initial detection result can be obtained. Based on the determined first initial detection result and the second initial detection result, a target detection result of the initial query statement can be determined, thereby achieving the purpose of avoiding data pollution in the production environment, thereby solving the technical problem of a large number of patches required, and further achieving the technical effect of reducing the number of patches required.
[0107] Figure 5 is a structural block diagram of an electronic device according to an embodiment of the present application. A person skilled in the art can understand that Figure 5 The structure shown is for illustration only, and the electronic device may also be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a PDA, a mobile Internet device (Mobile Internet Devices, MID), a PAD, or other terminal devices. Figure 5 The structure of the electronic device is not limited. Figure 5 More or fewer components (such as network interfaces, display devices, etc.) shown in, or having Figure 5 Different configurations shown.
[0108] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device through a program, and the program can be stored in a computer-readable storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc.
[0109] According to an embodiment of the present invention, a processor is further provided. The processor is used to run a program, wherein the program executes the method for detecting database statements in the embodiment when the program is run by the processor.
[0110] According to an embodiment of the present invention, there is further provided an electronic device, comprising: a memory storing an executable program; and a processor for running the program, wherein the method for detecting database statements in the embodiment is executed when the program is running.
[0111] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute the database statement detection method in the embodiment.
[0112] According to an embodiment of the present invention, a computer program product is further provided. The computer program product includes a computer program. When the computer program is executed by a processor, the method for detecting a database statement in the embodiment is implemented.
[0113] According to an embodiment of the present invention, a computer program product is also provided, including a non-volatile computer-readable storage medium, the non-volatile computer-readable storage medium is used to store a computer program, and when the computer program is executed by a processor, the database statement detection method in the embodiment is implemented.
[0114] According to an embodiment of the present invention, a computer program is also provided. When the computer program is executed by a processor, the method for deploying a task instance in a disaster recovery environment in the embodiment is implemented.
[0115] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0116] In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made 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. Among them, the device embodiments described above are only schematic. For example, the division of units can be a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0118] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed over multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0119] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0120] If the integrated unit is implemented in the form of 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 the present invention, or the part that contributes to the relevant technology or the whole or part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the methods of each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, referred to as Read-Only Memory), random access memory (RAM, referred to as RandomAccess Memory), mobile hard disk, magnetic disk or optical disk, etc. Various media that can store program codes.
[0121] The above are only preferred embodiments of the present invention. It should be pointed out that, for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A method for detecting a database statement, characterized in that: include: 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 tested; Generating a check statement of the initial query statement; Using the inspection statement, the initial query statement is subjected to statement detection to obtain a first initial detection result, and the initial query statement is input into a target statement detection model for statement detection to obtain a second initial detection result, wherein the first initial detection result is used to represent the relationship between the initial query statement and normal query statements 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, the sample query statement is used to represent a sample query statement to be subjected to statement detection, and the second initial detection result is used to represent the possibility of needing to correct the initial query statement; Based on the first initial detection result and the second initial detection result, a 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 modified.
2. The method according to claim 1, characterized in that Generating a check statement of the initial query statement includes: Determine the attribute information of the operation corresponding to the initial query statement, wherein the attribute information at least includes the structure and fields of the data table on which the operation acts, and the target database includes the data table; Based on the attribute information, a check statement of the initial query statement is generated.
3. The method according to claim 2, characterized in that Determining the attribute information of the operation corresponding to the initial query statement includes: The initial query statement is semantically analyzed to obtain the attribute information.
4. The method according to claim 2, characterized in that: Generating a check statement of the initial query statement based on the attribute information includes: Extracting the structure and the field from the attribute information; The check statement satisfying the structure and the field is generated.
5. The method according to claim 1, characterized in that Determining a target detection result of the initial query statement based on the first initial detection result and the second initial detection result includes: In response to the first initial detection result indicating that the initial query statement is the abnormal query statement, and the possibility degree indicated by the second initial detection result is greater than or equal to a target possibility degree, determining that the target detection result indicates 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 possibility degree indicated by the second initial detection result is less than the target possibility degree, it is determined that the target detection result does not require the initial query statement to be modified.
6. The method according to claim 5, characterized in that The method further comprises: In response to the first initial detection result indicating that the initial query statement is the abnormal query statement, and the possibility degree indicated by the second initial detection result is less than the target possibility degree, running the initial query statement and detecting the running state of the initial query statement; or, In response to the first initial detection result indicating that the initial query statement is the normal query statement, and the possibility degree indicated by the second initial detection result is greater than or equal to the target possibility degree, running the initial query statement and detecting the running state; In response to the detected operating state being a normal operating state, determining that the target detection result is that the initial query statement does not need to be modified; In response to the detected operating state being an abnormal operating state, determining that the target detection result is that the initial query statement needs to be corrected.
7. A database statement detection device, characterized in that: 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 is used to represent a query statement to be detected; A generating unit, used to generate a check statement of the initial query statement; a detection unit, configured to perform sentence detection on the initial query sentence using the check sentence to obtain a first initial detection result, and input the initial query sentence into a target sentence detection model to perform sentence detection to obtain a second initial detection result, wherein the first initial detection result is used to represent the relationship between the initial query sentence and normal query sentences and abnormal query sentences, the target sentence detection model is obtained by training the initial sentence detection model based on a sample query sentence set, the sample query sentence set includes at least one sample query sentence, the sample query sentence is used to represent a sample query sentence to be sentence detected, and the second initial detection result is used to represent the possibility of needing to correct the initial query sentence; The second determining unit is used to determine 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 to indicate whether the initial query statement needs to be modified.
8. A processor, characterized in that: The processor is used to run a program, wherein the program, when run by the processor, executes the method for detecting a database statement according to any one of claims 1 to 6.
9. An electronic device, characterized in that: include: A memory storing an executable program; A processor is used to run the program, wherein the program executes the method for detecting database statements according to any one of claims 1 to 6 when running.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored executable program, wherein when the executable program is run, the device where the storage medium is located is controlled to execute the database statement detection method described in any one of claims 1 to 6.
Citation Information
Patent Citations
AST-based source code anomaly detection method and device
CN115146282A
Grammar checking method and system for SQL (Structured Query Language) statement, electronic equipment and readable storage medium
CN116149666A
Structured query statement detection method and device, equipment and medium
CN117216095A
Query detection method and related device
CN117371041A
Detecting logical relationships based on structured query statements
US20170249361A1