SQL statement generation method, device, equipment, medium and product

By selecting the target entity object, configuring query rules and determining the target database, SQL statements are automatically generated using SQL assembly rules, which solves the problem of cumbersome SQL statement generation steps and realizes the shielding and simplified generation of database syntax.

CN114860753BActive Publication Date: 2025-09-19CHINA CONSTRUCTION BANK
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210346409.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-31
Publication Date
2025-09-19
Estimated Expiration
2042-03-31

AI Technical Summary

Technical Problem

The steps for generating SQL statements are cumbersome and require familiarity with the syntax characteristics of different databases. Auxiliary tools can only provide prompts and it is difficult to simplify the generation process.

Method used

By selecting the target entity object, configuring query rules and determining the target database, SQL statements are automatically generated using SQL assembly rules, shielding database syntax differences and providing a simple generation method.

Benefits of technology

Even if you are not familiar with the database, you can still generate correct SQL statements, which simplifies the generation process and improves efficiency and ease of use.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114860753B_ABST
    Figure CN114860753B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, apparatus, device, medium, and product for generating SQL statements, and relates to the field of data processing technology. The method comprises: selecting at least one target entity object from at least one preset entity object as a query target for the SQL statement, wherein each entity object corresponds to a database; configuring at least one target query rule for the entity object from preset query rules; determining the target database corresponding to the target entity object; and generating the SQL statement based on the at least one target query rule, the target database, and the target entity object. The technical solution of the present invention can solve the technical problem of overly complex SQL statement generation steps.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present invention relate to the field of data processing technology, and in particular to a method, apparatus, device, medium, and product for generating an SQL statement. Background Art

[0002] When writing SQL statements, you need to write standard statements according to SQL syntax. Although all databases follow standard SQL syntax, the architecture of each database product is different, so the writing requirements for SQL statements are higher.

[0003] In order to reduce the writing requirements of SQL statements, database tools can be used to edit SQL statements when writing them, providing some auxiliary functions for writing, such as keyword prompts for database writing.

[0004] However, this auxiliary function can only serve as a hint. You still need to be familiar with the SQL syntax to be able to write standard SQL statements. Therefore, a simpler method for generating SQL statements is needed. Summary of the Invention

[0005] The embodiments of the present invention provide a method, apparatus, device, medium and product for generating an SQL statement, so as to solve the problem that the steps for generating an SQL statement are too complicated.

[0006] In a first aspect, an embodiment of the present invention provides a method for generating an SQL statement, comprising: selecting at least one target entity object as a query target of an SQL statement from at least one preset entity object, wherein each of the entity objects corresponds to a database; configuring at least one target query rule for the entity object from preset query rules; determining a target database corresponding to the target entity object; and generating the SQL statement based on at least one target query rule, the target database, and the target entity object.

[0007] Optionally, generating the SQL statement according to at least one of the target query rules, the target database and the target entity object includes: determining the data type of the target database; assembling the SQL statement according to the SQL assembly rule corresponding to the data type; and generating the SQL statement according to the SQL assembly rule, the target query rule and the target entity object.

[0008] Optionally, when at least two target entity objects are selected from the entity objects, generating the SQL statement according to the SQL assembly rule, the target query rule and the target entity objects includes: determining an association rule of at least two target entity objects, wherein the association rule corresponds to a data set form between at least two target entity objects; and generating the SQL statement according to the association rule, the SQL assembly rule, the target query rule and at least two target entity objects.

[0009] Optionally, the association rules include: inner join rules, outer join rules and full join rules; the inner join rules correspond to the intersection data set between at least two of the target entity objects; the outer join rules correspond to the intersection data set between at least two of the target entity objects and the complement data set of one of the target entity objects; the full join rules correspond to the full set data set between at least two of the target entity objects.

[0010] Optionally, the query rule includes a uniqueness rule; accordingly, when the target query rule is the uniqueness rule, the SQL statement is generated according to the SQL assembly rule, the target query rule and the target entity object, including: determining an identity query code corresponding to the uniqueness rule, the identity query code being used to query whether the identity of the target entity object is repeated with other target entity objects; and generating the SQL statement according to the identity query code and the SQL assembly rule.

