Database statement conversion method and device

By using preset syntax file conversion statements in the database management system, the problem of code modification and intrusion when the business end changes the database is solved, seamless database statement conversion is achieved, and manpower and time costs are reduced.

CN118550940APending Publication Date: 2024-08-27QI AN XIN TECHNOLOGY GROUP INC

Patent Information

Application Number
CN202410571604.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-09
Publication Date
2024-08-27

AI Technical Summary

Technical Problem

When replacing the database on the business end, the existing technology requires a lot of manpower and time to modify the statements and write the code. It is also highly intrusive to the business end code and cannot seamlessly convert the grammar rules.

Method used

By storing the preset grammar files of multiple databases in the database management system, the target grammar files corresponding to the original adapted database of the business end and the replaced database are determined, and based on the target grammar files, statements that comply with the grammar rules of the first database are converted into A statement that has the same semantics as the first statement and conforms to the syntax rules of the second database enables database statement conversion without modifying the business-end code.

Benefits of technology

It avoids code intrusion caused by the business end changing the database, reduces manpower and time costs, and enables the business end to operate the replaced database without modifying the code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118550940A
    Figure CN118550940A
Patent Text Reader

Abstract

The invention discloses a database statement conversion method and device, relates to the technical field of computers, and mainly aims to realize operation of a replaced database at a service end without modifying a code at the service end under the condition that the database is replaced at the service end. According to the main technical scheme, the method is applied to a database management system, preset grammar files corresponding to a plurality of databases respectively are stored in the database management system, and the preset grammar files are used for declaring grammar rules of the corresponding databases; when database statement conversion needs to be carried out, determining a first database adaptive to the service end and a replaced second database; determining target grammar files corresponding to the first database and the second database in preset grammar files; and based on the target grammar file, converting a first statement meeting the grammar rule of the first database into a second statement which has the same semantics with the first statement and meets the grammar rule of the second database.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a database statement conversion method and device. Background Art

[0002] In some business scenarios, clients, business systems and other business terminals will switch from their own adapted databases to other databases.

[0003] At present, in order to enable the business end to operate the replaced database, the statement writing code originally applicable to the grammatical rules of the database adapted by the client is usually modified into the statement writing code applicable to the grammatical rules of the replaced database, so that the statement that can operate the replaced database can be written through the modified statement writing code to realize the business end to operate the replaced database. This method not only requires a lot of manpower and time cost to modify the statement writing code, but also has a strong invasiveness to the business end code. Summary of the invention

[0004] In view of this, the present application proposes a database statement conversion method and device, the main purpose of which is to enable the business end to operate the replaced database without modifying the business end code when the business end changes the database.

[0005] In order to achieve the above objectives, this application mainly provides the following technical solutions:

[0006] In a first aspect, the present application provides a database statement conversion method, which is applied to a database management system, wherein the database management system stores preset grammar files corresponding to multiple databases, respectively, and the preset grammar files are used to declare grammar rules of the corresponding databases. The database statement conversion method includes:

[0007] When database statement conversion is required, determine the first database adapted by the business end itself and the replaced second database;

[0008] Determine, in a preset grammar file, target grammar files corresponding to the first database and the second database;

[0009] Based on the target grammar file, a first statement conforming to the grammar rule of the first database is converted into a second statement having the same semantics as the first statement and conforming to the grammar rule of the second database.

[0010] In some embodiments of the present application, the target grammar file includes a first grammar file for declaring grammar rules of a first database, a second grammar file for declaring grammar rules of a second database, and a third grammar file for recording the correspondence between statements with the same semantics in the first database and the second database; then, based on the target grammar file, a first statement that conforms to the grammar rules of the first database is converted into a second statement that has the same semantics as the first statement and conforms to the grammar rules of the second database, including: parsing the first statement based on the grammar rules recorded in the first grammar file to obtain a first abstract syntax tree; based on the correspondence recorded in the third grammar file, replacing the corresponding statements of the first abstract syntax tree with the corresponding statements of the second database to obtain a second abstract syntax tree; processing the second abstract syntax tree based on the grammar rules declared in the second grammar file to obtain the second statement.

[0011] In some embodiments of the present application, the database statement conversion method also includes: if the first abstract syntax tree includes a third statement for which no corresponding relationship exists in the third syntax file, determining the semantics of the third statement, calling a preset compilation function to compile a fourth statement having the semantics of the third statement and supported by the second database, and replacing the third statement with the fourth statement.

[0012] In some embodiments of the present application, the database statement conversion method further includes: creating a correspondence between the third statement and the fourth statement; and adding the correspondence between the third statement and the fourth statement to the third grammar file.

[0013] In some embodiments of the present application, the preset syntax file is stored in a global configuration file of the business end, and the global configuration file also stores the types and configuration parameters of the first database and the second database; the database statement conversion method also includes: in response to receiving a database change instruction, determining that database statement conversion is required; obtaining the global configuration file of the business end; based on the preset syntax file, the types and configuration parameters of the first database and the second database recorded in the global configuration file, migrating the data in the first database to the second database.

[0014] In some embodiments of the present application, the database statement conversion method further includes: detecting whether the data in the first database adapted by the business end itself is migrated to a database of a different database type from that of the first database; if so, determining that database statement conversion is required.

[0015] In some embodiments of the present application, the database statement conversion method further includes: detecting whether the business end needs to migrate the data queried from the first database to a database of a different database type from the first database; if so, determining that database statement conversion is required.

