Terminal equipment, database processing system and database processing method
By adjusting the syntax tree of database processing operations to conform to the statement rules of the target database, the operation complexity problem caused by the differences in SQL statement rules between different databases is solved, and the convenience and efficiency of cross-database operations are achieved.
Patent Information
- Application Number
- CN202411592570.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-08
- Publication Date
- 2025-04-04
AI Technical Summary
In the prior art, due to the different statement rules supported by different databases, a large number of SQL statements need to be manually modified or a database-specific adaptation layer is written when replacing the database, which increases operational complexity and reduces operational efficiency.
By detecting the database processing operations triggered by the user, a syntax tree of the initial request statement is generated, and nodes that do not comply with the target database statement rules are adjusted to generate a target syntax tree that comply with the target database rules, thereby generating a processing request that can be executed by the target database.
It reduces the complexity of database migration, upgrade and cross-database operations, and realizes a convenient and fast cross-database operation solution.
Smart Images

Figure CN119759945A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of database management system and data access layer, and in particular to a terminal device, a database processing system and a database processing method. Background Art
[0002] In the prior art, since different databases support different statement rules, each database can only support SQL statements that comply with the statement rules of the database. Therefore, when changing databases, a large number of SQL statements need to be manually modified or a database-specific adaptation layer needs to be written to implement cross-database operations. This results in high operational complexity and reduced operational efficiency when performing cross-database operations. Summary of the invention
[0003] The purpose of the application is to provide a terminal device, a database processing system and a database processing method, so as to provide a solution that can conveniently and quickly implement cross-database operations.
[0004] In a first aspect, the present application provides a terminal device, comprising: an input component, a communication unit and a processor;
[0005] The input component is used to detect a database processing operation triggered by a user; the database processing operation indicates processing of a target database on the server;
[0006] The communication unit is used to send a processing request to the server and receive a processing result returned by the server based on the processing request; the processing request is generated based on an initial request statement corresponding to the database processing operation;
[0007] The processor is configured to:
[0008] When the syntax tree corresponding to the initial request statement does not conform to the statement rule corresponding to the target database, a target syntax tree conforming to the statement rule is obtained by adjusting the nodes in the syntax tree that do not conform to the statement rule;
[0009] The processing request is generated based on the target syntax tree.
[0010] The above technical solution has the following advantages or beneficial effects: the application adjusts the nodes in the syntax tree that do not conform to the statement rules of the target database to obtain a target syntax tree that conforms to the statement rules of the target database, generates a processing request based on the target syntax tree and sends it to the target database, so that the target database can perform corresponding operations based on the processing request. This reduces the complexity of database migration, upgrade and cross-database operations, and implements a solution for cross-database operations quickly and conveniently.
[0011] In a possible embodiment, the database interaction operation is an operation triggered by a user on a function of a client, and the target database is a database among multiple databases corresponding to the function of the client.
[0012] The above technical solution has the following advantages or beneficial effects: after the user triggers a database interaction operation, the target database corresponding to the client function is determined from multiple databases according to the client function triggered by the user, so that the application can specifically convert the initial request statement into a processing request that can be executed by the target database.
[0013] In a possible embodiment, the syntax tree corresponding to the initial request statement includes a plurality of nodes, each of the plurality of nodes includes a statement element in the initial request statement, and the position of each node in the syntax tree represents the syntax structure of the initial request statement;
[0014] The processor is specifically configured to determine that the syntax tree corresponding to the initial request statement does not conform to the statement rule corresponding to the target database in the following manner:
[0015] It is determined that a sentence element and / or a grammatical structure represented by at least one node in the grammar tree does not conform to a sentence rule corresponding to the target database.
[0016] The above technical solution has the following advantages or beneficial effects: judging whether the syntax tree conforms to the sentence rules corresponding to the target database from the two aspects of sentence elements and syntax structure, and improving the accuracy of syntax tree adjustment.
[0017] In a possible embodiment, the statement rule includes an element type requirement and a grammatical structure requirement; and the processor is specifically configured to:
[0018] Traverse each node in the syntax tree based on the statement rules corresponding to the target database, and when the statement elements contained in the node are different from the statement elements in the element type requirements in the statement rules, determine that the node does not meet the element type requirements in the statement rules; when the grammatical structure represented by at least one node is different from the grammatical structure requirements in the statement rules, determine that the at least one node does not meet the grammatical structure requirements in the statement rules.
[0019] The above technical solution has the following advantages or beneficial effects: by comparing the sentence elements in the syntax tree with the element type requirements in the sentence rules, and comparing the grammatical structure in the syntax tree with the grammatical structure requirements in the sentence rules, the nodes in the syntax tree that do not comply with the sentence rules are determined, thereby improving the accuracy of the syntax tree adjustment.
[0020] In a possible embodiment, the processor is specifically configured to:
[0021] If the node does not meet the element type requirement in the statement rule, replacing the statement element in the node with the statement element in the element type requirement;
[0022] If the node does not meet the grammatical structure requirement in the sentence rule, the position of the node in the syntax tree is adjusted based on the grammatical structure requirement.
[0023] The above technical solution has the following advantages or beneficial effects: when a node in a syntax tree does not meet the element type requirement, the sentence element in the node is replaced with the sentence element in the element type requirement, and when a node in a syntax tree does not meet the syntax structure requirement, the position of the node in the syntax tree is adjusted based on the syntax structure requirement, so that the target syntax tree generated after the adjustment can meet the sentence rules corresponding to the target database, so that the processing request generated based on the target syntax tree can be executed by the target database.
[0024] In a possible embodiment, the element type requirements in the statement rule include function type requirements, data type requirements, and syntax type requirements.
[0025] The above technical solution has the following advantages or beneficial effects: the element type requirements in the statement rules include function type requirements, data type requirements and syntax type requirements, and the syntax tree is standardized from multiple dimensions, thereby improving the accuracy of syntax tree adjustment.
[0026] In a possible embodiment, the statement rules corresponding to the target database are pre-stored locally, or acquired in real time from an external device.
[0027] The above technical solution has the following advantages or beneficial effects: by pre-storing sentence rules locally or acquiring sentence rules from an external device in real time, the flexibility of acquiring sentence rules can be improved.
[0028] In a second aspect, the present application provides a database processing system, the system comprising a client and a Java database connection JDBC driver;
[0029] In response to a database processing operation triggered by a user, the client sends an initial request statement corresponding to the database processing operation to the JDBC driver, wherein the database processing operation indicates processing of a target database;
[0030] The JDBC driver receives the initial request statement and sends the processing request to the server; the processing request is generated by the JDBC driver based on the initial request statement corresponding to the database processing operation; when the syntax tree corresponding to the initial request statement does not conform to the statement rule corresponding to the target database, the JDBC driver obtains a target syntax tree that conforms to the statement rule by adjusting the nodes in the syntax tree that do not conform to the statement rule, and generates the processing request based on the target syntax tree;
[0031] The JDBC driver receives the processing result returned by the server based on the processing request, and returns the processing result to the client.
[0032] In a third aspect, the present application provides a database processing method, comprising:
[0033] In response to a database processing operation triggered by a user, a processing request is sent to a server; the database processing operation indicates processing of a target database; the processing request is generated based on an initial request statement corresponding to the database processing operation; when a syntax tree corresponding to the initial request statement does not conform to a statement rule corresponding to the target database, a target syntax tree conforming to the statement rule is obtained by adjusting nodes in the syntax tree that do not conform to the statement rule, and the processing request is generated based on the target syntax tree;
[0034] Receive a processing result returned by the server based on the processing request.
[0035] In a fourth aspect, the present application provides a database processing device, including:
[0036] A sending module, configured to send a processing request to a server in response to a database processing operation triggered by a user; the database processing operation indicates processing of a target database; the processing request is generated based on an initial request statement corresponding to the database processing operation; when a syntax tree corresponding to the initial request statement does not conform to a statement rule corresponding to the target database, a target syntax tree conforming to the statement rule is obtained by adjusting nodes in the syntax tree that do not conform to the statement rule, and the processing request is generated based on the target syntax tree;
[0037] The receiving module is used to receive the processing result returned by the server based on the processing request.
[0038] In a fifth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method in the third aspect is implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. Obviously, the drawings introduced below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0040] Figure 1 This is an application scenario of an optional database processing method of an embodiment of the present application;
[0041] Figure 2 This is an application scenario of an optional database processing method of an embodiment of the present application;
[0042] Figure 3 This is a flowchart of a database processing method according to an embodiment of the present application;
[0043] Figure 4 A flowchart of generating a processing request according to an embodiment of the present application;
[0044] Figure 5 This is a flowchart of obtaining a target syntax tree according to an embodiment of the present application;
[0045] Figure 6 This is a flowchart of an implementation of a database processing system according to an embodiment of the present application;
[0046] Figure 7 This is a JDBC driver implementation flow chart for an embodiment of the present application;
[0047] Figure 8 This is an overall implementation flow chart of the embodiment of the present application;
[0048] Fig. 9 A schematic diagram of a database processing device according to an embodiment of the present application. DETAILED DESCRIPTION
[0049] In order to make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Among them, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0050] Furthermore, in the description of the embodiments of the present application, unless otherwise specified, “ / ” means or. For example, A / B can mean A or B. The “and / or” in the text is merely a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, “multiple” refers to two or more than two.
[0051] In the following, the terms "first" and "second" are used for descriptive purposes only and should not be understood as suggesting or implying relative importance or implicitly indicating the number of technical features indicated. Thus, features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of the present application, unless otherwise specified, "multiple" means two or more.
[0052] In order to facilitate understanding of a terminal device, a database processing system and a database processing method provided in the embodiments of the present application, some terms in the embodiments of the present application are explained below to facilitate understanding by those skilled in the art.
[0053] Database Management System (DBMS) is a large-scale software for manipulating and managing databases. It is used to establish, use and maintain databases. It manages and controls the database in a unified manner to ensure the security and integrity of the database.
[0054] An Abstract Syntax Tree (AST), or syntax tree for short, is a tree representation of the abstract syntax structure of source code written in a programming language. Each node of the tree represents a construct that appears in the source code.
[0055] Structured Query Language (SQL) is a special-purpose programming language. It is a database query and programming language used to access data and query, update and manage relational database systems.
[0056] Java Database Connectivity (JDBC) is an application programming interface in the Java language that regulates how client programs access databases. It provides methods such as querying and updating data in the database. JDBC is also a trademark of Sun Microsystems. The JDBC we usually refer to is oriented to relational databases.
[0057] The following introduces an application scenario of an optional database processing method provided in an embodiment of the present application in conjunction with the accompanying drawings.
[0058] like Figure 1 As shown, an application scenario of an optional database processing method in an embodiment of the present application includes a terminal device 10 and a server 11.
[0059] The terminal device 10 sends a processing request to the server 11 in response to a database processing operation triggered by a user; the database processing operation instructs processing of a target database; the processing request is generated based on an initial request statement corresponding to the database processing operation; when the syntax tree corresponding to the initial request statement does not conform to the statement rules corresponding to the target database, a target syntax tree conforming to the statement rules is obtained by adjusting the nodes in the syntax tree that do not conform to the statement rules, and a processing request is generated based on the target syntax tree.
[0060] The terminal device 10 receives the processing result returned by the server 11 based on the processing request.
[0061] The server 11 in the embodiment of the present application can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, as well as big data and artificial intelligence platforms.
[0062] like Figure 2 As shown, an application scenario of an optional database processing method in an embodiment of the present application includes a terminal device 20; wherein the terminal device 20 includes an input component 21, a communication unit 22 and a processor 23.
[0063] An input component, used to detect a database processing operation triggered by a user; the database processing operation indicates processing of a target database on a server;
[0064] A communication unit, used to send a processing request to a server, and receive a processing result returned by the server based on the processing request; the processing request is generated based on an initial request statement corresponding to a database processing operation;
[0065] The processor is configured to: when the syntax tree corresponding to the initial request statement does not conform to the statement rules corresponding to the target database, obtain a target syntax tree that conforms to the statement rules by adjusting the nodes in the syntax tree that do not conform to the statement rules; and generate a processing request based on the target syntax tree.
[0066] Of course, the method provided in the embodiment of the present application is not limited to Figure 1 or Figure 2The application scenario shown can also be used in other possible application scenarios, which are not limited in the embodiments of the present application.
[0067] like Figure 3 The flowchart of a database processing method provided by the present application is shown, which is applied to a terminal device, and the specific steps are as follows:
[0068] Step S301: In response to a database processing operation triggered by a user, a processing request is sent to a server; the database processing operation indicates processing of a target database.
[0069] Exemplarily, the database processing operation is an operation in which the client needs to access the database. For example, the database processing operation may include operations such as querying the database, updating the database, and inserting into the database.
[0070] Optionally, the processing request in the embodiment of the present application is generated by the terminal device based on an initial request statement corresponding to the database processing operation; when the syntax tree corresponding to the initial request statement does not conform to the statement rules corresponding to the target database, the target syntax tree that conforms to the statement rules is obtained by adjusting the nodes in the syntax tree that do not conform to the statement rules, and a processing request is generated based on the target syntax tree.
[0071] like Figure 4 As shown, a flowchart of generating a processing request in an embodiment of the present application, the specific steps are as follows:
[0072] Step S401: based on the statement rules corresponding to the target database, traverse the syntax tree corresponding to the initial request statement, where the initial request statement is generated based on the database processing operation.
[0073] The client applied on the terminal device generates an initial request statement corresponding to the database processing operation in response to the database processing operation triggered by the user.
[0074] It should be noted that when a user triggers a database processing operation for a client function, the client will generate an initial request statement corresponding to the database processing operation.
[0075] Optionally, the initial request statement may be a SQL statement.
[0076] For example, taking the database processing operation triggered by the user as a query operation, the initial request statement generated by the client may be a standard SQL statement, such as SELECT*FROM users WHERE age>30; or, the initial request statement generated by the client may be an SQL statement that complies with specific database statement rules. This application does not limit this.
[0077] Optionally, the database interaction operation in the embodiment of the present application is an operation triggered by a user on a function of a client, and the target database is a database among multiple databases corresponding to the function of the client.
[0078] It should be noted that, since each function of the client belongs to a corresponding service, and each service has a corresponding database, each function of the client has a corresponding database. Therefore, after the user triggers the database interaction operation, the database corresponding to the client function in multiple databases can be used as the target database according to the function triggered by the user on the client.
[0079] Step S402: When the syntax tree corresponding to the initial request statement does not conform to the statement rules corresponding to the target database, a target syntax tree conforming to the statement rules is obtained by adjusting the nodes in the syntax tree that do not conform to the statement rules.
[0080] The statement rules corresponding to the target database are pre-stored locally or acquired in real time from an external device.
[0081] For example, the JDBC driver can have a pre-built dialect rule library and can also dynamically load or update dialect rules. The dialect rules can be updated in real time through a remote server or loaded from an external file to support a wider range of database types or SQL extensions.
[0082] The embodiments of the present application can improve the flexibility of the system through the above method, can quickly adapt to newly released databases or SQL features, and reduce the frequency of driver upgrades.
[0083] In the embodiment of the present application, the JDBC driver determines the statement rules corresponding to the current target database by reading the configuration file or connection information corresponding to the target database.
[0084] Exemplarily, the JDBC driver identifies the type of the current target database (such as MySQL, PostgreSQL, Oracle, etc.) by reading the configuration file or connection information corresponding to the target database. Based on the identification result, the rules and mapping tables related to the target database dialect are loaded to determine the statement rules corresponding to the target database.
[0085] like Figure 5 As shown, a flowchart of obtaining a target syntax tree in an embodiment of the present application, the specific steps are as follows:
[0086] Step S501: Based on the initial request statement, generate a syntax tree corresponding to the initial request statement.
[0087] In an optional implementation, after the client generates an SQL statement, the embodiment of the present application calls the built-in SQL parser through the JDBC driver, uses the abstract syntax tree technology to perform syntax analysis on the SQL statement, and generates a syntax tree corresponding to the SQL statement.
[0088] Specifically, the SQL parser splits the SQL statement into basic grammatical units (such as table name, column name, condition, operator, etc.), and constructs a syntax tree corresponding to the SQL statement based on the grammatical units.
[0089] Exemplarily, the split grammatical units may be SELECT, FROM, WHERE, etc.
[0090] In another optional implementation, the embodiment of the present application parses the SQL statement based on a machine learning or deep learning model to generate a syntax tree corresponding to the SQL statement.
[0091] It should be noted that the machine learning or deep learning model used in the embodiments of the present application is obtained based on SQL training samples and corresponding syntax tree training.
[0092] This approach can better adapt to various non-standard or mixed SQL statements through model training, and may perform better when processing complex SQL queries. The advantage of this approach is that it can handle more complex SQL structures and dialects, and gradually improve the adaptability to new SQL features through continuous model training.
[0093] The embodiment of the present application describes the statement structure of the SQL statement in detail through AST, so that subsequent SQL conversion and optimization operations can be more easily implemented at the grammatical level.
[0094] Optionally, the syntax tree corresponding to the initial request statement in the embodiment of the present application includes multiple nodes, each of the multiple nodes contains a statement element in the initial request statement, and the position of each node in the syntax tree represents the grammatical structure of the initial request statement.
[0095] It should be noted that the meaning of the sentence element representation contained in the node in the embodiment of the present application is the same as the meaning of the sentence element representation in the initial request statement.
[0096] Step S502: based on the statement rules corresponding to the target database, traverse each node in the syntax tree corresponding to the initial request statement, and determine the nodes in the syntax tree that do not comply with the statement rules corresponding to the target database.
[0097] Optionally, the processor in the terminal device of the embodiment of the present application is specifically used to determine that the syntax tree corresponding to the initial request statement does not conform to the statement rules corresponding to the target database in the following manner: determine that the statement elements and / or grammatical structures represented by at least one node in the syntax tree do not conform to the statement rules corresponding to the target database.
[0098] Exemplarily, based on the statement rules corresponding to the target database, the JDBC driver gradually traverses each node in the syntax tree to determine the nodes in the syntax tree that do not comply with the statement rules corresponding to the target database.
[0099] Optionally, the sentence rules in the embodiment of the present application include element type requirements and grammatical structure requirements.
[0100] In an optional implementation, the processor is specifically used to: traverse each node in the syntax tree based on the statement rules corresponding to the target database, and when the statement elements contained in the node are different from the statement elements in the element type requirements in the statement rules, determine that the node does not meet the element type requirements in the statement rules; when the grammatical structure represented by at least one node is different from the grammatical structure requirements in the statement rules, determine that at least one node does not meet the grammatical structure requirements in the statement rules.
[0101] Step S503: Based on the sentence rules corresponding to the target database, the nodes in the syntax tree that do not conform to the sentence rules corresponding to the target database are adjusted to obtain a target syntax tree that conforms to the sentence rules.
[0102] After determining the nodes in the syntax tree that do not conform to the statement rules corresponding to the target database, the nodes that do not conform to the statement rules corresponding to the target database are adjusted in the following manner: if the node does not conform to the element type requirement in the statement rule, the statement element in the node is replaced with the statement element in the element type requirement. If the node does not conform to the grammatical structure requirement in the statement rule, the position of the node in the syntax tree is adjusted based on the grammatical structure requirement.
[0103] Optionally, the element type requirements in the statement rules of the embodiment of the present application include function type requirements, data type requirements and syntax type requirements.
[0104] In example 1, if the function type requirement corresponding to the target database is COALESCE, and the function represented by the node in the syntax tree is IFNULL, the node does not meet the function type requirement in the statement rule, and the node is converted to the function type requirement COALESCE corresponding to the target database.
[0105] That is, converting database-specific function calls into equivalent functions in the target database.
[0106] Example 2: If the data type requirement corresponding to the target database is Oracle's NUMBER(3), and the data type represented by the node in the syntax tree is TINYINT in MySQL, then the node does not meet the data type requirement in the statement rule, and the node is converted to Oracle's NUMBER(3), the data type requirement corresponding to the target database.
[0107] That is, adjust the data type in the SQL statement to match the data type requirements of the target database.
[0108] It should be noted that the syntax includes: keywords, identifiers, literals, operators, separators and comments. The syntax type requirement includes the requirement for at least one of the keywords, identifiers, literals, operators, separators and comments.
[0109] Example three, if the keyword corresponding to the target database is ROWNUM in the Oracle database, and the keyword represented by the node in the syntax tree is LIMIT, the node does not meet the syntax type requirements in the statement rule, and the node is converted to the syntax type requirements corresponding to the target database ROWNUM in the Oracle database.
[0110] Example 4: If at least one node in the syntax tree has a nested query that does not meet the syntax structure requirements, or does not contain a connection type required by the syntax structure, then it is determined that the at least one node in the syntax tree does not meet the syntax structure requirements in the syntax rules, and the position of the at least one node in the syntax tree is adjusted based on the syntax structure requirements.
[0111] The embodiment of the present application adjusts the nodes in the syntax tree that do not conform to the statement rules corresponding to the target database, so that a processing request that conforms to the statement rules corresponding to the target database can be generated based on the adjusted target syntax tree, thereby achieving cross-database compatibility.
[0112] In other words, the JDBC driver will also adjust incompatible parts involving data types, operators, etc. to ensure that the generated SQL statements conform to the syntax and execution requirements of the target database.
[0113] Step S403: Generate a processing request based on the target syntax tree.
[0114] It should be noted that the processing request may also be an SQL statement.
[0115] Exemplarily, the adjusted syntax tree is regenerated into an SQL statement. In this process, the modified nodes in the syntax tree are recombined to generate a complete SQL statement text, so that the regenerated SQL statement strictly follows the statement rules of the target database.
[0116] Optionally, in the process of SQL statement conversion in the embodiment of the present application, the JDBC driver can also introduce a multi-level optimization strategy. In addition to the basic syntax tree conversion, query optimization techniques such as index suggestions and execution plan estimation can also be combined to perform multi-level optimization on the generated SQL statements to improve execution efficiency.
[0117] It should be noted that query optimization technology includes three levels of optimization: semantic optimization, syntax optimization, and execution optimization. Semantic optimization is to optimize queries by using the semantics and integrity rules of the model. Syntax optimization (logical layer optimization) is to optimize the execution order of operations by using the syntax structure. Execution optimization (physical layer optimization) is to optimize the selection and execution order of access paths and execution algorithms.
[0118] Exemplarily, the JDBC driver optimizes and adjusts the generated SQL statement based on the optimization strategy corresponding to the target database.
[0119] The optimization strategies corresponding to the target database may include index suggestions, execution plan estimates, etc.
[0120] It should be noted that the optimization strategy corresponding to the target database is determined based on the target database.
[0121] Through the above method, cross-database compatibility can be guaranteed, further improving the execution performance of SQL statements in the target database, and adapting to performance-sensitive enterprise application scenarios.
[0122] Optionally, the application embodiment itself may also adopt a modular design, encapsulating the SQL conversion function as an independent plug-in. The SQL conversion plug-in for a specific database can be selected or developed as needed. The JDBC driver is responsible for the scheduling and management of the plug-in, and each plug-in is responsible for the SQL statement conversion of a specific database.
[0123] Exemplarily, the JDBC driver determines the SQL conversion plug-in corresponding to the target database, and the SQL conversion plug-in corresponding to the target database converts the SQL statement into a syntax tree, and adjusts the syntax tree.
[0124] Optionally, the SQL conversion plug-in corresponding to the target database can also regenerate SQL statements based on the syntax tree.
[0125] The plug-in design in the embodiment of the present application makes the system easier to expand, and third-party developers or database manufacturers can quickly develop and integrate support for specific databases without modifying the core driver code.
[0126] In the embodiment of the present application, the JDBC driver sends the regenerated SQL statement (processing request) to the target database, so that the target database receives the processing request and processes according to the instructions in the processing request. The target database returns the processing result to the JDBC driver.
[0127] Step S302: Receive the processing result returned by the server based on the processing request.
[0128] Optionally, in the embodiment of the present application, the JDBC driver may perform preliminary processing on the processing result after receiving the processing result, such as data format conversion, error handling, etc., and then send the processing result after preliminary processing to the client.
[0129] The embodiment of the present application ensures that the application obtains correct output by passing the processing result to the application. The processing result may include the query result of the database and the execution feedback.
[0130] Optionally, the present application embodiment provides a database processing system, such as Figure 6 As shown, this is an implementation flow chart of a database processing system according to an embodiment of the present application.
[0131] The database processing system includes a client and a JDBC (Java Database Connectivity) driver.
[0132] Step S601: The client generates an initial request statement corresponding to the database processing operation in response to the database processing operation triggered by the user.
[0133] Step S602: The client sends an initial request statement corresponding to the database processing operation to the JDBC driver.
[0134] The database processing operation indicates processing the target database.
[0135] Step S603: The JDBC driver receives the initial request statement and sends a processing request to the server.
[0136] Among them, the processing request is generated by the JDBC driver based on the initial request statement corresponding to the database processing operation; when the syntax tree corresponding to the initial request statement does not conform to the statement rules corresponding to the target database, the JDBC driver adjusts the nodes in the syntax tree that do not conform to the statement rules to obtain the target syntax tree that conforms to the statement rules, and generates a processing request based on the target syntax tree.
[0137] Step S604: The JDBC driver receives the processing result returned by the server based on the processing request.
[0138] Step S605: The JDBC driver returns the processing result to the client.
[0139] like Figure 7 As shown, a JDBC driver implementation flow chart of an embodiment of the present application, the specific steps are as follows:
[0140] Step S701: The JDBC driver generates a syntax tree corresponding to the initial request statement based on the initial request statement.
[0141] Step S702: The JDBC driver determines, based on the statement rules corresponding to the target database, the nodes in the syntax tree corresponding to the initial request statement that do not comply with the statement rules corresponding to the target database.
[0142] Step S703: The JDBC driver adjusts the nodes in the syntax tree that do not comply with the statement rules based on the statement rules corresponding to the target database, and generates an adjusted target syntax tree.
[0143] Step S704: The JDBC driver generates a processing request based on the adjusted target syntax tree.
[0144] like Figure 8 As shown, an overall implementation flow chart of the embodiment of the present application, the specific steps are as follows:
[0145] Step S801: The terminal device generates an SQL statement corresponding to the database processing operation in response to the database processing operation triggered by the user.
[0146] During implementation, the terminal device executes step 801 through the client.
[0147] Step S802: The terminal device determines whether the configuration is correct based on the configuration parameters corresponding to the target database. If so, step S803 is executed; if not, the process ends.
[0148] Optionally, the embodiment of the present application can determine whether the configuration is correct through a JDBC driver.
[0149] Exemplarily, the configuration parameters corresponding to the target database may include the target database type, connection information, etc., to determine whether the target database type can be converted, and if not, to determine that the configuration is incorrect. Also, determine whether the connection information corresponding to the target database is correct, etc.
[0150] Optionally, in the embodiment of the present application, the terminal device may execute steps S802 to S8011 through a JDBC driver.
[0151] Step S803: The terminal device generates a syntactic AST based on the syntax in the SQL statement.
[0152] Step S804: The terminal device generates a data type AST based on the data type in the SQL statement.
[0153] Step S805: The terminal device generates a function AST based on the function in the SQL statement.
[0154] Step S806: The terminal device generates a metadata keyword AST based on the metadata keywords in the SQL statement.
[0155] In step S807, the terminal device determines whether there is a subquery in the SQL statement; if so, execute step S803; if not, execute step S808.
[0156] Step S808: The terminal device obtains the AST corresponding to the SQL statement based on the syntax AST, type AST, function AST and metadata keyword AST.
[0157] Step S809: The terminal device adjusts the AST corresponding to the SQL statement to generate a target AST.
[0158] Step S8010: The terminal device regenerates the SQL statement based on the target AST.
[0159] Step S8011: The terminal device sends the regenerated SQL statement to the target database.
[0160] The biggest advantage of the embodiment of the present application is its extremely high versatility and flexibility, so that developers do not need to worry about the specific SQL syntax differences of the underlying database. Through AST-based SQL conversion, the present invention can support the access of any database and ensure that the SQL execution effect can be maintained consistently under different database environments. This technology reduces the time and labor costs of adapting the business system to different database bases, significantly reduces the complexity of migration caused by inconsistent SQL dialect syntax, reduces the development costs and risks of enterprises when changing databases, and also improves the maintainability and scalability of the system, making switching between databases and cross-database operations more convenient and efficient. Compared with the prior art, the present invention not only expands the scope of application of JDBC, but also improves the database compatibility of the system, and has broad application prospects.
[0161] like Fig. 9 As shown, the embodiment of the present application provides a database processing device 900, which can be specifically applied to the terminal device in the above embodiment, including:
[0162] The sending module 901 is used to send a processing request to the server in response to a database processing operation triggered by a user; the database processing operation indicates processing of a target database; the processing request is generated based on an initial request statement corresponding to the database processing operation; when a syntax tree corresponding to the initial request statement does not conform to a statement rule corresponding to the target database, a target syntax tree conforming to the statement rule is obtained by adjusting nodes in the syntax tree that do not conform to the statement rule, and the processing request is generated based on the target syntax tree;
[0163] The receiving module 902 is used to receive the processing result returned by the server based on the processing request.
[0164] Optionally, the database interaction operation is an operation triggered by a user on a function of a client, and the target database is a database among multiple databases corresponding to the function of the client.
[0165] Optionally, the syntax tree corresponding to the initial request statement includes multiple nodes, each of the multiple nodes contains a statement element in the initial request statement, and the position of each node in the syntax tree represents the grammatical structure of the initial request statement;
[0166] The sending module 901 is specifically used to determine that the syntax tree corresponding to the initial request statement does not conform to the statement rule corresponding to the target database in the following manner:
[0167] It is determined that a sentence element and / or a grammatical structure represented by at least one node in the grammar tree does not conform to a sentence rule corresponding to the target database.
[0168] Optionally, the statement rule includes element type requirements and grammatical structure requirements; the sending module 901 is specifically used for:
[0169] Traverse each node in the syntax tree based on the statement rules corresponding to the target database, and when the statement elements contained in the node are different from the statement elements in the element type requirements in the statement rules, determine that the node does not meet the element type requirements in the statement rules; when the grammatical structure represented by at least one node is different from the grammatical structure requirements in the statement rules, determine that the at least one node does not meet the grammatical structure requirements in the statement rules.
[0170] Optionally, the sending module 901 is specifically used for:
[0171] If the node does not meet the element type requirement in the statement rule, replacing the statement element in the node with the statement element in the element type requirement;
[0172] If the node does not meet the grammatical structure requirement in the sentence rule, the position of the node in the syntax tree is adjusted based on the grammatical structure requirement.
[0173] Optionally, the element type requirements in the statement rule include function type requirements, data type requirements and syntax type requirements.
[0174] Optionally, the statement rules corresponding to the target database are pre-stored locally, or acquired in real time from an external device.
[0175] 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.
[0176] 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 present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes 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 processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing 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.
[0177] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising 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.
[0178] These computer program instructions can also be loaded onto a computer or other programmable data processing 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 implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1The steps for the functions specified in one or more boxes.
[0179] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A terminal device, characterized in that: include: Input components, communication units and processors; The input component is used to detect the database processing operation triggered by the user; The database processing operation indicates processing of a target database on the server; The communication unit is used to send a processing request to the server, and receive a processing result returned by the server based on the processing request; The processing request is generated based on an initial request statement corresponding to the database processing operation; The processor is configured to: When the syntax tree corresponding to the initial request statement does not conform to the statement rule corresponding to the target database, a target syntax tree conforming to the statement rule is obtained by adjusting the nodes in the syntax tree that do not conform to the statement rule; The processing request is generated based on the target syntax tree.
2. The terminal device according to claim 1, characterized in that: The database interaction operation is an operation triggered by a user on a function of a client, and the target database is a database among multiple databases corresponding to the function of the client.
3. The terminal device according to claim 1, characterized in that: The syntax tree corresponding to the initial request statement includes a plurality of nodes, each of the plurality of nodes includes a statement element in the initial request statement, and the position of each node in the syntax tree represents the syntax structure of the initial request statement; The processor is specifically configured to determine that the syntax tree corresponding to the initial request statement does not conform to the statement rule corresponding to the target database in the following manner: It is determined that a sentence element and / or a grammatical structure represented by at least one node in the grammar tree does not conform to a sentence rule corresponding to the target database.
4. The terminal device according to claim 3, characterized in that: The statement rules include element type requirements and grammatical structure requirements; the processor is specifically used to: Traversing each node in the syntax tree based on the statement rule corresponding to the target database, and when the statement element included in the node is different from the statement element in the element type requirement in the statement rule, determining that the node does not meet the element type requirement in the statement rule; When the grammatical structure represented by at least one node is different from the grammatical structure requirement in the sentence rule, it is determined that the at least one node does not meet the grammatical structure requirement in the sentence rule.
5. The terminal device according to claim 4, characterized in that: The processor is specifically used for: If the node does not meet the element type requirement in the statement rule, replacing the statement element in the node with the statement element in the element type requirement; If the node does not meet the grammatical structure requirement in the sentence rule, the position of the node in the syntax tree is adjusted based on the grammatical structure requirement.
6. The terminal device according to claim 4 or 5, characterized in that: The element type requirements in the statement rules include function type requirements, data type requirements and syntax type requirements.
7. The terminal device according to any one of claims 1 to 5, characterized in that: The statement rules corresponding to the target database are pre-stored locally or acquired in real time from an external device.
8. A database processing system, characterized in that: The system includes a client and a Java database connection JDBC driver; In response to a database processing operation triggered by a user, the client sends an initial request statement corresponding to the database processing operation to the JDBC driver, wherein the database processing operation indicates processing of a target database; Receiving the initial request statement through the JDBC driver, and sending the processing request to the server; The processing request is generated by the JDBC driver based on an initial request statement corresponding to the database processing operation; When the syntax tree corresponding to the initial request statement does not conform to the statement rules corresponding to the target database, the JDBC driver obtains a target syntax tree that conforms to the statement rules by adjusting the nodes in the syntax tree that do not conform to the statement rules, and generates the processing request based on the target syntax tree; The JDBC driver receives the processing result returned by the server based on the processing request, and returns the processing result to the client.
9. A database processing method, characterized in that: include: In response to a database processing operation triggered by a user, a processing request is sent to a server; The database processing operation indicates processing of the target database; The processing request is generated based on an initial request statement corresponding to the database processing operation; when a syntax tree corresponding to the initial request statement does not conform to a statement rule corresponding to the target database, a target syntax tree conforming to the statement rule is obtained by adjusting nodes in the syntax tree that do not conform to the statement rule, and the processing request is generated based on the target syntax tree; Receive a processing result returned by the server based on the processing request.
10. A computer-readable storage medium, wherein a computer program is stored in the computer-readable storage medium, characterized in that: When the computer program is executed by a processor, the method described in claim 9 is implemented.