CN112948418A - Dynamic query method, device, equipment and storage medium - Google Patents

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

Info

Publication number
CN112948418A
CN112948418A CN202110214284.4A CN202110214284A CN112948418A CN 112948418 A CN112948418 A CN 112948418A CN 202110214284 A CN202110214284 A CN 202110214284A CN 112948418 A CN112948418 A CN 112948418A
Authority
CN
China
Prior art keywords
variable
instruction
acquiring
database
dynamic query
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
CN202110214284.4A
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.)
Ping An Puhui Enterprise Management Co Ltd
Original Assignee
Ping An Puhui Enterprise Management 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 Ping An Puhui Enterprise Management Co Ltd filed Critical Ping An Puhui Enterprise Management Co Ltd
Priority to CN202110214284.4A priority Critical patent/CN112948418A/en
Publication of CN112948418A publication Critical patent/CN112948418A/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/242Query formulation
    • G06F16/2433Query languages
    • G06F16/2445Data retrieval commands; View definitions
    • 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
    • G06F16/24553Query execution of query operations

Landscapes

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

Abstract

The invention relates to data processing and provides a dynamic query method, a dynamic query device, dynamic query equipment and a storage medium. The method includes the steps of determining a database to be queried according to a dynamic query request, obtaining a configuration file of the database to be queried, reading each instruction in the configuration file, analyzing the read instruction to obtain a variable and a variable expression of each instruction, obtaining a demand list according to the dynamic query request, extracting a variable value corresponding to the variable from the demand list, generating a structured query statement according to the variable value and the variable expression if the variable value meets the variable expression, and executing the structured query statement in the database to be queried by utilizing a MyBatis framework to obtain a query result. The invention not only can solve the problem that the MyBatis framework can not directly execute the query statement with the conditional expression, but also can quickly and dynamically query data. In addition, the invention also relates to a block chain technology, and the query result can be stored in the block chain.

Description

