CN116303622A - Database query method, device, equipment and storage medium - Google Patents

Database query method, device, equipment and storage medium Download PDF

Info

Publication number
CN116303622A
CN116303622A CN202310455391.5A CN202310455391A CN116303622A CN 116303622 A CN116303622 A CN 116303622A CN 202310455391 A CN202310455391 A CN 202310455391A CN 116303622 A CN116303622 A CN 116303622A
Authority
CN
China
Prior art keywords
database
query
queried
information
template
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.)
Pending
Application number
CN202310455391.5A
Other languages
Chinese (zh)
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.)
China Construction Bank Corp
CCB Finetech Co Ltd
Original Assignee
China Construction Bank Corp
CCB Finetech 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 China Construction Bank Corp, CCB Finetech Co Ltd filed Critical China Construction Bank Corp
Priority to CN202310455391.5A priority Critical patent/CN116303622A/en
Publication of CN116303622A publication Critical patent/CN116303622A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • 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/245Query processing
    • G06F16/2455Query execution
    • 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
    • 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/245Query processing
    • G06F16/2452Query translation
    • 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/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Mathematical Physics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application discloses a database query method, a database query device, database query equipment and a database query storage medium. The application relates to the technical field of big data. The method comprises the following steps: receiving query information input by a user through a query template, wherein the query information is used for representing information of a database to be queried, generating SQL sentences matched with the database to be queried according to the query information, and querying the database to be queried according to the SQL sentences matched with the database to be queried. According to the technical scheme, the technical effects of reducing the query threshold of the database and improving the query efficiency of the database can be achieved.

Description