[0016] In some embodiments of the present application, after obtaining the second statement, the database statement conversion method further includes: determining whether there is a semantic difference between the first statement and the second statement; if not, operating the second database based on the second statement; if so, issuing a statement conversion failure prompt for the first statement.

[0017] In some embodiments of the present application, determining whether there is a semantic difference between the first statement and the second statement includes: performing semantic analysis on the first statement and the second statement to obtain semantic vectors of the first statement and the second statement, respectively; detecting whether the similarity between the semantic vectors of the first statement and the second statement reaches a preset threshold; if so, determining that there is no semantic difference between the first statement and the second statement; if not, determining that there is a semantic difference between the first statement and the second statement.

[0018] In some embodiments of the present application, the database is a relational database; and / or the first statement includes any one of the following: a database login statement, a database logout statement, a data addition statement, a data deletion statement, a data query statement, a data modification statement, and a data migration statement.

[0019] In a second aspect, the present application provides a database statement conversion device, which is applied to a database management system, wherein the database management system stores preset grammar files corresponding to multiple databases, and the preset grammar files are used to declare grammar rules of the corresponding databases. The database statement conversion device includes:

[0020] A first determination module is used to determine the first database adapted by the business end itself and the replaced second database when database statement conversion is required;

[0021] A second determination module, configured to determine target grammar files corresponding to the first database and the second database in a preset grammar file;

[0022] A conversion module is used to convert, based on the target grammar file, a first statement that complies with the grammar rules of the first database into a second statement that has the same semantics as the first statement and complies with the grammar rules of the second database.

[0023] In a third aspect, the present application provides a computer-readable storage medium, wherein the storage medium includes a stored program, wherein when the program is executed, the device where the storage medium is located is controlled to execute the database statement conversion method described in the first aspect.

[0024] In a fourth aspect, the present application provides an electronic device, comprising: a memory for storing a program; and a processor, coupled to the memory, for running the program to execute the database statement conversion method described in the first aspect.

[0025] The database statement conversion method and device provided by the present application, when database statement conversion is required, determine the first database adapted by the business end itself and the second database after the business end is replaced. From the preset grammar file, determine the target grammar files corresponding to the first database and the second database. Based on the target grammar file, convert the first statement that conforms to the grammar rules of the first database into a second statement that has the same semantics as the first statement and conforms to the grammar rules of the second database. It can be seen that the solution provided by the present application does not need to modify the code of the business end when the business end replaces the database. Statement conversion is performed through the grammar files corresponding to the database originally adapted by the business end and the replaced database, and the converted statements can be used to implement the business end to operate the replaced database. In this way, not only can the intrusion of the business end code caused by the replacement of the database by the business end be avoided, but also the manpower and time cost invested by the business end in replacing the database can be reduced.

[0026] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0028] Figure 1 A flowchart of a database statement conversion method provided by an embodiment of the present application is shown;

[0029] Figure 2 A schematic diagram of the structure of a database management system provided by an embodiment of the present application is shown;

[0030] Figure 3A schematic diagram of the structure of a database statement conversion device provided by an embodiment of the present application is shown;

[0031] Figure 4 A schematic diagram of the structure of a database statement conversion device provided in another embodiment of the present application is shown. DETAILED DESCRIPTION

[0032] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.

[0033] Business terminals such as clients and business systems provide corresponding business services to users by operating databases. However, in some business scenarios, the business terminal will switch from its own adapted database to other databases. The business scenarios here may include but are not limited to the following two: First, the data on which the business terminal provides services has changed, and the database where the changed data is located is the replaced database; second, the database on which the business terminal provides services has migrated, for example, from the MYSQL database to the DAMO database, and the migrated database is the replaced database. In order to enable the business terminal to operate the replaced database, the statement writing code that is originally applicable to the grammatical rules of the database adapted by the client in the client is usually modified to the statement writing code that is applicable to the grammatical rules of the replaced database, so as to write statements that can operate the replaced database through the modified statement writing code, so as to realize the business terminal's operation on the replaced database. Although this code modification method can enable the business terminal to operate the replaced database, the business terminal needs to modify the code every time the database is changed, which not only requires a lot of manpower and time cost to modify the statement writing code, but also has a strong invasiveness to the business terminal code.

[0034] After research, the inventor found that if the preset grammar files corresponding to multiple databases are stored in a database management system, then when the business end changes the database, the grammar files corresponding to the first database originally adapted by the business end and the second database after the change can be determined from the preset grammar files, and then based on the target grammar file, the first statement that conforms to the grammar rules of the first database is converted into a second statement that has the same semantics as the first statement and conforms to the grammar rules of the second database, so as to enable the business end to operate the replaced database through the second statement. In this way, when the business end changes the database, there is no need to modify the code of the business end. The statement conversion can be performed through the grammar files corresponding to the database originally adapted by the business end and the database after the change, and the business end can operate the replaced database through the converted statements. In this way, not only can the intrusion of the business end code caused by the change of the database by the business end be avoided, but also the manpower and time cost invested in changing the database by the business end can be reduced.

[0035] Based on the above findings, the present embodiment specifically provides a technical solution for database statement conversion, specifically: a preset grammar file corresponding to multiple databases is stored in a database management system; when database statement conversion is required, the first database adapted by the business end itself and the replaced second database are determined; in the preset grammar file, the target grammar file corresponding to the first database and the second database is determined; based on the target grammar file, a first statement that conforms to the grammar rules of the first database is converted into a second statement that has the same semantics as the first statement and conforms to the grammar rules of the second database.

