Database operation method, device, computer equipment and readable storage medium

By receiving the execution request from the user, extracting the file path to obtain the database script, parsing the script name to identify the target database, and directly running the target script to perform data operations on the target database, solving the operation inconvenience of users frequently accessing the database in the existing technology and improving data operation efficiency.

CN114238270BActive Publication Date: 2025-06-20PING AN PAY ELECTRONIC PAYMENT CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111521344.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-13
Publication Date
2025-06-20
Estimated Expiration
2041-12-13

AI Technical Summary

Technical Problem

In the prior art, users need to frequently access multiple databases in multiple clusters and write sql statements into the database, resulting in inconvenient operation and inefficient data operation.

Method used

It provides a database operation method, which can obtain the database script by receiving execution requests from the user, extract the file path, parse the script name to identify the target database, and directly run the target script to perform data operations on the target database, simplifying the acquisition and operation process of the database script.

Benefits of technology

Database scripts can be obtained and executed without frequent access to the database by the user, which improves the efficiency of identifying and locking target libraries by the user, and improves the data operation efficiency of multiple databases for multiple clusters.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114238270B_ABST
    Figure CN114238270B_ABST
Patent Text Reader

Abstract

The present invention relates to the technical field of cloud storage, and discloses a database operation method, device, computer device and readable storage medium, including: receiving an execution request sent by a user terminal, and extracting a file path in the execution request; obtaining a database script according to the file path, and setting the database script as a target script; parsing the script name of the target script to obtain script information, identifying the database corresponding to the target script according to the script information, and setting the database as a target database; running the target script to perform data operations on the data in the target database and obtain an operation result. The present invention simplifies the process required to obtain a database script, improves the efficiency of the user terminal to identify and lock the target database, and can directly run the target script to perform data operations on the data in the target database, avoiding the problem of low data operation efficiency caused by frequent access to different databases in different clusters.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of cloud storage, and particularly to a database operation method, device, computer device and readable storage medium. Background Art

[0002] Currently, when performing DDL and DML operations in a database, it is usually necessary to write SQL statements in the database to perform the DDL or DML operations. If the data is distributed and stored in multiple databases of multiple clusters, then the user needs to first send the cluster name and IP of the database to be operated, then access the corresponding database according to the cluster name and IP, and finally perform DDL and DML operations by writing SQL statements in the database. The inventor has realized that the current database operation method makes it necessary for the user to frequently access each of the different databases in different clusters and write SQL statements in the database to complete the operation on the data in different databases of different clusters, resulting in inconvenient operation for the user and low data operation efficiency. Summary of the Invention

[0003] The purpose of the present invention is to provide a database operation method, device, computer device and readable storage medium, which are used to solve the problem in the prior art that in multiple databases of multiple clusters, the user needs to frequently access each of the databases and write SQL statements, resulting in inconvenient operation for the user and low data operation efficiency.

[0004] To achieve the above purpose, the present invention provides a database operation method, which is applied to at least one cluster, and the cluster has at least one database, including:

[0005] Receiving an execution request sent by a client, and extracting a file path in the execution request; obtaining a database script according to the file path, and setting the database script as a target script;

[0006] Analyzing the script name of the target script to obtain script information, identifying the database corresponding to the target script according to the script information, and setting the database as a target database;

[0007] Running the target script to perform data operation on the data in the target database and obtain an operation result; wherein, the data operation refers to an operation of adding, and / or deleting, and / or modifying the target database, or a carrier object in the target database, or data in the carrier object according to the SQL statement in the database script, and the carrier object is a set for storing data in the database.

[0008] In the above solution, before receiving the execution request sent by the client, the method further includes:

[0009] Receive the database script sent by the development side, perform a naming operation on the database script to obtain a script name, and construct a script library with at least one such database script; wherein, the script name reflects the attribute information of the database and its cluster, as well as the execution information and operation type of the database script.

[0010] In the above solution, before receiving the execution request sent by the user side, the method further includes:

[0011] Construct a script table with at least one such script name, send the script table to the user side, and display the script table on the user side in the form of a clickable interface.

[0012] In the above solution, the extraction of the file path in the execution request includes:

[0013] Identify the path field or path character in the execution request;

[0014] Obtain the path information corresponding to the path field or the path character, and set the path information as the file path.

[0015] In the above solution, the parsing of the script name of the target script to obtain script information, identifying the database corresponding to the target script according to the script information, and setting the database as the target library includes:

[0016] Identify the attribute characters in the script name, and obtain the attribute information corresponding to the attribute characters, wherein the attribute information includes database type, cluster name, user name, database name;

[0017] Identify the operation characters in the script name, and obtain the operation type corresponding to the operation characters, wherein the operation type refers to the file type of the database script;

[0018] Identify the execution characters in the script name, and obtain the execution information corresponding to the execution characters, wherein the execution information characterizes the number of affected rows, execution time point, execution sequence number, and execution number of the database script;

[0019] Summarize the attribute information, the operation information, and the execution information to form the script information.

[0020] In the above solution, running the target script to perform data operations on the data in the target library and obtain an operation result includes:

[0021] Obtain the script information of the database script, and extract the execution information from the script information; extract the execution sequence number, execution library name, and execution number in the execution information, and load the database script into the running process in the database corresponding to the execution library name;

[0022] Mark the database script with the execution number as the unique identifier of the database script, and sort the database scripts in the running process according to the execution sequence number to obtain a script sequence;

[0023] Execute the running process to sequentially execute the database scripts in the script sequence, so as to perform data operations on the target library corresponding to the database script and obtain an operation result.