Database query method, device, equipment and storage medium
Technical Field
The present disclosure relates to the field of big data technologies, and in particular, to a method, an apparatus, a device, and a storage medium for querying a database.
Background
With the development of big data technology, databases are becoming more and more popular in various industries and businesses. Business data is increasingly stored by means of corresponding databases. For some businesses with large data volume, data storage is needed by a database splitting table mode.
In the related art, when querying data stored in a database-splitting and table-splitting mode, a query person is required to write corresponding structured query language (Structured Query Language, SQL) sentences for different databases. And each database is queried according to the SQL sentences input by the query personnel.
However, the above-mentioned query requires a high level of demands on the query staff, and the query staff needs to be familiar with the grammar of each database, and the process of writing the SQL statement takes a long time. Therefore, the database query mode in the related art has higher query threshold and lower query efficiency.
Disclosure of Invention
The application provides a database query method, a device, equipment and a storage medium, which are used for solving the technical problems of higher query threshold and lower query efficiency in a database query mode in the related technology.
In a first aspect, the present application provides a database query method, including:
receiving query information input by a user through a query template; the query information is used for representing information of a database to be queried;
according to the query information, generating an SQL sentence matched with the database to be queried;
and inquiring the database to be inquired according to the SQL statement matched with the database to be inquired.
In a second aspect, the present application further provides a database query apparatus, including:
the receiving module is used for receiving query information input by a user through a query template; the query information is used for representing information of a database to be queried;
the generating module is used for generating SQL sentences matched with the database to be queried according to the query information;
and the query module is used for querying the database to be queried according to the SQL statement matched with the database to be queried.
In a third aspect, the present application further provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, the processor implementing a database query method as described in any one of the present applications when executing the program.
In a fourth aspect, the present application also provides a computer readable storage medium having stored thereon a computer program which when executed by a processor implements a database query method as described in any of the present applications.
In a fifth aspect, the present application also provides a computer program product comprising a computer program which, when executed by a processor, implements a database query method as described in any of the present applications.
According to the method and the device, query information input by a user through the query template is received, wherein the query information is used for representing information of the database to be queried, SQL sentences matched with the database to be queried are generated according to the query information, query is conducted on the database to be queried according to the SQL sentences matched with the database to be queried, the query information is input through the query template without writing the SQL sentences of the database to be queried by the user in the database query process, on one hand, the query threshold is reduced, on the other hand, the query information input by the user can be automatically converted into the SQL sentences matched with the database to be queried by the database query method, and compared with the mode of writing the SQL sentences by the user, the query efficiency is improved. Therefore, the database query method provided by the application can reduce the query threshold of the database and improve the query efficiency of the database.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the embodiments will be briefly described below, it being understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered limiting the scope, and that other related drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
Fig. 1A is a schematic diagram of an application scenario of a database query method provided in an embodiment of the present application;
fig. 1B is a schematic diagram of another application scenario of the database query method provided in the embodiments of the present application;
fig. 2 is a flow chart of a database query method according to an embodiment of the present application;
fig. 3 is a schematic diagram of a query task and a database in a database query method according to an embodiment of the present application;
FIG. 4 is a flowchart of another database query method according to an embodiment of the present disclosure;
FIG. 5 is a schematic diagram of a configuration data source in a database query method according to an embodiment of the present application;
FIG. 6 is a flowchart of another database query method according to an embodiment of the present disclosure;
fig. 7 is a schematic flow chart of obtaining target grammar rule information in the database query method provided in the embodiment of the present application;
FIG. 8 is a flowchart of another database query method according to an embodiment of the present disclosure;
FIG. 9 is a schematic diagram of a query result provided in an embodiment of the present application;
FIG. 10 is a flowchart illustrating another database query method according to an embodiment of the present disclosure;
fig. 11 is a schematic structural diagram of a database query device according to an embodiment of the present application;
Fig. 12 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
The present application is described in further detail below with reference to the drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the application and not limiting thereof. It should be further noted that, for convenience of description, only some, but not all of the structures related to the present application are shown in the drawings.
It should be noted that: like reference numerals and letters denote like items in the following figures, and thus once an item is defined in one figure, no further definition or explanation thereof is necessary in the following figures. Meanwhile, in the description of the present application, the terms "first", "second", and the like are used only to distinguish the description, and are not to be construed as indicating or implying relative importance. The data acquisition, storage, use, processing and the like in the technical scheme meet the relevant regulations of national laws and regulations.
Fig. 1A is a schematic diagram of an application scenario of a database query method according to an embodiment of the present application. As shown in fig. 1A, the database query method provided in the embodiment of the present application may be applied to the first database 11. The first database 11 is communicatively connected to the second database 12. The second database 12 has data stored therein. Since big data is generally stored in a manner of database and table division, the number of the second databases 12 in this embodiment may be plural. Each of the second databases 12 has a plurality of tables stored therein. Each table may be stored in a sub-table manner. A user may query data from the second database 12 via the first database 11.
The types of the plurality of second databases 12 may be different, which results in a different syntax of the SQL statement that the second databases 12 adapt. In the related art, if the data is to be queried in the plurality of second databases 12, the user is required to write the SQL statement adapted to each second database 12 in the first database 11, which has a high requirement on the user, and the user is required to be familiar with the grammar of each database.
Illustratively, the first database 11 may be a mysql database and the second database 12 may be an oracle database.
Fig. 1B is a schematic diagram of another application scenario of the database query method provided in the embodiment of the present application. As shown in fig. 1B, the database query method provided in this embodiment may be applied to the computer device 13. The computer device 13 is communicatively connected to the second database 12. The second database 12 in this scenario is the same as the second database 12 in the scenario shown in fig. 1A, and will not be described again here. In the related art, if the data is to be queried in the plurality of second databases 12, the user is required to write the SQL statement adapted to each second database 12 in the computer device 13, which has high requirements on the user, and the user is required to be familiar with the grammar of each database, in addition, the process of writing the SQL statement takes more time, resulting in high query threshold and low query efficiency.
Based on the application scenarios shown in fig. 1A and fig. 1B, the application provides a database query method. According to the database query method, query information input by a user through the query template is received, wherein the query information is used for representing information of the database to be queried, SQL sentences matched with the database to be queried are generated according to the query information, query is conducted on the database to be queried according to the SQL sentences matched with the database to be queried, the query information is input through the query template without writing the SQL sentences of the database to be queried by the user in the database query process, on one hand, the query threshold is reduced, on the other hand, the database query method can automatically convert the query information input by the user into the SQL sentences matched with the database to be queried, and compared with the mode of writing the SQL sentences by the user, the query efficiency is improved. Therefore, the database query method provided by the application can reduce the query threshold of the database and improve the query efficiency of the database.
The database query method of the present application is described in further detail below by way of several specific embodiments.
Fig. 2 is a flowchart of a database query method according to an embodiment of the present application. The method may be performed by a database querying device, which may be implemented in hardware and/or software, which may be configured in an electronic device. The electronic device here may be a server in the first database in fig. 1A or a computer device in fig. 1B. As shown in fig. 2, the database query method provided in this embodiment includes the following steps:
Step 201: query information input by a user through a query template is received.
The query information is used for representing information of the database to be queried.
The query template in this embodiment is a template specifically set forth in this application for a user to implement a database query. The user may enter query information through a query template.
Optionally, the query templates in this embodiment include at least one or a combination of the following: form templates, model configuration templates, and SQL statement templates.
Optionally, the form template in the present embodiment includes: query conditions and a list of tables corresponding to the query conditions. The query condition in this embodiment may be a user identifier or an item identifier, etc. The list of tables corresponding to the query condition may be an information table corresponding to the user identifier or an information table corresponding to the item identifier, etc. Illustratively, the format of the form template in the present embodiment may be Excel. An advantage of the form template is that the scope of the form is configurable. When a user inputs query information through the form template, the list of the form can be flexibly selected according to requirements. As a specific example, assuming that the information of the article a is to be queried, the user may select in the table template which tables to query the information of the article a, so as to further improve the query efficiency. Of course, the table template may include only the query condition and not include the table list corresponding to the query condition.
Optionally, the model configuration template in the present embodiment includes: databases and tables corresponding to the databases. The representation of the model configuration template in this embodiment may be in canvas form or in graphic form. For example, a plurality of databases and tables corresponding to the plurality of databases are displayed on a canvas. The user may perform a connection or configuration between a plurality of databases and corresponding tables in advance to specify the queried databases and corresponding tables, or may specify a query order, etc. to form a model configuration template. The model configuration template has the advantages that parameters can be dynamically changed, the configured model configuration template can be queried by combining different tasks with different parameters, and multiplexing of the model configuration template is realized, so that query efficiency is further improved. The parameters here can be understood as databases to be queried and corresponding tables etc. As a specific example, a model configuration template may include 3 databases and corresponding tables, where the tables may be configured by default or may be user selectable. The user can implement queries in 3 databases based on the model configuration template. In one scenario, a user may implement queries in databases A, B and C based on the model configuration templates. In another scenario, a user may implement a query in databases D, E and F based on the model configuration template. It can be seen that multiplexing of model configuration templates can be achieved by changing parameters based on one model configuration template.
Alternatively, the SQL statement template may be a pre-written SQL statement or a standardized SQL statement, where information such as a database name to be queried and a table to be queried is reserved.
The query information in this embodiment is used to characterize information of the database to be queried. It should be noted that, based on different implementation manners of the query template, in one implementation manner, the query information may directly include information of the database to be queried. In another implementation manner, the query information includes a query condition and the like, and because the query condition and the database have a corresponding relationship, in this implementation manner, the query information does not directly include the information of the database to be queried, but the information of the database to be queried can be obtained finally according to the query information.
Optionally, the information of the database to be queried in this embodiment may include an identification of the database to be queried. Alternatively, the information of the database to be queried may include an identification of the database to be queried and an identification of a table to be queried in the database to be queried.
In the embodiment, the user inputs the query information through the query template, so that the user is prevented from writing SQL sentences during query, and the query threshold of the database can be reduced.
Optionally, before step 201, the database query method provided in this embodiment may further include the following steps: and configuring a query template. The query template is configured in this embodiment to generate a query template. For example, one or a combination of a configuration form template, a model configuration template, and an SQL statement template. The user can also configure different form templates, different model configuration templates and different SQL sentence templates to meet different query requirements, and further improve query efficiency.
In one implementation, a user may select a query template prior to entering query information. In this implementation, before step 201, the following steps may be further included: template selection information input by a user is received; and determining the query template selected by the user according to the template selection information. Based on this implementation, correspondingly, step 201 may be: query information input by a user through the selected query template is received.
The template selection information in this embodiment may be a mode that the user directly carries the identifier of the query template, or clicks an icon of the selected query template on the user interface, so long as the query template can be selected, and the specific mode of the specific template selection information is not limited in this embodiment.
In the implementation mode, the user can flexibly select the query template, and the user experience is improved.
Still further, querying the information may include: the first query parameter and/or the second query parameter. When receiving the query information input by the user through the selected query template, or receiving the query information input by the user through the query template, the following three schemes are available.
The first scheme is as follows: and receiving a first query parameter input by a user when configuring the query template or the selected query template. In this scheme, the user may configure the first query parameter when configuring the query template or the selected query template.
The second scheme is as follows: and receiving a second query parameter input by the user through the query template or the selected query template after the user finishes configuring the query template. In this scenario, the user may reserve parameters when configuring the query templates or selected query templates. When the query is needed, a second query parameter is input through the query template or the selected query template.
Third scheme: receiving a first query parameter input by a user when configuring a selected query template; and receiving a second query parameter input by the user through the selected query template after the user finishes configuring the query template. The scheme is a combination of the two schemes, and a user can input a first query parameter when configuring a query template or a selected query template, or can input a second query parameter through the query template or the selected query template when querying.
It should be noted that, based on different implementations of the query template, the first query parameter and the second query parameter include different contents. For example, the first query parameter and the second query parameter may include at least one or a combination of the following: information of the database to be queried, query conditions, a list of the queried tables, etc.
In the three schemes, different modes can be provided for users to input query information, different requirements of the users are met, the flexibility of query is improved, and the user experience is improved.
Step 202: and generating SQL sentences matched with the database to be queried according to the query information.
In this embodiment, after the query information is obtained, an SQL statement that matches the database to be queried may be automatically generated.
In one possible implementation manner, a target grammar rule corresponding to a database to be queried can be determined according to query information, and then an SQL sentence matched with the database to be queried is generated according to the target grammar rule.
In the scenario that the query template is an SQL statement template, the standardized SQL statement can be converted into an SQL statement matched with the database to be queried according to the target grammar rule.
Step 203: and querying the database to be queried according to the SQL statement matched with the database to be queried.
After the SQL sentence matched with the database to be queried is generated, the query can be performed in the database based on the sentence to be queried.
In one possible implementation, the number of databases to be queried is a plurality. In order to improve the query efficiency, step 203 may specifically include the following steps: generating a query task corresponding to each database to be queried according to the SQL sentences matched with the databases to be queried; and querying in the database to be queried through the query task. In the implementation manner, the query tasks include SQL sentences matched with the databases to be queried, and each query task queries one database to be queried correspondingly, namely the databases to be queried corresponding to each query task are not repeated. Multiple query tasks may be performed in parallel to improve query efficiency.
Fig. 3 is a schematic diagram of a query task and a database in a database query method according to an embodiment of the present application. As shown in fig. 3, assume that there are n query tasks: query task 1, query tasks 2 and … … and query task n, wherein each query task corresponds to a database to be queried. Illustratively, query task 1 is for querying database 1, query task 2 is for querying database 2, … …, and query task n is for querying database n. Wherein n is an integer greater than or equal to 2. The query task in this embodiment may be a task in an application thread. The database may be an oracle database. The application thread here can query in the oracle database through the mysql database. The application thread may also be a thread in a mysql database. The present embodiment is not limited thereto.
According to the database query method, query information input by a user through the query template is received, wherein the query information is used for representing information of a database to be queried, SQL sentences matched with the database to be queried are generated according to the query information, query is conducted on the database to be queried according to the SQL sentences matched with the database to be queried, the query information is input through the query template without writing the SQL sentences of the database to be queried by the user in the database query process, on one hand, the query threshold is reduced, on the other hand, the database query method can automatically convert the query information input by the user into the SQL sentences matched with the database to be queried, and compared with the mode of writing the SQL sentences by the user, the query efficiency is improved. Therefore, the database query method provided by the application can reduce the query threshold of the database and improve the query efficiency of the database.
Fig. 4 is a flowchart of another database query method according to an embodiment of the present application. This embodiment describes in detail the way in which the queriable database, i.e. the data source, is configured, based on the embodiment shown in fig. 1 and various alternative implementations. The data source in this embodiment includes a database to be queried.
As shown in fig. 4, the database query method provided in this embodiment includes the following steps:
step 401: the database is configured as a data source based on the information of the database.
Optionally, the information of the database comprises at least one or a combination of: the drive of the database, the connection information of the database, the user name of the database and the password of the database.
The connection information of the database includes the name of the database, an internet protocol (Internet Protocol, IP) port, and the like.
Because the data is stored in separate banks, the data sources are more involved, and the data sources are not fixed, the data sources need to be dynamically configured and dynamically acquired.
In this embodiment, the database may be configured as a data source according to the information of the database, so as to implement that a user queries in the database of the data source, and may implement that the data source is dynamically configured, so as to improve the flexibility of query.
Fig. 5 is a schematic diagram of a configuration data source in a database query method according to an embodiment of the present application. As shown in fig. 5, the original data source includes 3 databases: database a, database B, and database C. Meaning that the user may choose to query in several of these three databases. After dynamic configuration, the configured data sources comprise 4 databases: database a, database B, database C, and database D. At this point, the user may choose to query in several of these four databases. It can be seen that dynamically configuring the data sources allows for more flexibility in the selection by the user to meet the different needs of the user.
Step 402: query information input by a user through a query template is received.
The query information is used for representing information of the database to be queried.
Step 403: and generating SQL sentences matched with the database to be queried according to the query information.
Step 404: and querying the database to be queried according to the SQL statement matched with the database to be queried.
The implementation and technical principles of step 402 and step 201, step 403 and step 202, and step 404 and step 203 are similar, and will not be described again here.
It should be noted that, in step 404 in this embodiment, the query is performed in the database to be queried in the data source according to the SQL statement matched with the database to be queried.
According to the database query method provided by the embodiment, the database is configured as the data source according to the information of the database, so that a user can query in the database of the data source, the dynamic configuration of the data source can be realized, and the query flexibility is improved.
Fig. 6 is a flowchart of another database query method according to an embodiment of the present application. The present embodiment describes in detail how to generate an SQL statement matching a database to be queried based on query information based on the embodiments shown in fig. 2 and 4. As shown in fig. 6, the database query method provided in this embodiment includes the following steps:
Step 601: query information input by a user through a query template is received.
The query information is used for representing information of the database to be queried.
Step 601 is similar to the implementation and technical principle of step 201, and will not be described here again.
The information of the database to be queried in this embodiment includes: identification of the database to be queried.
Step 602: and determining the identification of the database to be queried according to the query information.
In one implementation, the query information directly carries the identifier of the database to be queried, and the identifier of the database to be queried is directly obtained from the query information.
In another implementation, querying information includes: query conditions and a list of tables to query. In this implementation manner, the identification of the database to be queried may be determined according to the query condition, the table list of the query, and the pre-stored database, the mapping relationship between the query condition and the table. Namely, in the mapping relation of the pre-stored database, the query condition and the table, the database to be queried corresponding to the query condition and the queried table list is determined, so that the identification of the database to be queried is determined.
Step 603: and determining target grammar rule information corresponding to the database to be queried according to the identification of the database to be queried.
In one implementation, the target grammar rule information corresponding to the database to be queried is determined according to the identification of the database to be queried and the mapping relation between the grammar rule information of the database and the database, which are stored in advance.
In this implementation, the mapping relation between the grammar rule information of the database and the database is stored in advance. And directly inquiring when determining the target grammar rule information. The efficiency of acquiring the target grammar rule information in the implementation mode is higher.
In another implementation manner, according to the identification of the database to be queried, the target grammar rule information corresponding to the database to be queried is requested to the grammar rule information storage device of the database.
Fig. 7 is a schematic flow chart of obtaining target grammar rule information in the database query method according to the embodiment of the present application. As shown in fig. 7, the database query means 71 may request target grammar rule information corresponding to the database to be queried from the grammar rule information storage device 72 of the database. Alternatively, the database querying device 71 may send a request message to the grammar rule information storage device 72 of the database, where the request message carries the identification of the database to be queried. The grammar rule information storage 72 of the database returns the target grammar rule information to the database query device 71 after receiving the request message.
In the implementation mode, the mapping relation between the grammar rule information of the database and the database is not required to be stored in the storage space of the database query device, so that the storage space of the database query device is saved.
Step 604: and generating SQL sentences matched with the database to be queried according to the target grammar rule information.
After the target grammar rule information is obtained, in this embodiment, an SQL statement matched with the database to be queried may be generated according to the target grammar rule information.
Step 605: and querying the database to be queried according to the SQL statement matched with the database to be queried.
Step 605 is similar to the implementation and technical principle of step 203 and will not be described again here.
The database query method provided by the embodiment provides two implementation modes for acquiring the target grammar rule information corresponding to the database to be queried, and then generating the SQL sentence matched with the database to be queried according to the target grammar rule information corresponding to the database to be queried. In one implementation, the mapping relation between the grammar rule information of the database and the database is stored in advance. When the target grammar rule information is determined, the target grammar rule information is directly queried, and the efficiency of generating SQL sentences matched with the database to be queried is higher. In another implementation manner, the mapping relation between the grammar rule information of the database and the database is not required to be stored in the storage space of the database query device, so that the storage space of the database query device is saved.
Fig. 8 is a flowchart of another database query method according to an embodiment of the present application. The present embodiment describes in detail how to query the database to be queried according to the SQL statement matched with the database to be queried based on the embodiments shown in fig. 2, 4 and 6. As shown in fig. 8, the database query method provided in this embodiment includes the following steps:
step 801: query information input by a user through a query template is received.
The query information is used for representing information of the database to be queried.
Step 802: and generating SQL sentences matched with the database to be queried according to the query information.
Steps 801 and 802 are similar to the implementation process and technical principle of the corresponding steps in the foregoing embodiments, and are not repeated herein.
The query information in this embodiment is used to characterize the identifier of the database to be queried, and the identifier of the table to be queried in the database to be queried. Correspondingly, the SQL statement matched with the database to be queried comprises: the identification of the database to be queried and the identification of the table to be queried in the database to be queried.
Step 803: and connecting the database to be queried according to the identification of the database to be queried in the SQL sentence matched with the database to be queried.
In step 803, in the query process, the database to be queried is first connected according to the identifier of the database to be queried in the SQL sentence matched with the database to be queried. If the number of the databases to be queried is plural, the databases to be queried may be connected one by one, or the databases to be queried may be connected in parallel.
Connecting the database to be queried in this embodiment means establishing a communication link or a communication channel with the database to be queried.
Step 804: and acquiring an intermediate query result from each sub-table in the to-be-queried table of the to-be-queried database according to the identifier of the to-be-queried table in the SQL sentence matched with the to-be-queried database.
Because the data in this embodiment is stored in a database and table division manner, each table to be queried includes a plurality of tables or sub-tables. After the query result is connected with the database to be queried, the intermediate query result can be obtained from each sub-table in the table to be queried of the database to be queried according to the identification of the table to be queried in the SQL statement.
Optionally, after the intermediate query result is obtained, the intermediate query result of the same table to be queried may be placed in the same temporary table.
Step 805: and determining the query result of the database to be queried according to each intermediate query result.
In one implementation, after each intermediate query result is obtained, a set of each intermediate query result may be used as a query result of the database to be queried.
In another implementation manner, after each intermediate query result is obtained, a query file corresponding to the database to be queried is generated according to each intermediate query result, and the query file is used as the query result of the database to be queried.
In this implementation, the size of the query file may be preset. In this implementation, the query file may be generated according to a preset size of the query file. If the data volume of all intermediate query results is too large, multiple query documents may be generated. The implementation can realize the standardization of each query file in the query result.
Fig. 9 is a schematic diagram of a query result provided in an embodiment of the present application. As shown in fig. 9, the query result of the database a to be queried includes two query files: query file A1 and query file A2. The query file A1 includes intermediate query results of the sub-tables of the table B1 to be queried. The query file A2 includes intermediate query results of the sub-tables of the table B2 to be queried.
Further, the number of databases to be queried may be plural. Based on step 805, the database query method provided in this embodiment further includes the following steps: and packaging and encrypting according to the query results of the databases to be queried to generate a final query file. The implementation mode can encrypt the query results of the databases to be queried, so that the security of the query process is improved, and the information security is ensured.
In the implementation manner, the retrograde file in the query process can be packaged and encrypted.
Further, after forming the final query file, the database query method provided in this embodiment further includes the following steps: and recording the storage path information of the final query file, and storing the storage path information of the final query file. In the implementation mode, the storage path information of the final query file is recorded and stored, multiplexing of the final query file can be achieved, and query efficiency is further improved.
According to the database query method provided by the embodiment, the database to be queried is connected according to the identification of the database to be queried in the SQL sentence matched with the database to be queried, the intermediate query results are obtained from each sub-table in the table to be queried of the database to be queried according to the identification of the table to be queried in the SQL sentence matched with the database to be queried, and the query results of the database to be queried are determined according to each intermediate query result, so that the standardization of the query process is realized, and the query efficiency is further improved.
Fig. 10 is a flowchart of another database query method according to an embodiment of the present application. The present embodiment describes in detail other steps of the database query method based on the embodiments shown in fig. 2, 4, 6 and 8. As shown in fig. 10, the database query method provided in this embodiment includes the following steps:
Step 1001: query information input by a user through a query template is received.
The query information is used for representing information of the database to be queried.
Step 1002: and receiving an operation request input by a user, and operating the query process according to the operation request.
Wherein the operation request is for indicating at least one of: and (3) terminating the query process, and periodically starting to execute the step of generating SQL sentences matched with the database to be queried according to the query information to acquire a task log of the query process.
In this embodiment, after the user inputs the query information through the query template, the user may also input an operation request. The operation request here may be to terminate the query process, to start executing step 1003 for timing, or to obtain a task log of the query process.
The user can input operation requests according to the requirements so as to meet different service requirements.
In an implementation manner, in a case where the operation request is used to indicate that the log of the query process is obtained, step 1002 may specifically be: and acquiring a task log of the query process, and outputting the task log to a user. So that the user knows the dynamics of the query process.
Step 1003: and generating SQL sentences matched with the database to be queried according to the query information.
Step 1004: and querying the database to be queried according to the SQL statement matched with the database to be queried.
Steps 1001, 1003 and 1004 are similar to the implementation process and technical principle of the corresponding steps in the foregoing embodiments, and will not be repeated here.
In the database query method provided by the embodiment, the user can input the operation request according to the requirements, receive the operation request input by the user, and operate the query process according to the operation request so as to meet different service requirements, thereby improving the user experience.
Fig. 11 is a schematic structural diagram of a database query device according to an embodiment of the present application. As shown in fig. 11, the database query device provided in this embodiment includes the following modules: a receiving module 111, a generating module 112 and a querying module 113.
And the receiving module 111 is used for receiving the query information input by the user through the query template.
The query information is used for representing information of the database to be queried.
The generating module 112 is configured to generate, according to the query information, an SQL statement that matches the database to be queried.
And the query module 113 is used for querying the database to be queried according to the SQL statement matched with the database to be queried.
In some embodiments, the query templates include at least one or a combination of the following: form templates, model configuration templates, and SQL statement templates.
In some embodiments, the form template includes: query conditions and a list of tables corresponding to the query conditions. The model configuration template comprises: databases and tables corresponding to the databases.
In some embodiments, the database querying device further comprises: the first configuration module is used for configuring the query template.
In some embodiments, the database querying device further comprises: and a determining module. The receiving module 111 is further configured to receive template selection information input by a user. And the determining module is used for determining the query template selected by the user according to the template selection information. In terms of receiving query information entered by a user through a query template, the receiving module 111 is further configured to: query information input by a user through the selected query template is received.
In some embodiments, querying the information includes: the first query parameter and/or the second query parameter. The receiving module 111 is configured to perform at least one of: receiving a first query parameter input by a user when configuring a selected query template; and receiving a second query parameter input by the user through the selected query template after the user finishes configuring the query template.
In some embodiments, the data source comprises a database to be queried. The database query device further includes: and the second configuration module is used for configuring the database as a data source according to the information of the database.
In some embodiments, the information of the database includes at least one or a combination of: the drive of the database, the connection information of the database, the user name of the database and the password of the database.
In some embodiments, the information of the database to be queried includes: identification of the database to be queried. The generating module 112 is specifically configured to: determining the identification of the database to be queried according to the query information; determining target grammar rule information corresponding to the database to be queried according to the identification of the database to be queried; and generating SQL sentences matched with the database to be queried according to the target grammar rule information.
In some embodiments, querying the information includes: query conditions and a list of tables to query. In determining the identity of the database to be queried based on the query information, the generating module 112 is specifically configured to: and determining the identification of the database to be queried according to the query conditions, the query list and the pre-stored database, the mapping relation between the query conditions and the table.
In some embodiments, in determining the target grammar rule information corresponding to the database to be queried according to the identification of the database to be queried, the generating module 112 is specifically configured to: and determining target grammar rule information corresponding to the database to be queried according to the identification of the database to be queried and the mapping relation between the grammar rule information of the database and the database, which are stored in advance.
In some embodiments, in determining the target grammar rule information corresponding to the database to be queried according to the identification of the database to be queried, the generating module 112 is specifically configured to: and according to the identification of the database to be queried, requesting target grammar rule information corresponding to the database to be queried from grammar rule information storage equipment of the database.
In some embodiments, the query information is used to characterize the identity of the database to be queried, and the identity of the table to be queried in the database to be queried; the SQL statement includes: the identification of the database to be queried and the identification of the table to be queried in the database to be queried. The query module 113 is specifically configured to: connecting the database to be queried according to the identification of the database to be queried in the SQL sentence matched with the database to be queried; acquiring an intermediate query result from each sub-table in the to-be-queried table of the to-be-queried database according to the identifier of the to-be-queried table in the SQL sentence matched with the to-be-queried database; and determining the query result of the database to be queried according to each intermediate query result.
In some embodiments, in determining the query results of the database to be queried based on the intermediate query results, the query module 113 is specifically configured to: and generating a query file corresponding to the database to be queried according to each intermediate query result, and taking the query file as the query result of the database to be queried.
In some embodiments, the number of databases to be queried is a plurality. The database query device further includes: and the encryption module is used for generating a final query file after packaging and encrypting according to the query results of the databases to be queried.
In some embodiments, the database querying device further comprises: the record saving module is used for recording the storage path information of the final query file and saving the storage path information of the final query file.
In some embodiments, the receiving module 111 is further configured to: and receiving an operation request input by a user, and operating the query process according to the operation request. Wherein the operation request is for indicating at least one of: and (3) terminating the query process, and periodically starting to execute the step of generating SQL sentences matched with the database to be queried according to the query information to acquire a task log of the query process.
In some embodiments, where the operation request is used to indicate that a log of the query process is obtained, the receiving module 111 is specifically configured to: and acquiring a task log of the query process, and outputting the task log to a user.
In some embodiments, the number of databases to be queried is a plurality. The query module 113 is specifically configured to: generating a query task corresponding to each database to be queried according to the SQL sentences matched with the databases to be queried; and querying in the database to be queried through the query task.
The database query device provided in the embodiment of the present application may be used to execute the technical scheme of the database query method in the above embodiment, and its implementation principle and technical effect are similar, and are not described herein again.
It should be noted that, it should be understood that the division of the modules of the above apparatus is merely a division of a logic function, and may be fully or partially integrated into a physical entity or may be physically separated. And these modules may all be implemented in software in the form of calls by the processing element; or can be realized in hardware; the method can also be realized in a form of calling software by a processing element, and the method can be realized in a form of hardware by a part of modules. For example, the receiving module 111, the generating module 112, and the querying module 113 may be individually set up processing elements, may be integrated into one of the chips of the above-described apparatus, may be stored in the memory of the above-described apparatus in the form of program codes, and may be called by one of the processing elements of the above-described apparatus to execute the functions of the receiving module 111, the generating module 112, and the querying module 113. The implementation of the other modules is similar. In addition, all or part of the modules can be integrated together or can be independently implemented. The processing element here may be an integrated circuit with signal processing capabilities. In implementation, each step of the above method or each module above may be implemented by an integrated logic circuit of hardware in a processor element or an instruction in a software form.
Fig. 12 is a schematic structural diagram of an electronic device according to an embodiment of the present application. As shown in fig. 12, the electronic device may include: a transceiver 121, a processor 122 and a memory 123.
Processor 122 executes the computer-executable instructions stored in the memory, causing processor 122 to perform the aspects of the embodiments described above. The processor 122 may be a general-purpose processor including a central processing unit CPU, a network processor (network processor, NP), etc.; but may also be a digital signal processor DSP, an application specific integrated circuit ASIC, a field programmable gate array FPGA or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component.
Memory 123 is coupled to processor 122 via the system bus and communicates with each other, and memory 123 is configured to store computer program instructions.
Transceiver 121 may be used to receive query information entered by a user via a query template.
The system bus may be a peripheral component interconnect standard (peripheral component interconnect, PCI) bus or an extended industry standard architecture (extended industry standard architecture, EISA) bus, among others. The system bus may be classified into an address bus, a data bus, a control bus, and the like. For ease of illustration, the figures are shown with only one bold line, but not with only one bus or one type of bus. The transceiver is used to enable communication between the database querying device and other computer devices. The memory may include random access memory (random access memory, RAM) and may also include non-volatile memory (non-volatile memory).
The embodiment of the application also provides a chip for running the instruction, which is used for executing the technical scheme of the database query method in the embodiment.
The embodiment of the application also provides a computer readable storage medium, wherein the computer readable storage medium stores computer instructions, and when the computer instructions run on a computer, the computer is caused to execute the technical scheme of the database query method in the embodiment.
Embodiments of the present application also provide a computer program product comprising a computer program which, when executed by a processor, implements a database query method as provided by any of the embodiments of the present application.
Computer program product in the implementation, the computer program code for carrying out the operations of the present application may be written in one or more programming languages, including an object oriented programming language such as Java, smalltalk, C ++ and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computer (for example, through the Internet using an Internet service provider).
Note that the above is only a preferred embodiment of the present application and the technical principle applied. Those skilled in the art will appreciate that the present application is not limited to the particular embodiments described herein, but is capable of numerous obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the present application. Therefore, while the present application has been described in connection with the above embodiments, the present application is not limited to the above embodiments, but may include many other equivalent embodiments without departing from the spirit of the present application, the scope of which is defined by the scope of the appended claims.

Claims (23)

1. A database query method, comprising:
receiving query information input by a user through a query template; the query information is used for representing information of a database to be queried;
generating a Structured Query Language (SQL) statement matched with the database to be queried according to the query information;
and inquiring the database to be inquired according to the SQL statement matched with the database to be inquired.
2. The method of claim 1, wherein the query template comprises at least one or a combination of:
Form templates, model configuration templates, and SQL statement templates.
3. The method of claim 2, wherein the step of determining the position of the substrate comprises,
the form template includes: query conditions and a list of tables corresponding to the query conditions;
the model configuration template comprises: databases and tables corresponding to the databases.
4. The method of claim 2, wherein prior to receiving query information entered by a user via a query template, the method further comprises:
and configuring the query template.
5. The method of claim 4, wherein prior to receiving query information entered by a user via a query template, the method further comprises:
template selection information input by a user is received;
determining a query template selected by a user according to the template selection information;
the receiving the query information input by the user through the query template comprises the following steps:
and receiving query information input by a user through the selected query template.
6. The method of claim 5, wherein querying the information comprises: a first query parameter and/or a second query parameter;
the receiving of the query information input by the user through the selected query template comprises at least one of the following:
Receiving a first query parameter input by the user when configuring the selected query template;
and receiving a second query parameter input by the user through the selected query template after completing configuration of the query template.
7. The method according to any one of claims 1 to 6, wherein a data source comprises the database to be queried;
before the query information input by the user through the query template is received, the method further comprises the following steps:
and configuring the database as a data source according to the information of the database.
8. The method of claim 7, wherein the information of the database comprises at least one or a combination of: the drive of the database, the connection information of the database, the user name of the database and the password of the database.
9. The method according to any one of claims 1 to 6, wherein the information of the database to be queried comprises: the identification of the database to be queried;
according to the query information, generating an SQL sentence matched with the database to be queried, comprising:
determining the identification of the database to be queried according to the query information;
Determining target grammar rule information corresponding to the database to be queried according to the identification of the database to be queried;
and generating SQL sentences matched with the database to be queried according to the target grammar rule information.
10. The method of claim 9, wherein querying the information comprises: querying conditions and a list of queried tables;
the determining the identification of the database to be queried according to the query information comprises the following steps:
and determining the identification of the database to be queried according to the query conditions, the query list and the mapping relation among the prestored database, the query conditions and the table.
11. The method according to claim 9, wherein the determining, according to the identification of the database to be queried, target grammar rule information corresponding to the database to be queried includes:
and determining target grammar rule information corresponding to the database to be queried according to the identification of the database to be queried and the mapping relation between the grammar rule information of the database and the database, which are stored in advance.
12. The method according to claim 9, wherein the determining, according to the identification of the database to be queried, target grammar rule information corresponding to the database to be queried includes:
And according to the identification of the database to be queried, requesting target grammar rule information corresponding to the database to be queried from grammar rule information storage equipment of the database.
13. The method according to any one of claims 1 to 6, wherein the query information is used to characterize an identity of a database to be queried, and an identity of a table to be queried in the database to be queried; the SQL statement includes: an identification of a database to be queried and an identification of a table to be queried in the database to be queried;
the step of querying the database to be queried according to the SQL statement matched with the database to be queried comprises the following steps:
connecting the database to be queried according to the identification of the database to be queried in the SQL sentence matched with the database to be queried;
acquiring an intermediate query result from each sub-table in the to-be-queried table of the to-be-queried database according to the identifier of the to-be-queried table in the SQL sentence matched with the to-be-queried database;
and determining the query result of the database to be queried according to each intermediate query result.
14. The method of claim 13, wherein determining the query result of the database to be queried based on each of the intermediate query results comprises:
And generating a query file corresponding to the database to be queried according to each intermediate query result, and taking the query file as the query result of the database to be queried.
15. The method of claim 14, wherein the number of databases to be queried is a plurality;
the method further comprises the steps of, after the database to be queried is queried according to the SQL statement matched with the database to be queried:
and packaging and encrypting according to the query results of the databases to be queried to generate a final query file.
16. The method according to claim 15, wherein after the final query file is generated after packaging and encrypting according to the query result of each database to be queried, the method further comprises:
and recording the storage path information of the final query file, and storing the storage path information of the final query file.
17. The method according to any one of claims 1 to 6, wherein after receiving query information input by a user through a query template, the method further comprises:
receiving an operation request input by a user, and operating a query process according to the operation request; wherein the operation request is used for indicating at least one of the following: and (3) terminating the query process, and starting to execute the step of generating SQL sentences matched with the database to be queried according to the query information at fixed time to acquire a task log of the query process.
18. The method of claim 17, wherein, in the case where the operation request is used to indicate that a log of a query process is obtained, the operating the query process according to the operation request comprises:
and acquiring a task log of the query process, and outputting the task log to the user.
19. The method according to any one of claims 1 to 6, wherein the number of databases to be queried is a plurality;
the step of querying the database to be queried according to the SQL statement matched with the database to be queried comprises the following steps:
generating a query task corresponding to each database to be queried according to the SQL sentences matched with the databases to be queried;
and querying the database to be queried through the query task.
20. A database query apparatus, comprising:
the receiving module is used for receiving query information input by a user through a query template; the query information is used for representing information of a database to be queried;
the generation module is used for generating a Structured Query Language (SQL) statement matched with the database to be queried according to the query information;
And the query module is used for querying the database to be queried according to the SQL statement matched with the database to be queried.
21. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable by the processor, wherein the processor implements the database query method of any of claims 1 to 19 when the computer program is executed by the processor.
22. A computer readable storage medium having stored thereon a computer program, which when executed by a processor implements a database querying method as claimed in any one of claims 1 to 19.
23. A computer program product comprising a computer program which, when executed by a processor, implements the database query method of any of claims 1 to 19.
CN202310455391.5A 2023-04-25 2023-04-25 Database query method, device, equipment and storage medium Pending CN116303622A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310455391.5A CN116303622A (en) 2023-04-25 2023-04-25 Database query method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310455391.5A CN116303622A (en) 2023-04-25 2023-04-25 Database query method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN116303622A true CN116303622A (en) 2023-06-23