[0036] For any business end, when the business end changes from its own adapted database to another database, the technical solution of database statement conversion provided by this embodiment can realize the business end operation of the changed database without modifying the relevant code of the business end. This embodiment does not limit the specific types of the business end and the database, and both can be flexibly selected based on specific business needs. Exemplarily, the business end is a client or a business system, and the database is a relational database.

[0037] Based on the technical solution for database statement conversion provided above, this embodiment specifically provides a database statement conversion method and device. The database statement conversion method and device provided in this embodiment are specifically described below.

[0038] The database statement conversion method provided in the embodiment of the present application is applied to a database management system, in which a plurality of preset grammar files corresponding to databases are stored, such as Figure 1 As shown, the database statement conversion method mainly includes the following steps 101 to 103:

[0039] 101. When database statement conversion is required, determine the first database adapted by the business end itself and the replaced second database.

[0040] In some business scenarios of this embodiment, the business end will switch from its own adapted database to another database. In order to enable the business end to operate the replaced database without modifying the business end code, it is necessary to convert the statements of the business end to obtain statements that can operate the replaced database, so that the business end can operate the replaced database through the converted statements. Therefore, it is necessary to determine whether database statement conversion is required. The method for determining whether database statement conversion is required can include at least the following three methods:

[0041] The first method is to detect whether the data in the first database adapted by the business end itself is migrated to a database of a database type different from that of the first database; if so, it is determined that database statement conversion is required.

[0042] In some scenarios, users usually have their own accustomed database types, which are more convenient for users to use and maintain data. If the database type of the first database adapted by the business end purchased by the user is not the database type they are accustomed to, the data in the first database will be migrated to the database of the accustomed database type. For example, the first database adapted by the business end itself is the MYSQL database, and the user is accustomed to the DAMO database, so the data in the MYSQL database will be migrated to the DAMO database.

[0043] After the data in the first database is migrated to another database, the business end using the first database will inevitably switch from the first database to the migrated database so that it can continue to use the data to provide corresponding business services. In order to enable the business end to operate the replaced database without modifying the business end code, after the business end changes the database, it will inevitably determine that database statement conversion is required, so as to obtain statements that can operate the replaced database through statement conversion, so as to enable the business end to operate the replaced database through the converted statements. Therefore, it is possible to determine whether database syntax conversion is required by detecting whether the data in the first database adapted by the business end itself is migrated to a database of a different database type from the first database.

[0044] If it is detected that the data in the first database adapted by the business end itself is migrated to a database of a different database type from that of the first database, it means that the data required for the business end to provide business services is migrated to a database of a different database type from that of the first database. Therefore, in order to enable the business end to continue to provide business services based on these data, it is determined that database statement conversion is required so that the business end can operate the replaced database through the converted statements.

[0045] If it is detected that the data in the first database adapted by the business end itself has not been migrated, it means that the data required by the business end to implement business services still remains in the first database, and the business end can still use its own statements to continue operating the first database, so it is determined that no database statement conversion is required.

[0046] The second method is to detect whether the business end needs to migrate the data queried from the first database to a database of a different database type from the first database; if so, determine that database statement conversion is required.

[0047] In this embodiment, the business end may also have a data migration function. For example, the business end is used to migrate data in the first database adapted by itself to a database of a different database type from the first database, so as to manage and maintain data through the migrated database.

[0048] In order to enable the business end to migrate the data queried from the first database to a database of a different database type from the first database without modifying the business end code, it is necessary to determine whether database statement conversion is required, so as to obtain statements that can migrate the data to a database of a different database type from the first database through statement conversion, thereby achieving data migration through the converted statements. Therefore, it is possible to determine whether database syntax conversion is required by detecting whether the business end needs to migrate the data queried from the first database to a database of a different database type from the first database.

[0049] If it is detected that the business end needs to migrate the data queried from the first database to a database of a different database type from the first database, it means that the business end needs to change from operating the first database to operating a database of a different database type from the first database. Therefore, in order to enable the business end to operate a database of a different database type from the first database, it is determined that database statement conversion is required to achieve data migration through the converted statements.

[0050] If it is detected that the business end does not need to migrate the data queried from the first database to a database of a different database type from the first database, it means that the business end has not changed the database, so it is determined that no database statement conversion is required.

[0051] Third, if a database change instruction is received, it is determined that database statement conversion is required.

[0052] The database replacement instruction is used to indicate that the business end has replaced the database, and the database type of the replaced database is different from the database adapted by the business end itself. The database replacement instruction can specifically indicate the first database adapted by the business end itself and the replaced second database. There are two types of second databases here: one is that the second database is the database after the data migration of the first database, that is, the data in the second database is the same as that in the first database, but the database type of the second database is different from that of the first database. The other is that the second database and the first database are two independent databases, and the data in the second database and the first database are different, but the data in the second database can also support the business of the business end. In other words, the second database is not obtained by migrating the data in the first database.

[0053] If a database change instruction is received, it means that the business end has changed the database. Therefore, in order to enable the business end to operate the changed database, it is determined that database statement conversion is required, so that the business end can operate the changed database through the converted statement.

[0054] If no database change instruction is received, it means that the business end has not changed the database, so it is determined that database statement conversion is not required.

[0055] When it is determined that database statement conversion is required by the above method for determining whether database statement conversion is required, it is necessary to determine the first database adapted by the service end itself and the replaced second database.

