CN113111079A - Database execution statement generation method and device - Google Patents

Database execution statement generation method and device Download PDF

Info

Publication number
CN113111079A
CN113111079A CN202110396397.0A CN202110396397A CN113111079A CN 113111079 A CN113111079 A CN 113111079A CN 202110396397 A CN202110396397 A CN 202110396397A CN 113111079 A CN113111079 A CN 113111079A
Authority
CN
China
Prior art keywords
statement
condition
code
database execution
target
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
CN202110396397.0A
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.)
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology 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 Beijing Jingdong Century Trading Co Ltd, Beijing Wodong Tianjun Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN202110396397.0A priority Critical patent/CN113111079A/en
Publication of CN113111079A publication Critical patent/CN113111079A/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
    • 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/25Integrating or interfacing systems involving database management systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/279Recognition of textual entities
    • G06F40/284Lexical analysis, e.g. tokenisation or collocates

Abstract

The application discloses a method and a device for generating database execution statements, which relate to the technical field of computers, and one specific embodiment comprises the steps of intercepting the database execution statements; calling an event-driven analysis interface, analyzing database execution statements, further acquiring a corresponding configuration file, and determining a target adding condition from the configuration file; determining the type of a database execution statement, and determining a code modification condition according to the type; and calling an internal class of the lexical analyzer, and modifying the query analysis statement code of the lexical analyzer based on the target adding condition, the code modifying condition and a preset modifying rule to generate a target database execution statement. Therefore, the implementation mode can shorten the delivery time when the condition is uniformly increased when the query or the change is executed on the database, and improve the delivery efficiency.

Description

