Database adaptation compatibility method and device, electronic equipment and storage medium

By scanning and testing structure query statements in the database, syntax modification and replacement are performed, the compatibility problem between different database management systems is solved, and the adaptation of structure query statements is realized to ensure the stability and consistency of database operations.

CN118885463APending Publication Date: 2024-11-01CHINA MOBILE (SUZHOU) SOFTWARE TECH CO LTD +1

Patent Information

Application Number
CN202410984552.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-22
Publication Date
2024-11-01

AI Technical Summary

Technical Problem

The differences in CPU, operating system and storage device between different database management systems lead to incompatibility problems in the new configured database, and the adaptation of structure query statements is required.

Method used

By scanning the file packages in the source database, obtaining preset methods, associating structure query statements, and query testing in the source database and the target database, syntax modification and replacement are performed based on the test results to ensure that the statements are adapted in the target database.

Benefits of technology

Effectively detect and modify unfit structure query statements to reduce the impact on business logic and ensure the smooth progress of database migration and adaptation process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118885463A_ABST
    Figure CN118885463A_ABST
Patent Text Reader

Abstract

The invention provides a database adaptation compatibility method and device, electronic equipment and a storage medium, and the method comprises the steps: scanning a file package and / or a class file in a source database to obtain a preset method in the file package and / or the class file; a structure query statement associated with a preset method is subjected to query testing in a source database and a target database, a comparison testing result is obtained, and the preset method is associated with the structure query statement based on the data mapping annotation; and according to a comparison test result, performing grammar modification on a target structure query statement which is not matched with the target database so as to adapt to the target database. Compared with the prior art, whether the structure query statement meets the grammar requirement of the target database or not can be tested; the influence of the adaptive target database on the business logic can be effectively reduced; by means of adaptation recognition of the to-be-executed structure query statement, dynamic updating adaptation of the target database with the updated grammar rule can be achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a method and device for database adaptation and compatibility, an electronic device, and a storage medium. Background Art

[0002] Database management systems play an important role in big data and cloud computing services, and with the rapid development of big data and cloud computing services, more and more database management systems are being launched. The differences between different database management systems are mainly in the differences between CPUs, operating systems, and storage devices. Due to these configuration differences, database operations originally designed based on open source databases (for example: DDL, DML, DQL, DCL) are incompatible in the newly configured database. Therefore, how to adapt the original structure query statements in the new database management system has become an urgent problem to be solved. Summary of the invention

[0003] The present invention provides a method and device for database adaptation and compatibility, an electronic device and a storage medium, the main purpose of which is to achieve structural query statement adaptation between different databases.

[0004] According to a first aspect of the present disclosure, a method for database adaptation and compatibility is provided, comprising:

[0005] Scan the file packages and / or class files in the source database to obtain the preset methods in the file packages and / or class files;

[0006] Perform query tests on the structured query statements associated with the preset method in the source database and the target database respectively to obtain comparative test results, wherein the preset method is associated with the structured query statements based on data mapping annotations;

[0007] According to the comparison test result, the target structure query statement that is not compatible with the target database is grammatically modified to adapt to the target database.

[0008] In some embodiments, the method further comprises:

[0009] Before the target database runs the structure query statement to be executed, the structure query statement to be executed is adapted and identified, and the incompatible structure query statement to be executed is replaced.

[0010] In some embodiments, scanning a file package or a class file in a source database to obtain a preset method in the file package or the class file includes:

[0011] Scan and obtain class files in the file package and its sub-file packages in a recursive manner;

[0012] A preset method in the class file is obtained, wherein the preset method is associated with a structured query statement in the extensible markup file based on a data mapping annotation.

[0013] In some embodiments, the structured query statement associated with the preset method is subjected to query testing in the source database and the target database respectively to obtain comparative test results, including:

[0014] Obtaining the parameter type in the preset method, and generating corresponding query parameters according to the parameter type;

[0015] Inputting the query parameters into the source database and the target database respectively to perform query testing on the structure query statement associated with the preset method;

[0016] A comparison process is performed based on the query results corresponding to the source database and the target database, to determine whether the structured query statement is compatible with the target database, and to generate the comparison test result.

[0017] In some embodiments, obtaining the parameter type in the preset method and generating the corresponding query parameter according to the parameter type includes:

[0018] Based on the parameter type, generate an empty query parameter corresponding to the parameter type;

[0019] Input the empty query parameter into the source database to perform a query, and obtain a complete query result, wherein the complete query result is a set of all data satisfying the source database;

[0020] The query fields in the complete query result are assigned values ​​to generate the query parameters.

[0021] In some embodiments, the step of modifying the target structure query statement that is not compatible with the target database according to the comparison test result to adapt the target database includes:

[0022] Determining whether the target structure query statement can be modified into a target syntax format that is adapted to both the source database and the target database;

[0023] If it can be modified into the target grammatical format, modifying the target structure query statement into the target grammatical format;