Dynamic query method, device, equipment and storage medium
Technical Field
The present invention relates to the field of data processing technologies, and in particular, to a dynamic query method, apparatus, device, and storage medium.
Background
In the existing data query scheme with the conditional expression, query results can be obtained by executing query statements written by developers in a database, however, when new query requirements are added, the method needs the developers to rewrite the query statements according to the new query requirements, and is not beneficial to rapidly and dynamically querying data.
In addition, the MyBatis framework is free from almost all JDBC codes and the work of setting parameters and obtaining a result set, so that data results can be quickly obtained from a database by using the MyBatis framework, however, since the conditional expression cannot be directly copied after the MyBatis framework is started, the MyBatis framework cannot directly execute a query statement with the conditional expression.
Disclosure of Invention
In view of the above, it is necessary to provide a dynamic query method, apparatus, device and storage medium, which can not only solve the problem that the MyBatis framework cannot directly execute a query statement with a conditional expression, but also quickly and dynamically query data.
In one aspect, the present invention provides a dynamic query method, where the dynamic query method includes:
when a dynamic query request is received, determining a database to be queried according to the dynamic query request;
acquiring a configuration file of the database to be queried;
reading each instruction in the configuration file, and analyzing the read instruction to obtain a variable of each instruction and a variable expression of each instruction;
acquiring a demand list according to the dynamic query request, and extracting variable values corresponding to the variables from the demand list;
detecting whether the variable value satisfies the variable expression;
if the variable value meets the variable expression, generating a structured query statement according to the variable value and the variable expression;
and executing the structured query statement in the database to be queried by utilizing a MyBatis framework to obtain a query result.
According to a preferred embodiment of the present invention, the determining a database to be queried according to the dynamic query request includes:
acquiring a sending address of the dynamic query request, and determining sending equipment according to the sending address;
acquiring the receiving time of the dynamic query request, and acquiring a target log from the sending equipment according to the receiving time;
determining the executing user on the target log as a sending user of the dynamic query request;
and acquiring a database corresponding to the sending user from a preset user list as the database to be inquired.
According to the preferred embodiment of the present invention, the obtaining the sending address of the dynamic query request includes:
analyzing the message header of the dynamic query request to obtain address information carried by the message header;
acquiring a preset label, wherein the preset label is used for indicating an address for sending a request;
and acquiring information corresponding to the preset label from the address information as the sending address.
According to the preferred embodiment of the present invention, before obtaining the configuration file of the database to be queried, the dynamic query method further includes:
acquiring all parameters from the database to be queried and acquiring the parameter condition of each parameter;
generating an initial statement according to each parameter and each parameter condition;
acquiring a configuration template of the MyBatis framework;
writing the initial statement into the configuration template to obtain a query instruction corresponding to each parameter;
and fusing the query instruction to obtain the configuration file.
According to a preferred embodiment of the present invention, the parsing the read instructions to obtain the variable of each instruction and the variable expression of each instruction includes:
analyzing the instruction to obtain a node label carried in the instruction;
acquiring a node attribute corresponding to the node label;
acquiring information corresponding to the node attribute from the instruction as the variable expression;
and extracting characters which are the same as any parameter in all the parameters from the variable expression to serve as the variables.
According to a preferred embodiment of the present invention, the obtaining the requirement list according to the dynamic query request includes:
analyzing the message of the dynamic query request to obtain the data information carried by the message;
acquiring information indicating a file address from the data information as a storage position;
acquiring the generation time of all lists in the storage position, and acquiring the current time;
calculating the time difference between the generation time and the current time to obtain the interval time corresponding to each list;
and determining the list with the largest interval time as the demand list.
According to a preferred embodiment of the present invention, the generating a structured query statement according to the variable value and the variable expression comprises:
acquiring an instruction corresponding to the variable expression from the configuration file as a target instruction;
acquiring configuration characters, wherein the configuration characters are used for indicating a screening statement with a conditional expression;
obtaining a sentence corresponding to the configuration character from the target instruction as a target sentence;
and replacing the variable expression with the variable value in the target statement to obtain the structured query statement.
In another aspect, the present invention further provides a dynamic query apparatus, where the dynamic query apparatus includes:
the device comprises a determining unit, a query unit and a query unit, wherein the determining unit is used for determining a database to be queried according to a dynamic query request when the dynamic query request is received;
the acquisition unit is used for acquiring the configuration file of the database to be queried;
the analysis unit is used for reading each instruction in the configuration file and analyzing the read instruction to obtain a variable of each instruction and a variable expression of each instruction;
the extraction unit is used for acquiring a demand list according to the dynamic query request and extracting variable values corresponding to the variables from the demand list;
a detecting unit for detecting whether the variable value satisfies the variable expression;
the generating unit is used for generating a structured query statement according to the variable value and the variable expression if the variable value meets the variable expression;
and the execution unit is used for executing the structured query statement in the database to be queried by utilizing a MyBatis framework to obtain a query result.
In another aspect, the present invention further provides an electronic device, including:
a memory storing computer readable instructions; and
a processor executing computer readable instructions stored in the memory to implement the dynamic query method.
In another aspect, the present invention further provides a computer-readable storage medium, in which computer-readable instructions are stored, and the computer-readable instructions are executed by a processor in an electronic device to implement the dynamic query method.
It can be seen from the above technical solutions that, in the present invention, the database to be queried can be accurately determined through the dynamic query request, and the configuration file to be analyzed can be accurately obtained, because a plurality of instructions with conditional expressions are pre-stored in the configuration file, variables of each instruction and variable expressions of each instruction can be accurately obtained by analyzing each instruction in the configuration file, and the variable values can be accurately extracted from a requirement list through the variables, further, because a statement generated when the variable value does not satisfy the variable expression cannot obtain a query result from the database to be queried, the structured query statement is generated when the variable value satisfies the variable expression, which is beneficial for generating the query result, meanwhile, the generated structured query statement does not contain a conditional expression, so that the direct execution of the structured query statement by a MyBatis framework is facilitated. In addition, the structured query statement is executed by utilizing the MyBatis framework, and the query statement does not need to be manually written by developers when new query needs to be obtained, so that the query efficiency of the query result can be doubly improved.
Drawings
FIG. 1 is a flow chart of a preferred embodiment of the dynamic query method of the present invention.
FIG. 2 is a flow diagram of one embodiment of the present invention for determining a database to query.
FIG. 3 is a flow diagram of one embodiment of the present invention for generating a structured query statement.
FIG. 4 is a functional block diagram of a preferred embodiment of the dynamic query apparatus of the present invention.
FIG. 5 is a schematic structural diagram of an electronic device implementing the dynamic query method according to the preferred embodiment of the invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention will be described in detail with reference to the accompanying drawings and specific embodiments.
FIG. 1 is a flow chart of a preferred embodiment of the dynamic query method of the present invention. The order of the steps in the flow chart may be changed and some steps may be omitted according to different needs.
The dynamic query method is applied to one or more electronic devices, which are devices capable of automatically performing numerical calculation and/or information processing according to computer readable instructions set or stored in advance, and the hardware thereof includes, but is not limited to, a microprocessor, an Application Specific Integrated Circuit (ASIC), a Programmable Gate Array (FPGA), a Digital Signal Processor (DSP), an embedded device, and the like.
The electronic device may be any electronic product capable of performing human-computer interaction with a user, for example, a Personal computer, a tablet computer, a smart phone, a Personal Digital Assistant (PDA), a game machine, an interactive Internet Protocol Television (IPTV), a smart wearable device, and the like.
The electronic device may include a network device and/or a user device. Wherein the network device includes, but is not limited to, a single network electronic device, an electronic device group consisting of a plurality of network electronic devices, or a Cloud Computing (Cloud Computing) based Cloud consisting of a large number of hosts or network electronic devices.
The network in which the electronic device is located includes, but is not limited to: the internet, a wide area Network, a metropolitan area Network, a local area Network, a Virtual Private Network (VPN), and the like.
S10, when receiving the dynamic query request, determining the database to be queried according to the dynamic query request.
In at least one embodiment of the present invention, the information carried by the dynamic query request includes, but is not limited to: a transmission address, a storage location, etc. The dynamic query request may be triggered by any user.
The database to be queried is a database which needs to be dynamically queried, and the database to be queried can be queried by any user.
Referring to fig. 2, fig. 2 is a flow chart of an embodiment of the present invention for determining a database to be queried. In at least one embodiment of the present invention, the electronic device determining a database to be queried according to the dynamic query request includes:
s100, acquiring a sending address of the dynamic query request, and determining sending equipment according to the sending address.
Specifically, the obtaining, by the electronic device, the sending address of the dynamic query request includes:
analyzing the message header of the dynamic query request to obtain address information carried by the message header;
acquiring a preset label, wherein the preset label is used for indicating an address for sending a request;
and acquiring information corresponding to the preset label from the address information as the sending address.
With the above embodiment, since it is not necessary to analyze the entire dynamic query request, the efficiency of acquiring the address information can be improved, and the efficiency of acquiring the transmission address can be improved.
Specifically, the electronic device determines a device corresponding to the transmission address as the transmission device.
The sending address can be an IP address uniquely identifying the device, and the sending address can uniquely identify the device, so that the sending device can be accurately determined according to the sending address.
S101, obtaining the receiving time of the dynamic query request, and obtaining a target log from the sending device according to the receiving time.
Wherein the receiving time refers to a time when the electronic device receives the dynamic query request.
The target log stores a user main body for executing operation.
Specifically, the electronic device calculates a difference between the receiving time and the configuration time to obtain a target time, further determines a time interval according to the target time and the receiving time, and further screens, from a log list of the sending device, a log with a log execution time in the time interval as the target log.
By the implementation mode, the target log can be quickly acquired from the sending equipment.
S102, determining the executing user on the target log as the sending user of the dynamic query request.
S103, acquiring a database corresponding to the sending user from a preset user list as the database to be inquired.
And the preset user list stores the mapping relation between the user and a database which is managed by the user.
The sending device can be accurately determined through the sending address, the sending log of the dynamic query request can be accurately obtained from the sending device according to the receiving time, the sending user can be accurately determined from the sending log, and therefore the database to be queried can be accurately determined.
And S11, acquiring the configuration file of the database to be queried.
In at least one embodiment of the invention, the configuration file may be a mapper xml file. The configuration file stores a plurality of parameter variables in the database to be queried, for example, the parameter variables may include dates and the like.
In at least one embodiment of the present invention, before obtaining the configuration file of the database to be queried, the method further includes:
acquiring all parameters from the database to be queried and acquiring the parameter condition of each parameter;
generating an initial statement according to each parameter and each parameter condition;
acquiring a configuration template of a MyBatis framework;
writing the initial statement into the configuration template to obtain a query instruction corresponding to each parameter;
and fusing the query instruction to obtain the configuration file.
The parameter condition refers to a conditional expression including any parameter of all the parameters.
The initial statement may refer to a structured query statement with a conditional expression.
The configuration template refers to a preset template supporting the execution of the MyBatis framework, and the configuration template stores operation information with query operation, for example, the configuration template includes select. The format of the configuration file is a mapper xml format.
Through the implementation mode, all parameters in the database to be queried can be provided in the configuration file, and the configuration file is further favorable for generating the query statement subsequently.
Specifically, the fusing the query instruction to obtain the configuration file includes:
determining the generation sequence of the query instructions;
and fusing the query instructions according to the sequence from small to large of the generation sequence to obtain the configuration file.
In at least one embodiment of the present invention, the acquiring, by the electronic device, the configuration file of the database to be queried includes:
determining a database identifier of the database to be queried;
and acquiring a file corresponding to the database identifier from a preset configuration library as the configuration file.
The preset configuration library stores mapping relations between the identifiers of the indication databases and the configuration files.
Specifically, the electronic device obtains the database identifier from the database to be queried.
The configuration file can be accurately acquired from the configuration library through the database identification.
And S12, reading each instruction in the configuration file, and analyzing the read instruction to obtain a variable of each instruction and a variable expression of each instruction.
In at least one embodiment of the present invention, each instruction in the configuration file includes a node tag, the variable, and the variable expression. The variable expression may be a conditional expression corresponding to the variable.
For example, the variable may be a date, and accordingly, the variable expression may be that the date is not null.
In at least one embodiment of the present invention, the analyzing, by the electronic device, the read instructions to obtain the variable of each instruction and the variable expression of each instruction includes:
analyzing the instruction to obtain a node label carried in the instruction;
acquiring a node attribute corresponding to the node label;
acquiring information corresponding to the node attribute from the instruction as the variable expression;
and extracting characters which are the same as any parameter in all the parameters from the variable expression to serve as the variables.
The node tag may be if, and the node tag may also be foreach.
The node attribute refers to an attribute corresponding to the node tag, and for example, when the node tag is if, the node attribute may be a test attribute.
The instruction is analyzed, the node label can be rapidly obtained, the node attribute can be accurately determined through the mapping relation between the node label and the attribute, the variable expression can be accurately obtained from the instruction by utilizing the node attribute, and the variable can be accurately extracted from the variable expression by comparing the variable expression with all the parameters.
And S13, acquiring a demand list according to the dynamic query request, and extracting variable values corresponding to the variables from the demand list.
In at least one embodiment of the present invention, the requirement list stores a plurality of requirements for querying the database to be queried.
In at least one embodiment of the present invention, the obtaining, by the electronic device, the requirement list according to the dynamic query request includes:
analyzing the message of the dynamic query request to obtain the data information carried by the message;
acquiring information indicating a file address from the data information as a storage position;
acquiring the generation time of all lists in the storage position, and acquiring the current time;
calculating the time difference between the generation time and the current time to obtain the interval time corresponding to each list;
and determining the list with the largest interval time as the demand list.
Wherein the storage location stores a plurality of lists, each list having a corresponding generation time.
According to the embodiment, the data information can be quickly acquired and the storage position can be quickly acquired without analyzing the whole dynamic query request, and the list with the maximum generation time is determined as the demand list due to the fact that a plurality of lists exist in the storage position and the newly added characteristic of the query demand, so that the accuracy of the demand list is improved.
S14, detecting whether the variable value satisfies the variable expression.
In at least one embodiment of the present invention, the electronic device detects whether the variable value satisfies the variable expression, for example, the variable value is X ═ 15, the variable expression is X >1, and since 15>1, the electronic device determines that the variable value satisfies the variable expression.
In at least one embodiment of the present invention, if the variable value does not satisfy the variable expression, an alert message is generated, and the alert message is sent to the terminal that triggered the dynamic query request.
Through the implementation mode, when the variable value does not meet the variable expression, the user triggering the dynamic query request can be notified in time.
And S15, if the variable value meets the variable expression, generating a structured query statement according to the variable value and the variable expression.
In at least one embodiment of the invention, the structured query statement refers to a query statement without the variable expression.
Referring to FIG. 3, FIG. 3 is a flow diagram of one embodiment of the present invention for generating a structured query statement. In at least one embodiment of the present invention, the electronic device generating the structured query statement according to the variable value and the variable expression comprises:
and S150, acquiring the instruction corresponding to the variable expression from the configuration file as a target instruction.
Wherein, the target instruction comprises a plurality of statements.
Specifically, the electronic device traverses the instructions in the configuration file by using the variable expression, and determines the traversed instruction containing the variable expression as the target instruction.
S151, obtaining configuration characters, wherein the configuration characters are used for indicating screening sentences with conditional expressions.
The configuration characters may be arbitrarily configured.
S152, obtaining the sentence corresponding to the configuration character from the target instruction as a target sentence.
Specifically, the electronic device traverses the sentence in the target instruction by using the configuration character, and determines the traversed sentence containing the configuration character as the target sentence.
S153, replacing the variable expression with the variable value in the target statement to obtain the structured query statement.
By the above embodiment, since it is not necessary to rewrite the frame of the structured query statement, the efficiency of generating the structured query statement can be improved, and in addition, since the variable expression is replaced by the variable value, the generated structured query statement does not have the variable expression, which is beneficial to the MyBatis frame to execute the structured query statement.
And S16, executing the structured query statement in the database to be queried by using the MyBatis framework to obtain a query result.
It is emphasized that, in order to further ensure the privacy and security of the query result, the query result may also be stored in a node of a blockchain.
In at least one embodiment of the present invention, the query result includes data information that is found by the electronic device from the database to be queried by using the structured query statement.
In at least one embodiment of the present invention, it is prior art that the electronic device executes the structured query statement by using the MyBatis framework, and details of this are not repeated in the present invention.
In at least one embodiment of the invention, after obtaining the query result, the method further comprises:
acquiring a request number of the dynamic query request;
generating prompt information according to the request number and the query result;
encrypting the prompt information by adopting a symmetric encryption technology to obtain a ciphertext;
and sending the ciphertext to a trigger terminal of the dynamic query request.
The triggering terminal is a terminal which triggers the generation of the dynamic query request.
By the implementation mode, the trigger user of the dynamic query request can be notified in time after the query result is obtained.
It can be seen from the above technical solutions that, in the present invention, the database to be queried can be accurately determined through the dynamic query request, and the configuration file to be analyzed can be accurately obtained, because a plurality of instructions with conditional expressions are pre-stored in the configuration file, variables of each instruction and variable expressions of each instruction can be accurately obtained by analyzing each instruction in the configuration file, and the variable values can be accurately extracted from a requirement list through the variables, further, because a statement generated when the variable value does not satisfy the variable expression cannot obtain a query result from the database to be queried, the structured query statement is generated when the variable value satisfies the variable expression, which is beneficial for generating the query result, meanwhile, the generated structured query statement does not contain a conditional expression, so that the direct execution of the structured query statement by a MyBatis framework is facilitated. In addition, the structured query statement is executed by utilizing the MyBatis framework, and the query statement does not need to be manually written by developers when new query needs to be obtained, so that the query efficiency of the query result can be doubly improved.
Fig. 4 is a functional block diagram of a preferred embodiment of the dynamic query apparatus according to the present invention. The dynamic querying device 11 includes a determining unit 110, an obtaining unit 111, an analyzing unit 112, an extracting unit 113, a detecting unit 114, a generating unit 115, an executing unit 116, a writing unit 117, a fusing unit 118, an encrypting unit 119, and a sending unit 120. The module/unit referred to herein is a series of computer readable instruction segments that can be accessed by the processor 13 and perform a fixed function and that are stored in the memory 12. In the present embodiment, the functions of the modules/units will be described in detail in the following embodiments.
When receiving a dynamic query request, the determining unit 110 determines a database to be queried according to the dynamic query request.
In at least one embodiment of the present invention, the information carried by the dynamic query request includes, but is not limited to: a transmission address, a storage location, etc. The dynamic query request may be triggered by any user.
The database to be queried is a database which needs to be dynamically queried, and the database to be queried can be queried by any user.
In at least one embodiment of the present invention, the determining unit 110 determines the database to be queried according to the dynamic query request includes:
acquiring a sending address of the dynamic query request, and determining sending equipment according to the sending address;
acquiring the receiving time of the dynamic query request, and acquiring a target log from the sending equipment according to the receiving time;
determining the executing user on the target log as a sending user of the dynamic query request;
and acquiring a database corresponding to the sending user from a preset user list as the database to be inquired.
Specifically, the obtaining, by the determining unit 110, the sending address of the dynamic query request includes:
analyzing the message header of the dynamic query request to obtain address information carried by the message header;
acquiring a preset label, wherein the preset label is used for indicating an address for sending a request;
and acquiring information corresponding to the preset label from the address information as the sending address.
With the above embodiment, since it is not necessary to analyze the entire dynamic query request, the efficiency of acquiring the address information can be improved, and the efficiency of acquiring the transmission address can be improved.
Specifically, the determination unit 110 determines a device corresponding to the transmission address as the transmission device.
The sending address can be an IP address uniquely identifying the device, and the sending address can uniquely identify the device, so that the sending device can be accurately determined according to the sending address.
And the preset user list stores the mapping relation between the user and a database which is managed by the user.
The sending device can be accurately determined through the sending address, the sending log of the dynamic query request can be accurately obtained from the sending device according to the receiving time, the sending user can be accurately determined from the sending log, and therefore the database to be queried can be accurately determined.
The obtaining unit 111 obtains the configuration file of the database to be queried.
In at least one embodiment of the invention, the configuration file may be a mapper xml file. The configuration file stores a plurality of parameter variables in the database to be queried, for example, the parameter variables may include dates and the like.
In at least one embodiment of the present invention, before acquiring the configuration file of the database to be queried, the acquiring unit 111 acquires all parameters from the database to be queried, and acquires a parameter condition of each parameter;
the generation unit 115 generates an initial sentence from each parameter and each parameter condition;
the obtaining unit 111 obtains a configuration template of the MyBatis frame;
the writing unit 117 writes the initial statement into the configuration template to obtain a query instruction corresponding to each parameter;
the fusion unit 118 fuses the query instruction to obtain the configuration file.
Wherein the initial statement may refer to a structured query statement with a conditional expression.
Through the implementation mode, all parameters in the database to be queried can be provided in the configuration file, and the configuration file is further favorable for generating the query statement subsequently.
In at least one embodiment of the present invention, the obtaining unit 111 obtains the configuration file of the database to be queried, where the obtaining unit includes:
determining a database identifier of the database to be queried;
and acquiring a file corresponding to the database identifier from a configuration library as the configuration file.
The parsing unit 112 reads each instruction in the configuration file, and parses the read instruction to obtain a variable of each instruction and a variable expression of each instruction.
In at least one embodiment of the present invention, the parsing unit 112 parses the read instructions to obtain the variable of each instruction and the variable expression of each instruction includes:
analyzing the instruction to obtain a node label carried in the instruction;
acquiring a node attribute corresponding to the node label;
acquiring information corresponding to the node attribute from the instruction as the variable expression;
and extracting characters which are the same as any parameter in all the parameters from the variable expression to serve as the variables.
The node tag may be if, and the node tag may also be foreach.
The node attribute refers to an attribute corresponding to the node tag, and for example, when the node tag is if, the node attribute may be a test attribute.
The instruction is analyzed, the node label can be rapidly obtained, the node attribute can be accurately determined through the mapping relation between the node label and the attribute, the variable expression can be accurately obtained from the instruction by utilizing the node attribute, and the variable can be accurately extracted from the variable expression by comparing the variable expression with all the parameters.
The extracting unit 113 obtains a requirement list according to the dynamic query request, and extracts a variable value corresponding to the variable from the requirement list.
In at least one embodiment of the present invention, the obtaining, by the extracting unit 113, the requirement list according to the dynamic query request includes:
analyzing the message of the dynamic query request to obtain the data information carried by the message;
acquiring information indicating a file address from the data information as a storage position;
acquiring the generation time of all lists in the storage position, and acquiring the current time;
calculating the time difference between the generation time and the current time to obtain the interval time corresponding to each list;
and determining the list with the largest interval time as the demand list.
According to the embodiment, the data information can be quickly acquired and the storage position can be quickly acquired without analyzing the whole dynamic query request, and the list with the maximum generation time is determined as the demand list due to the fact that a plurality of lists exist in the storage position and the newly added characteristic of the query demand, so that the accuracy of the demand list is improved.
The detection unit 114 detects whether the variable value satisfies the variable expression.
In at least one embodiment of the present invention, if the variable value does not satisfy the variable expression, the generating unit 115 generates warning information and sends the warning information to the terminal that triggers the dynamic query request.
Through the implementation mode, when the variable value does not meet the variable expression, the user triggering the dynamic query request can be notified in time.
If the variable value satisfies the variable expression, the generating unit 115 generates a structured query statement according to the variable value and the variable expression.
In at least one embodiment of the invention, the structured query statement refers to a query statement without the variable expression.
In at least one embodiment of the present invention, the generating unit 115 generates the structured query statement according to the variable value and the variable expression includes:
acquiring an instruction corresponding to the variable expression from the configuration file as a target instruction;
acquiring configuration characters, wherein the configuration characters are used for indicating a screening statement with a conditional expression;
obtaining a sentence corresponding to the configuration character from the target instruction as a target sentence;
and replacing the variable expression with the variable value in the target statement to obtain the structured query statement.
By the above embodiment, since it is not necessary to rewrite the frame of the structured query statement, the efficiency of generating the structured query statement can be improved, and in addition, since the variable expression is replaced by the variable value, the generated structured query statement does not have the variable expression, which is beneficial to the MyBatis frame to execute the structured query statement.
The execution unit 116 executes the structured query statement in the database to be queried by using the MyBatis framework, so as to obtain a query result.
It is emphasized that, in order to further ensure the privacy and security of the query result, the query result may also be stored in a node of a blockchain.
In at least one embodiment of the present invention, it is prior art that the executing unit 116 executes the structured query statement by using the MyBatis framework, and details of this are not repeated herein.
In at least one embodiment of the present invention, after obtaining the query result, the obtaining unit 111 obtains the request number of the dynamic query request;
the generating unit 115 generates prompt information according to the request number and the query result;
the encryption unit 119 encrypts the prompt message by using a symmetric encryption technology to obtain a ciphertext;
the sending unit 120 sends the ciphertext to the trigger terminal of the dynamic query request.
By the implementation mode, the trigger user of the dynamic query request can be notified in time after the query result is obtained.
It can be seen from the above technical solutions that, in the present invention, the database to be queried can be accurately determined through the dynamic query request, and the configuration file to be analyzed can be accurately obtained, because a plurality of instructions with conditional expressions are pre-stored in the configuration file, variables of each instruction and variable expressions of each instruction can be accurately obtained by analyzing each instruction in the configuration file, and the variable values can be accurately extracted from a requirement list through the variables, further, because a statement generated when the variable value does not satisfy the variable expression cannot obtain a query result from the database to be queried, the structured query statement is generated when the variable value satisfies the variable expression, which is beneficial for generating the query result, meanwhile, the generated structured query statement does not contain a conditional expression, so that the direct execution of the structured query statement by a MyBatis framework is facilitated. In addition, the structured query statement is executed by utilizing the MyBatis framework, and the query statement does not need to be manually written by developers when new query needs to be obtained, so that the query efficiency of the query result can be doubly improved.
Fig. 5 is a schematic structural diagram of an electronic device implementing the dynamic query method according to the preferred embodiment of the invention.
In one embodiment of the present invention, the electronic device 1 includes, but is not limited to, a memory 12, a processor 13, and computer readable instructions, such as a dynamic query program, stored in the memory 12 and executable on the processor 13.
It will be appreciated by a person skilled in the art that the schematic diagram is only an example of the electronic device 1 and does not constitute a limitation of the electronic device 1, and that it may comprise more or less components than shown, or some components may be combined, or different components, e.g. the electronic device 1 may further comprise an input output device, a network access device, a bus, etc.
The Processor 13 may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic device, discrete hardware component, etc. The processor 13 is an operation core and a control center of the electronic device 1, and is connected to each part of the whole electronic device 1 by various interfaces and lines, and executes an operating system of the electronic device 1 and various installed application programs, program codes, and the like.
Illustratively, the computer readable instructions may be partitioned into one or more modules/units that are stored in the memory 12 and executed by the processor 13 to implement the present invention. The one or more modules/units may be a series of computer readable instruction segments capable of performing specific functions, which are used for describing the execution process of the computer readable instructions in the electronic device 1. For example, the computer-readable instructions may be divided into a determination unit 110, an acquisition unit 111, a parsing unit 112, an extraction unit 113, a detection unit 114, a generation unit 115, an execution unit 116, a writing unit 117, a fusion unit 118, an encryption unit 119, and a transmission unit 120.
The memory 12 may be used for storing the computer readable instructions and/or modules, and the processor 13 implements various functions of the electronic device 1 by executing or executing the computer readable instructions and/or modules stored in the memory 12 and invoking data stored in the memory 12. The memory 12 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application program required by at least one function (such as a sound playing function, an image playing function, etc.), and the like; the storage data area may store data created according to use of the electronic device, and the like. The memory 12 may include non-volatile and volatile memories, such as: a hard disk, a memory, a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), at least one magnetic disk storage device, a Flash memory device, or other storage device.
The memory 12 may be an external memory and/or an internal memory of the electronic device 1. Further, the memory 12 may be a memory having a physical form, such as a memory stick, a TF Card (Trans-flash Card), or the like.
The integrated modules/units of the electronic device 1 may be stored in a computer-readable storage medium if they are implemented in the form of software functional units and sold or used as separate products. Based on such understanding, all or part of the flow of the method according to the above embodiments may be implemented by hardware that is configured to be instructed by computer readable instructions, which may be stored in a computer readable storage medium, and when the computer readable instructions are executed by a processor, the steps of the method embodiments may be implemented.
Wherein the computer readable instructions comprise computer readable instruction code which may be in source code form, object code form, an executable file or some intermediate form, and the like. The computer-readable medium may include: any entity or device capable of carrying said computer readable instruction code, recording medium, U-disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM).
The block chain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism, an encryption algorithm and the like. A block chain (Blockchain), which is essentially a decentralized database, is a series of data blocks associated by using a cryptographic method, and each data block contains information of a batch of network transactions, so as to verify the validity (anti-counterfeiting) of the information and generate a next block. The blockchain may include a blockchain underlying platform, a platform product service layer, an application service layer, and the like.
In conjunction with fig. 1, the memory 12 of the electronic device 1 stores computer-readable instructions to implement a dynamic querying method, and the processor 13 executes the computer-readable instructions to implement:
when a dynamic query request is received, determining a database to be queried according to the dynamic query request;
acquiring a configuration file of the database to be queried;
reading each instruction in the configuration file, and analyzing the read instruction to obtain a variable of each instruction and a variable expression of each instruction;
acquiring a demand list according to the dynamic query request, and extracting variable values corresponding to the variables from the demand list;
detecting whether the variable value satisfies the variable expression;
if the variable value meets the variable expression, generating a structured query statement according to the variable value and the variable expression;
and executing the structured query statement in the database to be queried by utilizing a MyBatis framework to obtain a query result.
Specifically, the processor 13 may refer to the description of the relevant steps in the embodiment corresponding to fig. 1 for a specific implementation method of the computer readable instructions, which is not described herein again.
In the embodiments provided in the present invention, it should be understood that the disclosed system, apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the modules is only one logical functional division, and other divisions may be realized in practice.
The computer readable storage medium has computer readable instructions stored thereon, wherein the computer readable instructions when executed by the processor 13 are configured to implement the steps of:
when a dynamic query request is received, determining a database to be queried according to the dynamic query request;
acquiring a configuration file of the database to be queried;
reading each instruction in the configuration file, and analyzing the read instruction to obtain a variable of each instruction and a variable expression of each instruction;
acquiring a demand list according to the dynamic query request, and extracting variable values corresponding to the variables from the demand list;
detecting whether the variable value satisfies the variable expression;
if the variable value meets the variable expression, generating a structured query statement according to the variable value and the variable expression;
and executing the structured query statement in the database to be queried by utilizing a MyBatis framework to obtain a query result.
The modules described as separate parts may or may not be physically separate, and parts displayed as modules may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
In addition, functional modules in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, or in a form of hardware plus a software functional module.
The present embodiments are therefore to be considered in all respects as illustrative and not restrictive, the scope of the invention being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any reference signs in the claims shall not be construed as limiting the claim concerned.
Furthermore, it is obvious that the word "comprising" does not exclude other elements or steps, and the singular does not exclude the plural. The plurality of units or devices may also be implemented by one unit or device through software or hardware. The terms first, second, etc. are used to denote names, but not any particular order.
Finally, it should be noted that the above embodiments are only for illustrating the technical solutions of the present invention and not for limiting, and although the present invention is described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that modifications or equivalent substitutions may be made on the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.