[0024] In the above solution, after running the target script to perform data operations on the data in the target library and obtain an operation result, the method further includes:

[0025] Extract the operation type of the script information; if the operation type is a definition operation, submit the operation result to the target library; if the operation type is a processing operation, extract the execution affected row count in the script information, and determine whether the execution row count in the operation result is consistent with the execution affected row count; if they are consistent, submit the operation result to the target library; if they are inconsistent, perform a rollback operation to restore the data in the target library to the state before running the target script; wherein, the definition operation refers to operating on the target library and / or the carrier object in the target library, and the processing operation refers to operating on the data in the carrier object;

[0026] Upload the operation result to the blockchain.

[0027] To achieve the above object, the present invention also provides a database operation device, which is applied in at least one cluster, and the cluster has at least one database, including:

[0028] A script recognition module, configured to receive an execution request sent by a user terminal, extract the file path in the execution request; obtain a database script according to the file path, and set the database script as the target script;

[0029] A parsing and recognition module, configured to parse the script name of the target script to obtain script information, identify the database corresponding to the target script according to the script information, and set the database as the target library;

[0030] A script running module for running the target script to perform data operations on the data in the target library and obtain an operation result. Herein, the data operation refers to an operation of adding, and / or deleting, and / or modifying the target library, or a carrier object in the target library, or the data in the carrier object according to the SQL statement in the database script, and the carrier object is a set for storing data in the database.

[0031] To achieve the above object, the present invention further provides a computer device, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor of the computer device executes the computer program, the steps of the above database operation method are implemented.

[0032] To achieve the above object, the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program stored on the readable storage medium is executed by a processor, the steps of the above database operation method are implemented.

[0033] The database operation method, device, computer device, and readable storage medium provided by the present invention simplify the process required to obtain the database script by extracting the file path in the execution request and directly obtaining the target script according to the file path, so that the client can obtain the required database script without accessing the database. By parsing the script name of the target script to obtain script information and identifying the database corresponding to the target script according to the script information, the target library can be obtained only according to the script name, without the client accessing the target library or inputting the cluster name, username, and database name of the target library to lock the target library, improving the efficiency of the client to identify and lock the target library, which is conducive to efficiently implementing different data operations on multiple databases of multiple clusters. By directly running the target script, the data in the target library that the client needs to change can be subjected to the data operation corresponding to the target script, without the client accessing the required target library, extracting, and running the database script in the target library to obtain the operation result, resulting in the problems of low data operation efficiency, large human resources consumption, and long time consumption for the client due to frequent access to different databases of different clusters. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] Figure 1 It is a flowchart of the first embodiment of the database operation method of the present invention;

[0035] Figure 2 It is a schematic diagram of the environmental application of the database operation method in the second embodiment of the database operation method of the present invention;

[0036] Figure 3It is the specific method flowchart of the database operation method in the second embodiment of the database operation method of the present invention;

[0037] Figure 4 It is the schematic diagram of program modules of the database operation device in the third embodiment of the present invention;

[0038] Figure 5 It is the schematic diagram of the hardware structure of the computer device in the fourth embodiment of the computer device of the present invention. Detailed implementation manners

[0039] In order to make the objectives, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.

[0040] The database operation method, device, computer device and readable storage medium provided by the present invention are applicable to the technical field of cloud storage, and are used to provide a database operation method based on a script recognition module, a parsing recognition module and a script running module. The present invention receives an execution request sent by a user terminal, extracts a file path in the execution request; obtains a database script according to the file path, and sets the database script as a target script; parses a script name of the target script to obtain script information, identifies a database corresponding to the target script according to the script information, and sets the database as a target database; runs the target script to perform data operation on data in the target database and obtain an operation result.

[0041] Embodiment 1:

[0042] Please refer to Figure 1 , a database operation method in this embodiment, is applied to at least one cluster, and the cluster has at least one database, including:

[0043] S103: Receive an execution request sent by a user terminal, extract a file path in the execution request; obtain a database script according to the file path, and set the database script as a target script;

[0044] S104: Parse a script name of the target script to obtain script information, identify a database corresponding to the target script according to the script information, and set the database as a target database;

[0045] S105: Run the target script to perform data operations on the data in the target library and obtain an operation result. Herein, the data operation refers to an operation of adding, and / or deleting, and / or modifying the target library, or the carrier objects in the target library, or the data in the carrier objects according to the SQL statements in the database script, and the carrier object is a set used to store data in the database.

[0046] In an exemplary embodiment, by extracting the file path in the execution request and directly obtaining the target script according to the file path, the process required to obtain the database script is simplified, so that the client can obtain the required database script without accessing the database.

[0047] By parsing the script name of the target script to obtain script information, and identifying the database corresponding to the target script according to the script information, the target library can be obtained only according to the script name, without the client accessing the target library, nor the client inputting the cluster name, username, and database name of the target library to lock the target library, which improves the efficiency of the client to identify and lock the target library and is conducive to efficiently implementing different data operations on multiple databases of multiple clusters.

[0048] By directly running the target script, the data in the target library that the client needs to change can be subjected to the data operation corresponding to the target script, without the client accessing the required target library and extracting and running the database script in the target library to obtain the operation result, resulting in the problems of low data operation efficiency, large human consumption in data operation, and long time consumption for the client due to the need to frequently access different databases of different clusters.

[0049] Embodiment 2:

[0050] This embodiment is a specific application scenario of the above Embodiment 1. Through this embodiment, the method provided by the present invention can be described more clearly and specifically.

