Database code detection method and device, equipment and medium
By automatically detecting structured query statements in the code submission pipeline, the problem of low efficiency and poor accuracy of code review during database upgrades is solved, achieving efficient and accurate code file detection and reducing operational complexity and cost.
Patent Information
- Application Number
- CN202511618819.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-06
- Publication Date
- 2026-02-03
AI Technical Summary
During the database upgrade and transformation process, developers are unable to quickly understand the characteristics and syntax rules of the new database, resulting in bad structured query code that does not conform to development standards flowing into the test environment and even the production environment. The existing manual review is inefficient and prone to errors.
By acquiring code files from the code submission pipeline, extracting structured query statements, and performing detection according to preset detection rules, the system generates detection results and determines whether to intercept the code file submission process, ensuring that the code conforms to the specifications of the new database.
It improves the efficiency and accuracy of code inspection, reduces the coupling of manual review and the complexity of operation and maintenance, ensures that code files comply with specifications before submission, and reduces errors and vulnerabilities.
Smart Images

Figure CN121455822A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of Internet technology, and in particular to a database code detection method, apparatus, device, and medium. Background Technology
[0002] During the database upgrade and transformation process, developers are unable to quickly understand and master the characteristics and syntax rules of the new database, resulting in a large amount of bad structured query code that does not conform to development standards flowing into the test environment, and even into the production environment, causing production incidents.
[0003] Currently, code review is primarily done manually, with designers reviewing and verifying each piece of code submitted by developers. Manual review requires a significant investment of time and effort, and it is inevitably prone to errors and omissions. Furthermore, reviewers need a certain level of technical expertise, and the project is heavily reliant on manual efficiency; low manual efficiency can lead to project stagnation. Summary of the Invention
[0004] This invention provides a database code detection method, apparatus, device, and medium, which can improve the efficiency and accuracy of code detection.
[0005] According to one aspect of the present invention, an embodiment of the present invention provides a database code detection method, the method comprising:
[0006] Retrieve the code file to be inspected sent by the code submission pipeline system;
[0007] Extract at least one structured query statement from the code file to be detected;
[0008] According to the preset detection rules, each of the structured query statements is detected to obtain the detection results of each of the structured query statements;
[0009] Based on the detection results of each structured query statement, the detection result of the code file is determined. The detection result of the code file is used by the code submission pipeline system to determine whether to intercept the submission process of the code file.
[0010] According to another aspect of the present invention, embodiments of the present invention also provide a database code detection device, the device comprising:
[0011] The file acquisition module is used to acquire the code files to be inspected sent by the code submission pipeline system;
[0012] The statement extraction module is used to extract at least one structured query statement from the code file to be detected;
[0013] The statement detection module is used to detect each of the structured query statements according to preset detection rules, and obtain the detection results of each of the structured query statements;
[0014] The interception judgment module is used to determine the detection result of the code file based on the detection results of each structured query statement. The detection result of the code file is used by the code submission pipeline system to determine whether to intercept the submission process of the code file.
[0015] According to another aspect of the present invention, embodiments of the present invention also provide a database code detection device, the database code detection device comprising:
[0016] At least one processor; and
[0017] A memory that is communicatively connected to at least one processor; wherein,
[0018] The memory stores a computer program that can be executed by at least one processor, such that the at least one processor is able to execute the database code detection method of any embodiment of the present invention.
[0019] According to another aspect of the present invention, a computer-readable storage medium is provided, which stores computer instructions for causing a processor to execute and implement the database code detection method of any embodiment of the present invention.
[0020] According to another aspect of the present invention, a computer program product is provided, the computer program product comprising a computer program that, when executed by a processor, implements the database code detection method according to any embodiment of the present invention.
[0021] The technical solution of this invention obtains code files circulating in the code submission pipeline, extracts structured query statements from the code files, performs anomaly detection, obtains the detection results of the code files, and feeds the detection results of the code files back to the code submission pipeline. The code submission pipeline determines whether to intercept the code files. If the code files are intercepted before submission, it ensures that the submitted code files are correct. This solves the problems of poor accuracy and low efficiency in manual review of code files in the prior art. It can insert code file detection into the code submission pipeline, improve the detection efficiency of code files, and improve the accuracy of submitted code files. Moreover, it is independent of the code submission pipeline system, which can reduce the coupling between the code submission pipeline and code review, and reduce the operational complexity and cost of code detection.
[0022] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0023] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0024] Figure 1 This is a flowchart of a database code detection method provided according to an embodiment of the present invention;
[0025] Figure 2 This is a flowchart of a database code detection method provided according to an embodiment of the present invention;
[0026] Figure 3 This is a timing diagram of a database code detection method provided according to an embodiment of the present invention;
[0027] Figure 4 This is a structural diagram of a database code detection device according to an embodiment of the present invention;
[0028] Figure 5 This is a schematic diagram of the structure of a database code detection device provided in an embodiment of the present invention. Detailed Implementation
[0029] 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.
[0030] 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.
[0031] The acquisition, storage, and application of driving trajectory points and other related technologies in the technical solutions of this invention comply with relevant laws and regulations and do not violate public order and good morals.
[0032] Figure 1 This is a flowchart illustrating a database code detection method provided in an embodiment of the present invention. This embodiment is applicable to situations where database code detection is performed on code files ready for submission in a code submission pipeline. The method can be executed by a database code detection device, which can be implemented in hardware and / or software.
[0033] See Figure 1 The database code detection methods shown include:
[0034] S101. Obtain the code file to be inspected sent by the code submission pipeline system.
[0035] The code submission pipeline is a fully automated system that handles the entire process from code development and submission to final deployment. Specifically, it describes the deployment process through code, linking each stage of software development (building, testing, and deployment, etc.) into an automated pipeline. The code submission pipeline system calls the external interface of the code inspection server, sending the code files to be inspected to the server. The code inspection server is a server that implements database code inspection methods.
[0036] The code file to be detected can refer to a code file that has been developed in the code submission pipeline but has not yet been submitted. The code file can also refer to files required for application deployment. In this embodiment of the invention, the code detection server is mainly used to detect the code files of the database. Specifically, the code file can refer to a code file that meets the development specifications of the new database. This is especially important for scenarios involving changes from an old database to new data, where code files are developed specifically for the new database's development specifications.
[0037] S102. Extract at least one structured query statement from the code file to be detected.
[0038] Structured query statements are used for querying, defining, and controlling data in a database. A structured query statement can refer to statements in the Structured Query Language (SCL). SCL is a database query and programming language used to access, query, update, and manage relational database systems.
[0039] In an optional embodiment, at least one structured query statement is extracted from the code file to be detected, including: extracting at least one structured query statement from the code file to be detected based on the statement's start and end key information.
[0040] The key information at the beginning and end of a statement refers to the information that identifies the start and end of a structured query statement. This key information can include keywords and end flags. Structured query statements can be parsed and extracted from code files based on this key information.
[0041] S103. According to the preset detection rules, each of the structured query statements is detected to obtain the detection results of each of the structured query statements.
[0042] The detection rules can refer to rules established based on the development and coding specifications of the new database. These rules are used to detect structured queries. Each structured query can be detected independently or jointly. Joint detection involves using adjacent structured queries as the context of the query to be detected, and then performing the detection on that query to obtain the detection result. The detection result of a structured query can include whether it violates a rule. In some embodiments, the detection result may also include a risk level and / or optimization suggestions.
[0043] The structured query statements extracted from the code file are subjected to rule detection one by one. Each structured query statement is detected using each detection rule, and the detection result for each structured query statement is obtained for each detection rule.
[0044] In some embodiments, the detection rule could be: prohibit the selection of *, and explicitly list the fields. Another example is: prohibit unconditional queries, updates, and deletions, requiring additional conditions. Yet another example is: capitalize key fields. And yet another example is: primary key example: XX.
[0045] In some embodiments, the detection rule is configured with at least one decision branch, and each branch has a corresponding risk level and optimization suggestion. When the detection result of the code file is interception, the optimization suggestion corresponding to the violated rule is determined based on the rule violated and the corresponding risk level in the detection results of each structured query statement; the optimization suggestion is then added to the detection result of the code file.
[0046] S104. Based on the detection results of each structured query statement, determine the detection result of the code file. The detection result of the code file is used by the code submission pipeline system to determine whether to intercept the submission process of the code file.
[0047] Specifically, the detection results of the code file are determined based on the detection results of the structured query statements in the code file. Subsequent commits to the code file can be made by submitting it to the code repository.
[0048] In some embodiments, the detection result of the code file can be the detection result of each structured query statement for each detection rule. The code submission pipeline determines the pipeline decision result based on the detection result of the code file, which can be pass or fail. Alternatively, the pipeline decision result can be block or not block.
[0049] In some embodiments, the detection result of a code file can be either pass or fail. Alternatively, the detection result can be either block or not block. A pass or not block result indicates that the code file can proceed with subsequent submissions and deployments. A fail or block result indicates that the code file cannot proceed with subsequent submissions and deployments and requires optimization and improvement.
[0050] In some embodiments, based on the detection results of each structured query statement, if at least one detection result indicates a rule violation, the code file is determined to be blocked or rejected. If none of the structured query statements are detected as violating the rules, the code file is determined to be neither blocked nor rejected.
[0051] In some embodiments, the number of rule violations can be counted, or a weighted score can be calculated based on the weight of the violated rule to determine whether the code file is blocked or fails the detection.
[0052] When the code submission pipeline system receives the detection results of a code file, it parses the results. If the detection result is an interception, the code submission pipeline system blocks the subsequent code submission process and prompts the developer. The developer modifies the code file. The modified code file re-enters the code submission pipeline system. The code submission pipeline system sends the modified code file to the code detection server for re-detection: extracting at least one structured query statement from the modified code file; detecting each structured query statement according to preset detection rules, obtaining the detection results of each structured query statement; determining the detection result of the modified code file based on the detection results of each structured query statement; the modified code file is fed back to the code submission pipeline system for another determination on whether to submit. If interception is still required, the detection process is repeated; if interception is not required, the code submission pipeline system submits the modified code file to the code repository so that the new database system can run the modified code file.
[0053] In some embodiments, if the modified code has issues, the code submission pipeline system will block the submission. Users can be provided with a query function for the detection results, which can display the violated rules, the corresponding risk level, and rectification suggestions. Simultaneously, the corresponding detection results can also be viewed on the code detection server, showing whether rules were violated, the violated rules, the corresponding risk level, and optimization suggestions.
[0054] The technical solution of this invention obtains code files circulating in the code submission pipeline, extracts structured query statements from the code files, performs anomaly detection, obtains the detection results of the code files, and feeds the detection results of the code files back to the code submission pipeline. The code submission pipeline determines whether to intercept the code files. If the code files are intercepted before submission, it ensures that the submitted code files are correct. This solves the problems of poor accuracy and low efficiency in manual review of code files in the prior art. It can insert code file detection into the code submission pipeline, improve the detection efficiency of code files, and improve the accuracy of submitted code files. Moreover, it is independent of the code submission pipeline system, which can reduce the coupling between the code submission pipeline and code review, and reduce the operational complexity and cost of code detection.
[0055] In an optional embodiment, determining the detection result of the code file based on the detection results of each of the structured query statements includes: determining whether to intercept the code file based on the rules violated and the corresponding risk level in the detection results of each of the structured query statements, thereby obtaining the detection result of the code file.
[0056] The detection results for structured query statements include whether they violate rules and the risk level corresponding to the violated rules. The detection results for the code file can be determined based on the risk level corresponding to the violated rules.
[0057] In some embodiments, if a high-risk detection result exists in the violated rules, the code file is determined to be blocked. If only low-risk detection results exist in the rules within the scope, the code file is determined not to be blocked. For example, if the number of high-risk detection results in the violated rules exceeds a preset threshold, the code file is determined to be blocked. If only low-risk detection results exist in the rules within the scope, or the number of high-risk detection results is less than or equal to a preset threshold, the code file is determined not to be blocked. Other situations may also exist, which can be determined based on the business scenario.
[0058] As can be seen, by combining the rules violated in the detection results with the risk level of the violated rules, it is possible to determine whether to block the code file. This allows for fine-grained control over whether to block the code file and flexible adjustments to be made to suit specific scenarios.
[0059] In an optional embodiment, obtaining the code file to be detected sent by the code submission pipeline system includes: obtaining candidate files sent by the code submission pipeline system; filtering out code files with target characters based on the file extensions of each candidate file as the code file to be detected; the target characters correspond to code files of the Structured Query Language type.
[0060] In this system, the code submission pipeline sends at least one candidate file. The code inspection server filters these candidate files to obtain code files of the Structured Query Language (SQL) type. The code inspection server is primarily used to detect structured query statements within the SQL code files. Therefore, code files lacking structured query statements are not the inspection targets of this embodiment. The target character can refer to key content in the filename of the SQL code file. For example, the target character could be ".sql".
[0061] In some embodiments, the code submission pipeline aspect utilizes a code review component deployed within the code submission pipeline. The code review component extracts the manifest of the submitted code. Based on the manifest, the code submission pipeline system retrieves the source code files (code files) from the corresponding directory on the pipeline server. It then compresses and packages all filtered code files and sends the compressed code to the code detection server via an application programming interface (API). The code submission pipeline system awaits the return of detection results for each code file. Upon receiving the code detection request, the code detection server decompresses the transmitted data packet and filters the program files for structured query languages based on their file extensions.
[0062] In some embodiments, the code review component in the code submission pipeline can filter program files in the program manifest, specifically filtering program files for structured query languages based on their file extensions. The code submission pipeline system then retrieves the code files from the corresponding directory on the code submission pipeline server based on the filtered program manifest, thus reducing the transmission of redundant data. The code inspection server performs a secondary screening of the program files, further reducing missed detections.
[0063] The code submission pipeline system extracts the code files to be checked through the review component in the code submission pipeline aspect and initiates the code checking task through application programming interface calls.
[0064] It is evident that by filtering the candidate files submitted by the code submission pipeline system and only checking code files containing structured query statements, invalid checks can be reduced and code detection efficiency can be improved.
[0065] Figure 2 This is a flowchart illustrating a database code detection method provided by an embodiment of the present invention. Based on the above embodiments, this embodiment of the present invention detects each structured query statement according to preset detection rules to obtain detection results for each structured query statement. Specifically, it involves: for each structured query statement, performing text standardization detection on the structured query statement using a first rule in the detection rules to obtain a first detection result for the structured query statement; obtaining the structure information of the target database; performing performance detection on the structured query statement using a second rule in the detection rules based on the structure information to obtain a second detection result for the structured query statement; and determining the detection result of the structured query statement based on the first detection result and the second detection result.
[0066] It should be noted that for parts not described in detail in the embodiments of the present invention, please refer to the descriptions in other embodiments.
[0067] See Figure 2 The database code detection methods shown include:
[0068] S201. Obtain the code file to be inspected sent by the code submission pipeline system.
[0069] S202. Extract at least one structured query statement from the code file to be detected.
[0070] S203. For each of the structured query statements, the first rule in the detection rules is used to perform text standardization detection on the structured query statements to obtain the first detection result of the structured query statements.
[0071] The first rule is used to perform normative checks on the text content of structured query statements. The first rule typically specifies the correct content format of the structured query statement's syntax and / or incorrect content format. In some embodiments, the first rule is: ending with a semicolon. Another example is: selection statements must use XX connecting conditions. Yet another example is: using the specific character XX as the starting identifier for comments.
[0072] S204. Obtain the structural information of the target database.
[0073] The structural information of the target database refers to its data structure, which may include table structure and indexes. Table structure refers to the layout of tables in the database, defining columns (fields), data types, constraints, and other attributes. An index is a data structure in a database used to accelerate data retrieval operations within a table. Similar to a table of contents in a book, an index helps the database system quickly locate the required data without scanning the entire table.
[0074] In some embodiments, based on the application identifier (such as the application name) in the code submission pipeline and in conjunction with the database management system of the business system, the system obtains the application to which the current code file belongs, as well as the information of the new database in the test environment corresponding to that application; and after authorized login to the database, it obtains the table structure and indexes of that database. The database management system of the business system can be a bank's database ledger management system.
[0075] In some embodiments, the target database may refer to a newly developed, new application, or new interaction database, etc.
[0076] S205. Based on the structural information, the second rule in the detection rules is used to perform performance testing on the structured query statement to obtain the second detection result of the structured query statement.
[0077] The second rule is used to test the query performance of structured query statements. The second rule typically specifies the content that a structured query statement must include and / or the conditions that must be met to execute the query operation.
[0078] S206. Determine the detection result of the structured query statement based on the first detection result and the second detection result of the structured query statement.
[0079] The first detection result of the first rule is determined as the detection result of the structured query statement, and the second detection result of the second rule is determined as the detection result of the structured query statement.
[0080] S207. Based on the detection results of each of the structured query statements, determine the detection result of the code file. The detection result of the code file is used by the code submission pipeline system to determine whether to intercept the submission process of the code file.
[0081] This invention divides the detection rules into a first rule and a second rule. The first rule is used to perform text standardization detection on structured query statements, while the second rule is used to perform performance testing on structured query statements. This achieves multi-dimensional detection of structured query statements, enriches the detection scope, and improves the accuracy of structured query statements.
[0082] In an optional embodiment, the step of performing performance testing on the structured query statement according to the structure information and using the second rule in the detection rules to obtain a second detection result of the structured query statement includes: using the second rule in the detection rules to detect whether the index information existing in the structured query statement belongs to the index information in the structure information, and obtaining a second detection result; and / or using the second rule in the detection rules to detect whether the query content existing in the structured query statement is consistent with the table structure in the structure information, and obtaining a second detection result.
[0083] In this scenario, if a structured query performs a full query, its efficiency is typically low, meaning its performance is poor. The structured query should at least contain indexed information (e.g., key fields). Accordingly, a second rule can be configured based on this scenario. If the structured query is a query function and it lacks indexed information, the second detection result of this second rule is to block. If the structured query is a query function and it contains indexed information, it is further determined whether the existing indexed information belongs to the structured information. The indexed information of the structured query should be searchable in the database, meaning it should belong to the database's indexed information. If the existing indexed information belongs to the structured information, the second detection result of this second rule is to not block; otherwise, the second detection result of this second rule is to block.
[0084] The content of a structured query statement must conform to the table structure in the database. For example, the data type of the key value in a structured query statement should be consistent with the data type of the corresponding key value in the database. If they are inconsistent, the query result will be incorrect. Accordingly, a second rule can be configured based on this scenario. If the structured query statement is a query function and does not contain query content, the second detection result of this second rule is to block it. If the structured query statement is a query function and contains query content, it is further determined whether the existing query content is consistent with the table structure in the structure information. If the query content is inconsistent with the table structure in the structure information, the second detection result of this second rule is to block it. If the query content is consistent with the table structure in the structure information, the second detection result of this second rule is not to block it.
[0085] As can be seen, by configuring the judgment method of the second rule to determine whether the index information existing in the structured query statement belongs to the index information in the structure information, and / or to determine whether the existing query content is consistent with the table structure in the structure information, a second detection result can be obtained. This can refine and enrich the content of the second rule, adapt the judgment of the performance of the structured query statement for different query scenarios, and improve the accuracy of the performance detection of the structured query statement.
[0086] In some embodiments, the database code detection method further includes: generating rule content and risk level based on the development specifications of the new database and / or problem scenarios encountered during code production, and generating detection rules based on the rule content and risk level.
[0087] Specifically, based on the development and coding specifications of the new database for the business system, a set of inspection rules is compiled, and each inspection rule is defined with a risk level based on the severity of the problem it causes. Simultaneously, in conjunction with production issues, corresponding scenarios are refined into inspection rules, enriching and improving the set of inspection rules. The set of inspection rules can be updated in real-time according to specifications and production issues, allowing for the addition, deletion, and modification of inspection rules, as well as the addition, deletion, and modification of risk levels within the inspection rules.
[0088] In an optional embodiment, the database code detection method further includes: obtaining a specification file of a new database; extracting at least one key code element and corresponding specification indication information from the specification file; generating rule content corresponding to each key code element based on the key code element and the corresponding specification indication information; generating a risk level corresponding to the key code element based on the specification indication information; and generating detection rules based on the rule content and risk level corresponding to the key code element.
[0089] The specification document can define the feasibility of code. Key code content can be defined code snippets. Specification instructions can indicate whether a code is feasible or infeasible. In the specification document, code describing the same event can be considered key code content. Feasibility or infeasibility instructions within that content describing the same event can be used as specification instructions for that key code content. The content describing the same event can be text from the same line or paragraph. Alternatively, a pre-trained specification recognition model can be used. The specification document is input into the model, and the output of the model includes key code content and corresponding specification instructions.
[0090] In this context, rule content can refer to instructions indicating whether a piece of code is feasible or not. Key code content and specification instructions work together to generate rule content. Risk level refers to the severity of a violation of a rule. Specification instructions are used to generate the risk level corresponding to the key content. The risk level can be determined based on the intensity of the wording in the specification instructions. For example, "not recommended" corresponds to a low risk level, while "prohibited" corresponds to a high risk level. A pre-defined correspondence between different specification instructions and different risk levels can be established, and the risk level can be determined based on this correspondence.
[0091] A detection rule is defined as the rule content corresponding to a key piece of code, along with the risk level of the corresponding specification instruction information. Additionally, developers or operations users can configure optimization suggestions for the detection rule and add them to the rule.
[0092] It is evident that by extracting key code content and corresponding specification instructions from specification documents, and generating specification content and risk levels accordingly, rule content and risk levels can be accurately extracted from specification documents. This reduces the complexity and manual cost of rule formulation, improves the efficiency of generating detection rules, and increases the richness of rules by extracting rules from specific content in specification documents.
[0093] In an optional embodiment, the database code detection method further includes: acquiring at least one historical event; acquiring code content corresponding to each historical event; extracting key data based on the code content corresponding to the historical event and generating rule content corresponding to the historical event; acquiring impact data corresponding to the historical event; generating a risk level corresponding to the historical event based on the impact data corresponding to the historical event; and generating detection rules based on the rule content and risk level corresponding to the historical event.
[0094] Historical events can refer to problems encountered during the production, submission, deployment, and release of the database's Structured Query Language (SCL) files. This database can include the new database involved in this embodiment and general databases different from it. The code content corresponding to a historical event can refer to the problematic code content from that historical event. Historical events are essentially checks on the Structured Query Language (SCL) statements, and the check items for historical events include the code content within those statements. The impact data corresponding to a historical event can refer to the impact data resulting from the submission of the problematic code content from that historical event. This impact data describes the degree of adverse effects caused by the problematic code content in the historical event.
[0095] In some embodiments, a code content corresponding to a historical event can be defined as a rule content, and the impact data of that code content can be defined as the risk level of that rule content. A detection rule is determined by combining the rule content and risk level of a code content. Accordingly, at least one detection rule can be generated for each historical event. Multiple historical events can generate redundant detection rules; redundancy removal processing can be performed on the detection rules generated from each historical event to reduce redundant detection rules.
[0096] It is evident that by extracting code content and corresponding impact data from historical events, and generating corresponding standard content and risk levels, rule content and risk levels can be accurately extracted from historical events. This reduces the complexity and manual cost of rule formulation, improves the efficiency of generating detection rules, and allows for continuous iteration and updating of detection rules based on rules extracted from historical events, thereby improving the accuracy of detection rules.
[0097] In a scenario, such as Figure 3As shown, a code submission pipeline system includes at least: an auditing component, an interception and control module, and a result display module. The code detection server includes: a rules module and a code detection module. Correspondingly, database code detection methods include:
[0098] The rules module in the code detection server configures, generates, and retrieves code detection rules, and then sends the detection rules to the code detection module.
[0099] The code review component of the code submission pipeline system retrieves the source files from the pipeline server based on the list of program files to be submitted, and filters the files by file extension and uses a structured query to determine the language type, resulting in at least one code file. The code review component then sends the code file to the code inspection module.
[0100] The code inspection module in the code inspection server receives the code file to be inspected sent by the code review component of the code submission pipeline;
[0101] The code detection module filters the received candidate files based on their file extensions and uses a structured query to find the language type, thus obtaining at least one code file.
[0102] The code inspection module extracts structured query statements based on key information at the beginning and end of the statements.
[0103] The code inspection module obtains the structure information of the test environment database based on the application name and business system of the code file;
[0104] After logging into the database, the code detection module obtains the table structure and / or index information to obtain the database structure information.
[0105] The code inspection module inspects each structured query statement one by one; it uses each inspection rule to inspect each structured query statement, obtains the inspection results for each structured query statement for each inspection rule, integrates them to obtain the inspection results of the code file, and returns the inspection results of the code file to the interception and control module of the code submission pipeline system.
[0106] In the code submission pipeline system, the interception control module determines that there is a serious anomaly based on the detection results of the code file and blocks the code submission process.
[0107] The result display module in the code submission pipeline system can show the detection results of code files, which may include whether rules are violated, the rules violated, the risk level, and optimization suggestions.
[0108] This invention provides a method for detecting structured query statements based on a code submission pipeline. By generating detection rules, initiating detection tasks, detecting structured query statements, interception control, and querying results, it enables rapid code review based on a new type of database, effectively reducing labor costs and technical or business entry barriers.
[0109] Figure 4 This is a schematic diagram of a database code detection device provided in an embodiment of the present invention. The present invention is applicable to situations where database code detection is performed on code files ready for submission in a code submission pipeline. This device can execute a database code detection method and can be implemented in hardware and / or software.
[0110] See Figure 4 The database code detection device shown includes:
[0111] The file acquisition module 401 is used to acquire the code file to be inspected sent by the code submission pipeline system;
[0112] The statement extraction module 402 is used to extract at least one structured query statement from the code file to be detected;
[0113] The statement detection module 403 is used to detect each of the structured query statements according to preset detection rules, and obtain the detection results of each of the structured query statements.
[0114] The interception judgment module 404 is used to determine the detection result of the code file based on the detection results of each of the structured query statements. The detection result of the code file is used by the code submission pipeline system to determine whether to intercept the submission process of the code file.
[0115] The technical solution of this invention obtains code files circulating in the code submission pipeline, extracts structured query statements from the code files, performs anomaly detection, obtains the detection results of the code files, and feeds the detection results of the code files back to the code submission pipeline. The code submission pipeline determines whether to intercept the code files. If the code files are intercepted before submission, it ensures that the submitted code files are correct. This solves the problems of poor accuracy and low efficiency in manual review of code files in the prior art. It can insert code file detection into the code submission pipeline, improve the detection efficiency of code files, and improve the accuracy of submitted code files. Moreover, it is independent of the code submission pipeline system, which can reduce the coupling between the code submission pipeline and code review, and reduce the operational complexity and cost of code detection.
[0116] Optional, statement detection module 403, specifically used for:
[0117] For each of the structured query statements, the first rule in the detection rules is used to perform text standardization detection on the structured query statements to obtain the first detection result of the structured query statements;
[0118] Obtain the structural information of the target database;
[0119] Based on the structural information, the second rule in the detection rules is used to perform performance testing on the structured query statement to obtain the second detection result of the structured query statement;
[0120] The detection result of the structured query statement is determined based on the first detection result and the second detection result of the structured query statement.
[0121] Optional, statement detection module 403, specifically used for:
[0122] Using the second rule in the detection rules, the system detects whether the index information existing in the structured query statement belongs to the index information in the structured information, and obtains a second detection result; and / or
[0123] Using the second rule in the detection rules, the system detects whether the query content in the structured query statement is consistent with the table structure in the structure information, and obtains the second detection result.
[0124] Optionally, the database code detection device may also include:
[0125] The standard rule extraction module is used for:
[0126] Obtain the specification documents for the new database;
[0127] Extract at least one key code element and the corresponding specification instruction information from the specification document;
[0128] For each of the aforementioned key code contents, rule content corresponding to the key code contents is generated based on the key code contents and the corresponding specification instructions;
[0129] The risk level corresponding to the key content of the code is generated based on the specification instructions corresponding to the key content of the code.
[0130] Based on the rule content and risk level corresponding to the key content of the code, detection rules are generated.
[0131] Optionally, the database code detection device may also include:
[0132] The event rule extraction module is used for:
[0133] Obtain at least one historical event;
[0134] For each of the aforementioned historical events, obtain the corresponding code content for that historical event;
[0135] Extract key data from the code content corresponding to the historical events and generate the rule content corresponding to the historical events;
[0136] Obtain the impact data corresponding to the historical events;
[0137] Based on the impact data corresponding to the historical events, a risk level corresponding to the historical events is generated;
[0138] Detection rules are generated based on the rule content and risk level corresponding to the historical events.
[0139] Optional, statement detection module 403, specifically used for:
[0140] Based on the rules violated and the corresponding risk levels in the detection results of each structured query statement, it is determined whether to intercept the code file, and the detection results of the code file are obtained.
[0141] Optional, file acquisition module 401, specifically used for:
[0142] Retrieve alternative files sent by the code submission pipeline system;
[0143] Based on the file extensions of the candidate files, code files containing the target characters are selected as the code files to be detected; the target characters correspond to code files of the Structured Query Language type.
[0144] The database code detection device provided in this embodiment of the invention can execute the database code detection method provided in any embodiment of the invention, and has the corresponding functional modules and beneficial effects for executing the database code detection method.
[0145] Figure 5 A schematic diagram of the structure of a database code detection device 500 that can be used to implement embodiments of the present invention is shown.
[0146] like Figure 5As shown, the database code detection device 500 includes at least one processor 501 and a memory, such as a read-only memory 502 or a random access memory 503, communicatively connected to the at least one processor 501. The memory stores computer programs executable by the at least one processor. The processor 501 can perform various appropriate actions and processes based on the computer program stored in the read-only memory 502 or loaded from the storage unit 508 into the random access memory 503. The random access memory 503 can also store various programs and data required for the operation of the database code detection device 500. The processor 501, read-only memory 502, and random access memory 503 are interconnected via a bus 504. An input / output interface 505 is also connected to the bus 504.
[0147] Multiple components in the database code detection device 500 are connected to the input / output interface 505, including: an input unit 506, such as a keyboard, mouse, etc.; an output unit 507, such as various types of monitors, speakers, etc.; a storage unit 508, such as a disk, optical disk, etc.; and a communication unit 509, such as a network card, modem, wireless transceiver, etc. The communication unit 509 allows the database code detection device 500 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0148] Processor 501 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 501 include, but are not limited to, central processing units, graphics processing units, various special-purpose artificial intelligence computing chips, various processors running machine learning model algorithms, digital signal processors, and any suitable processor, controller, microcontroller, etc. Processor 501 performs the various methods and processes described above, such as database code detection methods.
[0149] In some embodiments, the database code detection method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 508. In some embodiments, part or all of the computer program may be loaded and / or installed onto the database code detection device 500 via read-only memory 502 and / or communication unit 509. When the computer program is loaded into random access memory 503 and executed by processor 501, one or more steps of the database code detection method described above may be performed. Alternatively, in other embodiments, processor 501 may be configured to execute the database code detection method by any other suitable means (e.g., by means of firmware).
[0150] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays, application-specific integrated circuits (ASICs), application-specific standard products (ASICs), systems-on-a-chip (SoCs), complex programmable logic devices, computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0151] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0152] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory, read-only memory, erasable programmable read-only memory, flash memory, optical fiber, portable compact disk read-only memory, optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0153] To provide user interaction, the systems and techniques described herein can be implemented on an operational detection device, which includes: a display device (e.g., a cathode ray tube or liquid crystal monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the database code detection device. Other types of devices can also be used to provide user interaction; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0154] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0155] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a host product within the cloud computing service system. This addresses the shortcomings of traditional physical hosts and virtual private servers, such as high management difficulty and weak business scalability.
[0156] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0157] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A database code detection method, characterized in that, The method includes: Retrieve the code file to be inspected sent by the code submission pipeline system; Extract at least one structured query statement from the code file to be detected; According to the preset detection rules, each of the structured query statements is detected to obtain the detection results of each of the structured query statements; Based on the detection results of each structured query statement, the detection result of the code file is determined. The detection result of the code file is used by the code submission pipeline system to determine whether to intercept the submission process of the code file.
2. The method according to claim 1, characterized in that, The step of detecting each structured query statement according to preset detection rules and obtaining the detection results of each structured query statement includes: For each of the structured query statements, the first rule in the detection rules is used to perform text standardization detection on the structured query statements to obtain the first detection result of the structured query statements; Obtain the structural information of the target database; Based on the structural information, the second rule in the detection rules is used to perform performance testing on the structured query statement to obtain the second detection result of the structured query statement; The detection result of the structured query statement is determined based on the first detection result and the second detection result of the structured query statement.
3. The method according to claim 2, characterized in that, The step of performing performance testing on the structured query statement based on the structure information and using the second rule in the detection rules to obtain the second detection result of the structured query statement includes: Using the second rule in the detection rules, the system detects whether the index information existing in the structured query statement belongs to the index information in the structured information, and obtains a second detection result; and / or Using the second rule in the detection rules, the system detects whether the query content in the structured query statement is consistent with the table structure in the structure information, and obtains the second detection result.
4. The method according to claim 1, characterized in that, Also includes: Obtain the specification documents for the new database; Extract at least one key code element and the corresponding specification instruction information from the specification document; For each of the aforementioned key code contents, rule content corresponding to the key code contents is generated based on the key code contents and the corresponding specification instructions; The risk level corresponding to the key content of the code is generated based on the specification instructions corresponding to the key content of the code. Based on the rule content and risk level corresponding to the key content of the code, detection rules are generated.
5. The method according to claim 1, characterized in that, Also includes: Obtain at least one historical event; For each of the aforementioned historical events, obtain the corresponding code content for that historical event; Extract key data from the code content corresponding to the historical events and generate the rule content corresponding to the historical events; Obtain the impact data corresponding to the historical events; Based on the impact data corresponding to the historical events, a risk level corresponding to the historical events is generated; Detection rules are generated based on the rule content and risk level corresponding to the historical events.
6. The method according to claim 1, characterized in that, Determining the detection result of the code file based on the detection results of each structured query statement includes: Based on the rules violated and the corresponding risk levels in the detection results of each structured query statement, it is determined whether to intercept the code file, and the detection results of the code file are obtained.
7. The method according to claim 1, characterized in that, The code file to be inspected sent by the code submission pipeline system includes: Retrieve alternative files sent by the code submission pipeline system; Based on the file extensions of the candidate files, code files containing the target characters are selected as the code files to be detected; the target characters correspond to code files of the Structured Query Language type.
8. A database code detection device, characterized in that, The device includes: The file acquisition module is used to acquire the code files to be inspected sent by the code submission pipeline system; The statement extraction module is used to extract at least one structured query statement from the code file to be detected; The statement detection module is used to detect each of the structured query statements according to preset detection rules, and obtain the detection results of each of the structured query statements; The interception judgment module is used to determine the detection result of the code file based on the detection results of each structured query statement. The detection result of the code file is used by the code submission pipeline system to determine whether to intercept the submission process of the code file.
9. A database code detection device, characterized in that, The database code detection device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the database code detection method according to any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that are used to cause a processor to execute the database code detection method according to any one of claims 1-7.