CN112866348B - Database access method and device, computer equipment and storage medium - Google Patents

Database access method and device, computer equipment and storage medium Download PDF

Info

Publication number
CN112866348B
CN112866348B CN202011637495.0A CN202011637495A CN112866348B CN 112866348 B CN112866348 B CN 112866348B CN 202011637495 A CN202011637495 A CN 202011637495A CN 112866348 B CN112866348 B CN 112866348B
Authority
CN
China
Prior art keywords
database
access
target
target database
statement
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202011637495.0A
Other languages
Chinese (zh)
Other versions
CN112866348A (en
Inventor
郑政芳
王宏
李坤镇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Kingdee Software China Co Ltd
Original Assignee
Kingdee Software China Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Kingdee Software China Co Ltd filed Critical Kingdee Software China Co Ltd
Priority to CN202011637495.0A priority Critical patent/CN112866348B/en
Publication of CN112866348A publication Critical patent/CN112866348A/en
Application granted granted Critical
Publication of CN112866348B publication Critical patent/CN112866348B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/60Scheduling or organising the servicing of application requests, e.g. requests for application data transmissions using the analysis and optimisation of the required network resources
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages

Abstract

The application relates to a database access method, a database access device, computer equipment and a storage medium. The method comprises the following steps: acquiring a first database access request sent by a first access terminal, wherein a first database access statement corresponding to the first database access request is compiled by adopting a preset database language corresponding to the unified access agent equipment; obtaining a target database routing parameter from the first database access request, and determining a corresponding target database according to the target database routing parameter; acquiring a target database language corresponding to the target database; converting the first database access statement into a second database access statement corresponding to the target database language; and sending a second database access statement to the target database, so that the target database performs data processing based on the second database access statement to obtain a database access result. By adopting the method, the access efficiency of the database can be improved.

Description

Database access method and device, computer equipment and storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a database access method and apparatus, a computer device, and a storage medium.
Background
With the development of computer technology, more and more data need to be stored in a computer, so that a database capable of storing data is more and more important. A database is a repository that organizes, stores, and manages data according to a data structure, which is an organized, shareable, and uniformly manageable collection of large amounts of data that is stored long term in a computer. There are many types of databases, such as MySQL, oracle, postgreSQL, or dam, etc., each having its own features and advantages. Generally, operations such as storing data in a database, reading data from a database, or deleting unnecessary data in a database can be realized by accessing the database.
However, the current database access method has the problem of low database access efficiency for the scenes needing to access various types of databases.
Disclosure of Invention
In view of the foregoing, it is desirable to provide a database access method, an apparatus, a computer device, and a storage medium capable of improving database access efficiency.
A database access method, the method comprising: acquiring a first database access request sent by a first access terminal, wherein a first database access statement corresponding to the first database access request is compiled by adopting a preset database language corresponding to the unified access agent equipment; obtaining a target database routing parameter from the first database access request, and determining a corresponding target database according to the target database routing parameter; acquiring a target database language corresponding to the target database; converting the first database access statement into a second database access statement corresponding to the target database language; and sending the second database access statement to the target database, so that the target database performs data processing based on the second database access statement to obtain a database access result.
In one embodiment, the method further comprises: responding to the first database access request, and establishing virtual database connection with the access terminal; obtaining the database access result returned by the target database; and returning the database access result to the first access terminal through the virtual database link.
In one embodiment, the obtaining the database access result returned by the target database includes: acquiring a database access result sent by the target database through a preset data transmission format; and storing the database access result to the local in a character string form.
In one embodiment, the sending the second database access statement to the target database includes: acquiring the established network connection between the unified access proxy equipment and the target database according to the connection information in the database connection pool; and sending the second database access statement to the target database through the established network connection.
In one embodiment, the method further comprises: receiving a second database access request sent by the second access terminal, wherein the second database access request carries the target database routing parameters; establishing a network connection with the target database in response to the second database access request; and adding the target connection information corresponding to the established network connection into the database connection pool, wherein the target connection information comprises a connection identifier corresponding to the network connection and a database identifier corresponding to the target database.
In one embodiment, the obtaining of the established network connection between the unified access proxy device and the target database according to the connection information in the database connection pool includes: acquiring a database identifier of the target database; and acquiring a connection identifier corresponding to the database identifier from the database connection pool, and taking the network connection corresponding to the connection identifier as the established network connection.
In one embodiment, the sending the second database access statement to the target database includes: acquiring a database type corresponding to the target database; acquiring driving information corresponding to the database type; initializing the target database according to the driving information, and sending the second database access statement to the target database after the target database is initialized.
In one embodiment, the obtaining the database routing parameter from the database access request, and determining the corresponding target database according to the database routing parameter includes: obtaining database routing parameters from the database access request; acquiring a corresponding target service type from a pre-stored routing parameter configuration list according to the database routing parameters; and screening the candidate database set according to the service type to obtain a target database, wherein the physical database is logically divided according to the service type to obtain the candidate database set.
A database access apparatus, the apparatus comprising: a first database access request obtaining module, configured to obtain a first database access request sent by a first access terminal, where a first database access statement corresponding to the first database access request is compiled by using a preset database language corresponding to a unified access proxy device; the target database determining module is used for acquiring a target database routing parameter from the first database access request and determining a corresponding target database according to the target database routing parameter; the target database language acquisition module is used for acquiring a target database language corresponding to the target database; a second database access statement acquisition module, configured to convert the first database access statement into a second database access statement corresponding to the target database language; and the second database access statement sending module is used for sending the second database access statement to the target database so as to enable the target database to perform data processing based on the second database access statement and obtain a database access result.
In one embodiment, the apparatus further includes a virtual database connection establishing module, configured to establish a virtual database connection with the access terminal in response to the first database access request; a database access result obtaining module, configured to obtain the database access result returned by the target database; and the database access result returning module is used for returning the database access result to the first access terminal through the virtual database link.
In one embodiment, the database access result acquiring module is configured to acquire a database access result sent by the target database through a preset data transmission format; and storing the database access result to the local in a character string form.
In one embodiment, the second database access statement sending module is configured to obtain an established network connection between the unified access agent device and the target database according to connection information in a database connection pool; sending the second database access statement to the target database through the established network connection.
In one embodiment, the apparatus further includes a second database access request receiving module, configured to receive a second database access request sent by the second access terminal, where the second database access request carries the target database routing parameter; the second database access request receiving module is used for responding to the second database access request and establishing network connection with the target database; and the target connection information adding module is used for adding the target connection information corresponding to the established network connection into the database connection pool, wherein the target connection information comprises a connection identifier corresponding to the network connection and a database identifier corresponding to the target database.
In one embodiment, the second database access statement sending module is configured to obtain a database identifier of the target database; and acquiring a connection identifier corresponding to the database identifier from the database connection pool, and taking the network connection corresponding to the connection identifier as the established network connection.
In one embodiment, the second database access statement sending module is configured to obtain a database type corresponding to the target database; acquiring driving information corresponding to the database type; initializing the target database according to the driving information, and sending the second database access statement to the target database after the target database is initialized.
In one embodiment, the target database determination module is configured to obtain a database routing parameter from the database access request; acquiring a corresponding target service type from a pre-stored routing parameter configuration list according to the database routing parameters; and screening the candidate database set according to the service type to obtain a target database, wherein the physical database is logically divided according to the service type to obtain the candidate database set.
A computer device comprising a memory storing a computer program and a processor implementing the following steps when the computer program is executed: acquiring a first database access request sent by a first access terminal, wherein a first database access statement corresponding to the first database access request is compiled by adopting a preset database language corresponding to the unified access agent equipment; obtaining a target database routing parameter from the first database access request, and determining a corresponding target database according to the target database routing parameter; acquiring a target database language corresponding to the target database; converting the first database access statement into a second database access statement corresponding to the target database language; and sending the second database access statement to the target database, so that the target database performs data processing based on the second database access statement to obtain a database access result.
A computer-readable storage medium, on which a computer program is stored which, when executed by a processor, carries out the steps of: acquiring a first database access request sent by a first access terminal, wherein a first database access statement corresponding to the first database access request is compiled by adopting a preset database language corresponding to the unified access agent equipment; obtaining a target database routing parameter from the first database access request, and determining a corresponding target database according to the target database routing parameter; acquiring a target database language corresponding to the target database; converting the first database access statement into a second database access statement corresponding to the target database language; and sending the second database access statement to the target database, so that the target database performs data processing based on the second database access statement to obtain a database access result.
According to the database access method, the database access device, the computer equipment and the storage medium, the first database access request sent by the first access terminal is obtained through the unified access proxy equipment, the target database routing parameters are obtained from the first database access request, and the corresponding target database is determined according to the target database routing parameters; acquiring a target database language corresponding to a target database; converting the first database access statement into a second database access statement corresponding to the target database language; and sending the second database access statement to the target database, so that the target database performs data processing based on the second database access statement to obtain a database access result. And writing a first database access statement corresponding to the first database access request by adopting a preset database language corresponding to the unified access agent equipment. Therefore, when the access terminal accesses the databases written by different database languages, the access terminal can access by adopting the same preset database language, and the target database to be accessed is quickly determined based on different database routing parameters, so that the aim of improving the database access efficiency can be fulfilled.
Drawings
FIG. 1 is a diagram of an application environment of a database access method in one embodiment;
FIG. 2 is a schematic flow chart diagram illustrating a database access method in one embodiment;
FIG. 3 is a schematic flow chart diagram of a database access method in another embodiment;
FIG. 4 is a flowchart illustrating the step of sending a second database access statement to the target database in one embodiment;
FIG. 5 is a schematic flow chart diagram of a database access method in another embodiment;
FIG. 6 is a flowchart illustrating the step of obtaining an established network connection between the unified access proxy device and the target database according to the connection information in the database connection pool in one embodiment;
FIG. 7 is a flowchart illustrating the step of sending a second database access statement to the target database in another embodiment;
FIG. 8 is a flowchart illustrating steps of obtaining database routing parameters from a database access request and determining a corresponding target database according to the database routing parameters, in accordance with an embodiment;
FIG. 9 is a schematic flow chart diagram illustrating a database access method in accordance with another embodiment;
FIG. 10 is a schematic flow chart diagram illustrating a database access method in accordance with another embodiment;
FIG. 11 is a schematic flow chart diagram illustrating a database access method in accordance with another embodiment;
FIG. 12 is a block diagram showing the structure of a database access device according to one embodiment;
fig. 13 is an internal structural diagram of a computer device in one embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more clearly understood, the present application is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
The database access method provided by the application can be applied to the application environment shown in fig. 1. The method is particularly applied to a database access system. The database access system includes an access terminal 102, a unified access proxy device 104, and a set of candidate databases 106. Wherein the access terminal 102, the unified access proxy device 104, and the candidate database set 106 communicate over a network. The unified access proxy device 104 is used to perform a database access method. Specifically, the unified access agent device 104 obtains a first database access request sent by the access terminal 102, and a first database access statement corresponding to the first database access request is compiled by using a preset database language corresponding to a database client on the unified access agent device 104; the unified access agent device 104 obtains a target database routing parameter from the first database access request, and determines a corresponding target database according to the target database routing parameter; acquiring a target database language corresponding to a target database; the unified access agent device 104 converts the first database access statement into a second database access statement corresponding to the target database language; and sending the second database access statement to a target database in the candidate database set 106, so that the target database performs data processing based on the second database access statement to obtain a database access result. The access terminal may be a terminal or a server, and the unified access proxy device 104 may be a server. The terminal can be, but is not limited to, various personal computers, notebook computers, smart phones, tablet computers and portable wearable devices, and the server can be implemented by an independent server or a server cluster formed by a plurality of servers.
In one embodiment, as shown in fig. 2, a database access method is provided, which is described by taking the example that the method is applied to the unified access proxy device in fig. 1, and includes the following steps:
step 202, a first database access request sent by a first access terminal is obtained, and a first database access statement corresponding to the first database access request is compiled by adopting a preset database language corresponding to the unified access proxy equipment.
The access terminal refers to a terminal or a server for accessing the database. The database access request refers to a request for performing operations such as searching, deleting, reading or upgrading on data in the database. The unified access proxy equipment refers to equipment capable of processing database access requests, and corresponding unified access proxy software is installed on the equipment. The access terminal can access different types of databases through the unified access agent device. The database Language refers to a description Language defining a data storage structure in a database, such as SQL (Structured Query Language) Language.
Specifically, when a certain access terminal needs to access a database connected to the unified access proxy device, the access terminal sends a first database access request, a destination Address of the first database access request is a network Address of the unified access proxy device, the network Address may be an IP (Internet Protocol Address) Address, and a first database access statement corresponding to the first database access request is compiled by using a preset database language corresponding to the unified access proxy device. It will be appreciated that there may be differences in the language in which the data storage structures of each type of database are described. For example, a TABLE is deleted from a MySQL-type database, and the description language is "DROP TABLE IF EXISTS TABLE name or DROP TABLE IF EXISTS TABLE name; "while the language is described as" drop table name "in an Oracle type database.
In one embodiment, the unified access agent device obtains a first database access request matched with the identity authentication information by identifying the identity authentication information of the first access terminal and a destination address bound with the identity information, where the destination address of the database access request is a network address of the local terminal of the unified access agent device.
And 204, acquiring the routing parameters of the target database from the first database access request, and determining the corresponding target database according to the routing parameters of the target database.
The target database routing parameters are used for determining the target database, and different databases have different routing parameters. Specifically, the first database access request carries a target database routing parameter, and the unified access proxy device can find a target database to be accessed by obtaining the target database routing parameter.
In one embodiment, the routing parameter may be added before a preset position in the structure description language of the first database access request, for example, the routing parameter may be added in a comment section in the structure description language of the first database access request. Meanwhile, the routing parameter may be acquired from a preset location. For example, using FI to represent routing parameters, if a table is looked up in the database, the first database access request is described in the structural description language "/. XDB:. Fl:/select top 10 from t gl. ", the corresponding target database can be determined from FI in/'XDB: fl/' of the annotation location.
Step 206, a target database language corresponding to the target database is obtained.
The target database language is a database language which can be recognized and compiled by the target database and has certain grammar rules.
Specifically, after the terminal determines the corresponding target database according to the target database routing parameter, the target database can identify and translate the first database access request by acquiring the target database language corresponding to the target database.
In an embodiment, the unified access agent device may query, according to the determined target database, a target database language corresponding to the target database from a target database language library stored at a local terminal of the unified access agent device by obtaining a locally stored target database and a corresponding relationship list of database languages corresponding to the target database. For example, if the target database is an Oracle-type database, the database language corresponding to the Oracle-type database is acquired from the target database language database stored in the home terminal of the first terminal.
Step 208, converting the first database access statement into a second database access statement corresponding to the target database language.
The database access statement refers to a program statement which accesses the database and has a certain grammar rule.
Specifically, database languages of different types of databases are different, one database access statement may be recognized or compiled in one type of database, but may not be recognized or compiled in another type of database, and when a unified database access statement is used to access different types of databases, conversion between database languages is required.
In one embodiment, the database language may be converted using a database language conversion plug-in the unified access proxy device. For example, selecting the first ten in the certificate table, the access sentence "/_ XDB: fl ×/select top 10 from t glucher where fbzdate >? "convert to Access statement in MySQL" select from t _ gl voucher where fbizdate >? And 10' of Limit.
And step 210, sending the second database access statement to the target database, so that the target database performs data processing based on the second database access statement to obtain a database access result.
The database access result refers to an execution result returned by the database based on the database access statement. For example, if the database access statement is a query data statement for the database, then the query result for the database is returned; if the database access statement is an insert data statement for the database, then the data result after the database inserts data is returned.
Specifically, after the first database access statement is converted into the second database access statement corresponding to the target database language, the second database access statement needs to be sent to the target database.
In one embodiment, the second database access statement may be converted into a data packet, and the data packet is sent to a target database, where an editor corresponding to processing the data packet is located in the target database, and the data packet may be analyzed to obtain a database access result. For example, the second database access statement is converted into a pymysql data packet, a corresponding python editor is arranged in the target database, and when the target database receives the pymysql data packet, the python editor can be used for data processing to obtain a database access result.
In the database access method, a first database access request sent by a first access terminal is obtained through a unified access proxy device, a target database routing parameter is obtained from the first database access request, and a corresponding target database is determined according to the target database routing parameter; acquiring a target database language corresponding to a target database; converting the first database access statement into a second database access statement corresponding to the target database language; and sending the second database access statement to the target database, so that the target database performs data processing based on the second database access statement to obtain a database access result. And writing a first database access statement corresponding to the first database access request by adopting a preset database language corresponding to the unified access agent equipment. Therefore, when the access terminal accesses the databases written by different database languages, the access terminal can access by adopting the same preset database language, and the target database to be accessed is quickly determined based on different database routing parameters, so that the aim of improving the database access efficiency can be fulfilled.
In one embodiment, as shown in fig. 3, the database access method further comprises:
step 302, responding to the first database access request, and establishing a virtual database connection with the access terminal.
The virtual database connection refers to the database connection established by the access terminal and the unified access proxy equipment through the network address, and is not a real database directly connected through the access terminal.
Specifically, when the access terminal sends an access request to the unified access proxy device, the unified access proxy device responds to the request and establishes a virtual database connection with the access terminal.
In one embodiment, the unified access proxy device determines the validity of the first database access request by judging the authentication credential carried in the first database access request and the time limit of the authentication credential, and if the authentication credential and the time limit of the authentication credential both pass, authorizes the first database access request and establishes virtual database connection with the access terminal.
And step 304, obtaining a database access result returned by the target database.
Specifically, when the unified access agent device is connected with the access terminal, after the target database executes the access statement corresponding to the first database access request, the executed database access result is sent to the unified access agent device, and the corresponding unified access agent device obtains the database access result returned by the target database.
In an embodiment, when the number of the databases to be accessed by the access terminal is at least one, the unified access proxy device sends the database access result to the corresponding access terminal after obtaining each database access result.
In one embodiment, the unified access agent device may obtain the database access result returned by the target database after a preset time period after responding to the first database access request. And if the database access result is not obtained after the preset time period, carrying out reacquisition operation. For example, after 60S of responding to the first database access request, the database access result returned by the target database is obtained, and if the database access result is not obtained after 60S, the unified access proxy device may perform a reacquisition operation.
And step 306, returning the database access result to the first access terminal through the virtual database connection.
Specifically, after the unified access proxy device obtains the database access result, the database access result is transmitted to the first access terminal having a connection relationship with the local terminal and the virtual database.
In one embodiment, when the number of the access terminals is at least one, the virtual database connection may correspond to a corresponding connection identifier, and through a relationship between the connection identifier and the access terminal, it may be determined to return a database access result to the access terminal corresponding to the connection identifier.
In this embodiment, the unified access proxy device establishes a virtual database connection with the access terminal, and the database access result returned by the target database acquired by the unified access proxy device can be returned to the first access terminal through the virtual database connection, so that the purpose of establishing a connection relationship between the access terminal and the target database through the unified access proxy device can be achieved.
In one embodiment, obtaining the database access result returned by the target database comprises: acquiring a database access result sent by a target database through a preset format;
the preset format refers to a preset data transmission format. For example, json (JavaScript Object Notification) format, XML (eXtensible Markup Language) format, YAML (Yet antenna Markup Language) format, or the like.
Specifically, in order to facilitate reading and writing and save the storage space of the unified access proxy device, the database access result sent by the target database needs to be acquired in a certain transmission format.
In one embodiment, the database access result sent by the target database is obtained in a Json format, and the access terminal can obtain the database access result sent by the target database through an eval () function in a JavaScript script.
In one embodiment, after the unified access proxy device obtains the database access result, the database access result is stored locally in a character string form. Therefore, when the access terminal carries out a database access request corresponding to the database access result, the database access result in the unified access proxy equipment is directly called, and the access efficiency of the target database is improved.
In one embodiment, as shown in FIG. 4, sending the second database access statement to the target database comprises:
step 402, obtaining the established network connection between the unified access proxy device and the target database according to the connection information in the database connection pool.
The database connection pool is a storage area for storing database connection in the unified access proxy equipment. When the user needs to access the database, an established free connection object can be taken out from the connection pool. After the use is finished, the connection is placed back into the connection pool for the next access request.
Specifically, in order to obtain a faster access response speed, the established network connection between the unified access proxy device and the target database may be directly obtained in the database connection pool without re-establishing the connection.
In one embodiment, the established network Connection in the Database Connection Pool may be obtained in a DBCP (Database Connection Pool) manner.
Step 404, sending the second database access statement to the target database through the established network connection.
Specifically, after the unified access agent device establishes a network connection with the target database, the second database access statement may be sent to the target database.
In one embodiment, the second database access statement may be edited, the driving information of the target database is acquired, and after the target database is initialized, the edited second database access statement is sent to the target database.
In this embodiment, the connection between the unified access agent device and the target database is established in a manner of directly obtaining the connection from the database connection pool, so that the purpose of improving the efficiency of sending the second database access statement to the target database can be achieved.
In one embodiment, as shown in fig. 5, the database access method further includes:
step 502, receiving a second database access request sent by a second access terminal, where the second database access request carries a target database routing parameter.
Specifically, the access to the target database has at least one access terminal, and the access terminals can initiate the access to the target database; in order to accurately find the target database which the access terminal needs to access, the second database access request sent by the access terminal carries the target database routing parameters. The target database routing parameters are the same as the routing parameters of the first database access request.
In one embodiment, the unified access proxy device compares the network identifier of the second access terminal carried in the second database access request with the locally stored network identifier, and receives the second database access request sent by the second access terminal if the network identifier of the second access terminal is consistent with the locally stored network identifier. For example, the network identifier locally stored with the target database is 192.168.2.3 or 192.168.2.6, and when the second database access request sent by the second access terminal carries the network identifier of the access terminal is 192.168.2.3, it is determined that the access terminal is a valid access terminal, and the database access request of the access terminal is received.
Step 504, establishing a network connection with the target database in response to the second database access request.
Specifically, after the unified access proxy device receives the second database access request, the unified access proxy device analyzes the second database access request and establishes network connection with the target database.
In one embodiment, the corresponding target database is determined according to the target database routing parameter carried by the second database access request, and network connection is established with the target database.
Step 506, adding the target connection information corresponding to the established network connection into a database connection pool, wherein the target connection information includes a connection identifier corresponding to the network connection and a database identifier corresponding to the target database.
The target connection information refers to connection information between the unified access proxy device and the target database. The connection identifier means an identifier capable of uniquely determining connection information. The database identification refers to an identification capable of uniquely identifying a target database.
Specifically, in order to improve the reusability of the connection, the target connection information corresponding to the established network connection may be added to the database connection pool, so that when the next access terminal accesses, reconnection is not required, and only the existing connection needs to be acquired from the connection pool.
In one embodiment, after the unified access proxy device establishes a connection with the target database, a connection identifier of the connection is obtained. The connection identification may be identified using a binary character. For example, the connection identifier is 00101000, etc. Meanwhile, database identifiers corresponding to the target databases are obtained, and when at least one target database is available, the target database to be connected can be determined through the database identifiers. For example, the database name and date may be used as the identification of the target database, which in the case of a MySQL type database may be MySQL2000&01&20.
In this embodiment, the connection between the second access terminal and the target database is established, and the connection information is added to the database connection pool. When the connection between other access terminals and the target database is established, the connection information can be directly acquired from the database connection pool, so that the access efficiency of the target database is improved.
In one embodiment, as shown in fig. 6, the obtaining of the established network connection between the unified access proxy device and the target database according to the connection information in the database connection pool includes:
step 602, a database identifier of a target database is obtained.
Specifically, if the connection information between the access terminal and the target database to be accessed already exists in the database connection pool, the connection information is directly obtained from the database connection pool. When acquiring the connection information, the database identifier of the target database may be acquired first.
In one embodiment, the database identification of the target database may be obtained by the unified access proxy device calling a database identification obtaining function. For example, assuming the database identification is the database name database _ name, then using the select function, the database identification operation for the target database may be represented as select database _ name.
Step 604, obtaining a connection identifier corresponding to the database identifier from the database connection pool, and taking the network connection corresponding to the connection identifier as the established network connection.
Specifically, the database identifier and the connection identifier have a one-to-one correspondence relationship, and after the database identifier of the target database is obtained, the connection identifier corresponding to the obtained database identifier can be uniquely determined.
In one embodiment, the unified access agent device locally stores a corresponding list between the database identifier and the connection identifier, and when the unified access agent device acquires any one of the database identifier and the connection identifier, the unified access agent device may acquire a data item having an association relationship with the database identifier and the connection identifier from the list. For example, the unified access agent device obtains the database identifier, and may obtain a connection identifier having an association relationship with the database identifier from the list.
In this embodiment, the network connection corresponding to the connection identifier may be used as the established network connection through the database identifier of the target database and the connection identifier corresponding to the database identifier obtained from the database connection pool. The purpose of acquiring the established network connection between the unified access proxy equipment and the target database according to the connection information in the database connection pool can be achieved, and the access efficiency of the target database is improved.
In one embodiment, as shown in FIG. 7, sending the second database access statement to the target database comprises:
step 702, obtaining a database type corresponding to the target database.
The database type refers to the kind of database. Such as MySQL, oracle, postgreSQL, or DaMeng, among others. Different types of databases differ in the required driving information, grammar rules, performance or applicability, etc.
Specifically, the database type corresponding to the target database needs to be determined so as to facilitate obtaining the driving information corresponding to the target database.
In one embodiment, the database type may be determined by a function, symbolic information, or annotation, etc., that is specific to each of the different database types. For example, the database types are distinguished by using functions specific to the respective databases, the database type in which the specific function connection _ id () last _ insert _ id () row _ count () exists is MySQL, and the database type in which the specific function select extract (now from now ()) exists is PostgreSQL, and the like.
Step 704, obtaining the driving information corresponding to the database type.
The drive information is program information that enables the database to be started. For example, the drive information of the MySQL database is com.
In one embodiment, after the unified access proxy device acquires the database type corresponding to the target database, the corresponding driving information is acquired through the locally stored database type and the driving information configuration table of the link relationship formed by the database type and the corresponding driving information.
Step 706, initializing the target database according to the driving information, and sending a second database access statement to the target database after the target database is initialized.
Specifically, after the unified access proxy device obtains the driving information, the target database is initialized by using the driving information, so that the target database can construct an instance basic environment, a tablespace or a permission library and the like. The authority library can provide the authority of various instructions for the access terminal. For example, in a MySQL type database, an access terminal needs to use a query function select function, and needs to have a select right to use a query table select table, where the table is a basic unit for storing data in the database.
In this embodiment, by acquiring the database type and the corresponding driving information, the purpose of efficiently sending the second database access statement to the target database can be achieved.
In one embodiment, as shown in fig. 8, the obtaining the database routing parameters from the database access request, and determining the corresponding target database according to the database routing parameters includes:
step 802, obtaining database routing parameters from the database access request.
Specifically, as the amount of data in the target database is continuously increased, more and more tables for different functions are provided in the database, and each table corresponds to a database routing parameter
In one embodiment, the database routing parameters are obtained by accessing the annotation content in the database access request. For example, FI represents a database routing parameter, and if an access request statement in the KSQL database is/' XDB: flx/select from t ql glucer, the database routing parameter FI can be acquired from the database access request by annotating FI in information/' XDB: fl '.
And step 804, acquiring a corresponding target service type from a pre-stored routing parameter configuration list according to the database routing parameters.
The service types refer to different service types, such as a commodity management type or a personnel management type, and the target service type refers to service types corresponding to different target databases. For example, the commodity database corresponds to a business type of commodity management, or the user database corresponds to user management, and the like.
Specifically, after the routing parameters of each database are obtained, the target service type corresponding to the target database is obtained according to the configuration list corresponding to the routing parameters and the service types.
In one embodiment, the unified access proxy device locally stores a configuration list of a corresponding relationship between a routing parameter and a target service type, and can acquire the corresponding relationship between the routing parameter and the target service type from the list, and acquire the corresponding target service type from a pre-stored routing parameter configuration list through a database routing parameter.
And 806, screening the candidate database set according to the service types to obtain a target database, wherein the physical database is logically divided according to the service types to obtain the candidate database set.
The physical database refers to a database which really exists in the unified access proxy device, and the database includes a plurality of operating system files, such as a primary data file, a secondary data file, or a transaction log file. The logical division refers to dividing the database according to the logical storage units, and can be divided in the form of data blocks. For example, the database is logically partitioned in a data block size of 8 KB.
Specifically, the physical database may be logically divided according to the service types to obtain a database set composed of a plurality of sub-databases, the service types corresponding to the sub-databases in the set are different, and the target database may be screened out according to the service types.
In one embodiment, the names of the sub-databases corresponding to each service type are different, and the target database is screened out according to the names. For example, the goods database may be named commodityDB or the user database userDB, etc.
In this embodiment, the purpose of determining the target database according to the service type can be achieved by obtaining the database routing parameter from the database access request and obtaining the service type according to the database routing parameter.
In one embodiment, as shown in fig. 9, the unified access proxy device has the unified access proxy software installed thereon, and the unified access proxy device communicates with the client using a unified protocol. For example, the MySQL protocol is used. Corresponding database drivers are installed through the client, after a database with a unified protocol is initialized, communication with the unified access proxy equipment is established, and after the database access processing is carried out through the unified access proxy equipment, an initial database access request is converted into an access request which can be identified by different types of databases. Meanwhile, the output side of the unified access proxy device is corresponding to databases of different physical partitions, and the databases can be classified according to the types of the databases. For example, the database identifiers corresponding to different physical partitions are fi, sys, or base, and these physical databases with different physical partitions all belong to MySQL type databases. As another example, databases corresponding to different physical partitions are identified as cus1, cus, or cus, and these physical databases with different physical partitions all belong to an Oracle type of database.
In one embodiment, as shown in fig. 10, when a certain access terminal accesses a target database MySQL or an Oracle database, the unified access proxy device and the access terminal perform a virtual session by establishing a database connection. And executing an access request statement sent by an access terminal on the unified access proxy equipment, wherein the access request statement carries the routing information of the target database, and analyzing the request statement through a MySQL protocol in the unified access proxy equipment to obtain the routing information of the target database carried in the access request statement. And locally acquiring a configuration list on the unified access agent equipment, wherein the configuration list comprises the binding relationship between the routing information and the target database, and the target database can be uniquely determined through the routing information. And after the target database is determined, locally finding out the stored database driving information corresponding to the target database, searching whether existing connection information exists in a database connection pool, if so, directly acquiring the connection with the target database from the database connection pool, and if not, establishing new connection. In order to ensure the safety and consistency of data in the database, a transaction state management function is added on the unified access agent device. And after the target database is initialized through the database driving information, translating the access request statement into the access request statement of the grammar rule corresponding to the target database, and transmitting the access request statement to the target database. The target database may be a different type of database, for example, mySQL, oracle, postgreSQL, or the like. For each type of database, the access can also be carried out according to target databases of different physical partitions in each type of database. The uniform access agent equipment achieves the purpose that a user can access the sub-databases of different types or different physical partitions of the same type of database by using the uniform database access type.
In an embodiment, as shown in fig. 11, the unified access agent device may further encapsulate an access request statement execution result set sent by the target database and send the encapsulated result set to the client, and may directly invoke the access result when another access end has the same access next time, thereby improving the access efficiency to the target database. Specifically, after the client is connected with the unified access proxy device, the unified protocol analysis is performed on the database access request sent by the access terminal. The method comprises the steps of establishing connection with a target database through routing information carried in an analyzed access request, converting the database access request into a database access request statement which can be identified by the target database, sending the database access request statement to the target database for execution, sending an execution result to a unified access agent device by the target database, and packaging the result by the unified access agent device by using a protocol corresponding to the database type of a local terminal, for example, packaging the access result by using a unified MySQL protocol of the local terminal of the unified access agent device and sending the packaged result to a client.
It should be understood that although the various steps in the flow diagrams of fig. 2-11 are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least some of the steps in fig. 2-11 may include multiple steps or multiple stages, which are not necessarily performed at the same time, but may be performed at different times, which are not necessarily performed in sequence, but may be performed in turn or alternately with other steps or at least some of the other steps.
In one embodiment, as shown in fig. 12, there is provided a database access apparatus 1200, including: a first database access request obtaining module 1202, a target database determining module 1204, a target database language obtaining module 1206, a second database access statement obtaining module 1208, and a second database access statement sending module 1210, wherein: a first database access request obtaining module 1202, configured to obtain a first database access request sent by a first access terminal, where a first database access statement corresponding to the first database access request is compiled by using a preset database language corresponding to a unified access proxy device; a target database determining module 1204, configured to obtain a target database routing parameter from the first database access request, and determine a corresponding target database according to the target database routing parameter; a target database language obtaining module 1206, configured to obtain a target database language corresponding to the target database; a second database access statement obtaining module 1208, configured to convert the first database access statement into a second database access statement corresponding to the target database language; the second database access statement sending module 1210 is configured to send the second database access statement to the target database, so that the target database performs data processing based on the second database access statement to obtain a database access result.
In one embodiment, the database access device further comprises a virtual database connection establishing module, configured to respond to the first database access request and establish a virtual database connection with the access terminal; the database access result acquisition module is used for acquiring a database access result returned by the target database; and the database access result returning module is used for returning the database access result to the first access terminal through the virtual database link.
In one embodiment, the database access result obtaining module is configured to obtain a database access result sent by a target database through a preset data transmission format; and storing the database access result to the local in a character string mode.
In one embodiment, the second database access statement sending module 1210 is configured to obtain an established network connection between the unified access agent device and the target database according to the connection information in the database connection pool; the second database access statement is sent to the target database over the established network connection.
In one embodiment, the database access device further includes a second database access request receiving module, configured to receive a second database access request sent by a second access terminal, where the second database access request carries a target database routing parameter; the second database access request receiving module is used for responding to the second database access request and establishing network connection with the target database; and the target connection information adding module is used for adding the target connection information corresponding to the established network connection into the database connection pool, and the target connection information comprises a connection identifier corresponding to the network connection and a database identifier corresponding to the target database.
In one embodiment, the second database access statement sending module 1210 is configured to obtain a database identifier of a target database; and acquiring a connection identifier corresponding to the database identifier from the database connection pool, and taking the network connection corresponding to the connection identifier as the established network connection.
In one embodiment, the second database access statement sending module 1210 is configured to obtain a database type corresponding to a target database; acquiring driving information corresponding to the type of the database; and initializing the target database according to the driving information, and sending a second database access statement to the target database after the target database is initialized.
In one embodiment, the target database determination module 1204 is configured to obtain a database routing parameter from the database access request; acquiring a corresponding target service type from a pre-stored routing parameter configuration list according to the database routing parameters; and screening the candidate database set according to the service type to obtain a target database, wherein the physical database is logically divided according to the service type to obtain the candidate database set.
For specific limitations of the database access device, reference may be made to the above limitations of the database access method, which are not described herein again. The modules in the database access device can be wholly or partially implemented by software, hardware and a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as shown in fig. 13. The computer device includes a processor, a memory, a communication interface, a display screen, and an input device connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The communication interface of the computer device is used for carrying out wired or wireless communication with an external terminal, and the wireless communication can be realized through WIFI, an operator network, NFC (near field communication) or other technologies. The computer program is executed by a processor to implement a database access method. The display screen of the computer equipment can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer equipment can be a touch layer covered on the display screen, a key, a track ball or a touch pad arranged on the shell of the computer equipment, an external keyboard, a touch pad or a mouse and the like.
Those skilled in the art will appreciate that the architecture shown in fig. 13 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing devices to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
In one embodiment, a computer device is further provided, which includes a memory and a processor, the memory stores a computer program, and the processor implements the steps of the above method embodiments when executing the computer program.
In an embodiment, a computer-readable storage medium is provided, on which a computer program is stored which, when being executed by a processor, carries out the steps of the above-mentioned method embodiments.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above may be implemented by hardware that is instructed by a computer program, and the computer program may be stored in a non-volatile computer-readable storage medium, and when executed, may include the processes of the embodiments of the methods described above. Any reference to memory, storage, database or other medium used in the embodiments provided herein can include at least one of non-volatile and volatile memory. Non-volatile Memory may include Read-Only Memory (ROM), magnetic tape, floppy disk, flash Memory, optical Memory, or the like. Volatile Memory can include Random Access Memory (RAM) or external cache Memory. 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), among others.
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present application, and the description thereof is specific and detailed, but not to be understood as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent application shall be subject to the appended claims.