Database execution statement generation method and device
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method and an apparatus for generating database execution statements.
Background
At present, when a condition is uniformly added for database query or change, the adopted method is usually to modify all persistent layer framework Mybatis query and update statements and add judgment conditions at each place.
In the process of implementing the present application, the inventor finds that at least the following problems exist in the prior art:
when a condition is uniformly added for querying or changing the historical data stored in the relational database management system Mysql, codes, entity objects and the like of each place need to be changed, so that the program is extremely intrusive, and the delivery time is long and the delivery efficiency is low.
Disclosure of Invention
In view of this, the embodiment of the present application provides a method and an apparatus for generating a database execution statement, which can solve the problems that when a condition is uniformly added to query or change the existing historical data stored in Mysql, each code, entity object, and the like need to be changed, which is extremely intrusive to a program, and results in long delivery time and low delivery efficiency.
To achieve the above object, according to an aspect of the embodiments of the present application, there is provided a database execution statement generation method, including:
intercepting a database execution statement;
calling an event-driven analysis interface, analyzing database execution statements, further acquiring a corresponding configuration file, and determining a target adding condition from the configuration file;
determining the type of a database execution statement, and determining a code modification condition according to the type;
and calling an internal class of the lexical analyzer, and modifying the query analysis statement code of the lexical analyzer based on the target adding condition, the code modifying condition and a preset modifying rule to generate a target database execution statement.
Optionally, intercepting the database execution statement comprises:
receiving a database execution statement, and acquiring an interactive class in the database execution statement;
and calling a preset document type definition file, and intercepting a database execution statement in response to determining that the interaction class is matched with the preset document type definition file.
Optionally, determining a code modification condition according to the type includes:
in response to the fact that the type of the database execution statement is determined to be query and the target adding condition is not null, a lexical analyzer is called to analyze the database execution statement, and then a query statement structure is determined;
and acquiring a code modification condition corresponding to the preset statement from the query statement structure.
Optionally, determining a code modification condition according to the type includes:
in response to determining that the type of the database execution statement is update and the target add condition is non-null, determining that the code modification condition is null.
Optionally, modifying the query analysis statement code of the lexical parser to generate a target database execution statement, including:
determining a writing position of a target adding condition;
writing the target adding condition into a writing position according to a preset modification rule, and updating a query analysis statement code;
and modifying the updated query analysis statement code based on the code modification condition and a preset modification rule, and further generating a target database execution statement.
Optionally, modifying the updated query analysis statement code based on the code modification condition and a preset modification rule, and further generating a target database execution statement, including:
splicing the code modification conditions according to a preset modification rule corresponding to the updated query analysis statement code to generate a target query analysis statement code;
and generating a target database execution statement according to the target query analysis statement code by using a reflection mechanism.
Optionally, obtaining a code modification condition corresponding to the preset statement from the query statement structure includes:
and in response to the fact that the database execution statement is determined to be the combined query statement, recursively acquiring code modification conditions corresponding to preset statements in the combined query statement from the query statement structure.
Optionally, determining a writing location of the target addition condition includes:
judging whether a where condition exists in the query analysis statement code;
in response to determining that the where condition exists, the location of the where condition is located as the write location of the target add condition.
Optionally, determining a writing location of the target adding condition further includes:
and responding to the situation condition, increasing the situation condition in the query analysis statement code according to a preset modification rule, and determining the position of the increased situation condition as the writing position of the target adding condition.
In addition, the present application also provides a database execution statement generation apparatus, including:
an interception unit configured to intercept a database execution statement;
the target adding condition determining unit is configured to call the event-driven analysis interface, analyze the database execution statement, further acquire a corresponding configuration file, and determine a target adding condition from the configuration file;
a code modification condition determining unit configured to determine a type of the database execution statement, determine a code modification condition according to the type;
and the database execution statement generation unit is configured to call an internal class of the lexical parser and modify the query analysis statement codes of the lexical parser based on the target addition condition, the code modification condition and a preset modification rule to generate a target database execution statement.
Optionally, the intercepting unit is further configured to:
receiving a database execution statement, and acquiring an interactive class in the database execution statement;
and calling a preset document type definition file, and intercepting a database execution statement in response to determining that the interaction class is matched with the preset document type definition file.
Optionally, the code modification condition determining unit is further configured to:
in response to the fact that the type of the database execution statement is determined to be query and the target adding condition is not null, a lexical analyzer is called to analyze the database execution statement, and then a query statement structure is determined;
and acquiring a code modification condition corresponding to the preset statement from the query statement structure.
Optionally, the code modification condition determining unit is further configured to:
in response to determining that the type of the database execution statement is update and the target add condition is non-null, determining that the code modification condition is null.
Optionally, the database execution statement generation unit is further configured to:
determining a writing position of a target adding condition;
writing the target adding condition into a writing position according to a preset modification rule, and updating a query analysis statement code;
and modifying the updated query analysis statement code based on the code modification condition and a preset modification rule, and further generating a target database execution statement.
Optionally, the database execution statement generation unit is further configured to:
splicing the code modification conditions according to a preset modification rule corresponding to the updated query analysis statement code to generate a target query analysis statement code;
and generating a target database execution statement according to the target query analysis statement code by using a reflection mechanism.
Optionally, the code modification condition determining unit is further configured to:
and in response to the fact that the database execution statement is determined to be the combined query statement, recursively acquiring code modification conditions corresponding to preset statements in the combined query statement from the query statement structure.
Optionally, the database execution statement generation unit is further configured to:
judging whether a where condition exists in the query analysis statement code;
in response to determining that the where condition exists, the location of the where condition is located as the write location of the target add condition.
Optionally, the database execution statement generation unit is further configured to:
and responding to the situation condition, increasing the situation condition in the query analysis statement code according to a preset modification rule, and determining the position of the increased situation condition as the writing position of the target adding condition.
In addition, the present application also provides an electronic device for generating a database execution statement, including: one or more processors; and a storage device for storing one or more programs, which when executed by the one or more processors, cause the one or more processors to implement the database execution statement generation method as described above.
In addition, the present application also provides a computer readable medium, on which a computer program is stored, which when executed by a processor implements the database execution statement generation method as described above.
One embodiment of the above invention has the following advantages or benefits: according to the method and the device, the database execution statements can be selectively intercepted, so that all the database execution statements can be prevented from being intercepted indiscriminately, and a plurality of interceptors do not need to be adapted independently, so that multiplexing is realized. The configuration file can be obtained by calling the event-driven analysis interface and analyzing the database execution statement, so that the target adding condition can be accurately determined. The type of the database execution statement is determined, whether the code needs to be modified or not is accurately determined according to the type, and a code modification condition is determined. By calling the internal class of the lexical analyzer, on the basis of the existing code framework, the internal codes of the lexical analyzer are partially modified based on the target adding condition, the code modifying condition and the preset modifying rule, and then target database execution statements which can uniformly increase conditions for database query or modification can be generated without intruding a program, so that the delivery time of uniformly increasing conditions for database query or modification is shortened, and the delivery efficiency is improved.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a further understanding of the application and are not to be construed as limiting the application. Wherein:
fig. 1 is a schematic diagram of a main flow of a database execution statement generation method according to a first embodiment of the present application;
FIG. 2 is a schematic diagram of a main flow of a database execution statement generation method according to a second embodiment of the present application;
FIG. 3 is a schematic diagram of an application scenario of a database execution statement generation method according to a third embodiment of the present application;
FIG. 4 is a schematic diagram of the main modules of a database execution statement generation apparatus according to an embodiment of the present application;
FIG. 5 is an exemplary system architecture diagram to which embodiments of the present application may be applied;
fig. 6 is a schematic structural diagram of a computer system suitable for implementing the terminal device or the server according to the embodiment of the present application.
Detailed Description
The following description of the exemplary embodiments of the present application, taken in conjunction with the accompanying drawings, includes various details of the embodiments of the application for the understanding of the same, which are to be considered exemplary only. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the present application. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Fig. 1 is a schematic diagram of a main flow of a database execution statement generation method according to a first embodiment of the present application, and as shown in fig. 1, the database execution statement generation method includes:
step S101, intercepting a database execution statement.
In this embodiment, an execution main body (for example, a server) of the database execution statement generation method may receive an operation request for the database initiated by a user in a wired connection or wireless connection manner, and invoke a database execution statement corresponding to the operation request to operate the database. The execution main body can check the called database execution statements in real time, intercept the database execution statements matched with the preset interception condition in a StatementHandler layer for operating a Statement object to communicate with the database in the Mybatis workflow of the persistent layer framework, and acquire the corresponding XML file. By way of example, the database execution statement may be a Structured Query Language (SQL), a database Query and programming Language for accessing data and querying, updating, and managing a relational database system.
And step S102, calling an event-driven analysis interface, analyzing database execution statements, further acquiring a corresponding configuration file, and determining a target adding condition from the configuration file.
After intercepting the database execution statement and acquiring the corresponding XML file, the execution body may call an event-driven parsing interface, for example, an sax (simple API for XML) event parsing interface, to parse the XML file. The SAX event parsing interface encapsulates methods for handling events, and when the XML parser starts parsing an XML input document, special events are encountered, such as the beginning and end of the document, the beginning and end of an element, and character data in the element. When the events are met, the XML parser calls a corresponding method in the SAX event parsing interface to respond to the events, and then the corresponding configuration files are obtained through parsing and stored in a local memory. The configuration file obtained by the analysis may include incoming parameter mapping configuration, executed SQL statements, result mapping configuration, target addition conditions, information about which table in the database to interact with, and the like. The target adding condition may be, for example, a condition of adding a field identifier to the database to identify whether the field identifier is a physical deletion, adding a filter of some fields, adding a query operation, adding an update operation, and the like. The execution subject may obtain the target addition condition from the parsed configuration file.
Specifically, the execution main body may invoke the SAX event parsing interface to parse the DefaultHandler of the XML file, further obtain constraint configuration information, interpret the XML file based on the obtained constraint configuration information to obtain a configuration file, and obtain a target addition condition to be added to the database from the configuration file. The DefaultHandler is a default base class of the SAX event handler and is also a processing class for analyzing the xml file, inherits the four interfaces of EntityResolver, DTDHANdler, ContentHandler and ErrorHandler, contains all the methods of the four interfaces, and can directly inherit the class to generate the required method. The EntityResolver interface is used for acquiring constraint configuration information. The DTDHandler interface is used to receive notifications of events related to constrained configuration information. The ContentHandler interface is used to notify the application of basic resolution events. The errorsandler interface is used to obtain error information. And if the user-defined modification conditions exist, preferentially acquiring and using the user-defined modification conditions as target addition conditions.
And step S103, determining the type of the database execution statement, and determining a code modification condition according to the type.
In this embodiment, the configuration file may further include a StatementHandler object in the persistent layer frame Mybatis, and then the execution main body may obtain the delete attribute in the StatementHandler object by using a reflection mechanism, so as to obtain the delete object. And then obtaining a mappedStatement object according to the delete object, determining the type of a database execution statement corresponding to the obtained mappedStatement object according to the obtained mappedStatement object and the preset corresponding relation between the mappedStatement object and the type of the database execution statement, and determining a code modification condition according to the modification content corresponding to the type. For example, the modified content corresponding to the type a is a part B and a part C of the modified code, and accordingly, a code modification condition B and a code modification condition C corresponding to the part B and the part C need to be obtained; the modified content corresponding to the type B is only the part B of the modified code, the part C is not modified, and correspondingly, only the code modification condition B corresponding to the part B needs to be obtained. In particular, the types of database execution statements may include query SELECT and UPDATE. The code modification condition may be a condition that is connected to where, join, from, etc. in the code framework. The reflection mechanism is that in a running state, all the attributes and methods of any class can be known; any method and property can be called for any object. The method has the functions of dynamically acquiring information and dynamically calling an object method.
And step S104, calling an internal class of the lexical analyzer, and modifying the query analysis statement code of the lexical analyzer based on the target adding condition, the code modifying condition and a preset modifying rule to generate a target database execution statement.
The embodiment is to partially modify the code of the lexical parser on the original code framework of the lexical parser. After determining the code modification condition, the execution main body can call an internal class of the lexical analyzer, and replace the original condition of the corresponding position of the lexical analyzer by the code modification condition and the target addition condition according to a preset modification rule so as to generate a target database execution statement. Preset modification rules, which may include a preset placement position of the target addition condition, such as adding and after where placed in the code and writing the target addition condition; the method may further include a preset placement position corresponding to the code modification condition, for example, the code modification condition is placed behind a join in the code, behind from, on the left of the join, and the like. The code modification condition may be a table name, a file name, an address name, or the like.
The embodiment can avoid indiscriminate interception of all database execution statements by selectively intercepting the database execution statements, and does not need to individually adapt a plurality of interceptors, thereby realizing multiplexing. The configuration file can be obtained by calling the event-driven analysis interface and analyzing the database execution statement, so that the target adding condition can be accurately determined. The type of the database execution statement is determined, whether the code needs to be modified or not is accurately determined according to the type, and a code modification condition is determined. By calling the internal class of the lexical analyzer, on the basis of the existing code framework, the internal codes of the lexical analyzer are partially modified based on the target adding condition, the code modifying condition and the preset modifying rule, and then target database execution statements which can uniformly increase conditions for database query or modification can be generated without intruding a program, so that the delivery time of uniformly increasing conditions for database query or modification is shortened, and the delivery efficiency is improved.
Fig. 2 is a schematic main flow diagram of a database execution statement generation method according to a second embodiment of the present application, and as shown in fig. 2, the database execution statement generation method includes:
step S201, intercepting a database execution statement.
The principle of step S201 is similar to that of step S101, and is not described here.
Specifically, step S201 can also be implemented by steps S2011 to S2012:
step S2011, receiving the database execution statement, and acquiring an interaction class in the database execution statement.
The execution body may receive a database execution statement invoked according to a user request before intercepting the database execution statement, and obtain an interaction class in the database execution statement, where the interaction class, for example, may be mapper, is a class for defining which table in the database to interact with, that is, may be used to indicate an interaction address, and may be equivalent to an address ID.
Step S2012 calls a preset document type definition file, and intercepts a database execution statement in response to determining that the interaction class matches the preset document type definition file.
After the execution body obtains the interaction class in the database execution statement, a preset document Type definition file can be called, namely a Document Type Definition (DTD) (document Type definition) file, which is a special document and defines and restricts the definition and statement conforming to the Standard General Markup Language (SGML) or SGML subset extensible markup language (XML) rule. The document Type definition dtd (document Type definition) of the XML file may be regarded as a template of one or more XML files, and may define elements, attributes of the elements, arrangement of the elements, contents included in the elements, and the like in the XML file. The interaction class is contained in a document type definition file. After calling the document type definition file, the executing body can match the interaction class in the document type definition file with the interaction class in the received database execution statement, if the matching is successful, the received database execution statement is the database execution statement needing to be intercepted, and the received database execution statement is intercepted. The specific content of the DTD description may be:
<!ELEMENT logicDelConfig(parseList?)>
<!ELEMENT parseList(value+)>
<!ELEMENT value(mapper,condition?)>
<!ELEMENT mapper(#PCDATA)>
<!ELEMENT condition(#PCDATA)>
in the embodiment, by calling the preset document type definition file, when it is determined that the interaction class in the received database execution statement matches the preset document type definition file, the received database execution statement is intercepted, so that dynamic interception of some query and update statements can be realized, and some places which do not need to be modified in the database and are caused by intercepting all database execution statements are prevented from being modified, so that the database can be modified more accurately, the condition that the database execution statement can be increased without invading codes is realized, and the reusability is improved.
Step S202, calling an event-driven analysis interface, analyzing database execution statements, further acquiring a corresponding configuration file, and determining a target adding condition from the configuration file.
Step S203, determining the type of the database execution statement, and determining a code modification condition according to the type.
The principle of step S202 to step S203 is similar to that of step S102 to step S103, and is not described here again.
Specifically, step S203 can also be realized by step S2031 to step S2032:
step S2031, in response to determining that the type of the database execution statement is query and the target addition condition is non-null, invoking a lexical analyzer to analyze the database execution statement, and further determining a query statement structure.
The execution subject, after determining the type of the database execution statement, may determine whether the type is a query or an update, and determine whether the target addition condition is null. The target addition condition is null, indicating unconditional, no conditional restriction. And in response to the fact that the type of the database execution Statement is determined to be query and the target adding condition is not null, namely the limitation of the target adding condition is indicated, the execution main body needs to further judge and call a lexical analyzer to analyze the database execution Statement, and further determines a query Statement structure, namely State. Statement is used to send database execution statements, SQL statements, to the database.
Step S2032, a code modification condition corresponding to the preset statement is acquired from the query statement structure.
The executing body may determine that a join occurs several times in total from the query Statement structure, Statement, and fetch the statements following the join. The executive may also obtain the table name that appears from behind from in the Statement. The executing agent may also find the first table name to the left of the join from the Statement according to the algorithm, and so on. The obtained table name can be a code modification condition. The preset sentences may be, for example, sentences connected by join, sentences connected by where, sentences connected by from, and the like.
In this embodiment, when the type of the database execution statement is query and the target addition condition is non-empty, the code modification condition is obtained from the determined query statement structure, and whether the code modification condition is to be obtained can be prejudged in advance according to the type of the database execution statement, so that the delivery time when the conditions are uniformly added for query or modification of the database is shortened, and the delivery efficiency is improved.
Specifically, step S2032 can also be implemented by step S20321:
step S20321, in response to determining that the database execution statement is a joint query statement, recursively acquiring, from the query statement structure, a code modification condition corresponding to a preset statement in the joint query statement.
When the execution main body determines that the database execution Statement is the joint query Statement, that is, the Statement connected by the join, the preset Statement in the joint query Statement, for example, the code modification condition corresponding to the preset Statement from, join, where, etc., can be recursively obtained from the query Statement structure, that is, Statement, corresponding to the joint query Statement layer by layer from inside to outside. A join query is a result set that can merge multiple similar select queries, equivalent to appending one table to another, thereby enabling the queries of both tables to be combined together.
In this embodiment, when the database execution statement is a joint query statement, the code modification condition corresponding to the joint query statement is finally and accurately determined by recursively obtaining the code modification condition corresponding to the preset statement in the joint query statement layer by layer from inside to outside in the query statement structure, so that the query or modification performed on the database is more accurate, and the result of the query or modification performed on the database is higher in reliability.
And step S204, calling an internal class of the lexical analyzer, and modifying the query analysis statement code of the lexical analyzer based on the target adding condition, the code modifying condition and a preset modifying rule to generate a target database execution statement.
The principle of step S204 is similar to that of step S104, and is not described here again.
Specifically, step S204 can also be realized by step S2041 to step S2043:
in step S2041, the writing position of the target addition condition is determined.
Step S2042, writing the target addition condition into the write-in position according to a preset modification rule, and updating the query analysis statement code.
In this embodiment, after determining the target addition condition and the code modification condition, the execution subject may determine whether a where condition exists in the original query analysis statement code of the lexical parser; in response to determining that the where condition exists, the location of the where condition is located as the write location of the target add condition. Specifically, the execution principal may add and write the target add condition after the located where condition.
And the execution main body responds to the situation that no work condition exists in the original query analysis statement code of the lexical analyzer, and according to a preset modification rule, the work condition is added to the query analysis statement code, so that the position of the added work condition is determined as the writing position of the target adding condition. The preset modification rule may be to add where to the original query analysis statement code and directly write the target addition condition after the added where in the writing mode of the code.
After the execution main body writes the target adding condition into the writing position according to a preset modification rule, the query analysis statement code modified by the lexical analyzer part can be updated.
Step S2043, modifying the updated query analysis statement code based on the code modification condition and the preset modification rule, and further generating a target database execution statement.
The execution main body can find the join and the from in the updated query analysis Statement code based on the structure of the query analysis Statement code updated by the lexical analyzer, replace and splice the code modification condition into the position corresponding to the join and the from in the updated query analysis Statement code according to the query Statement structure corresponding to the intercepted database execution Statement, namely, the position relation between the join and the from in the Statement, and further generate the target database execution Statement. That is, the execution subject may replace the conditions around the corresponding join, from positions in the query analysis statement code updated by the lexical parser with the code modification condition (the updated query statement analysis code refers to the code in which the target addition condition is inserted in the original query statement code of the lexical parser) to obtain the target database execution statement. The target database execution statement can be called to inquire or update the database without intruding a program or changing each code and entity object, so that the delivery time is shortened and the delivery efficiency is improved.
Specifically, step S2043 may also be implemented by step S20431 to step S20432:
step S20431, the code modification conditions are spliced according to the preset modification rule corresponding to the updated query analysis statement code, and a target query analysis statement code is generated.
Step S20432, using a reflection mechanism, generating a target database execution statement according to the target query analysis statement code.
The preset modification rules may include various marks, various symbols, and the positions of the marks, symbols, and the like to be added during the writing process of the code.
In this embodiment, the execution main body splices the code modification conditions at corresponding positions (for example, positions after the join, on the left side of the join, after the from, or the like) in the updated query analysis Statement code frame according to a preset modification rule, for example, the code modification conditions after the join in the intercepted query Statement structure, i.e., Statement, corresponding to the database execution Statement still replace the conditions after the join in the updated query analysis Statement code frame, and other conditions are replaced similarly and are not described again, and the target query analysis Statement code is generated. In the embodiment, the query analysis statement codes of the lexical analyzer can be partially modified through condition replacement of the corresponding positions, so that the delivery time when the conditions are uniformly increased when the query is executed or the query is changed on the database is shortened, the delivery efficiency is improved, and reusability is realized. After the execution main body generates the target query analysis statement codes, the reflection mechanism can be utilized to generate target database execution statements, namely target SQL statements, according to the target query analysis statement codes.
In some optional implementations of this embodiment, step S203 may also be implemented by step S2033 not shown in fig. 2:
step S2033, in response to determining that the type of the database execution statement is update and the target addition condition is not null, determining that the code modification condition is null.
In this embodiment, when the execution main body determines that the type of the database execution statement is updated, it is determined that the query analysis statement code in the lexical parser does not need to be replaced, and when the target addition condition is non-empty, that is, when the target addition condition exists, the target addition condition is only required to be added to the where position in the query analysis statement code in the lexical parser, and then the target query analysis statement code can be generated, and the target database execution statement can be generated by using a reflection mechanism.
In the embodiment, when the type of the database execution statement is updated, the query analysis statement code in the lexical parser does not need to be replaced, so that the modification mode of the query analysis statement code in the lexical parser is more definite, the lexical parser is introduced, the lexical parser is modified and rewritten, all sql statements can be recognized and added, and the reusability is strong.
Fig. 3 is a schematic view of an application scenario of a database execution statement generation method according to a third embodiment of the present application. The database execution statement generation method can be applied to a scene that a condition is uniformly added for historical data query or change stored in Mysql. As shown in fig. 3, a server 303 intercepts a database execution statement 301. The server 303 calls the event-driven parsing interface 302 to parse the database execution statement 301, and further obtains a corresponding configuration file 304, and determines a target addition condition 305 from the configuration file 304. The server 303 determines the type 306 of the database execution statement and determines the code modification condition 307 according to the type 306. The server 303 calls the internal class 308 of the lexical parser, and modifies the query analysis statement code (not shown) of the lexical parser based on the target addition condition 305, the code modification condition 307, and the preset modification rule 309 to generate the target database execution statement 310.
Fig. 4 is a schematic diagram of main modules of a database execution statement generation apparatus according to an embodiment of the present application. As shown in fig. 4, the database execution statement generation means includes an interception unit 401, a target addition condition determination unit 402, a code modification condition determination unit 403, and a database execution statement generation unit 404.
An intercepting unit 401 configured to intercept the database execution statement.
And a target adding condition determining unit 402, configured to call the event-driven parsing interface, parse the database execution statement, further obtain a corresponding configuration file, and determine a target adding condition from the configuration file.
A code modification condition determining unit 403 configured to determine a type of the database execution statement, and determine a code modification condition according to the type.
A database execution statement generation unit 404 configured to call an internal class of the lexical parser, modify the query analysis statement code of the lexical parser based on the target addition condition, the code modification condition, and a preset modification rule to generate a target database execution statement.
In some embodiments, the interception unit 401 is further configured to: receiving a database execution statement, and acquiring an interactive class in the database execution statement; and calling a preset document type definition file, and intercepting a database execution statement in response to determining that the interaction class is matched with the preset document type definition file.
In some embodiments, the code modification condition determination unit 403 is further configured to: in response to the fact that the type of the database execution statement is determined to be query and the target adding condition is not null, a lexical analyzer is called to analyze the database execution statement, and then a query statement structure is determined; and acquiring a code modification condition corresponding to the preset statement from the query statement structure.
In some embodiments, the code modification condition determination unit 403 is further configured to: in response to determining that the type of the database execution statement is update and the target add condition is non-null, determining that the code modification condition is null.
In some embodiments, the database execution statement generation unit 404 is further configured to: determining a writing position of a target adding condition; writing the target adding condition into a writing position according to a preset modification rule, and updating a query analysis statement code; and modifying the updated query analysis statement code based on the code modification condition and a preset modification rule, and further generating a target database execution statement.
In some embodiments, the database execution statement generation unit 404 is further configured to: splicing the code modification conditions according to a preset modification rule corresponding to the updated query analysis statement code to generate a target query analysis statement code; and generating a target database execution statement according to the target query analysis statement code by using a reflection mechanism.
In some embodiments, the code modification condition determination unit 403 is further configured to: and in response to the fact that the database execution statement is determined to be the combined query statement, recursively acquiring code modification conditions corresponding to preset statements in the combined query statement from the query statement structure.
In some embodiments, the database execution statement generation unit 404 is further configured to: judging whether a where condition exists in the query analysis statement code; in response to determining that the where condition exists, the location of the where condition is located as the write location of the target add condition.
In some embodiments, the database execution statement generation unit 404 is further configured to: and responding to the situation condition, increasing the situation condition in the query analysis statement code according to a preset modification rule, and determining the position of the increased situation condition as the writing position of the target adding condition.
In the database execution statement generation method and the database execution statement generation device according to the present application, the implementation contents have corresponding relationships, and therefore, the description of the duplicated contents is omitted.
Fig. 5 shows an exemplary system architecture 500 to which the database execution statement generation method or the database execution statement generation apparatus according to the embodiment of the present application may be applied.
As shown in fig. 5, the system architecture 500 may include terminal devices 501, 502, 503, a network 504, and a server 505. The network 504 serves to provide a medium for communication links between the terminal devices 501, 502, 503 and the server 505. Network 504 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
The user may use the terminal devices 501, 502, 503 to interact with a server 505 over a network 504 to receive or send messages or the like. The terminal devices 501, 502, 503 may have installed thereon various communication client applications, such as shopping-like applications, web browser applications, search-like applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only).
The terminal devices 501, 502, 503 may be various electronic devices including, but not limited to, smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 505 may be a server providing various services, such as a background management server (for example only) providing support for database execution statements intercepted by the terminal devices 501, 502, 503. The background management server can intercept database execution statements; calling an event-driven analysis interface, analyzing database execution statements, further acquiring a corresponding configuration file, and determining a target adding condition from the configuration file; determining the type of a database execution statement, and determining a code modification condition according to the type; and calling an internal class of the lexical analyzer, and modifying the query analysis statement code of the lexical analyzer based on the target adding condition, the code modifying condition and a preset modifying rule to generate a target database execution statement. Therefore, the delivery time when the conditions are uniformly increased when the query or the change is executed on the database can be shortened, and the delivery efficiency is improved.
It should be noted that the database execution statement generation method provided in the embodiment of the present application is generally executed by the server 505, and accordingly, the database execution statement generation apparatus is generally disposed in the server 505.
It should be understood that the number of terminal devices, networks, and servers in fig. 5 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 6, shown is a block diagram of a computer system 600 suitable for use in implementing a terminal device of an embodiment of the present application. The terminal device shown in fig. 6 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present application.
As shown in fig. 6, the computer system 600 includes a Central Processing Unit (CPU)601 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)602 or a program loaded from a storage section 608 into a Random Access Memory (RAM) 603. In the RAM603, various programs and data necessary for the operation of the computer system 600 are also stored. The CPU601, ROM602, and RAM603 are connected to each other via a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
The following components are connected to the I/O interface 605: an input portion 606 including a keyboard, a mouse, and the like; an output section 607 including a signal processing section such as a Cathode Ray Tube (CRT), a liquid crystal credit authorization inquiry processor (LCD), and the like, and a speaker and the like; a storage section 608 including a hard disk and the like; and a communication section 609 including a network interface card such as a LAN card, a modem, or the like. The communication section 609 performs communication processing via a network such as the internet. The driver 610 is also connected to the I/O interface 605 as needed. A removable medium 611 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 610 as necessary, so that a computer program read out therefrom is mounted in the storage section 608 as necessary.
In particular, according to embodiments disclosed herein, the processes described above with reference to the flow diagrams may be implemented as computer software programs. For example, embodiments disclosed herein include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 609, and/or installed from the removable medium 611. The above-described functions defined in the system of the present application are executed when the computer program is executed by the Central Processing Unit (CPU) 601.
It should be noted that the computer readable medium shown in the present application may be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present application, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In this application, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present application may be implemented by software or hardware. The described units may also be provided in a processor, and may be described as: a processor includes an intercepting unit, a target addition condition determining unit, a code modification condition determining unit, and a database execution statement generating unit. Wherein the names of the elements do not in some way constitute a limitation on the elements themselves.
As another aspect, the present application also provides a computer-readable medium, which may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to intercept database execution statements; calling an event-driven analysis interface, analyzing database execution statements, further acquiring a corresponding configuration file, and determining a target adding condition from the configuration file; determining the type of a database execution statement, and determining a code modification condition according to the type; and calling an internal class of the lexical analyzer, and modifying the query analysis statement code of the lexical analyzer based on the target adding condition, the code modifying condition and a preset modifying rule to generate a target database execution statement. Therefore, the delivery time when the conditions are uniformly increased when the query or the change is executed on the database can be shortened, and the delivery efficiency is improved.
According to the technical scheme of the embodiment of the application, all database execution statements can be prevented from being subjected to indiscriminate interception by selectively intercepting the database execution statements, and a plurality of interceptors do not need to be adapted independently, so that multiplexing is realized. The configuration file can be obtained by calling the event-driven analysis interface and analyzing the database execution statement, so that the target adding condition can be accurately determined. The type of the database execution statement is determined, whether the code needs to be modified or not is accurately determined according to the type, and a code modification condition is determined. By calling the internal class of the lexical analyzer, on the basis of the existing code framework, the internal codes of the lexical analyzer are partially modified based on the target adding condition, the code modifying condition and the preset modifying rule, and then target database execution statements which can uniformly increase conditions for database query or modification can be generated without intruding a program, so that the delivery time of uniformly increasing conditions for database query or modification is shortened, and the delivery efficiency is improved.
The above-described embodiments should not be construed as limiting the scope of the present application. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims (12)