[0051] Next, taking the identification of the target script and its corresponding target library in a server running a database operation method and running the target script to perform data operations on the data in the target library as an example, the method provided in this embodiment will be specifically described. It should be noted that this embodiment is only exemplary and does not limit the scope protected by the embodiments of the present invention.

[0052] Figure 2 Schematically shows an environmental application diagram of the database operation method according to Embodiment 2 of the present application.

[0053] In an exemplary embodiment, the server 2 where the database operation method is located is connected to the development end 3 and the user end 4 through the network respectively; the server 2 can provide services through one or more networks. The network 3 can include various network devices, such as routers, switches, multiplexers, hubs, modems, bridges, repeaters, firewalls, proxy devices, and / or the like. The network 3 can include physical links, such as coaxial cable links, twisted pair cable links, fiber optic links, their combinations, and / or the like. The network can include wireless links, such as cellular links, satellite links, Wi-Fi links, and / or the like; the development end 3 and the user end 4 can be computer devices such as smart phones, tablet computers, laptop computers, desktop computers, etc.

[0054] Figure 3 FIG. 4 is a specific method flowchart of a database operation method provided by an embodiment of the present invention. The method specifically includes steps S201 to S206.

[0055] Specifically, it includes the following steps:

[0056] S201: Receive the database script sent by the development end, perform a naming operation on the database script to obtain a script name, and construct a script library having at least one of the database scripts; wherein, the script name reflects the attribute information of the database and its cluster, as well as the execution information and operation type of the database script.

[0057] To ensure that the user end can directly obtain the database script without having to access the database and then obtain the database script, which may cause the user end to frequently access each cluster and each database. In this step, a naming operation is performed on the database script to obtain a script name, and a script library having the database script is constructed, thereby constructing a script library independent of the cluster and its database, and making the database script have a unique address path in the script library. This enables the user end to perform subsequent data operations by simply retrieving the corresponding database script according to its needs, greatly simplifying the current cumbersome data operation process and improving the data operation efficiency.

[0058] Exemplarily, the naming format of the script name is:

[0059] Dbtype_clutername_databasename_SQLtype_linenumber_BEFORE_SEQ_Unifiednumber_Random string_DB execute, where

[0060] Dbtype is the database type, which is oracle or mysql;

[0061] The clutername database instance represents the cluster name and username of the target database for which the database script is executed. For example: group1, user2;

[0062] The databasename represents the target of the database script. For example: jfxtedwxdata. The SQLtype represents the SQL language type of the database script. For example, it represents DDL (data definition language) for defining operations and DML (data manipulation language) for processing operations. Among them, DDL (data definition language) is used to create, modify, and delete databases or carrier objects in the database (such as tables, views, stored procedures, triggers, indexes); DML (data manipulation language) is used to perform operations of adding, deleting, and modifying data in the tables of the database.

[0063] The linenumber represents the number of lines of code executed by the database script. For example: 10 lines;

[0064] The BEFORE execution time point represents that the execution is completed before a certain time point. For example: The execution is completed before 2 o'clock every day: Calendar.HOUR_OF_DAY, 2;

[0065] The SEQ execution sequence number represents the execution sequence of the database script. For example: SEQ1;

[0066] The Unified number represents the unified execution number to which the database script belongs. For example: 302134;

[0067] The Random string is a randomly generated string used to ensure the uniqueness of the data script. For example: ojefdg;

[0068] The DB execute represents the name of the database where the database script is executed (DB, full English name: data base). For example: The database named pafba.

[0069] If the database type of the database script is oracle, the database instance is group1user2, the database name is jfxtedwxdata, the file type is DDL, and the number of affected rows for execution is 10 rows; it needs to be completed before 2 o'clock every day: Calendar.HOUR_OF_DAY, 2; the execution sequence number is SEQ1, the unified execution number is 302134, the randomly generated string is ojefdg, and the execution library name is pafba; then, the script name will be obtained: Oracle_group1user2_jfxtedwxdata_DDL_10_Calendar.HOUR_OF_DAY,2_SEQ1_302134_ojefdg_pafba.sql.

[0070] Based on the above example, the content of the database script is an sql statement, for example:

[0071] create database dearabao;

[0072] use dearabao;

[0073] create table niuzi(name varchar(20));

[0074] Save the database script in the hello world directory of script library F, so the path of this file is: F:\hello world\Oracle_group1user2_jfxtedwxdata_DDL_10_Calendar.HOUR_OF_DAY,2_SEQ1_302134_ojefdg_pafba.sql.

[0075] In a preferred embodiment, building at least one database script in the database and naming the database script to obtain a script name includes:

[0076] S11: Receive the script package sent by the development end, and extract the attribute information and the database script in the script package. Among them, the attribute information describes the database type of the database script execution library name, the cluster name of the cluster where the database is located, and the database name and user name of the database.

[0077] S12: Extract the operation type and execution information in the database script. Among them, the operation type refers to the file type of the database script, and the execution information represents the number of affected rows for execution, the execution time point, the execution sequence number, and the execution number.

[0078] S13: Extract the characters in the database script and summarize the characters to form a string.

[0079] S14: Summarize the attribute information, operation type, execution information, and the string to form the script name of the database script.

[0080] Specifically, obtain the naming format of the script name, which is used to define the positions of each field in the attribute information, operation type, execution information, and the string in the script name. Among them, the first position is the database type, that is: Dbtype is; the second position is the database instance, that is: clutername; the third position is the database name, that is: databasename; the fourth position is the file type, that is: SQLtype; the fifth position is the number of affected rows in execution, that is: linenumber; the sixth position is the execution time point, that is: BEFORE; the seventh position is the execution sequence number, that is: SEQ; the eighth position is the execution number, that is: Unified number; the ninth position is a randomly generated string, that is: Random string; the tenth position is the execution database name, that is: DB execute; therefore, arrange the database type, database type database instance, database name, file type, number of affected rows in execution, execution time point, execution sequence number, execution number, string, and execution database name according to the naming format to obtain the script name.

[0081] S202: Construct a script table with at least one such script name, send the script table to the client, and display the script table on the client in the form of a clickable interface.

[0082] In this step, by sending a script table displayed in the form of a clickable interface to the client, it is convenient for the client to select the required database script. The client generates an execution request with the script name by selecting the script name in the clickable interface, and thus there is no need for the client to enter a character-rich execution request, improving the efficiency of the client in selecting database scripts.

[0083] In this embodiment, a radio box and / or a check box corresponding to the script name will be added before the script name to facilitate the client to select the required database script; or a drop-down box is set in the clickable interface, and the script name is recorded in the drop-down box, so as to facilitate the client to select the database script by clicking the script name in the drop-down box, achieving the technical effect of selecting the database script.

[0084] S203: Receive the execution request sent by the client, extract the file path in the execution request; obtain the database script according to the file path, and set the database script as the target script.

[0085] To obtain the database script required by the client without accessing the database, this step simplifies the process of obtaining the database script by extracting the file path in the execution request and directly obtaining the target script according to the file path.

[0086] In a preferred embodiment, the extracting the file path in the execution request includes:

[0087] S31: Identify the path field or path character in the execution request;

[0088] S32: Obtain the path information corresponding to the path field or the path character, and set the path information as the file path.

[0089] Specifically, the execution request can be http request information or a command line input by the client in the sql command window;

[0090] If the execution request is http request information, for example: "path:F:\hello world\Oracle_group1user2_jfxtedwxdata_DDL_10_Calendar.HOUR_OF_DAY,2_SEQ1_302134_ojefdg_pafba.sql"; then, through a preset regular expression, identify the path field in the http request message, for example: "PATH"; extract the path information "F:\hello world\Oracle_group1user2_jfxtedwxdata_DDL_10_Calendar.HOUR_OF_DAY,2_SEQ1_302134_ojefdg_pafba.sql" corresponding to the path field, and set it as the file path; where the regular expression records the path field.

[0091] If the execution request is the command line, <F:\hello world\Oracle_group1user2_jfxtedwxdata_DDL_10_Calendar.HOUR_OF_DAY,2_SEQ1_302134_ojefdg_pafba.sql; identify the address character in the command line, for example: "<", to obtain the path information "F:\hello world\Oracle_group1user2_jfxtedwxdata_DDL_10_Calendar.HOUR_OF_DAY,2_SEQ1_302134_ojefdg_pafba.sql", and set it as the file path.

[0092] S204: Parse the script name of the target script to obtain script information, identify the database corresponding to the target script according to the script information, and set the database as the target database.

[0093] To accurately execute the obtained database script in the target database, this step parses the script name of the target script to obtain script information, identifies the database corresponding to the target script according to the script information, and only needs to obtain the target database according to the script name, without the client accessing the target database, nor the client inputting the cluster name, username, and database name of the target database to lock the target database, improving the efficiency of the client to identify and lock the target database, which is conducive to efficiently implementing different data operations on multiple databases of multiple clusters.

[0094] In a preferred embodiment, the parsing the script name of the target script to obtain script information, identifying the database corresponding to the target script according to the script information, and setting the database as the target database includes:

[0095] S41: Identify the attribute characters in the script name, and obtain the attribute information corresponding to the attribute characters, where the attribute information includes database type, cluster name, username, and database name;

[0096] S42: Identify the operation characters in the script name, and obtain the operation type corresponding to the operation characters, where the operation type refers to the file type of the database script;

[0097] S43: Identify the execution characters in the script name, and obtain the execution information corresponding to the execution characters, where the execution information represents the number of affected rows, execution time point, execution sequence number, and execution number of the database script.

[0098] S44: Summarize the attribute information, the operation information, and the execution information to form the script information.

[0099] Specifically, extract the fields in the first, second, and third positions of the script name, and summarize to obtain the attribute information; extract the field in the fourth position of the script name to obtain the operation type; extract the fields in the fifth, sixth, seventh, eighth, and tenth positions of the script name, and summarize to obtain the execution information; extract the field in the ninth position of the script name to obtain the string.

[0100] In a preferred embodiment, the identifying the database corresponding to the target script according to the script information, and setting the database as the target database includes:

[0101] S45: Identify the cluster corresponding to the cluster name in the script information, and set the cluster corresponding to the database type in the cluster corresponding to the cluster name as the target cluster;

[0102] S46: Identify the database corresponding to the user name in the script information in the target cluster, set the database as the user database, and set the user database corresponding to the database name in the script information as the target database.

[0103] It should be noted that currently, the method of traversing each cluster and each database in each cluster according to the database name is usually adopted to obtain the database corresponding to the database name. However, when the number of clusters and the number of databases in each cluster are very large, the problem of low efficiency in obtaining the target database will occur due to traversing the database name. In this embodiment, the method of identifying the cluster corresponding to the cluster name in the script information and setting the cluster corresponding to the database type in the cluster corresponding to the cluster name as the target cluster is adopted to accurately lock the applicable cluster of the database script; by identifying the database corresponding to the user name in the script information in the target cluster, setting the database as the user database, and setting the user database corresponding to the database name in the script information as the target database, the target database is accurately locked. Therefore, for a script with a specific operation method, this step can accurately obtain the target database that matches it among a large number of clusters and databases. Also, because the method of obtaining the target database adopts the order of comparing the cluster name, database type, user name, and database name in sequence, each check only consumes less computing power and can quickly obtain the required result. Through the method of four quick check and match, the technical effect of reducing computing power consumption and improving the efficiency of obtaining the target database is achieved.