Claims (11)

1. A database access method performed by a unified access proxy device, the method comprising:
acquiring a first database access request sent by a first access terminal, wherein a first database access statement corresponding to the first database access request is compiled by adopting a preset database language corresponding to the unified access proxy equipment;
acquiring a target database routing parameter from the first database access request, and determining a corresponding target database from a candidate database set according to a target service type corresponding to the target database routing parameter, wherein the target database routing parameter is acquired through a preset position in a structure description language in the first database access request, and the candidate database set is a database set consisting of a plurality of sub-databases obtained by logically dividing a physical database according to service types;
acquiring a target database language corresponding to the target database, wherein the target database language is inquired according to the target database and a corresponding relation list of database languages corresponding to the target database;
converting the first database access statement into a second database access statement corresponding to the target database language;
and acquiring an idle established network connection in a database connection pool, wherein the database connection pool is a storage area for storing database connections in the unified access agent equipment, and sending the second database access statement to the target database through the idle established network connection, so that the target database performs data processing based on the second database access statement to obtain a database access result.
2. The method of claim 1, further comprising:
responding to the first database access request, and establishing virtual database connection with the first access terminal;
obtaining the database access result returned by the target database;
and returning the database access result to the first access terminal through the virtual database link.
3. The method of claim 2, wherein the obtaining the database access result returned by the target database comprises:
acquiring a database access result sent by the target database through a preset data transmission format;
and storing the database access result to the local in a character string form.
4. The method of claim 1, wherein sending the second database access statement to the target database comprises:
acquiring the established network connection between the unified access agent equipment and the target database according to the connection information in the database connection pool;
and sending the second database access statement to the target database through the established network connection.
5. The method of claim 4, further comprising:
receiving a second database access request sent by a second access terminal, wherein the second database access request carries the target database routing parameters;
establishing a network connection with the target database in response to the second database access request;
and adding the target connection information corresponding to the established network connection into the database connection pool, wherein the target connection information comprises a connection identifier corresponding to the network connection and a database identifier corresponding to the target database.
6. The method of claim 5, wherein the obtaining the established network connection between the unified access proxy device and the target database according to the connection information in the database connection pool comprises:
acquiring a database identifier of the target database;
and acquiring a connection identifier corresponding to the database identifier from the database connection pool, and taking the network connection corresponding to the connection identifier as the established network connection.
7. The method of claim 1, wherein sending the second database access statement to the target database comprises:
acquiring a database type corresponding to the target database;
acquiring driving information corresponding to the database type;
initializing the target database according to the driving information, and sending the second database access statement to the target database after the target database is initialized.
8. The method of claim 1, wherein obtaining database routing parameters from the database access request and determining the corresponding target database according to the database routing parameters comprises:
obtaining database routing parameters from the database access request;
acquiring a corresponding target service type from a pre-stored routing parameter configuration list according to the database routing parameters;
and screening the candidate database set according to the service type to obtain a target database, wherein the physical database is logically divided according to the service type to obtain the candidate database set.
9. A database access apparatus, the apparatus comprising:
a first database access request obtaining module, configured to obtain a first database access request sent by a first access terminal, where a first database access statement corresponding to the first database access request is compiled by using a preset database language corresponding to a unified access proxy device;
a target database determining module, configured to obtain a target database routing parameter from the first database access request, and determine a corresponding target database from a candidate database set according to a target service type corresponding to the target database routing parameter, where the target database routing parameter is obtained through a preset position in a structure description language in the first database access request, and the candidate database set is a database set composed of multiple sub-databases obtained by logically dividing a physical database according to service types;
a target database language obtaining module, configured to obtain a target database language corresponding to the target database, where the target database language is obtained by querying according to the target database and a corresponding relationship list of database languages corresponding to the target database;
a second database access statement acquisition module, configured to convert the first database access statement into a second database access statement corresponding to the target database language;
and the second database access statement sending module is configured to obtain an idle established network connection in a database connection pool, where the database connection pool is a storage area in which the database connection is stored in the unified access agent device, and send the second database access statement to the target database through the idle established network connection, so that the target database performs data processing based on the second database access statement to obtain a database access result.
10. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor, when executing the computer program, implements the steps of the method of any of claims 1 to 8.
11. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 8.
CN202011637495.0A 2020-12-31 2020-12-31 Database access method and device, computer equipment and storage medium Active CN112866348B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011637495.0A CN112866348B (en) 2020-12-31 2020-12-31 Database access method and device, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011637495.0A CN112866348B (en) 2020-12-31 2020-12-31 Database access method and device, computer equipment and storage medium