1. A database execution statement generation method is characterized by comprising the following steps:
intercepting a database execution statement;
calling an event-driven analysis interface, analyzing the database execution statement, further acquiring a corresponding configuration file, and determining a target adding condition from the configuration file;
determining the type of the database execution statement, and determining a code modification condition according to the type;
and calling an internal class of a lexical analyzer, and modifying the query analysis statement code of the lexical analyzer based on the target adding condition, the code modifying condition and a preset modifying rule to generate a target database execution statement.
2. The method of claim 1, wherein intercepting the database execution statement comprises:
receiving a database execution statement, and acquiring an interaction class in the database execution statement;
and calling a preset document type definition file, and intercepting the database execution statement in response to determining that the interaction class is matched with the preset document type definition file.
3. The method of claim 1, wherein determining a code modification condition based on the type comprises:
in response to the fact that the type of the database execution statement is determined to be query and the target adding condition is not null, a lexical analyzer is called to analyze the database execution statement, and then a query statement structure is determined;
and acquiring a code modification condition corresponding to a preset statement from the query statement structure.
4. The method of claim 1, wherein determining a code modification condition based on the type comprises:
in response to determining that the type of the database execution statement is update and the target add condition is non-null, determining that a code modification condition is null.
5. The method of claim 3, wherein modifying the query analysis statement code of the lexical parser to generate a target database execution statement comprises:
determining a writing position of the target adding condition;
writing the target adding condition into the writing position according to a preset modification rule, and updating the query analysis statement code;
and modifying the updated query analysis statement code based on the code modification condition and a preset modification rule, and further generating a target database execution statement.
6. The method of claim 5, wherein modifying the updated query analysis statement code based on the code modification condition and a preset modification rule to generate a target database execution statement comprises:
splicing the code modification conditions according to a preset modification rule corresponding to the updated query analysis statement code to generate a target query analysis statement code;
and generating a target database execution statement according to the target query analysis statement code by using a reflection mechanism.
7. The method of claim 3, wherein the obtaining of the code modification condition corresponding to the preset statement from the query statement structure comprises:
and in response to determining that the database execution statement is a joint query statement, recursively acquiring a code modification condition corresponding to a preset statement in the joint query statement from the query statement structure.
8. The method of claim 5, wherein the determining the write location of the target add condition comprises:
judging whether a where condition exists in the query analysis statement code;
in response to determining that a where condition exists, locating a location of the where condition as a write location of the target add condition.
9. The method of claim 8, wherein the determining a write location of the target add condition further comprises:
and responding to the situation condition, adding the situation condition in the query analysis statement code according to a preset modification rule, and determining the position of the added situation condition as the writing position of the target adding condition.
10. A database execution statement generation apparatus, comprising:
an interception unit configured to intercept a database execution statement;
the target adding condition determining unit is configured to call an event-driven analysis interface, analyze the database execution statement, further acquire a corresponding configuration file, and determine a target adding condition from the configuration file;
a code modification condition determining unit configured to determine a type of the database execution statement, determine a code modification condition according to the type;
a database execution statement generation unit configured to call an internal class of a lexical parser, modify a query analysis statement code of the lexical parser based on the target addition condition, the code modification condition, and a preset modification rule to generate a target database execution statement.
11. An electronic device for generating database execution statements, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-9.
12. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-9.
CN202110396397.0A 2021-04-13 2021-04-13 Database execution statement generation method and device Pending CN113111079A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110396397.0A CN113111079A (en) 2021-04-13 2021-04-13 Database execution statement generation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110396397.0A CN113111079A (en) 2021-04-13 2021-04-13 Database execution statement generation method and device

