Method and apparatus for executing database statement
By determining the connection object of the target database and generating the execution order, the problem of low efficiency in calling multiple databases in big data platforms is solved, and the interaction is simplified and the efficiency is improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING PACTERA JINXIN TECH LTD
- Filing Date
- 2023-10-18
- Publication Date
- 2026-04-24
AI Technical Summary
When big data platforms call multiple databases, the technology stack becomes too complex, reducing the efficiency of database calls.
The connection object is determined based on the identification information of the target database, the execution order is generated based on the control statements and SQL execution statements, the list of SQL execution statements is sent to the target database, and the execution result set is obtained.
It simplifies the interaction process between the server and various types of databases, reduces the technology stack, and improves database call efficiency.
Smart Images

Figure CN117407411B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method and apparatus for executing database statements. Background Technology
[0002] With the continuous development of computers, the amount of data in databases is growing rapidly. Big data platforms have become an important data architecture for enterprises to process big data. The backend of big data platforms cleans, transforms, and loads data by running a large number of tasks.
[0003] In related technologies, when performing the aforementioned tasks, big data platforms need to use various external computer languages to call SQL statements, thereby accessing data from different types of databases. Since the data that the big data platform needs to access is stored in multiple databases, using multiple computer languages to access each database leads to an overly complex technology stack for the enterprise, thus reducing the efficiency of the big data platform in accessing databases. Summary of the Invention
[0004] Therefore, it is necessary to provide a method, apparatus, computer device, computer-readable storage medium, and computer program product for executing database statements that can improve the efficiency of database calls by big data platforms, in order to address the aforementioned technical problems.
[0005] Firstly, this application provides a method for executing database statements, including:
[0006] Based on the identification information of the target database, the connection object corresponding to the target database is determined, and the target database is connected based on the connection object. The identification information of the target database is determined based on the SQL connection statement in the database statement, and the identification information corresponds one-to-one with the target database.
[0007] Based on the multiple control statements and multiple SQL execution statements contained in the database statement, a list of SQL execution statements to be executed is obtained. The control statements contain the control logic of the database statement, and the execution order of the list of SQL execution statements to be executed is determined based on the control logic of each control statement.
[0008] According to the execution order of the list of SQL execution statements to be executed, each of the SQL execution statements in the list of SQL execution statements to be executed is sent to the target database, so that the target database processes each of the SQL execution statements, obtains the execution result set, and returns the execution result set.
[0009] In one embodiment, determining the connection object corresponding to the target database based on the identification information of the target database includes:
[0010] Based on preset character recognition rules, the SQL connection statement is used to identify character information that matches the character recognition rules, and the character information is identified as the identification information of the target database.
[0011] Based on the preset correspondence between the connection object and the database identification information, the connection object corresponding to the identification information of the target database is determined.
[0012] In one embodiment, determining the connection object corresponding to the target database based on the identification information of the target database includes:
[0013] Determine the driver path corresponding to the identifier information of the target database, and obtain the database connection driver corresponding to the target database contained in the driver path;
[0014] The database connection driver creates a connection object corresponding to the target database.
[0015] In one embodiment, after creating the connection object corresponding to the target database through the database connection driver, the method further includes:
[0016] The identification information of the target database and the connection object corresponding to the target database are added to the preset correspondence between the connection object and the database identification information to obtain an updated correspondence. The updated correspondence is used to determine the connection object corresponding to the target database when connecting to the target database.
[0017] In one embodiment, the step of obtaining a list of SQL execution statements to be executed based on the multiple control statements and multiple SQL execution statements contained in the database statement includes:
[0018] Based on the control logic of each control statement contained in the database statement, the execution order and number of executions of the multiple SQL execution statements contained in the database statement are adjusted to obtain a list of SQL execution statements to be executed containing multiple SQL execution statements.
[0019] In one embodiment, before sending each of the SQL execution statements in the list of SQL execution statements to be executed to the target database according to the execution order of the list of SQL execution statements to be executed, the method further includes:
[0020] The parameters of the SQL execution statement are updated according to the statement update parameters in the target parameter configuration file corresponding to the database statement, resulting in the updated SQL execution statement.
[0021] In one embodiment, the method further includes:
[0022] Obtain the target update parameters contained in the execution result set;
[0023] In the target parameter configuration file, the statement update parameters are updated based on the target update parameters to obtain the updated statement update parameters.
[0024] In one embodiment, determining the connection object corresponding to the target database based on the identification information of the target database includes:
[0025] Based on the identification information of the target database, the login information corresponding to the target database is determined in the target parameter configuration file, and the target parameter configuration file contains encrypted login information;
[0026] The connection object corresponding to the target database is determined based on the login information.
[0027] In one embodiment, the method further includes:
[0028] If the identification information of the target database contains the characters for "target thread", then create the target thread;
[0029] The database statement is executed through the target thread.
[0030] In one embodiment, the method further includes:
[0031] When connected to a first target database and a second target database via the SQL connection statement, a target pipeline file is determined such that the first target database performs read table operations and write table operations on the target pipeline file, and the second target database performs read table operations and write table operations on the target pipeline file.
[0032] Secondly, this application also provides a database statement execution device, comprising:
[0033] The database connection module is used to determine the connection object corresponding to the target database based on the identification information of the target database, and connect to the target database based on the connection object. The identification information of the target database is determined based on the SQL connection statement in the database statement, and the identification information corresponds one-to-one with the target database.
[0034] The SQL statement determination module is used to obtain a list of SQL execution statements to be executed based on multiple control statements and multiple SQL execution statements contained in the database statement. The control statements contain the control logic of the database statement, and the execution order of the list of SQL execution statements to be executed is determined based on the control logic of each control statement.
[0035] The SQL statement execution module is used to send each of the SQL statements in the list of SQL statements to be executed to the target database in the execution order of the list of SQL statements to be executed, so that the target database processes each of the SQL statements to obtain an execution result set and returns the execution result set.
[0036] In one embodiment, the database connection module is specifically used to: identify characters in the SQL connection statement based on preset character recognition rules, determine character information that matches the character recognition rules, and determine that the character information is the identification information of the target database; and determine the connection object corresponding to the identification information of the target database based on the preset correspondence between connection objects and database identification information.
[0037] In one embodiment, the database connection module is further configured to: determine the driver path corresponding to the identification information of the target database, and obtain the database connection driver corresponding to the target database contained in the driver path; and create a connection object corresponding to the target database through the database connection driver.
[0038] In one embodiment, the database connection module is further configured to: add the identification information of the target database and the connection object corresponding to the target database to the preset correspondence between the connection object and the database identification information to obtain an updated correspondence, wherein the updated correspondence is used to determine the connection object corresponding to the target database based on the updated correspondence when connecting to the target database.
[0039] In one embodiment, the SQL statement determination module is specifically used to: adjust the execution order and execution number of multiple SQL execution statements contained in the database statement based on the control logic of each control statement contained in the database statement, so as to obtain a list of SQL execution statements to be executed containing multiple SQL execution statements.
[0040] In one embodiment, the device further includes a parameter update module, specifically used to: update the parameters of the SQL execution statement according to the statement update parameters in the target parameter configuration file corresponding to the database statement, so as to obtain the updated SQL execution statement.
[0041] In one embodiment, the parameter update module is further configured to: obtain the target update parameters contained in the execution result set; and update the statement update parameters in the target parameter configuration file based on the target update parameters to obtain the updated statement update parameters.
[0042] In one embodiment, the database connection module is further configured to: determine the login information corresponding to the target database in the target parameter configuration file based on the identification information of the target database, wherein the target parameter configuration file contains encrypted login information; and determine the connection object corresponding to the target database based on the login information.
[0043] In one embodiment, the apparatus further includes a thread execution module, specifically configured to: create a target thread if the identification information of the target database contains the character for target thread; and execute the database statements through the target thread.
[0044] In one embodiment, the apparatus further includes a pipeline file determination module, specifically configured to: determine a target pipeline file when connected to a first target database and a second target database via the SQL connection statement, such that the first target database performs a read outer table operation and a write inner table operation on the target pipeline file, and the second target database performs a read inner table operation and a write outer table operation on the target pipeline file.
[0045] Thirdly, this application also provides a computer device. The computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the steps of the method described in the first aspect.
[0046] Fourthly, this application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program thereon, which, when executed by a processor, implements the steps of the method described in the first aspect.
[0047] Fifthly, this application also provides a computer program product. The computer program product includes a computer program that, when executed by a processor, implements the steps of the method as described in the first aspect.
[0048] The aforementioned database statement execution method, apparatus, computer equipment, storage medium, and computer program product allow the server to connect to the target database through a connection object determined based on the target database's identification information. The server can also obtain a list of SQL execution statements to be executed based on the control logic of the control statements and the SQL execution statements. Based on this, after connecting to the target database, the server can send the list of SQL execution statements to the target database. Upon receiving the list, the target database can operate on the database according to the statements in the list, obtain the execution results, and return the results. By adopting this method, connections can be made to various types of databases, enabling the target database to execute the SQL execution statements contained in the database statements and obtain the execution results. This simplifies the process of server interaction with various types of databases, reduces the technology stack required by the server, and ultimately improves the efficiency of establishing connections and interacting with various types of databases. Attached Figure Description
[0049] To more clearly illustrate the technical solutions in the embodiments or related technologies of this application, the accompanying drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0050] Figure 1 This is an application environment diagram of a database statement execution method in one embodiment;
[0051] Figure 2 This is a flowchart illustrating the execution method of database statements in one embodiment;
[0052] Figure 3 This is a flowchart illustrating the steps for determining the connection object in one embodiment;
[0053] Figure 4 This is a flowchart illustrating the steps for determining the connection object in another embodiment;
[0054] Figure 5 This is a flowchart illustrating the steps of updating statement parameters in one embodiment;
[0055] Figure 6 This is a flowchart illustrating the steps for determining the connection object in another embodiment;
[0056] Figure 7 This is a flowchart illustrating the execution method of database statements in another embodiment;
[0057] Figure 8This is a structural block diagram of a database statement execution device in one embodiment;
[0058] Figure 9 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0059] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0060] The database statement execution method provided in this application embodiment can be applied to, for example, Figure 1 In the application environment shown, terminal 102 communicates with server 104 via a network. Terminal 102 can send database statements to be executed to server 104, enabling server 104 to establish a communication connection with the data storage system (database), and then send the database statements to the database, causing the database to execute the database statements and obtain an execution result set. The data storage system can store the data that server 104 needs to process and retrieve the data after receiving the database statements. The data storage system can be integrated on server 104 or placed on the cloud or other network servers. Terminal 102 can be, but is not limited to, various personal computers, laptops, smartphones, and tablets. Server 104 can be implemented using a standalone server or a server cluster consisting of multiple servers.
[0061] In one exemplary embodiment, such as Figure 2 As shown, a method for executing database statements is provided, which can be applied to... Figure 1 Taking the server in the example, the explanation includes the following steps S202 to S206. Wherein:
[0062] Step S202: Based on the identification information of the target database, determine the connection object corresponding to the target database, and connect to the target database based on the connection object.
[0063] The identification information of the target database is determined based on the SQL join statement in the database statement. The SQL join statement is the statement used to connect to the target database, and the identification information corresponds one-to-one with the target database. The connection object is the connection entity required when the server establishes a connection with the database. The connection entity can be represented by code, and the server can connect to the database through the connection object.
[0064] Specifically, the server identifies the SQL connection statement from the database statements and determines the identification information contained in the SQL connection statement according to preset character recognition rules. Since the identification information corresponds one-to-one with the target database, the server can determine the connection object corresponding to the target database based on the identification information. The server then calls the execution statement containing the connection object to establish a connection between the server and the target database.
[0065] Optionally, the server identifies the SQL connection statement based on a preset character recognition rule, and determines the identification information of the target database based on the character recognition rule, thereby replacing the connection object in the server with the connection object corresponding to the target database. For example, if the database statement contains the format "@Sysid", it is determined that the database statement is an SQL connection statement. Based on this, if the "id" in "@Sysid" is "001", the identification information of the SQL connection statement can be determined as the identification information corresponding to "001", and the connection object corresponding to "001" can be determined based on this identification information.
[0066] Step S204: Based on the multiple control statements and multiple SQL execution statements contained in the database statement, obtain a list of SQL execution statements to be executed.
[0067] The database statements consist of control statements and SQL execution statements. Control statements contain the control logic for the database statements, which determines the number of times and the execution order of the SQL execution statements. This ensures that the SQL execution statements are executed by the target database according to a preset number of times and preset execution logic, thereby obtaining the execution result. The execution order of the list of SQL execution statements to be executed is determined based on the control logic of each control statement.
[0068] Specifically, the server iterates through the database statements. For each statement, it determines its type based on preset statement recognition rules. The statement type can be a control statement or an SQL execution statement. If the statement is a control statement, the server adjusts the execution order of the SQL execution statements within the control logic, resulting in a statement sequence containing multiple SQL execution statements corresponding to the control statement. After completing the database statement traversal, the statement sequences corresponding to each control statement are merged according to the traversal order to obtain a list of SQL execution statements to be executed.
[0069] Optionally, the server can determine whether a database statement is a control statement by using a combination of preset characters and control commands. For example, a database statement containing ".quit" is a control statement, the preset character is ".", and the control command is "quit". This control statement indicates that the list of SQL execution statements has been completed and there is no need to add any more SQL execution statements to be executed. The server can also determine whether a database statement is an execution statement by using single quotes. For example, a database statement enclosed in two single quotes can be an SQL execution statement.
[0070] Step S206: According to the execution order of the list of SQL execution statements to be executed, send each SQL execution statement in the list of SQL execution statements to be executed to the target database, so that the target database processes each SQL execution statement, obtains the execution result set, and returns the execution result set.
[0071] Specifically, the server iterates through the list of SQL statements to be executed, determines the execution order of the SQL statements, and sends multiple SQL statements to the connected target database in that order. Upon receiving the SQL statements, the target database executes them sequentially, performing CRUD operations (Create, Read, Update, Delete) based on the instructions within the SQL statements. The results of each SQL statement are then merged into a result set, which is finally sent back to the server.
[0072] In one example, the server can send each SQL statement to the target database sequentially according to the execution order of the SQL statement list, so that the target database processes each SQL statement in the order they are sent; the server can also send each SQL statement in the SQL statement list to the target database synchronously, so that the target database processes each SQL statement in the execution order of the SQL statement list.
[0073] Optionally, if the server connects to two or more target databases simultaneously, the list of SQL execution statements to be executed may include the identification information of a single target database, so that the server can send the corresponding SQL execution statements to the target database.
[0074] Based on the aforementioned database statement execution method, it can be seen that the server connects to the target database using a connection object determined by the target database's identification information. The server can also obtain a list of SQL execution statements to be executed based on the control logic of the control statements and the SQL execution statements. Therefore, after connecting to the target database, the server can send the list of SQL execution statements to the target database. Upon receiving the list, the target database can operate on the database according to the statements in the list, obtain the execution results, and return them. By adopting this method, connections can be made with various types of databases, enabling the target database to execute the SQL execution statements contained in the database statements and obtain the execution results. This simplifies the process of server interaction with various types of databases, reduces the technology stack required by the server, and ultimately improves the efficiency of establishing connections and interacting with various types of databases.
[0075] In one exemplary embodiment, such as Figure 3 As shown, the specific implementation process of the step "determine the connection object corresponding to the target database based on the identification information of the target database" includes steps S302 to S304. Wherein:
[0076] Step S302: Based on preset character recognition rules, the character information is identified in the SQL connection statement to determine the character information that matches the character recognition rules, and the character information is determined to be the identification information of the target database.
[0077] The character information refers to the string-type text information in the SQL join statement. This character information can serve as identification information for the target database.
[0078] Specifically, after the server identifies the SQL connection statement from the database statement, the server can parse the SQL connection statement according to the preset character recognition rules, determine the text data that conforms to the character recognition rules, and use the text data as character information that matches the character recognition rules. The server searches for the character information in the mapping relationship between character information and identification information. If the character information exists in the mapping relationship between character information and identification information, the server obtains the identification information corresponding to the character information based on the mapping relationship, thereby determining the identification information of the target database.
[0079] Optionally, the server identifies SQL connection statements based on preset character recognition rules and determines the character information of the target database based on these rules. The server can determine the identifier information corresponding to the character information matching the character recognition rules based on a preset mapping relationship between the target database and character information. Based on this, the server replaces the connection object in the server with the connection object corresponding to the target database. For example, if the database statement contains the text "@Sysid", it is determined that the database statement is an SQL connection statement. Therefore, if the "id" in "@Sysid" is "002", the identifier information corresponding to the character information "002" in the SQL connection statement can be determined from the preset mapping relationship between the target database and character information.
[0080] Step S304: Based on the preset correspondence between the connection object and the database identification information, determine the connection object corresponding to the identification information of the target database.
[0081] The pre-defined correspondence between connection objects and database identification information can include multiple one-to-one correspondences between connection objects and identification information.
[0082] Specifically, the server can query a pre-defined mapping between connection objects and database identifiers based on the identified target server's identifier information. If the mapping contains the identifier information, the server can obtain the connection object corresponding to that identifier. Since the pre-defined mapping between connection objects and database identifier information can provide an association between the identifier information of multiple databases and their corresponding connection objects, the server can obtain the connection object for the target database based on its identifier information.
[0083] In this embodiment, the identification information is determined by character recognition rules, and the correspondence between the identification information of the connection object and the database can be used to quickly obtain the connection object of the target database, thereby improving the efficiency of user interaction with the database.
[0084] In one exemplary embodiment, such as Figure 4 As shown, the specific implementation process of the step "determine the connection object corresponding to the target database based on the identification information of the target database" includes steps S402 to S404. Wherein:
[0085] Step S402: Determine the driver path corresponding to the identifier information of the target database, and obtain the database connection driver corresponding to the target database contained in the driver path.
[0086] Step S404: Create a connection object for the target database using the database connection driver.
[0087] The driver path indicates the storage location of the database connection driver corresponding to the target database on the server. The database connection driver can be used to create the connection object corresponding to the target database. The database connection driver can be the driver file corresponding to the database provided by the database vendor.
[0088] Specifically, after obtaining the identification information of the target database, the server can merge the text of the identification information into a preset driver path to obtain the driver path corresponding to the identification information. The server then calls the driver path corresponding to the identification information to determine the database connection driver for the target database. The server runs the database connection driver to create the connection object for the target database.
[0089] Optionally, the server can store the Java driver files corresponding to multiple database connection drivers in a preset target driver path. After the server obtains the identification information of the target database, it can load the corresponding Java driver file in the target driver path through the identification information, execute the calling instruction, and create the connection object corresponding to the target database.
[0090] In this embodiment, by locating the database connection driver through the driver path and obtaining the connection object corresponding to the target database based on the database connection driver, it can be ensured that the server accurately calls the database connection driver of the target database and creates the connection object corresponding to the target database, thereby improving the stability of creating the connection object corresponding to the target database.
[0091] In an exemplary embodiment, after the step "creating a connection object corresponding to the target database through a database connection driver", the method for executing the database statement further includes:
[0092] Add the target database's identifier information and the corresponding connection object to the preset mapping relationship between connection objects and database identifier information to obtain the updated mapping relationship.
[0093] The updated mapping relationship is used to determine the connection object corresponding to the target database when connecting to the target database.
[0094] Specifically, the server contains a file containing a pre-defined mapping between connection objects and database identification information. Based on this, after obtaining the identification information of a new target database and its corresponding connection object, the server adds the target database's identification information and corresponding connection object to this file, thereby updating the mapping between connection objects and identification information contained in that file. When the server reconnects to the target database based on the identification information, it can preferentially determine the connection object from the file containing the pre-defined mapping between connection objects and database identification information.
[0095] In this embodiment, by updating the correspondence between the identification information of the connection object and the database, an updated file containing the correspondence is obtained, which can improve the speed at which the server creates the connection object corresponding to the target database, thereby improving the efficiency of the server connecting to the target database.
[0096] In an exemplary embodiment, the specific implementation process of the step "obtaining a list of SQL execution statements to be executed based on multiple control statements and multiple SQL execution statements contained in the database statement" includes:
[0097] Based on the control logic of each control statement contained in the database statement, the execution order and number of executions of multiple SQL execution statements contained in the database statement are adjusted to obtain a list of SQL execution statements to be executed containing multiple SQL execution statements.
[0098] Specifically, the server iterates through the database statements. For each statement, it determines whether it is a control statement or an SQL execution statement based on preset statement recognition rules. If the statement is a control statement, the server determines the execution order, loop count, and loop logic of each SQL execution statement within the control logic. Based on the loop logic, the server merges the execution order and loop count of each SQL execution statement corresponding to the control statement, thus obtaining a statement sequence containing multiple SQL execution statements corresponding to the control statement. After completing the traversal of the database statements, the statement sequences corresponding to each control statement are merged according to the traversal order to obtain a list of SQL execution statements to be executed.
[0099] In this embodiment, by traversing the database statements, an execution order and number of executions are added to multiple SQL execution statements to obtain a list of SQL execution statements to be executed. This enables the target database to determine the execution result corresponding to the SQL execution statement list, thereby improving the execution efficiency of the database statements.
[0100] In an exemplary embodiment, before the step of "sending each SQL statement in the list of SQL statements to be executed to the target database in the execution order of the list of SQL statements to be executed", the method for executing the database statements further includes:
[0101] The parameters of the SQL execution statement are updated based on the statement update parameters in the target parameter configuration file corresponding to the database statement, resulting in the updated SQL execution statement.
[0102] The target parameter file can contain attribute parameters required by the database statements. These attribute parameters may include connection configuration parameters for connecting to the target database, statement update parameters for dynamically adjusting data objects in the SQL execution statement, and working variable parameters representing the server's execution environment for the database statements. Statement update parameters can be parameter information corresponding to the data objects to be processed in the SQL execution statement.
[0103] Specifically, when a user inputs the target execution object corresponding to an SQL execution statement into the server, the server stores the target execution object in a target parameter configuration file and parses the file to determine the statement update parameters corresponding to the target execution object. Based on this, the server updates the SQL execution statement corresponding to the target execution object with the update parameters, resulting in an updated SQL execution statement. The updated SQL execution statement can interact with the target execution object in the target database to obtain the corresponding interaction results. The target execution object can be a field of a table in the target database. For example, after a user inputs multiple field parameters into the server, the server stores these parameters in the target configuration file. Based on this, the server replaces the expected update parameters with the new field parameters to obtain an updated SQL execution statement, enabling the target database to execute the SQL execution statement containing multiple field parameters and obtain the execution results corresponding to those parameters.
[0104] In one example, connection configuration parameters can include the target database's identifier, address, username, and password. When determining the target database's identifier, the server can create a connection object corresponding to the target database based on the identifier and the connection configuration parameters.
[0105] In one example, the working variable parameters could include the server's IP address, port number, root directory, and identification information corresponding to the initial database.
[0106] In this embodiment, by updating the parameters in the target parameter configuration file, the parameters of the SQL execution statement are updated. This allows the parameters to be executed in the SQL execution statement to be dynamically changed without changing the SQL execution statement itself. As a result, the SQL execution statement with the same structure can be repeatedly executed by only changing the parameters, thereby improving the utilization rate of the SQL execution statement.
[0107] In one exemplary embodiment, such as Figure 5 As shown, the execution method of this database statement further includes steps S502 to S504. Wherein:
[0108] Step S502: Obtain the target update parameters contained in the execution result set.
[0109] Step S504: In the target parameter configuration file, update the statement update parameters based on the target update parameters to obtain the updated statement update parameters.
[0110] The execution result set comprises the results obtained by the target database based on each SQL statement. The target update parameters are the attribute parameters of the data contained in each result within the execution result set. After the target database executes the SQL statements, the server can use the execution result set as input parameters to update the SQL statements, resulting in updated SQL statements. Finally, the target database executes the updated SQL statements again, thus completing the iterative execution of SQL statements in the target database. Therefore, the target update parameters are used to update the parameters in the SQL statements.
[0111] Specifically, after obtaining the execution result set returned by the target database, the server parses the execution result set, determines the target update parameters contained in the execution result set, and updates the parameters in the SQL execution statement based on the target update parameters contained in the execution result set to obtain the updated statement update parameters. For example, it can replace the fields queried in the SQL execution statement. The original statement update parameters are used to query animal information, while the updated statement update parameters are used to query human information contained in the animal information.
[0112] In this embodiment, the target update parameters in the target parameter configuration file are updated using the target update parameters in the execution result set. This allows for dynamic modification of parameters in the SQL execution statement based on the execution results of the target database, thereby improving the execution efficiency of the SQL statement.
[0113] In one exemplary embodiment, such as Figure 6 As shown, the specific implementation process of the step "determine the connection object corresponding to the target database based on the identification information of the target database" includes:
[0114] Step S602: Based on the identification information of the target database, determine the login information corresponding to the target database in the target parameter configuration file.
[0115] Step S604: Determine the connection object corresponding to the target database based on the login information.
[0116] The target parameter configuration file contains encrypted login information, which may include login information for the target database. This login information can consist of connection configuration parameters from the target parameter configuration file. The connection configuration parameters for the target database may include the target database's identifier, address, username, and password.
[0117] Specifically, based on the identified target database's identifier, the server can determine the login information corresponding to the target database that matches the identifier from the connection configuration parameters included in the target parameter configuration file. Then, based on the target database's address, username, and password from the login information, the server creates a connection object for the target database. When creating the connection object, the server executes the driver file corresponding to the database connection driver, inputting the target database's address, username, and password into the driver file to obtain the connection object for the target database.
[0118] In this embodiment, the login information corresponding to the target database is determined in the target parameter configuration file by identifying the information, and a connection object is created based on the login information. This allows users to flexibly define the database login information in the target parameter configuration file so that the server can create connection objects, thereby improving the efficiency of creating connection objects for each target database when the server connects to each target database.
[0119] In an exemplary embodiment, the method for executing the database statement further includes: creating a target thread if the identification information of the target database contains the character for target thread; and executing the database statement through the target thread.
[0120] Specifically, if the identification information of the target database contains a preset call character, the server creates a new thread. The target database can execute the corresponding SQL execution statement based on the new thread. The new thread provides the database with the execution environment and computing power to execute the SQL execution statement, so that the database can efficiently output the execution result set.
[0121] In one example, if the target database's identifier contains " / bg", the server creates a new thread. For instance, if the target database's identifier is "@sysid[ / bg]", which contains " / bg", the server creates a new thread.
[0122] In this embodiment, creating new threads can improve the execution efficiency of SQL statements in the target database.
[0123] In an exemplary embodiment, the specific implementation process of the database statement execution method further includes: when connecting to a first target database and a second target database via an SQL connection statement, determining a target pipeline file, so that the first target database performs read table operations and write table operations on the target pipeline file, and the second target database performs read table operations and write table operations on the target pipeline file. The target pipeline file enables two different databases to read and write data simultaneously.
[0124] Specifically, when the server connects to the first target database and the second target database, it can create a target pipeline file through either the first or the second target database. Based on this, the first target database performs read operations on the outer table and write operations on the inner table on the target pipeline file, while the second target database performs read operations on the inner table and write operations on the outer table on the target pipeline file. Since the channels used by the first target database for reading and writing data are different from those used by the second target database for reading and writing data, data synchronization between the first and second target databases can be achieved.
[0125] In this embodiment, by creating a target pipeline file, two target databases can be executed in parallel, thereby improving the efficiency of the server calling the database.
[0126] like Figure 7 As shown, the following describes in detail the specific execution process of the above database statement execution method, including the following steps, with reference to a specific embodiment:
[0127] Step S702: Initialize the target parameter configuration file corresponding to the server. The server creates the target parameter configuration file, which is in XML format. The target parameter configuration file includes login information for multiple databases, including database address, database name, database password, and database password encryption method, and configures initial values for them. In addition, the target parameter configuration file may also include server environment information, including the server's IP address, port number, root directory information, etc.
[0128] Step S704: Iterate through the database statements to determine the connection object for the target database and connect to it. Parse the statement corresponding to ".logon" and log in to the target database based on this SQL connection statement. This SQL connection statement also includes the prefix "@sysID", indicating a connection to the database corresponding to "id".
[0129] Since the target parameter configuration file contains the database address, database name, and database password, a connection object for the target database is created based on this default configuration information. Because the target database supports JDBC connections, the server can store the corresponding JDBC driver file (in JAR format). The connection object is then created based on the database driver path corresponding to this JDBC driver file. For example, the JDBC implementation class can be specified using the `Class.forName` statement, and the `DriverManager.getConnection` statement can be called to obtain the JDBC database connection object. Based on this connection object, SQL execution statements can be submitted to the target database.
[0130] Step S706: Traverse the database statements and determine the list of SQL execution statements to be executed based on the control statements and SQL execution statements in the database statements.
[0131] The server iterates through the database statements. For each statement, it determines whether it is a control statement or an SQL execution statement based on preset statement recognition rules. If the statement is a control statement, the server adjusts the corresponding SQL execution statement based on the control logic of the control statement. After the iteration is complete, a list of SQL execution statements to be executed is obtained.
[0132] In step S708, the target database obtains an execution result set based on the list of SQL execution statements to be executed.
[0133] The server iterates through the list of SQL statements to be executed, determining the execution order. It then sends multiple SQL statements to the connected target database in that order. Upon receiving the SQL statements, the target database executes them, performing CRUD operations based on the instructions within the statements. The server then merges the results of each SQL statement into a result set, which is finally returned to the server.
[0134] Step S710: Update the parameters in the target parameter configuration file based on the execution result set, and replace the parameters in the SQL execution statement. When a user inputs the target execution object corresponding to the SQL execution statement into the server, the server can store the target execution object in the target parameter configuration file, parse the target parameter configuration file, and determine the statement update parameters corresponding to the target execution object. Based on this, the server updates the statement update parameters to the SQL execution statement corresponding to the target execution object, obtaining the updated SQL execution statement. This allows the updated SQL execution statement to interact with the target execution object in the target database and obtain the interaction result corresponding to the target execution object.
[0135] In addition, to support the parallel execution of specific SQL statements in two target databases, a character recognition rule for "@sysid" is set. If the identifier information of the target database is "@sysid[ / bg]", the server can internally create a thread to execute the current SQL statement because " / bg" is appended to the identifier information.
[0136] Furthermore, if both target databases support file-based external table operations, a data file format that both target databases can support can be selected, such as TSV. One target database reads internal tables and writes them to the external table, while the other target database reads the external table and writes it to the internal table, with the files corresponding to both external tables sharing the same pipe file. Based on this, a full data synchronization document without intermediate files can be written from both target databases. This method can achieve full synchronization of tables from one target database to tables in another.
[0137] For example, ".OS" control commands can be used to invoke operating system commands, enabling the server and the target database system's corresponding loading or exporting tools to work together. If there is a data warehouse system (DWS) and an Oracle system, DWS creates a readable external table parameter pointing to a pipe file. It then uses background SQL execution statements to read the external table and write the internal table. Next, the ".OS" control command starts the Oracle system's data extraction tool, which exports data and writes it to the pipe file. Furthermore, the actions of DWS reading the external table and writing the internal table are executed in parallel with the data extraction actions performed by the Oracle system. Based on this, database table data synchronization between the Oracle system and DWS can be achieved.
[0138] It should be understood that although the steps in the flowcharts of the above embodiments are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the above embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0139] Based on the same inventive concept, this application also provides a database statement execution apparatus for implementing the database statement execution method described above. The solution provided by this apparatus is similar to the implementation described in the above method; therefore, the specific limitations in one or more database statement execution apparatus embodiments provided below can be found in the limitations of the database statement execution method described above, and will not be repeated here.
[0140] In one exemplary embodiment, such as Figure 8 As shown, a database statement execution device 800 is provided, including: a database connection module 801, an SQL statement determination module 802, and an SQL statement execution module 803, wherein:
[0141] The database connection module 801 is used to determine the connection object corresponding to the target database based on the identification information of the target database, and connect to the target database based on the connection object. The identification information of the target database is determined based on the SQL connection statement in the database statement, and the identification information corresponds one-to-one with the target database.
[0142] The SQL statement determination module 802 is used to obtain a list of SQL execution statements to be executed based on multiple control statements and multiple SQL execution statements contained in the database statement. The control statements contain the control logic of the database statement, and the execution order of the list of SQL execution statements to be executed is determined based on the control logic of each control statement.
[0143] The SQL statement execution module 803 is used to send each SQL statement in the list of SQL statements to be executed to the target database in the execution order, so that the target database can process each SQL statement, obtain the execution result set, and return the execution result set.
[0144] Furthermore, the database connection module 801 is specifically used for: identifying characters in an SQL connection statement based on preset character recognition rules, determining character information that matches the character recognition rules, and determining the character information as the identifier information of the target database; and determining the connection object corresponding to the identifier information of the target database based on the preset correspondence between the connection object and the identifier information of the database.
[0145] Furthermore, the database connection module 801 is specifically used to: determine the driver path corresponding to the identification information of the target database, and obtain the database connection driver corresponding to the target database contained in the driver path; and create a connection object corresponding to the target database through the database connection driver.
[0146] Furthermore, the database connection module 801 is specifically used to: add the identification information of the target database and the connection object corresponding to the target database to the preset correspondence between the connection object and the database identification information to obtain the updated correspondence. The updated correspondence is used to determine the connection object corresponding to the target database based on the updated correspondence when connecting to the target database.
[0147] Furthermore, the SQL statement determination module 802 is specifically used to: adjust the execution order and execution number of multiple SQL execution statements contained in the database statement based on the control logic of each control statement contained in the database statement, so as to obtain a list of SQL execution statements to be executed containing multiple SQL execution statements.
[0148] Furthermore, the device also includes a parameter update module, which is specifically used to update the parameters of the SQL execution statement according to the statement update parameters in the target parameter configuration file corresponding to the database statement, so as to obtain the updated SQL execution statement.
[0149] Furthermore, the parameter update module is specifically used to: obtain the target update parameters contained in the execution result set; and update the statement update parameters in the target parameter configuration file based on the target update parameters to obtain the updated statement update parameters.
[0150] Furthermore, the database connection module 801 is specifically used to: determine the login information corresponding to the target database in the target parameter configuration file based on the identification information of the target database, the target parameter configuration file containing encrypted login information; and determine the connection object corresponding to the target database based on the login information.
[0151] Furthermore, the device also includes a thread execution module, specifically used for: creating a target thread if the identification information of the target database contains the characters for target thread; and executing database statements through the target thread.
[0152] Furthermore, the device also includes a pipeline file determination module, specifically used to: determine a target pipeline file when connected to a first target database and a second target database via an SQL connection statement, so that the first target database performs read table operations and write table operations on the target pipeline file, and the second target database performs read table operations and write table operations on the target pipeline file.
[0153] The modules in the aforementioned database statement execution device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can call and execute the operations corresponding to each module.
[0154] In one exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 9 As shown, this computer device includes a processor, memory, input / output interfaces (I / O), and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores database statement data containing control statements and SQL execution statements. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When the computer program is executed by the processor, it implements a method for executing database statements.
[0155] Those skilled in the art will understand that Figure 9 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0156] In one exemplary embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:
[0157] Based on the identification information of the target database, determine the connection object corresponding to the target database, and connect to the target database based on the connection object. The identification information of the target database is determined based on the SQL connection statement in the database statement, and the identification information corresponds one-to-one with the target database.
[0158] Based on the multiple control statements and multiple SQL execution statements contained in the database statement, a list of SQL execution statements to be executed is obtained. The control statements contain the control logic of the database statement, and the execution order of the list of SQL execution statements to be executed is determined based on the control logic of each control statement.
[0159] According to the execution order of the list of SQL statements to be executed, each SQL statement in the list is sent to the target database so that the target database can process each SQL statement, obtain the execution result set, and return the execution result set.
[0160] In one embodiment, when the processor executes the computer program, it further performs the following steps: based on a preset character recognition rule, it identifies the character information that matches the character recognition rule in the SQL connection statement, and determines that the character information is the identification information of the target database; based on a preset correspondence between the connection object and the identification information of the database, it determines the connection object corresponding to the identification information of the target database.
[0161] In one embodiment, when the processor executes the computer program, it further performs the following steps: determining the driver path corresponding to the identification information of the target database, and obtaining the database connection driver corresponding to the target database contained in the driver path; and creating a connection object corresponding to the target database through the database connection driver.
[0162] In one embodiment, when the processor executes the computer program, it further implements the following steps: adding the identification information of the target database and the connection object corresponding to the target database to a preset correspondence between the connection object and the database identification information to obtain an updated correspondence. The updated correspondence is used to determine the connection object corresponding to the target database based on the updated correspondence when connecting to the target database.
[0163] In one embodiment, when the processor executes the computer program, it further performs the following steps: based on the control logic of each control statement contained in the database statement, it adjusts the execution order and execution number of multiple SQL execution statements contained in the database statement to obtain a list of SQL execution statements to be executed containing multiple SQL execution statements.
[0164] In one embodiment, when the processor executes the computer program, it further performs the following steps: updating the parameters of the SQL execution statement according to the statement update parameters in the target parameter configuration file corresponding to the database statement, and obtaining the updated SQL execution statement.
[0165] In one embodiment, when the processor executes the computer program, it further performs the following steps: obtaining the target update parameters contained in the execution result set; updating the statement update parameters in the target parameter configuration file based on the target update parameters to obtain the updated statement update parameters.
[0166] In one embodiment, when the processor executes the computer program, it further performs the following steps: determining the login information corresponding to the target database in the target parameter configuration file based on the identification information of the target database, the target parameter configuration file containing encrypted login information; and determining the connection object corresponding to the target database based on the login information.
[0167] In one embodiment, when the processor executes the computer program, it further performs the following steps: if the identification information of the target database contains the characters for target thread, it creates a target thread; and executes database statements through the target thread.
[0168] In one embodiment, when the processor executes the computer program, it further performs the following steps: in the case of connecting to a first target database and a second target database via an SQL connection statement, determining a target pipeline file such that the first target database performs read table operations and write table operations on the target pipeline file, and the second target database performs read table operations and write table operations on the target pipeline file.
[0169] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, the computer program performing the following steps when executed by a processor:
[0170] Based on the identification information of the target database, determine the connection object corresponding to the target database, and connect to the target database based on the connection object. The identification information of the target database is determined based on the SQL connection statement in the database statement, and the identification information corresponds one-to-one with the target database.
[0171] Based on the multiple control statements and multiple SQL execution statements contained in the database statement, a list of SQL execution statements to be executed is obtained. The control statements contain the control logic of the database statement, and the execution order of the list of SQL execution statements to be executed is determined based on the control logic of each control statement.
[0172] According to the execution order of the list of SQL statements to be executed, each SQL statement in the list is sent to the target database so that the target database can process each SQL statement, obtain the execution result set, and return the execution result set.
[0173] In one embodiment, when the processor executes the computer program, it further performs the following steps: based on a preset character recognition rule, it identifies the character information that matches the character recognition rule in the SQL connection statement, and determines that the character information is the identification information of the target database; based on a preset correspondence between the connection object and the identification information of the database, it determines the connection object corresponding to the identification information of the target database.
[0174] In one embodiment, when the processor executes the computer program, it further performs the following steps: determining the driver path corresponding to the identification information of the target database, and obtaining the database connection driver corresponding to the target database contained in the driver path; and creating a connection object corresponding to the target database through the database connection driver.
[0175] In one embodiment, when the processor executes the computer program, it further implements the following steps: adding the identification information of the target database and the connection object corresponding to the target database to a preset correspondence between the connection object and the database identification information to obtain an updated correspondence. The updated correspondence is used to determine the connection object corresponding to the target database based on the updated correspondence when connecting to the target database.
[0176] In one embodiment, when the processor executes the computer program, it further performs the following steps: based on the control logic of each control statement contained in the database statement, it adjusts the execution order and execution number of multiple SQL execution statements contained in the database statement to obtain a list of SQL execution statements to be executed containing multiple SQL execution statements.
[0177] In one embodiment, when the processor executes the computer program, it further performs the following steps: updating the parameters of the SQL execution statement according to the statement update parameters in the target parameter configuration file corresponding to the database statement, and obtaining the updated SQL execution statement.
[0178] In one embodiment, when the processor executes the computer program, it further performs the following steps: obtaining the target update parameters contained in the execution result set; updating the statement update parameters in the target parameter configuration file based on the target update parameters to obtain the updated statement update parameters.
[0179] In one embodiment, when the processor executes the computer program, it further performs the following steps: determining the login information corresponding to the target database in the target parameter configuration file based on the identification information of the target database, the target parameter configuration file containing encrypted login information; and determining the connection object corresponding to the target database based on the login information.
[0180] In one embodiment, when the processor executes the computer program, it further performs the following steps: if the identification information of the target database contains the characters for target thread, it creates a target thread; and executes database statements through the target thread.
[0181] In one embodiment, when the processor executes the computer program, it further performs the following steps: in the case of connecting to a first target database and a second target database via an SQL connection statement, determining a target pipeline file such that the first target database performs read table operations and write table operations on the target pipeline file, and the second target database performs read table operations and write table operations on the target pipeline file.
[0182] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, performs the following steps:
[0183] Based on the identification information of the target database, determine the connection object corresponding to the target database, and connect to the target database based on the connection object. The identification information of the target database is determined based on the SQL connection statement in the database statement, and the identification information corresponds one-to-one with the target database.
[0184] Based on the multiple control statements and multiple SQL execution statements contained in the database statement, a list of SQL execution statements to be executed is obtained. The control statements contain the control logic of the database statement, and the execution order of the list of SQL execution statements to be executed is determined based on the control logic of each control statement.
[0185] According to the execution order of the list of SQL statements to be executed, each SQL statement in the list is sent to the target database so that the target database can process each SQL statement, obtain the execution result set, and return the execution result set.
[0186] In one embodiment, when the processor executes the computer program, it further performs the following steps: based on a preset character recognition rule, it identifies the character information that matches the character recognition rule in the SQL connection statement, and determines that the character information is the identification information of the target database; based on a preset correspondence between the connection object and the identification information of the database, it determines the connection object corresponding to the identification information of the target database.
[0187] In one embodiment, when the processor executes the computer program, it further performs the following steps: determining the driver path corresponding to the identification information of the target database, and obtaining the database connection driver corresponding to the target database contained in the driver path; and creating a connection object corresponding to the target database through the database connection driver.
[0188] In one embodiment, when the processor executes the computer program, it further implements the following steps: adding the identification information of the target database and the connection object corresponding to the target database to a preset correspondence between the connection object and the database identification information to obtain an updated correspondence. The updated correspondence is used to determine the connection object corresponding to the target database based on the updated correspondence when connecting to the target database.
[0189] In one embodiment, when the processor executes the computer program, it further performs the following steps: based on the control logic of each control statement contained in the database statement, it adjusts the execution order and execution number of multiple SQL execution statements contained in the database statement to obtain a list of SQL execution statements to be executed containing multiple SQL execution statements.
[0190] In one embodiment, when the processor executes the computer program, it further performs the following steps: updating the parameters of the SQL execution statement according to the statement update parameters in the target parameter configuration file corresponding to the database statement, and obtaining the updated SQL execution statement.
[0191] In one embodiment, when the processor executes the computer program, it further performs the following steps: obtaining the target update parameters contained in the execution result set; updating the statement update parameters in the target parameter configuration file based on the target update parameters to obtain the updated statement update parameters.
[0192] In one embodiment, when the processor executes the computer program, it further performs the following steps: determining the login information corresponding to the target database in the target parameter configuration file based on the identification information of the target database, the target parameter configuration file containing encrypted login information; and determining the connection object corresponding to the target database based on the login information.
[0193] In one embodiment, when the processor executes the computer program, it further performs the following steps: if the identification information of the target database contains the characters for target thread, it creates a target thread; and executes database statements through the target thread.
[0194] In one embodiment, when the processor executes the computer program, it further performs the following steps: in the case of connecting to a first target database and a second target database via an SQL connection statement, determining a target pipeline file such that the first target database performs read table operations and write table operations on the target pipeline file, and the second target database performs read table operations and write table operations on the target pipeline file.
[0195] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.
[0196] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments described above. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0197] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0198] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A method for executing database statements, characterized in that, The method includes: Based on the identification information of the target database, the connection object corresponding to the target database is determined, and the target database is connected based on the connection object. The identification information of the target database is determined based on the SQL connection statement in the database statement, and the identification information corresponds one-to-one with the target database. Based on the multiple control statements and multiple SQL execution statements contained in the database statement, a list of SQL execution statements to be executed is obtained. The control statements contain the control logic of the database statement, and the execution order of the list of SQL execution statements to be executed is determined based on the control logic of each control statement. According to the execution order of the list of SQL statements to be executed, each of the SQL statements in the list of SQL statements to be executed is sent to the target database so that the target database processes each of the SQL statements, obtains an execution result set, and returns the execution result set.
2. The method according to claim 1, characterized in that, The step of determining the connection object corresponding to the target database based on the identification information of the target database includes: Based on preset character recognition rules, the SQL connection statement is used to identify character information that matches the character recognition rules, and the character information is identified as the identification information of the target database. Based on the preset correspondence between the connection object and the database identification information, the connection object corresponding to the identification information of the target database is determined.
3. The method according to claim 2, characterized in that, The step of determining the connection object corresponding to the target database based on the identification information of the target database includes: Determine the driver path corresponding to the identifier information of the target database, and obtain the database connection driver corresponding to the target database contained in the driver path; The database connection driver creates a connection object corresponding to the target database.
4. The method according to claim 3, characterized in that, After creating the connection object corresponding to the target database through the database connection driver, the method further includes: The identification information of the target database and the connection object corresponding to the target database are added to the preset correspondence between the connection object and the database identification information to obtain an updated correspondence. The updated correspondence is used to determine the connection object corresponding to the target database when connecting to the target database.
5. The method according to claim 1, characterized in that, The process involves obtaining a list of SQL execution statements to be executed based on the multiple control statements and multiple SQL execution statements contained in the database statement, including: Based on the control logic of each control statement contained in the database statement, the execution order and number of executions of the multiple SQL execution statements contained in the database statement are adjusted to obtain a list of SQL execution statements to be executed containing multiple SQL execution statements.
6. The method according to claim 1, characterized in that, Before sending each of the SQL statements in the list of SQL statements to be executed to the target database according to the execution order of the list of SQL statements to be executed, the method further includes: The parameters of the SQL execution statement are updated according to the statement update parameters in the target parameter configuration file corresponding to the database statement, resulting in the updated SQL execution statement.
7. The method according to claim 6, characterized in that, The method further includes: Obtain the target update parameters contained in the execution result set; In the target parameter configuration file, the statement update parameters are updated based on the target update parameters to obtain the updated statement update parameters.
8. The method according to claim 6, characterized in that, The step of determining the connection object corresponding to the target database based on the identification information of the target database includes: Based on the identification information of the target database, the login information corresponding to the target database is determined in the target parameter configuration file, and the target parameter configuration file contains encrypted login information; The connection object corresponding to the target database is determined based on the login information.
9. The method according to claim 1, characterized in that, The method further includes: When connected to a first target database and a second target database via the SQL connection statement, a target pipeline file is determined such that the first target database performs read table operations and write table operations on the target pipeline file, and the second target database performs read table operations and write table operations on the target pipeline file.
10. A database statement execution device, characterized in that, The device includes: The database connection module is used to determine the connection object corresponding to the target database based on the identification information of the target database, and connect to the target database based on the connection object. The identification information of the target database is determined based on the SQL connection statement in the database statement, and the identification information corresponds one-to-one with the target database. The SQL statement determination module is used to obtain a list of SQL execution statements to be executed based on multiple control statements and multiple SQL execution statements contained in the database statement. The control statements contain the control logic of the database statement, and the execution order of the list of SQL execution statements to be executed is determined based on the control logic of each control statement. The SQL statement execution module is used to send each of the SQL statements in the list of SQL statements to be executed to the target database in the execution order of the list of SQL statements to be executed, so that the target database processes each of the SQL statements to obtain an execution result set and returns the execution result set.
Citation Information
Patent Citations
Database statement execution method and related device
CN110674162A
Data rollback method and device, server and readable storage medium
CN112100001A