Publications (2)

Publication Number Publication Date
CN112866348A CN112866348A (en) 2021-05-28
CN112866348B true CN112866348B (en) 2022-11-11

Family

ID=76000360

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011637495.0A Active CN112866348B (en) 2020-12-31 2020-12-31 Database access method and device, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN112866348B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113961790B (en) * 2021-09-30 2022-10-14 稿定(厦门)科技有限公司 Access method and device suitable for batch texts and storage medium
CN115309726B (en) * 2022-09-27 2023-01-13 北京奥星贝斯科技有限公司 Database instance access method and device
CN117235107B (en) * 2023-11-10 2024-01-26 恒生电子股份有限公司 Data access processing method and device, electronic equipment and storage medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5734887A (en) * 1995-09-29 1998-03-31 International Business Machines Corporation Method and apparatus for logical data access to a physical relational database
US6226649B1 (en) * 1997-06-23 2001-05-01 Oracle Corporation Apparatus and method for transparent access of foreign databases in a heterogeneous database system

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103823815B (en) * 2012-11-19 2017-05-17 中国联合网络通信集团有限公司 server and database access method
US10536545B2 (en) * 2013-09-27 2020-01-14 Oracle International Corporation Cloud database connection multiplexing
CN108763536B (en) * 2018-05-31 2020-04-14 阿里巴巴集团控股有限公司 Database access method and device
WO2020264431A1 (en) * 2019-06-28 2020-12-30 Amazon Technologies, Inc. Connection pooling for scalable network services
CN110674162A (en) * 2019-09-23 2020-01-10 税友软件集团股份有限公司 Database statement execution method and related device
CN111367983B (en) * 2020-03-10 2023-08-15 中国联合网络通信集团有限公司 Database access method, system, device and storage medium
CN111460506B (en) * 2020-04-03 2024-04-16 中国工商银行股份有限公司 Data access control method and device

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5734887A (en) * 1995-09-29 1998-03-31 International Business Machines Corporation Method and apparatus for logical data access to a physical relational database
US6226649B1 (en) * 1997-06-23 2001-05-01 Oracle Corporation Apparatus and method for transparent access of foreign databases in a heterogeneous database system