[0011] Optionally, the query rule includes a non-emptiness rule; accordingly, when the target query rule is the non-emptiness rule, the SQL statement is generated according to the SQL assembly rule, the target query rule and the target entity object, including: determining a content detection code corresponding to the uniqueness rule, the content detection code being used to detect whether the preset content of the target entity object is empty; and generating the SQL statement according to the content detection code and the SQL assembly rule.

[0012] Optionally, generating the SQL statement according to the SQL assembly rule, the target query rule, and the target entity object includes:

[0013] Determine the SQL statement template to be assembled according to the SQL assembly rule;

[0014] The target query rule and the target entity object are assembled into the SQL statement template to be assembled to obtain the SQL statement.

[0015] In a second aspect, an embodiment of the present invention further provides a device for generating SQL statements, characterized in that the device includes:

[0016] An entity object selection unit, configured to select at least one target entity object as a query target of an SQL statement from at least one preset entity object, wherein each of the entity objects corresponds to a database;

[0017] A query rule configuration unit, configured to configure at least one target query rule for the entity object from preset query rules;

[0018] A database selection unit, configured to determine a target database corresponding to the target entity object;

[0019] A statement processing unit is used to generate the SQL statement according to at least one of the target query rules, the target database and the target entity object.

[0020] In a third aspect, an embodiment of the present invention further provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the SQL statement generation method as described in any one of the embodiments of the present invention is implemented.

[0021] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the SQL statement generation method as described in any one of the embodiments of the present invention.

[0022] In a fifth aspect, an embodiment of the present invention further provides a computer program product, including a computer program, which, when executed by a processor, implements the SQL statement generation method as described in any one of the embodiments of the present invention.

[0023] In an embodiment of the present invention, after determining the target entity object as the target of the SQL statement query, the desired query SQL statement can be automatically generated by configuring the query rules and the target database, and the different grammatical characteristics of the databases of different background products can be automatically shielded. Even if you are not familiar with the database product, you can use it, thereby solving the problem of overly complicated SQL statement generation steps. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments. It should be understood that the following drawings only illustrate certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without paying any creative work.

[0025] Figure 1 A flowchart of a method for generating an SQL statement provided in Example 1 of the present invention;

[0026] Figure 2 A flowchart of another SQL statement generation method provided in the second embodiment of the present invention;

[0027] Figure 3 A flowchart of another SQL statement generation method provided in the second embodiment of the present invention;

[0028] Figure 4 A flowchart of a method for generating SQL statements for a multi-entity linked query according to a third embodiment of the present invention;

[0029] Figure 5 A schematic diagram of the structure of an SQL statement generating device provided in the fourth embodiment of the present invention;

[0030] Figure 6 FIG. 1 is a schematic structural diagram of an electronic device 10 implementing an embodiment of the present invention. DETAILED DESCRIPTION

[0031] The present invention will be further described in detail below with reference to the accompanying drawings and examples. It will be understood that the specific embodiments described herein are intended only to illustrate the present invention and are not intended to limit the present invention. It should also be noted that, for ease of description, the accompanying drawings only illustrate portions relevant to the present invention, not all structures.

[0032] It should be noted that similar reference numerals and letters represent similar items in the following figures. Therefore, once an item is defined in one figure, it does not need to be further defined or explained in subsequent figures. Furthermore, in the description of the present invention, the terms "first," "second," etc. are used only to distinguish descriptions and should not be understood to indicate or imply relative importance. The acquisition, storage, use, and processing of data in the technical solution of this application comply with the relevant provisions of national laws and regulations.

[0033] Example 1

[0034] Figure 1 This is a flow chart of a method for generating SQL statements provided in the first embodiment of the present invention. This embodiment is applicable to the case of generating SQL query statements for corresponding entity objects in a database. This method can be executed by an SQL statement generating device, which can be implemented in the form of hardware and / or software. Figure 1 As shown, the method includes:

[0035] S110: Select at least one target entity object from at least one preset entity object as a target for an SQL statement query, wherein each of the entity objects corresponds to a database.

[0036] The target entity object is the query object of the SQL statement. Each entity object is deployed in the database, and a corresponding relationship is established between the entity object and the database. This allows the target entity object to include relevant database information for subsequent processing when selecting the target entity object from the database. When selecting entity objects, all one or more target entity objects involved in the query must be selected.

[0037] S120: Configure at least one target query rule for the entity object from preset query rules.

[0038] The query rules are the relevant constraints for querying entity objects. Before generating SQL statements, users can configure the query rules according to query requirements and select the required query rules from the preset query rules.

[0039] S130: Determine the target database corresponding to the target entity object.

[0040] Among them, since the entity object has a corresponding relationship with the database, the target database corresponding to the target entity object can be determined. Since the generation of SQL statements requires the combination of relevant information of the database, it is necessary to determine the target database in order to generate the corresponding SQL statements. The SQL statements generated between different databases are different in some of the generation syntax, so the final generated SQL statements are also different.

[0041] S140: Generate the SQL statement according to at least one of the target query rules, the target database, and the target entity object.

[0042] Among them, the target database can determine some special generation syntax for the characteristics of the target database when generating SQL statements. The target entity object is the query target of the SQL statement. The target query rule is used to configure the query according to the user's needs. These elements are combined together to generate the query SQL statements that the user wants according to different databases.

[0043] Example 2

[0044] Figure 2 This is a flowchart of another SQL statement generation method provided by the second embodiment of the present invention. This embodiment is optimized based on the above embodiment. Figure 2 As shown, the method includes:

[0045] Step 210: Determine the data type of the target database.

[0046] The data type may be determined based on the name field and attribute value of the target database. As mentioned above, the target database may be determined based on the corresponding relationship between the target entity object and the target database.

[0047] Step 220: Assemble the SQL rules according to the data type.

[0048] Step 230: Generate the SQL statement according to the SQL assembly rule, the target query rule and the target entity object.

[0049] Among them, since different databases have some differences due to different implementation architectures, different databases correspond to different SQL assembly rules when generating SQL statements. When assembling SQL statements, different SQL statements can be generated according to different databases.

[0050] In the second embodiment of the present invention, the query rule includes a uniqueness rule;

[0051] Correspondingly, when the target query rule is the uniqueness rule, generating the SQL statement according to the SQL assembly rule, the target query rule and the target entity object includes:

[0052] Determine an identity query code corresponding to the uniqueness rule, where the identity query code is used to query whether the identity of the target entity object is repeated with other target entity objects;

[0053] The SQL statement is generated according to the identity query code and the SQL assembly rule.

[0054] The uniqueness rule is used to check whether the target entity object meets the uniqueness requirement, that is, no duplicate records exist in all record values ​​within the target entity object. For example, in the organization information table, if there are no duplicate organization numbers in the structure information table, the uniqueness requirement is considered met. When generating SQL statements, you need to configure a detection object to check for uniqueness. In the output configuration, you can choose whether the content meets the uniqueness rule or not.

[0055] In the second embodiment of the present invention, the query rule includes a non-emptiness rule;

[0056] Correspondingly, when the target query rule is the non-emptiness rule, generating the SQL statement according to the SQL assembly rule, the target query rule and the target entity object includes:

[0057] Determining a content detection code corresponding to the uniqueness rule, wherein the content detection code is used to detect whether the preset content of the target entity object is empty;

[0058] The SQL statement is generated according to the content detection code and the SQL assembly rule.

[0059] The non-nullability rule checks whether the target entity object meets the non-nullability requirement, meaning that all records do not contain null values. For example, in an organization information table, the organization name cannot be null. When generating SQL statements, you need to configure a detection object to check for non-nullability. In the output configuration, you can choose whether the content meets the non-nullability rule or not.