[0056] In this embodiment, in order to enable the business end to flexibly change the database, a configuration file can be preset in advance. The preset configuration file is used to instruct the business end to change the database, and the database after the change is different from the database type of the database adapted by the business end itself, and specifically indicates the database adapted by the business end itself and the database after the change by the business end. Therefore, based on the database indicated by the preset configuration file, the first database adapted by the business end itself and the second database after the change can be determined. The first database in this embodiment is the database adapted by the statement writing code in the business end. No matter how many times the business end changes the database, as long as the statement writing code is not modified, the first database adapted by the business end itself remains unchanged. The second database in this embodiment is the database used by the business end after changing the database. The business end needs to provide corresponding business services by operating the replaced database.

[0057] 102. Determine target grammar files corresponding to the first database and the second database in the preset grammar files.

[0058] In this embodiment, the database management system stores preset grammar files corresponding to multiple databases. When the business end replaces the database, statement conversion is performed through the grammar files corresponding to the database originally adapted by the business end and the replaced database. The converted statements can enable the business end to operate the replaced database.

[0059] The preset grammar file is used to declare the grammar rules of the corresponding database. The file types of the preset grammar file may include the following two types: one is a grammar file used to declare the grammar rules of the corresponding database. The grammar file of this file type supports converting the grammar that conforms to the grammar rules of one database into the grammar that conforms to the grammar rules of another database. One is a grammar file used to record the correspondence between statements with the same semantics in two databases. The grammar file of this file type supports the statements before and after the conversion to have the same semantics. Only by combining the grammar files of the above two file types can statements that conform to the grammar rules of one database be converted into statements with the same semantics and conform to the grammar rules of another database. That is, through the grammar files of these two file types, it is possible to ensure that the semantics of the statements remain unchanged while performing grammatical conversion on the statements.

[0060] After determining the first database adapted by the business end itself and the replaced second database, in the preset grammar file, the target grammar files corresponding to the first database and the second database are determined, and the target grammar files include: a first grammar file for declaring grammar rules of the first database, a second grammar file for declaring grammar rules of the second database, and a third grammar file for recording the correspondence between statements with the same semantics in the first database and the second database.

[0061] 103. Based on the target grammar file, convert the first statement that complies with the grammar rules of the first database into a second statement that has the same semantics as the first statement and complies with the grammar rules of the second database.

[0062] The business end usually implements operations on the database through statements. In this embodiment, since the corresponding code in the business end is not modified after the business end changes the database, the first statement issued by the business end usually conforms to the syntax rules of the first database, but does not conform to the syntax rules of the second database. Therefore, in order to enable the business end to operate the replaced second database, it is necessary to convert the first statement that conforms to the syntax rules of the first database into a second statement that has the same semantics as the first statement and conforms to the syntax rules of the second database based on the target syntax file. The specific type of the first statement here is not limited in this embodiment. For example, the first statement can include but is not limited to any of the following: database login statement, database logout statement, data addition statement, data deletion statement, data query statement, data modification statement, data migration statement.

[0063] The target grammar file determined in step 102 includes a first grammar file for declaring grammar rules of the first database, a second grammar file for declaring grammar rules of the second database, and a third grammar file for recording the correspondence between statements with the same semantics in the first database and the second database. Therefore, based on the target grammar file, the specific process of converting a first statement that conforms to the grammar rules of the first database into a second statement that has the same semantics as the first statement and conforms to the grammar rules of the second database may include the following steps 103A to 103C:

[0064] 103A. Parse the first statement based on the grammar rules recorded in the first grammar file to obtain a first abstract syntax tree.

[0065] The specific process of parsing the first sentence based on the grammatical rules recorded in the first grammar file to obtain the first abstract syntax tree may include the following steps: using a preset parser to perform lexical analysis on the first sentence according to the grammatical rules recorded in the first grammar file, performing grammatical analysis on the word stream generated by the lexical analysis, and finally performing semantic analysis to obtain the corresponding first abstract syntax tree.

[0066] 103B. Based on the correspondence recorded in the third grammar file, replace the corresponding statements of the first abstract syntax tree with the corresponding statements of the second database to obtain a second abstract syntax tree.

[0067] In order to convert a second statement that has the same semantics as the first statement and conforms to the grammatical rules of the second database, after obtaining the first abstract syntax tree, it is necessary to execute the corresponding relationship recorded in the third syntax file, replace the statement in the first abstract syntax tree with the corresponding statement of the second database, and obtain the step of obtaining the second abstract syntax tree. The specific execution process of this step may include: determining the statements included in the first abstract syntax tree; for each determined statement, finding whether there is a corresponding relationship corresponding to the statement in the third syntax file, if so, replacing the statement with the corresponding statement of the second database based on the corresponding corresponding relationship; when all the determined statements have completed the corresponding replacement, the second abstract syntax tree is obtained. The statements included in the first abstract syntax tree are the statements that constitute the first statement. For example, the statement "sum" included in the first abstract syntax tree is replaced with the corresponding statement "sumi" of the second database based on the third syntax file.

[0068] Furthermore, if the first abstract syntax tree includes a third statement for which there is no corresponding relationship in the third syntax file, the semantics of the third statement is determined, a preset compilation function is called to compile a fourth statement having the semantics of the third statement and supported by the second database, and the third statement is replaced by the fourth statement.

