A database conversion method, apparatus, device, medium and program product

By automatically identifying and converting SQL statements from Oracle databases to SQL statements from MySQL databases, the problem of tedious manual modification and high error rates in existing technologies has been solved, achieving efficient database conversion and improving system upgrade efficiency.

CN116756173BActive Publication Date: 2026-07-03CHINA CONSTRUCTION BANK +1
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
CHINA CONSTRUCTION BANK
Filing Date
2023-06-21
Publication Date
2026-07-03

AI Technical Summary

Technical Problem

Existing technologies for replacing Oracle databases with MySQL databases suffer from the problems of tedious, inefficient, and error-prone manual modification of SQL statements. Existing tools have limited functionality and low conversion efficiency, making it difficult to meet actual needs.

Method used

By obtaining SQL statements from the source database, parsing and identifying the keywords to be converted, and automatically converting them into SQL statements for the target database using preset conversion strategies or historical conversion records, conversion strategies are generated for keywords without preset conversion strategies, thus achieving automatic database conversion.

Benefits of technology

It improved the success rate and efficiency of database conversion, reduced labor and time costs, reduced the occurrence of modification errors, and improved system upgrade efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116756173B_ABST
    Figure CN116756173B_ABST
Patent Text Reader

Abstract

This invention relates to the field of database technology, specifically a database conversion method, apparatus, device, medium, and program product. The method includes: obtaining a source SQL statement to be converted from a source database; obtaining conversion strategies corresponding to each keyword to be converted in the source SQL statement, and determining whether conversion strategies corresponding to all keywords to be converted can be obtained; if not, identifying a first keyword to be converted for which no conversion strategy has been obtained, and obtaining a historical conversion record corresponding to the first keyword to be converted; wherein the historical conversion record records conversion operations that convert the first keyword to be converted into a first target keyword in the target database; and converting each keyword to be converted in the source SQL statement based on the conversion strategy or the historical conversion record to obtain a target SQL statement in the target database. The conversion method of this invention can greatly improve the success rate and efficiency of automatic database conversion.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of database technology, and in particular to a database conversion method, apparatus, device, medium, and program product. Background Technology

[0002] With the rapid development of internet applications and the growing demand for internet-enabled, open-source, and distributed software, it is often necessary to upgrade existing legacy systems. However, after the upgrade, the new system may be incompatible with the original database, thus requiring database conversion. For example, replacing an Oracle database with a MySQL database.

[0003] Currently, the common practice of replacing Oracle databases with MySQL databases involves manually locating the Extensible Markup Language (XML) files that need to be replaced. Based on the differences between MySQL and Oracle databases, each Structured Query Language (SQL) statement in the XML file is examined, modified, and then a new version is released to test the changes. This process is tedious, requires significant manpower and time, and the skill levels of developers vary, meaning they may not be able to identify all the SQL statements that need modification. Furthermore, because it is done manually, errors are highly likely to occur (such as common spelling mistakes, incorrect symbol formats, etc.).

[0004] In addition, although database conversion tools exist on the market, existing database conversion tools have limited functionality, do not provide conversion functions for stored procedures and other parts, and have low conversion efficiency, making it difficult to meet the needs of actual work. Summary of the Invention

[0005] In view of the above-mentioned problems in the prior art, the purpose of the present invention is to provide a database conversion method, apparatus, device, medium and program product that can realize automatic database conversion and greatly improve the success rate and efficiency of automatic database conversion.

[0006] To address the above problems, this invention provides a database conversion method, comprising:

[0007] Retrieve the source SQL statement to be converted from the source database;

[0008] Obtain the conversion strategy corresponding to each keyword to be converted in the source SQL statement, and determine whether the conversion strategies corresponding to all keywords to be converted can be obtained;

[0009] If not, it is determined that the first keyword to be converted by the conversion strategy has not been obtained, and the historical conversion record corresponding to the first keyword to be converted is obtained; wherein, the historical conversion record records the conversion operation of converting the first keyword to be converted into the first target keyword in the target database;

[0010] Based on the conversion strategy or the historical conversion records, each keyword to be converted in the source SQL statement is converted to obtain the target SQL statement in the target database.

[0011] Furthermore, obtaining the source SQL statement to be converted from the source database includes:

[0012] Obtain the SQL file to be converted from the source database and read the SQL statements in the SQL file;

[0013] Determine whether the SQL statement needs to be converted.

[0014] If so, the SQL statement will be used as the source SQL statement to be converted.

[0015] Further, the step of obtaining the conversion strategies corresponding to each keyword to be converted in the source SQL statement, and determining whether all conversion strategies corresponding to the keywords to be converted can be obtained, includes:

[0016] The source SQL statement is parsed to determine the individual keywords to be converted in the source SQL statement;

[0017] For each keyword to be converted, the conversion strategy corresponding to the keyword is searched from the preset configuration file;

[0018] If a corresponding conversion strategy can be found for each of the keywords to be converted in the configuration file, then it is determined that the conversion strategies corresponding to all the keywords to be converted can be obtained.

[0019] If any of the keywords to be converted cannot be found in the configuration file, then it is determined that the conversion strategies corresponding to all the keywords to be converted cannot be obtained.

[0020] Further, the conversion of each keyword to be converted in the source SQL statement based on the conversion strategy or the historical conversion records includes:

[0021] For the first keyword to be converted for which no conversion strategy has been obtained, a corresponding conversion strategy is generated based on the historical conversion records corresponding to the first keyword to be converted, and the first keyword to be converted is converted into the first target keyword in the target database based on the generated conversion strategy;