[0060] In addition, query rules are not limited to the two mentioned above. To ensure the applicability and ease of use of rule configuration, we have extracted rule configuration templates that can meet most common needs based on the common functional characteristics of queries, including uniqueness check, non-null check, value range check, value constraint check, operation balance check, data format check, total score check, indicator fluctuation check, and custom check configuration templates.

[0061] Figure 3 This is a flowchart of another SQL statement generation method provided in the second embodiment of the present invention, such as Figure 3 As shown, the method includes the following steps:

[0062] S310: Determine a SQL statement template to be assembled according to the SQL assembly rule.

[0063] S320: Assemble the target query rule and the target entity object into the SQL statement template to be assembled to obtain the SQL statement.

[0064] Among them, after completing the configuration of the target query rules, determine the SQL assembly rules corresponding to the database, and assemble the SQL statements through the SQL statement template to be assembled. For users who are not familiar with the database, through the SQL statement template, the user only needs to configure the query rules, and then the SQL statement can be generated according to the SQL statement template, thereby shielding the grammatical characteristics of the databases of different products. For users, they only need to pay attention to the required query rules.

[0065] The present invention can be made into a plug-in form, can be summarized and referenced in current mainstream B / S software, and has strong applicability.

[0066] Example 3

[0067] Figure 4 This is a flowchart of a method for generating SQL statements for a multi-entity linked query provided by the third embodiment of the present invention. This embodiment is optimized based on the above embodiment. Figure 4 As shown, when at least two target entity objects are selected from the entity objects, the method includes:

[0068] S410: Determine an association rule between at least two target entity objects, wherein the association rule corresponds to a data set form between at least two target entity objects.

[0069] Among them, when performing a multi-entity joint query on two or more target entity objects, the target entity objects need to be associated with each other to ensure that the multi-entity joint query does not result in a Cartesian product. Simply put, each member of the two entity objects is associated with any member of the other set. When developers write code, they often miss the join condition, which triggers a data in set A to be associated with another element of set B and then presented in a row of data, and it appears without error, forming a mandatory relationship; therefore, when performing a multi-entity joint query, it is necessary to configure the association rules to avoid the occurrence of such piled-up nameless data.

[0070] S420: Generate the SQL statement according to the association rule, the SQL assembly rule, the target query rule, and at least two target entity objects.

[0071] After the association rules are configured, the SQL statement for multi-entity joint query is generated through the association rules, SQL assembly rules and target query rules.

[0072] In the third embodiment of the present invention, the association rules include: inner join rules, outer join rules and full join rules;

[0073] The inner join rule corresponds to an intersection data set between at least two target entity objects;

[0074] The outer join rule corresponds to an intersection data set between at least two target entity objects and a complement data set of one of the target entity objects;

[0075] The full connection rule corresponds to a complete set of data between at least two target entity objects.

[0076] For example, there are two target entity objects A and B. When the association rule is an inner join rule, the query result only retains the part that exists in both A and B. When the association rule is an outer join rule, the query result retains the part that exists in both A and B and the remaining part of A or B; when the association rule is an outer join rule, the query result retains the part that exists in both A and B and the remaining part of A and B.

[0077] When performing a joint query on multiple entity objects, at least n-1 join rules are required. For example, if there are three target entity objects, at least two join rules are required.

[0078] Example 4

[0079] Figure 5This is a schematic diagram of the structure of a SQL statement generation device provided in the fourth embodiment of the present invention. As shown in the figure, the device includes:

[0080] An entity object selection unit 510 is configured to select at least one target entity object from at least one preset entity object as a target of an SQL statement query, wherein each entity object corresponds to a database;

[0081] A query rule configuration unit 520, configured to configure at least one target query rule for the entity object from preset query rules;

[0082] A database selection unit 530 is configured to determine a target database corresponding to the target entity object;

[0083] The statement processing unit 540 is configured to generate the SQL statement according to at least one of the target query rules, the target database, and the target entity object.

[0084] In the fourth embodiment of the present invention, the statement processing unit 540 is used to determine the data type of the target database; generate the SQL statement according to the SQL assembly rule corresponding to the data type; and generate the SQL statement according to the SQL assembly rule, the target query rule and the target entity object.