[0104] S205: Run the target script to perform data operations on the data in the target database and obtain an operation result; wherein, the data operation refers to an operation of adding, and / or deleting, and / or modifying the target database, or the carrier object in the target database, or the data in the carrier object according to the sql statement in the database script, and the carrier object is a set used to store data in the database.

[0105] In this step, by directly running the target script, the data operation corresponding to the target script can be performed on the data in the target database that the user side needs to change, without the need for the user side to access the target database it needs, extract and run the database script in the target database to obtain the operation result, which causes the problems of low data operation efficiency, large human resources consumption for data operation, and long time consumption for the user side due to frequent access to different databases in different clusters.

[0106] In a preferred embodiment, the running of the target script to perform data operations on the data in the target library and obtain operation results includes:

[0107] S51: Acquire script information of the database script, extract execution information from the script information; extract the execution sequence number, execution library name and execution number in the execution information, and load the database script into the running process in the database corresponding to the execution library name.

[0108] In this step, a process is a running activity of a program in a computer on a certain data set, is the basic unit for resource allocation and scheduling of the system, and is the basis of the operating system structure. The running process is a process preset in the database corresponding to the execution library name, which is used to allocate resources for the database script and execute the database script.

[0109] S52: marking the database script with the execution number as a unique identifier of the database script, and sorting the database scripts in the running process according to the execution sequence number to obtain a script sequence;

[0110] In this step, the execution number is used to identify the database script, so that the user end and the development end can manage the database script in the running process; there is at least one database script in the running process, and the database scripts are sorted according to the execution sequence number to determine the sequence of the database scripts.

[0111] S53: Execute the running process to sequentially execute the database scripts in the script sequence to perform data operations on the target library corresponding to the database scripts and obtain operation results.

[0112] Furthermore, if an error occurs during the execution of the database script, a rollback operation is performed on the target library corresponding to the database script (for example, using a rollback function) to restore the target library, or the carrier object in the target library, or the data in the carrier object to the state before the execution of the priority script.

[0113] In a preferred embodiment, after sorting the database scripts in the running process according to the execution sequence number to obtain a script sequence, the method further includes:

[0114] S54: Extract the execution time point from the execution information, calculate the time difference between the execution time point and the current time, and determine the priority of the database scripts in the script sequence according to the time difference; wherein, if the time difference is not greater than a preset time threshold, it is determined that the priority is the first level, and if the time difference is greater than the time threshold, it is determined that the priority is the second level;

[0115] In this step, the current time is obtained in real time through a preset time module (such as: clock function or component), and the time difference between the execution time point and the current time is calculated through the time module.

[0116] If the time difference is negative or zero, it means that the current time has exceeded the execution time point. Therefore, it is determined that the database script corresponding to the execution time point is an expired script, and the expired script is deleted from the running process.

[0117] If the time difference is positive, it is judged whether the time difference is greater than the time threshold. If so, it means that the database script corresponding to the time difference has a long remaining running time. Therefore, its priority is set to the second level. If not, it means that the database script corresponding to the time difference does not have enough remaining running time. Therefore, its priority is set to the first level.

[0118] S55: Open a priority branch process in the running process, set the database scripts with the first-level priority as priority scripts, and enter the priority scripts into the priority branch process;

[0119] Since the remaining running time of the database scripts at the first level is insufficient, in order to ensure that these database scripts can be completed before the execution time point, this step opens a priority branch process in the running process through the fork function, and makes the running priority of the priority branch process higher than that of the running process to ensure that the database scripts in the priority branch process can be run in time.

[0120] S56: Extract the database scripts in the script sequence whose attribute information is the same as that of the priority scripts, and set them as associated scripts; enter the associated scripts into the priority branch process, arrange the priority scripts and the associated scripts in the priority branch process according to the execution sequence number, and execute the priority branch process to run the priority scripts and the associated scripts to perform data operations on the target library corresponding to the priority scripts and the target library corresponding to the associated scripts and obtain the operation results.

[0121] In this step, the execution condition of the priority script may be the operation result generated based on the pre - execution of other database scripts. Therefore, the database script with attribute information consistent with the priority script is used as the associated script, and then the priority script and the associated script are sorted according to the execution sequence number to ensure the complete and correct execution of the priority script.

[0122] Furthermore, if an error occurs during the execution of the priority script, a rollback operation (e.g., using the rollback function) is performed on the target library corresponding to the priority script to restore the target library, or the carrier object in the target library, or the data in the carrier object to the state before the execution of the priority script.

[0123] S206: Extract the operation type of the script information; if the operation type is a definition operation, submit the operation result to the target library; if the operation type is a processing operation, extract the number of affected rows in the execution of the script information, and determine whether the number of executed rows in the operation result is consistent with the number of affected rows; if they are consistent, submit the operation result to the target library; if they are inconsistent, perform a rollback operation to restore the data in the target library to the state before running the target script; where the definition operation refers to an operation on the target library and / or the carrier object in the target library, and the processing operation refers to an operation on the data in the carrier object.

[0124] In this step, by accessing the log information generated by running the target script, obtain the number of executed rows of the database script recorded in the log information; where the log information is generated by the running process of running the target script, the number of executed rows reflects the actual number of rows executed by the database script in the target library, and the number of executed rows is generated in real - time in the log information during the process of the running process running the target script. Among them, the definition operation is DDL (data definition language), which is used to create, modify, delete databases or carrier objects in the database (e.g., tables, views, stored procedures, triggers, indexes); the processing operation is DML (data manipulation language), which is used to perform operations of adding, deleting, and modifying data in the tables in the database.

