A data revision method and device
Patent Information
- Application Number
- CN202311383912.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-24
- Publication Date
- 2026-10-30
- Estimated Expiration
- 2043-10-24
AI Technical Summary
[0003]有鉴于此,本申请实施例的目的在于提出一种数据订正方法及装置,以解决数据库指令存在错误的问题
[0041]从上面所述可以看出,本申请实施例提供的数据订正方法及装置,对输入的数据库指令按照预设的语法规则进行语法校验,如果语句校验通过,对数据库指令按照预设的语义规则进行语义校验,如果语义校验通过,对数据库指令按照预设的逻辑规则进行逻辑校验,得到逻辑校验结果。本申请能够实现自动校验数据库指令,保证校验通过的数据库指令的正确性、可靠性。
Smart Images

Figure CN117474008B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to a data correction method and apparatus. Background Technology
[0002] In the production environment of banking IT systems, dirty data can occur for various reasons. Dirty data can cause program malfunctions or data inaccuracies, necessitating its correction. Current data correction methods typically involve developers creating database commands for data correction, testers validating these commands in a test environment, and then executing them in the production environment. However, due to inconsistencies between test and production environments, database commands validated in the test environment may contain errors in the production environment. Summary of the Invention
[0003] In view of this, the purpose of this application is to provide a data correction method and apparatus to solve the problem of errors in database instructions.
[0004] To achieve the above objectives, this application provides a data correction method, including:
[0005] According to the preset syntax rules, the input database commands are syntax-validated to obtain the syntax validation results;
[0006] If the syntax verification result is passed, the database instruction is semantically verified according to the preset semantic rules to obtain the semantic verification result;
[0007] If the semantic verification result is passed, the database instruction is logically verified according to the preset logical rules to obtain the logical verification result.
[0008] Optionally, the database instructions include insert instructions and update instructions; according to preset syntax rules, the input database instructions are syntax-checked to obtain syntax check results, including:
[0009] For the insert command, it is determined whether the number of fields to be inserted matches the number of values to be inserted. If they do not match, the syntax check result is that the insert command is incorrect.
[0010] For the update instruction, it is determined whether there is a separator between each pair of updated fields. If not, the syntax check result is that the update instruction is incorrect.
[0011] Optionally, the database instruction further includes a delete instruction; if the syntax verification result is passed, the database instruction is semantically verified according to preset semantic rules to obtain a semantic verification result, including:
[0012] If the database instruction does not belong to any of the insert, update, and delete instructions, the semantic verification result is an instruction error.
[0013] For any of the insert, update, and delete instructions, determine whether a query sub-instruction exists. If it does, the semantic verification result is that it does not conform to the correction rule.
[0014] Optionally, if the semantic verification result is passed, the database instruction is logically verified according to preset logical rules to obtain a logical verification result, including: for the insert instruction:
[0015] Determine whether creation information exists in the insertion instruction; if not, the logical verification result is that it does not conform to the correction rules.
[0016] Based on the preset metadata information, determine whether there is a field in the insertion instruction that is not present in the metadata information. If so, the logical verification result is that the insertion instruction is incorrect.
[0017] Determine whether the data of the inserted value in the insertion instruction exceeds a preset insertion threshold. If it does, the logical verification result is that the insertion instruction exceeds the threshold.
[0018] Optionally, if the semantic verification result is passed, the database instruction is logically verified according to preset logical rules to obtain a logical verification result, including: for the update instruction:
[0019] Determine whether there is update information in the update instruction; if not, the logical verification result is that it does not conform to the correction rules.
[0020] Based on the preset metadata information, it is determined whether the update instruction is based on the primary key update. If not, the logical verification result is that it does not conform to the correction rules.
[0021] Determine whether there is a field in the update instruction that is not in the metadata information. If there is, the logical verification result is that the update instruction is incorrect.
[0022] Determine whether the field to be updated in the update instruction includes the primary key. If so, the logical verification result is that the primary key cannot be updated.
[0023] If the update instruction includes a conditional sub-instruction, and the conditional sub-instruction contains a range query other than an IN query, the logical verification result is that range queries are not allowed.
[0024] If the update instruction includes a conditional sub-instruction and a grouping sub-instruction, and the conditional sub-instruction and the grouping sub-instruction contain functions, the logical verification result is that functions are not allowed.
[0025] If the update instruction includes a conditional sub-instruction, and the number of primary keys in the conditional sub-instruction exceeds a preset update threshold, the logical verification result is that the update instruction exceeds the threshold.
[0026] Optionally, if the semantic verification result is passed, the database instruction is logically verified according to preset logical rules to obtain a logical verification result, including: for the deletion instruction:
[0027] Based on the preset metadata information, it is determined whether the deletion instruction is based on the primary key deletion. If not, the logical verification result is that it does not conform to the correction rules.
[0028] Determine whether the deletion instruction contains a field that is not present in the metadata information. If it does, the logical verification result is that the deletion instruction is incorrect.
[0029] If the deletion instruction includes a conditional sub-instruction, and the conditional sub-instruction contains a range query excluding the IN query, the logical verification result is that range queries are not allowed.
[0030] If the deletion instruction includes a conditional sub-instruction and a grouping sub-instruction, and the conditional sub-instruction and the grouping sub-instruction contain functions, the logical verification result is that functions are not allowed.
[0031] If the deletion instruction includes a conditional sub-instruction, and the number of primary keys of the conditional sub-instruction exceeds a preset deletion threshold, the logical verification result is that the deletion instruction exceeds the threshold.
[0032] This application also provides a data correction device, including:
[0033] The syntax verification module is used to perform syntax verification on the input database commands according to preset syntax rules and obtain the syntax verification results.
[0034] The semantic verification module is used to perform semantic verification on the database instruction according to preset semantic rules when the syntax verification result is passed, and obtain the semantic verification result.
[0035] The logic verification module is used to perform logical verification on the database instruction according to preset logical rules when the semantic verification result is passed, and obtain the logical verification result.
[0036] Optionally, the database instructions include insert instructions and update instructions;
[0037] The syntax verification module is used to determine whether the number of inserted fields matches the number of inserted values for the insert instruction. If they do not match, the syntax verification result is that the insert instruction is incorrect. For the update instruction, it is used to determine whether there is a separator between each pair of update fields. If there is no separator, the syntax verification result is that the update instruction is incorrect.
[0038] Optionally, the database instructions may also include deletion instructions;
[0039] The semantic verification module is used to determine that if the database instruction does not belong to any of the insert, update, and delete instructions, the semantic verification result is an instruction error; for any of the insert, update, and delete instructions, it determines whether there is a query sub-instruction, and if so, the semantic verification result is that it does not conform to the correction rules.
[0040] Optionally, the logic verification module is configured to: determine whether creation information exists in the insertion instruction; if not, the logic verification result is that it does not conform to the correction rules; determine whether there is a field in the insertion instruction that is not present in the metadata information, based on preset metadata information; if so, the logic verification result is that the insertion instruction is incorrect; determine whether the data of the inserted value in the insertion instruction exceeds a preset insertion threshold; if so, the logic verification result is that the insertion instruction exceeds the threshold. For the update instruction: determine whether update information exists in the update instruction; if not, the logic verification result is that it does not conform to the correction rules; determine whether the update instruction is based on the primary key update; if not, the logic verification result is that it does not conform to the correction rules; determine whether there is a field in the update instruction that is not present in the metadata information; if so, the logic verification result is that the update instruction is incorrect; determine whether the field updated in the update instruction includes the primary key; if so, the logic verification result is that the primary key cannot be updated; if the update instruction includes a conditional sub-instruction, and the conditional sub-instruction contains a range query other than an IN query, the logic verification result is that it is not allowed. For the update instruction: if the update instruction includes a conditional sub-instruction and a grouping sub-instruction, and the conditional sub-instruction and the grouping sub-instruction contain functions, the logical verification result is that functions are not allowed; if the update instruction includes a conditional sub-instruction, and the number of primary keys in the conditional sub-instruction exceeds a preset update threshold, the logical verification result is that the update instruction exceeds the threshold; for the delete instruction: based on preset metadata information, determine whether the delete instruction is based on primary key deletion; if not, the logical verification result is that it does not conform to the correction rules; determine whether there is a field in the delete instruction that is not present in the metadata information; if so, the logical verification result is that the delete instruction is incorrect; if the delete instruction includes a conditional sub-instruction, and the conditional sub-instruction contains a range query excluding IN, the logical verification result is that range queries are not allowed; if the delete instruction includes a conditional sub-instruction and a grouping sub-instruction, and the conditional sub-instruction and the grouping sub-instruction contain functions, the logical verification result is that functions are not allowed; if the delete instruction includes a conditional sub-instruction, and the number of primary keys in the conditional sub-instruction exceeds a preset delete threshold, the logical verification result is that the delete instruction exceeds the threshold.
[0041] As can be seen from the above description, the data correction method and apparatus provided in this application perform grammatical verification on the input database instructions according to preset grammatical rules. If the statement verification passes, the database instructions undergo semantic verification according to preset semantic rules. If the semantic verification passes, the database instructions undergo logical verification according to preset logical rules to obtain the logical verification result. This application can automatically verify database instructions, ensuring the correctness and reliability of the verified database instructions. Attached Figure Description
[0042] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0043] Figure 1 This is a schematic diagram of the method flow of an embodiment of this application;
[0044] Figure 2 This is a block diagram of the device structure according to an embodiment of this application;
[0045] Figure 3 This is a block diagram of the electronic device structure according to an embodiment of this application. Detailed Implementation
[0046] To make the objectives, technical solutions, and advantages of this disclosure clearer, the following detailed description is provided in conjunction with specific embodiments and the accompanying drawings.
[0047] It should be noted that, unless otherwise defined, the technical or scientific terms used in the embodiments of this application should have the ordinary meaning understood by one of ordinary skill in the art to which this disclosure pertains. The terms "first," "second," and similar terms used in the embodiments of this application do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Terms such as "comprising" or "including" mean that the element or object preceding the word encompasses the elements or objects listed after the word and their equivalents, without excluding other elements or objects. Terms such as "connected" or "linked" are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. Terms such as "upper," "lower," "left," and "right" are only used to indicate relative positional relationships; when the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0048] In related technologies, the strict separation of testing and production environments in banking systems leads to inconsistencies in the table structures of the databases in the testing and production environments. For example, field types in the testing and production environments may differ. Database commands developed by developers based on the test environment's table structure may work in the testing environment but contain errors in the production environment, making data correction impossible or resulting in incorrect corrections. Moreover, the manual development, testing, and execution of data correction processes is not only inefficient but also prone to errors, especially when dealing with large amounts of data in the database commands, making it difficult to guarantee the correctness of all commands.
[0049] In view of this, embodiments of this application provide a data correction method, which performs grammatical verification on the input database command according to preset grammatical rules. If the statement verification passes, the database command is semantically verified according to preset semantic rules. If the semantic verification passes, the database command is logically verified according to preset logical rules to obtain the logical verification result. This enables the database command to be automatically verified according to the set grammatical, semantic and logical rules, ensuring the correctness and reliability of the verified command.
[0050] The technical solution of this application will be further described in detail below through specific embodiments.
[0051] like Figure 1 As shown, the data correction method provided in this application includes:
[0052] S101: Perform syntax validation on the input database command according to the preset syntax rules, and obtain the syntax validation result;
[0053] In this embodiment, developers create a series of database commands for data correction. These commands are input into the data correction device, which automatically performs syntax, semantic, and logical checks on the input commands. No manual testing or verification is required, ensuring that the automatically verified database commands conform to relevant verification rules. In some implementations, the data correction device in this embodiment is based on an SQL parser, and the database commands for data correction are SQL-based insert, update, and delete commands, etc., used to perform related operations on the data tables in the database.
[0054] In some embodiments, the method for performing syntax validation on database instructions includes:
[0055] For insert commands, it is checked whether the number of fields to be inserted matches the number of values to be inserted. If they do not match, the syntax check result is that the insert command is incorrect.
[0056] For update instructions, it is determined whether there is a separator between each pair of updated fields. If not, the syntax check result is that the update instruction is incorrect.
[0057] In this embodiment, the syntax validation of database commands mainly involves validating the syntax rules of insert and update commands. For insert commands, it's necessary to verify whether the number of inserted fields matches the number of inserted values. If the number of inserted fields does not equal the number of inserted values, the insert command contains an error. For example, if an insert command includes 'name', 'time', and 'type' as fields, and 'Lucy' and '19:00' as values, the validation will determine that the number of inserted fields and values are inconsistent; the inserted fields and values do not appear in pairs, thus the insert command contains an error. For update commands, according to the syntax rules, the pairs of fields being updated in an update command must be separated by a delimiter (e.g., a comma). Therefore, if an update command contains a syntax error, it contains an error.
[0058] S102: If the syntax check result is passed, perform semantic check on the database instructions according to the preset semantic rules to obtain the semantic check result;
[0059] In this embodiment, after the syntax of the input database command passes the validation, semantic validation is performed. The method for performing semantic validation on the database command includes:
[0060] If the database command does not belong to any of the insert, update, or delete commands, the semantic check result is a command error.
[0061] For any of the insert, update, and delete instructions, determine whether a query sub-instruction exists. If it does, the semantic check result is that it does not conform to the correction rule.
[0062] In this embodiment, according to semantic rules, the database command used for data correction can only be one of the following: insert, update, or delete commands. That is, dirty data can be modified by inserting, updating, or deleting fields and values. Therefore, during semantic verification, if the database command is determined to be any command other than insert, update, or delete, then the command is considered erroneous. For any of the insert, update, or delete commands, if any command contains a nested query sub-command, meaning other types of commands still exist, then it still does not conform to the data correction rules.
[0063] S103: If the semantic verification result is passed, perform logical verification on the database instruction according to the preset logical rules to obtain the logical verification result.
[0064] In this embodiment, after the semantic verification of the database command passes, logical verification continues.
[0065] The methods for logically validating database commands include:
[0066] For insert instructions:
[0067] Determine whether creation information exists in the insertion instruction. If not, the logical verification result is that it does not conform to the correction rules.
[0068] Based on the preset metadata information, determine whether there are fields in the insert command that are not in the metadata information. If they are, the logical verification result is that the insert command is incorrect.
[0069] Determine whether the data of the inserted value in the insert instruction exceeds the preset insertion threshold. If it does, the logical verification result is that the insert instruction exceeds the threshold.
[0070] In this embodiment, the database stores metadata information of the data tables. The metadata information records the data of the data tables in the production environment, including the table name, field names, field types, field lengths, index names, index fields, primary key names, etc. When performing logical validation on insert commands, firstly, to facilitate tracing data insertion history, database commands should include creation information such as the creator and creation time. Therefore, for insert commands, it is necessary to determine whether the command includes creation information; if not, it is determined that it does not comply with the data correction rules. Secondly, it is necessary to determine whether the insert command is suitable for execution in a production environment. The fields in the insert command are compared with the fields in the metadata information to determine whether the fields in the insert command are the same as the fields in the metadata information. If the insert command contains a field that is not in the metadata information, it is considered that the field is not present in the production environment, and the command will result in an error when executed in the production environment, thus determining that the insert command is incorrect. Thirdly, to control the scope of data correction, the amount of data corrected in a single data correction should be within a set threshold range. Therefore, it is necessary to determine whether the value to be inserted in the insert command exceeds the set insertion threshold. If the number of inserted values is less than or equal to the insertion threshold, the insert operation can be executed; if it exceeds the insertion threshold, the logical validation will fail.
[0071] For update commands:
[0072] Based on the preset metadata information, determine whether the update instruction contains a non-existent table or field. If a table or field not included in the metadata exists, the logical verification result is that it does not conform to the correction rules.
[0073] Determine whether the update instruction is based on the primary key update. If not, the logical check result is that it does not conform to the correction rules.
[0074] If the update instruction includes a conditional sub-instruction, and the conditional sub-instruction contains a range query other than an IN query, the logical validation result is that range queries are not allowed.
[0075] If the update instruction includes a conditional sub-instruction and a grouping sub-instruction, and both the conditional sub-instruction and the grouping sub-instruction contain functions, the logical check result is that functions are not allowed.
[0076] If the update instruction includes a conditional sub-instruction, and the number of primary keys in the conditional sub-instruction exceeds the preset update threshold, the logical verification result is that the update instruction exceeds the threshold.
[0077] In this embodiment, when performing logical verification on update instructions, firstly, to facilitate tracing data update history, database instructions should include update information such as the updater and update time. Therefore, for update instructions, it is necessary to determine whether the instruction includes update information; if not, it is determined that it does not conform to the data correction rules. Secondly, to ensure the integrity of the data table, update instructions should be based on primary keys, that is, they need to be updated row by row according to the primary key. The primary key field in the update instruction is compared with the primary key field in the metadata information to determine whether the primary key field in the update instruction is the same as the primary key field in the metadata information. If it is not the same as the primary key field in the metadata information, then... If the update instruction does not update according to the primary key, it can be determined that it does not comply with the correction rules. Thirdly, it is necessary to determine whether the update instruction is suitable for execution in a production environment. If the field in the update instruction is not a field in the metadata information, it is considered that the update instruction contains a field that does not exist in the production environment, and the instruction may malfunction in the production environment, thus determining that the update instruction is incorrect. Fourthly, since the primary key of the data table cannot be updated, it is necessary to determine whether the field being updated in the update instruction includes the primary key. If it does, it is determined that it does not comply with the logical rules, and a message can be displayed indicating that the primary key cannot be updated. Fifthly, due to range queries... Since queries cannot determine the amount of data correction, they are not allowed as data correction instructions. In contrast, IN queries can determine the amount of data correction and can be used as database instructions for data correction. Therefore, for update instructions that include conditional sub-instructions, it is necessary to determine whether the conditional sub-instructions include range queries other than IN queries. If they do, it is determined that the query does not conform to the logical rules, and a message indicating that range queries are not allowed can be displayed. Alternatively, it can be determined whether a range query is included by checking for the presence of symbols indicating data range queries such as greater than, less than, greater than or equal to, and less than or equal to. Sixthly, functions increase complexity and uncertainty. To reduce the complexity and uncertainty of update instructions, for update instructions that include conditional sub-instructions and grouping sub-instructions, it is necessary to determine whether the instruction contains functions. If functions are included, it does not conform to the logical rules, and a message indicating that functions are not allowed can be displayed. Seventhly, to control the scope of data correction, the amount of data updated in a single data update should be within a set threshold range. Therefore, it is necessary to determine whether the number of primary keys contained in the conditional sub-instructions of the update instruction exceeds the set update threshold. If the number of primary keys is less than or equal to the update threshold, the update operation can be executed; if it exceeds the update threshold, the logical validation will fail.
[0078] For the delete command:
[0079] Based on the preset metadata information, determine whether the deletion instruction is based on the primary key. If not, the logical verification result is that it does not comply with the correction rules.
[0080] Determine if the specified field exists in the deletion command. If it does, the logical check result is that the deletion command is incorrect.
[0081] If the delete instruction includes a conditional sub-instruction, and the conditional sub-instruction contains a range query other than an IN query, the logical validation result is that range queries are not allowed.
[0082] If the deletion instruction includes a conditional sub-instruction and a grouping sub-instruction, and both the conditional sub-instruction and the grouping sub-instruction contain functions, the logical verification result is that functions are not allowed.
[0083] If the deletion instruction includes a conditional sub-instruction, and the number of primary keys in the conditional sub-instruction exceeds the preset deletion threshold, the logical verification result is that the deletion instruction exceeds the threshold.
[0084] In this embodiment, when performing logical validation on the delete command, firstly, it is necessary to determine whether the delete command is suitable for execution in a production environment. If the delete command contains fields that are not in the metadata information, then the delete command contains fields that do not exist in the production environment, and the execution of the command in the production environment may result in an error, thus the delete command can be determined to be erroneous. Secondly, for delete commands that include conditional sub-instructions, it is necessary to determine whether the conditional sub-instructions include range queries other than IN queries. If they include range queries other than IN queries, it is determined that they do not conform to the logical rules, and a prompt can be displayed indicating that range queries are not allowed. Thirdly, functions increase complexity and uncertainty. In order to reduce the complexity and uncertainty of delete commands, for delete commands containing... This also includes conditional sub-instructions and grouping sub-instructions. It's necessary to determine if the instruction contains functions. If it does, it violates the logical rules, and a message indicating that functions are not allowed can be displayed. Fourthly, to ensure the integrity of the data table, deletion instructions should be based on primary keys, meaning each record must be deleted according to the primary key. If a deletion instruction does not delete according to the primary key, it can be determined that it does not comply with the correction rules. Fifthly, to control the scope of data correction, the amount of data deleted in a single instance should be within a set threshold. Therefore, it's necessary to determine whether the number of primary keys contained in the conditional sub-instructions of the deletion instruction exceeds the set deletion threshold. If the number of primary keys is less than or equal to the deletion threshold, the deletion operation can be performed; if it exceeds the deletion threshold, the logical check will fail.
[0085] The data correction method provided in this application verifies the configured database instructions for data correction according to syntax rules, semantic rules, and logical rules. This enables timely detection of erroneous instructions that do not conform to the relevant rules, ensuring the correctness and reliability of the verified database instructions. The verified database instructions can then be correctly executed in the production environment to correct the data, ensuring the stable operation of the system.
[0086] It should be noted that the method in this embodiment can be executed by a single device, such as a computer or server. The method can also be applied in a distributed scenario, where multiple devices cooperate to complete the task. In such a distributed scenario, one of these devices may execute only one or more steps of the method in this embodiment, and the multiple devices will interact with each other to complete the method described.
[0087] It should be noted that the above description describes specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims may be performed in a different order than that shown in the embodiments and still achieve the desired results. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0088] like Figure 2 As shown in the illustration, this application also provides a data correction device, including:
[0089] The syntax verification module is used to perform syntax verification on the input database commands according to preset syntax rules and obtain the syntax verification results.
[0090] The semantic validation module is used to perform semantic validation on database instructions according to preset semantic rules when the syntax validation result is passed, and obtain the semantic validation result.
[0091] The logic verification module is used to perform logical verification on database instructions according to preset logical rules when the semantic verification result is passed, and obtain the logical verification result.
[0092] In some embodiments, database instructions include insert instructions and update instructions;
[0093] The syntax validation module is used to check whether the number of fields to be inserted matches the number of values to be inserted for insert commands. If they do not match, the syntax validation result is that the insert command is incorrect. For update commands, it checks whether there is a separator between each pair of updated fields. If there is no separator, the syntax validation result is that the update command is incorrect.
[0094] In some embodiments, the database instructions also include delete instructions;
[0095] The semantic validation module is used to determine if a database command does not belong to any of the insert, update, or delete commands, and the semantic validation result is that the command is incorrect. For any of the insert, update, or delete commands, it checks whether a query sub-command exists. If it does, the semantic validation result is that it does not conform to the correction rules.
[0096] In some embodiments, the logic verification module is used for the following purposes: For insert instructions: Based on preset metadata information, determine whether creation information exists in the insert instruction; if not, the logic verification result is that it does not conform to the correction rules; determine whether a predetermined field exists in the insert instruction; if it does, the logic verification result is that the insert instruction is incorrect; determine whether the data of the inserted value in the insert instruction exceeds a preset insertion threshold; if it does, the logic verification result is that the insert instruction exceeds the threshold. For update instructions: Determine whether update information exists in the update instruction; if not, the logic verification result is that it does not conform to the correction rules; determine whether the update instruction is based on a primary key update; if not, the logic verification result is that it does not conform to the correction rules; determine whether a predetermined field exists in the update instruction; if it does, the logic verification result is that the update instruction is incorrect; determine whether the field updated in the update instruction includes the primary key; if so, the logic verification result is that the primary key cannot be updated; if the update instruction includes a conditional sub-instruction, and the conditional sub-instruction contains a range query other than an IN query, the logic verification result is that the range query is not allowed. For range queries: If the update instruction includes conditional sub-instructions and grouping sub-instructions, and functions exist in both, the logical verification result is that functions are not allowed. If the update instruction includes conditional sub-instructions, and the number of primary keys in the conditional sub-instructions exceeds a preset update threshold, the logical verification result is that the update instruction exceeds the threshold. For delete instructions: Based on preset metadata information, determine whether the delete instruction is based on primary key deletion; if not, the logical verification result is that it does not conform to the correction rules. Determine whether a predetermined field exists in the delete instruction; if it does, the logical verification result is that the delete instruction is incorrect. If the delete instruction includes conditional sub-instructions, and range queries other than IN queries exist in the conditional sub-instructions, the logical verification result is that range queries are not allowed. If the delete instruction includes conditional sub-instructions and grouping sub-instructions, and functions exist in both, the logical verification result is that functions are not allowed. If the delete instruction includes conditional sub-instructions, and the number of primary keys in the conditional sub-instructions exceeds a preset delete threshold, the logical verification result is that the delete instruction exceeds the threshold.
[0097] For ease of description, the above devices are described in terms of function, divided into various modules. Of course, in implementing the embodiments of this application, the functions of each module can be implemented in one or more software and / or hardware.
[0098] The apparatus described above is used to implement the corresponding methods in the foregoing embodiments and has the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0099] Figure 3This embodiment illustrates a more specific hardware structure of an electronic device, which may include a processor 1010, a memory 1020, an input / output interface 1030, a communication interface 1040, and a bus 1050. The processor 1010, memory 1020, input / output interface 1030, and communication interface 1040 are interconnected internally via the bus 1050.
[0100] The processor 1010 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification.
[0101] The memory 1020 can be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 1020 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program code is stored in the memory 1020 and is called and executed by the processor 1010.
[0102] The input / output interface 1030 is used to connect input / output modules to realize information input and output. Input / output modules can be configured as components within the device (not shown in the figure) or externally connected to the device to provide corresponding functions. Input devices may include keyboards, mice, touchscreens, microphones, various sensors, etc., while output devices may include displays, speakers, vibrators, indicator lights, etc.
[0103] The communication interface 1040 is used to connect a communication module (not shown in the figure) to enable communication between this device and other devices. The communication module can communicate via wired means (such as USB, Ethernet cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).
[0104] Bus 1050 includes a pathway for transmitting information between various components of the device, such as processor 1010, memory 1020, input / output interface 1030, and communication interface 1040.
[0105] It should be noted that although the above-described device only shows the processor 1010, memory 1020, input / output interface 1030, communication interface 1040, and bus 1050, in specific implementations, the device may also include other components necessary for normal operation. Furthermore, those skilled in the art will understand that the above-described device may only include the components necessary for implementing the embodiments of this specification, and not necessarily all the components shown in the figures.
[0106] The electronic devices described above are used to implement the corresponding methods in the foregoing embodiments and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0107] The computer-readable medium of this embodiment includes permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transfer medium that can be used to store information accessible by a computing device.
[0108] Those skilled in the art should understand that the discussion of any of the above embodiments is merely exemplary and is not intended to imply that the scope of this disclosure (including the claims) is limited to these examples; within the framework of this disclosure, the technical features of the above embodiments or different embodiments can also be combined, the steps can be implemented in any order, and there are many other variations of different aspects of the embodiments of this application as described above, which are not provided in the details for the sake of brevity.
[0109] Additionally, to simplify the description and discussion, and to avoid obscuring the embodiments of this application, the well-known power / ground connections to integrated circuit (IC) chips and other components may or may not be shown in the provided drawings. Furthermore, the apparatus may be shown in block diagram form to avoid obscuring the embodiments of this application, and this also takes into account the fact that the details of the implementation of these block diagram apparatuses are highly dependent on the platform on which the embodiments of this application will be implemented (i.e., these details should be fully understood by those skilled in the art). While specific details (e.g., circuits) have been set forth to describe exemplary embodiments of this disclosure, it will be apparent to those skilled in the art that the embodiments of this application can be implemented without these specific details or with variations thereof. Therefore, these descriptions should be considered illustrative rather than restrictive.
[0110] Although this disclosure has been described in conjunction with specific embodiments thereof, many substitutions, modifications, and variations of these embodiments will be apparent to those skilled in the art from the foregoing description. For example, other memory architectures (e.g., dynamic RAM (DRAM)) may be used with the embodiments discussed.
[0111] The embodiments of this application are intended to cover all such substitutions, modifications, and variations that fall within the broad scope of the appended claims. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the embodiments of this application should be included within the protection scope of this disclosure.
Claims
1. A data correction method, characterized in that, include: According to preset syntax rules, the input database commands are syntax-validated to obtain syntax validation results; wherein, the database commands include insert commands, update commands, and delete commands; If the syntax verification result is passed, the database instruction is semantically verified according to the preset semantic rules to obtain the semantic verification result, including: if the database instruction does not belong to any of the insert instruction, update instruction and delete instruction, the semantic verification result is an instruction error; For any of the insert, update, and delete instructions, determine whether a query sub-instruction exists. If it does, the semantic verification result is that it does not conform to the correction rule. If the semantic verification result is passed, the database instruction is logically verified according to the preset logical rules to obtain the logical verification result.
2. The method according to claim 1, characterized in that, According to preset syntax rules, the input database commands are syntax-validated, and the syntax validation results are obtained, including: For the insert command, it is determined whether the number of fields to be inserted matches the number of values to be inserted. If they do not match, the syntax check result is that the insert command is incorrect. For the update instruction, it is determined whether there is a separator between each pair of updated fields. If not, the syntax check result is that the update instruction is incorrect.
3. The method according to claim 1, characterized in that, If the semantic verification result is successful, the database instruction is logically verified according to preset logical rules to obtain the logical verification result, including: for the insert instruction: Determine whether creation information exists in the insertion instruction; if not, the logical verification result is that it does not conform to the correction rules. Based on the preset metadata information, determine whether there is a field in the insertion instruction that is not present in the metadata information. If so, the logical verification result is that the insertion instruction is incorrect. Determine whether the data of the inserted value in the insertion instruction exceeds a preset insertion threshold. If it does, the logical verification result is that the insertion instruction exceeds the threshold.
4. The method according to claim 1, characterized in that, If the semantic verification result is passed, the database instruction is logically verified according to preset logical rules to obtain the logical verification result, including: for the update instruction: Determine whether there is update information in the update instruction; if not, the logical verification result is that it does not conform to the correction rules. Based on the preset metadata information, it is determined whether the update instruction is based on the primary key update. If not, the logical verification result is that it does not conform to the correction rules. Determine whether there is a field in the update instruction that is not in the metadata information. If there is, the logical verification result is that the update instruction is incorrect. Determine whether the field to be updated in the update instruction includes the primary key. If so, the logical verification result is that the primary key cannot be updated. If the update instruction includes a conditional sub-instruction, and the conditional sub-instruction contains a range query other than an IN query, the logical verification result is that range queries are not allowed. If the update instruction includes a conditional sub-instruction and a grouping sub-instruction, and the conditional sub-instruction and the grouping sub-instruction contain functions, the logical verification result is that functions are not allowed. If the update instruction includes a conditional sub-instruction, and the number of primary keys in the conditional sub-instruction exceeds a preset update threshold, the logical verification result is that the update instruction exceeds the threshold.
5. The method according to claim 1, characterized in that, If the semantic verification result is passed, the database instruction is logically verified according to preset logical rules to obtain the logical verification result, including: for the deletion instruction: Based on the preset metadata information, it is determined whether the deletion instruction is based on the primary key deletion. If not, the logical verification result is that it does not conform to the correction rules. Determine whether the deletion instruction contains a field that is not present in the metadata information. If it does, the logical verification result is that the deletion instruction is incorrect. If the deletion instruction includes a conditional sub-instruction, and the conditional sub-instruction contains a range query excluding the IN query, the logical verification result is that range queries are not allowed. If the deletion instruction includes a conditional sub-instruction and a grouping sub-instruction, and the conditional sub-instruction and the grouping sub-instruction contain functions, the logical verification result is that functions are not allowed. If the deletion instruction includes a conditional sub-instruction, and the number of primary keys of the conditional sub-instruction exceeds a preset deletion threshold, the logical verification result is that the deletion instruction exceeds the threshold.
6. A data correction device, characterized in that, include: The syntax verification module is used to perform syntax verification on the input database commands according to preset syntax rules and obtain the syntax verification results; wherein, the database commands include insert commands, update commands and delete commands; The semantic verification module is used to perform semantic verification on the database instruction according to preset semantic rules when the syntax verification result is passed, and obtain a semantic verification result, including: when it is determined that the database instruction does not belong to any of the insert instruction, update instruction and delete instruction, the semantic verification result is an instruction error; for any of the insert instruction, update instruction and delete instruction, it is determined whether there is a query sub-instruction, and if there is, the semantic verification result is that it does not conform to the correction rule; The logic verification module is used to perform logical verification on the database instruction according to preset logical rules when the semantic verification result is passed, and obtain the logical verification result.
7. The apparatus according to claim 6, characterized in that, The syntax verification module is used to determine whether the number of inserted fields matches the number of inserted values for the insert instruction. If they do not match, the syntax verification result is that the insert instruction is incorrect. For the update instruction, it is used to determine whether there is a separator between each pair of update fields. If there is no separator, the syntax verification result is that the update instruction is incorrect.
8. The apparatus according to claim 6, characterized in that, The logic verification module is used to: determine whether creation information exists in the insertion instruction; if not, the logic verification result is that it does not conform to the correction rules; and determine whether there are fields in the insertion instruction that are not present in the metadata information according to the preset metadata information; if so, the logic verification result is that the insertion instruction is incorrect. The system checks whether the data of the inserted value in the insertion instruction exceeds a preset insertion threshold. If it does, the logical verification result is that the insertion instruction exceeds the threshold. For the update instruction: the system checks whether there is update information in the update instruction. If not, the logical verification result is that it does not conform to the correction rules. The system checks whether the update instruction is based on the primary key update. If not, the logical verification result is that it does not conform to the correction rules. The system checks whether there is a field in the update instruction that does not exist in the metadata information. If it does, the logical verification result is that the update instruction is incorrect. Determine whether the field to be updated in the update instruction includes the primary key. If so, the logical verification result is that the primary key cannot be updated. If the update instruction includes a conditional sub-instruction, and the conditional sub-instruction contains a range query excluding IN, the logical verification result is that range queries are not allowed; if the update instruction includes both a conditional sub-instruction and a grouping sub-instruction, and both the conditional sub-instruction and the grouping sub-instruction contain functions, the logical verification result is that functions are not allowed; if the update instruction includes a conditional sub-instruction, and the number of primary keys in the conditional sub-instruction exceeds a preset update threshold, the logical verification result is that the update instruction exceeds the threshold; for the deletion instruction: based on preset metadata information, determine whether the deletion instruction is based on primary key deletion; if not, the logical verification result is that it does not conform to the correction rules; determine whether the deletion instruction contains a field that is not present in the metadata information; if so, the logical verification result is that the deletion instruction is incorrect; If the deletion instruction includes a conditional sub-instruction, and the conditional sub-instruction contains a range query excluding IN, the logical verification result is that range queries are not allowed; if the deletion instruction includes both a conditional sub-instruction and a grouping sub-instruction, and both the conditional sub-instruction and the grouping sub-instruction contain functions, the logical verification result is that functions are not allowed; if the deletion instruction includes a conditional sub-instruction, and the number of primary keys in the conditional sub-instruction exceeds a preset deletion threshold, the logical verification result is that the deletion instruction exceeds the threshold.
Citation Information
Patent Citations
Database management method and device, electronic equipment and storage medium
CN113722347A