[0085] In the fourth embodiment of the present invention, when at least two target entity objects are selected from the entity objects, the statement processing unit 540 is used to determine the association rules of the at least two target entity objects, wherein the association rules correspond to the data set form between the at least two target entity objects; and generate the SQL statement according to the association rules, the SQL assembly rules, the target query rules and the at least two target entity objects.

[0086] In the fourth embodiment of the present invention, the association rules include: inner join rules, outer join rules and full join rules; the inner join rules correspond to the intersection data set between at least two of the target entity objects; the outer join rules correspond to the intersection data set between at least two of the target entity objects and the complement data set of one of the target entity objects; the full join rules correspond to the full set data set between at least two of the target entity objects.

[0087] In embodiment four of the present invention, when the query rule includes a uniqueness rule, the statement processing unit 540 is used to determine the identity query code corresponding to the uniqueness rule, and the identity query code is used to query whether the identity of the target entity object is repeated with other target entity objects; and generate the SQL statement according to the identity query code and the SQL assembly rule.

[0088] In the fourth embodiment of the present invention, when the query rule includes a non-emptiness rule,

[0089] The statement processing unit 540 is used to determine the content detection code corresponding to the uniqueness rule, where the content detection code is used to detect whether the preset content of the target entity object is empty; and generate the SQL statement according to the content detection code and the SQL assembly rule.

[0090] In the fourth embodiment of the present invention, the statement processing unit 540 is used to determine the SQL statement template to be assembled according to the SQL assembly rule; assemble the target query rule and the target entity object into the SQL statement template to be assembled to obtain the SQL statement.

[0091] The SQL statement generation device provided in the embodiment of the present invention can execute the SQL statement generation method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0092] Example 5

[0093] Figure 6 A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or claimed herein.

[0094] like Figure 6 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., which is communicatively connected to the at least one processor 11. The memory stores a computer program that can be executed by the at least one processor. The processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 into the random access memory (RAM) 13. Various programs and data required for the operation of the electronic device 10 can also be stored in the RAM 13. The processor 11, ROM 12, and RAM 13 are connected to each other via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0095] Multiple components in the electronic device 10 are connected to the I / O interface 15, including an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a magnetic disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.

[0096] The processor 11 can be any general-purpose and / or specialized processing component with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various specialized artificial intelligence (AI) computing chips, various processors that run machine learning model algorithms, a digital signal processor (DSP), and any other suitable processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as the SQL statement generation method.

[0097] In some embodiments, the SQL statement generation method can be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as the storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the SQL statement generation method described above can be performed. Alternatively, in other embodiments, the processor 11 can be configured to execute the SQL statement generation method by any other appropriate means (e.g., by means of firmware).

[0098] Various embodiments of the systems and techniques described herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), system-on-chip systems (SOCs), programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer programs that are executable and / or interpreted on a programmable system that includes at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0099] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when the computer program is executed by the processor, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The computer program may be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.

[0100] In the context of the present invention, computer-readable storage media can be tangible media that can contain or store a computer program for use with an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. Computer-readable storage media can include but are not limited to electronic, magnetic, optical, electromagnetic, infrared or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, computer-readable storage media can be machine-readable signal media. More specific examples of machine-readable storage media can include electrical connections based on one or more lines, portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0101] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0102] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0103] A computing system may include clients and servers. The clients and servers are typically remote from each other and typically interact via a communication network. This client-server relationship arises through computer programs running on the respective computers, creating a client-server relationship. The server may be a cloud server, also known as a cloud computing server or cloud host. This server is a hosting product within the cloud computing service ecosystem that addresses the management difficulties and limited scalability of traditional physical hosting and VPS services.

[0104] Example 6

[0105] An embodiment of the present invention further provides a computer program product, including a computer program, which, when executed by a processor, implements the SQL statement generation method provided in any embodiment of the present application.

