Database operation statement processing method and device, electronic equipment and storage medium
By obtaining and querying statement templates in the database operation statement processing method, and performing metadata extraction processing to generate operation statements that adapt to the target database, the problem of adapting multiple database types in the existing technology requires changing the underlying code, and efficient and flexible database adaptation is achieved.
Patent Information
- Application Number
- CN202311092775.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-28
- Publication Date
- 2025-02-28
AI Technical Summary
The existing technology requires changing the underlying business code when adapting to multiple database types, resulting in huge workloads and error-proneness, which is expensive to implement.
By obtaining operation statements for the target database, querying the statement template library to obtain the target statement template, and performing metadata extraction processing on the operation statements to generate target operation statements that adapt to the target database to achieve adaptation to multiple database types.
No need to change the underlying business code, you can adapt to multiple database types, reduce implementation costs, reduce adaptation workload, and improve flexibility and scalability.
Smart Images

Figure CN119536803A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to database technology, and in particular to a method, device, electronic device, computer-readable storage medium, and computer program product for processing database operation statements. Background Art
[0002] Driven by the digital upgrades and development demands of various industries, many new database types have emerged, and each industry also has customized databases. During software product development, there are often customized requirements for specific database types, requiring the software product to adapt to several databases specified by the demander. This is especially true for big data software products, which inherently require integration with multiple database types for data collection and querying. Therefore, adapting to multiple database types is a large, systematic project that is crucial to the proper functioning of the software product.
[0003] In the solutions provided by related technologies, different versions of database operation codes are usually developed and adapted for different types of databases. That is, a series of processes such as development adaptation, debugging, testing, and online release are carried out from the code level. However, since this solution requires changing the underlying business code of the software product, it results in a huge workload and is prone to errors. The implementation cost of adapting to multiple types of databases is high. Summary of the Invention
[0004] The embodiments of the present application provide a database operation statement processing method, device, electronic device, computer-readable storage medium and computer program product, which can adapt to various database types without changing the underlying business code, thereby reducing implementation costs.
[0005] The technical solution of the embodiment of the present application is implemented as follows:
[0006] The present invention provides a method for processing database operation statements, including:
[0007] Obtain operation statements for the target database;
[0008] According to the target database type to which the target database belongs, querying in a statement template library to obtain a target statement template corresponding to the target database type; wherein the statement template library includes statement templates corresponding to a plurality of database types respectively;
[0009] Performing metadata extraction processing on the operation statement to obtain operation metadata;
[0010] A statement generation process is performed according to the target statement template and the operation metadata to obtain a target operation statement adapted to the target database; wherein the target operation statement is used to operate the target database.
[0011] The present invention provides a database operation statement processing device, including:
[0012] An acquisition module is used to obtain operation statements for a target database;
[0013] A query module, configured to query a statement template library according to the target database type to which the target database belongs, and obtain a target statement template corresponding to the target database type; wherein the statement template library includes statement templates corresponding to a plurality of database types;
[0014] An extraction module, configured to perform metadata extraction processing on the operation statement to obtain operation metadata;
[0015] A generation module is used to perform statement generation processing based on the target statement template and the operation metadata to obtain a target operation statement adapted to the target database; wherein the target operation statement is used to operate the target database.
[0016] An embodiment of the present application provides an electronic device, including:
[0017] a memory for storing executable instructions;
[0018] The processor is used to implement the database operation statement processing method provided in the embodiment of the present application when executing the executable instructions stored in the memory.
[0019] An embodiment of the present application provides a computer-readable storage medium storing executable instructions for causing a processor to execute instructions to implement the database operation statement processing method provided in the embodiment of the present application.
[0020] An embodiment of the present application provides a computer program product, which includes executable instructions for causing a processor to execute and implement the database operation statement processing method provided in the embodiment of the present application.
[0021] The embodiments of the present application have the following beneficial effects:
[0022] After obtaining the operation statement for the target database, on the one hand, according to the target database type to which the target database belongs, a query is performed in the statement template library to obtain the target statement template corresponding to the target database type. In this way, the queried target statement template conforms to the syntax of the target database; on the other hand, metadata extraction processing is performed on the operation statement to obtain operation metadata. The operation metadata obtained in this way can break away from the limitations of the original syntax (or original dialect) of the operation statement, so as to accurately represent the meaning of the operation statement. Then, statement generation processing is performed based on the target statement template and the operation metadata to obtain the target operation statement adapted to the target database. The target database can be operated according to the target operation statement. Therefore, the embodiment of the present application can achieve adaptation to multiple database types by configuring the statement template library without modifying the underlying business code, which can effectively reduce the adaptation workload and reduce the implementation cost. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0024] Figure 1 This is a schematic diagram of the architecture of the database operation statement processing system provided in an embodiment of the present application;
[0025] Figure 2 This is a schematic diagram of the structure of a terminal device provided in an embodiment of the present application;
[0026] Figure 3A This is a flowchart of a method for processing database operation statements provided by an embodiment of the present application;
[0027] Figure 3B This is another flowchart of the method for processing database operation statements provided in an embodiment of the present application;
[0028] Figure 3C This is another flowchart of the method for processing database operation statements provided in an embodiment of the present application;
[0029] Figure 3D This is another flowchart of the method for processing database operation statements provided in an embodiment of the present application;
[0030] Figure 3E This is another flowchart of the method for processing database operation statements provided in an embodiment of the present application;
[0031] Figure 4This is another flowchart of the database operation statement processing method provided in an embodiment of the present application. DETAILED DESCRIPTION
[0032] In order to make the purpose, technical solutions and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limiting this application. All other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0033] In the following description, references to "some embodiments" describe a subset of all possible embodiments. However, it is understood that "some embodiments" may be the same subset or different subsets of all possible embodiments, and may be combined with each other without conflict. In the following description, the term "plurality" refers to at least two.
[0034] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this application pertains. The terms used herein are for the purpose of describing the embodiments of this application only and are not intended to limit this application.
[0035] Before further describing the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.
[0036] 1) Database: This can be thought of as a digital filing cabinet, a place where electronic files are stored. Users can add, query, update, and delete data in these files. A database is a collection of data stored in a specific manner, shared by multiple users, with minimal redundancy, and independent of applications. Databases can be categorized based on the syntax used. For example, database types include MySQL, Oracle, SQL Server, DB2, HBase, and Hive.
[0037] A database management system (DBMS) is a computer software system designed for managing databases, and generally has basic functions such as storage, interception, security, and backup. Database management systems can be classified according to the database models they support, such as relational and extensible markup language (XML); or according to the types of computers they support, such as server clusters and mobile phones; or according to the query language used, such as structured query language (SQL) and XQuery; or according to performance impulse focus, such as maximum scale and maximum operating speed; or other classification methods. Regardless of the classification method used, some DBMSs can cross categories, for example, support multiple query languages at the same time. In an embodiment of the present application, the obtained target operation statement can be sent to the database management system so that the database management system operates the managed database (target database) according to the target operation statement; or, the database management system can also implement the database operation statement processing method provided in the embodiment of the present application.
[0038] 2) Metadata: It is data about data, mainly describing the properties of data. In the embodiment of the present application, the metadata of the operation statement is called operation metadata. Operation metadata is used to describe the variables that need to be defined in the operation statement. Variables are used to identify the objects to be operated on in the database (such as data tables, data columns, fields, permissions, etc.). For example, operation metadata can include the variable value of the variable and the variable type corresponding to the variable value. The variable type is used to distinguish different variables. For example, if a variable type is a data table, the corresponding variable value is the actual value of the data table; the variable type corresponding to the variable value is, that is, the variable type of the variable.
[0039] 3) Abstract Syntax Tree (AST): This is an abstract representation of the grammatical structure of source code. It represents the grammatical structure of a programming language in a tree-like format, with each node in the tree representing a structure in the source code. In the database field, ASTs can be used to represent the grammatical structure of operation statements. Specifically, in databases and related tools (such as query parsers, query optimizers, and code generators), ASTs are used to represent the components of operation statements and the relationships between them, facilitating parsing, optimization, and execution of operation statements.
[0040] 4) Statement Template Library: This includes statement templates corresponding to various database types. For a statement template corresponding to a particular database type, the template conforms to the syntax of that database type. A statement template includes at least one unassigned variable, each corresponding to a variable type. Statement generation is accomplished by assigning values to the variables in the statement template. In the embodiments of the present application, statement templates can be user-defined or automatically generated.
[0041] 5) Operation Type: Operation statements are classified according to specific classification criteria, and the resulting operation statement determines the type of data operation to be performed. For example, depending on the function being performed, four operation types can be classified: data query, data manipulation, data definition, and data control. Based on this, the operation language used to perform data query is called Data Query Language (DQL), the operation statement used to perform data manipulation is called Data Manipulation Language (DML), the operation statement used to perform data definition is called Data Definition Language (DDL), and the operation statement used to perform data control is called Data Control Language (DCL).
[0042] 6) Rule Engine: This is a business component tool for processing business logic and belongs to the middleware system. It allows developers to dynamically create, modify, and execute predefined business rules without changing the source code. The rule engine can be used in professional fields and is an effective tool for solving business logic needs. It improves development efficiency, reduces maintenance costs, and enhances the adaptability of the system. In the embodiment of the present application, a statement template library can be constructed in the form of a rule engine. The statement templates can be regarded as rules in the rule engine.
[0043] 7) Application Programming Interface (API): A set of predefined functions or conventions that connect different components of a software system. Its purpose is to provide application developers with access to a set of routines within a piece of software or hardware, without requiring them to access the source code or understand the details of the internal workings.
[0044] 8) Java Database Connectivity (JDBC): A Java API for executing statements that provides unified access to a wide variety of database types. It consists of a set of classes and interfaces written in the Java language. JDBC provides a baseline upon which higher-level tools and interfaces can be built, enabling database developers to write database applications.
[0045] 9) In response to: used to indicate the conditions or states on which the executed operations depend. When the dependent conditions or states are met, one or more operations executed can be in real time or with a set delay. Unless otherwise specified, there is no restriction on the order in which the multiple operations executed are executed.
[0046] In software development, adapting to multiple database types is a major, systematic undertaking that critically affects the proper functioning of software products. Conventional solutions typically involve developing and adapting different versions of database operation code for different database types. This involves a series of steps, including code-level development, adaptation, debugging, testing, and rollout. However, this approach is labor-intensive and error-prone. Adaptation also introduces significant uncertainty and multi-branch maintenance difficulties to product development, creating significant workload challenges and dramatically increasing R&D costs for many product development teams.
[0047] To this end, embodiments of the present application provide a method, apparatus, electronic device, computer-readable storage medium, and computer program product for processing database operation statements, which can adapt to multiple database types without modifying the underlying business code, thereby reducing implementation costs and providing greater flexibility and scalability. The following describes exemplary applications of the electronic device provided by embodiments of the present application. The electronic device provided by embodiments of the present application can be implemented as various types of terminal devices or as a server.
[0048] See also Figure 1 , Figure 1 1 is a schematic diagram of the architecture of the database operation statement processing system 100 provided in an embodiment of the present application. The terminal device 400 is connected to the server 200 via the network 300. The server 200 is connected to at least one database (in other embodiments, the at least one database may also be deployed in the server 200). Figure 1 In the example, database 500-1, database 500-2 and database 500-3 are used. The network 300 may be a wide area network or a local area network, or a combination of the two.
[0049] In some embodiments, taking the electronic device as a terminal device as an example, the database operation statement processing method provided in the embodiment of the present application can be implemented by the terminal device. For example, the database can be deployed on the terminal device 400 as a target database. The terminal device 400 can run the target business (such as stand-alone software). During the operation of the target business, there is a need to perform data operations on the target database (such as obtaining data from the target database), and then generate corresponding operation statements according to the preset logic. For the generated operation statements, the terminal device 400 queries the statement template library according to the target database type to which the target database belongs, and obtains the target statement template corresponding to the target database type; wherein the statement template library includes statement templates corresponding to a plurality of database types; metadata extraction processing is performed on the operation statement to obtain operation metadata; statement generation processing is performed according to the target statement template and the operation metadata to obtain a target operation statement adapted to the target database. The terminal device 400 can operate on the target database according to the target operation statement, thereby meeting the data operation requirements of the target business.
[0050] Alternatively, when the target database is database 500-1 connected to server 200, terminal device 400 may also send the target operation statement to server 200 so that server 200 operates database 500-1. Server 200 may send the obtained operation result (such as the data obtained from database 500-1) to terminal device 400.
[0051] In some embodiments, taking the electronic device as a server as an example, the database operation statement processing method provided in the embodiments of the present application can also be implemented by the server. For example, server 200 is connected to database 500-1, database 500-2, and database 500-3. When server 200 obtains an operation statement for database 500-1, it uses database 500-1 as the target database. The generated operation statement can be sent to server 200 by client 410 in terminal device 400, or server 200 can generate the operation statement itself. Then, server 200 queries the statement template library based on the target database type to which database 500-1 belongs, obtains the target statement template corresponding to the target database type; performs metadata extraction processing on the operation statement to obtain operation metadata; and performs statement generation processing based on the target statement template and operation metadata to obtain the target operation statement adapted to database 500-1. Server 200 can operate on database 500-1 according to the target operation statement and can send the obtained operation result to terminal device 400.
[0052] It is worth noting that the target operation statement can be executed in the target database through the database management system, or the database operation statement processing method of the embodiment of the present application can also be implemented by the database management system. Figure 1 The database may be deployed in the terminal device 400 or the server 200 shown, or in a dedicated database server (in this case, the server 200 may be a Web server).
[0053] In some embodiments, the terminal device 400 or the server 200 can implement the database operation statement processing method provided in the embodiment of the present application by running a computer program. For example, the computer program can be a native program or software module in the operating system; it can be a local (Native) application (APP, Application), that is, a program that needs to be installed in the operating system to run, such as the client of the target business (corresponding to the client 410 above); it can also be a small program, that is, a program that can be run only when downloaded to a browser environment; it can also be a small program that can be embedded in any APP, and the small program can be controlled by the user to run or close. In short, the above-mentioned computer program can be an application, module or plug-in in any form.
[0054] In some embodiments, the server 200 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be 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, content delivery networks (CDNs), and big data and artificial intelligence platforms. Among them, the cloud service can be a database operation statement processing service for the terminal device 400 to call. The terminal device 400 can be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart TV, a smart watch, etc., but is not limited to this. The terminal device and the server can be directly or indirectly connected via wired or wireless communication, which is not limited in the embodiments of the present application.
[0055] Taking the electronic device provided in the embodiment of the present application as an example, it can be understood that in the case where the electronic device is a server, Figure 2 Parts of the structure shown in FIG (such as the user interface, the presentation module, and the input processing module) may be omitted. Figure 2 , Figure 2 is a schematic diagram of the structure of the terminal device 400 provided in an embodiment of the present application. Figure 2The terminal device 400 shown includes: at least one processor 410, a memory 450, at least one network interface 420, and a user interface 430. The various components in the terminal device 400 are coupled together via a bus system 440. It is understood that the bus system 440 is used to achieve connection and communication between these components. In addition to including a data bus, the bus system 440 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clarity, the bus system 440 is not shown in FIG. Figure 2 Various buses are labeled as bus system 440 .
[0056] The processor 410 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., where the general-purpose processor can be a microprocessor or any conventional processor, etc.
[0057] The user interface 430 includes one or more output devices 431 that enable presentation of media content, including one or more speakers and / or one or more visual display screens. The user interface 430 also includes one or more input devices 432, including user interface components that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls.
[0058] The memory 450 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state memory, hard drives, optical drives, etc. The memory 450 may optionally include one or more storage devices that are physically remote from the processor 410.
[0059] The memory 450 includes volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. The non-volatile memory may be a read-only memory (ROM), and the volatile memory may be a random access memory (RAM). The memory 450 described in the embodiments of the present application is intended to include any suitable type of memory.
[0060] In some embodiments, the memory 450 can store data to support various operations, examples of which include programs, modules, and data structures, or a subset or superset thereof, as exemplified below.
[0061] Operating system 451, including system programs for processing various basic system services and performing hardware-related tasks, such as the framework layer, core library layer, and driver layer, which are used to implement various basic services and process hardware-based tasks;
[0062] A network communication module 452 for reaching other computing devices via one or more (wired or wireless) network interfaces 420 , exemplary network interfaces 420 including Bluetooth, WiFi, and USB;
[0063] a presentation module 453 for enabling presentation of information via one or more output devices 431 (e.g., a display screen, a speaker, etc.) associated with the user interface 430 (e.g., a user interface for operating peripheral devices and displaying content and information);
[0064] The input processing module 454 is configured to detect one or more user inputs or interactions from one of the one or more input devices 432 and to translate the detected inputs or interactions.
[0065] In some embodiments, the apparatus provided in the embodiments of the present application may be implemented in software. Figure 2 The diagram shows a database operation statement processing device 455 stored in memory 450. This device can be software in the form of a program or plug-in, and includes the following software modules: an acquisition module 4551, a query module 4552, an extraction module 4553, and a generation module 4554. These modules are logical and can be arbitrarily combined or further separated according to the functions they implement. The functions of each module will be described below.
[0066] The database operation statement processing method provided in the embodiment of the present application will be explained in combination with the exemplary application and implementation of the electronic device provided in the embodiment of the present application.
[0067] See also Figure 3A , Figure 3A This is a flow chart of the database operation statement processing method provided by the embodiment of the present application, which will be combined with Figure 3A The steps shown are explained.
[0068] In step 101, an operation statement for a target database is obtained.
[0069] Here, an operation statement is obtained. The operation statement is used to operate a specific database. For easy identification, the specific database is named the target database. The number of target databases can be one or more, that is, the operation statement can be used to operate a single database or to perform batch operations on multiple databases.
[0070] It is worth noting that the embodiment of the present application does not limit the syntax used for the operation statement, that is, the syntax of any database type can be used.
[0071] In some embodiments, the operation statement is generated during the operation of the target business; the target database can be determined in the following manner: determining the business database configured by the target business; and determining the business database as the target database targeted by the operation statement.
[0072] The target business refers to the digital business implemented by the software product. The embodiments of the present application do not limit the type of target business. For example, based on the implementation environment, the target business can be a stand-alone business running in a stand-alone environment, or a network business running in a network environment, such as a cloud business implemented in combination with cloud technology; based on the technology involved, the target business can involve cloud technology, artificial intelligence, security, smart maps or image recognition technologies; based on the industry in which it is located, the target business can be a business related to industries such as retail, industry, education, medical care, transportation or government affairs.
[0073] The target business is pre-configured with a corresponding business database, which stores data related to the target business. During the operation of the target business, there is a need to perform data operations on the business database, such as storing generated logs in the business database or obtaining required data from the business database for user viewing. Based on the data operation requirements, corresponding operation statements are generated. At this time, for the electronic device that obtains the operation statement, the business database can be determined as the target database for the operation statement. In this way, the target database can be automatically determined to meet the data operation requirements of the target business.
[0074] In some embodiments, when the electronic device receives a database operation request including an operation statement, it determines the database to which the electronic device is connected, or the database deployed inside the electronic device, as the target database for the operation statement.
[0075] In step 102, according to the target database type to which the target database belongs, a query is performed in the statement template library to obtain a target statement template corresponding to the target database type; wherein the statement template library includes statement templates corresponding to multiple database types.
[0076] Databases can be pre-classified based on applicable syntax. For example, databases can be categorized into MySQL, Oracle, SQL Server, DB2, HBase, and Hive. For each database type that requires adaptation, pre-register statement templates that conform to the syntax of the database type in the statement template library and establish a mapping between the registered statement templates and the database type.
[0077] In this way, after obtaining the operation statement for the target database, a query is performed in the statement template library according to the target database type to which the target database belongs, and a statement template corresponding to the target database type can be obtained. For ease of distinction, the statement template obtained by the query is called the target statement template.
[0078] It is worth noting that a statement template library can be constructed in the form of a rule engine. The statement templates in the statement template library can be regarded as rules in the rule engine, which can be specifically reflected as configuration files. In this way, statement templates can be dynamically created, modified and deleted without changing the source code of the target business.
[0079] In some embodiments, before step 102, the database operation statement processing method further includes: performing any one of the following processing for any database type: in response to a template registration request for any database type, registering the candidate statement template in the template registration request as a statement template corresponding to any database type; performing commonality extraction processing on multiple historical operation statements adapted to any database type to obtain a common statement template, and registering the common statement template as a statement template corresponding to any database type.
[0080] Here, two methods are provided to implement statement template registration. For ease of understanding, database type A is used for illustration.
[0081] 1) In response to a template registration request for database type A, register the candidate statement template in the template registration request as the statement template corresponding to database type A. This method requires manual provision of candidate statement templates for database type A. As long as the candidate statement templates are sufficiently accurate, the adaptation effect with database type A can be guaranteed.
[0082] 2) Commonality extraction is performed on multiple historical operation statements adapted to database type A to obtain common statement templates, and the common statement templates are registered as statement templates corresponding to database type A. The historical operation statements adapted to database type A may refer to historical operation statements that were successfully executed in a database corresponding to database type A. Since these historical operation statements were successfully executed, it can be determined that these historical operation statements can be accurately parsed and executed in the database of database type A, and further, it can be determined that these historical operation statements conform to the grammar of database type A.
[0083] Commonality extraction involves extracting the syntax used across multiple historical operation statements to form a common statement template. For example, elements used in the same position across multiple historical operation statements are extracted and arranged in the order of the elements in the historical operation statements to form a common statement template. Elements include variables and non-variables. Variables identify the objects to be operated on in the database, such as data tables, data columns, and data within a specific numerical range. Non-variables represent the method of operation, such as select, insert, and drop commands.
[0084] For example, the two historical operation statements are "DROP TABLE table1" and "DROP TABLEtable2". Since "DROP TABLE" has the same position in the two historical operation statements and the element value (referring to "DROPTABLE" itself) is also the same, it is extracted as a non-variable; since "table1" and "table2" have the same position in the two historical operation statements and different element values, they are extracted as variables. Since "table1" and "table2" both represent specific data tables, the variable type corresponding to the variable is identified as a data table. Through the above commonality extraction process, the common statement template can be obtained as "DROP TABLE tableName", where "tableName" represents the data table and is the variable to be assigned.
[0085] Through the above-mentioned method 2), it is possible to realize the automatic generation and automatic registration of statement templates based on historical experience, effectively improving the registration efficiency. On the basis of the above-mentioned method 2), corresponding statement templates can also be registered for different operation types. For example, the operation type includes operation type 1 and operation type 2. Then, a commonality extraction process can be performed on multiple historical operation statements that are adapted to database type A and whose operation type is operation type 1, and a commonality statement template 1 is obtained, and commonality statement template 1 is registered as a statement template corresponding to operation type 1 under database type A; a commonality extraction process can be performed on multiple historical operation statements that are adapted to database type A and whose operation type is operation type 2, and a commonality statement template 2 is obtained, and commonality statement template 2 is registered as a statement template corresponding to operation type 2 under database type A. In this way, the statement template obtained is more targeted and can further improve the adaptation effect.
[0086] In step 103, metadata extraction processing is performed on the operation statement to obtain operation metadata.
[0087] Because the acquired operation statements use the syntax of a specific database type, which may not be compatible with the syntax applicable to the target database, or the programming language corresponding to the operation statements may not be accurately parsed by the target database, directly executing the operation statements in the target database may result in inaccurate parsing of the operation statements. Therefore, to avoid interference from the syntax of the operation statements themselves, metadata is extracted from the operation statements to obtain operation metadata. Operation metadata is used to describe the variables that need to be defined in the operation statements. Variables are used to identify the objects to be operated on in the database, such as data tables, data columns, fields, permissions, etc. It is understandable that the operation metadata extracted from the operation statements reflects the most essential characteristics of the operation statements and is independent of the syntax of the operation statements or the programming language used in the operation statements.
[0088] For example, the position of each variable value in the operation statement and the corresponding variable type can be determined based on the syntax used by the operation statement, and the variable value can be extracted from the corresponding position to construct the operation metadata of the operation statement.
[0089] It is worth noting that the embodiment of the present application does not limit the execution order between step 102 and step 103. The two steps can be executed simultaneously or successively. For example, step 103 can also be executed before step 102.
[0090] In some embodiments, the operation metadata includes at least one variable value in the operation statement, and the variable type corresponding to each variable value; after step 103, the database operation statement processing method further includes: for any variable type, performing the following processing: determining the legal value condition corresponding to any variable type; when the variable value corresponding to any variable type in the operation metadata does not meet the legal value condition, performing risk control processing on the operation statement.
[0091] Here, after extracting the operation metadata, a validity check can be performed on the operation metadata. If the operation metadata includes at least one variable value in the operation statement and the variable type corresponding to each variable value, a validity check can be performed on at least one of the variable types. For ease of understanding, the following description uses an arbitrary variable type, namely variable type 1.
[0092] First, determine the legal value conditions corresponding to variable type 1. The legal value conditions can be pre-set according to the specific circumstances of variable type 1. For example, if variable type 1 is a user name, the corresponding legal value conditions can be set as follows: the number of characters is limited to 5 to 20 characters, and can only be composed of uppercase and lowercase letters, numbers, and does not contain special characters. Then, the variable value corresponding to variable type 1 in the operation metadata is compared with the legal value conditions corresponding to variable type 1. When the variable value corresponding to variable type 1 does not meet the legal value conditions, it is proved that the variable value corresponding to variable type 1 is illegal, so the operation statement is subjected to risk control processing. The embodiment of the present application does not limit the method of risk control processing. For example, it can stop generating target operation statements based on operation statements, and can also issue alarms based on operation statements. Through the above method, the legality of the operation metadata and the subsequently generated target operation statements can be guaranteed, the security of the target database can be improved, and attacks such as SQL injection can be effectively defended.
[0093] In step 104, statement generation processing is performed based on the target statement template and the operation metadata to obtain a target operation statement adapted to the target database; wherein the target operation statement is used to operate the target database.
[0094] Since the target statement template conforms to the syntax of the target database, and the operation metadata is data in the operation statement that is unrelated to the syntax, the two can be combined to perform statement generation processing to obtain a target operation statement that is adapted to the target database. The target operation statement obtained in this way not only conforms to the syntax of the target database, but also can operate on the objects required by the operation statement (referring to the operation statement obtained in step 101).
[0095] After obtaining the target operation statement, an operation can be performed on the target database according to the target operation statement. For example, the target operation statement can be executed in the target database through a database management system (DBMS), where the DBMS is used to manage the target database, to obtain an operation result. The obtained operation result can be a prompt indicating whether the operation is successful or failed. If the operation statement is used to query data (retrieve data), if the operation is successful, the operation result may also include the queried data.
[0096] If there are multiple target databases, a target operation statement may be generated for each target database separately and executed in the corresponding target database, thereby implementing batch operations.
[0097] In some embodiments, after step 104, the database operation statement processing method further includes: operating the target database according to the target operation statement; when the operation on the target database according to the target operation statement fails, prompting to update at least one of the operation statement and the target statement template.
[0098] Here, when an operation on the target database fails according to a target operation statement, it indicates that there may be an error in at least one of the operation statement and the target statement template. For example, a variable value in the operation statement is an illegal variable value and cannot point to an object in the target database; or there is a syntax error in the target statement template, resulting in failure to execute in the target database. In this case, a prompt can be provided to update at least one of the operation statement and the target statement template. For example, the prompt can be provided by displaying at least one of the operation statement, the target statement template, the target operation statement, and the operation result. This allows the user to quickly locate the root cause of the error and fix it.
[0099] Since the target statement template may contain errors, for other obtained operation statements, the statement generation and processing based on the target statement template can be suspended until the target statement template is updated or the target statement template is determined to be correct. This can avoid the situation where new operation statements generated using the target statement template for other operation statements are unavailable, thereby avoiding waste of resources.
[0100] After at least one of the operation statement and the target statement template is updated, the target operation statement may be regenerated, and the target database may be operated according to the new target operation statement.
[0101] In addition, considering that the operation failure may be caused by other factors during the operation (such as network fluctuations), the operation on the target database can be retried according to the target operation statement. If the result of the retried operation is that the operation is successful, there is no need to update the operation statement and at least one of the target statement templates.
[0102] In some embodiments, metadata extraction processing is performed on the operation statement. After the operation metadata is obtained, the database operation statement processing method also includes: displaying the operation metadata; the above-mentioned statement generation processing based on the target statement template and the operation metadata can be implemented in such a way to obtain the target operation statement adapted to the target database: in response to the update operation on the operation metadata, statement generation processing is performed based on the target statement template and the updated operation metadata to obtain the target operation statement adapted to the target database.
[0103] After the operation metadata is obtained through metadata extraction processing, the operation metadata can be displayed. For example, if the operation metadata includes at least one variable value in the operation statement and the variable type corresponding to each variable value, it can be displayed in the form of "variable value 1-variable type 1" and "variable value 2-variable type 2". Of course, this does not constitute a limitation on the embodiments of the present application.
[0104] Because operation metadata is separated from the syntax of the operation statement, the displayed operation metadata accurately represents the objects and operations to be performed by the operation statement in the target database. Users can use the displayed operation metadata to determine whether it meets the operation requirements. If not, they can update the displayed operation metadata. This includes but is not limited to adding data to the operation metadata, deleting data from the operation metadata, and modifying data in the operation metadata.
[0105] In response to an update operation on the operational metadata, the electronic device generates a statement based on the target statement template and the updated operational metadata, obtaining a target operational statement adapted to the target database. This approach avoids the waste of resources associated with regenerating operational statements by updating the operational metadata. Furthermore, because the operational metadata itself is simple and clear, users unfamiliar with the syntax can quickly understand its meaning and update it, effectively lowering the operational barrier to entry.
[0106] like Figure 3A As shown, the embodiment of the present application configures a statement template library, which includes statement templates corresponding to multiple database types. After obtaining the operation statement for the target database, the target statement template corresponding to the target database type to which the target database belongs is obtained from the statement template library; metadata is extracted from the operation statement to obtain operation metadata decoupled from the syntax of the operation statement; because the target statement template is adapted to the syntax of the target database, based on the operation metadata and the target statement template, a target operation statement adapted to the syntax of the target database can be generated, which can ensure that the target operation statement is accurately parsed and executed in the target database, thereby improving the success rate of database operations. Since the entire process does not require changes to the underlying business code of the target business and the database, it can reduce the implementation cost of adapting to multiple database types while improving flexibility and scalability.
[0107] In some embodiments, see Figure 3B , Figure 3B This is a flowchart of a method for processing database operation statements provided by an embodiment of the present application. Figure 3A Step 104 shown can be implemented through steps 201 to 202 , which will be described in conjunction with each step.
[0108] In step 201 , for any variable in the target statement template, a variable value in the operation metadata that corresponds to the same variable type as the variable is assigned to the variable.
[0109] Here, the target statement template includes at least one variable, each variable corresponds to a variable type, and the operation metadata includes at least one variable value in the operation statement and the variable type corresponding to each variable value. In this case, the statement generation processing is essentially a process of assigning a value to each variable in the target statement template.
[0110] For ease of understanding, let's use variable 1 as an example. For variable 1, the value of the variable with the same variable type as variable 1 in the operation metadata is assigned to variable 1 in the target statement template. For example, if variable 1 is of the data table type, the actual value of the data table in the operation metadata is assigned to the data table variable in the target statement template.
[0111] It is worth noting that during the metadata extraction process, a lexical analysis process may occur. Lexical analysis may split a complete variable value into multiple variable values according to specific splitting rules. Therefore, for a variable type, the corresponding variable value in the operation metadata may be one or more. In the latter case, multiple variable values can be combined according to their order in the operation statement and then assigned. For example, in the operation statement, the variable value of the query condition variable is "age>18", but in the operation metadata, it may be split into three variable values: "age">", and "18". Therefore, these three variable values can be recombined into "age>18" and then assigned to the query condition variable in the target statement template.
[0112] In step 202, a target statement template to which at least one variable has been assigned a value is determined as a target operation statement adapted to a target database.
[0113] Here, the target statement template to which each variable has been assigned is determined to be a target operation statement adapted to the target database. The target operation statement obtained in this way points to the same object as the operation statement obtained in step 101, and the target operation statement conforms to the syntax of the target database and can be executed in the target database.
[0114] In some embodiments, during step 201, the database operation statement processing method further includes: when the operation metadata does not include a variable value corresponding to the target variable type, and the target variable type is a non-essential variable type, deleting the target variable corresponding to the target variable type in the target statement template, or assigning a default variable value corresponding to the target variable type to the target variable in the target statement template.
[0115] Here, the variable type involved in the target statement template may include at least one of a required variable type and a non-required variable type. Variables corresponding to the required variable type must be assigned a value, otherwise they will become invalid variables, while variables corresponding to the non-required variable type can be deleted or defaulted. The required variable type and the non-required variable type can be determined based on the syntax of the corresponding database type.
[0116] For any variable type in the target statement template (named as the target variable type), when the operation metadata does not include the variable value corresponding to the target variable type, and the target variable type is a necessary variable type, the target variable corresponding to the target variable type in the target statement template becomes an invalid variable. At this time, the generation of the target operation statement can be stopped, and a prompt to update the operation statement can be given (such as a prompt to supplement the variable value corresponding to the target variable type); when the operation metadata does not include the variable value corresponding to the target variable type, and the target variable type is a non-necessary variable type, the target variable corresponding to the target variable type in the target statement template can be deleted, or the default variable value corresponding to the target variable type can be assigned to the target variable in the target statement template, so that the target variable obtained is a valid variable. In the above manner, when the operation metadata lacks a variable value, different processing is performed according to whether the corresponding variable type is a necessary variable type, which can improve the effectiveness of the obtained target operation statement and thereby improve the success rate of database operations.
[0117] like Figure 3B As shown, the embodiment of the present application generates a target operation statement by assigning variables, thereby achieving an effective combination of the target statement template and the operation metadata, so that the target operation statement can point to the correct object in the target database.
[0118] In some embodiments, see Figure 3C , Figure 3C This is a flowchart of a method for processing database operation statements provided by an embodiment of the present application. Figure 3A Step 103 shown can be implemented through steps 301 to 303 , which will be described in conjunction with each step.
[0119] In step 301, the operation statement is subjected to lexical analysis and syntactic analysis to obtain an abstract syntax tree including multiple nodes; wherein the multiple nodes include variable value nodes corresponding to variable values in the operation statement and variable type nodes corresponding to variable types.
[0120] Here, an example of metadata extraction processing is provided. First, the operation statement is lexically analyzed. For example, the operation statement is scanned from the start position to the end position of the operation statement to split the operation statement into multiple lexical units (tokens). In other words, lexical analysis essentially implements word segmentation.
[0121] Then, the multiple lexical units obtained by splitting are parsed to resolve the relationships between them, resulting in a tree-structured abstract syntax tree (ABST). The ABST includes multiple nodes, each corresponding to at least one lexical unit. Based on the grammatical structure of the ABST, the multiple nodes in the ABST are divided into variable value nodes and variable type nodes. The variable values in the operation statement are obtained from the lexical units corresponding to the variable value nodes, and the variable types in the operation statement are obtained from the lexical units corresponding to the variable type nodes.
[0122] Among them, there is no limitation on the classification method of nodes. For example, it can be implemented based on the principle of machine learning. For example, a sample operation statement is obtained, and the sample operation statement is annotated with a variable value and a corresponding variable type (i.e., the annotation result). The sample operation statement is lexically analyzed and syntactically analyzed to obtain an abstract syntax tree. The abstract syntax tree is then classified by a node classification model. The difference between the classification result and the annotation result is calculated to train the node classification model. The trained node classification model can be used to classify the nodes of the abstract syntax tree corresponding to the operation statement. For example, a rigid classification rule can be adopted, such as taking the nodes of a specific level in the abstract syntax tree (such as the level below the level where the root node is located, where the root node is usually used to represent the operation type) as variable type nodes, and the nodes of the levels below the specific level as variable value nodes.
[0123] In step 302, for any variable value node in the abstract syntax tree, a correspondence is established between the variable value corresponding to any variable value node and the variable type corresponding to the target variable type node; wherein the target variable type node is the ancestor node of any variable value node.
[0124] Here, the relationship between variable values and variable types is established based on the relationship between variable value nodes and variable type nodes in the abstract syntax tree. For example, taking any variable value node in the abstract syntax tree (named as the target variable value node) as an example, a corresponding relationship is established between the variable value corresponding to the target variable value node and the variable type corresponding to the target variable type node, where the target variable type node is the ancestor node of the target variable value node, that is, the target variable type node is connected to the target variable value node, and the target variable type node is located at a level above the target variable value node.
[0125] In step 303, operation metadata of the operation statement is constructed according to the corresponding relationship.
[0126] Here, the operation metadata of the operation statement is constructed according to the correspondence between the variable value and the variable type in the operation statement. In this way, the obtained operation metadata includes at least one variable value in the operation statement and the variable type corresponding to each variable value.
[0127] like Figure 3C As shown, the embodiment of the present application extracts metadata by generating an abstract syntax tree, which can accurately split the various parts in the operation statement and analyze the relationship between the various parts, thereby improving the accuracy of the obtained operation metadata.
[0128] In some embodiments, see Figure 3D , Figure 3D This is a flowchart of a method for processing database operation statements provided by an embodiment of the present application. Figure 3A Step 102 shown can be implemented through steps 401 to 402, which will be described in conjunction with each step.
[0129] In step 401, the operation type to which the operation statement belongs is determined as the target operation type.
[0130] For the same database type, the syntax of different operation types may differ. Therefore, in embodiments of the present application, the statement templates in the statement template library can be further refined, that is, statement templates corresponding to each database type and multiple operation types can be configured. In the statement template library, the storage format of the statement template is similar to the key-value format, where the key is "database type-operation type" and the value is "statement template".
[0131] The operation type is obtained by classifying the operation statements according to specific classification criteria. For example, according to the different functions implemented, four operation types can be classified: DQL, DML, DDL, and DCL. Among them, DQL is used to query data, DML is used to select, insert, update, and delete content in the database, DDL is used to describe the real-world entities to be stored in the database, and DCL is used to control data access permissions in the database. Based on this example, for database type A, the statement template library has registered statement templates corresponding to database type A's DQL, statement templates corresponding to database type A's DML, statement templates corresponding to database type A's DDL, and statement templates corresponding to database type A's DCL.
[0132] Based on the classification of multiple operation types, the operation type to which the operation statement belongs is determined as the target operation type. The target operation type can be obtained by directly identifying the operation statement (such as keyword identification) or by identifying the operation metadata.
[0133] In some embodiments, due to the differences in functions (non-variable) involved in operation statements of different operation types, for example, for data query language (DQL), it is usually a select statement, such as "select * from XX". If an operation statement includes a "select" function, it can be determined that the operation type to which the operation statement belongs is DQL. The function name representing the function in the operation statement can be used as a keyword in the operation statement, such as "select" in the above operation statement. On this basis, a keyword set corresponding to each operation type can be pre-constructed. Then, after determining the keyword in the operation statement, the operation type corresponding to the keyword set where the keyword is located is determined as the target operation type to which the operation statement belongs.
[0134] In step 402, a query is performed in a statement template library according to the target database type and the target operation type to obtain a target statement template; wherein the statement template library includes statement templates corresponding to multiple operation types of each database type.
[0135] Here, according to the target database type of the target database targeted by the operation statement and the target operation type of the operation statement, a query is performed in the statement template library to obtain the target statement template. The target statement template corresponds to the target database type and the target operation type, that is, the target statement template conforms to the syntax of the target database regarding the target operation type.
[0136] like Figure 3D As shown, the embodiment of the present application introduces operation types to make the queried target statement template more accurate and targeted, which can effectively improve the success rate of database operations.
[0137] In some embodiments, see Figure 3E , Figure 3E This is a flowchart of a method for processing database operation statements provided by an embodiment of the present application. Figure 3A After step 102 shown, in step 501 , the target statement template and the operation statement may be subjected to statement matching processing to obtain a statement matching result.
[0138] Since the embodiments of the present application do not restrict the syntax used by the operation statement, there are two situations. The first situation is that the syntax used by the operation statement is not the syntax of the target database. In this situation, the target database cannot be directly operated according to the operation statement, and the operation statement needs to be converted; the second situation is that the syntax used by the operation statement happens to be the syntax of the target database.
[0139] In order to determine which of the above situations the actual situation belongs to, the queried target statement template can be matched with the operation statement to obtain a statement matching result. Since grammar is more often reflected through non-variables, the statement matching process can be a match for non-variables. For example, when the operation statement contains all the non-variables in the target statement template, the statement matching result is determined to be a successful match; when the operation statement does not contain all the non-variables in the target statement template, the statement matching result is determined to be a failed match. When the operation statement contains all the non-variables in the target statement template, it can be further determined whether the position of the same non-variable in the operation statement is consistent with the position in the target statement template. If they are consistent, the statement matching result is determined to be a successful match; if they are inconsistent, the statement matching result is determined to be a failed match. Of course, the above example does not constitute a limitation on the statement matching process. For example, the statement matching process can also calculate the similarity between the operation statement and the target statement template. If the similarity is greater than a similarity threshold, the statement matching result is determined to be a successful match; if the similarity is less than or equal to the similarity threshold, the statement matching result is determined to be a failed match.
[0140] In step 502, when the statement matching result is successful, the target database is operated according to the operation statement.
[0141] Here, when the statement matching result is a successful match, it is determined that the syntax used in the operation statement is the syntax of the target database. At this time, the target database is operated directly according to the operation statement without converting the operation statement, which can avoid unnecessary waste of resources.
[0142] exist Figure 3E middle, Figure 3A The illustrated step 103 may be updated to step 503. In step 503, when the statement matching result is a match failure, metadata extraction processing is performed on the operation statement to obtain operation metadata.
[0143] When the statement matching result is a match failure, it is determined that the syntax used in the operation statement is not the syntax of the target database. At this time, metadata extraction processing is performed on the operation statement to obtain operation metadata, and the operation statement is converted into a target operation statement using the operation metadata and the target statement template.
[0144] like Figure 3E As shown, the embodiment of the present application distinguishes two different situations based on the syntax used in the operation statement and performs different processing, which can effectively reduce the waste of computing resources. At the same time, when the syntax used in the operation statement is the syntax of the target database, the operation is directly performed, thereby improving operation efficiency.
[0145] Below, the exemplary application of the embodiment of the present application in an actual application scenario will be described. For ease of understanding, the scenario in which the operation statement is an SQL statement will be used as an example. The embodiment of the present application parses the SQL statement for the target database into an abstract syntax tree through an SQL parser. The abstract syntax tree is a structured representation of the metadata of the SQL statement, so the metadata of the SQL statement (corresponding to the operation metadata above) can be extracted from the abstract syntax tree. Then, a suitable SQL generation rule is selected in the rule engine dynamically maintained in the background, and the SQL generation rule and metadata are finally read by the SQL generator to generate a target SQL statement (corresponding to the target operation statement above) that conforms to the target database dialect (the dialect corresponds to the grammar above). The obtained target SQL statement can be executed in the database instance of the target database to implement data operations.
[0146] Next, we will combine Figure 4 The flowchart shown is explained in detail in the form of steps.
[0147] Step 1) Receive SQL statements in any dialect.
[0148] Here, an SQL statement in any dialect generated by an application is obtained, wherein the application can generate the SQL statement through preset code, and the application is used to implement the above target business.
[0149] Step 2) Parse the SQL statement into an abstract syntax tree.
[0150] The SQL statement is parsed into an abstract syntax tree through an SQL parser (such as SQL Parsing). The abstract syntax tree is a structured metadata representation.
[0151] For example, if the SQL statement obtained is "SELECT name,age FROM users WHERE age>18", the abstract syntax tree obtained by parsing can be:
[0152]
[0153] The above abstract syntax tree is explained from top to bottom: the SELECT node is the root node, which represents the query operation, which is also the operation type of the SQL statement; the Columns node represents the column to be queried, and the Column node represents the specific column name (such as name and age); the FROM node represents the data table to be queried, and the Table node represents the name of the data table (such as users); the WHERE node represents the query condition, that is, the data filtering condition, the BinaryExpr node represents the binary expression involved in the query condition (such as >), and the Column node represents the column name involved in the query condition (such as age); the Value node represents the specific value involved in the query condition (such as 18).
[0154] It is worth noting that in the above abstract syntax tree, the Columns node, the FROM node, and the WHERE node correspond to the variable type nodes above, and the child nodes of the Columns node, the child nodes of the FROM node, and the child nodes of the WHERE node correspond to the variable value nodes above.
[0155] By converting SQL statements into an abstract syntax tree, it is easier to analyze SQL statements, rewrite them, or convert them to a specific database dialect.
[0156] Step 3) Extract metadata from the abstract syntax tree.
[0157] Here, metadata may include the variable values in the abstract syntax tree and the variable type corresponding to each variable value. Taking the above abstract syntax tree as an example, the extracted metadata may be:
[0158]
[0159] Step 4) Read the SQL generation rules in the rule engine.
[0160] Here, users can use the rule management backend to write or modify SQL generation rules in the rule engine based on different database types and operation types. SQL generation rules in the rule engine can be stored in the form of configuration files (Config). For each SQL generation rule, it can include the applicable database type (such as MySQL, Oracle, or SQL Server), the applicable operation type (such as DQL, DDL, DML, or DCL), and the SQL template (corresponding to the statement template mentioned above).
[0161] For example, a SQL generation rule can be in the following form:
[0162]
[0163] Among them, data tables, columns and inserted values are all variables that need to be assigned values.
[0164] Step 5) Select appropriate SQL generation rules to generate the target SQL statement.
[0165] For example, a rule executor (SQL Generate) can be designed in advance. The rule executor selects a suitable SQL generation rule from multiple SQL generation rules read according to the database type of the database configured by the application (corresponding to the business database mentioned above) and the operation type of the SQL statement generated by the application. For easy distinction, the SQL template in the selected SQL generation rule is named the target SQL template (corresponding to the target statement template mentioned above).
[0166] Then, the rule executor generates statements based on the metadata and the target SQL template to obtain the target SQL statement. For example, if the target SQL template is "INSERT INTO {table}({column})VALUES({insert value})", and the actual values of the table, column, and insert value in the extracted metadata are users, age, and 18, respectively, then the target SQL statement obtained after statement generation is "INSERT INTO users(age)VALUES(18)", which means: insert a new row in the age column of the users table, and the data in the age column of this row is 18.
[0167] After obtaining the target SQL statement, you can execute the target SQL statement in the target database through the JDBC driver of the target database. Figure 4 The example below takes the case where the target database is MySQL database.
[0168] It is worth noting that the embodiments of the present application can be applicable to a variety of environments, for example, can be deployed in a stand-alone environment or a network environment (networked environment).
[0169] Through the above steps, at least the following technical effects can be achieved:
[0170] 1) Low code and lightweight: The embodiments of the present application do not require changes to the underlying business code, and can dynamically modify rules (i.e., modify statement templates) while the application is running. It is easy to maintain and update, does not affect business operations, and has a low technical threshold.
[0171] 2) Reduce database adaptation workload: For each database type, only a few operation types such as DQL, DML, DDL, and DCL need to be adapted, without the need to adapt rules for all SQL statements, thereby greatly reducing the adaptation workload of multi-source databases.
[0172] 3) Improve code maintainability: The adaptation code for multi-source databases is reflected in configuration files, and the application code becomes more concise and readable, which helps reduce costs and risks during project maintenance and iteration.
[0173] 4) Easy to expand: When you need to support new database types or new operation types, you only need to add the corresponding SQL generation rules in the rule engine.
[0174] 5) Wide range of applications: The multi-source database adaptation implemented in the embodiments of the present application has the advantages of standardization and consistency, and meets the traceability and auditability requirements of industries such as medical care and government affairs.
[0175] The following continues to describe the exemplary structure of the database operation statement processing device 455 provided in the embodiment of the present application implemented as a software module. In some embodiments, such as Figure 2 As shown, the software modules stored in the database operation statement processing device 455 of the memory 450 may include: an acquisition module 4551, used to obtain operation statements for the target database; a query module 4552, used to query in the statement template library according to the target database type to which the target database belongs, and obtain the target statement template corresponding to the target database type; wherein the statement template library includes statement templates corresponding to multiple database types; an extraction module 4553, used to perform metadata extraction processing on the operation statement to obtain operation metadata; a generation module 4554, used to perform statement generation processing according to the target statement template and the operation metadata to obtain the target operation statement adapted to the target database; wherein the target operation statement is used to operate the target database.
[0176] In some embodiments, the target statement template includes at least one variable, each variable corresponds to a variable type; the operation metadata includes at least one variable value in the operation statement, and the variable type corresponding to each variable value; the generation module 4554 is also used to: for any variable in the target statement template, assign the variable value of the same variable type corresponding to any variable in the operation metadata to any variable; determine the target statement template to which at least one variable has been assigned as the target operation statement adapted to the target database.
[0177] In some embodiments, the generation module 4554 is also used to: when the operation metadata does not include a variable value corresponding to the target variable type, and the target variable type is a non-essential variable type, delete the target variable corresponding to the target variable type in the target statement template, or assign the default variable value corresponding to the target variable type to the target variable in the target statement template.
[0178] In some embodiments, the extraction module 4553 is further used to: perform lexical analysis and syntactic analysis on the operation statement to obtain an abstract syntax tree including multiple nodes; wherein the multiple nodes include variable value nodes corresponding to the variable values in the operation statement, and variable type nodes corresponding to the variable types; for any variable value node in the abstract syntax tree, establish a correspondence between the variable value corresponding to any variable value node and the variable type corresponding to the target variable type node; wherein the target variable type node is the ancestor node of any variable value node; and construct the operation metadata of the operation statement according to the correspondence.
[0179] In some embodiments, the query module 4552 is also used to: determine the operation type to which the operation statement belongs as the target operation type; query in the statement template library according to the target database type and the target operation type to obtain the target statement template; wherein the statement template library includes statement templates corresponding to multiple operation types of each database type.
[0180] In some embodiments, the database operation statement processing device 455 also includes a matching module, which is used to perform statement matching processing on the target statement template and the operation statement to obtain a statement matching result; when the statement matching result is a successful match, the target database is operated according to the operation statement; the extraction module 4553 is also used to: when the statement matching result is a failed match, the operation statement is subjected to metadata extraction processing to obtain operation metadata.
[0181] In some embodiments, the operation metadata includes at least one variable value in the operation statement, and the variable type corresponding to each variable value; the database operation statement processing device 455 also includes a risk control module, which is used to perform the following processing for any variable type: determine the legal value condition corresponding to any variable type; when the variable value corresponding to any variable type in the operation metadata does not meet the legal value condition, the operation statement is subjected to risk control processing.
[0182] In some embodiments, the database operation statement processing device 455 also includes a registration module, which is used to perform any of the following processing for any database type: in response to a template registration request for any database type, registering the candidate statement template in the template registration request as a statement template corresponding to any database type; performing commonality extraction processing on multiple historical operation statements adapted to any database type to obtain a common statement template, and registering the common statement template as a statement template corresponding to any database type.
[0183] In some embodiments, the database operation statement processing device 455 also includes an operation module for: operating the target database according to the target operation statement; when the operation on the target database fails according to the target operation statement, prompting to update at least one of the operation statement and the target statement template.
[0184] In some embodiments, the database operation statement processing device 455 also includes a display module for displaying operation metadata; the generation module 4554 is also used to respond to the update operation on the operation metadata, perform statement generation processing according to the target statement template and the updated operation metadata, and obtain the target operation statement adapted to the target database.
[0185] In some embodiments, the operation statement is generated during the operation of the target business; the database operation statement processing device 455 also includes a determination module for: determining the business database configured by the target business; and determining the business database as the target database targeted by the operation statement.
[0186] The present invention provides a computer program product or computer program, which includes executable instructions stored in a computer-readable storage medium. A processor of an electronic device reads the executable instructions from the computer-readable storage medium and executes the executable instructions, causing the electronic device to perform the database operation statement processing method described in the present invention.
[0187] An embodiment of the present application provides a computer-readable storage medium storing executable instructions, wherein the executable instructions are stored. When the executable instructions are executed by a processor, the processor will execute the database operation statement processing method provided in the embodiment of the present application.
[0188] In some embodiments, the computer-readable storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface storage, optical disk, or CD-ROM; or various devices including one or any combination of the above memories.
[0189] In some embodiments, executable instructions may be in the form of a program, software, software module, script, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine, or other unit suitable for use in a computing environment.
[0190] As an example, executable instructions may, but need not, correspond to a file in a file system, may be stored as part of a file that stores other programs or data, such as in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinating files (e.g., files storing one or more modules, subroutines, or code portions).
[0191] By way of example, executable instructions may be deployed to be executed on one computing device, or on multiple computing devices at one site, or on multiple computing devices distributed across multiple sites and interconnected by a communication network.
[0192] In summary, the embodiments of the present application can achieve at least the following technical effects:
[0193] 1) Adaptation to various database types can be achieved by configuring the statement template library without changing the underlying business code. This can effectively reduce implementation costs and the complexity of the overall solution, and improve flexibility, maintainability, ease of use, scalability, readability, and portability.
[0194] 2) The target operation statement is generated by variable assignment, which realizes the effective combination of the target statement template and the operation metadata, so that the target operation statement can point to the correct object in the target database.
[0195] 3) By generating an abstract syntax tree to extract metadata, it is possible to accurately split the various parts of the operation statement and analyze the relationship between the parts, thereby improving the accuracy of the obtained operation metadata.
[0196] 4) By configuring statement templates corresponding to various operation types in the statement template library, the adaptation effect is more refined, the queried target statement templates are more accurate and more targeted, which can effectively improve the success rate of database operations.
[0197] 5) It has a wide range of applications and can be applied to businesses related to industries such as retail, industry, education, medical care, transportation or government affairs, and can meet the traceability and auditability requirements of specific businesses.
[0198] The above are merely examples of the present application and are not intended to limit the scope of protection of the present application. Any modifications, equivalent replacements, and improvements made within the spirit and scope of the present application are included in the scope of protection of the present application.
Claims
1. A method for processing database operation statements, characterized in that: include: Get the operation statement for the target database; According to the target database type to which the target database belongs, query in the statement template library to obtain the target statement template corresponding to the target database type; wherein the statement template library includes statement templates corresponding to a plurality of database types respectively; Performing metadata extraction processing on the operation statement to obtain operation metadata; A statement generation process is performed according to the target statement template and the operation metadata to obtain a target operation statement adapted to the target database; wherein the target operation statement is used to operate the target database.
2. The method according to claim 1, characterized in that The target statement template includes at least one variable, each variable corresponds to a variable type; the operation metadata includes at least one variable value in the operation statement, and the variable type corresponding to each variable value; The generating process of the statement according to the target statement template and the operation metadata to obtain the target operation statement adapted to the target database includes: For any variable in the target statement template, assigning a variable value in the operation metadata and corresponding to the same variable type as the any variable to the any variable; The target statement template to which the at least one variable has been assigned a value is determined as a target operation statement adapted to the target database.
3. The method according to claim 2, characterized in that The method further comprises: When the operation metadata does not include a variable value corresponding to the target variable type, and the target variable type is a non-essential variable type, the target variable corresponding to the target variable type in the target statement template is deleted, or Assign a default variable value corresponding to the target variable type to the target variable in the target statement template.
4. The method according to claim 1, characterized in that The step of performing metadata extraction processing on the operation statement to obtain operation metadata includes: Performing lexical analysis and grammatical analysis on the operation statement to obtain an abstract syntax tree including a plurality of nodes; wherein the plurality of nodes include variable value nodes corresponding to the variable values in the operation statement and variable type nodes corresponding to the variable types; For any variable value node in the abstract syntax tree, a correspondence relationship between a variable value corresponding to the any variable value node and a variable type corresponding to a target variable type node is established; wherein the target variable type node is an ancestor node of the any variable value node; The operation metadata of the operation statement is constructed according to the corresponding relationship.
5. The method according to claim 1, characterized in that The querying in the statement template library according to the target database type to which the target database belongs, and obtaining the target statement template corresponding to the target database type, includes: Determine the operation type to which the operation statement belongs as the target operation type; According to the target database type and the target operation type, a query is performed in the statement template library to obtain a target statement template; wherein the statement template library includes statement templates corresponding to multiple operation types of each database type.
6. The method according to any one of claims 1 to 5, characterized in that: After querying in a statement template library according to the target database type to which the target database belongs and obtaining a target statement template corresponding to the target database type, the method further includes: Perform sentence matching processing on the target sentence template and the operation sentence to obtain a sentence matching result; When the statement matching result is a successful match, operating the target database according to the operation statement; The step of performing metadata extraction processing on the operation statement to obtain operation metadata includes: When the statement matching result is a match failure, metadata extraction processing is performed on the operation statement to obtain operation metadata.
7. The method according to any one of claims 1 to 5, characterized in that: The operation metadata includes at least one variable value in the operation statement, and a variable type corresponding to each variable value; After performing metadata extraction processing on the operation statement to obtain the operation metadata, the method further includes: For any variable type, perform the following processing: Determine a legal value condition corresponding to any one of the variable types; When the variable value corresponding to any one of the variable types in the operation metadata does not satisfy the legal value condition, risk control processing is performed on the operation statement.
8. The method according to any one of claims 1 to 5, characterized in that: According to the target database type to which the target database belongs, before querying in the statement template library, the method further includes: For any database type, perform any of the following operations: In response to a template registration request for the any one database type, registering the candidate statement template in the template registration request as a statement template corresponding to the any one database type; A commonality extraction process is performed on a plurality of historical operation statements adapted to any one of the database types to obtain a common statement template, and the common statement template is registered as a statement template corresponding to any one of the database types.
9. The method according to any one of claims 1 to 5, characterized in that: After performing statement generation processing according to the target statement template and the operation metadata to obtain a target operation statement adapted to the target database, the method further includes: Performing operations on the target database according to the target operation statement; When the target database operation fails according to the target operation statement, a prompt is provided to update at least one of the operation statement and the target statement template.
10. The method according to any one of claims 1 to 5, characterized in that: After performing metadata extraction processing on the operation statement to obtain the operation metadata, the method further includes: Displaying the operation metadata; The generating process of the statement according to the target statement template and the operation metadata to obtain the target operation statement adapted to the target database includes: In response to an update operation on the operation metadata, statement generation processing is performed according to the target statement template and the updated operation metadata to obtain a target operation statement adapted to the target database.
11. The method according to any one of claims 1 to 5, characterized in that: The operation statement is generated during the operation of the target service; the method further includes: Determining a service database configured for the target service; The business database is determined as the target database targeted by the operation statement.
12. A database operation statement processing device, characterized in that: include: An acquisition module is used to acquire operation statements for a target database; A query module, used to query in a statement template library according to the target database type to which the target database belongs, and obtain a target statement template corresponding to the target database type; wherein the statement template library includes statement templates corresponding to a plurality of database types respectively; An extraction module, used to perform metadata extraction processing on the operation statement to obtain operation metadata; A generation module is used to perform statement generation processing according to the target statement template and the operation metadata to obtain a target operation statement adapted to the target database; wherein the target operation statement is used to operate the target database.
13. An electronic device, characterized in that: include: A memory for storing executable instructions; A processor, configured to implement the database operation statement processing method according to any one of claims 1 to 11 when executing the executable instructions stored in the memory.
14. A computer-readable storage medium, characterized in that: Executable instructions are stored, and when executed by a processor, the method for processing database operation statements according to any one of claims 1 to 11 is implemented.
15. A computer program product, characterized in that It includes executable instructions, which are used to implement the database operation statement processing method described in any one of claims 1 to 11 when executed by a processor.