Claims (10)

1. A dynamic query method, comprising:
when a dynamic query request is received, determining a database to be queried according to the dynamic query request;
acquiring a configuration file of the database to be queried;
reading each instruction in the configuration file, and analyzing the read instruction to obtain a variable of each instruction and a variable expression of each instruction;
acquiring a demand list according to the dynamic query request, and extracting variable values corresponding to the variables from the demand list;
detecting whether the variable value satisfies the variable expression;
if the variable value meets the variable expression, generating a structured query statement according to the variable value and the variable expression;
and executing the structured query statement in the database to be queried by utilizing a MyBatis framework to obtain a query result.
2. The dynamic query method of claim 1, wherein said determining a database to be queried according to the dynamic query request comprises:
acquiring a sending address of the dynamic query request, and determining sending equipment according to the sending address;
acquiring the receiving time of the dynamic query request, and acquiring a target log from the sending equipment according to the receiving time;
determining the executing user on the target log as a sending user of the dynamic query request;
and acquiring a database corresponding to the sending user from a preset user list as the database to be inquired.
3. The dynamic query method of claim 2, wherein said obtaining the sending address of the dynamic query request comprises:
analyzing the message header of the dynamic query request to obtain address information carried by the message header;
acquiring a preset label, wherein the preset label is used for indicating an address for sending a request;
and acquiring information corresponding to the preset label from the address information as the sending address.
4. The dynamic query method of claim 1, wherein before obtaining the configuration file of the database to be queried, the dynamic query method further comprises:
acquiring all parameters from the database to be queried and acquiring the parameter condition of each parameter;
generating an initial statement according to each parameter and each parameter condition;
acquiring a configuration template of the MyBatis framework;
writing the initial statement into the configuration template to obtain a query instruction corresponding to each parameter;
and fusing the query instruction to obtain the configuration file.
5. The dynamic query method of claim 4, wherein said parsing the fetched instructions to obtain the variables of each instruction and the variable expressions of each instruction comprises:
analyzing the instruction to obtain a node label carried in the instruction;
acquiring a node attribute corresponding to the node label;
acquiring information corresponding to the node attribute from the instruction as the variable expression;
and extracting characters which are the same as any parameter in all the parameters from the variable expression to serve as the variables.
6. The dynamic query method of claim 1, wherein the obtaining the list of requirements according to the dynamic query request comprises:
analyzing the message of the dynamic query request to obtain the data information carried by the message;
acquiring information indicating a file address from the data information as a storage position;
acquiring the generation time of all lists in the storage position, and acquiring the current time;
calculating the time difference between the generation time and the current time to obtain the interval time corresponding to each list;
and determining the list with the largest interval time as the demand list.
7. The dynamic query method of claim 1, wherein said generating a structured query statement as a function of the variable value and the variable expression comprises:
acquiring an instruction corresponding to the variable expression from the configuration file as a target instruction;
acquiring configuration characters, wherein the configuration characters are used for indicating a screening statement with a conditional expression;
obtaining a sentence corresponding to the configuration character from the target instruction as a target sentence;
and replacing the variable expression with the variable value in the target statement to obtain the structured query statement.
8. A dynamic query apparatus, comprising:
the device comprises a determining unit, a query unit and a query unit, wherein the determining unit is used for determining a database to be queried according to a dynamic query request when the dynamic query request is received;
the acquisition unit is used for acquiring the configuration file of the database to be queried;
the analysis unit is used for reading each instruction in the configuration file and analyzing the read instruction to obtain a variable of each instruction and a variable expression of each instruction;
the extraction unit is used for acquiring a demand list according to the dynamic query request and extracting variable values corresponding to the variables from the demand list;
a detecting unit for detecting whether the variable value satisfies the variable expression;
the generating unit is used for generating a structured query statement according to the variable value and the variable expression if the variable value meets the variable expression;
and the execution unit is used for executing the structured query statement in the database to be queried by utilizing a MyBatis framework to obtain a query result.
9. An electronic device, characterized in that the electronic device comprises:
a memory storing computer readable instructions; and
a processor executing computer readable instructions stored in the memory to implement the dynamic query method of any of claims 1 to 7.
10. A computer-readable storage medium characterized by: the computer readable storage medium stores computer readable instructions, which are executed by a processor in an electronic device to implement the dynamic query method according to any one of claims 1 to 7.
CN202110214284.4A 2021-02-25 2021-02-25 Dynamic query method, device, equipment and storage medium Pending CN112948418A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110214284.4A CN112948418A (en) 2021-02-25 2021-02-25 Dynamic query method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110214284.4A CN112948418A (en) 2021-02-25 2021-02-25 Dynamic query method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN112948418A true CN112948418A (en) 2021-06-11