Publications (1)

Publication Number Publication Date
CN113111079A true CN113111079A (en) 2021-07-13

Family

ID=76716669

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110396397.0A Pending CN113111079A (en) 2021-04-13 2021-04-13 Database execution statement generation method and device

Country Status (1)

Country Link
CN (1) CN113111079A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117390055A (en) * 2023-12-13 2024-01-12 火石创造科技有限公司 JOOQ continuous list sentence generation method, device and medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1881208A (en) * 2005-06-14 2006-12-20 联想(北京)有限公司 Construction method for dynamic structured query language statement
CN110555030A (en) * 2018-03-28 2019-12-10 北京京东尚科信息技术有限公司 SQL statement processing method and device
CN110858202A (en) * 2018-08-21 2020-03-03 北京京东尚科信息技术有限公司 Method and device for generating where clause in database query statement
CN111552678A (en) * 2020-03-30 2020-08-18 平安医疗健康管理股份有限公司 Data permission configuration method and device and computer equipment

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1881208A (en) * 2005-06-14 2006-12-20 联想(北京)有限公司 Construction method for dynamic structured query language statement
CN110555030A (en) * 2018-03-28 2019-12-10 北京京东尚科信息技术有限公司 SQL statement processing method and device
CN110858202A (en) * 2018-08-21 2020-03-03 北京京东尚科信息技术有限公司 Method and device for generating where clause in database query statement
CN111552678A (en) * 2020-03-30 2020-08-18 平安医疗健康管理股份有限公司 Data permission configuration method and device and computer equipment

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117390055A (en) * 2023-12-13 2024-01-12 火石创造科技有限公司 JOOQ continuous list sentence generation method, device and medium
CN117390055B (en) * 2023-12-13 2024-03-01 火石创造科技有限公司 JOOQ continuous list sentence generation method, device and medium