[0069] If the first abstract syntax tree includes a third statement that has no corresponding relationship in the third syntax file, it means that based on the third syntax file, all statements in the first abstract syntax tree cannot be replaced with corresponding statements in the second database. At this time, in order not to affect the statement conversion process, the preset compilation function is called to compile a fourth statement that has the semantics of the third statement and is supported by the second database, and the third statement is replaced with the fourth statement.

[0070] Furthermore, in order to gradually improve the preset grammar file, the database statement conversion method may also include the following steps: after compiling the fourth statement, creating a correspondence between the third statement and the fourth statement, and adding the correspondence between the third statement and the fourth statement to the third grammar file.

[0071] The compiled fourth statement is a new fourth statement in the second database, so a correspondence between the third statement and the fourth statement is created, and the correspondence between the third statement and the fourth statement is added to the third grammar file to update the third grammar file. In this way, the updated third grammar file can be used subsequently to participate in new database statement conversion operations.

[0072] 103C. Process the second abstract syntax tree based on the syntax rules declared in the second syntax file to obtain a second statement.

[0073] The statements in the second abstract syntax tree are all statements supported by the second database. Therefore, in order to ensure that the business end can operate the second database, the second abstract syntax tree is processed based on the grammar rules declared in the second grammar file to obtain the second statement. The specific process of this step can be: the second abstract syntax tree is processed based on the grammar rules declared in the second grammar file by a preset statement compiler to obtain the second statement.

[0074] The second statement complies with the grammatical rules of the second database and has the same semantics as the first statement. Therefore, not only can the second statement be used to enable the business end to operate the second database, but it can also ensure that the operation on the second database meets the actual operation intention of the business end.

[0075] The database statement conversion method provided in the embodiment of the present application, when database statement conversion is required, determines the first database adapted by the business end itself and the second database after the business end is replaced. From the preset grammar file, determine the target grammar files corresponding to the first database and the second database. Based on the target grammar file, the first statement that conforms to the grammar rules of the first database is converted into a second statement that has the same semantics as the first statement and conforms to the grammar rules of the second database. It can be seen that the solution provided in the embodiment of the present application does not need to modify the code of the business end when the business end replaces the database. Statement conversion is performed through the grammar files corresponding to the database originally adapted by the business end and the replaced database, and the business end can operate the replaced database through the converted statements. In this way, not only can the intrusion of the business end code caused by the replacement of the database by the business end be avoided, but also the manpower and time cost invested in replacing the database by the business end can be reduced.

[0076] In some embodiments of the present application, in order to ensure that the second database can be operated to satisfy the real intention of the business end based on the second statement obtained by conversion, after the second statement is converted in the above step 103, the database statement conversion method may further include the following steps: determining whether there is a semantic difference between the first statement and the second statement; if not, operating the second database based on the second statement; if so, issuing a statement conversion failure prompt for the first statement.

[0077] Determining whether there is a semantic difference between the first sentence and the second sentence is to further verify whether the second sentence can truly express the true intention of the first sentence. The method of determining whether there is a semantic difference between the first sentence and the second sentence can include at least the following two methods:

[0078] First, the specific process of determining whether there is a semantic difference between the first sentence and the second sentence may include the following steps: performing semantic analysis on the first sentence and the second sentence to obtain semantic vectors of the first sentence and the second sentence respectively; detecting whether the similarity between the semantic vectors of the first sentence and the second sentence reaches a preset threshold; if so, determining that there is no semantic difference between the first sentence and the second sentence; if not, determining that there is a semantic difference between the first sentence and the second sentence.

[0079] In this embodiment, a corresponding semantic parsing model is preset for each database in advance, and a preset threshold value corresponding to any two databases is calibrated. After obtaining the second sentence, the semantic parsing models corresponding to the first database and the second database are used to process the first sentence and the second sentence respectively, and obtain the semantic vectors of the first sentence and the second sentence. Then the similarity between the semantic vectors of the first sentence and the second sentence is determined, and it is detected whether the similarity reaches the corresponding preset threshold value. If it is detected that the preset threshold value is reached, it means that the first sentence and the second sentence are most likely to have the same semantics, so it is determined that there is no semantic difference between the first sentence and the second sentence. If it is detected that the preset threshold value is not reached, it means that the first sentence and the second sentence are most likely to have different semantics, so it is determined that there is a semantic difference between the first sentence and the second sentence.

[0080] Second, the specific process of determining whether there is a semantic difference between the first statement and the second statement may include the following steps: parsing the first statement based on the grammar rules recorded in the first grammar file to obtain a first abstract syntax tree; parsing the second statement based on the grammar rules recorded in the second grammar file to obtain a second abstract syntax tree; detecting whether the statements in the first abstract syntax tree correspond one-to-one to the statements in the second abstract syntax tree, and whether the corresponding statements have the same semantics; if so, determining that there is no semantic difference between the first statement and the second statement; if not, determining that there is a semantic difference between the first statement and the second statement.

[0081] In this embodiment, the statements in the corresponding abstract syntax tree can be obtained through lexical analysis. In principle, if the first statement and the second statement have the same semantics, each statement in the first abstract syntax tree must have a corresponding statement with the same semantics in the second abstract syntax tree, and the statements in the second abstract syntax tree will not have more statements than those in the first abstract syntax tree. Therefore, it is detected whether the statements in the first abstract syntax tree correspond to the statements in the second abstract syntax tree one by one, and the corresponding statements have the same semantics.

[0082] If it is detected that the statements in the first abstract syntax tree correspond to the statements in the second abstract syntax tree one by one, and the corresponding statements have the same semantics, it means that the first statement and the second statement are likely to have the same semantics, and therefore it is determined that there is no semantic difference between the first statement and the second statement.

[0083] If it is detected that the statements in the first abstract syntax tree and the statements in the second abstract syntax tree are not one-to-one corresponding, or although it is detected that the statements in the first abstract syntax tree and the statements in the second abstract syntax tree correspond one-to-one but there are corresponding statements with different semantics, it means that the first statement and the second statement are likely to have different semantics, and therefore it is determined that there is a semantic difference between the first statement and the second statement.

[0084] The above two methods for determining whether there is a semantic difference between the first sentence and the second sentence may be used alone or in combination, and this embodiment does not make any specific limitation.

[0085] After determining whether there is a semantic difference between the first statement and the second statement, if it is determined that there is no semantic difference between the first statement and the second statement, it means that the second database can be operated based on the converted second statement to meet the real intention of the business end, so the second database is operated based on the second statement. If it is determined that there is a semantic difference between the first statement and the second statement, it means that only operations that do not meet the real intention of the business end can be performed on the second database based on the converted second statement, which means that there is an exception in the conversion of the first statement, so a statement conversion failure prompt is issued for the first statement, so that the user performs corresponding exception elimination processing based on the prompt.

[0086] In some embodiments of the present application, in order to more conveniently perform database statement conversion, the preset syntax file of this embodiment is stored in the global configuration file of the business end, and the global configuration file also stores the types and configuration parameters of the first database and the second database. Then the database statement conversion method also includes the following steps: in response to receiving a database change instruction, determining that database statement conversion is required; obtaining the global configuration file of the business end; based on the preset syntax file, the types and configuration parameters of the first database and the second database recorded in the global configuration file, migrating the data in the first database to the second database.

[0087] When receiving the database update instruction, the business end must have changed the database. Therefore, in order to enable the business end to operate the changed database, it is determined that database statement conversion is required, so that the business end can operate the changed database through the converted statement. In addition, it should be noted that the types and configuration parameters of the first database and the second database stored in the global configuration file are configured and stored in real time when the business end changes the database, so that the global configuration file can be guaranteed to be consistent with the real-time database change situation of the business end.

[0088] When it is determined that database conversion is required, the global configuration file of the business end is obtained. After obtaining the global matching file of the business end, the following two operations need to be performed: one is to determine the corresponding first database and second database based on the types of the first database and the second database recorded in the global configuration file, and determine the corresponding target syntax files of the first database and the second database from the preset syntax file; the other is to establish a connection with the second database based on the configuration parameters recorded in the global configuration file, so that after the second statement that can operate the second database is obtained through the conversion, the second database can be operated through the established connection. The configuration parameters may include but are not limited to the database address, user name, login password and other parameters that can enable the business end to legally connect and log in to the second database.

[0089] After performing the above two operations, the business end can query the target data to be migrated from the first database and form a first statement for migrating the target data to the second database. Then, based on the target syntax file, the first statement that conforms to the syntax rules of the first database is converted into a second statement that has the same semantics as the first statement and conforms to the syntax rules of the second database. Finally, the second statement is used to operate the second database through the connection established with the second database, thereby achieving the migration of the target data to the second database through the second statement.

[0090] In some embodiments of the present application, the database statement conversion method provided in this embodiment is applied to a database management system, and the database management system is used to implement the business end to operate the replaced database without modifying the business end code when the database is replaced. Figure 2 As shown, the database management system may include a global configurator, a syntax parser, a semantically compatible interpretation plug-in and a memory.

[0091] The global configurator is used to configure preset grammar files corresponding to multiple databases, and store the preset grammar files in the global configuration file of the business end. When the business end changes the database, the type of the first database adapted by the business end itself and the second database after the change and the corresponding configuration parameters are stored in the global configuration file. The memory is used to store the global configuration file of the business end.

[0092] When receiving a database update instruction, the database management system determines that database statement conversion is required and obtains the global configuration file of the business end. Then, based on the types of the first database and the second database recorded in the global configuration file, the corresponding first database and the second database are determined, and the target syntax files corresponding to the first database and the second database are determined from the preset syntax file, and a connection with the second database is established based on the configuration parameters recorded in the global configuration file, so that after the second statement that can operate the second database is obtained through conversion, the second database can be operated through the established connection. When the business end queries the target data to be migrated from the first database and forms a first statement for migrating the target data to the second database, the database management system converts the first statement that conforms to the syntax rules of the first database into a second statement that has the same semantics as the first statement and conforms to the syntax rules of the second database based on the target syntax file through the syntax parser and the semantically compatible interpretation plug-in, and finally uses the second statement to operate the second database through the connection established with the second database, thereby realizing the migration of the target data to the second database through the second statement.

[0093] Furthermore, an embodiment of the present application also provides a database statement conversion device, which is applied to a database management system, wherein the database management system stores preset grammar files corresponding to multiple databases, and the preset grammar files are used to declare the grammar rules of the corresponding database, such as Figure 3 As shown, the database statement conversion device includes:

[0094] A first determination module 21 is used to determine the first database adapted by the service end itself and the replaced second database when database statement conversion is required;

[0095] A second determination module 22, configured to determine, in a preset grammar file, target grammar files corresponding to the first database and the second database;

[0096] The conversion module 23 is used to convert, based on the target grammar file, a first statement that complies with the grammar rules of the first database into a second statement that has the same semantics as the first statement and complies with the grammar rules of the second database.

[0097] The database statement conversion device provided in the embodiment of the present application, when database statement conversion is required, determines the first database adapted by the business end itself and the second database after the business end is replaced. From the preset grammar file, determine the target grammar files corresponding to the first database and the second database. Based on the target grammar file, the first statement that conforms to the grammar rules of the first database is converted into a second statement that has the same semantics as the first statement and conforms to the grammar rules of the second database. It can be seen that the solution provided in the embodiment of the present application does not need to modify the code of the business end when the business end replaces the database. Statement conversion is performed through the grammar files corresponding to the database originally adapted by the business end and the replaced database, and the business end can operate the replaced database through the converted statements. In this way, not only can the intrusion of the business end code caused by the replacement of the database by the business end be avoided, but also the manpower and time cost invested in replacing the database by the business end can be reduced.

[0098] In some embodiments of the present application, Figure 4 As shown, the target grammar file includes a first grammar file for declaring grammar rules of the first database, a second grammar file for declaring grammar rules of the second database, and a third grammar file for recording the correspondence between statements with the same semantics in the first database and the second database; then, the conversion module 23 includes:

[0099] A parsing unit 231, configured to parse the first statement based on the grammar rules recorded in the first grammar file to obtain a first abstract syntax tree;

[0100] A replacing unit 232, configured to replace corresponding statements of the first abstract syntax tree with corresponding statements of the second database based on the corresponding relationship recorded in the third syntax file, so as to obtain a second abstract syntax tree;

[0101] The processing unit 233 is configured to process the second abstract syntax tree based on the grammar rules declared in the second grammar file to obtain the second statement.

[0102] In some embodiments of the present application, Figure 4 As shown, the conversion module 23 also includes:

[0103] The compiling unit 234 is configured to determine the semantics of the third statement if the first abstract syntax tree includes a third statement for which no corresponding relationship exists in the third syntax file, call a preset compiling function to compile a fourth statement having the semantics of the third statement and supported by the second database, and trigger the replacing unit 232 to replace the third statement with the fourth statement.

[0104] In some embodiments of the present application, Figure 4 As shown, the database statement conversion device also includes:

[0105] The adding module 24 is used to create a correspondence between the third statement and the fourth statement compiled by the compiling unit 234; and add the correspondence between the third statement and the fourth statement to the third grammar file.

[0106] In some embodiments of the present application, Figure 4 As shown, the preset grammar file is stored in a global configuration file of the service end, and the global configuration file also stores the types and configuration parameters of the first database and the second database; the database statement conversion device also includes:

[0107] The migration module 25 is used to determine the need for database statement conversion in response to receiving a database change instruction; obtain the global configuration file of the business end; and migrate the data in the first database to the second database based on the preset syntax file recorded in the global configuration file, the types and configuration parameters of the first database and the second database.

[0108] In some embodiments of the present application, Figure 4 As shown, the database statement conversion device also includes: a first detection module 26, which is used to detect whether the data in the first database adapted by the business end itself is migrated to a database of a database type different from that of the first database; if so, it is determined that database statement conversion is required.

[0109] In some embodiments of the present application, Figure 4As shown, the database statement conversion device also includes: a second detection module 27, which is used to detect whether the business end needs to migrate the data queried from the first database to a database of a database type different from that of the first database; if so, it is determined that database statement conversion is required.

[0110] In some embodiments of the present application, Figure 4 As shown, the database statement conversion device also includes:

[0111] The judgment module 28 is used to judge whether there is a semantic difference between the first statement and the second statement after the conversion module 23 obtains the second statement; if not, operate the second database based on the second statement; if so, issue a statement conversion failure prompt for the first statement.

[0112] In some embodiments of the present application, Figure 4 As shown, the judgment module 28 is specifically used to perform semantic analysis on the first sentence and the second sentence to obtain the semantic vectors of the first sentence and the second sentence respectively; detect whether the similarity between the semantic vectors of the first sentence and the second sentence reaches a preset threshold; if so, determine that there is no semantic difference between the first sentence and the second sentence; if not, determine that there is a semantic difference between the first sentence and the second sentence.

[0113] In some embodiments of the present application, the database is a relational database; and / or the first statement includes any one of the following: a database login statement, a database logout statement, a data addition statement, a data deletion statement, a data query statement, a data modification statement, and a data migration statement.

[0114] In the database statement conversion device provided in the embodiment of the present application, the detailed explanations used in the operation of each functional module can be found in the corresponding detailed explanations of the above-mentioned database statement conversion method embodiment, which will not be repeated here.

[0115] Furthermore, an embodiment of the present application also provides a computer-readable storage medium, wherein the storage medium includes a stored program, wherein when the program is executed, the device where the storage medium is located is controlled to execute the above-mentioned database statement conversion method.

[0116] Furthermore, an embodiment of the present application also provides an electronic device, which includes: a memory for storing a program; and a processor, coupled to the memory, for running the program to execute the above-mentioned database statement conversion method.

[0117] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0118] It is understandable that the related features in the above methods and devices can be referenced to each other. In addition, the "first", "second" and the like in the above embodiments are used to distinguish the embodiments, but do not represent the advantages and disadvantages of the embodiments.

[0119] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0120] The algorithm and display provided herein are not inherently related to any particular computer, virtual system or other device. Various general purpose systems can also be used together with the teachings based on this. According to the above description, it is obvious to construct the structure required for this type of system. In addition, the application is not directed to any specific programming language either. It should be understood that various programming languages ​​can be utilized to realize the content of the application described herein, and the description of the above specific language is to disclose the preferred embodiment of the application.