[0024] If the target syntax format cannot be modified, an association relationship is established between the target structure query statement and a structure query statement with the same function in the target database.

[0025] In some embodiments, the establishing of an association relationship between the target structure query statement and a structure query statement with the same function in the target database includes:

[0026] Generate a first identifier of the target structure query statement in the source database, and a second identifier of the structure query statement with the same function in the target database;

[0027] Based on the first identifier and the second identifier, an association relationship between the target structure query statement and a structure query statement with the same function in the target database is established.

[0028] In some embodiments, the adapting and identifying the to-be-executed structure query statements and replacing the incompatible to-be-executed structure query statements include:

[0029] Based on a preset replacement rule, determining whether the to-be-executed structure query statement needs to be replaced;

[0030] If it is determined that replacement is required, the to-be-executed structure query statement is replaced;

[0031] If it is determined that no replacement is required, the to-be-executed structure query statement continues to be executed.

[0032] In some embodiments, judging whether the to-be-executed structure query statement needs to be replaced based on a preset replacement rule includes:

[0033] Based on the preset replacement rule, it is determined whether there is at least one of the keywords, table names, and library names that need to be replaced in the to-be-executed structure query statement, wherein the preset replacement rule represents a correspondence between the source database and the target database between any one of the keywords, table names, and library names that need to be replaced.

[0034] According to a second aspect of the present disclosure, a database adaptation and compatibility device is provided, including:

[0035] An acquisition unit, configured to scan a file package and / or a class file in a source database to acquire a preset method in the file package and / or the class file;

[0036] A testing unit, used for performing query tests on the structured query statements associated with the preset method in the source database and the target database respectively to obtain comparative test results, wherein the preset method is associated with the structured query statements based on a data mapping annotation;

[0037] The adaptation unit is used to modify the syntax of the target structure query statement that is not compatible with the target database according to the comparison test result, so as to adapt to the target database.

[0038] In some embodiments, the apparatus further comprises:

[0039] The replacement unit is used to perform adaptation identification on the to-be-executed structure query statement and replace the incompatible to-be-executed structure query statement before the target database runs the to-be-executed structure query statement.

[0040] In some embodiments, the acquisition unit includes:

[0041] A scanning module, used for scanning and obtaining class files in the file package and its sub-file packages in a recursive manner;

[0042] The acquisition module is used to acquire the preset method in the class file, wherein the preset method is associated with the structure query statement in the extensible markup file based on the data mapping annotation.

[0043] In some embodiments, the testing unit comprises:

[0044] A generation module, used to obtain the parameter type in the preset method and generate corresponding query parameters according to the parameter type;

[0045] A testing module, used for inputting the query parameters into the source database and the target database respectively to perform query testing on the structure query statement associated with the preset method;

[0046] The determination module is used to perform comparison processing based on the query results corresponding to the source database and the target database, determine whether the structured query statement is compatible with the target database, and generate the comparison test result.

[0047] In some embodiments, the generating module is further configured to:

[0048] Based on the parameter type, generate an empty query parameter corresponding to the parameter type;

[0049] Input the empty query parameter into the source database to perform a query, and obtain a complete query result, wherein the complete query result is a set of all data satisfying the source database;

[0050] The query fields in the complete query result are assigned values ​​to generate the query parameters.

[0051] In some embodiments, the adaptation unit comprises:

[0052] A first judgment module is used to judge whether the target structure query statement can be modified into a target syntax format adapted to both the source database and the target database;

[0053] A modification module, used for modifying the target structure query statement into the target grammatical format when it can be modified into the target grammatical format;

[0054] The establishing module is used to establish an association relationship between the target structure query statement and a structure query statement with the same function in the target database when the target grammatical format cannot be modified.

[0055] In some embodiments, the establishing module is further configured to:

[0056] Generate a first identifier of the target structure query statement in the source database, and a second identifier of the structure query statement with the same function in the target database;

[0057] Based on the first identifier and the second identifier, an association relationship between the target structure query statement and a structure query statement with the same function in the target database is established.

[0058] In some embodiments, the replacement unit comprises:

[0059] A second judgment module is used to judge whether the to-be-executed structure query statement needs to be replaced based on a preset replacement rule;

[0060] A replacement module, used to replace the to-be-executed structure query statement when it is determined that replacement is required;

[0061] The execution module is used to continue executing the to-be-executed structure query statement when it is determined that no replacement is needed.

[0062] In some embodiments, the second determination module is further configured to:

[0063] Based on the preset replacement rule, it is determined whether there is at least one of the keywords, table names, and library names that need to be replaced in the to-be-executed structure query statement, wherein the preset replacement rule represents a correspondence between the source database and the target database between any one of the keywords, table names, and library names that need to be replaced.

[0064] According to a third aspect of the present disclosure, there is provided an electronic device, including:

[0065] at least one processor; and

[0066] a memory communicatively connected to the at least one processor; wherein,

[0067] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method described in the first aspect.

[0068] According to a fourth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute the method described in the first aspect.

[0069] According to a fifth aspect of the present disclosure, a computer program product is provided, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the method as described in the first aspect above.

[0070] The present disclosure provides a method and device, electronic device and storage medium for database adaptation and compatibility, which scans the file package and / or class file in the source database to obtain the preset method in the file package and / or the class file; performs query test on the structure query statement associated with the preset method in the source database and the target database respectively to obtain the comparison test result, wherein the preset method is associated with the structure query statement based on the data mapping annotation; according to the comparison test result, the target structure query statement that is not compatible with the target database is subjected to grammatical modification to adapt to the target database. Compared with the related art, the present disclosure can detect the structure query statement in the source database that is not compatible with the target database, and can test whether the structure query statement meets the grammatical requirements of the target database; by adapting and modifying the incompatible structure query statement, the influence of adapting the target database on the business logic can be effectively reduced.

[0071] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present application, nor is it intended to limit the scope of the present application. Other features of the present application will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0072] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.

[0073] Figure 1 A flowchart of a method for database adaptation and compatibility provided by an embodiment of the present disclosure;

[0074] Figure 2 A flowchart of another database adaptation and compatibility method provided by an embodiment of the present disclosure;

[0075] Figure 3 A technical framework for a database adaptation and compatibility method;

[0076] Figure 4 It is a flowchart of a SQL statement scanning method;

[0077] Figure 5 It is a flowchart of a SQL statement testing method;

[0078] Figure 6 A flowchart of a method for intercepting and replacing SQL statements;

[0079] Figure 7 A schematic diagram of the structure of a database adaptation and compatibility device provided in an embodiment of the present disclosure;

[0080] Figure 8 A schematic diagram of the structure of another database adaptation and compatibility device provided in an embodiment of the present disclosure;

[0081] Fig. 9 A schematic block diagram of an exemplary electronic device provided for an embodiment of the present disclosure. DETAILED DESCRIPTION

[0082] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.

[0083] The following describes the database adaptation and compatibility method and device, electronic device and storage medium of the embodiments of the present disclosure with reference to the accompanying drawings.

[0084] Figure 1 A flowchart of a method for database adaptation and compatibility provided in an embodiment of the present disclosure.

[0085] like Figure 1 As shown, the method comprises the following steps:

[0086] Step 101 : Scan the file packages and / or class files in the source database to obtain the preset methods in the file packages and / or the class files.

[0087] In the embodiments of the present disclosure, the source database is an existing database that contains structured query statements (SQL statements) and other related data. These SQL statements need to be adapted and adjusted in the new database (i.e., the target database) to adapt to the structure, rules, and characteristics of the new database. When adapting, it is necessary to ensure that the data and functions in the source database are fully and consistently reflected in the target database.

[0088] Perform a deep scan in the source database to identify and locate all relevant file packages and class files. These file packages and class files should contain preset methods, which are functions or methods defined in the program. These methods are necessary to implement specific operations or achieve specific functions in the database. These preset methods are associated with specific SQL statements in the XML file through annotations. After scanning these methods, the program can be used to simulate the data generated in the business, and a large amount of test data can be generated for different field attributes between databases. By triggering the execution of SQL statements, it is possible to test whether the SQL statements can adapt to the new target database.

[0089] Step 102 , querying and testing the structured query statements associated with the preset method in the source database and the target database respectively to obtain comparative test results, wherein the preset method is associated with the structured query statements based on data mapping annotations.

[0090] In an embodiment of the present disclosure, in order to ensure that the SQL statements of the source database can be successfully executed in the target database, it is necessary to conduct a comprehensive test on the source database and the target database. By executing the structure query statements associated with the preset method in the two databases respectively, the test results can be compared and the inconsistencies therein can be found. The test may include but is not limited to the execution efficiency of the SQL statements, the accuracy of the returned data, the grammatical structure and other aspects to ensure that the SQL statements in the source database can be normally executed in the target database and produce the expected results. By comparing the test results, the differences between the source database and the target database when processing the same query can be found. These differences may be due to factors such as the internal implementation of the database, version differences, configuration settings, etc. Any mismatches or errors found can be repaired and adjusted in a timely manner to ensure the smooth progress of data migration.

[0091] This testing method not only helps to identify potential problems, but also provides valuable feedback to developers, helping them better understand the characteristics and limitations of the target database. By comparing test results, developers can better understand the problems and challenges that may be encountered during the database migration process, and thus develop more effective solutions.

[0092] Step 103: According to the comparison test result, the target structure query statement that is not compatible with the target database is grammatically modified to adapt to the target database.

[0093] In the embodiments of the present disclosure, due to the possible differences between the source database and the target database, some structured query statements may not be executed normally in the target database. In order to ensure that the SQL statements of the source database can be successfully executed in the target database, it is necessary to modify the syntax of the structured query statements associated with the preset method to make them compatible with the target database. It is necessary to carefully analyze the comparison test results to find out the SQL statements that do not match or are wrong. These statements may be caused by syntax differences, data type mismatches, unsupported functions, etc. Next, according to the syntax rules and characteristics of the target database, these statements are appropriately modified. This may include but is not limited to operations such as adjusting the structure of the query statement, replacing unsupported functions, and modifying data types. During the modification process, the performance and constraints of the target database also need to be considered. For example, the target database may have features such as indexes, triggers, and stored procedures, and the SQL statements need to be adjusted accordingly to make full use of these features. In addition, it is also necessary to ensure that the modified statements can be efficiently executed in the target database to meet business needs.

[0094] The present disclosure provides a method for database adaptation and compatibility, which includes scanning a file package and / or a class file in a source database to obtain a preset method in the file package and / or the class file; performing query tests on the structure query statements associated with the preset method in the source database and the target database respectively to obtain comparative test results, wherein the preset method is associated with the structure query statement based on a data mapping annotation; according to the comparative test results, performing grammatical modification on the target structure query statement that is not compatible with the target database to adapt to the target database; before the target database runs the structure query statement to be executed, performing adaptation and identification on the structure query statement to be executed and replacing the incompatible structure query statement to be executed. Compared with the related art, the present disclosure can detect the structure query statement in the source database that is not compatible with the target database, and can test whether the structure query statement meets the grammatical requirements of the target database; by performing adaptation and modification on the incompatible structure query statement, the influence of the adaptation target database on the business logic can be effectively reduced.

[0095] In some embodiments of the present disclosure, in order to achieve dynamic real-time update of the grammar library and ensure that the structured query statement can be correctly executed normally in the target database, before the target database runs the structured query statement to be executed, the structured query statement to be executed is adapted and identified and the unmatched structured query statement to be executed is replaced.

[0096] In the disclosed embodiment, in the database migration process, it is not enough to simply modify the structure query statement associated with the preset method. In order to ensure the stable operation of the target database, we also need to adapt, identify and replace all the structure query statements to be executed before execution. By building an adaptation identification mechanism, the mechanism can automatically scan the structure query statements to be executed in the target database, and check whether they are compatible with the target database. This may include but is not limited to multiple aspects such as syntax analysis, semantic inspection, performance evaluation, etc. Through this mechanism, unmatched structure query statements can be found in time, and corresponding measures can be taken to repair or replace. Once unmatched structure query statements are found, it is necessary to repair or replace them in time according to the characteristics and requirements of the target database. This may include but is not limited to operations such as adjusting the structure of the query statement, modifying the data type, replacing unsupported functions, etc. Through these modifications, it can be ensured that the structure query statement to be executed can be correctly executed in the target database and produce expected results.

[0097] In order to clearly illustrate the embodiment of the present disclosure, this embodiment provides a flowchart of another method for database adaptation and compatibility.

[0098] like Figure 2 As shown, the method comprises the following steps:

[0099] Step 201 : Scan the file packages and / or class files in the source database to obtain the preset methods in the file packages and / or class files.

[0100] Figure 3 It is a technical framework for a database adaptation and compatibility method. The microservice model is widely used in microservices. There are a large number of SQL statements in each microservice that process business logic and act on the target database through the database connection layer. When the target database changes, the corresponding database connection properties are often modified at the database connection layer, but the changed database may not be compatible with the SQL statements in the microservice. Therefore, before officially switching the database, the SQL is tested in the test environment. The test process includes Mapper scanning, test SQL statement generation, and transaction rollback after the SQL statement test to prevent the test SQL statement from generating dirty data or modifying the real data. Then analyze the failed SQL statements in the test results to determine whether they can be modified to a form that is compatible with both the source database and the target database. If not, it is necessary to add database tags in the SQL statements to enable the system to execute different SQL statements according to the connected database. For some common modification methods, SQL interception and replacement can be used to achieve full SQL adaptation to avoid repeated adaptation of SQL statements.

[0101] Specifically in step 201, usually in microservices under the microservice model, a persistence layer framework is often used to achieve connection with the database and data operations. MyBatis is a widely used persistence layer framework that supports customized SQL, stored procedures, and advanced mapping, and almost avoids all JDBC codes and manual parameter settings and result set acquisition. Simple XML or annotations can be used to configure and map native information, and map interfaces and Java objects into records in the database.

[0102] Figure 4 This is a flowchart of a SQL statement scanning method. This application proposes a SQL method scanning solution based on the introduction of Mybatis, which supports users to scan a certain file package, or specify all methods under a certain Java class. When the file package contains sub-file packages, all methods under the package can be obtained recursively. These methods are associated with specific SQL statements in XML files through the @Mapper annotation. After scanning these methods, the data generated in the business can be simulated by the program, and a large amount of test data can be generated for different field attributes between databases. By triggering the execution of SQL statements, it is tested whether the SQL statements can adapt to the new target database.

[0103] Step 202: Obtain the parameter type in the preset method, and generate corresponding query parameters according to the parameter type.

[0104] Step 2021: Based on the parameter type, generate an empty query parameter corresponding to the parameter type.

[0105] Step 2022: input the empty query parameter into the source database for query to obtain a complete query result, wherein the complete query result is a set of all data satisfying the source database.

[0106] Step 2023: assign values ​​to the query fields in the complete query result to generate the query parameters.

[0107] Specifically, in step 202, the randomly generated query parameters may not be consistent with the business, resulting in the query result being empty and unable to verify whether the business logic has been changed. When generating query parameters, this solution will generate a test process with empty query parameters. When the query parameters are empty, SQL will obtain the complete query results, and then find the fields that are the same as the query parameters from the query results to obtain the values ​​of the query parameters, so as to ensure that the query parameters comply with normal business processes. Secondly, the query parameters will be arranged and combined according to the number to simulate the query conditions in different business scenarios.

[0108] Step 203: input the query parameters into the source database and the target database respectively to perform query testing on the structure query statement associated with the preset method.

[0109] Step 204 , performing comparison processing based on the query results corresponding to the source database and the target database, determining whether the structured query statement is compatible with the target database, and generating the comparison test result.

[0110] Specifically, in step 203 to step 204, Figure 5 The figure is a flowchart of a SQL statement testing method. The interface methods corresponding to all SQL statements in the microservice can be obtained through the above SQL scanning steps. The next step is to obtain the corresponding parameters and return bodies in the interface methods. The corresponding input parameter objects and return body objects can be generated according to the parameters and return bodies. The existing testing scheme randomly generates a set of input parameter objects according to different parameter types to test SQL statements. The randomly generated input parameters do not take into account the actual values ​​in the business, and the test results are often empty. This type of test can only reflect whether the SQL statement meets the grammatical requirements of the target database, and cannot test whether the modified or adapted SQL statement is consistent with the original business logic. Therefore, this scheme will match the attributes in the query results with the input parameter attributes, and use the values ​​in the query results as the input parameters for the test. This can effectively test whether the business logic in SQL is consistent with the original business logic. The specific steps are as follows: Figure 3 As shown:

[0111] First, get the parameter type in the method, and use different random generation methods to generate different query parameters according to different parameter types; then pass the query parameters into the SQL method to execute in the source database and the target database respectively, and get the query results; then record the query results corresponding to different query parameters in the two databases respectively; then roll back the SQL statement through the transaction to prevent the test data from affecting the production data; finally, compare whether the query results corresponding to the same query parameters in different databases are consistent. If they are consistent, it means that the current SQL can adapt to the target database. If they are inconsistent, it means that the current SQL does not support the target database, or the adapted SQL is inconsistent with the business logic expressed by the original SQL, and needs to be modified.

[0112] Step 205: determine whether the target structure query statement can be modified into a target syntax format that is compatible with both the source database and the target database.

[0113] If it can be modified to the target syntax format, execute step 206; if it cannot be modified to the target syntax format, execute step 207.

[0114] Step 206: modify the target structure query statement into the target grammatical format.

[0115] Step 207: establishing an association relationship between the target structure query statement and a structure query statement with the same function in the target database.

[0116] As an implementable manner of an embodiment of the present disclosure, the establishment of an association relationship between the target structure query statement and a structure query statement with the same function in the target database may be carried out in, but not limited to, the following manner: generating a first identifier of the target structure query statement in the source database and a second identifier of the structure query statement with the same function in the target database; and establishing an association relationship between the target structure query statement and a structure query statement with the same function in the target database based on the first identifier and the second identifier.

[0117] Specifically, in step 206 to step 207, after the above-mentioned SQL test steps, the comparison test results of the SQL statements in the microservice in the MySQL database (source database) and the PgSQL database (target database) can be obtained. For the SQL statements that fail the test results on the PgSQL database, it is necessary to adapt and transform them according to the grammatical rules supported by PgSQL. First, consider whether the original SQL statements can be modified to a format supported by both the source database and the target database. If not, configure the source database id and the target database id in the database configuration of the microservice at the same time, and add the databaseId="postgresql" tag to the SQL statements that need additional adaptation in the xml file of mybatis, so that the service will automatically select the corresponding SQL statement for execution when connecting to the PgSQL database. This can greatly reduce the number of SQL statements that need to be adapted, and only adapt and transform the incompatible SQL.

[0118] Step 208: Based on a preset replacement rule, determine whether the to-be-executed structure query statement needs to be replaced.

[0119] As an implementable manner of an embodiment of the present disclosure, the determining whether the to-be-executed structure query statement needs to be replaced based on a preset replacement rule may be performed in, but not limited to, the following manner: determining whether there is at least one of the keywords, table names, and library names that need to be replaced in the to-be-executed structure query statement based on the preset replacement rule, wherein the preset replacement rule represents the correspondence between any one of the keywords, table names, and library names that need to be replaced between the source database and the target database.

[0120] If it is determined that replacement is required, the to-be-executed structure query statement is replaced; if it is determined that replacement is not required, the to-be-executed structure query statement continues to be executed.

[0121] Specifically, in step 208, Figure 6 This is a flow chart of a method for intercepting and replacing SQL statements. After the above SQL adaptation steps, the microservice can adapt to both MySQL and PgSQL databases. Even if new problems are found during the database switching process, or the database service fails to provide services on time, it can be switched back to the source database in time, so as not to affect the normal external service of the microservice. However, with the continuous development of technology, database services will continue to upgrade versions. In order to avoid the need for microservices to follow the changes brought about by database service upgrades, this solution introduces an SQL interception strategy, which can replace the SQL statements generated in the microservices according to the interception strategy before execution to achieve dynamic adaptation of the target database. First, obtain the SQL statement to be executed, and read the configured interception and replacement strategy at the same time to determine whether the SQL statement contains keywords, table names or library names that need to be replaced. If so, replace them according to the strategy. If not, execute the SQL statement directly.

[0122] It should be noted that the embodiments of the present disclosure may include multiple steps. For the convenience of description, these steps are numbered, but these numbers do not limit the execution time slots or execution order between the steps; these steps can be implemented in any order, and the embodiments of the present disclosure do not limit this.

[0123] Corresponding to the above database adaptation and compatibility method, the present invention also provides a database adaptation and compatibility device. Since the device embodiment of the present invention corresponds to the above method embodiment, the details not disclosed in the device embodiment can be referred to the above method embodiment, and will not be repeated in the present invention.

[0124] Figure 7 A schematic diagram of a database adaptation and compatibility device provided in an embodiment of the present disclosure, such as Figure 7 As shown, including:

[0125] An acquisition unit 31 is used to scan a file package and / or a class file in a source database to acquire a preset method in the file package and / or the class file;

[0126] A testing unit 32, configured to perform query tests on the structured query statements associated with the preset method in the source database and the target database respectively to obtain comparative test results, wherein the preset method is associated with the structured query statements based on a data mapping annotation;

[0127] The adaptation unit 33 is used to modify the syntax of the target structure query statement that is not compatible with the target database according to the comparison test result, so as to adapt to the target database.

[0128] The present disclosure provides a device for database adaptation and compatibility, which scans the file package and / or class file in the source database to obtain the preset method in the file package and / or the class file; performs query test on the structure query statement associated with the preset method in the source database and the target database respectively to obtain the comparison test result, wherein the preset method is associated with the structure query statement based on the data mapping annotation; according to the comparison test result, the target structure query statement that is not compatible with the target database is grammatically modified to adapt to the target database; before the target database runs the structure query statement to be executed, the structure query statement to be executed is adapted and identified and the incompatible structure query statement to be executed is replaced. Compared with the related art, the present disclosure can detect the structure query statement in the source database that is not compatible with the target database, and can test whether the structure query statement meets the grammatical requirements of the target database; by adapting and modifying the incompatible structure query statement, the influence of adapting the target database on the business logic can be effectively reduced.

[0129] Furthermore, in a possible implementation of this embodiment, Figure 8 As shown, the device also includes:

[0130] The replacement unit 34 is used to perform adaptation identification on the to-be-executed structure query statement and replace the incompatible to-be-executed structure query statement before the target database runs the to-be-executed structure query statement.

[0131] Furthermore, in a possible implementation of this embodiment, Figure 8 As shown, the acquisition unit 31 includes:

[0132] A scanning module 311 is used to scan and obtain class files in the file package and its sub-file packages in a recursive manner;

[0133] The acquisition module 312 is used to acquire the preset method in the class file, wherein the preset method is associated with the structure query statement in the extensible markup file based on the data mapping annotation.

[0134] Furthermore, in a possible implementation of this embodiment, Figure 8 As shown, the testing unit 32 includes:

[0135] A generating module 321, used to obtain the parameter type in the preset method and generate corresponding query parameters according to the parameter type;

[0136] A testing module 322, used to input the query parameters into the source database and the target database respectively to perform query testing on the structure query statement associated with the preset method;

[0137] The determination module 323 is used to perform comparison processing based on the query results corresponding to the source database and the target database, determine whether the structured query statement is compatible with the target database, and generate the comparison test result.

[0138] Furthermore, in a possible implementation of this embodiment, the generating module 321 is further configured to:

[0139] Based on the parameter type, generate an empty query parameter corresponding to the parameter type;

[0140] Input the empty query parameter into the source database to perform a query, and obtain a complete query result, wherein the complete query result is a set of all data satisfying the source database;

[0141] The query fields in the complete query result are assigned values ​​to generate the query parameters.

[0142] Furthermore, in a possible implementation of this embodiment, Figure 8 As shown, the adaptation unit 33 includes:

[0143] The first judgment module 331 is used to judge whether the target structure query statement can be modified into a target syntax format adapted by both the source database and the target database;

[0144] A modification module 332, configured to modify the target structure query statement into the target grammatical format when it can be modified into the target grammatical format;

[0145] The establishing module 333 is used to establish an association relationship between the target structure query statement and a structure query statement with the same function in the target database when the target grammatical format cannot be modified.

[0146] Furthermore, in a possible implementation of this embodiment, Figure 8 As shown, the establishment module 333 is also used for:

[0147] Generate a first identifier of the target structure query statement in the source database, and a second identifier of the structure query statement with the same function in the target database;

[0148] Based on the first identifier and the second identifier, an association relationship between the target structure query statement and a structure query statement with the same function in the target database is established.

[0149] Furthermore, in a possible implementation of this embodiment, Figure 8 As shown, the replacement unit 34 includes:

[0150] The second judgment module 341 is used to judge whether the to-be-executed structure query statement needs to be replaced based on a preset replacement rule;

[0151] A replacement module 342 is used to replace the to-be-executed structure query statement when it is determined that replacement is required;

[0152] The execution module 343 is used to continue executing the to-be-executed structure query statement when it is determined that no replacement is required.

[0153] Furthermore, in a possible implementation of this embodiment, the second determining module 341 is further configured to:

[0154] Based on the preset replacement rule, it is determined whether there is at least one of the keywords, table names, and library names that need to be replaced in the to-be-executed structure query statement, wherein the preset replacement rule represents a correspondence between the source database and the target database between any one of the keywords, table names, and library names that need to be replaced.

[0155] It should be noted that the above explanation of the method embodiment is also applicable to the device of this embodiment, and the principle is the same, which is not limited in this embodiment.

[0156] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.

[0157] Fig. 9 A schematic block diagram of an example electronic device 400 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.

[0158] like Fig. 9As shown, the device 400 includes a computing unit 401, which can perform various appropriate actions and processes according to a computer program stored in a ROM (Read-Only Memory) 402 or a computer program loaded from a storage unit 408 to a RAM (Random Access Memory) 403. In the RAM 403, various programs and data required for the operation of the device 400 can also be stored. The computing unit 401, the ROM 402, and the RAM 403 are connected to each other via a bus 404. An I / O (Input / Output) interface 405 is also connected to the bus 404.

[0159] A number of components in the device 400 are connected to the I / O interface 405, including: an input unit 406, such as a keyboard, a mouse, etc.; an output unit 407, such as various types of displays, speakers, etc.; a storage unit 408, such as a disk, an optical disk, etc.; and a communication unit 409, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 409 allows the device 400 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0160] The computing unit 401 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 401 include, but are not limited to, a CPU (Central Processing Unit), a GPU (Graphic Processing Units), various dedicated AI (Artificial Intelligence) computing chips, various computing units running machine learning model algorithms, DSP (Digital Signal Processor), and any appropriate processor, controller, microcontroller, etc. The computing unit 401 performs the various methods and processes described above, such as a database adaptation and compatibility method. For example, in some embodiments, the database adaptation and compatibility method may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 408. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 400 via the ROM 402 and / or the communication unit 409. When the computer program is loaded into the RAM 403 and executed by the computing unit 401, one or more steps of the method described above may be performed. Alternatively, in other embodiments, the computing unit 401 may be configured to execute the aforementioned database adaptation and compatibility method in any other appropriate manner (for example, by means of firmware).

[0161] Various embodiments of the systems and techniques described above herein may be implemented in digital electronic circuit systems, integrated circuit systems, FPGAs (Field Programmable Gate Arrays), ASICs (Application-Specific Integrated Circuits), ASSPs (Application Specific Standard Products), SOCs (System On Chips), CPLDs (Complex Programmable Logic Devices), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include: being implemented in one or more computer programs that may be executed and / or interpreted on a programmable system including at least one programmable processor that may be a dedicated or general-purpose programmable processor that may receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0162] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0163] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. More specific examples of machine-readable storage media may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a RAM, a ROM, an EPROM (Electrically Programmable Read-Only-Memory) or a flash memory, an optical fiber, a CD-ROM (Compact Dis sc Read-Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0164] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (Cathode-Ray Tube) or LCD (Liquid Crystal Display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0165] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: LAN (Local Area Network), WAN (Wide Area Network), the Internet, and blockchain networks.

[0166] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship between the client and the server is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services ("Virtual Private Server", or "VPS" for short). The server may also be a server of a distributed system, or a server combined with a blockchain.

[0167] It should be noted that artificial intelligence is a discipline that studies how computers can simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, planning, etc.), and includes both hardware-level and software-level technologies. Artificial intelligence hardware technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, and big data processing; artificial intelligence software technologies mainly include computer vision technology, speech recognition technology, natural language processing technology, as well as machine learning / deep learning, big data processing technology, knowledge graph technology, and other major directions.

[0168] The various numerical numbers such as first and second involved in the present disclosure are only for the convenience of description and are not used to limit the scope of the embodiments of the present disclosure, but also indicate the order of precedence.

[0169] At least one in the present disclosure may also be described as one or more, and a plurality may be two, three, four or more, which is not limited in the present disclosure. In the embodiments of the present disclosure, for a technical feature, the technical features in the technical feature are distinguished by "first", "second", "third", "A", "B", "C" and "D", etc., and there is no order of precedence or size between the technical features described by the "first", "second", "third", "A", "B", "C" and "D".

[0170] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.

[0171] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.

Claims

1. A method for database adaptation and compatibility, characterized in that: include: Scan the file packages and / or class files in the source database to obtain the preset methods in the file packages and / or class files; Perform query tests on the structured query statements associated with the preset method in the source database and the target database respectively to obtain comparative test results, wherein the preset method is associated with the structured query statements based on data mapping annotations; According to the comparison test result, the target structure query statement that is not compatible with the target database is grammatically modified to adapt to the target database.

2. The method according to claim 1, characterized in that The method further comprises: Before the target database runs the structure query statement to be executed, the structure query statement to be executed is adapted and identified, and the incompatible structure query statement to be executed is replaced.

3. The method according to claim 1, characterized in that The structure query statement associated with the preset method is respectively subjected to query test in the source database and the target database to obtain comparative test results, including: Obtaining the parameter type in the preset method, and generating corresponding query parameters according to the parameter type; Inputting the query parameters into the source database and the target database respectively to perform query testing on the structure query statement associated with the preset method; A comparison process is performed based on the query results corresponding to the source database and the target database, to determine whether the structured query statement is compatible with the target database, and to generate the comparison test result.

4. The method according to claim 3, characterized in that The obtaining of the parameter type in the preset method and generating corresponding query parameters according to the parameter type includes: Based on the parameter type, generate an empty query parameter corresponding to the parameter type; Input the empty query parameter into the source database to perform a query, and obtain a complete query result, wherein the complete query result is a set of all data satisfying the source database; The query fields in the complete query result are assigned values ​​to generate the query parameters.

5. The method according to claim 1, characterized in that: According to the comparison test result, the target structure query statement that is not compatible with the target database is grammatically modified to adapt to the target database, including: Determining whether the target structure query statement can be modified into a target syntax format that is adapted to both the source database and the target database; If it can be modified into the target grammatical format, modifying the target structure query statement into the target grammatical format; If the target syntax format cannot be modified, an association relationship is established between the target structure query statement and a structure query statement with the same function in the target database.

6. The method according to claim 5, characterized in that The establishing of an association relationship between the target structure query statement and a structure query statement with the same function in the target database includes: Generate a first identifier of the target structure query statement in the source database, and a second identifier of the structure query statement with the same function in the target database; Based on the first identifier and the second identifier, an association relationship between the target structure query statement and a structure query statement with the same function in the target database is established.

7. The method according to claim 2, characterized in that: The step of adapting and identifying the to-be-executed structure query statements and replacing the incompatible to-be-executed structure query statements includes: Based on a preset replacement rule, determining whether the to-be-executed structure query statement needs to be replaced; If it is determined that replacement is required, the to-be-executed structure query statement is replaced; If it is determined that no replacement is required, the to-be-executed structure query statement continues to be executed.

8. The method according to claim 7, characterized in that The step of judging whether the to-be-executed structure query statement needs to be replaced based on a preset replacement rule includes: Based on the preset replacement rule, it is determined whether there is at least one of the keywords, table names, and library names that need to be replaced in the to-be-executed structure query statement, wherein the preset replacement rule represents a correspondence between the source database and the target database between any one of the keywords, table names, and library names that need to be replaced.

9. A database adaptation and compatibility device, characterized in that: include: An acquisition unit, configured to scan a file package and / or a class file in a source database to acquire a preset method in the file package and / or the class file; A testing unit, used for performing query tests on the structured query statements associated with the preset method in the source database and the target database respectively to obtain comparative test results, wherein the preset method is associated with the structured query statements based on a data mapping annotation; The adaptation unit is used to modify the syntax of the target structure query statement that is not compatible with the target database according to the comparison test result, so as to adapt to the target database.

10. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 8.

11. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-8.

12. A computer program product, characterized in that The invention comprises a computer program which, when executed by a processor, implements the method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Method and device for comparing transaction functions in database migration

    CN111090638A

  • Database migration evaluation method and system, computer equipment and storage medium

    CN115408370A

  • Query statement processing method and device, equipment and storage medium

    CN115794858A

  • Compatible processing method and device of database, equipment and medium

    CN118069622A

Cited By

  • Cross-database operation method

    CN119293018A

  • Data comparison method, device and equipment and computer readable medium

    CN120316140A

  • Data comparison method, apparatus, device, and computer-readable medium

    CN120316140B