Similar Documents

Publication Publication Date Title
CN109492053B (en) Method and device for accessing data
CN109582691B (en) Method and apparatus for controlling data query
CN111400061A (en) Data processing method and system
CA2747783C (en) Extensibility for web based diagram visualization
CN107491382B (en) Log output method and device
CN111949693B (en) Data processing device, data processing method, storage medium and electronic equipment
CN111666293A (en) Database access method and device
CN110555030A (en) SQL statement processing method and device
CN110795315A (en) Method and device for monitoring service
CN110858202A (en) Method and device for generating where clause in database query statement
CN113626223A (en) Interface calling method and device
CN113111079A (en) Database execution statement generation method and device
CN108694172B (en) Information output method and device
CN112559024A (en) Method and device for generating transaction code change list
CN112926008A (en) Method and device for generating form page, electronic equipment and storage medium
CN113778725A (en) Data verification method and device
US10275264B1 (en) Configuration management of remote sources using activator fields
CN114327404A (en) File processing method and device, electronic equipment and computer readable medium
CN114722108A (en) Customer service data processing method and device, electronic equipment and storage medium
CN112261072B (en) Service calling method, device, equipment and storage medium
CN114489674A (en) Data verification method and device of dynamic data model
CN113419740A (en) Program data stream analysis method and device, electronic device and readable storage medium
CN113760969A (en) Data query method and device based on elastic search
CN112131257A (en) Data query method and device
CN109376023B (en) Method and equipment for generating calling information and issuing return code group

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