[0121] In addition, the memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.

[0122] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0123] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data cutover device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data cutover device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0124] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data switching device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0125] These computer program instructions can also be loaded onto a computer or other programmable data transfer device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0126] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0127] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0128] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.

[0129] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0130] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0131] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.

Claims

1. A database statement conversion method, characterized in that: Applied to a database management system, the database management system stores preset grammar files corresponding to a plurality of databases respectively, the preset grammar files are used to declare grammar rules of the corresponding databases, the method comprises: When database statement conversion is required, determine the first database adapted by the business end itself and the replaced second database; Determine, in a preset grammar file, target grammar files corresponding to the first database and the second database; Based on the target grammar file, a first statement conforming to the grammar rule of the first database is converted into a second statement having the same semantics as the first statement and conforming to the grammar rule of the second database.

2. The method according to claim 1, characterized in that The target grammar file includes a first grammar file for declaring grammar rules of a first database, a second grammar file for declaring grammar rules of a second database, and a third grammar file for recording the correspondence between statements with the same semantics in the first database and the second database; then, based on the target grammar file, converting a first statement that conforms to the grammar rules of the first database into a second statement that has the same semantics as the first statement and conforms to the grammar rules of the second database includes: Parse the first statement based on the grammar rules recorded in the first grammar file to obtain a first abstract syntax tree; Based on the correspondence recorded in the third grammar file, corresponding statements of the first abstract syntax tree are replaced with corresponding statements of the second database to obtain a second abstract syntax tree; The second abstract syntax tree is processed based on the syntax rules declared in the second syntax file to obtain the second statement.

3. The method according to claim 2, characterized in that The method further comprises: If the first abstract syntax tree includes a third statement for which no corresponding relationship exists in the third syntax file, the semantics of the third statement is determined, a preset compilation function is called to compile a fourth statement having the semantics of the third statement and supported by the second database, and the third statement is replaced by the fourth statement.

4. The method according to claim 3, characterized in that The method further comprises: Creating a correspondence between the third statement and the fourth statement; Add the correspondence between the third statement and the fourth statement to the third grammar file.

5. The method according to claim 1, characterized in that The preset grammar file is stored in a global configuration file of the service end, and the global configuration file also stores the types and configuration parameters of the first database and the second database; the method further includes: In response to receiving a database change instruction, determining that a database statement conversion is required; Obtaining a global configuration file of the service end; Based on the preset grammar file recorded in the global configuration file, the types and configuration parameters of the first database and the second database, the data in the first database is migrated to the second database.

6. The method according to claim 1, characterized in that The method further comprises: Detecting whether the data in the first database adapted by the service end itself is migrated to a database of a different database type from that of the first database; If so, it is determined that database statement conversion is required.

7. The method according to claim 1, characterized in that The method further comprises: detecting whether the business end needs to migrate the data queried from the first database to a database of a different database type from that of the first database; If so, it is determined that database statement conversion is required.

8. The method according to any one of claims 1 to 7, characterized in that After obtaining the second statement, the method further includes: Determining whether there is a semantic difference between the first sentence and the second sentence; If not, operating the second database based on the second statement; If so, a statement conversion failure prompt is issued for the first statement.

9. The method according to claim 8, characterized in that Determining whether there is a semantic difference between the first statement and the second statement includes: Performing semantic analysis on the first sentence and the second sentence to obtain semantic vectors of the first sentence and the second sentence respectively; Detecting whether the similarity between the semantic vectors of the first sentence and the second sentence reaches a preset threshold; If so, it is determined that there is no semantic difference between the first statement and the second statement; If not, it is determined that there is a semantic difference between the first statement and the second statement.

10. The method according to any one of claims 1 to 7 and 9, characterized in that: The database is a relational database; And / or, the first statement includes any one of the following: a database login statement, a database logout statement, a data addition statement, a data deletion statement, a data query statement, a data modification statement, and a data migration statement.

11. A database statement conversion device, characterized in that: Applied to a database management system, the database management system stores preset grammar files corresponding to multiple databases respectively, the preset grammar files are used to declare grammar rules of the corresponding databases, and the device includes: A first determination module is used to determine the first database adapted by the business end itself and the replaced second database when database statement conversion is required; A second determination module, used to determine the target grammar files corresponding to the first database and the second database in a preset grammar file; A conversion module is used to convert, based on the target grammar file, a first statement that complies with the grammar rules of the first database into a second statement that has the same semantics as the first statement and complies with the grammar rules of the second database.

12. A computer-readable storage medium, characterized in that: The storage medium includes a stored program, wherein when the program is running, the device where the storage medium is located is controlled to execute the database statement conversion method according to any one of claims 1 to 10.

13. An electronic device, characterized in that: The electronic device comprises: Memory, used to store programs; A processor, coupled to the memory, is used to run the program to execute the database statement conversion method according to any one of claims 1 to 10.

Citation Information

Patent Citations

  • Source code equivalence verification device and source code equivalence verification method

    CN105408872A

  • SQL (Structured Query Language) statement processing method and device, electronic equipment and storage medium

    CN115269632A

  • General heterogeneous relational database SQL migration method based on parse tree

    CN116450616A

  • Method for transforming Oracle storage process and related equipment thereof

    CN116450752A

  • Database migration method and device, equipment and storage medium

    CN117112536A

Cited By

  • Grammar error processing method and device, cluster, storage medium and program product

    CN119441257A