[0125] If the operation type is a definition operation (e.g., DDL), only perform the corresponding operation on the target library and / or the carrier object, and submit the operation result to the target library through the commit function. If the operation type is a processing operation (e.g., DML), it is necessary to determine whether the actual number of executed lines of the database script is consistent with the planned number of affected execution lines in the corresponding script information of the database script; if not, it indicates that a calculation error or a running error has occurred during the execution of the database script. At this time, the generated operation data cannot be submitted to the target library. Therefore, use the rollback function to restore the data in the target library to the state before running the target script. If they are consistent, submit the operation result to the target library through the commit function.

[0126] In the Figure 3 S206 is shown by the following annotations:

[0127] S206-1: Extract the operation type of the script information;

[0128] S206-2: If the operation type is a definition operation, submit the operation result to the target library;

[0129] S206-3: If the operation type is a processing operation, extract the number of affected execution lines in the script information, and determine whether the number of executed lines in the operation result is consistent with the number of affected execution lines;

[0130] S206-4: If they are consistent, submit the operation result to the target library;

[0131] S206-5: If they are not consistent, perform a rollback operation to restore the data in the target library to the state before running the target script; where the definition operation refers to operating on the target library and / or the carrier object in the target library, and the processing operation refers to operating on the data in the carrier object.

[0132] Furthermore, upload the operation result to the blockchain.

[0133] It should be noted that corresponding summary information is obtained based on the operation result. Specifically, the summary information is obtained by hashing the operation result, for example, by using the sha256s algorithm. Uploading the summary information to the blockchain can ensure its security and fairness and transparency to users. The user device can download the summary information from the blockchain to verify whether the operation result has been tampered with. The blockchain referred to in this example is a new application mode of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, and encryption algorithm. Blockchain, in essence, is a decentralized database, a string of data blocks generated by using cryptographic methods. Each data block contains information about a batch of network transactions, which is used to verify the validity of the information (anti-counterfeiting) and generate the next block. The blockchain can include the blockchain underlying platform, the platform product service layer, and the application service layer, etc.

[0134] Embodiment Three:

[0135] Please refer to Figure 4 , a database operation device 1 of this embodiment is applied in at least one cluster. The cluster has at least one database, and includes:

[0136] A script recognition module 13, configured to receive an execution request sent by a user terminal, extract the file path in the execution request; obtain a database script according to the file path, and set the database script as a target script;

[0137] A parsing and recognition module 14, configured to parse the script name of the target script to obtain script information, identify the database corresponding to the target script according to the script information, and set the database as a target database;

[0138] A script running module 15, configured to run the target script to perform data operations on the data in the target database and obtain an operation result; wherein, the data operation refers to an operation of adding, and / or deleting, and / or modifying the target database, or a carrier object in the target database, or data in the carrier object according to the sql statement in the database script, and the carrier object is a set for storing data in the database.

[0139] Optionally, the database operation device 1 further includes:

[0140] A library construction module 11, configured to receive a database script sent by a development terminal, perform a naming operation on the database script to obtain a script name, and construct a script library having at least one of the database scripts; wherein, the script name reflects the attribute information of the database and its cluster, as well as the execution information and operation type of the database script.

[0141] Optionally, the library construction module 11 further includes:

[0142] An attribute extraction unit 111, configured to receive a script package sent by a development end, and extract attribute information and a database script from the script package, where the attribute information describes a database type of a database name of the database script execution library, a cluster name of a cluster where the database is located, and a database name and a user name of the database.

[0143] An information extraction unit 112, configured to extract an operation type and execution information from the database script, where the operation type refers to a file type of the database script, and the execution information represents the number of affected rows executed, the execution time point, the execution sequence number, and the execution number.

[0144] A character extraction unit 113, configured to extract characters from the database script, and summarize the characters to form a character string.

[0145] A name construction unit 114, configured to summarize the attribute information, the operation type, the execution information, and the character string to form a script name of the database script.

[0146] Optionally, the database operation device 1 further includes:

[0147] A table construction module 12, configured to construct a script table having at least one of the script names, send the script table to the user end, and display the script table on the user end in the form of a clickable interface.

[0148] Optionally, the script recognition module 13 further includes:

[0149] A path recognition unit 131, configured to recognize a path field or a path character in the execution request;

[0150] A path confirmation unit 132, configured to obtain path information corresponding to the path field or the path character, and set the path information as the file path.

[0151] Optionally, the parsing recognition module 14 further includes:

[0152] An attribute recognition unit 141, configured to recognize an attribute character in the script name, and obtain attribute information corresponding to the attribute character, where the attribute information includes a database type, a cluster name, a user name, and a database name;

[0153] A type recognition unit 142, configured to recognize an operation character in the script name, and obtain an operation type corresponding to the operation character, where the operation type refers to a file type of the database script;

[0154] An execution recognition unit 143, configured to recognize execution characters in the script name, and obtain execution information corresponding to the execution characters, where the execution information represents the number of affected rows, execution time point, execution sequence number, and execution number of the database script;

[0155] An information summarization unit 144, configured to summarize the attribute information, the operation information, and the execution information to form the script information;

[0156] A cluster recognition unit 145, configured to recognize the cluster corresponding to the cluster name in the script information, and set the cluster corresponding to the database type in the cluster corresponding to the cluster name as the target cluster;