Family

ID=76246360

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110214284.4A Pending CN112948418A (en) 2021-02-25 2021-02-25 Dynamic query method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN112948418A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113553059A (en) * 2021-07-28 2021-10-26 北京达佳互联信息技术有限公司 Local variable query method, device, server and storage medium
CN113779068A (en) * 2021-09-13 2021-12-10 网易(杭州)网络有限公司 Data query method, device, equipment and storage medium
CN117452873A (en) * 2023-12-26 2024-01-26 宁波和利时信息安全研究院有限公司 Communication method, device, equipment and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109271403A (en) * 2018-09-28 2019-01-25 北京京东金融科技控股有限公司 A kind of operating method of data query, device, medium and electronic equipment
CN110866028A (en) * 2019-10-10 2020-03-06 微梦创科网络科技(中国)有限公司 SQL instruction generation method and system
CN110866029A (en) * 2019-10-11 2020-03-06 支付宝(杭州)信息技术有限公司 sql statement construction method, device, server and readable storage medium

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109271403A (en) * 2018-09-28 2019-01-25 北京京东金融科技控股有限公司 A kind of operating method of data query, device, medium and electronic equipment
CN110866028A (en) * 2019-10-10 2020-03-06 微梦创科网络科技(中国)有限公司 SQL instruction generation method and system
CN110866029A (en) * 2019-10-11 2020-03-06 支付宝(杭州)信息技术有限公司 sql statement construction method, device, server and readable storage medium

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113553059A (en) * 2021-07-28 2021-10-26 北京达佳互联信息技术有限公司 Local variable query method, device, server and storage medium
CN113553059B (en) * 2021-07-28 2024-04-30 北京达佳互联信息技术有限公司 Local variable query method, device, server and storage medium
CN113779068A (en) * 2021-09-13 2021-12-10 网易(杭州)网络有限公司 Data query method, device, equipment and storage medium
CN113779068B (en) * 2021-09-13 2023-09-12 网易(杭州)网络有限公司 Data query method, device, equipment and storage medium
CN117452873A (en) * 2023-12-26 2024-01-26 宁波和利时信息安全研究院有限公司 Communication method, device, equipment and storage medium
CN117452873B (en) * 2023-12-26 2024-03-15 宁波和利时信息安全研究院有限公司 Communication method, device, equipment and storage medium

