SQL conversion method, device, computer equipment and storage medium
By parsing and converting native SQL, and using database dialect instances to generate SQL of the target dialect type, it solves the problem of SQL differences between database dialects and improves the versatility and efficiency of the code.
Patent Information
- Application Number
- CN202311069057.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-23
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2043-08-23
AI Technical Summary
In the existing technology, there are differences in the SQL language between database dialects, which results in the need to write multiple sets of codes that have nothing to do with the business, reducing the versatility of the code.
By obtaining the native SQL, parsing it into a collection of syntax tree objects, and using the database dialect instance to convert the syntax structure, combined with the conversion vector table, the converted SQL of the target dialect type is generated to achieve compatibility between different databases.
It improves the versatility and usage efficiency of SQL, enables switching between different databases, and reduces the need to write multiple sets of codes.
Smart Images

Figure CN117033348B
Abstract
Description
Technical Field
[0001] The present application relates to the field of database technology, and in particular to an SQL conversion method, apparatus, computer equipment, storage medium and computer program product. Background Art
[0002] Database dialect refers to a set of grammatical rules and data structures used to represent the structure and properties of a database. It is one of the important concepts in database theory and is used to build various types of databases, including relational databases and non-relational databases. Developers will use multiple types of databases when developing applications. Therefore, applications need to support the ability to switch between different database types.
[0003] In the related art, for different databases, the SQL language written by database vendors itself has differences (different SQL language expressions, applicable syntax, etc. are different, and some may also have fields, functions and table names customized by the database vendor, etc.). If it is necessary to switch between different databases, in order to achieve the compatibility of the SQL language, it is also necessary to write multiple sets of business-independent codes, resulting in poor versatility of the code. Summary of the invention
[0004] Based on this, it is necessary to provide a SQL conversion method, apparatus, computer device, computer-readable storage medium and computer program product that can ensure the universality of code files in response to the above technical problems.
[0005] In a first aspect, the present application provides a SQL conversion method. The method comprises:
[0006] Obtain native SQL, parse the native SQL, and obtain a set of syntax tree objects, wherein the native SQL is generated when the application is running;
[0007] Obtaining data source connection information of the application program through a dialect component, determining a database type based on the data source connection information, and determining a database dialect instance corresponding to the database type;
[0008] Parsing the syntax structure of the native SQL into a data structure of a target item of the syntax tree object set through a database dialect instance, and converting the data structure of the target item with a conversion vector table to obtain a converted SQL of a target dialect type;
[0009] If it is determined that the conversion is normal, a network request is initiated to the database based on the converted SQL.
[0010] In one embodiment, obtaining native SQL includes:
[0011] Obtain the target data message through the dialect component;
[0012] The target data message is parsed to obtain the native SQL contained in the target data message.
[0013] In one embodiment, the parsing of the grammatical structure of the native SQL into a data structure of a target item of the syntax tree object set through a database dialect instance, and converting the data structure of the target item with a conversion vector table to obtain a converted SQL of a target dialect type includes:
[0014] If it is determined that the statement type of the native SQL is a data definition language type, the syntax structure of the native SQL is converted into a data structure of an SQL query instruction set of the syntax tree object set through the database dialect instance, and based on the data structure of the SQL query instruction set and a field type mapping vector table, a definition conversion of the database field type is performed to obtain a mySQL field definition of the target dialect type;
[0015] Based on the mySQL field definition of the target dialect type, get the converted SQL of the target dialect type.
[0016] In one embodiment, the parsing of the grammatical structure of the native SQL into a data structure of a target item of the syntax tree object set through a database dialect instance, and converting the data structure of the target item with a conversion vector table to obtain a converted SQL of a target dialect type includes:
[0017] If it is determined that the statement type of the native SQL is a data query language type, extracting the data structure of the SQL query instruction set from the syntax tree object set through the database dialect instance;
[0018] Based on the data structure of the SQL query instruction set, extract the data structure of the SQL expression, parse the function name, perform function conversion based on the function vector table, and obtain the function of the target dialect type;
[0019] Based on the function of the target dialect type, a converted SQL of the target dialect type is obtained.
[0020] In one embodiment, the parsing of the grammatical structure of the native SQL into a data structure of a target item of the syntax tree object set through a database dialect instance, and converting the data structure of the target item with a conversion vector table to obtain a converted SQL of a target dialect type includes:
[0021] If it is determined that the statement type of the native SQL is a data query language type, extracting the data structure of the SQL query instruction set from the syntax tree object set through the database dialect instance;
[0022] Based on the data structure of the SQL query instruction set, extract the data structure of the SQL limited query, and perform paging conversion based on the paging template conversion table to obtain paging of the target dialect type;
[0023] Based on the paging of the target dialect type, a converted SQL of the target dialect type is obtained.
[0024] In one embodiment, the parsing of the grammatical structure of the native SQL into a data structure of a target item of the syntax tree object set through a database dialect instance, and converting the data structure of the target item with a conversion vector table to obtain a converted SQL of a target dialect type includes:
[0025] If it is determined that the statement type of the native SQL is a data definition language type, extracting a data structure of a SQL query instruction set from a syntax tree object set through the database dialect instance;
[0026] Based on the data structure of the SQL query instruction set, extract the data structure of the SQL expression, parse the function name, perform function conversion based on the function vector table, and obtain the function of the target dialect type;
[0027] Based on the data structure of the SQL query instruction set, extract the data structure of the SQL limited query, and perform paging conversion based on the paging template conversion table to obtain paging of the target dialect type;
[0028] Based on the function of the target dialect type and the paging of the target dialect type, a converted SQL of the target dialect type is obtained.
[0029] In one embodiment, the method further comprises:
[0030] If the conversion is determined to be abnormal, an abnormal prompt message is generated and output.
[0031] In one embodiment, initiating a network request to a database based on the converted SQL includes:
[0032] The converted SQL is sent to a target drive component, and through the target drive component, a network request is initiated to a database based on the converted SQL.
[0033] In a second aspect, the present application also provides a SQL conversion device. The device comprises:
[0034] A first acquisition module is used to acquire native SQL, parse the native SQL, and obtain a syntax tree object set, wherein the native SQL is generated when the application is running;
[0035] A second acquisition module is used to acquire data source connection information of the application through a dialect component, determine a database type based on the data source connection information, and determine a database dialect instance corresponding to the database type;
[0036] An extraction module, used to parse the syntax structure of the native SQL into a data structure of a target item of the syntax tree object set through a database dialect instance, and convert the data structure of the target item with a conversion vector table to obtain a converted SQL of a target dialect type;
[0037] The request module is used to initiate a network request to the database based on the converted SQL if it is determined that the conversion is normal.
[0038] In one embodiment, the first acquisition module is specifically used to:
[0039] Obtain the target data message through the dialect component;
[0040] The target data message is parsed to obtain the native SQL contained in the target data message.
[0041] In one embodiment, the extraction module is specifically used to:
[0042] If it is determined that the statement type of the native SQL is a data definition language type, the syntax structure of the native SQL is converted into a data structure of an SQL query instruction set of the syntax tree object set through the database dialect instance, and based on the data structure of the SQL query instruction set and a field type mapping vector table, a definition conversion of the database field type is performed to obtain a mySQL field definition of the target dialect type;
[0043] Based on the mySQL field definition of the target dialect type, get the converted SQL of the target dialect type.
[0044] In one embodiment, the extraction module is specifically used to:
[0045] If it is determined that the statement type of the native SQL is a data query language type, extracting the data structure of the SQL query instruction set from the syntax tree object set through the database dialect instance;
[0046] Based on the data structure of the SQL query instruction set, extract the data structure of the SQL expression, parse the function name, perform function conversion based on the function vector table, and obtain the function of the target dialect type;
[0047] Based on the function of the target dialect type, a converted SQL of the target dialect type is obtained.
[0048] In one of the embodiments, the extraction module is specifically used to: if it is determined that the statement type of the native SQL is a data query language type, extract the data structure of the SQL query instruction set from the syntax tree object set through the database dialect instance;
[0049] Based on the data structure of the SQL query instruction set, extract the data structure of the SQL limited query, and perform paging conversion based on the paging template conversion table to obtain paging of the target dialect type;
[0050] Based on the paging of the target dialect type, a converted SQL of the target dialect type is obtained.
[0051] In one of the embodiments, the extraction module is specifically used to: if it is determined that the statement type of the native SQL is a data definition language type, extract the data structure of the SQL query instruction set from the syntax tree object set through the database dialect instance;
[0052] Based on the data structure of the SQL query instruction set, extract the data structure of the SQL expression, parse the function name, perform function conversion based on the function vector table, and obtain the function of the target dialect type;
[0053] Based on the data structure of the SQL query instruction set, extract the data structure of the SQL limited query, and perform paging conversion based on the paging template conversion table to obtain paging of the target dialect type;
[0054] Based on the function of the target dialect type and the paging of the target dialect type, a converted SQL of the target dialect type is obtained.
[0055] In one embodiment, the device further comprises:
[0056] A generation module is used to generate an abnormal prompt message if the conversion is determined to be abnormal, and output the abnormal prompt message.
[0057] In one of the embodiments, the request module is specifically used to: send the converted SQL to a target driver component, and initiate a network request to a database based on the converted SQL through the target driver component.
[0058] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0059] Obtain native SQL, parse the native SQL, and obtain a set of syntax tree objects, wherein the native SQL is generated when the application is running;
[0060] Obtaining data source connection information of the application program through a dialect component, determining a database type based on the data source connection information, and determining a database dialect instance corresponding to the database type;
[0061] Parsing the syntax structure of the native SQL into a data structure of a target item of the syntax tree object set through a database dialect instance, and converting the data structure of the target item with a conversion vector table to obtain a converted SQL of a target dialect type;
[0062] If it is determined that the conversion is normal, a network request is initiated to the database based on the converted SQL.
[0063] In a fourth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0064] Obtain native SQL, parse the native SQL, and obtain a set of syntax tree objects, wherein the native SQL is generated when the application is running;
[0065] Obtaining data source connection information of the application program through a dialect component, determining a database type based on the data source connection information, and determining a database dialect instance corresponding to the database type;
[0066] Parsing the syntax structure of the native SQL into a data structure of a target item of the syntax tree object set through a database dialect instance, and converting the data structure of the target item with a conversion vector table to obtain a converted SQL of a target dialect type;
[0067] If it is determined that the conversion is normal, a network request is initiated to the database based on the converted SQL.
[0068] In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0069] Obtain native SQL, parse the native SQL, and obtain a set of syntax tree objects, wherein the native SQL is generated when the application is running;
[0070] Obtaining data source connection information of the application program through a dialect component, determining a database type based on the data source connection information, and determining a database dialect instance corresponding to the database type;
[0071] Parsing the syntax structure of the native SQL into a data structure of a target item of the syntax tree object set through a database dialect instance, and converting the data structure of the target item with a conversion vector table to obtain a converted SQL of a target dialect type;
[0072] If it is determined that the conversion is normal, a network request is initiated to the database based on the converted SQL.
[0073] The above-mentioned SQL conversion method, device, computer equipment, storage medium and computer program product, the method includes: obtaining native SQL, parsing native SQL, and obtaining a syntax tree object set, the native SQL is generated by the application when it is running; obtaining the data source connection information of the application through the dialect component, determining the database type based on the data source connection information, and determining the database dialect instance corresponding to the database type; parsing the syntax structure of the native SQL into the data structure of the target item of the syntax tree object set through the database dialect instance, and converting the data structure of the target item with the conversion vector table to obtain the converted SQL of the target dialect type; if it is determined that the conversion is normal, then initiating a network request to the database based on the converted SQL. By adopting this method, after reading the structure of the database, it can generate functions of corresponding dialect types corresponding to different database parsing, realize switching between different databases, improve the versatility of the compiled SQL, and improve the use efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0074] Figure 1 A flowchart of an SQL conversion method in one embodiment;
[0075] Figure 2 It is a flowchart of intercepting native SQL steps in one embodiment;
[0076] Figure 3 A flowchart of a step of obtaining a converted SQL of a target dialect type in one embodiment;
[0077] Figure 4 A flowchart of a step of obtaining a converted SQL of a target dialect type in one embodiment;
[0078] Figure 5 A flowchart of a step of obtaining a converted SQL of a target dialect type in one embodiment;
[0079] Figure 6A flowchart of a step of obtaining a converted SQL of a target dialect type in one embodiment;
[0080] Figure 7 A flowchart of an SQL conversion method in another embodiment;
[0081] Figure 8 is a structural block diagram of an SQL conversion device in an embodiment;
[0082] Fig. 9 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0083] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0084] In one embodiment, a SQL conversion method is provided. This embodiment uses the method applied to a database client as an example. It is understandable that the database system may include multiple database clients and database servers corresponding to the database clients, i.e., database devices. The database server is used to store data, and the database client and the database server may communicate through a network. The database client may be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, etc., and the database server may be implemented as an independent server or a server cluster consisting of multiple servers. In this embodiment, Figure 1 As shown, taking the application in a database client as an example for illustration, the SQL conversion method includes the following steps:
[0085] Step 102, obtain native SQL, parse the native SQL, and obtain a syntax tree object set.
[0086] The native SQL is generated when the application is running; the native SQL refers to the language used for data management and query using a relational database management system (RDBMS). The syntax tree object collection may be an st collection (Sql Select Query collection), and the syntax tree object collection may contain the following content as shown in Table 1:
[0087] Table 1
[0088]
[0089] Specifically, other communication devices can interact with the database device with data packets containing native SQL. Before other communication devices send native SQL, the database client can use the language of relational database management system for data management and query, that is, obtain one or more native SQLs, and parse each native SQL to obtain the syntax object set corresponding to each native SQL (which can be recorded as Sql Select Query object set).
[0090] Step 104: obtain the data source connection information of the application program through the dialect component, determine the database type based on the data source connection information, and determine the database dialect instance corresponding to the database type.
[0091] Among them, the application can be an application using the database device of the above-mentioned embodiment, that is, an application whose data is stored in the database device, or an application running on a database client, etc.; the data source connection information of the application can be connection information used to characterize the database type used by the application; in an example, the data source connection information of mysql can be: jdbc:mysql: / / IP:port, etc.
[0092] Specifically, the database client can obtain the data source connection information corresponding to the database device used by the application, and determine the database type of the database device used based on the data source connection information through the dialect component, and determine the corresponding database dialect instance based on the determined database type. The database client can also initialize the determined database dialect instance to obtain the initialized database dialect instance. The database dialect instance can include multiple syntax tree objects, for example, a syntax tree object for describing a list of fields, i.e., SQL Select Items; a syntax tree object for describing a function, i.e., a SQL Expr data structure (a data structure of an SQL expression); a syntax tree object for describing paging, i.e., a SQL Limit data structure (a data structure of an SQL limited query), and the like.
[0093] Step 106, through the database dialect instance, the syntax structure of the native SQL is parsed and converted into the data structure of the target item of the syntax tree object set, and the data structure of the target item is converted with the conversion vector table to obtain the converted SQL of the target dialect type.
[0094] Among them, the data structure of the target item of the syntax tree object set that is parsed and converted into the syntax structure of the native SQL can be a syntax tree object of the SQL Select Items (SQL query instruction set) that describes a list of fields, representing the field definition of the native SQL, and the conversion vector table can include the correspondence between the various field definitions in multiple types of databases, and can also include the correspondence between the functions in multiple types of databases and the correspondence between the paging templates in multiple types of databases.
[0095] Specifically, the database client can determine the grammatical structure of the native SQL through the database dialect instance, and convert the grammatical structure of the native SQL into a syntax tree object set containing a data structure corresponding to the target item, and perform conversion calculations based on the target dialect type, the data structure of the target item, and the conversion vector table corresponding to the data structure of the target item to obtain the converted SQL of the target dialect type.
[0096] In one example, the data structure corresponding to the target item contained in the syntax tree object set determined by the database client may be a syntax tree object of SQL Select Items for describing a list of fields. In this way, the database client determines that the conversion vector table corresponding to the syntax tree object of SQL Select Items for the list of fields may include field type definitions of multiple dialect types. In this way, the database client can query and convert the field type definitions of multiple dialect types based on the syntax tree object of SQL SelectItems for describing a list of fields and the target dialect type to obtain the converted SQL of the target dialect type.
[0097] Step 108: If the conversion is determined to be normal, a network request is initiated to the database based on the converted SQL.
[0098] Specifically, the database client can determine whether the converted SQL obtained based on the conversion vector table is normal; if the database client determines that the conversion based on the conversion vector table is normal and the converted SQL obtained is also normal, the database client can initiate a network request to the database device based on the converted SQL, that is, the SQL of the target dialect type. In an example, the network request can be a database query request, a database table creation request, or a database table deletion request, etc.
[0099] In the above SQL conversion method, native SQL is obtained, parsed, and a set of syntax tree objects is obtained. The native SQL is generated when the application is running; the data source connection information of the application is obtained through the dialect component, and the database type is determined based on the data source connection information, and the database dialect instance corresponding to the database type is determined; through the database dialect instance, the syntax structure of the native SQL is parsed and converted into the data structure of the target item of the syntax tree object set, and the data structure of the target item is converted with the conversion vector table to obtain the converted SQL of the target dialect type; if the conversion is determined to be normal, a network request is initiated to the database based on the converted SQL. By adopting this method, after reading the structure of the database, the corresponding dialect type of language can be generated according to different database parsing, so as to realize switching between different databases, improve the versatility of the compiled SQL, and improve the use efficiency.
[0100] In one embodiment, Figure 2 As shown, the specific processing process of step 102 "obtaining native SQL" includes:
[0101] Step 202, obtaining the target data message through the dialect component.
[0102] Step 204: parse the target data message to obtain the native SQL contained in the target data message.
[0103] The target configuration file may be a code file of the application program, or a pre-configured configuration file of the application program. The target configuration file may also be a code file.
[0104] Specifically, the database client can use the dialect component to read the target data message in the target configuration file, parse the target data message, and obtain the native SQL carried by the target data message; the database client can also read the native SQL in the code file.
[0105] In this embodiment, the target data message is read through the dialect component, and the target data message is parsed to obtain the native SQL contained in the target data message, which can ensure the efficiency of obtaining the native SQL and improve the versatility of the native SQL.
[0106] In one embodiment, Figure 3 As shown, the specific processing process of step 106 "through the database dialect instance, parsing the syntax structure of the native SQL into the data structure of the target item of the syntax tree object set, and converting the data structure of the target item with the conversion vector table to obtain the converted SQL of the target dialect type" includes:
[0107] Step 302, if it is determined that the statement type of the native SQL is a data definition language type, the syntax structure of the native SQL is converted into the data structure of the SQL query instruction set of the syntax tree object set through the database dialect instance, and based on the data structure of the SQL query instruction set and the field type mapping vector table, the definition conversion of the database field type is performed to obtain the mySQL field definition of the target dialect type.
[0108] The SQL statement for processing the database device may include multiple statement types, and the DDL type may be a data definition language (Data Definition Language), which is a language used to describe real-world entities to be stored in the database. The field type mapping vector table includes field type definitions of multiple dialect types, for example, it may include field type definitions of multiple dialect types and the correspondence between field type definitions of each dialect type. For example, for the target field type definition, the type mapping vector table may include a target field type definition of a first dialect type, and a target field type definition of a second dialect type, and may also include target field type definitions of various other dialect types.
[0109] In an example, the field type mapping vector table may be a TypeMappings vector table, which may include multiple dialect types, such as SQLiteDialect, AccessDialect, ExcelDialect, TextDialect, ParadoxDialect, and CobolDialect. Various field type definitions may include: t_BIGINT, t_BINARY, t_BIT, t_BLOB, and t_BOOLEAN. It may include dialect representations of various field types under various dialect types. For example, for the t_BIGINT field, its corresponding various dialect representations, that is, various dialect field type definitions may include: bigint, integer, bigint, bigint, integer, and bigint, respectively corresponding to the various dialect types described above.
[0110] Specifically, when the database client determines that the statement type of the native SQL corresponding to the database device used by the application is a data definition language type, the database client can convert the grammatical structure of the native SQL through the database dialect instance, and specifically can convert the grammatical structure of the native SQL into a data structure of corresponding items in a syntax tree object set obtained by parsing the native SQL; for example, when the statement type of the native SQL is a data definition language type, the data structure of the corresponding items contained in the syntax tree object set can be a data structure of SQL Select Items, and the database client can convert the grammatical structure of the native SQL into a data structure of SQL Select Items, and based on the data structure of SQL Select Items and the field type mapping vector table and the target dialect type corresponding to the database device, perform a definition conversion of the database field type, that is, query the target field under the target dialect type representation in the type mapping vector table to obtain the MySQL field definition of the target dialect type.
[0111] Step 304: based on the mySQL field definition of the target dialect type, obtain the converted SQL of the target dialect type.
[0112] Specifically, the database client can obtain the converted SQL of the target dialect type through the MySQL field definition of the target dialect type obtained after the conversion.
[0113] In this embodiment, field type definition conversion is performed based on the data structure of SQL Select Items to enhance the versatility of SQL and improve the efficiency of SQL usage.
[0114] In one embodiment, Figure 4 As shown, the specific processing process of step 106 "through the database dialect instance, parsing the syntax structure of the native SQL into the data structure of the target item of the syntax tree object set, and converting the data structure of the target item with the conversion vector table to obtain the converted SQL of the target dialect type" includes:
[0115] Step 402: If it is determined that the statement type of the native SQL is a data query language type, then the data structure of the SQL query instruction set is extracted from the syntax tree object set through the database dialect instance.
[0116] The dql type may be a data query language (Data Query Language) type, that is, the statement type corresponding to the native SQL may be a data query language (Data Query Language) type.
[0117] Specifically, the database client can determine the type of database used by the application. If the database client determines that the type of database used by the application is a data query language type, the database client can extract the data structure of the SQL query instruction set from the syntax tree object set through the database dialect instance corresponding to the database type.
[0118] When the database client determines that the statement type of the native SQL corresponding to the database device used by the application is the dql type, the database client can convert the grammatical structure of the native SQL through the database dialect instance. Specifically, the grammatical structure of the native SQL can be converted into a data structure of corresponding items in a syntax tree object set obtained by parsing the native SQL; for example, when the statement type of the native SQL is the dql type, the data structure of the corresponding items (target items) contained in the syntax tree object set can be a data structure of SQL Select Items and a data structure of SQL Expr.
[0119] Step 404, based on the data structure of the SQL query instruction set, extract the data structure of the SQL expression, parse the function name, perform function conversion based on the function vector table, and obtain the function of the target dialect type.
[0120] The function vector table may store a plurality of functions. The function vector table includes functions of a plurality of dialect types, for example, functions of a plurality of dialect types and the correspondence between functions of each dialect type. For example, for a target function, the function vector table may include a target function of a first dialect type, a target function of a second dialect type, and may also include target functions of various other dialect types.
[0121] Specifically, the database client can extract from the data structure of SQL SELECT ITEMS extracted from the parsed syntax tree object set through the database dialect instance to obtain the SQL Expr data structure; in this way, the database client can further determine that the data structure of the corresponding item contained in the syntax tree object set can be the SQL Expr data structure; the database client can convert the syntax structure of the native SQL into the SQL Expr data structure, and determine the target function based on the SQL Expr data structure, and convert the database function type based on the target function, the function vector table and the target dialect type corresponding to the database device, that is, query the target function under the target dialect type representation in the function vector table to obtain the function of the target dialect type.
[0122] Step 406: Based on the function of the target dialect type, obtain the converted SQL of the target dialect type.
[0123] Specifically, the database client may replace the function in the native SQL based on the function of the target dialect type, that is, replace the function in the native SQL with the function of the target dialect type to obtain the converted SQL of the target dialect type.
[0124] In this embodiment, function conversion is performed based on the SQL Expr data structure and a function mapping table corresponding to multiple dialect types, thereby improving the versatility of SQL and the efficiency of SQL usage.
[0125] In one embodiment, Figure 5 As shown, the specific processing process of step 106 "through the database dialect instance, parsing the syntax structure of the native SQL into the data structure of the target item of the syntax tree object set, and converting the data structure of the target item with the conversion vector table to obtain the converted SQL of the target dialect type" includes:
[0126] Step 502: If it is determined that the statement type of the native SQL is a data query language type, then the data structure of the SQL query instruction set is extracted from the syntax tree object set through the database dialect instance.
[0127] The dql type may be a Data Query Language (Data Query Language) type.
[0128] Specifically, the database client can determine the type of database used by the application. If the database client determines that the type of database used by the application is a data query language type, the database client can extract the data structure of the SQL query instruction set from the syntax tree object set through the database dialect instance corresponding to the database type.
[0129] When the database client determines that the statement type of the native SQL corresponding to the database device used by the application is the dql type, the database client can convert the grammatical structure of the native SQL through the database dialect instance. Specifically, the grammatical structure of the native SQL can be converted into a data structure of corresponding items in a syntax tree object set obtained by parsing the native SQL; for example, when the statement type of the native SQL is the dql type, the data structure of the corresponding items (target items) contained in the syntax tree object set can be a data structure of SQL Select Items and a data structure of SQL Limit.
[0130] Step 504: extract the data structure of the SQL limited query based on the data structure of the SQL query instruction set, perform paging conversion based on the paging template conversion table, and obtain paging of the target dialect type.
[0131] Among them, the paging template conversion table can store multiple paging templates. The paging template conversion table includes paging templates of multiple dialect types, for example, it can include paging templates of multiple dialect types and the correspondence between paging templates of each dialect type. For example, for a target paging template, the paging template conversion table can include a target paging template of a first dialect type, and a target paging template of a second dialect type, and can also include target paging templates of various other dialect types.
[0132] Specifically, the database client can extract from the data structure of SQL SELECT ITEMS extracted from the parsed syntax tree object set through the database dialect instance to obtain the SQL Limit data structure; in this way, the database client can further determine that the data structure of the corresponding item contained in the syntax tree object set can be the SQL Limit data structure; the database client can convert the syntax structure of the native SQL into the SQL Limit data structure, and determine the target paging template (i.e., the paging template of the native SQL) based on the SQL Limit data structure. The database client can perform database paging template conversion based on the target paging template, the paging template conversion table, and the target dialect type corresponding to the database device, that is, query the target paging template under the target dialect type representation in the paging template conversion table to obtain the paging of the target dialect type.
[0133] Step 506: Based on the paging of the target dialect type, obtain the converted SQL of the target dialect type.
[0134] Specifically, the database client may replace the paging template in the native SQL based on the paging template of the target dialect type, that is, replace the paging template in the native SQL with the paging template of the target dialect type to obtain the converted SQL of the target dialect type.
[0135] In this embodiment, the paging template is converted based on the data structure of SQL Select Items and the data structure of SQL Limit, so as to improve the versatility of SQL and the efficiency of using SQL.
[0136] In one embodiment, Figure 6 As shown, the specific processing process of step 106 "through the database dialect instance, parsing the syntax structure of the native SQL into the data structure of the target item of the syntax tree object set, and converting the data structure of the target item with the conversion vector table to obtain the converted SQL of the target dialect type" includes:
[0137] Step 602: If it is determined that the statement type of the native SQL is a data definition language type, the data structure of the SQL query instruction set is extracted from the syntax tree object set through the database dialect instance.
[0138] The dql type may be a Data Query Language (DQL) type.
[0139] Specifically, when the database client determines that the statement type of the native SQL corresponding to the database device used by the application is the dql type, the database client can convert the grammatical structure of the native SQL through the database dialect instance. Specifically, the grammatical structure of the native SQL can be converted into a data structure of corresponding items in a syntax tree object set obtained by parsing the native SQL; for example, when the statement type of the native SQL is the dql type, the data structure of the corresponding items (target items) contained in the syntax tree object set can be a SQL Select Items data structure, a SQL Expr data structure, and a SQL Limit data structure.
[0140] Step 604: based on the data structure of the SQL query instruction set, extract the data structure of the SQL expression, parse the function name, perform function conversion based on the function vector table, and obtain the function of the target dialect type.
[0141] Specifically, the database client can extract from the data structure of SQL SELECT ITEMS extracted from the parsed syntax tree object set through the database dialect instance to obtain the SQL Expr data structure; the database client can convert the syntax structure of the native SQL into the SQL Expr data structure, and determine the target function based on the SQL Expr data structure, and convert the database function type based on the target function, the function vector table and the target dialect type corresponding to the database device, that is, query the target function under the target dialect type representation in the function vector table to obtain the function of the target dialect type.
[0142] Step 606: based on the data structure of the SQL query instruction set, extract the data structure of the SQL limited query, perform paging conversion based on the paging template conversion table, and obtain paging of the target dialect type.
[0143] Specifically, the database client can extract from the data structure of SQL SELECT ITEMS extracted from the parsed syntax tree object set through the database dialect instance to obtain the SQL Limit data structure; in this way, the database client can further determine that the data structure of the corresponding item contained in the syntax tree object set can be the SQL Limit data structure; the database client can convert the syntax structure of the native SQL into the SQL Limit data structure, and determine the target paging template (i.e., the paging template of the native SQL) based on the SQL Limit data structure. The database client can perform database paging template conversion based on the target paging template, the paging template conversion table, and the target dialect type corresponding to the database device, that is, query the target paging template under the target dialect type representation in the paging template conversion table to obtain the paging of the target dialect type.
[0144] Step 608: Obtain the converted SQL of the target dialect type based on the function of the target dialect type and the paging of the target dialect type.
[0145] The database client can replace the paging template in the native SQL and the function in the native SQL based on the paging of the target dialect type and the function of the target dialect type, that is, replace the paging template in the native SQL with the paging template of the target dialect type and replace the function in the native SQL with the function of the target dialect type to obtain the converted SQL of the target dialect type.
[0146] In this embodiment, based on the data structure of SQL SELECT ITEMS, the data structure of SQL Expr, and the data structure of SQLLimit, function conversion and paging template conversion are performed to enhance the versatility of SQL and improve the efficiency of SQL usage.
[0147] In one embodiment, the SQL conversion method further includes:
[0148] If the conversion is determined to be abnormal, abnormal prompt information is generated and output.
[0149] The abnormal prompt information may be used to prompt the operation and maintenance personnel or the user of the database that an abnormal situation has occurred in the current database.
[0150] Specifically, when determining that an exception occurs in the current conversion, the database client may generate exception prompt information and send the exception prompt information to the middleware corresponding to the database, so that the corresponding database operation and maintenance personnel can perform exception processing based on the exception prompt information.
[0151] In this embodiment, by outputting abnormal information, abnormal situations can be prompted in time, ensuring high availability and reliability of the database.
[0152] In one example, the specific implementation of the step of "initiating a network request to the database based on the converted SQL" includes:
[0153] The converted SQL is sent to the target driver component, and through the target driver component, a network request is initiated to the database based on the converted SQL.
[0154] Among them, the target driven component can be a middleware, which can be a variety of types of middleware. The present application does not specifically limit the specific types of middleware and target driven components, and those skilled in the art can determine based on actual application scenarios. Middleware can be software that provides a connection between system software and application software, and is used to implement data interaction between various software components. For example, the middleware can be an ORM middleware, mybatis, or beetlsql.
[0155] Specifically, the database client can send the converted SQL of the target dialect type to the target driver component, and the target driver component can initiate a network request to the database based on the converted SQL after receiving the converted SQL of the target dialect type. For example, the target driver component can parse the converted SQL, determine the target instruction, and send the target instruction to the database device, so that the database device can perform the target operation corresponding to the target instruction on the database device after receiving the target instruction.
[0156] In one example, the database client can intercept the native SQL sent by the ORM middleware to the database through the dialect component, that is, the database client can intercept on the communication link between the ORM middleware and the database to obtain the native SQL sent by the ORM middleware to the database. In one example, the database client can intercept based on the communication address of the ORM middleware, and the specific interception process can include: the database client can determine the source address based on the communication address of the ORM middleware and the destination address based on the communication address of the database through the dialect component, intercept the native SQL based on the source address and the destination address, and obtain the native SQL whose source address is the communication address of the ORM middleware and the destination address is the communication address of the database.
[0157] The following, such as Figure 7 As shown, in combination with a specific embodiment, the specific execution process of the above SQL conversion method is described in detail:
[0158] Database dialects are grammatical rules and data structures that represent the structure and properties of a database, and are used to build various types of databases, including relational databases and non-relational databases, such as databases represented by ER diagrams, graph databases based on 9NF, etc. The database dialect provided in this embodiment can be a grammatical rule for different databases to complete the corresponding data structure design and conversion logic, and generally includes a set of grammatical rules that represent data relationships and properties, as well as rules that define the entities, attributes, relationships, queries, and operations of the above data in the database.
[0159] The relational database dialect includes a set of grammatical rules for representing tables and data, such as CREATE TABLE, INSERT, UPDATE, DELETE statements, etc., wherein the database involved is not limited to the relational databases and domestic databases in projects such as db2, oracle, mysql, DM, Gauss, etc. Since the general syntax of mysql is used in the database, all ORM middlewares such as springdata jpa, mybatis, etc. can be parsed normally. Based on this, the dialect component in this embodiment intercepts the message before the ORM middleware sends the message to the database, parses the native SQL and determines the database type based on the data source connection information, and then converts the mysql semantics into the dialect representation of the corresponding database type, and finally sends the converted sql to the database, that is, initiates a network request. By adopting the mysql general syntax as the intermediate language of each database, and because spring data jpa, mybatis, etc. support mysql syntax, the decoupling of the dialect component and the ORM middleware can be achieved. The implementation of the dialect component in this embodiment does not rely on any ORM middleware application program interface (API), and is a lightweight JAR (Java Archive, Java Archive) package.
[0160] For various types of databases, the prior art requires a unified tool to implement operations on different types of databases, such as supporting native SQL for data management and query, extending functions under native SQL, such as paging, functions, storage field types, etc., and performing the following function conversions: creating cross-database paging SQL, generating the current database's paging SQL according to the current dialect; creating cross-database table creation and deletion DDL statements, generating corresponding DDL statements according to the current database dialect, and creating cross-database SQL functions, generating corresponding SQL function fragments according to the current database dialect. Specifically, the extended storage field type definitions of different types of databases are different, such as mysqlvarchar and oracle Varchar2 are both definitions of string types.
[0161] S01, each application system uses its own middleware (such as mybatis) to read the native SQL in the code or configuration file. Specifically, during the running of the application, the database client can read the native SQL in the code configuration file or the pre-configured configuration file through different ORM middleware. The database client can intercept the native SQL sent by the ORM middleware to the database through the dialect component, and read the SQL to be sent by the ORM middleware; the database client can parse the native SQL through the dialect component to obtain the st set.
[0162] S02, the dialect tool intercepts the SQL message sent by the middleware to MySQL, parses the native SQL, generates a SqlSelect Query object set st, and then instantiates the dialect object according to the database configuration or link address. Specifically, the database client can obtain the data source connection information of the application. According to the data source connection information, the dialect component can determine the current database type. The dialect component can initialize the corresponding database dialect instance. The instance can include three types of data structures, corresponding to the paging template "Paginations", field type "TypeMappings" and function definition "Functions" in "DatabaseDialects.xls".
[0163] In an example, the oralce data source connection information can be: jdbc:oracle:thin:IP:port
[0164] S03, the dialect tool takes the SQL Select Items data structure from the st collection, and then performs the database field type definition conversion according to the TypeMappings vector table. Specifically, the database client can extract the SQLSelectItems data structure from the st collection through the dialect tool (dialect component) and the database dialect instance, and then performs the database field type definition conversion according to the TypeMappings vector table. That is, the mySQL field definition is translated into the field definition of the corresponding dialect. If the conversion is normal, the converted SQL is returned to the ORM middleware, and the ORM middleware can initiate a network request to the database based on the received converted SQL.
[0165] S04, the dialect tool extracts the SQL Expr data structure from the SQLSelectItems data structure, parses the function name, and then performs function conversion according to the Functions vector table. Specifically, the database dialect instance can extract the SQL Expr data structure from the SQL SelectItems data structure, parse the function name, and then perform function conversion according to the Functions vector table to translate the function defined in the mySQL syntax into the function definition of the corresponding database of the corresponding dialect. If the conversion is normal, the converted SQL is returned to the ORM middleware, and the ORM middleware can initiate a network request to the database based on the received converted SQL.
[0166] S05, the dialect tool extracts the SQL Limit data structure from the SQL Select Items data structure, and performs paging conversion according to the Paginations paging template table. Specifically, the database client extracts the SQL Limit data structure from the SQL Select Items data structure through the database dialect instance. Paging conversion is performed according to the Paginations paging template table, and the paging template defined in the mySQL syntax is translated into the paging semantics of the database corresponding to the corresponding dialect. If the conversion is normal, the converted SQL is returned to the ORM middleware, and the ORM middleware can initiate a network request to the database based on the received converted SQL. In this embodiment, 81 types of databases can be collected, and templates can be set for paging of different databases. When converting native SQL, the paging template is replaced.
[0167] S06, judging whether the conversion is normal, if the conversion is abnormal, prompting the conversion abnormality, generating abnormal prompt information, and sending the abnormal prompt information to the corresponding ORM middleware, so that the developer can execute the corresponding exception handling strategy based on the abnormal prompt information.
[0168] The SQL conversion method provided in this embodiment can create DDL from Java methods, that is, create DDL based on Java method configuration, and can also modify the configuration at runtime. The database client can generate entity class source code based on the database, read the database structure, and generate annotated entity class POJO, which can improve the coding efficiency of developers. Paging: Provide a cross-database paging method. Function transformation: For different databases, functions that are parsed into corresponding dialects only need to use the functions agreed upon by MySQL syntax. The dialect component tries to complete the replacement of different database functions, so that SQL can be written once and different databases can run normally. Type transformation: For different database field types, mutual transformation with Java types is provided. Reserved word check: Provide database reserved word check function, support the definition of reserved words, in custom functions or stored procedures, the function name or procedure name can be pre-configured, and the dialect component skips the database built-in function check when translating these functions, which can avoid the prompt "XXX function is not supported in XXX database" message and ensure user experience.
[0169] It should be understood that, although the steps in the flowcharts involved in the above embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0170] Based on the same inventive concept, the embodiment of the present application also provides a SQL conversion device for implementing the SQL conversion method involved above. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above method, so the specific limitations in one or more SQL conversion device embodiments provided below can refer to the limitations of the SQL conversion method above, and will not be repeated here.
[0171] In one embodiment, Figure 8 As shown, a SQL conversion device 800 is provided, comprising:
[0172] The first acquisition module 802 is used to acquire native SQL, parse the native SQL, and obtain a syntax tree object set. The native SQL is generated when the application is running;
[0173] The second acquisition module 804 is used to acquire the data source connection information of the application program through the dialect component, determine the database type based on the data source connection information, and determine the database dialect instance corresponding to the database type;
[0174] An extraction module 806 is used to parse the syntax structure of the native SQL into a data structure of a target item of a syntax tree object set through a database dialect instance, and convert the data structure of the target item with a conversion vector table to obtain a converted SQL of a target dialect type;
[0175] The request module 808 is configured to initiate a network request to the database based on the converted SQL if the conversion is determined to be normal.
[0176] In one embodiment, the first acquisition module is specifically used to:
[0177] Obtain the target data message through the dialect component;
[0178] Parse the target data message and obtain the native SQL contained in the target data message.
[0179] In one embodiment, the extraction module is specifically used to:
[0180] If it is determined that the statement type of the native SQL is a data definition language type, the syntax structure of the native SQL is converted into a data structure of an SQL query instruction set of a syntax tree object set through a database dialect instance, and based on the data structure of the SQL query instruction set and a field type mapping vector table, a definition conversion of the database field type is performed to obtain a mySQL field definition of the target dialect type;
[0181] Based on the mySQL field definition of the target dialect type, get the converted SQL of the target dialect type.
[0182] In one embodiment, the extraction module is specifically used to:
[0183] If it is determined that the statement type of the native SQL is a data query language type, then the data structure of the SQL query instruction set is extracted from the syntax tree object set through the database dialect instance;
[0184] Based on the data structure of the SQL query instruction set, extract the data structure of the SQL expression, parse the function name, convert the function based on the function vector table, and obtain the function of the target dialect type;
[0185] Based on the function of the target dialect type, get the converted SQL of the target dialect type.
[0186] In one of the embodiments, the extraction module is specifically used to: if it is determined that the statement type of the native SQL is a data query language type, extract the data structure of the SQL query instruction set from the syntax tree object set through the database dialect instance;
[0187] Based on the data structure of the SQL query instruction set, the data structure of the SQL limited query is extracted, and based on the paging template conversion table, paging conversion is performed to obtain the paging of the target dialect type;
[0188] Based on the target dialect type's paging, get the converted SQL of the target dialect type.
[0189] In one of the embodiments, the extraction module is specifically used to: if it is determined that the statement type of the native SQL is a data definition language type, extract the data structure of the SQL query instruction set from the syntax tree object set through the database dialect instance;
[0190] Based on the data structure of the SQL query instruction set, extract the data structure of the SQL expression, parse the function name, convert the function based on the function vector table, and obtain the function of the target dialect type;
[0191] Based on the data structure of the SQL query instruction set, the data structure of the SQL limited query is extracted, and based on the paging template conversion table, paging conversion is performed to obtain the paging of the target dialect type;
[0192] Based on the function of the target dialect type and the paging of the target dialect type, the converted SQL of the target dialect type is obtained.
[0193] In one embodiment, the device further comprises:
[0194] The generation module is used to generate an exception prompt message if the conversion is determined to be abnormal, and output the exception prompt message.
[0195] In one embodiment, the request module is specifically used to: send the converted SQL to the target driver component, and initiate a network request to the database based on the converted SQL through the target driver component.
[0196] Each module in the above SQL conversion device can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0197] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig. 9As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store dialect-related data. The network interface of the computer device is used to communicate with an external database client through a network connection. When the computer program is executed by the processor, an SQL conversion method is implemented.
[0198] Those skilled in the art will understand that Fig. 9 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0199] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0200] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0201] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0202] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.
[0203] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0204] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0205] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A SQL conversion method, characterized in that: The method comprises: Obtain native SQL, parse the native SQL, and obtain a set of syntax tree objects, wherein the native SQL is generated when the application is running; Obtaining data source connection information of the application through a dialect component, determining a database type based on the data source connection information, and determining a database dialect instance corresponding to the database type, wherein the database dialect instance includes a syntax tree object for describing a list of fields, namely, SQL Select Items, a syntax tree object for describing a function, namely, a SQL Expr data structure, and a syntax tree object for describing paging, namely, a SQL Limit data structure; Parsing the syntax structure of the native SQL into a data structure of a target item of the syntax tree object set through a database dialect instance, and converting the data structure of the target item with a conversion vector table to obtain a converted SQL of a target dialect type; If the conversion is determined to be normal, a network request is initiated to the database based on the converted SQL; The method of converting the syntax structure of the native SQL into the data structure of the target item of the syntax tree object set by parsing the database dialect instance, and converting the data structure of the target item with the conversion vector table to obtain the converted SQL of the target dialect type includes: If it is determined that the statement type of the native SQL is a data query language type, the data structure of the SQL query instruction set is extracted from the syntax tree object set through the database dialect instance; based on the data structure of the SQL query instruction set, the data structure of the SQL expression is extracted, the function name is parsed, and the function is converted based on the function vector table to obtain the function of the target dialect type; based on the data structure of the SQL query instruction set, the data structure of the SQL limited query is extracted, and paging conversion is performed based on the paging template conversion table to obtain the paging of the target dialect type; based on the function of the target dialect type and the paging of the target dialect type, the converted SQL of the target dialect type is obtained.
2. The method according to claim 1, characterized in that The obtaining of native SQL includes: Obtain the target data message through the dialect component; The target data message is parsed to obtain the native SQL contained in the target data message.
3. The method according to claim 1, characterized in that: The method of converting the syntax structure of the native SQL into the data structure of the target item of the syntax tree object set by parsing the database dialect instance, and converting the data structure of the target item with the conversion vector table to obtain the converted SQL of the target dialect type includes: If it is determined that the statement type of the native SQL is a data definition language type, the syntax structure of the native SQL is converted into a data structure of an SQL query instruction set of the syntax tree object set through the database dialect instance, and based on the data structure of the SQL query instruction set and a field type mapping vector table, a definition conversion of the database field type is performed to obtain a mySQL field definition of the target dialect type; Based on the mySQL field definition of the target dialect type, get the converted SQL of the target dialect type.
4. The method according to claim 3, characterized in that The method of converting the syntax structure of the native SQL into the data structure of the target item of the syntax tree object set by parsing the database dialect instance, and converting the data structure of the target item with the conversion vector table to obtain the converted SQL of the target dialect type includes: If it is determined that the statement type of the native SQL is a data query language type, extracting a data structure of a SQL query instruction set from a syntax tree object set through the database dialect instance; Based on the data structure of the SQL query instruction set, extract the data structure of the SQL expression, parse the function name, perform function conversion based on the function vector table, and obtain the function of the target dialect type; Based on the function of the target dialect type, a converted SQL of the target dialect type is obtained.
5. The method according to claim 3, characterized in that: The method of converting the syntax structure of the native SQL into the data structure of the target item of the syntax tree object set by parsing the database dialect instance, and converting the data structure of the target item with the conversion vector table to obtain the converted SQL of the target dialect type includes: If it is determined that the statement type of the native SQL is a data query language type, extracting a data structure of a SQL query instruction set from a syntax tree object set through the database dialect instance; Based on the data structure of the SQL query instruction set, extract the data structure of the SQL limited query, and perform paging conversion based on the paging template conversion table to obtain paging of the target dialect type; Based on the paging of the target dialect type, a converted SQL of the target dialect type is obtained.
6. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: If the conversion is determined to be abnormal, abnormal prompt information is generated and output.
7. The method according to claim 1, characterized in that The initiating a network request to the database based on the converted SQL includes: The converted SQL is sent to a target drive component, and through the target drive component, a network request is initiated to a database based on the converted SQL.
8. A SQL conversion device, characterized in that: The device comprises: A first acquisition module is used to acquire native SQL, parse the native SQL, and obtain a syntax tree object set, wherein the native SQL is generated when the application is running; A second acquisition module is used to acquire data source connection information of the application through a dialect component, determine a database type based on the data source connection information, and determine a database dialect instance corresponding to the database type, wherein the database dialect instance includes a syntax tree object for describing a list of fields, namely, SQL Select Items, a syntax tree object for describing a function, namely, a SQL Expr data structure, and a syntax tree object for describing paging, namely, a SQL Limit data structure; An extraction module, used to parse the syntax structure of the native SQL into a data structure of a target item of the syntax tree object set through a database dialect instance, and convert the data structure of the target item with a conversion vector table to obtain a converted SQL of a target dialect type; A request module, configured to initiate a network request to a database based on the converted SQL if the conversion is determined to be normal; The extraction module is specifically used to, if it is determined that the statement type of the native SQL is a data query language type, extract the data structure of the SQL query instruction set from the syntax tree object set through the database dialect instance; based on the data structure of the SQL query instruction set, extract the data structure of the SQL expression, parse the function name, perform function conversion based on the function vector table, and obtain the function of the target dialect type; based on the data structure of the SQL query instruction set, extract the data structure of the SQL limited query, perform paging conversion based on the paging template conversion table, and obtain the paging of the target dialect type; based on the function of the target dialect type and the paging of the target dialect type, obtain the converted SQL of the target dialect type.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