[0157] A library recognition unit 146, configured to recognize the database corresponding to the user name in the script information in the target cluster, and set the database as the user database, and set the user database corresponding to the database name in the script information as the target library.

[0158] Optionally, the script running module 15 further includes:

[0159] A running preparation unit 151, configured to obtain the script information of the database script, and extract execution information from the script information; extract the execution sequence number, execution library name, and execution number in the execution information, and load the database script into the running process in the database corresponding to the execution library name;

[0160] A marking and sorting unit 152, configured to mark the database script with the execution number as the unique identifier of the database script, and sort the database scripts in the running process according to the execution sequence number to obtain a script sequence;

[0161] A process execution unit 153, configured to execute the running process to sequentially execute the database scripts in the script sequence, so as to perform data operations on the target library corresponding to the database script and obtain an operation result;

[0162] A priority management unit 154, configured to extract the execution time point in the execution information, calculate the time difference between the execution time point and the current time, and determine the priority of the database scripts in the script sequence according to the time difference; where, if the time difference is not greater than a preset time threshold, it is determined that the priority is the first level, and if the time difference is greater than the time threshold, it is determined that the priority is the second level;

[0163] A priority preparation unit 155, configured to start a priority branch process in the running process, set the database scripts with the first-level priority as priority scripts, and enter the priority scripts into the priority branch process;

[0164] A priority execution unit 156 is configured to extract database scripts in the script sequence whose attribute information is consistent with the priority script, and set them as associated scripts; enter the associated scripts into the priority branch process, arrange the priority scripts and the associated scripts in the priority branch process according to the execution sequence numbers, and execute the priority branch process to run the priority scripts and the associated scripts, so as to perform data operations on the target library corresponding to the priority script and the target library corresponding to the associated script and obtain operation results.

[0165] Optionally, the database operation device 1 further includes:

[0166] An operation processing unit 16 is configured to extract the operation type of the script information; if the operation type is a definition operation, submit the operation result to the target library; if the operation type is a processing operation, extract the number of affected rows of execution in the script information, and determine whether the number of executed rows in the operation result is consistent with the number of affected rows of execution; if they are consistent, submit the operation result to the target library; if they are inconsistent, perform a rollback operation to restore the data in the target library to the state before running the target script; wherein, the definition operation refers to operating on the target library and / or the carrier object in the target library, and the processing operation refers to operating on the data in the carrier object.

[0167] This technical solution can be applied in the field of cloud storage technology of cloud technology. By extracting the file path in the execution request, obtaining a database script according to the file path, setting the database script as a target script, parsing the script name of the target script to obtain script information, identifying the database corresponding to the target script in a cluster for distributed storage of data according to the script information, and setting the database as a target library, running the target script to perform data operations on the data in the target library and obtain operation results; wherein, the target script can be a computer script for performing data operations on the data based on metadata management technology, and the metadata management includes the development of business glossaries, the definition of data elements and entities, business rules and algorithms, and data characteristics.

[0168] Embodiment 4:

[0169] To achieve the above object, the present invention further provides a computer device 5. The components of the database operation device in Embodiment 3 can be distributed in different computer devices. The computer device 5 can be a smart phone, a tablet computer, a notebook computer, a desktop computer, a rack-mounted server, a blade server, a tower server, or a cabinet server (including an independent server or a server cluster composed of multiple application servers) that executes a program. The computer device in this embodiment at least includes, but is not limited to, a memory 51 and a processor 52 that can communicate with each other through a system bus, as Figure 5 shown. It should be noted that Figure 5 only a computer device with components - is shown, but it should be understood that it is not required to implement all the shown components, and more or fewer components can be alternatively implemented.

[0170] In this embodiment, the memory 51 (i.e., the readable storage medium) includes flash memory, a hard disk, a multimedia card, a card-type memory (e.g., SD or DX memory, etc.), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the memory 51 can be an internal storage unit of the computer device, such as the hard disk or memory of the computer device. In other embodiments, the memory 51 can also be an external storage device of the computer device, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, etc., equipped on the computer device. Of course, the memory 51 can also include both the internal storage unit and the external storage device of the computer device. In this embodiment, the memory 51 is generally used to store the operating system and various application software installed in the computer device, such as the program code of the database operation device in Embodiment 3. In addition, the memory 51 can also be used to temporarily store various data that have been output or will be output.

[0171] In some embodiments, the processor 52 can be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips. The processor 52 is generally used to control the overall operation of the computer device. In this embodiment, the processor 52 is used to run the program code stored in the memory 51 or process data, such as running the database operation device to implement the database operation methods in Embodiment 1 and Embodiment 2.

[0172] Embodiment 5:

[0173] To achieve the above object, the present invention further provides a computer-readable storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory (e.g., SD or DX memory, etc.), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a magnetic disk, an optical disk, a server, an App application store, etc., on which a computer program is stored, and when the program is executed by the processor 52, the corresponding functions are realized. The computer-readable storage medium of this embodiment is used to store the computer program for implementing the database operation method, and when executed by the processor 52, it realizes the database operation methods of Embodiment 1 and Embodiment 2.

[0174] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages and disadvantages of the embodiments.

[0175] Through the description of the above embodiments, those skilled in the art can clearly understand that the above embodiment methods can be implemented by means of software plus a necessary general hardware platform. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method.

[0176] The above are only the preferred embodiments of the present invention, and do not limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made by using the content of the specification and drawings of the present invention, or directly or indirectly applied in other related technical fields, shall be equally included in the patent protection scope of the present invention.

Claims