Also Published As

Publication number Publication date
CN112866348A (en) 2021-05-28

Similar Documents

Publication Publication Date Title
CN112866348B (en) Database access method and device, computer equipment and storage medium
US10769228B2 (en) Systems and methods for web analytics testing and web development
WO2021184725A1 (en) User interface test method and apparatus, storage medium, and computer device
US9280665B2 (en) Fast and accurate identification of message-based API calls in application binaries
CN111414407A (en) Data query method and device of database, computer equipment and storage medium
CN110365724B (en) Task processing method and device and electronic equipment
US10754717B2 (en) Fast and accurate identification of message-based API calls in application binaries
CN110888838A (en) Object storage based request processing method, device, equipment and storage medium
CN111475376A (en) Method and device for processing test data, computer equipment and storage medium
CN111581271A (en) Interface parameter determination method and device, computer equipment and storage medium
CN110781505A (en) System construction method and device, retrieval method and device, medium and equipment
US20160269446A1 (en) Template representation of security resources
CN113381866A (en) Service calling method, device, equipment and storage medium based on gateway
CN112860507B (en) Control method and device for sampling rate of distributed link tracking system
CN111885184A (en) Method and device for processing hot spot access keywords in high concurrency scene
KR20130126012A (en) Method and apparatusfor providing report of business intelligence
WO2021232860A1 (en) Communication method, apparatus and system
CN114840574A (en) Data query method, server, node and storage medium
CN114637969A (en) Target object authentication method and device
CN109981738B (en) Cloud server suitable for application of narrow-band Internet of things
CN109831496B (en) Terminal data debugging method
CN112988589A (en) Interface testing method, device and system
CN112417324A (en) Chrome-based URL (Uniform resource locator) interception method and device and computer equipment
CN117171108B (en) Virtual model mapping method and system
CN115270110B (en) Account inspection method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant