Data query method and device of database, computer device and storage medium
By establishing a WebSocket connection and full-duplex communication protocol in database queries, user permission information can be obtained and processed, thus solving the problem of information leakage in PL/SQL Developer and achieving secure and efficient data querying and result management.
Patent Information
- Application Number
- CN202010090838.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-02-13
- Publication Date
- 2025-12-23
- Estimated Expiration
- 2040-02-13
AI Technical Summary
In existing technologies, database data queries using PL/SQL Developer pose a risk of information leakage, resulting in low database query security.
Establish a WebSocket connection with the client, construct a full-duplex communication protocol, obtain user information and query statements, process the query results according to permission conditions, and send the target query results through the full-duplex communication protocol. Combine with ElasticSearch for data sharding storage and management.
It improves the security of database data queries, avoids access control problems, and enhances the management and transmission efficiency of query results.
Smart Images

Figure CN111414407B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing, and in particular to a data query method, apparatus, computer equipment, and storage medium for a database. Background Technology
[0002] With the advent of the big data era, the amount of data stored in databases is increasing, and different people have different data query needs and require different permissions. Currently, many database queries are performed using PL / SQL Developer, which greatly facilitates database data querying and improves query efficiency. However, in the process of developing this invention, the inventors discovered at least the following problems in the existing technology: using PL / SQL Developer to query data in the database can easily lead to information leakage, which makes the database query security low. Therefore, providing a highly secure database data query method has become an urgent problem to be solved. Summary of the Invention
[0003] This invention provides a database data query method, apparatus, computer device, and storage medium to improve the security of the database data query process.
[0004] A database data query method, comprising:
[0005] Establish a WebSocket connection with the client, and build a full-duplex communication protocol based on the WebSocket connection;
[0006] If a data query request is received from a client, the user information, query statement, and target database contained in the query request are obtained.
[0007] The query statement is executed on the target database to obtain initial query results;
[0008] Based on preset permission conditions, obtain the initial query results corresponding to the user permission information, and use them as the target query results;
[0009] The target query result is sent to the client via the full-duplex communication protocol.
[0010] Optionally, executing the query statement on the target database to obtain initial query results includes:
[0011] The query statement is executed on the target database so that the target database performs query processing based on the query statement;
[0012] If a query failure message is detected, the error code contained in the message is obtained, the error code is analyzed, and a query modification prompt is generated for the query statement sent by the client.
[0013] The statement modification prompt is sent to the client so that the client user can modify the query statement according to the statement modification prompt, obtain the corrected statement, and send the corrected statement to the server;
[0014] The system receives the correction statement sent by the client and uses the correction statement to perform query processing to obtain the initial query result.
[0015] Optionally, after obtaining the initial query result corresponding to the user permission information according to preset permission conditions as the target query result, and before sending the target query result to the client through the full-duplex communication protocol, the database data query method further includes:
[0016] For the target query results, a basic index is generated and recorded in a log file;
[0017] Using the base index and predefined types in the log file, the data in the target query result is sharded according to preset values, and the sharded data is stored in ElasticSearch;
[0018] When data is exported, the sharded data is read from the ElasticSearch according to the base index in the log file, and the sharded data is used as the target query result to be sent to the client.
[0019] Optionally, sending the target query result to the client via the full-duplex communication protocol includes:
[0020] Receive the viewing command sent by the client;
[0021] According to the viewing method in the viewing instruction, the data of the target query result is encapsulated to obtain the encapsulation result;
[0022] The encapsulation result is sent to the client via the full-duplex communication protocol.
[0023] Optionally, the step of encapsulating the data of the target query result according to the viewing method in the viewing instruction to obtain the encapsulation result includes:
[0024] If the viewing method in the viewing instruction is online data viewing, an initial preview page is generated, and a preset number of target query results are obtained and packaged into the initial preview page.
[0025] Optionally, after sending the target query result to the client via the full-duplex communication protocol, the database data query method further includes:
[0026] Generate statistical records of the target query results;
[0027] Establish a mapping relationship between the user information, the query statement, and the statistical records, and store the mapping relationship in the query record database;
[0028] If a permission verification request is received from the management terminal, the user identifier contained in the permission verification request is obtained, and the mapping relationship corresponding to the user identifier is obtained from the query record database, and the mapping relationship is sent to the management terminal.
[0029] A database data query device, comprising:
[0030] A connection building module is used to establish a WebSocket connection with the client and build a full-duplex communication protocol based on the WebSocket connection;
[0031] The request acquisition module is used to acquire user information, query statements and target database contained in a data query request sent by a client if it receives such a request.
[0032] The initial query module is used to execute the query statement on the target database to obtain initial query results;
[0033] The result filtering module is used to obtain the initial query results corresponding to the user permission information based on preset permission conditions, and use them as the target query results.
[0034] The result transmission module is used to send the target query result to the client via the full-duplex communication protocol.
[0035] Optionally, the initial query module includes:
[0036] A query statement execution unit is configured to execute the query statement on the target database, so that the target database performs query processing according to the query statement;
[0037] The modification prompt generation unit is used to obtain the error code contained in the message if a query failure message is detected, analyze the error code, and generate a statement modification prompt for the query statement sent by the client.
[0038] The modification prompt sending unit is used to send the statement modification prompt to the client, so that the client user can modify the query statement according to the statement modification prompt, obtain the corrected statement, and send the corrected statement to the server;
[0039] The query statement update unit is used to receive the correction statement sent by the client, and use the correction statement to perform query processing to obtain the initial query result.
[0040] Optionally, the data query device for the database further includes:
[0041] The recording module is used to generate a basic index for the target query results and record the basic index in a log file;
[0042] The allocation module is used to shard the data in the target query result according to preset values based on the basic index and predefined type in the log file, and store the sharded data in ElasticSearch;
[0043] The read module is used to read sharded data from the ElasticSearch according to the base index in the log file when data is exported, and use the sharded data as the target query result to be sent to the client.
[0044] Optionally, the result transmission module includes:
[0045] The instruction receiving unit is used to receive the viewing instruction sent by the client;
[0046] The data encapsulation unit is used to encapsulate the data of the target query result according to the viewing method in the viewing instruction, and obtain the encapsulation result;
[0047] The result sending unit is used to send the encapsulation result to the client via the full-duplex communication protocol.
[0048] Optionally, the data encapsulation unit includes:
[0049] The data viewing subunit is used to generate an initial preview page and encapsulate a preset number of target query results into the initial preview page if the viewing method in the viewing instruction is online data viewing.
[0050] Optionally, the data query method for this database also includes:
[0051] A record generation module is used to generate statistical records of the target query results;
[0052] The mapping establishment module is used to establish the mapping relationship between the user information, the query statement and the statistical records, and store the mapping relationship in the query record database;
[0053] The permission verification module is used to, if it receives a permission verification request sent by the management terminal, obtain the user identifier contained in the permission verification request, obtain the mapping relationship corresponding to the user identifier from the query record database, and send the mapping relationship to the management terminal.
[0054] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the data query method for the database described above.
[0055] A computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the data query method for the aforementioned database.
[0056] The database data query method, apparatus, computer device, and storage medium provided in this invention establish a WebSocket connection with the client and construct a full-duplex communication protocol based on the WebSocket connection. Upon receiving a data query request from the client, the method obtains the user information, query statement, and target database contained in the query request, executes the query statement on the target database to obtain an initial query result, and obtains the initial query result corresponding to the user permission information according to preset permission conditions as the target query result. The target query result is then sent to the client through the full-duplex communication protocol. This avoids the difficulties in permission control and query result control caused by directly querying the database, thereby improving the security of database data query. Attached Figure Description
[0057] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0058] Figure 1 This is an exemplary system architecture diagram in which embodiments of the present invention can be applied;
[0059] Figure 2 This is a flowchart illustrating the implementation of the database data query method provided in this embodiment of the invention.
[0060] Figure 3 This is a schematic diagram of a database data query device provided in an embodiment of the present invention;
[0061] Figure 4 This is a schematic diagram of a computer device provided in an embodiment of the present invention. Detailed Implementation
[0062] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains; the terminology used herein in the specification of the application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application; the terms "comprising" and "having," and any variations thereof, in the specification, claims, and foregoing drawings of this application, are intended to cover non-exclusive inclusion. The terms "first," "second," etc., in the specification, claims, or foregoing drawings of this application are used to distinguish different objects, not to describe a particular order.
[0063] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0064] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0065] Please see Figure 1 ,like Figure 1 As shown, system architecture 100 may include terminal devices 101, 102, and 103, a network 104, and a server 105. Network 104 serves as the medium for providing communication links between terminal devices 101, 102, and 103 and server 105. Network 104 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.
[0066] Users can use terminal devices 101, 102, and 103 to interact with server 105 via network 104 to receive or send messages, etc.
[0067] Terminal devices 101, 102, and 103 can be various electronic devices with displays and support web browsing, including but not limited to smartphones, tablets, e-book readers, MP3 players (Moving Picture E interface displays perts Group Audio Layer III, Dynamic Picture Experts Compression Standard Audio Layer 3), MP4 players (Moving Picture E interface displays perts Group Audio Layer IV, Dynamic Picture Experts Compression Standard Audio Layer 4), laptops, and desktop computers, etc.
[0068] Server 105 can be a server that provides various services, such as a backend server that supports the pages displayed on terminal devices 101, 102, and 103.
[0069] It should be noted that the electronic document control method provided in this application embodiment is executed by the server, and correspondingly, the electronic document control device is set in the server.
[0070] It should be understood that Figure 1 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included. The terminal devices 101, 102, and 103 in this embodiment can specifically correspond to application systems in actual production.
[0071] Please see Figure 2 , Figure 2 This invention illustrates a database data query method provided by an embodiment of the present invention, which is applied to... Figure 1 Taking the server-side as an example, the details are as follows:
[0072] S10: Establish a WebSocket connection with the client and build a full-duplex communication protocol based on the WebSocket connection.
[0073] Specifically, a full-duplex communication protocol is built using WebSocket to achieve a continuous connection between the client and the server, so that the server can perform queries on the database and return the query results to the client through the full-duplex communication protocol.
[0074] WebSocket is a protocol that enables full-duplex communication over a single TCP connection, simplifying data exchange between clients and servers and allowing servers to proactively push data to clients. In the WebSocket API, browsers and servers only need to complete a single handshake to establish a persistent connection and perform bidirectional data transmission.
[0075] Among them, the full-duplex communication protocol is also known as bidirectional simultaneous communication, which means that both parties in the communication can send and receive information at the same time.
[0076] S20: If a data query request is received from the client, obtain the user information, query statement, and target database contained in the query request.
[0077] Specifically, after the full-duplex communication protocol is established, the server and client can communicate continuously in real time. When the server receives a data query request sent by the client, it obtains the user information, query statement and target database contained in the query request.
[0078] It should be noted that in this embodiment, the server includes at least one database. When multiple databases are included, the database to be queried can be determined by the target database in the query request.
[0079] In this embodiment, user information refers to identification information that can determine the user's identity. Different users have different permissions in different databases, and the query results they can obtain are also subject to different restrictions. By obtaining user information, the permissions corresponding to the user information preset by the server can be obtained. When querying the target database and obtaining data in the future, the corresponding operations are performed according to the permissions corresponding to the user information to ensure the security of database data query.
[0080] The query statement refers to the string used to query the database.
[0081] The target database refers to the identifier of the database that needs to be queried.
[0082] S30: Execute a query statement on the target database to obtain the initial query results.
[0083] Specifically, the obtained query statement is used to perform a query operation on the target database to obtain the initial query results.
[0084] It should be noted that before using the query statement to perform a query, this embodiment also includes parsing the query statement and determining whether the obtained parsed content conforms to the syntax requirements, to ensure that the query statement is executable and improve the efficiency of data querying. For details on the parsing and determination of the query statement, please refer to the description in the subsequent embodiments; to avoid repetition, it will not be repeated here.
[0085] S40: Based on preset permission conditions, obtain the initial query results corresponding to the user permission information, and use them as the target query results.
[0086] Specifically, the server has preset user permission information corresponding to user information. The same user information may have different user permissions in different databases. Based on the preset permissions corresponding to the user information, the server retrieves the initial query result corresponding to the user permission information from the initial query result and uses it as the target query result.
[0087] Among them, user permission information refers to the preset permissions of user information in the target database.
[0088] For example, in one specific implementation, the initial query results are 320, but the user information has some field attributes in the target database that are not visible. Based on this permission information, the initial query results are filtered to obtain 110 target query results that match the user's permission information.
[0089] S50: Sends the target query results to the client via a full-duplex communication protocol.
[0090] Specifically, the well-constructed full-duplex communication protocol enables the client and server to interact with data at any time without having to make a request and response every time. After obtaining the target query results that meet the user's permission information, the target query results are sent to the client according to the viewing method selected by the client.
[0091] It should be noted that when performing database queries, the target query results are usually numerous. To avoid excessive data volume leading to memory overflow, you can set up either a table-sharded viewing method or a download viewing method. Table-sharded viewing means dividing the target query results into multiple shard tables and sending one shard table to the client at a time. Download viewing means saving the target query results to a file with a preset format, which the client can then download for offline viewing.
[0092] In this embodiment, a WebSocket connection is established with the client, and a full-duplex communication protocol is constructed based on the WebSocket connection. When a data query request is received from the client, the user information, query statement, and target database contained in the query request are obtained. The query statement is executed on the target database to obtain the initial query result. According to the preset permission conditions, the initial query result corresponding to the user permission information is obtained as the target query result. The target query result is sent to the client through the full-duplex communication protocol. This avoids the difficulty in permission control and query result control caused by directly querying the database, and improves the security of data querying in the database.
[0093] In some optional implementations of this embodiment, step S30, executing a query statement on the target database to obtain initial query results, includes:
[0094] Execute a query statement on the target database so that the target database performs query processing based on the query statement;
[0095] If a query failure message is detected, the error code contained in the message is obtained, the error code is analyzed, and a query modification prompt is generated for the query statement sent by the client.
[0096] The system sends a statement modification suggestion to the client so that the client user can modify the query statement according to the statement modification suggestion, obtain the corrected statement, and send the corrected statement to the server.
[0097] Receive correction statements sent by the client, use the correction statements to perform query processing, and obtain the initial query results.
[0098] Specifically, after obtaining the target database and query statement, the query statement is executed on the target database. If the query statement is correct, the initial query results can be obtained. If the query statement does not conform to the syntax rules of the target database, a query failure message is generated. The server obtains the error code from the query failure message, parses the error code, generates a statement modification prompt, and sends it to the client so that the client user can modify the query statement according to the statement modification prompt. The modified query statement is then sent back to the server as a correction statement. After receiving the correction statement, the server executes the correction statement on the target database to obtain the initial results.
[0099] It should be noted that if the server executes a correction statement on the target database and then fails to query again, it will continue to generate a statement modification prompt and send it to the client, and re-execute the above steps. When the number of consecutive query failures reaches a preset number, an error record will be generated and the database connection at this point will be disconnected.
[0100] In this embodiment, a query statement is executed on the target database. When a query failure message is detected, a statement modification prompt is generated to prompt the client to make corrections. After receiving the corrected statement, the query continues, which helps to improve the efficiency of data query.
[0101] In some optional implementations of this embodiment, after step S40 and before step S50, the database data query method further includes:
[0102] For the target query results, generate a basic index and record the basic index in the log file;
[0103] The data in the target query results is sharded according to preset values using the base index and predefined types in the log file, and the sharded data is stored in ElasticSearch.
[0104] When data is exported, the sharded data is read from Elasticsearch according to the base index in the log file, and the sharded data is used as the target query result to be sent to the client.
[0105] Specifically, the target query results often involve a large amount of data. Sending them directly to the client would result in low transmission efficiency and could easily lead to memory overflow. In this embodiment, a basic index is generated for the target query results and recorded in a log file. Then, based on the basic index in the log file and a predefined type, the data in the target query results is sharded according to preset values, and the sharded data is stored in Elasticsearch. When data export is required, the sharded data is read from Elasticsearch according to the basic index in the log file, and the sharded data is used as the target query results to be sent to the client. This allows the data to be read on demand, which is beneficial for the client to view the data online later by using the sharded data.
[0106] Elasticsearch is a search server based on Lucene. It provides a distributed, multi-user, full-text search engine based on a RESTful web interface. Developed in Java and released as open source under the Apache License, Elasticsearch is a popular enterprise-grade search engine.
[0107] The predefined types can be set according to actual needs, such as the .dat type, etc., without specific limitations here.
[0108] In this embodiment, by storing the target query results in segments, when data needs to be exported, the segmented data is read as the target query results to be sent to the client, avoiding network congestion and memory overflow caused by sending a large amount of data at once, which helps to improve the efficiency of database data query.
[0109] In some optional implementations of this embodiment, step S50, sending the target query result to the client via a full-duplex communication protocol, includes:
[0110] Receive viewing instructions sent by the client;
[0111] Based on the viewing method specified in the viewing command, the data of the target query result is encapsulated to obtain the encapsulated result;
[0112] The encapsulation result is sent to the client via a full-duplex communication protocol.
[0113] Specifically, when the client needs to obtain the target query result, it sends a viewing instruction to the server via a full-duplex communication protocol. The server receives the viewing instruction, obtains the viewing method contained therein, and encapsulates the target query result according to the viewing method to obtain the encapsulated result. Then, it sends the encapsulated result to the client via a full-duplex communication protocol.
[0114] The viewing method in the command can be online browsing, local file download, or other feasible methods; no specific restrictions are made here.
[0115] It should be understood that the encapsulation method varies depending on the viewing method. For example, when viewing online, the data can be segmented and each segment can be encapsulated into a browsing page and sent to the client. Or, when viewing offline, the target query results can be stored in a file with a preset format (e.g., an Excel file) and provided to the client for download.
[0116] In this embodiment, after receiving the viewing instruction from the client, the target query result is encapsulated according to the viewing method contained in the viewing instruction, and the encapsulated result is sent to the client. This enables data transmission and result display according to the client's needs, which helps to improve the display efficiency of the target query result.
[0117] Furthermore, based on the viewing method specified in the viewing command, the data of the target query result is encapsulated to obtain the encapsulated result, which includes:
[0118] If the viewing method specified in the command is online data viewing, an initial preview page will be generated, and a preset number of target query results will be encapsulated into the initial preview page.
[0119] Specifically, when the viewing method in the command is online data viewing, the target query results are divided into segments according to a preset number, and each segment result is encapsulated into a preview page. The first preset page is sent to the client as the initial preview page. The client can send a page turning command to the server through the client's previous page and next page buttons. After receiving the page turning command, the server sends the preview page corresponding to the page turning command to the client.
[0120] The preset quantity can be set according to actual needs. Preferably, in this embodiment, the preset quantity is 30.
[0121] In this embodiment, when viewing data online, an initial preview page is generated by encapsulating a preset number of target query results, which avoids memory overflow caused by excessive data volume and helps improve the efficiency of data viewing.
[0122] In some optional implementations of this embodiment, after step S50, the database data query method further includes:
[0123] Generate statistical records of the target query results;
[0124] Establish a mapping relationship between user information, query statements, and statistical records, and store the mapping relationship in the query record database;
[0125] If a permission verification request is received from the management terminal, the user identifier contained in the permission verification request is obtained, and the mapping relationship corresponding to the user identifier is obtained from the query record database. The mapping relationship is then sent to the management terminal.
[0126] Specifically, for security reasons, the management side will verify the query records of each database on the server side according to actual needs to ensure the security of database data queries. After each target query result is sent to the client, the server generates a statistical record of the target query result and establishes a mapping relationship between user information, query statement and statistical record, and stores the mapping relationship in the query record database. When the management side verifies the query record, it obtains the user identifier contained in the permission verification request and uses the query record database to obtain the corresponding mapping relationship of the user identifier. Then, it can quickly verify the query record corresponding to the user information based on the mapping relationship, thereby improving the efficiency of permission verification.
[0127] It should be noted that each user identifier can have 0, 1, or multiple mapping relationships.
[0128] In this embodiment, statistical records of the target query results are generated, a mapping relationship between user information, query statements, and statistical records is established, and the mapping relationship is stored in the query record database. When a permission verification request is received from the management terminal, the user identifier contained in the permission verification request is obtained, and the mapping relationship corresponding to the user identifier is obtained from the query record database. The mapping relationship is then sent to the management terminal so that the management terminal can quickly verify the data query of the database based on the mapping relationship, thereby ensuring the security of the database data query.
[0129] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0130] Figure 3 A schematic block diagram of a database query device is shown, corresponding one-to-one with the database query method described in the above embodiments. For example... Figure 3As shown, the data query device for this database includes a connection building module 31, a request retrieval module 32, an initial query module 33, a result filtering module 34, and a result transmission module 35. Detailed descriptions of each functional module are as follows:
[0131] Connection building module 31 is used to establish a WebSocket connection with the client and build a full-duplex communication protocol based on the WebSocket connection;
[0132] The request retrieval module 32 is used to retrieve the user information, query statement and target database contained in the query request if a data query request is received from the client.
[0133] The initial query module 33 is used to execute query statements on the target database and obtain initial query results;
[0134] The result filtering module 34 is used to obtain the initial query results corresponding to the user's permission information based on preset permission conditions, and use them as the target query results.
[0135] The result transmission module 35 is used to send the target query result to the client via a full-duplex communication protocol.
[0136] Furthermore, the initial query module 31 includes:
[0137] The query execution unit is used to execute query statements on the target database so that the target database performs query processing based on the query statements.
[0138] The modification prompt generation unit is used to obtain the error code contained in the message if a query failure message is detected, analyze the error code, and generate a statement modification prompt for the query statement sent by the client.
[0139] The modification prompt sending unit is used to send statement modification prompts to the client so that the client user can modify the query statement according to the statement modification prompts, obtain the corrected statement, and send the corrected statement to the server;
[0140] The query statement update unit is used to receive correction statements sent by the client, and to process the query using the correction statements to obtain the initial query results.
[0141] Furthermore, the data query device for this database also includes:
[0142] The logging module is used to generate a basic index for the target query results and record the basic index in the log file;
[0143] The allocation module is used to shard the data in the target query results according to preset values based on the basic index and predefined types in the log file, and store the sharded data in ElasticSearch;
[0144] The read module is used to read sharded data from Elasticsearch according to the base index in the log file when data is exported, and use the sharded data as the target query result to be sent to the client.
[0145] Furthermore, the result transmission module 35 includes:
[0146] The instruction receiving unit is used to receive viewing instructions sent by the client;
[0147] The data encapsulation unit is used to encapsulate the data of the target query result according to the viewing method in the viewing instruction, and obtain the encapsulation result;
[0148] The result sending unit is used to send the encapsulated result to the client via a full-duplex communication protocol.
[0149] Furthermore, the data encapsulation unit includes:
[0150] The data viewing subunit is used to generate an initial preview page and encapsulate a preset number of target query results into the initial preview page if the viewing method in the viewing instruction is online data viewing.
[0151] Furthermore, the data query methods for this database also include:
[0152] The record generation module is used to generate statistical records of the target query results;
[0153] The mapping establishment module is used to establish the mapping relationship between user information, query statements and statistical records, and store the mapping relationship in the query record database;
[0154] The permission verification module is used to obtain the user identifier contained in the permission verification request when it receives a permission verification request from the management terminal, retrieve the mapping relationship corresponding to the user identifier from the query record database, and send the mapping relationship to the management terminal.
[0155] Specific limitations regarding the database query device can be found in the limitations of the database query method described above, and will not be repeated here. Each module in the aforementioned database query device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in the computer device in hardware form, or stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0156] To address the aforementioned technical problems, embodiments of this application also provide a computer device. Please refer to [link / reference needed]. Figure 4 , Figure 4 This is a basic structural block diagram of the computer device in this embodiment.
[0157] The computer device 4 includes a memory 41, a processor 42, and a network interface 43 that are interconnected via a system bus. It should be noted that only the computer device 4 with components connected to the memory 41, processor 42, and network interface 43 is shown in the figure; however, it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented alternatively. Those skilled in the art will understand that the computer device described here is a device capable of automatically performing numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes, but is not limited to, microprocessors, application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), digital signal processors (DSPs), embedded devices, etc.
[0158] The computer device can be a desktop computer, laptop, handheld computer, or cloud server, etc. The computer device can interact with the user via a keyboard, mouse, remote control, touchpad, or voice control.
[0159] The memory 41 includes at least one type of readable storage medium, including flash memory, hard disk, multimedia card, card-type memory (e.g., SD or D-interface display memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 41 may be an internal storage unit of the computer device 4, such as the hard disk or memory of the computer device 4. In other embodiments, the memory 41 may also be an external storage device of the computer device 4, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the computer device 4. Of course, the memory 41 may include both the internal storage unit and its external storage device of the computer device 4. In this embodiment, the memory 41 is typically used to store the operating system and various application software installed on the computer device 4, such as program code for controlling electronic documents. In addition, the memory 41 can also be used to temporarily store various types of data that have been output or will be output.
[0160] In some embodiments, the processor 42 may be a central processing unit (CPU), controller, microcontroller, microprocessor, or other data processing chip. The processor 42 is typically used to control the overall operation of the computer device 4. In this embodiment, the processor 42 is used to run program code stored in the memory 41 or process data, such as program code controlling electronic documents.
[0161] The network interface 43 may include a wireless network interface or a wired network interface, which is typically used to establish communication connections between the computer device 4 and other electronic devices.
[0162] This application also provides another embodiment, namely, a computer-readable storage medium storing an interface display program that can be executed by at least one processor to cause the at least one processor to perform the steps of the electronic document control method described above.
[0163] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0164] Obviously, the embodiments described above are only some embodiments of this application, not all embodiments. The accompanying drawings show preferred embodiments of this application, but do not limit the patent scope of this application. This application can be implemented in many different forms; rather, the purpose of providing these embodiments is to provide a more thorough and comprehensive understanding of the disclosure of this application. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing specific embodiments, or make equivalent substitutions for some of the technical features. Any equivalent structures made using the content of this application's specification and drawings, directly or indirectly applied to other related technical fields, are similarly within the scope of patent protection of this application.
Claims
1. A data query method for a database, characterized in that, The data query methods for the database include: Establish a WebSocket connection with the client, and build a full-duplex communication protocol based on the WebSocket connection; If a data query request is received from a client, the user information, query statement, and target database contained in the query request are obtained. The query statement is executed on the target database to obtain initial query results; Based on preset permission conditions, obtain the initial query results corresponding to the user's permission information, and use them as the target query results; The target query result is sent to the client via the full-duplex communication protocol. Among them, user information refers to the identification information that identifies the user, query statement refers to the string used to query the database, and target database refers to the identifier of the database to be queried. When performing database queries, you can set either a table-sharded viewing method or a download-based viewing method. Table-sharded viewing means dividing the target query results into multiple shard tables and sending one shard table to the client at a time. Download-based viewing means saving the target query results to a file with a preset format, which the client can then download and view offline. The step of executing the query statement on the target database to obtain the initial query results includes: The query statement is executed on the target database so that the target database performs query processing based on the query statement; If a query failure message is detected, the error code contained in the message is obtained, the error code is analyzed, and a query modification prompt is generated for the query statement sent by the client. The statement modification prompt is sent to the client so that the client user can modify the query statement according to the statement modification prompt, obtain the corrected statement, and send the corrected statement to the server; Receive the correction statement sent by the client, and use the correction statement to perform query processing to obtain the initial query result; The database data query method further includes, after obtaining the initial query result corresponding to the user permission information according to preset permission conditions and before sending the target query result to the client via the full-duplex communication protocol: For the target query results, a basic index is generated and recorded in a log file; Using the base index and predefined types in the log file, the data in the target query result is sharded according to preset values, and the sharded data is stored in ElasticSearch; When data is exported, the sharded data is read from the ElasticSearch according to the base index in the log file, and the sharded data is used as the target query result to be sent to the client; The predefined type is specifically the dat type.
2. The database data query method as described in claim 1, characterized in that, Sending the target query result to the client via the full-duplex communication protocol includes: Receive the viewing command sent by the client; According to the viewing method in the viewing instruction, the data of the target query result is encapsulated to obtain the encapsulation result; The encapsulation result is sent to the client via the full-duplex communication protocol.
3. The database data query method as described in claim 2, characterized in that, The step of encapsulating the data of the target query result according to the viewing method in the viewing instruction to obtain the encapsulation result includes: If the viewing method in the viewing instruction is online data viewing, an initial preview page is generated, and a preset number of target query results are obtained and packaged into the initial preview page.
4. The database data query method according to any one of claims 1 to 3, characterized in that, After sending the target query result to the client via the full-duplex communication protocol, the database data query method further includes: Generate statistical records of the target query results; Establish a mapping relationship between the user information, the query statement, and the statistical records, and store the mapping relationship in the query record database; If a permission verification request is received from the management terminal, the user identifier contained in the permission verification request is obtained, and the mapping relationship corresponding to the user identifier is obtained from the query record database, and the mapping relationship is sent to the management terminal.
5. A data query device for a database, characterized in that, The database query device includes: A connection building module is used to establish a WebSocket connection with the client and build a full-duplex communication protocol based on the WebSocket connection; The request acquisition module is used to acquire user information, query statement and target database contained in the query request if a data query request is received from the client. The initial query module is used to execute the query statement on the target database to obtain initial query results; The result filtering module is used to obtain the initial query results corresponding to the user's permission information based on preset permission conditions, and use them as the target query results. The result transmission module is used to send the target query result to the client via the full-duplex communication protocol; Among them, user information refers to the identification information that identifies the user, query statement refers to the string used to query the database, and target database refers to the identifier of the database to be queried. When performing database queries, you can set either a table-sharded viewing method or a download-based viewing method. Table-sharded viewing means dividing the target query results into multiple shard tables and sending one shard table to the client at a time. Download-based viewing means saving the target query results to a file with a preset format, which the client can then download and view offline. The initial query module includes: The query execution unit is used to execute query statements on the target database so that the target database performs query processing based on the query statements. The modification prompt generation unit is used to obtain the error code contained in the message if a query failure message is detected, analyze the error code, and generate a statement modification prompt for the query statement sent by the client. The modification prompt sending unit is used to send statement modification prompts to the client so that the client user can modify the query statement according to the statement modification prompts, obtain the corrected statement, and send the corrected statement to the server; The query statement update unit is used to receive the correction statement sent by the client, and to use the correction statement to perform query processing to obtain the initial query results; The data query device for this database also includes: The logging module is used to generate a basic index for the target query results and record the basic index in the log file; The allocation module is used to shard the data in the target query results according to preset values based on the basic index and predefined types in the log file, and store the sharded data in ElasticSearch; The read module is used to read sharded data from Elasticsearch according to the base index in the log file when data is exported, and use the sharded data as the target query result to be sent to the client; The predefined type is specifically the dat type.
6. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the database data query method as described in any one of claims 1 to 4.
7. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the database data query method as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Data query method and device
CN107741937A
Internet of things communication method and device
CN108616606A
Log processing system
CN109902072A