1. A database operation method, applied in at least one cluster, where the cluster has at least one database, characterized in that, Including: Receiving a database script sent by a development end, naming the database script to obtain a script name, and constructing a script library having at least one of the database scripts; wherein, the script name reflects attribute information of the database and its cluster, as well as execution information and operation type of the database script; Constructing a script table having at least one of the script names, sending the script table to a user end, and enabling the script table to be displayed in the form of a clickable interface on the user end; Receiving an execution request sent by the user end, and extracting a file path in the execution request; obtaining a database script according to the file path, and setting the database script as a target script; Parsing the script name of the target script to obtain script information, identifying a database corresponding to the target script according to the script information, and setting the database as a target database; wherein, including: identifying attribute characters in the script name, obtaining attribute information corresponding to the attribute characters, wherein the attribute information includes database type, cluster name, user name, database name; identifying operation characters in the script name, obtaining an operation type corresponding to the operation characters, wherein the operation type refers to a file type of the database script; identifying execution characters in the script name, obtaining execution information corresponding to the execution characters, wherein the execution information characterizes the number of affected rows, execution time point, execution sequence number, and execution number of the database script; summarizing the attribute information, the operation type, and the execution information to form the script information; identifying a cluster corresponding to the cluster name in the script information, and setting a cluster corresponding to the database type in the cluster corresponding to the cluster name as a target cluster; identifying a database corresponding to the user name in the script information in the target cluster, and setting the database as a user database, and setting the user database corresponding to the database name in the script information as a target database; Running the target script to perform a data operation on data in the target database and obtain an operation result; wherein, the data operation refers to an operation of adding, and / or deleting, and / or modifying the target database, or a carrier object in the target database, or data in the carrier object according to an SQL statement in the database script, and the carrier object is a set for storing data in the database.

2. The database operation method according to claim 1, characterized in that, The extracting the file path in the execution request includes: Identifying a path field or a path character in the execution request; Obtaining path information corresponding to the path field or the path character, and setting the path information as the file path.

3. The database operation method according to claim 1, characterized in that, The running the target script to perform a data operation on data in the target database and obtain an operation result includes: Obtaining script information of the database script, and extracting execution information from the script information; extracting the execution sequence number, execution database name, and execution number in the execution information, and loading the database script into a running process in the database corresponding to the execution database name; Annotate the database script with the execution number as the unique identifier of the database script, and sort the database scripts in the running process according to the execution sequence number to obtain a script sequence; Execute the running process to sequentially execute the database scripts in the script sequence to perform data operations on the target library corresponding to the database script and obtain an operation result.

4. The database operation method according to claim 1, characterized in that, After running the target script to perform data operations on the data in the target library and obtain an operation result, the method further includes: Extract the operation type of the script information; if the operation type is a definition operation, submit the operation result to the target library; if the operation type is a processing operation, extract the number of affected rows in the execution of the script information, and determine whether the number of executed rows in the operation result is consistent with the number of affected rows in the execution; if they are consistent, submit the operation result to the target library; if they are inconsistent, perform a rollback operation to restore the data in the target library to the state before running the target script; where the definition operation refers to operating on the target library and / or the carrier object in the target library, and the processing operation refers to operating on the data in the carrier object; Upload the operation result to the blockchain.

5. A database operation device, applied in at least one cluster, where the cluster has at least one database, characterized in that, It includes: A library construction module for receiving a database script sent by a development end, naming the database script to obtain a script name, and constructing a script library having at least one of the database scripts; where the script name reflects the attribute information of the database and its cluster, as well as the execution information and operation type of the database script; A table construction module for constructing a script table having at least one of the script names, sending the script table to the user end, and displaying the script table in the form of a clickable interface on the user end; A script recognition module for receiving an execution request sent by the user end, extracting the file path in the execution request; obtaining a database script according to the file path, and setting the database script as the target script; A parsing and recognition module for parsing the script name of the target script to obtain script information, identifying the database corresponding to the target script according to the script information, and setting the database as the target library; A script running module for running the target script to perform data operations on the data in the target library and obtain an operation result; where the data operation refers to an operation of adding, and / or deleting, and / or modifying the target library, or the carrier object in the target library, or the data in the carrier object according to the sql statement in the database script, and the carrier object is a set for storing data in the database; The parsing and recognition module includes: An attribute recognition unit for recognizing the attribute characters in the script name and obtaining the attribute information corresponding to the attribute characters, where the attribute information includes database type, cluster name, user name, and database name; A type recognition unit for recognizing operation characters in the script name and obtaining an operation type corresponding to the operation characters, where the operation type refers to the file type of the database script; An execution recognition unit for recognizing execution characters in the script name and obtaining execution information corresponding to the execution characters, where the execution information characterizes the number of affected rows, execution time point, execution sequence number, and execution number of the database script; An information summarization unit for summarizing the attribute information, the operation type, and the execution information to form the script information; A cluster recognition unit for recognizing the cluster corresponding to the cluster name in the script information and setting the cluster corresponding to the database type in the cluster corresponding to the cluster name as the target cluster; A database recognition unit for recognizing the database corresponding to the user name in the script information in the target cluster, setting the database as the user database, and setting the user database corresponding to the database name in the script information as the target database.

6. A computer device, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor of the computer device executes the computer program, the steps of the database operation method according to any one of claims 1 to 4 are implemented.

7. A computer-readable storage medium, on which a computer program is stored, characterized in that, When the computer program stored in the readable storage medium is executed by the processor, the steps of the database operation method according to any one of claims 1 to 4 are implemented.

Citation Information

Patent Citations

  • Database script management method, device, computer device, and storage medium

    CN109308285A

  • Method, apparatus and device for accessing database, and computer-readable storage medium

    WO2021051614A1