[0106] The computer program product may be implemented by writing computer program code for performing the operations of the present invention in one or more programming languages, or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0107] Note that the above are only preferred embodiments of the present invention and the technical principles employed. Those skilled in the art will appreciate that the present invention is not limited to the specific embodiments herein, and that various obvious changes, readjustments, and substitutions are possible for those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in detail through the above embodiments, the present invention is not limited to the above embodiments and may include many other equivalent embodiments without departing from the scope of the present invention. The scope of the present invention is determined by the scope of the appended claims.

Claims

1. A method for generating an SQL statement, characterized in that: include: Selecting at least one target entity object from at least one preset entity object as a target of an SQL statement query, wherein each of the entity objects corresponds to a database; Configure at least one target query rule for the entity object from preset query rules; Determining a target database corresponding to the target entity object; Generate the SQL statement according to at least one of the target query rules, the target database and the target entity object; Generating the SQL statement according to at least one of the target query rules, the target database, and the target entity object includes: Determining the data type of the target database; Determine the corresponding SQL assembly rule according to the data type; Generate the SQL statement according to the SQL assembly rule, the target query rule and the target entity object; Generating the SQL statement according to the SQL assembly rule, the target query rule and the target entity object includes: Determine the SQL statement template to be assembled according to the SQL assembly rule; The target query rule and the target entity object are assembled into the SQL statement template to be assembled to obtain the SQL statement.

2. The method according to claim 1, characterized in that When at least two target entity objects are selected from the entity objects, generating the SQL statement according to the SQL assembly rule, the target query rule, and the target entity objects includes: determining an association rule between at least two of the target entity objects, wherein the association rule corresponds to a data set form between the at least two target entity objects; The SQL statement is generated according to the association rule, the SQL assembly rule, the target query rule and at least two target entity objects.

3. The method according to claim 2, characterized in that The association rules include: inner join rules, outer join rules and full join rules; The inner join rule corresponds to an intersection data set between at least two target entity objects; The outer join rule corresponds to an intersection data set between at least two target entity objects and a complement data set of one of the target entity objects; The full connection rule corresponds to a complete set of data between at least two target entity objects.

4. The method according to claim 1, wherein The query rules include uniqueness rules; Correspondingly, when the target query rule is the uniqueness rule, generating the SQL statement according to the SQL assembly rule, the target query rule and the target entity object includes: Determine an identity query code corresponding to the uniqueness rule, where the identity query code is used to query whether the identity of the target entity object is repeated with other target entity objects; The SQL statement is generated according to the identity query code and the SQL assembly rule.

5. The method according to claim 1, wherein The query rules include non-emptiness rules; Correspondingly, when the target query rule is the non-emptiness rule, generating the SQL statement according to the SQL assembly rule, the target query rule and the target entity object includes: Determining a content detection code corresponding to the non-emptiness rule, wherein the content detection code is used to detect whether the preset content of the target entity object is empty; The SQL statement is generated according to the content detection code and the SQL assembly rule.

6. A device for generating SQL statements, characterized in that: The device comprises: An entity object selection unit, configured to select at least one target entity object as a query target of an SQL statement from at least one preset entity object, wherein each of the entity objects corresponds to a database; A query rule configuration unit, configured to configure at least one target query rule for the entity object from preset query rules; A database selection unit, configured to determine a target database corresponding to the target entity object; A statement processing unit, configured to generate the SQL statement according to at least one of the target query rules, the target database, and the target entity object; The statement processing unit is used to determine the data type of the target database; generate the SQL statement according to the SQL assembly rule corresponding to the data type, the target query rule and the target entity object; The statement processing unit is used to determine a SQL statement template to be assembled according to the SQL assembly rule; assemble the target query rule and the target entity object into the SQL statement template to be assembled to obtain the SQL statement.

7. An electronic device for generating SQL statements, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the SQL statement generation method according to any one of claims 1 to 5 when executing the computer program.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the SQL statement generation method according to any one of claims 1 to 5 is implemented.

9. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the computer program implements the SQL statement generation method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Data query method and device based on rule configuration, storage medium and terminal

    CN111259037A

  • Business data query method and device, storage medium, processor and electronic equipment

    CN113434529A