Family

ID=86790756

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310455391.5A Pending CN116303622A (en) 2023-04-25 2023-04-25 Database query method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN116303622A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117056343A (en) * 2023-10-11 2023-11-14 湖北华中电力科技开发有限责任公司 Multi-source data management method and system in power grid field and electronic equipment

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117056343A (en) * 2023-10-11 2023-11-14 湖北华中电力科技开发有限责任公司 Multi-source data management method and system in power grid field and electronic equipment
CN117056343B (en) * 2023-10-11 2024-01-23 湖北华中电力科技开发有限责任公司 Multi-source data management method and system in power grid field and electronic equipment

Similar Documents

Publication Publication Date Title
CN107798038B (en) Data response method and data response equipment
US20210326471A1 (en) Methods and apparatuses for chaining service data
KR100714693B1 (en) System and method for implementing database application which are guaranteeing independence of software module
CN111741035A (en) Electronic contract signing method, device and equipment
CN109062925B (en) Method, device, computer equipment and storage medium for automatically generating insert sentences
CN111400387B (en) Conversion method and device for import and export data, terminal equipment and storage medium
US20150066977A1 (en) Method and system for managing digital resources
CN110601880A (en) Cloud platform, service processing method, command interface and computer equipment
CN111818175B (en) Enterprise service bus configuration file generation method, device, equipment and storage medium
CN110955714B (en) Method and device for converting unstructured text into structured text
CN111258550A (en) Software architecture and software architecture development method
CN112861501A (en) Report generation method and device, electronic equipment and computer readable storage medium
CN109062906B (en) Translation method and device for program language resources
CN116303622A (en) Database query method, device, equipment and storage medium
CN111026931A (en) Data query method, device, equipment and medium
CN112860730A (en) SQL statement processing method and device, electronic equipment and readable storage medium
CN114238381A (en) Data quality checking method, device and computer readable storage medium
CN115712621A (en) Method for writing data into database and method for reading data from database
CN111786792A (en) Block chain-based data change recording method and device
CN114090672A (en) Business data import and export method, system, computer equipment and medium
CN112434037A (en) Data processing method, processing device, data processing apparatus, and storage medium
CN105760532B (en) Resource sharing system and method based on Web Service
CN109814916B (en) IVR flow configuration method, device, storage medium and server
CN111324645B (en) Block chain data processing method and device
CN110990000A (en) Data request processing method, device and equipment for MVC (model view controller) pattern design model layer

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