[0022] For the second keyword to be converted based on the obtained conversion strategy, the second keyword to be converted is converted into the second target keyword in the target database based on the obtained conversion strategy.

[0023] Furthermore, the method also includes:

[0024] Determine if it is possible to obtain all historical conversion records corresponding to the first keyword to be converted;

[0025] If so, then the step of converting the corresponding keyword to be converted based on the conversion strategy or the historical conversion record is executed;

[0026] If not, record the source SQL statement to be converted and annotate it.

[0027] Furthermore, the method also includes:

[0028] The target SQL statement is validated to determine its correctness;

[0029] If the target SQL statement passes the validation, the target SQL statement will be displayed.

[0030] Another aspect of the present invention provides a database conversion apparatus, comprising:

[0031] The statement retrieval module is used to retrieve the source SQL statements to be converted from the source database;

[0032] The conversion strategy acquisition module is used to acquire the conversion strategy corresponding to each keyword to be converted in the source SQL statement, and to determine whether the conversion strategies corresponding to all keywords to be converted can be acquired.

[0033] The conversion record acquisition module is used to determine the first keyword to be converted for which no conversion strategy has been obtained when it is determined that the conversion strategy corresponding to all keywords to be converted cannot be obtained, and to acquire the historical conversion record corresponding to the first keyword to be converted; wherein, the historical conversion record records the conversion operation of converting the first keyword to be converted into the first target keyword in the target database;

[0034] The conversion module is used to convert each keyword to be converted in the source SQL statement based on the conversion strategy or the historical conversion records, so as to obtain the target SQL statement in the target database.

[0035] In another aspect, the present invention provides an electronic device including a processor and a memory, wherein the memory stores at least one instruction or at least one program, the at least one instruction or the at least one program being loaded and executed by the processor to implement the database conversion method as described above.

[0036] In another aspect, the present invention provides a computer-readable storage medium storing at least one instruction or at least one program, wherein the at least one instruction or the at least one program is loaded and executed by a processor to implement the database conversion method described above.

[0037] In another aspect, the present invention provides a computer program product, including a computer program / instructions that, when executed by a processor, implement the steps of the database conversion method described above.

[0038] Due to the above technical solution, the present invention has the following beneficial effects:

[0039] According to the database conversion method of this invention, by pre-setting a conversion strategy, during the database conversion process, each keyword to be converted in the source SQL statement can be converted based on the preset conversion strategy to obtain the target SQL statement in the target database. This achieves automatic database conversion, reduces the workload of manual conversion by developers, greatly improves database conversion efficiency, saves manpower and time costs, and effectively solves the problem of low system upgrade efficiency. For keywords to be converted that do not have a preset conversion strategy, a corresponding conversion strategy is automatically generated by parsing the corresponding historical conversion records. Then, the keyword to be converted is converted according to the generated conversion strategy, which can greatly improve the success rate and efficiency of automatic database conversion. Attached Figure Description

[0040] To more clearly illustrate the technical solutions of the present invention, the accompanying drawings used in the description of the embodiments or prior art will be briefly introduced below. Obviously, the drawings described below are merely some embodiments of the present invention, and those skilled in the art can obtain other drawings based on these drawings without any creative effort.

[0041] Figure 1 This is a schematic diagram of the implementation environment provided in one embodiment of the present invention;

[0042] Figure 2 This is a flowchart of a database conversion method provided in one embodiment of the present invention;

[0043] Figure 3 This is a flowchart of a database conversion method provided in another embodiment of the present invention;

[0044] Figure 4 This is a flowchart of a database conversion method provided in another embodiment of the present invention;

[0045] Figure 5 This is a schematic diagram of a display interface provided in one embodiment of the present invention;

[0046] Figure 6 This is a schematic diagram of the structure of a database conversion device provided in one embodiment of the present invention;

[0047] Figure 7 This is a schematic diagram of the structure of a database conversion device provided in another embodiment of the present invention;

[0048] Figure 8 This is a schematic diagram of the structure of an electronic device provided in one embodiment of the present invention. Detailed Implementation

[0049] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0050] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, apparatus, product, or device that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.

[0051] To make the objectives, technical solutions, and advantages disclosed in the embodiments of the present invention clearer, the embodiments of the present invention will be further described in detail below with reference to the accompanying drawings and examples. The acquisition, storage, use, and processing of data in the technical solutions of the embodiments of the present invention all comply with the relevant provisions of national laws and regulations. It should be understood that the specific embodiments described herein are merely illustrative of the embodiments of the present invention and are not intended to limit the embodiments of the present invention. First, the following concepts are explained in the embodiments of the present invention:

[0052] MySQL Database: A small, open-source relational database management system.

[0053] Oracle Database: Oracle Database, also known as Oracle RDBMS, or simply Oracle, is a relational database management system with a distributed database at its core.

[0054] Mybatic: An excellent persistence layer framework that supports custom SQL, stored procedures, and advanced mappings for calling and using various databases.

[0055] Reference manual attached Figure 1 It illustrates a schematic diagram of the implementation environment of a database conversion method provided in an embodiment of the present invention, such as... Figure 1 As shown, this database transformation method can be applied to server 100, which can be a standalone server, a server cluster or distributed system composed of multiple servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms.

[0056] Specifically, the server 100 can implement the database conversion method provided in this embodiment of the invention based on the Mybatic framework. Optionally, the server 100 can use the database conversion method provided in this embodiment of the invention to convert an Oracle database into a MySQL database based on a preset configuration file. The SQL statements in the Oracle database can be custom-written code using the syntax corresponding to the Oracle database. The configuration file can include pre-set conversion strategies for converting keywords in the Oracle database into keywords in the MySQL database. The server 100 can convert the SQL statements in the Oracle database based on the various conversion strategies to obtain SQL statements in the MySQL database.

[0057] Optionally, for keywords in the Oracle database that do not have a preset conversion strategy, if a corresponding historical conversion record has been obtained through manual conversion before this conversion, the server 100 can also parse the historical conversion record to generate a corresponding conversion strategy, and then convert the keyword according to the generated conversion strategy.

[0058] It should be noted that, Figure 1 The implementation environment shown is merely exemplary; in practical applications, this implementation environment may also include more... Figure 1 The embodiments of the present invention do not limit the number of more or fewer components shown.

[0059] Reference manual attached Figure 2 This illustrates the flow of a database transformation method provided by an embodiment of the present invention, which can be applied to... Figure 1 Among the 100 servers, the specific ones are as follows: Figure 2 As shown, the method may include the following steps:

[0060] S210: Retrieve the source SQL statement to be converted from the source database.

[0061] In this embodiment of the invention, the source SQL statement can be an SQL statement stored in the source database that is to be converted into code in the target database. The source database may include, but is not limited to, an Oracle database, and the target database may include, but is not limited to, a MySQL database.

[0062] It is understandable that by converting an Oracle database to an open-source MySQL database, data security and other issues associated with using an Oracle database can be avoided.

[0063] In one possible embodiment, obtaining the source SQL statement to be converted from the source database may include: obtaining the SQL file to be converted from the source database and reading the SQL statement in the SQL file; determining whether the SQL statement needs to be converted; if so, using the SQL statement as the source SQL statement to be converted.

[0064] Specifically, each SQL statement in the SQL file to be converted can be read sequentially. The read SQL statements are analyzed to determine if they contain keywords that require conversion. If so, the SQL statement needs conversion and is used as the source SQL statement for conversion. If not, the SQL statement does not need conversion, is recorded, marked as not requiring replacement, and saved to the database. The keywords requiring conversion can be keywords with different syntax features in the source and target databases, including but not limited to function keywords, string keywords, parameter definition or assignment keywords, etc. This embodiment of the invention does not impose specific limitations on these.

[0065] For example, if the SQL statement in the SQL file to be converted contains a rounding keyword, since Oracle databases use the ceil() function and MySQL databases use the ceiling() function, it can be determined that the keyword is the one that needs to be converted, and the corresponding SQL statement can be used as the source SQL statement to be converted.

[0066] In one possible embodiment, referencing the appendix to the specification... Figure 3 The front-end can import the configuration file of the project to be modified and send it to the back-end. The back-end can obtain the SQL file to be converted based on the project configuration file and read the SQL statements in the SQL file. After reading the SQL statements, the back-end can also summarize and record the SQL statements in the database. The back-end can also determine whether the read SQL statements need to be converted and use the SQL statements that need to be converted as the source SQL statements to be converted. The database can be of various types, and this embodiment of the invention does not impose specific limitations on it.

[0067] In practical applications, the XML configuration file that needs modification can be searched based on the project's configuration file. This XML configuration file may include one or more SQL file directories. The SQL file to be converted can be obtained from the SQL file directory. Then, the SQL statements in the SQL file can be scanned and processed according to different cases.

[0068] For example, automated tools can be used to search for the mybatic-config.xml file throughout the entire project, identify the specific directory of SQL custom files within the found mybatic-config.xml file, and use all SQL custom files contained in that directory as the SQL files to be converted. Then, each SQL statement in each of the SQL custom files can be read, recorded in the database, and processed according to different scenarios.

[0069] S220: Obtain the conversion strategy corresponding to each keyword to be converted in the source SQL statement, and determine whether the conversion strategy corresponding to all keywords to be converted can be obtained.

[0070] In this embodiment of the invention, the conversion strategies corresponding to each keyword to be converted in the source SQL statement can be used to convert the corresponding keywords respectively, thereby obtaining the target SQL statement in the target database. Specifically, each keyword can correspond to a conversion strategy, and the conversion strategies corresponding to different keywords can be the same or different. This embodiment of the invention does not impose specific restrictions on this.

[0071] In one possible embodiment, obtaining the conversion strategies corresponding to each keyword to be converted in the source SQL statement and determining whether conversion strategies corresponding to all keywords to be converted can be obtained may include: parsing the source SQL statement to determine each keyword to be converted in the source SQL statement; searching for a conversion strategy corresponding to each keyword to be converted from a preset configuration file; if a corresponding conversion strategy can be found for each keyword to be converted in the configuration file, then it is determined that conversion strategies corresponding to all keywords to be converted can be obtained; if any keyword to be converted cannot find a corresponding conversion strategy in the configuration file, then it is determined that conversion strategies corresponding to all keywords to be converted cannot be obtained.

[0072] Specifically, conversion strategies corresponding to multiple keywords to be converted in the source database can be preset and saved in a configuration file. The conversion strategies may include conversion rules for converting keywords in the source database into target keywords in the target database. These conversion strategies can be preset based on information such as the syntax rules of the source and target databases.

[0073] Optionally, the transformation strategy can be stored in a transformation strategy table, and the transformation strategy may include, but is not limited to, information such as rule identification (ID), rule description, source database syntax, target database syntax, focus, and creation time and date.

[0074] It is understandable that storing the conversion strategy in a configuration file makes it easier to add or modify the conversion strategy, thereby improving the flexibility of the program code and enabling code reuse.

[0075] Specifically, the keywords to be converted in the source database may include, but are not limited to, function keywords, string keywords, parameter definition or assignment keywords, etc., and this embodiment of the invention does not impose specific limitations on them.

[0076] For example, conversion strategies can be pre-defined for the following types of keywords to be converted to describe the conversion rules for converting keywords in an Oracle database to target keywords in a MySQL database:

[0077] (1) Subquery alias modification: In Oracle database, subqueries of select, insert and update statements do not need to be aliased, while MySQL subqueries must have aliases.

[0078] (2) Translating and transforming special characters (\n): In the code, \n is escaped and converted to "\\n". The string can be processed directly in the corresponding DOS layer Java code before being passed to iBatissqlmap.

[0079] (3) The number of days between two dates: Oracle databases use the subtraction of two dates to calculate the number of days between two dates, while MySQL databases use datediff() instead.

[0080] (4) There are spaces between >, <, ==, and ! =, <, and >: Oracle database supports spaces in this type of expression, but MySQL database does not support them and the spaces in the middle need to be removed.

[0081] (5) Round up: Used to round up numeric parameters. In Oracle databases, the ceil() function is used to achieve this, while in MySQL, the ceiling() function is used instead.

[0082] (6) Get the string length: Oracle databases use the length() function to get the string length, while MySQL databases need to use the char_length() function instead.

[0083] (7) Character to integer: Oracle databases use the to_number() function to convert char or varchar2 String type to number type, while MySQL databases need to use the cast() function instead.

[0084] (8) String concatenation: Oracle databases use the concat() function or || to concatenate strings, while MySQL databases need to use concat_ws() instead.

[0085] (9) Whether a substring exists in a parent string: Oracle databases use the instr(str1,str2) function to determine whether a substring exists in a parent string, while MySQL databases use the locate(str2,str1) function instead.

[0086] (10) Returns the specified ASCII character: Oracle databases use the chr() function to convert ASCII codes to characters, while MySQL databases need to use the char() function instead.

[0087] (11) Get the current time: Oracle databases use sysdate to get the current time, while MySQL databases need to use the sysdate() function instead.

[0088] (12) Adding / subtracting months from dates: Oracle databases use the add_months(date,int) function to add or subtract months from dates, where the date parameter is a valid date expression and the int parameter is the increment by month. MySQL databases require the use of the DATE_ADD(date,INTERVALexprtype) function instead.

[0089] (13) Get system date and time (including microseconds and time zone: SYSTIMESTAMP): Oracle databases use Systimestamp to return the current system date and time (including microseconds and time zone) on the local database. MySQL databases need to use sysdate(6) instead.

[0090] (14) Time / Date to Character: Oracle databases use the to_char() function to convert date or numeric data types to character data types.

[0091] For date types, MySQL databases require the use of date_format(date,format) instead, where the date parameter is a valid date and the format specifies the output format of the date / time.

[0092] For numeric types, MySQL databases require the use of the format(##,format) function instead, where format is a positive number or a floating-point number with a certain number of decimal places.

[0093] For time-based data types, MySQL databases require the use of the FROM_UNIXTIME(time,format) function instead, where the time parameter is a valid time and the format specifies the output format of the time.

[0094] (15) The "DATE" type of jdbcType in ResultMap: The DATE type of some database table fields in Oracle database is different from that in MySQL database. Therefore, when using the iBatis framework, parameters with added types in the current code need to be replaced with DATETIME.

[0095] (16) Character to date: Oracle databases use the to_date() function to convert date type to character type, while MySQL databases need to use the str_to_date() function to replace it, and the date format also needs to be replaced according to the MySQL format.

[0096] (17) Extracting a specific portion from a time type (EXTRACT): Oracle databases use the extract() function to extract a specific time or calculate the difference between two times. For extracting a specific time, MySQL databases use functions such as year(), month(), and day() instead. For calculating time differences, MySQL databases use the timestampdiff() function instead.

[0097] (18) String to time type: In Oracle database, the to_timestamp() function is used to convert a string to a time type. In MySQL database, the str_to_date() function is used instead.

[0098] (19) Truncate time or number: Oracle database uses the trunc('123.456',2) function to truncate the decimal places, while MySQL database uses the truncate('123.456',2) function instead.

[0099] (20) Adding / subtracting days from a date: Oracle databases use the trunc() function to add / subtract days from a date, while MySQL databases use the date_add(date, intervalatype) function instead. Here, date is the time to be added or subtracted, a is the hour, day, month, etc. to be added or subtracted, and type can be hour, day, month, etc.

[0100] It should be noted that the keywords for which conversion strategies need to be set in the above-mentioned types are only examples. In practical applications, other keywords and corresponding conversion strategies can be predefined and set. This embodiment of the invention does not impose specific restrictions on this.

[0101] Specifically, when it is necessary to convert SQL statements in the source database into SQL statements in the target database, the source SQL statement can be parsed to obtain each keyword to be converted in the source SQL statement. For each keyword to be converted, the corresponding conversion strategy can be found from the preset configuration file.

[0102] It should be noted that various existing analysis methods can be used to parse the source SQL statement to obtain the various keywords to be converted in the source SQL statement. The embodiments of the present invention will not be described in detail here.

[0103] Specifically, if a corresponding conversion strategy can be found for each of the keywords to be converted in the configuration file, then it can be determined that the conversion strategies corresponding to all the keywords to be converted can be obtained. At this time, the existing conversion strategies can be directly used to convert each keyword to be converted in the source SQL statement.

[0104] Specifically, if any of the keywords to be converted cannot find a corresponding conversion strategy in the configuration file, it is determined that the conversion strategies corresponding to all the keywords to be converted cannot be obtained. In this case, the existing conversion strategies cannot be used to convert all the keywords to be converted, and the conversion strategies corresponding to the keywords to be converted that have not been found need to be generated first.

[0105] It is understandable that by parsing the source SQL statement, the source SQL statement that needs to be converted and the keywords that need to be converted can be automatically identified without manual intervention. This can quickly and accurately identify the statements and keywords that need to be modified, avoid conversion errors caused by missing SQL statements or keywords in SQL statements, and improve the success rate of database conversion.

[0106] S230: If not, then determine that the first keyword to be converted by the conversion strategy has not been obtained, and obtain the historical conversion record corresponding to the first keyword to be converted.

[0107] In this embodiment of the invention, when conversion strategies corresponding to all keywords to be converted cannot be obtained, a corresponding conversion strategy can be automatically generated based on the historical conversion records corresponding to the first keyword to be converted for which no conversion strategy has been obtained. The historical conversion records can be conversion records obtained by manually analyzing and converting SQL statements in the source database, including the first keyword to be converted, prior to this conversion. The historical conversion records may record conversion operations that convert the first keyword to be converted into a first target keyword in the target database.

[0108] Specifically, the historical conversion records can also be stored in a database. If the conversion strategies corresponding to all keywords to be converted cannot be obtained, the historical conversion records corresponding to the first keyword to be converted can be retrieved from the database.

[0109] For example, the historical conversion records can be stored in a conversion record table. The historical conversion records may include, but are not limited to, information such as project name, SQL configuration file path, SQL statement before conversion, SQL statement after conversion, type flag, status, conversion suggestion, creation date and time, last modification date and time, and / or conversion operation corresponding to each keyword.

[0110] In one possible embodiment, after step S230, the method may further include: determining whether all historical conversion records corresponding to the first keywords to be converted can be obtained; if yes, then performing a step of converting the corresponding keywords to be converted based on the conversion strategy or the historical conversion records; if no, then recording the source SQL statement to be converted and annotating the source SQL statement to be converted.

[0111] Specifically, if all historical conversion records corresponding to the first keyword to be converted can be obtained, it means that the conversion operations in the historical conversion records corresponding to each first keyword to be converted can be automatically learned to convert the first keyword to be converted into the first target keyword in the target database, thereby generating a corresponding conversion strategy to convert the first keyword to be converted to obtain the first target keyword. At this time, the subsequent step S240 can be executed.

[0112] Specifically, if historical conversion records for all first-to-be-converted keywords cannot be obtained, it means that at least one first-to-be-converted keyword cannot generate a corresponding conversion strategy, making automatic conversion impossible and requiring manual processing. In this case, the corresponding keywords in the source SQL statement can be converted based on the obtained conversion strategies and historical conversion records, and the converted results can be marked to remind developers to manually convert each unconverted keyword to obtain the target SQL statement in the target database. The method for converting the corresponding keywords in the source SQL statement based on the obtained conversion strategies and historical conversion records will be described in detail later.

[0113] S240: Based on the conversion strategy or the historical conversion records, convert each keyword to be converted in the source SQL statement to obtain the target SQL statement in the target database.

[0114] In this embodiment of the invention, when it is not possible to obtain the conversion strategies corresponding to all keywords to be converted, for the first keyword to be converted for which no conversion strategy has been obtained, it can be converted based on the corresponding historical conversion records; for the second keyword to be converted for which a conversion strategy has been obtained, it can be converted directly based on the obtained conversion strategy.

[0115] In one possible embodiment, the step of converting each keyword to be converted in the source SQL statement based on the conversion strategy or the historical conversion record may include: for a first keyword to be converted for which no conversion strategy has been obtained, generating a corresponding conversion strategy based on the historical conversion record corresponding to the first keyword to be converted, and converting the first keyword to be converted into a first target keyword in the target database based on the generated conversion strategy; for a second keyword to be converted for which a conversion strategy has been obtained, converting the second keyword to be converted into a second target keyword in the target database based on the obtained conversion strategy.

[0116] Specifically, for the first keyword to be converted for which no conversion strategy has been obtained, the conversion operations recorded in the historical conversion records corresponding to the first keyword to be converted can be parsed to generate a conversion strategy that converts the first keyword to be converted into the first target keyword in the target database. Specifically, various existing parsing methods can be used to parse the conversion operations and generate corresponding conversion strategies; these will not be elaborated upon here.

[0117] For example, assuming that the historical conversion record contains a conversion operation that converts the keyword to be converted, ceil(), to the target keyword, ceiling(), then the conversion operation can be parsed to generate a conversion strategy corresponding to the floor function, that is, the ceiling() function can be used to replace the ceil() function.

[0118] Specifically, for the second keyword to be converted based on the obtained conversion strategy, the corresponding conversion strategy can be directly used to convert the second keyword to be converted, thus obtaining the second target keyword in the target database. After converting each first keyword to be converted and each second keyword to be converted in the source SQL statement, the target SQL statement in the target database can be obtained.

[0119] In one possible embodiment, if the conversion strategies corresponding to all the keywords to be converted can be obtained, then there is no need to execute step S230. Instead, the obtained conversion strategies can be directly used to convert each keyword to be converted in the source SQL statement to obtain the target SQL statement in the target database.

[0120] In one possible implementation, if the conversion strategies corresponding to all keywords to be converted cannot be obtained, then for each keyword to be converted in the source SQL statement, a corresponding conversion strategy can be generated based on historical conversion records, and then the conversion can be performed according to the generated conversion strategy to obtain the target SQL statement in the target database.

[0121] In one possible embodiment, referencing the appendix to the specification... Figure 3 After converting the source SQL statement into the target SQL statement in the target database, the conversion process and result of the source SQL statement can be recorded, generating and saving the corresponding conversion record. For example, the SQL statement before conversion (i.e., the source SQL statement) and the SQL statement after conversion (i.e., the target SQL statement) can be recorded, marked as converted, and saved to the database.

[0122] In one possible embodiment, it can also be determined whether there are unknown source SQL statements or source SQL statements that cannot be easily replaced. If an unknown source SQL statement is determined to exist, it can be recorded and marked as "unknown." If a source SQL statement that cannot be easily replaced is determined to exist, it can be recorded and marked with a modification method. Developers can determine the modification status of the source SQL statement based on the corresponding annotation information, and / or manually process the source SQL statement based on the corresponding annotation information. For example, developers can manually analyze the unknown source SQL statement and convert it into the target SQL statement. Alternatively, developers can use the marked modification method to convert the source SQL statement that cannot be easily replaced to obtain the target SQL statement. Simultaneously, developers can also determine the corresponding conversion strategies for the above two situations to improve the conversion strategies in the configuration file, so that the conversion can be automatically completed when encountering the above situations again.

[0123] In summary, the database conversion method according to embodiments of the present invention, by pre-setting a conversion strategy, allows for the conversion of various keywords in the source SQL statement based on the preset strategy during the database conversion process, resulting in the target SQL statement in the target database. This achieves automatic database conversion, reduces the workload of manual conversion by developers, significantly improves database conversion efficiency, saves manpower and time costs, and effectively solves the problem of low system upgrade efficiency. Furthermore, by implementing automatic database conversion, it can also reduce the occurrence of modification errors, such as common spelling errors, symbol formatting errors, etc.

[0124] In addition, for keywords to be converted that do not have a preset conversion strategy, the corresponding conversion strategy can be automatically generated by parsing the corresponding historical conversion records. Then, the keywords to be converted can be converted according to the generated conversion strategy, which can greatly improve the success rate and efficiency of automatic database conversion.

[0125] In one possible embodiment, referencing the appendix to the specification... Figure 4 The method may further include the following steps:

[0126] S250: Validate the target SQL statement to determine its correctness.

[0127] In this embodiment of the invention, a connection can be made to the target database to read and execute the transformed target SQL statements, thereby verifying each target SQL statement individually. If the target SQL statement executes successfully, it indicates that the target SQL statement is correct, and the verification passes; if the target SQL statement fails to execute, it indicates that the target SQL statement is incorrect, and the verification fails. For target SQL statements that fail verification, they can be recorded and marked as verification failed. Developers can then manually process the target SQL statements based on the corresponding annotation information.

[0128] It is understandable that by validating the converted target SQL statement and manually handling those that fail the validation, the correctness of the converted SQL statement can be guaranteed, and errors in modification can be avoided.

[0129] S260: If the target SQL statement passes the verification, the target SQL statement will be displayed.

[0130] In this embodiment of the invention, if the target SQL statement passes the verification, the target SQL statement can be displayed on the display interface.

[0131] In one possible embodiment, referencing the appendix to the specification... Figure 3 After validating the target SQL statement, the validation results of the target SQL statements in the entire SQL file can be summarized and saved. Alternatively, the conversion results of the source SQL statements in the entire SQL file can be sent to the front end for display.

[0132] For example, it can be done through, as Figure 5 The interface shown displays the transformed results of the target SQL statement. For example... Figure 5 As shown, the display interface may include, but is not limited to, information such as project name, SQL configuration file path, type flag, status, last operation time, SQL statement before conversion, and SQL statement after conversion.

[0133] It is understood that the embodiments of the present invention read the SQL file in the project configuration file, as well as the SQL statements in the SQL file and summarize and record them. The SQL statements are then converted line by line to obtain the conversion results in the target database and recorded. Finally, the converted SQL statements are verified, and the verification results are summarized, recorded and displayed. This can record the entire database conversion process, making it easier for developers to track and control the overall project conversion progress and better match the needs of actual work.

[0134] In this embodiment of the invention, if the target SQL statement fails the validation, the validation results can be displayed while summarizing each target SQL statement that fails the validation and modifying the corresponding conversion strategy to improve the automatic conversion tool.

[0135] It is understandable that by continuously summarizing and improving conversion strategies, the success rate and efficiency of automatic database conversion can be further improved.

[0136] Reference manual attached Figure 6 This illustrates the structure of a database conversion apparatus 600 provided in one embodiment of the present invention. For example... Figure 6 As shown, the device 600 may include:

[0137] The statement acquisition module 610 is used to acquire the source SQL statement to be converted from the source database;

[0138] The conversion strategy acquisition module 620 is used to acquire the conversion strategy corresponding to each keyword to be converted in the source SQL statement, and to determine whether the conversion strategies corresponding to all keywords to be converted can be acquired.

[0139] The conversion record acquisition module 630 is used to determine the first keyword to be converted for which no conversion strategy has been obtained when it is determined that the conversion strategy corresponding to all keywords to be converted cannot be obtained, and to acquire the historical conversion record corresponding to the first keyword to be converted; wherein, the historical conversion record records the conversion operation of converting the first keyword to be converted into the first target keyword in the target database;

[0140] The conversion module 640 is used to convert each keyword to be converted in the source SQL statement based on the conversion strategy or the historical conversion record, so as to obtain the target SQL statement in the target database.

[0141] In one possible embodiment, the device 600 may further include:

[0142] The judgment module is used to determine whether all historical conversion records corresponding to the first keyword to be converted can be obtained;

[0143] The conversion module 640 is specifically used to perform the step of converting the corresponding keyword based on the conversion strategy or the historical conversion records when it is determined that all historical conversion records corresponding to the first keyword to be converted can be obtained.

[0144] The recording module is used to record the source SQL statement to be converted and to annotate the source SQL statement to be converted when it is determined that it is not possible to obtain all historical conversion records corresponding to the first keyword to be converted.

[0145] In one possible embodiment, referencing the appendix to the specification... Figure 7 The device 600 may further include:

[0146] The verification module 650 is used to verify the target SQL statement to determine the correctness of the target SQL statement;

[0147] The display module 660 is used to display the target SQL statement when the target SQL statement passes the verification.

[0148] It should be noted that the apparatus provided in the above embodiments is only illustrated by the division of the above functional modules when implementing its functions. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus provided in the above embodiments and the corresponding method embodiments belong to the same concept, and the specific implementation process can be found in the corresponding method embodiments, which will not be repeated here.

[0149] One embodiment of the present invention also provides an electronic device, which includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, the at least one instruction or the at least one program being loaded and executed by the processor to implement the database conversion method provided in the above method embodiments.

[0150] Memory can be used to store software programs and modules. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory. Memory can primarily include a program storage area and a data storage area. The program storage area can store the operating system, application programs required for the functions, etc.; the data storage area can store data created based on the use of the device, etc. Furthermore, memory can include high-speed random access memory, and can also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, memory can also include a memory controller to provide the processor with access to the memory.

[0151] Refer to the attached reference manual Figure 8 The diagram shown is a block diagram of an electronic device 800 according to an embodiment of the present invention. The electronic device 800 may include one or more processors 802, system control logic 808 connected to at least one of the processors 802, system memory 804 connected to the system control logic 808, non-volatile memory (NVM) 806 connected to the system control logic 808, and network interface 810 connected to the system control logic 808.

[0152] Processor 802 may include one or more single-core or multi-core processors. Processor 802 may include any combination of general-purpose processors and special-purpose processors (e.g., graphics processors, application processors, baseband processors, etc.). In embodiments herein, processor 802 may be configured to perform operations according to... Figures 2 to 4 One or more embodiments of the various embodiments shown.

[0153] In some embodiments, system control logic 808 may include any suitable interface controller to provide any suitable interface to at least one of the processors 802 and / or any suitable device or component communicating with system control logic 808.

[0154] In some embodiments, system control logic 808 may include one or more memory controllers to provide an interface to system memory 804. System memory 804 may be used to load and store data and / or instructions. In some embodiments, memory 804 of device 800 may include any suitable volatile memory, such as suitable dynamic random access memory (DRAM).

[0155] NVM / Memory 806 may include one or more tangible, non-transitory computer-readable media for storing data and / or instructions. In some embodiments, NVM / Memory 806 may include any suitable non-volatile memory such as flash memory and / or any suitable non-volatile storage device, such as at least one of HDD (Hard Disk Drive), CD (Compact Disc) drive, and DVD (Digital Versatile Disc) drive.

[0156] NVM / Storage 806 may include a portion of storage resources mounted on the device 800, or it may be accessible by the device but is not necessarily part of the device. For example, NVM / Storage 806 may be accessed over a network via network interface 810.

[0157] Specifically, system memory 804 and NVM / memory 806 may each include a temporary copy and a permanent copy of instruction 820. Instruction 820 may include, when executed by at least one of processors 802, causing device 800 to perform, as Figures 2 to 4 The instructions for the database conversion method are shown. In some embodiments, the instructions 820, hardware, firmware, and / or their software components may additionally / alternatively be located in the system control logic 808, the network interface 810, and / or the processor 802.

[0158] Network interface 810 may include a transceiver for providing a radio interface to device 800, thereby enabling communication with any other suitable device (such as a front-end module, antenna, etc.) via one or more networks. In some embodiments, network interface 810 may be integrated into other components of device 800. For example, network interface 810 may be integrated into at least one of the following: a communication module of processor 802, system memory 804, NVM / memory 806, and a firmware device (not shown) with instructions, which, when at least one of processor 802 executes the instructions, enable device 800 to implement... Figures 2 to 4 One or more embodiments of the various embodiments shown.

[0159] The network interface 810 may further include any suitable hardware and / or firmware to provide a multiple-input multiple-output radio interface. For example, the network interface 810 may be a network adapter, a wireless network adapter, a telephone modem, and / or a wireless modem.

[0160] In one embodiment, at least one of the processors 802 may be packaged together with the logic of one or more controllers for system control logic 808 to form a system-in-package (SiP). In another embodiment, at least one of the processors 802 may be integrated on the same die with the logic of one or more controllers for system control logic 808 to form a system-on-a-chip (SoC).

[0161] Device 800 may further include an input / output (I / O) device 812. The I / O device 812 may include a user interface enabling a user to interact with device 800; the peripheral component interface is designed to allow peripheral components to also interact with device 800. In some embodiments, device 800 may also include sensors for determining at least one of environmental conditions and location information related to device 800.

[0162] In some embodiments, the user interface may include, but is not limited to, a display (e.g., a liquid crystal display, a touch screen display, etc.), a speaker, a microphone, one or more cameras (e.g., a still image camera and / or a video camera), a flashlight (e.g., a light-emitting diode flash), and a keyboard.

[0163] In some embodiments, the peripheral component interface may include, but is not limited to, a non-volatile memory port, an audio jack, and a power interface.

[0164] In some embodiments, the sensor may include, but is not limited to, a gyroscope sensor, an accelerometer, a proximity sensor, an ambient light sensor, and a positioning unit. The positioning unit may also be part of or interact with the network interface 810 to communicate with components of the positioning network (e.g., Global Positioning System (GPS) satellites).

[0165] It is understood that the structures illustrated in the embodiments of the present invention do not constitute a specific limitation on the electronic device 800. In other embodiments of the present invention, the electronic device 800 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0166] One embodiment of the present invention also provides a computer-readable storage medium, which can be disposed in an electronic device to store at least one instruction or at least one program related to implementing a database conversion method, wherein the at least one instruction or the at least one program is loaded and executed by the processor to implement the database conversion method provided in the above method embodiment.

[0167] Optionally, in embodiments of the present invention, the storage medium may include, but is not limited to, various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.

[0168] One embodiment of the present invention also provides a computer program product comprising a computer program / instructions that, when the computer program product is run on an electronic device, are loaded and executed by a processor to implement the steps of the database conversion method provided in the various alternative embodiments described above.

[0169] It should be noted that the order of the above embodiments of the present invention is merely for descriptive purposes and does not represent the superiority or inferiority of the embodiments. Furthermore, specific embodiments have been described above. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims can be performed in a different order than that shown in the embodiments and still achieve the desired result. Additionally, the processes depicted in the drawings do not necessarily require a specific or sequential order to achieve the desired result. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0170] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the apparatus embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.

[0171] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.

[0172] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A database conversion method, characterized in that, include: Retrieve the source SQL statement to be converted from the source database; Obtain the conversion strategy corresponding to each keyword to be converted in the source SQL statement, and determine whether the conversion strategies corresponding to all keywords to be converted can be obtained; If not, it is determined that the first keyword to be converted by the conversion strategy has not been obtained, and the historical conversion record corresponding to the first keyword to be converted is obtained; wherein, the historical conversion record records the conversion operation of converting the first keyword to be converted into the first target keyword in the target database; Based on the transformation strategy or the historical transformation records, each keyword to be transformed in the source SQL statement is transformed to obtain the target SQL statement in the target database, specifically including: For the first keyword to be converted for which no conversion strategy has been obtained, a corresponding conversion strategy is generated based on the historical conversion records corresponding to the first keyword to be converted, and the first keyword to be converted is converted into the first target keyword in the target database based on the generated conversion strategy; For the second keyword to be converted based on the obtained conversion strategy, the second keyword to be converted is converted into the second target keyword in the target database based on the obtained conversion strategy.

