Database object detection method, device, equipment and storage medium
By dividing database objects and applying comparison rules, the consistency test results of database objects are automatically determined, which solves the problems of low detection accuracy and efficiency in the existing technology and achieves more efficient and accurate detection.
Patent Information
- Application Number
- CN202210124659.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-10
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2042-02-10
AI Technical Summary
In the prior art, database object consistency detection has a low degree of automation and low accuracy, which affects the test efficiency and quality.
By dividing the database objects in the detection environment, determining the object names of the same database objects, and obtaining the target database object creation statements associated with them, the preset comparison rules are used to determine the difference creation statements to achieve automated consistency detection.
Improves the accuracy and efficiency of database object consistency detection, ensuring the accuracy and consistency of test results.
Smart Images

Figure CN114490587B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of data processing technology, and in particular to a method, apparatus, device, and storage medium for detecting database objects. Background Art
[0002] To ensure the successful launch of a project or software, testing plays an irreplaceable role in ensuring its quality. During testing, ensuring the consistency of database objects across different environments is crucial. Differences in databases across different environments can severely impact testing, affecting both efficiency and quality, and even the launch of the entire project or software.
[0003] In the prior art, consistency detection of database objects is usually performed manually, which results in a low degree of automation and accuracy in database object consistency detection. Alternatively, the contents of databases in different environments are compared one by one, which results in a low efficiency in database object consistency detection. Summary of the Invention
[0004] Embodiments of the present application provide a method, apparatus, device, and storage medium for detecting database objects to improve the detection accuracy and efficiency of database objects.
[0005] In a first aspect, an embodiment of the present application provides a method for detecting a database object, the method comprising:
[0006] According to a preset database object division rule, database objects in the database to be tested in the detection environment are divided to obtain a first database object, a second database object, and a third database object; wherein the detection environment includes the first environment and the second environment;
[0007] Determine, according to the object name of the first database object in the database to be tested, based on a preset first comparison rule, the same database objects as the first database objects in the database to be tested in the first environment and the second environment;
[0008] According to the same object name of the same database object, obtaining a target database object creation statement associated with the object name in the detection environment; wherein the target database object creation statement includes a first database object creation statement, a second database object creation statement, and a third database object creation statement;
[0009] According to the preset second comparison rule, the difference creation statements in the target database object creation statements corresponding to the first environment and the second environment are determined, so that relevant testers can determine the consistency detection result of the database object based on the difference creation statements.
[0010] In a second aspect, an embodiment of the present application further provides a database object detection device, the device comprising:
[0011] A data object acquisition module, configured to divide the database objects in the database to be tested in the detection environment according to a preset database object division rule to obtain a first database object, a second database object, and a third database object; wherein the detection environment includes the first environment and the second environment;
[0012] an identical database object determining module, configured to determine, based on the object name of the first database object in the test database and a preset first comparison rule, identical database objects of the first database object in the test databases of the first environment and the second environment;
[0013] a creation statement acquisition module, configured to acquire, based on the same object name of the same database object, a target database object creation statement associated with the object name in the detection environment; wherein the target database object creation statement includes a first database object creation statement, a second database object creation statement, and a third database object creation statement;
[0014] The difference creation statement determination module is used to determine the difference creation statements in the target database object creation statements corresponding to the first environment and the second environment respectively according to the preset second comparison rule, so that relevant testers can determine the consistency detection results of the database objects based on the difference creation statements.
[0015] In a third aspect, an embodiment of the present application further provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, a method for detecting a database object as described in any one of the embodiments of the present application is implemented.
[0016] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the program is executed by a processor, the method for detecting a database object as described in any one of the embodiments of the present application is implemented.
[0017] The embodiment of the present application divides the database objects in the database to be tested in the detection environment to obtain the object name of the first database object in the database to be tested, and based on the preset first comparison rule, determines the object name of the same database object of the first database object in the two detection environments as the same object name. And obtains the target database object creation statements associated with the same object name in the two detection environments respectively. According to the preset second comparison rule, the difference creation statements in the target database object creation statements corresponding to the first environment and the second environment are determined, thereby realizing the automatic determination of the database object consistency detection result and improving the detection accuracy of the database object consistency detection. The above scheme improves the detection efficiency of the database object consistency detection by first determining the object name of the same database object in each detection environment, and then determining the database object consistency detection result based on the target database object creation statement associated with the same database object name. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 This is a flowchart of a method for detecting a database object in Example 1 of the present application;
[0019] Figure 2 This is a flowchart of a method for detecting a database object in the second embodiment of the present application;
[0020] Figure 3 This is a flowchart of a method for detecting a database object in Example 3 of the present application;
[0021] Figure 4 This is a structural block diagram of a database object detection device in the fourth embodiment of the present application;
[0022] Figure 5 This is a structural diagram of an electronic device in Example 5 of the present application. DETAILED DESCRIPTION
[0023] The present invention will be further described in detail below with reference to the accompanying drawings and examples. It will be understood that the specific embodiments described herein are intended only to illustrate the present invention and are not intended to limit the present invention. It should also be noted that, for ease of description, the accompanying drawings only illustrate portions relevant to the present invention, not all structures.
[0024] Example 1
[0025] Figure 1 This is a flow chart of a database object detection method provided in the first embodiment of the present application. This embodiment is applicable to situations where consistency detection of database objects in different environments is performed. The method can be executed by a database object detection device, which can be implemented in software and / or hardware. Figure 1As shown, the method specifically includes the following steps:
[0026] S101. Divide database objects in a database to be tested in a testing environment according to a preset database object division rule to obtain a first database object, a second database object, and a third database object; wherein the testing environment includes the first environment and the second environment.
[0027] Database object partitioning rules can be pre-defined by relevant technical personnel. These rules can include partitioning database objects based on their interdependencies, for example, determining whether database objects can exist independently without relying on each other. The detection environment can include a first environment and a second environment. The first and second environments can be development environments, test environments, or production environments. For example, if the first environment is a development environment, the second environment can be a test environment or a production environment; if the second development environment is a test environment, the first environment can be a development environment or a production environment.
[0028] The database to be tested may be a database to be tested for consistency in the first environment and the second environment. A database object may be a component of a database, and a database object may include at least one of a table, an index, a default value, a view, a rule, a stored procedure, a trigger, a function, and the like.
[0029] The first database object can be a primary database object. A primary database object can exist independently in the database, serving as the foundation for other database objects and being parasitic and dependent on them. A first database object can include tables, charts, and other items. A second database object can be a parasitic database object. A parasitic database object is dependent on a primary database object and cannot exist independently of it. If the primary database object disappears, the parasitic database object also ceases to exist. Accordingly, the second database object can include indexes, default values, rules, and triggers. A third database object can be a dependent database object. It can exist independently of the primary database object but is dependent on it. If the primary database object disappears, the dependent database object cannot function properly. Accordingly, the third database object can include views, stored procedures, and functions.
[0030] S102: Determine, according to the object name of the first database object in the database to be tested and based on a preset first comparison rule, the same database objects of the first database object in the database to be tested in the first environment and the second environment.
[0031] The object name of the first database object can be the name of a table. For example, the name of the table can be "Test1". The first comparison rule can be pre-set by relevant technical personnel. For example, the first comparison rule can be to compare the object name of the first database object in the database to be tested in the first environment with the object name of the first database object in the database to be tested in the second environment to see if they are consistent. Specifically, the names of the tables corresponding to the first environment and the names of the tables corresponding to the second environment can be compared one by one in alphabetical order. The same database objects can be database objects with the same first database object name in the databases to be tested corresponding to the first environment and the second environment, that is, the first database objects shared by the databases to be tested corresponding to the first environment and the second environment.
[0032] For example, the object name of the first database object in the database to be tested corresponding to the first environment and the object name of the first database object in the database to be tested corresponding to the second environment can be stored in a preset first blank text file. The first blank text file can be pre-set by relevant technical personnel. For example, the first blank text file can be a file in txt format. Based on the object name of the first database object stored in the first blank text file, the identical database objects of the first database object in the database to be tested in the first environment and the second environment are determined.
[0033] Specifically, a first blank text file containing the object names of first data objects can be traversed to determine identical database objects of the first database objects corresponding to the first environment and the second environment. For example, the object names of the first database objects corresponding to the first environment are stored in lines 1-200 in the first blank text file, while the object names of the first database objects corresponding to the second environment are stored in lines 201-400 in the first blank text file. Based on a preset first comparison rule, the object names in lines 1-200 and lines 201-400 of the first blank text file containing the object names of the first data objects are compared, thereby determining identical database objects of the first database objects corresponding to the first environment and the second environment.
[0034] S103. According to the same object name of the same database object, obtain a target database object creation statement associated with the object name in the detection environment; wherein the target database object creation statement includes a first database object creation statement, a second database object creation statement, and a third database object creation statement.
[0035] Target database object creation statements can be obtained from the database under test in each testing environment. First database object creation statements may include "GREAT TABLE" statements, etc. Second database object creation statements may include "Regular Index" statements, "Primary Key" statements, and "Unique Key" statements, etc. Third database object creation statements may include "CREATE VIEW" statements, "CREATE VIEW empvu" statements, and "Describe empvu" statements, etc.
[0036] Because both the second and third database objects depend on the first database object, the creation statements for the second and third database objects are related to the first database object. Specifically, the creation statements for the first, second, and third database objects can be obtained by traversing the creation statements in the database under test using the object names of the database objects identical to the first database object in the database under test corresponding to the detection environment.
[0037] S104. Determine, based on a preset second comparison rule, the difference creation statements in the target database object creation statements corresponding to the first environment and the second environment, respectively, so that relevant testers can determine the consistency test result of the database object based on the difference creation statements.
[0038] The second comparison rule may be pre-set by relevant technical personnel. For example, the second comparison rule may be to compare whether the number of target database object creation statements corresponding to the first environment and the target database object creation statements corresponding to the second environment is equal, and to compare whether the statement contents of the target database object creation statements corresponding to the respective detection environments are the same.
[0039] The difference creation statement may be a creation statement that does not satisfy the second comparison rule in the target database object creation statements corresponding to the first environment and the second environment. The consistency test result of the database objects may include consistency of the database objects corresponding to the first environment and the second environment, and inconsistency of the database objects corresponding to the first environment and the second environment. If there is a difference creation statement between the target database object creation statements corresponding to the first environment and the second environment, it can be considered that the database objects corresponding to the first environment and the second environment are inconsistent; if there is no difference creation statement between the target database object creation statements corresponding to the first environment and the second environment, it can be considered that the database objects corresponding to the first environment and the second environment are consistent.
[0040] For example, the first, second, and third database object creation statements corresponding to the first and second environments can be stored in a preset second blank text file. The second blank text file can be pre-set by a relevant technician. For example, the second blank text file can be a file in a txt format. Based on the first, second, and third database object creation statements stored in the second blank text file, the difference creation statements in the target database object creation statements corresponding to the first and second environments are determined.
[0041] Specifically, the second blank text file containing target database object creation statements corresponding to each detection environment can be traversed to determine the difference creation statements in the target database object creation statements corresponding to the first environment and the second environment, respectively. For example, the target database object creation statements corresponding to the first environment are stored in lines 1-600 in the second blank text file, wherein the first database object creation statements corresponding to the first environment are stored in lines 1-200 in the second blank text file, the second database object creation statements corresponding to the first environment are stored in lines 201-400 in the second blank text file, and the third database object creation statements corresponding to the first environment are stored in lines 401-600 in the second blank text file. Among them, the target database object creation statement corresponding to the second environment is stored in the second blank text file at lines 601-1200, wherein the first database object creation statement corresponding to the second environment is stored in the second blank text file at lines 601-800, the second database object creation statement corresponding to the second environment is stored in the second blank text file at lines 801-1000, and the third database object creation statement corresponding to the second environment is stored in the second blank text file at lines 1001-1200. Based on the preset second comparison rule, the first database object creation statements in lines 1-200 and 601-800 in the second blank text file storing the target database object creation statements corresponding to each detection environment are compared to obtain the difference creation statements in the first database object creation statements corresponding to the first environment and the second environment respectively. Based on the preset second comparison rule, the second database object creation statements in lines 201-400 and 801-1000 in the second blank text file storing the target database object creation statements corresponding to each detection environment are compared to obtain the difference creation statements in the second database object creation statements corresponding to the first environment and the second environment respectively. Based on the preset second comparison rule, the third database object creation statements in lines 401-600 and lines 1001-1200 in the second blank text file containing the target database object creation statements corresponding to each detection environment are compared to obtain the difference creation statements in the third database object creation statements corresponding to the first environment and the second environment respectively.
[0042] The embodiment of the present application divides the database objects in the database to be tested in the detection environment to obtain the object name of the first database object in the database to be tested, and based on the preset first comparison rule, determines the object name of the same database object of the first database object in the two detection environments as the same object name. And obtains the target database object creation statements associated with the same object name in the two detection environments respectively. According to the preset second comparison rule, the difference creation statements in the target database object creation statements corresponding to the first environment and the second environment are determined, thereby realizing the automatic determination of the database object consistency detection result and improving the detection accuracy of the database object consistency detection. The above scheme improves the detection efficiency of the database object consistency detection by first determining the object name of the same database object in each detection environment, and then determining the database object consistency detection result based on the target database object creation statement associated with the same database object name.
[0043] Example 2
[0044] Figure 2 This is a flow chart of a method for detecting database objects provided in Example 2 of the present application. This embodiment is optimized and improved on the basis of the above technical solutions.
[0045] Furthermore, the step of "determining, based on the object name of the first database object in the database to be tested, based on a preset first comparison rule, the identical database objects of the first database objects in the database to be tested in the first environment and the second environment" is refined into "storing the object name of the first database object in the database to be tested corresponding to the first environment in a preset first to-be-saved text file according to a preset arrangement rule; and storing the object name of the first database object in the database to be tested corresponding to the second environment in a preset second to-be-saved text file according to a preset arrangement rule; obtaining a first result text file and a second result text file based on the first to-be-saved text file and the second to-be-saved text file based on a preset first comparison rule, wherein the database objects in the first result text file and the second result text file are identical database objects." is used to improve the method for determining identical database objects.
[0046] The step of "obtaining, based on the same object name of the same database object, a target database object creation statement associated with the object name in the detection environment" is refined into "obtaining, based on the same object name of the same database object, a first target database object statement in the first environment; and, based on the same object name of the same database object, a second target database object statement in the second environment." Correspondingly, the step of "determining, based on a preset second comparison rule, the difference creation statements in the target database object creation statements corresponding to the first environment and the second environment, respectively" is refined into "obtaining, based on the first target database object statement and the second target database object statement, a first difference creation statement between the first target database object statement and the second target database object statement, based on a preset second comparison rule." This improves the method for determining the difference creation statements.
[0047] The step of "obtaining, based on the same object name of the same database object, a target database object creation statement associated with the object name in the detection environment" is refined into "obtaining, based on the same object name of the same database object, a third target database object statement in the first environment; and, based on the same object name of the same database object, obtaining a fourth target database object statement in the second environment." Correspondingly, the step of "determining, based on a preset second comparison rule, the difference creation statements in the target database object creation statements corresponding to the first environment and the second environment, respectively" is refined into "obtaining, based on the third target database object statement and the fourth target database object statement, a second difference creation statement between the third target database object statement and the fourth target database object statement, based on a preset second comparison rule." This improves the method for determining the difference creation statements.
[0048] like Figure 2 As shown, the method includes the following specific steps:
[0049] S201 . Divide database objects in a database to be tested in a detection environment according to a preset database object division rule to obtain a first database object, a second database object, and a third database object.
[0050] The detection environment includes a first environment and a second environment.
[0051] S202: Store the object name of the first database object in the database to be tested corresponding to the first environment into a preset first to-be-saved text file according to a preset arrangement rule.
[0052] The arrangement rules can be pre-set by relevant technical personnel, wherein the arrangement rules can be arranged in alphabetical order corresponding to the object name of the first database object. For example, the alphabetical order can be from A to Z, or from Z to A, which is not limited in this embodiment. The first text file to be stored can be pre-set by relevant technical personnel, wherein the file format of the first text file to be stored can be txt text format, doc text format, or docx text format, etc. For example, the first text file to be stored can be a blank text file in txt text format.
[0053] Exemplarily, the object names of the first database objects in the database to be tested corresponding to the first environment include "Test1", "Test2", "A1", "A2", "B1" and "B2". According to the preset arrangement order, "Test1", "Test2", "A1", "A2", "B1" and "B2" are stored in the preset first text file to be stored. Then, the object names of the first database objects in the database to be tested corresponding to the first environment are arranged in the first text file to be stored in the order of "A1, A2, B1, B2, Test1, Test2".
[0054] S203: Store the object name of the first database object in the database to be tested corresponding to the second environment into a preset second text file to be stored according to a preset arrangement rule.
[0055] The second text file to be stored can be pre-set by relevant technical personnel, wherein the file format of the second text file to be stored can be txt text format, doc text format, or docx text format, etc. For example, the second text file to be stored can be a blank text file in txt text format. It should be noted that, in order to facilitate the subsequent comparison of the text contents in the first text file to be stored and the second text file to be stored, it is preferred that the first text file to be stored and the second text file to be stored be set to the same file format.
[0056] S204 : Obtain a first result text file and a second result text file based on the first text file to be stored and the second text file to be stored based on a preset first comparison rule, wherein the database objects in the first result text file and the second result text file are the same database objects.
[0057] The text contents in the first result text file and the second result text file are the same, and are both object names of the same database objects in the first to-be-stored text file and the second to-be-stored text file.
[0058] Exemplarily, based on a preset first comparison rule, the first text file to be stored and the second text file to be stored are compared line by line. If the first text file to be stored contains a name of an object to be deleted that is not contained in the second text file to be stored, the name of the object to be deleted can be deleted from the first text file to be stored, and a first result text file is obtained after the name of the object to be deleted is deleted. If the second text file to be stored contains a name of an object to be deleted that is not contained in the first text file to be stored, the name of the object to be deleted can be deleted from the second text file to be stored, and a second result text file is obtained after the name of the object to be deleted is deleted. The name of the object to be deleted can be an object name that is not shared by the first text file to be stored and the second text file to be stored; that is, the name of the object to be deleted can be an object that exists in the first text file to be stored but does not exist in the second text file to be stored; or it can be an object that exists in the second text file to be stored but does not exist in the first text file to be stored.
[0059] In an optional embodiment, before obtaining the first result text file and the second result text file, it also includes: if the first text file to be stored contains the name of the object to be deleted that is not included in the second text file to be stored, the name of the object to be deleted is deleted from the first text file to be stored and stored in a preset comparison result file, so that relevant testers can add database objects to the database to be tested in the second environment according to the comparison result file.
[0060] The comparison result file may be pre-set by relevant testers, and the file format of the comparison result file may be a txt text format, a doc text format, or a docx text format.
[0061] This optional embodiment deletes the names of the objects to be deleted from the first text file to be stored and stores them in a preset comparison result file, so that relevant testers can subsequently determine the database objects missing in the database to be tested in the second environment through the comparison result file; and can add database objects to the database to be tested in the second environment based on the comparison result file, thereby ensuring consistency with the database objects of the database to be tested in the first environment, which provides convenience for the subsequent testing work of relevant testers.
[0062] S205: Acquire a first target database object statement in the first environment according to the same object name of the same database object.
[0063] The first target database object statement includes a first database object creation statement and a second database object creation statement associated with the same object name in the first environment.
[0064] It should be noted that because the second database object is parasitic on the first database object and cannot exist independently, if the first database object disappears, the second database object also ceases to exist. Accordingly, in the database under test, the second database object creation statement typically follows the first database object creation statement. Therefore, when extracting the first database object creation statement, the second database object creation statement is often also extracted. Therefore, the first and second database creation statements can be retrieved simultaneously.
[0065] Exemplarily, the same object name of the same database object is associated with the first target database object statement. Specifically, the first database object creation statement can be obtained using the same object name. For example, the object creation statement in the database under test can be "CREATE TABLE table_name," where "table_name" is the name of the table. Therefore, the table name "table_name" can be obtained through traversal, and then, based on the table name "table_name," the first database object creation statement "CREATE TABLE" corresponding to the table name can be obtained.
[0066] S206: Acquire a second target database object statement in the second environment according to the same object name of the same database object.
[0067] The second target database object statement includes a first database object creation statement and a second database object creation statement associated with the same object name in the second environment. The second target database object statement in the second environment can be obtained in the same manner as in the first environment, which is not further described in this embodiment.
[0068] It should be noted that this embodiment does not limit the execution order of S205 and S206. S205 may be executed first and then S206; S206 may be executed first and then S205; or S205 and S206 may be executed simultaneously.
[0069] S207 : Obtain a first difference creation statement between the first target database object statement and the second target database object statement based on a preset second comparison rule according to the first target database object statement and the second target database object statement.
[0070] The first difference creation statement may be a different database object creation statement between the first target database object statement and the second target database object statement. Exemplarily, the first difference creation statement may be a different first database object creation statement in the first environment and the second environment, respectively. The first difference creation statement may also be a different second database object creation statement in the first environment and the second environment, respectively.
[0071] In a specific embodiment, the first target database object statement obtained in the first environment can be stored in a preset first candidate text file, and the second target database object statement obtained in the second environment can be stored in a preset second candidate text file. The first candidate text file and the second candidate text file can be preset by relevant technical personnel. Based on the preset second comparison rule, the first database object creation statement and the second database object creation statement in the first candidate text file and the second candidate text file are compared. Specifically, it can be determined whether the first candidate text file has more lines than the second candidate text file, the first candidate text file has fewer lines than the second candidate text file, or whether the contents of the same lines in the first candidate text file and the second candidate text file are the same, thereby determining the first difference between the first target database object statement and the second target database object statement.
[0072] S208: Acquire a third target database object statement in the first environment according to the same object name of the same database object.
[0073] The third target database object statement includes a third database object creation statement associated with the same object name in the first environment.
[0074] It should be noted that the third database object can exist independently of the first database object. Accordingly, in the database under test, the location of the creation statement for the third database object can be independent of the location of the creation statement for the first database object. In other words, the creation statement for the third database object must be searched and determined separately in the database under test; it cannot be retrieved simultaneously with the first database object creation statement.
[0075] S209: Acquire a fourth target database object statement in the second environment according to the same object name of the same database object.
[0076] The fourth target database object statement includes a third database object creation statement associated with the same object name in the second environment.
[0077] It should be noted that the third target database object statement in the first environment and the second environment can be obtained in the same manner as the first target database object statement in the first environment and / or the second target database object statement in the second environment, which will not be described in detail in this embodiment.
[0078] S210 : Obtain a second difference creation statement between the third target database object statement and the fourth target database object statement based on a preset second comparison rule according to the third target database object statement and the fourth target database object statement.
[0079] The second difference creation statement may be a third database object creation statement that is different between the third target database object statement and the fourth target database object statement.
[0080] In a specific embodiment, the third target database object statement obtained in the first environment can be stored in a preset third candidate text file, and the fourth target database object statement obtained in the second environment can be stored in a preset fourth candidate text file. The third candidate text file and the fourth candidate text file can be pre-set by relevant technical personnel. Based on a preset second comparison rule, the third database object creation statements in the third candidate text file and the fourth candidate text file are compared. Specifically, the number of lines in the third candidate text file that are greater than or less than the fourth candidate text file can be determined, or the number of lines in the third candidate text file that are less than the fourth candidate text file can be determined, or the content of the same lines in the third candidate text file and the fourth candidate text file can be compared to determine whether they are identical, thereby determining text file C and text file D between the third target database object statement and the fourth target database object statement.
[0081] It should be noted that the execution order of S205 to S207 and S208 to S210 is not limited in this embodiment. Specifically, S205 to S207 may be executed first, and then S208 to S210; or S208 to S210 may be executed first, and then S205 to S207.
[0082] The scheme of this embodiment obtains the first difference creation statement based on the first target database object statement obtained in the first environment and the second target database object statement obtained in the second environment, based on the preset second comparison rule; obtains the second difference creation statement based on the third target database object statement obtained in the first environment and the fourth target database object statement obtained in the second environment, based on the preset second comparison rule. The above scheme realizes the accurate determination of the difference creation statement by respectively determining the difference creation statement corresponding to each database object statement, so that subsequent testers can more accurately test the database to be tested based on the difference creation statement. By first determining the object name of the same database object in each test environment, and then determining the consistency test result of the database object based on the target database object creation statement associated with the same database object name, the detection efficiency and detection accuracy of the database object consistency test are improved.
[0083] Example 3
[0084] Figure 3 This is a schematic diagram of the detection process of a database object detection method provided in Example 3 of the present application. This embodiment of the present application provides a preferred implementation method based on the technical solutions of the above embodiments.
[0085] This embodiment proposes a method for checking database objects deployed in a Linux operating system environment to quickly and effectively complete the consistency check of database objects between a second environment and a first environment.
[0086] This embodiment extracts all database objects from the database to be tested in each test environment and converts them into text files in a fixed format. The consistency check of the database objects is achieved by comparing the text files and generating the check results. At the same time, in order to reduce the workload of verification and improve the efficiency of detection, this solution adopts a method of classifying and grading the database objects for verification. All database objects in the database are divided into three categories according to their existence form: main database objects, parasitic database objects, and dependent database objects. First, the existence check of the main database object is performed, then the consistency check of the main database object and the parasitic database object is performed, and finally the consistency check of the dependent database object is performed, thereby completing the consistency check of all database objects.
[0087] like Figure 3 As shown, the detailed steps of this program are as follows:
[0088] S301: Check the existence of the main database object.
[0089] If the first environment is a development environment and the second environment is a test environment. The main database object names of the test environment and the development environment are extracted from the databases to be tested in the two environments according to the same sorting rules, and converted into text files in txt format respectively. Among them, the sorting rule can be to sort by the first letter of the object name. The two text files are automatically compared line by line, and the different parts are found based on the development environment. The specific comparison method is as follows: if the object name of the development environment exists and the object name of the test environment does not exist, it means that the database object corresponding to the object name has not been created in the database to be tested in the test environment, then the database object is filtered out and generated as a difference database object into the comparison result file, and at the same time, the object name of the filtered difference database object is removed from the text file corresponding to the development environment. Among them, the comparison result file can be pre-set by relevant technical personnel. If the object name of the test environment exists and the object name of the development environment does not exist, there is no need to generate the object name as a difference database object into the comparison result file, and it is only necessary to remove the object name of the filtered difference database object from the text file corresponding to the test environment. Finally, the common parts of the two text files corresponding to the development environment and the test environment are filtered out as the common database objects in the two environments, which facilitates the subsequent extraction of creation statements based on the object names of the common database objects.
[0090] S302: Check the consistency of the main database object and the parasitic database object.
[0091] Since parasitic database objects are all created on the main database object, their creation statements are also together with the creation statements of the main database objects. Therefore, when extracting the creation statements of the main database objects, their creation statements are also extracted. Based on the object names of the common main database objects of the two environments filtered out in the previous step, the creation statements of the main database objects and parasitic database objects corresponding to the two environments are extracted and stored in text files A and B respectively. Text files A and B are automatically compared line by line to find inconsistent parts, generate the first difference creation statement, and store it in the preset first difference text file. Specifically, the specific rules for generating the first difference creation statement are as follows:
[0092] Display all the contents of two text files simultaneously, line by line, and display the differences line by line according to three situations: (1) Text file A has more lines than text file B. (2) Text file A has fewer lines than text file B. (3) The same lines in text file A and text file B have different contents.
[0093] S303: Check the consistency of dependent database objects.
[0094] The dependent database object creation statements for the two environments are extracted sequentially and stored in text files C and D, respectively. Text files C and D are automatically compared line by line to identify inconsistencies, and a second difference creation statement is generated and stored in the second difference text file. The rules for the second difference creation statement can be the same as those for generating the first difference creation statement in S102, and will not be further described in this embodiment.
[0095] The method involved in this embodiment can be implemented using shell+sql, which has the advantages of being lightweight, installation-free, supporting deployment of various types of databases on an open platform, and consuming less system resources.
[0096] Example 4
[0097] Figure 4 This is a schematic diagram of the structure of a database object detection device provided in the fourth embodiment of the present application. The database object detection device provided in the embodiment of the present application is applicable to the situation where consistency detection is performed on database objects in different environments. The device can be implemented in software and / or hardware. Figure 4 As shown, the device specifically includes: a data object acquisition module 401, a same database object determination module 402, a creation statement acquisition module 403 and a difference creation statement determination module 404.
[0098] The data object acquisition module 401 is configured to divide the database objects in the database to be tested in the detection environment according to a preset database object division rule to obtain a first database object, a second database object, and a third database object; wherein the detection environment includes the first environment and the second environment;
[0099] The same database object determining module 402 is configured to determine the same database objects of the first database object in the test database in the first environment and the second environment based on the object name of the first database object in the test database and a preset first comparison rule;
[0100] A creation statement acquisition module 403 is configured to acquire, based on the same object name of the same database object, a target database object creation statement associated with the object name in the detection environment; wherein the target database object creation statement includes a first database object creation statement, a second database object creation statement, and a third database object creation statement;
[0101] The difference creation statement determination module 404 is used to determine the difference creation statements in the target database object creation statements corresponding to the first environment and the second environment respectively according to the preset second comparison rule, so that relevant testers can determine the consistency detection results of the database objects based on the difference creation statements.
[0102] The embodiment of the present application divides the database objects in the database to be tested in the detection environment to obtain the object name of the first database object in the database to be tested, and based on the preset first comparison rule, determines the object name of the same database object of the first database object in the two detection environments as the same object name. And obtains the target database object creation statements associated with the same object name in the two detection environments respectively. According to the preset second comparison rule, the difference creation statements in the target database object creation statements corresponding to the first environment and the second environment are determined, thereby realizing the automatic determination of the database object consistency detection result and improving the detection accuracy of the database object consistency detection. The above scheme improves the detection efficiency of the database object consistency detection by first determining the object name of the same database object in each detection environment, and then determining the database object consistency detection result based on the target database object creation statement associated with the same database object name.
[0103] Optionally, the same database object determining module 402 includes:
[0104] A first to-be-stored text file determining unit is configured to store the object name of the first database object in the database to be tested corresponding to the first environment into a preset first to-be-stored text file according to a preset arrangement rule; and
[0105] A second to-be-stored text file determining unit is configured to store the object names of the first database objects in the database to be tested corresponding to the second environment into a preset second to-be-stored text file according to a preset arrangement rule;
[0106] The result text file determining unit is configured to obtain a first result text file and a second result text file based on the first text file to be stored and the second text file to be stored, based on a preset first comparison rule, wherein the database objects in the first result text file and the second result text file are the same database objects.
[0107] Optionally, the device further includes:
[0108] A comparison result file determination module is used to, before obtaining the first result text file and the second result text file, if the first to-be-stored text file contains the name of the object to be deleted that is not included in the second to-be-stored text file, delete the name of the object to be deleted from the first to-be-stored text file and store it in a preset comparison result file, so that relevant testers can add database objects to the database to be tested in the second environment according to the comparison result file.
[0109] Optionally, the creation statement acquisition module 403 includes:
[0110] a first target database object statement acquiring unit, configured to acquire a first target database object statement in a first environment according to the same object name of the same database object; wherein the first target database object statement includes a first database object creation statement and a second database object creation statement associated with the same object name in the first environment; and
[0111] The second target database object statement acquiring unit is configured to acquire a second target database object statement in the second environment according to the same object name of the same database object; wherein the second target database object statement includes a first database object creation statement and a second database object creation statement associated with the same object name in the second environment.
[0112] Optionally, the difference creation statement determination module 404 includes:
[0113] The first difference creation statement determining unit is configured to obtain, according to the first target database object statement and the second target database object statement, a first difference creation statement between the first target database object statement and the second target database object statement based on a preset second comparison rule.
[0114] Optionally, the creation statement acquisition module 403 includes:
[0115] a third target database object statement acquiring unit, configured to acquire a third target database object statement in the first environment according to the same object name of the same database object; wherein the third target database object statement includes a third database object creation statement associated with the same object name in the first environment; and
[0116] The fourth target database object statement acquiring unit is configured to acquire a fourth target database object statement in the second environment according to the same object name of the same database object; wherein the fourth target database object statement includes a third database object creation statement associated with the same object name in the second environment.
[0117] Optionally, the difference creation statement determination module 404 includes:
[0118] The second difference creation statement determining unit is configured to obtain, based on the third target database object statement and the fourth target database object statement and a preset second comparison rule, a second difference creation statement between the third target database object statement and the fourth target database object statement.
[0119] The above-mentioned database object detection device can execute the database object detection method provided by any embodiment of the present application, and has corresponding functional modules and beneficial effects for executing each database object detection method.
[0120] Example 5
[0121] Figure 5 This is a structural diagram of an electronic device provided in Example 5 of the present application. Figure 5 A block diagram of an exemplary electronic device 500 suitable for implementing embodiments of the present application is shown. Figure 5 The electronic device 500 shown is merely an example and should not limit the functions and scope of use of the embodiments of the present application.
[0122] like Figure 5 As shown, electronic device 500 is a general-purpose computing device. Components of electronic device 500 may include, but are not limited to, one or more processors or processing units 501, system memory 502, and a bus 503 connecting various system components (including system memory 502 and processing unit 501).
[0123] Bus 503 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor, or a local bus using any of a variety of bus architectures. Examples of these architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MAC) bus, an Enhanced ISA bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus.
[0124] The electronic device 500 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the electronic device 500, including volatile and non-volatile media, removable and non-removable media.
[0125] System memory 502 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 504 and / or cache memory 505. Electronic device 500 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage system 506 may be used to read and write non-removable, non-volatile magnetic media ( Figure 5 Not shown, often called a "hard drive"). Although Figure 5Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 503 via one or more data medium interfaces. Memory 502 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of various embodiments of the present application.
[0126] A program / utility 508 having a set (at least one) of program modules 507 may be stored, for example, in memory 502. Such program modules 507 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data, each of which, or some combination thereof, may include an implementation of a network environment. Program modules 507 generally implement the functions and / or methods of the embodiments described herein.
[0127] The electronic device 500 may also communicate with one or more external devices 509 (e.g., keyboard, pointing device, display 510, etc.), and may also communicate with one or more devices that enable a user to interact with the electronic device 500, and / or any device that enables the electronic device 500 to communicate with one or more other computing devices (e.g., network card, modem, etc.). Such communication may be performed through an input / output (I / O) interface 511. Furthermore, the electronic device 500 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through a network adapter 512. As shown, the network adapter 512 communicates with other modules of the electronic device 500 via the bus 503. It should be understood that although Figure 5 Not shown, other hardware and / or software modules may be used in conjunction with electronic device 500, including but not limited to microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0128] The processing unit 501 executes various functional applications and data processing by running the programs stored in the system memory 502, such as implementing a method for detecting a database object provided in an embodiment of the present application.
[0129] Example 6
[0130] Embodiment 6 of the present application further provides a storage medium containing computer-executable instructions, on which a computer program is stored. When the program is executed by a processor, the method for detecting a database object as provided in the embodiment of the present application is implemented, including: dividing the database objects in the database to be tested in the detection environment according to a preset database object division rule to obtain a first database object, a second database object, and a third database object; wherein the detection environment includes a first environment and a second environment; according to the object name of the first database object in the database to be tested, based on a preset first comparison rule, determining the same database objects of the first database objects in the database to be tested in the first environment and the second environment; according to the same object name of the same database objects, obtaining a target database object creation statement associated with the object name in the detection environment; wherein the target database object creation statement includes the first database object creation statement, the second database object creation statement, and the third database object creation statement; according to a preset second comparison rule, determining the difference creation statements in the target database object creation statements corresponding to the first environment and the second environment respectively, so that relevant testers can determine the consistency test result of the database object based on the difference creation statements.
[0131] The computer storage medium of the embodiment of the present application can adopt any combination of one or more computer-readable media.Computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium.Computer-readable storage medium can be, for example, but not limited to, a system, device or component of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination thereof.More specific examples (non-exhaustive list) of computer-readable storage medium include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.In this document, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, a device or a device or used in combination with it.
[0132] A computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0133] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0134] The computer program code for performing the operations of the present application can be written in one or more programming languages, or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0135] Note that the above are only preferred embodiments of the present invention and the technical principles employed. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments, and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in detail through the above embodiments, the present invention is not limited to the above embodiments and may include many other equivalent embodiments without departing from the concept of the present invention. The scope of the present invention is determined by the scope of the appended claims.
Claims
1. A method for detecting a database object, characterized in that: include: According to a preset database object division rule, database objects in a database to be tested in a test environment are divided to obtain a first database object, a second database object, and a third database object; wherein the test environment includes the first environment and the second environment; the first database object is a primary database object, including a table and a chart; the second database object is a parasitic database object, including an index, a default value, a rule, and a trigger; and the third database object is a dependent database object, including a chart, a stored procedure, and a function; Determine, according to the object name of the first database object in the database to be tested, based on a preset first comparison rule, the same database objects as the first database objects in the database to be tested in the first environment and the second environment; According to the same object name of the same database object, obtaining a target database object creation statement associated with the object name in the detection environment; wherein the target database object creation statement includes a first database object creation statement, a second database object creation statement, and a third database object creation statement; According to the preset second comparison rule, the difference creation statements in the target database object creation statements corresponding to the first environment and the second environment are determined, so that relevant testers can determine the consistency detection result of the database object based on the difference creation statements.
2. The method according to claim 1, characterized in that Determining, according to the object name of the first database object in the database to be tested and based on a preset first comparison rule, the same database object as the first database object in the database to be tested in the first environment and the second environment, includes: storing the object name of the first database object in the database to be tested corresponding to the first environment into a preset first to-be-saved text file according to a preset arrangement rule; and The object name of the first database object in the database to be tested corresponding to the second environment is stored in a preset second to-be-saved text file according to a preset arrangement rule; According to the first text file to be stored and the second text file to be stored, a first result text file and a second result text file are obtained based on a preset first comparison rule. The database objects in the first result text file and the second result text file are the same database objects.
3. The method according to claim 2, characterized in that Before obtaining the first result text file and the second result text file, the method further includes: If the first text file to be stored contains the name of the object to be deleted that is not included in the second text file to be stored, the name of the object to be deleted will be deleted from the first text file to be stored and stored in the preset comparison result file for relevant testers to add database objects to the database to be tested in the second environment based on the comparison result file.
4. The method according to claim 1, wherein According to the same object name of the same database object, obtaining a target database object creation statement associated with the object name in the detection environment includes: Acquire a first target database object statement in the first environment according to the same object name of the same database object; wherein the first target database object statement includes a first database object creation statement and a second database object creation statement associated with the same object name in the first environment; and According to the same object name of the same database object, a second target database object statement in the second environment is obtained; wherein the second target database object statement includes a first database object creation statement and a second database object creation statement associated with the same object name in the second environment.
5. The method according to claim 4, characterized in that The step of determining, according to a preset second comparison rule, different creation statements in the target database object creation statements corresponding to the first environment and the second environment, respectively, includes: According to the first target database object statement and the second target database object statement, based on a preset second comparison rule, a first difference creation statement between the first target database object statement and the second target database object statement is obtained.
6. The method according to claim 1, characterized in that According to the same object name of the same database object, obtaining a target database object creation statement associated with the object name in the detection environment includes: According to the same object name of the same database object, obtaining a third target database object statement in the first environment; wherein the third target database object statement includes a third database object creation statement associated with the same object name in the first environment; and According to the same object name of the same database object, a fourth target database object statement in the second environment is obtained; wherein the fourth target database object statement includes a third database object creation statement associated with the same object name in the second environment.
7. The method according to claim 6, characterized in that The step of determining, according to a preset second comparison rule, different creation statements in the target database object creation statements corresponding to the first environment and the second environment, respectively, includes: According to the third target database object statement and the fourth target database object statement, based on a preset second comparison rule, a second difference creation statement between the third target database object statement and the fourth target database object statement is obtained.
8. A detection device for a database object, characterized in that: include: A data object acquisition module is configured to divide database objects in a database to be tested in a test environment according to a preset database object division rule to obtain a first database object, a second database object, and a third database object; wherein the test environment includes the first environment and the second environment; the first database object is a primary database object, including a table and a chart; the second database object is a parasitic database object, including an index, a default value, a rule, and a trigger; and the third database object is a dependent database object, including a chart, a stored procedure, and a function; an identical database object determining module, configured to determine, based on the object name of the first database object in the test database and a preset first comparison rule, identical database objects of the first database object in the test databases of the first environment and the second environment; a creation statement acquisition module, configured to acquire, based on the same object name of the same database object, a target database object creation statement associated with the object name in the detection environment; wherein the target database object creation statement includes a first database object creation statement, a second database object creation statement, and a third database object creation statement; The difference creation statement determination module is used to determine the difference creation statements in the target database object creation statements corresponding to the first environment and the second environment respectively according to the preset second comparison rule, so that relevant testers can determine the consistency detection results of the database objects based on the difference creation statements.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the method for detecting a database object according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method for detecting a database object according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Database synchronization method and device, electronic equipment and computer storage medium
CN112925849A
Basic data and object initialization method of application system
CN113986938A