Disclosure of Invention
Aiming at the defects in the prior art, the invention provides the SQL language generation system and the method, which do not require a user to master the database and the SQL language and have wider application range.
In a first aspect, a SQL language generation system includes:
an importing module: the system comprises a data table, a SQL structure and a database, wherein the data table is used for receiving user import data table and converting the data table to generate the SQL structure;
a logical relationship selection module: the SQL structure is used for receiving a logic relationship selection instruction of a user, generating a logic relationship according to the logic relationship selection instruction, and filling the logic relationship into the SQL structure;
the query logic selection module: the SQL structure is used for receiving a query logic selection instruction of a user, generating query logic according to the query logic selection instruction, and filling the query logic into the SQL structure;
a generation module: for generating the SQL language from the SQL constructs.
Preferably, the import module is specifically configured to:
analyzing the data table to obtain all fields in the data table, field values of the fields and sequencing of the fields;
and converting the fields, the corresponding field values and the sequence according to the SQL language to generate an SQL structure.
Preferably, the logical relationship selection module is specifically configured to:
parsing the logical relationship selection instruction to obtain at least one logic and at least one field value; the logic comprises AND logic, OR logic, and/or NOR logic;
nesting and/or combining the logic and field values according to a logic relation selection instruction to obtain the logic relation;
and converting the logical relation according to the SQL language, and filling the conversion result into the SQL structure.
Preferably, the logical relationship selection module is further configured to:
analyzing the logic relation selection instruction to obtain a keyword;
nesting and/or combining the key, logic and field values according to a logical relationship selection instruction to obtain the logical relationship.
Preferably, the query logic comprises one or a combination of several of the following:
multi-table joint query, left query, right query, sub-queries, and aggregation.
In a second aspect, a method for generating an SQL language includes the following steps:
receiving a user import data table, and converting the data table to generate an SQL structure;
receiving a logic relationship selection instruction of a user, generating a logic relationship according to the logic relationship selection instruction, and filling the logic relationship into the SQL structure;
receiving a query logic selection instruction of a user, generating query logic according to the query logic selection instruction, and filling the query logic into the SQL structure;
and generating the SQL language according to the SQL structure.
Preferably, the converting the data table to generate the SQL structure specifically includes:
analyzing the data table to obtain all fields in the data table, field values of the fields and sequencing of the fields;
and converting the fields, the corresponding field values and the sequence according to the SQL language to generate an SQL structure.
Preferably, the generating a logical relationship according to the logical relationship selection instruction, and the populating the logical relationship into the SQL structure specifically includes:
parsing the logical relationship selection instruction to obtain at least one logic and at least one field value; the logic comprises AND logic, OR logic, and/or NOR logic;
nesting and/or combining the logic and field values according to a logic relation selection instruction to obtain the logic relation;
and converting the logical relation according to the SQL language, and filling the conversion result into the SQL structure.
Preferably, after parsing the logical relationship selection instruction to obtain at least one logic and at least one field value, the method further includes:
analyzing the logic relation selection instruction to obtain a keyword;
the nesting and/or combining the logic and field values according to the logic relationship selection instruction to obtain the logic relationship specifically includes:
nesting and/or combining the key, logic and field values according to a logical relationship selection instruction to obtain the logical relationship.
Preferably, the query logic comprises one or a combination of several of the following:
multi-table joint query, left query, right query, sub-queries, and aggregation.
According to the technical scheme, the SQL language generation system and the method can generate the SQL language according to the configuration of the user, do not require the user to master the database and the SQL language, and are wider in application range.
Detailed Description
Embodiments of the present invention will be described in detail below with reference to the accompanying drawings. The following examples are only for illustrating the technical solutions of the present invention more clearly, and therefore are only examples, and the protection scope of the present invention is not limited thereby. It is to be noted that, unless otherwise specified, technical or scientific terms used herein shall have the ordinary meaning as understood by those skilled in the art to which the invention pertains.
It will be understood that the terms "comprises" and/or "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It is also to be understood that the terminology used in the description of the invention herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in the specification of the present invention and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
It should be further understood that the term "and/or" as used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
As used in this specification and the appended claims, the term "if" may be interpreted contextually as "when", "upon" or "in response to a determination" or "in response to a detection". Similarly, the phrase "if it is determined" or "if a [ described condition or event ] is detected" may be interpreted contextually to mean "upon determining" or "in response to determining" or "upon detecting [ described condition or event ]" or "in response to detecting [ described condition or event ]".
The first embodiment is as follows:
an SQL language generation system, see fig. 1, comprising:
an importing module: the method is used for receiving a user import data table, converting the data table and generating an SQL structure, and specifically comprises the following steps:
analyzing the data table to obtain all fields in the data table, field values of the fields and sequencing of the fields;
and converting the fields, the corresponding field values and the sequence according to the SQL language to generate an SQL structure.
Specifically, the data table is actively imported by the user, and the user imports the specific data table according to the condition of the user. And after receiving the data table, the import module analyzes the data table, acquires the related structure of the data table, and obtains all fields in the data table, the field values of the fields and the sequence of the fields. For example, the fields include name, gender, age group, and the like. Different field values are set for different fields, for example, a gender field contains a field value of male or female. The import module analyzes the fields, field values and sequences and converts the fields, field values and sequences into a standard SQL structure according to the SQL language.
The import module may convert the fields and corresponding field values by: firstly, identifying the type of the field, then uniformly converting the identified type into a standard type, then establishing an incidence relation among the fields, finally formatting the analyzed field, field value and sequencing according to the incidence relation of the fields, and finally uniformly displaying the formatted data to a user for viewing.
For example: assuming that the timestamp T in the table a is int (digital type, timestamp is from 1 month and 1 day to the current seconds in 1970), the ordinary user cannot understand the meaning of the timestamp, and the system converts the timestamp into year, month, day, hour, minute and second before presentation, so as to present the timestamp to the user. For example, the table B in the oracle library has a product number id, the table C in the mysql library has a product name, the field types in the two libraries are slightly different, and after the user sets the association of the two fields, the product number in the table B can be converted into the product name through comparison and presented to the user.
A logical relationship selection module: the method is used for receiving a logic relationship selection instruction of a user, generating a logic relationship according to the logic relationship selection instruction, and filling the logic relationship into the SQL structure, and specifically comprises the following steps:
analyzing the logic relation selection instruction to obtain at least one logic relation; the logic comprises AND logic, OR logic, and/or NOR logic;
nesting and/or combining the logic and field values according to a logic relation selection instruction to obtain the logic relation;
and converting the logical relation according to the SQL language, and filling the conversion result into the SQL structure.
Specifically, the system may be configured with an interactive interface facing a common user, and the interactive interface is configured with corresponding input boxes for the user to input a logic relationship selection instruction and a query logic selection instruction.
The logic relation selection module is used for a user to select logic, including AND, OR and NOT. And the user inputs the field value needing to be subjected to the logic operation, and the logic and the field value are nested and/or combined to obtain the logic relation. For example, when the user wants to search the information of Zhang III of male, the input field values are Zhang III and male, and the logic is AND, so that the combined logical relationship is Zhang III and male. When the logic relation selection module performs logic operation of the field value, if complex logic is encountered, the field value and the logic can be nested and combined.
When the logic relation selection module converts the logic relation, the logic relation is intercepted and spliced by using an interception and splicing method of the SQL language, and a conversion result is filled in the SQL structure generated by the import module.
Preferably, the logical relationship selection module is further configured to:
analyzing the logic relation selection instruction to obtain a keyword;
nesting and/or combining the key, logic and field values according to a logical relationship selection instruction to obtain the logical relationship.
Specifically, the logic relationship selection module is also used for inputting keywords by a user, the user can input the keywords while inputting the logic and the field value, the input of the logic, the field value and the keywords is not in sequence, and the user can independently input the keywords according to the self condition. The keywords are additional settings, such as how many lines are displayed, etc. The input of the logic, the field value and the key words can be input by the user on the established interactive interface.
The query logic selection module: the SQL structure is used for receiving a query logic selection instruction of a user, generating query logic according to the query logic selection instruction, and filling the query logic into the SQL structure;
preferably, the query logic comprises one or a combination of several of the following:
multi-table joint query, left query, right query, sub-queries, and aggregation.
Specifically, the user can select the corresponding query logic through the query logic selection module, and the query logic selection module can further guide the user to set the corresponding query field according to the selected query logic, and fill the query logic into the SQL structure to form a complete SQL structure.
A generation module: for generating the SQL language from the SQL constructs.
Specifically, the generating module generates the SQL language according to the SQL structure, so that the SQL language is suitable for common users, even if the common users do not master the database and the SQL language, the SQL language can be generated and managed by inputting logical combination without learning database knowledge.
The system can generate the SQL language according to the configuration of the user, does not require the user to master the database and the SQL language, and is wider in application range of the user.
Example two:
a method for generating SQL language, see fig. 2, comprising the following steps:
s1: receiving a user import data table, and converting the data table to generate an SQL structure;
s2: receiving a logic relationship selection instruction of a user, generating a logic relationship according to the logic relationship selection instruction, and filling the logic relationship into the SQL structure;
s3: receiving a query logic selection instruction of a user, generating query logic according to the query logic selection instruction, and filling the query logic into the SQL structure;
s4: and generating the SQL language according to the SQL structure.
Preferably, the converting the data table to generate the SQL structure specifically includes:
analyzing the data table to obtain all fields in the data table, field values of the fields and sequencing of the fields;
and converting the fields, the corresponding field values and the sequence according to the SQL language to generate an SQL structure.
Preferably, the generating a logical relationship according to the logical relationship selection instruction, and the populating the logical relationship into the SQL structure specifically includes:
parsing the logical relationship selection instruction to obtain at least one logic and at least one field value; the logic comprises AND logic, OR logic, and/or NOR logic;
nesting and/or combining the logic and field values according to a logic relation selection instruction to obtain the logic relation;
and converting the logical relation according to the SQL language, and filling the conversion result into the SQL structure.
Preferably, after parsing the logical relationship selection instruction to obtain at least one logic and at least one field value, the method further includes:
analyzing the logic relation selection instruction to obtain a keyword;
the nesting and/or combining the logic and field values according to the logic relationship selection instruction to obtain the logic relationship specifically includes:
nesting and/or combining the key, logic and field values according to a logical relationship selection instruction to obtain the logical relationship.
Preferably, the query logic comprises one or a combination of several of the following:
multi-table joint query, left query, right query, sub-queries, and aggregation.
For the sake of brief description, the method provided by the embodiment of the present invention may refer to the corresponding contents in the foregoing system embodiments.
Finally, it should be noted that: the above embodiments are only used to illustrate the technical solution of the present invention, and not to limit the same; while the invention has been described in detail and with reference to the foregoing embodiments, it will be understood by those skilled in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; such modifications and substitutions do not depart from the spirit and scope of the present invention, and they should be construed as being included in the following claims and description.