Similar Documents

Publication Publication Date Title
CN112948418A (en) Dynamic query method, device, equipment and storage medium
CN112669138B (en) Data processing method and related equipment
CN111639284A (en) Webpage labeling method and device, electronic equipment and medium
CN112667240A (en) Program code conversion method and related device
CN112433705A (en) Script generation method and device, electronic equipment and storage medium
CN112860737B (en) Data query method and device, electronic equipment and readable storage medium
CN114035827A (en) Application program updating method, device, equipment and storage medium
CN112711398A (en) Method, device and equipment for generating buried point file and storage medium
CN113283675B (en) Index data analysis method, device, equipment and storage medium
CN112416583A (en) High-frequency request processing method and device, electronic equipment and storage medium
CN111814045A (en) Data query method and device, electronic equipment and storage medium
CN113536770B (en) Text analysis method, device and equipment based on artificial intelligence and storage medium
CN111881209A (en) Data synchronization method and device for heterogeneous database, electronic equipment and medium
CN112947911A (en) Interface script generation method, device, equipment and storage medium
CN114510487A (en) Data table merging method, device, equipment and storage medium
CN114116108A (en) Dynamic rendering method, device, equipment and storage medium
CN113918467A (en) Financial system testing method, device, equipment and storage medium
CN112819305A (en) Service index analysis method, device, equipment and storage medium
CN112181485A (en) Script execution method and device, electronic equipment and storage medium
CN112434062A (en) Quasi-real-time data processing method, device, server and storage medium
CN112711696A (en) Request access method, device, electronic equipment and storage medium
CN112199483A (en) Information input assisting method and device, electronic equipment and storage medium
CN113283677B (en) Index data processing method, device, equipment and storage medium
CN114692204A (en) Data query method, device, equipment and storage medium
CN112738175B (en) Request processing method and related equipment

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