2. The method according to claim 1, characterized in that, The process of obtaining the source SQL statement to be converted from the source database includes: Obtain the SQL file to be converted from the source database and read the SQL statements in the SQL file; Determine whether the SQL statement needs to be converted. If so, the SQL statement will be used as the source SQL statement to be converted.

3. The method according to claim 1, characterized in that, The step of obtaining the conversion strategies corresponding to each keyword to be converted in the source SQL statement, and determining whether the conversion strategies corresponding to all keywords to be converted can be obtained, includes: The source SQL statement is parsed to determine the individual keywords to be converted in the source SQL statement; For each keyword to be converted, the conversion strategy corresponding to the keyword is searched from the preset configuration file; If a corresponding conversion strategy can be found for each of the keywords to be converted in the configuration file, then it is determined that the conversion strategies corresponding to all the keywords to be converted can be obtained. If any of the keywords to be converted cannot be found in the configuration file, then it is determined that the conversion strategies corresponding to all the keywords to be converted cannot be obtained.

4. The method according to claim 1, characterized in that, The method further includes: Determine if it is possible to obtain all historical conversion records corresponding to the first keyword to be converted; If so, then the step of converting the corresponding keyword to be converted based on the conversion strategy or the historical conversion record is executed; If not, record the source SQL statement to be converted and annotate it.

5. The method according to claim 1, characterized in that, The method further includes: The target SQL statement is validated to determine its correctness; If the target SQL statement passes the validation, the target SQL statement will be displayed.

6. A database conversion device, characterized in that, The device includes: The statement retrieval module is used to retrieve the source SQL statements to be converted from the source database; The conversion strategy acquisition module is used to acquire the conversion strategy corresponding to each keyword to be converted in the source SQL statement, and to determine whether the conversion strategies corresponding to all keywords to be converted can be acquired. The conversion record acquisition module is used to determine the first keyword to be converted for which no conversion strategy has been obtained when it is determined that the conversion strategy corresponding to all keywords to be converted cannot be obtained, and to acquire the historical conversion record corresponding to the first keyword to be converted; wherein, the historical conversion record records the conversion operation of converting the first keyword to be converted into the first target keyword in the target database; The conversion module is used to convert each keyword to be converted in the source SQL statement based on the conversion strategy or the historical conversion records to obtain the target SQL statement in the target database, specifically including: For the first keyword to be converted for which no conversion strategy has been obtained, a corresponding conversion strategy is generated based on the historical conversion records corresponding to the first keyword to be converted, and the first keyword to be converted is converted into the first target keyword in the target database based on the generated conversion strategy; For the second keyword to be converted based on the obtained conversion strategy, the second keyword to be converted is converted into the second target keyword in the target database based on the obtained conversion strategy.

7. An electronic device, characterized in that, The electronic device includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, the at least one instruction or the at least one program being loaded and executed by the processor to implement the database conversion method as described in any one of claims 1-5.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one instruction or at least one program, which is loaded and executed by a processor to implement the database conversion method as described in any one of claims 1-5.

9. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instruction is executed by the processor, it implements the database conversion method as described in any one of claims 1-5.

Citation Information

Patent Citations

  • Database code conversion method and system

    CN114047927A

  • Code conversion method and device, intelligent terminal and storage medium

    CN115827166A