SQL statement generation method, device, electronic device and storage medium
Through the SQL statement generation method of the Vue framework, users are guided to select SQL sub-statements in the specified order and assemble and translate them, solving the problem of difficulty in writing SQL by non-professional users, improving development efficiency and code quality, and supporting flexible querying.
Patent Information
- Application Number
- CN202110670309.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-17
- Publication Date
- 2025-01-07
- Estimated Expiration
- 2041-06-17
AI Technical Summary
In the prior art, non-professional users have difficulty in writing SQL statements, mainly because the writing order of SQL clauses is fixed and the writing process is complicated, making it difficult to meet flexible query scenarios.
Provides a SQL statement generation method based on the Vue framework. Through the preset interface, users are guided to select SQL sub-statements in the specified order, generate Chinese SQL sub-statements, and assemble and translate according to the English writing order to form executable SQL statements.
It reduces the difficulty of non-professional users to write SQL statements, improves the efficiency and quality of code development, supports the use of database functions, and meets more query scenarios.
Smart Images

Figure CN113326282B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to computer technology, and in particular to a method, device, electronic device and storage medium for generating SQL statements. Background Art
[0002] In recent years, with the development of computers and databases, Structured Query Language (SQL), a database-specific computer programming language, has been widely used and has become the most important and most commonly used relational database operating language.
[0003] However, the current method of editing SQL statements is to generate SQL statements by having users with relevant expertise such as databases write them at the back end. This method requires a high level of background knowledge from users who write SQL statements. In particular, the writing order of SQL clauses is fixed and cannot be changed at will. Changing the writing order will cause execution errors.
[0004] Therefore, the current SQL statement editing method has great difficulty for non-professional users. Summary of the invention
[0005] The present application provides a SQL statement generation method, device, electronic device and storage medium to solve the problem that non-professional users have difficulty in writing SQL statements.
[0006] In a first aspect, an embodiment of the present application provides a method for generating an SQL statement, comprising:
[0007] In response to a selection operation made by a user in a specified order on a preset interface, a plurality of Chinese structured query language SQL sub-statements are generated, wherein the preset interface is constructed based on a Vue framework;
[0008] According to the processing requirements of the preset English writing order, the plurality of Chinese-translated SQL sub-statements are assembled and processed to obtain a Chinese-translated SQL statement;
[0009] The Chinese SQL statement is translated into English to obtain an SQL statement.
[0010] In an optional implementation, in response to the selection operation made by the user in a preset interface in a specified order, a plurality of Chinese structured query language SQL sub-statements are generated, including:
[0011] In response to a first operation performed by a user on a first sub-interface of the preset interface, generating a table selection result corresponding to the first operation;
[0012] Switching the preset interface from the first sub-interface to the second sub-interface of the preset interface;
[0013] In response to a second operation performed by a user on a second sub-interface of the preset interface, generating a field selection result corresponding to the second operation;
[0014] Switching the preset interface from the second sub-interface to the third sub-interface of the preset interface;
[0015] In response to a third operation performed by the user on a third sub-interface of the preset interface, a definition selection result corresponding to the third operation is generated, and the table selection result, the field selection result and the definition selection result are determined as the Chinese structured query language SQL sub-statement.
[0016] In an optional implementation, the definition selection result includes one or more of a condition definition result, a grouping definition result, a sorting definition result, and a statement information definition result.
[0017] In an optional implementation manner, after generating a field selection result corresponding to a second operation performed by the user on a second sub-interface of the preset interface in response to the second operation performed by the user, the method further includes:
[0018] In response to an interface switching operation performed by a user on the preset interface, the preset interface is switched to a sub-interface corresponding to the interface switching operation.
[0019] In an optional implementation manner, before the step of switching the preset interface to a sub-interface corresponding to the interface switching operation performed by the user on the preset interface, the step further includes:
[0020] It is determined that the first sub-interface has a table selection result and the second sub-interface has a field selection result.
[0021] In an optional embodiment, the method further comprises:
[0022] If it is detected that the table selection result in the first sub-interface is changed, the field selection result in the second sub-interface and the definition selection result in the third sub-interface are cleared.
[0023] In an optional embodiment, the method further comprises:
[0024] If it is detected that the table selection result in the second sub-interface is changed, the definition selection result in the third sub-interface is cleared.
[0025] In a second aspect, an embodiment of the present application provides a SQL statement generating device, comprising:
[0026] An SQL sub-statement generation module, used to generate a plurality of Chinese structured query language SQL sub-statements in response to selection operations made by a user in a preset interface in a specified order, wherein the preset interface is constructed based on a Vue framework;
[0027] A processing module, used for assembling the plurality of Chinese SQL sub-statements according to a preset processing requirement of an English writing order to obtain a Chinese SQL statement;
[0028] The translation module is used to translate the Chinese SQL statement into English to obtain an SQL statement.
[0029] In an optional implementation manner, the SQL sub-statement generation module includes:
[0030] A table selection result generating unit, configured to generate a table selection result corresponding to a first operation performed by a user on a first sub-interface of the preset interface in response to the first operation performed by the user on the first sub-interface of the preset interface;
[0031] A first switching unit, used to switch the preset interface from the first sub-interface to the second sub-interface of the preset interface;
[0032] a field selection result generating unit, configured to generate a field selection result corresponding to a second operation performed by a user on a second sub-interface of the preset interface;
[0033] A second switching unit, used to switch the preset interface from the second sub-interface to a third sub-interface of the preset interface;
[0034] A definition selection result generating unit is used to generate a definition selection result corresponding to the third operation performed by the user on the third sub-interface of the preset interface in response to the third operation performed by the user on the third sub-interface of the preset interface, and determine the table selection result, the field selection result and the definition selection result as the Chinese structured query language SQL sub-statement.
[0035] In an optional implementation, the definition selection result includes one or more of a condition definition result, a grouping definition result, a sorting definition result, and a statement information definition result.
[0036] In an optional implementation manner, the SQL statement generating device further includes:
[0037] The switching operation response module is used to respond to the interface switching operation performed by the user on the preset interface and switch the preset interface to a sub-interface corresponding to the interface switching operation.
[0038] In an optional implementation manner, the switching operation response module is further used to:
[0039] It is determined that the first sub-interface has a table selection result and the second sub-interface has a field selection result.
[0040] In an optional implementation manner, the SQL statement generating device further includes:
[0041] The first clearing module is used to clear the field selection results in the second sub-interface and the definition selection results in the third sub-interface if it is detected that the table selection result in the first sub-interface has changed.
[0042] In an optional implementation manner, the SQL statement generating device further includes:
[0043] The second clearing module is used to clear the definition selection result in the third sub-interface if it is detected that the table selection result in the second sub-interface has changed.
[0044] In a third aspect, an embodiment of the present application provides an electronic device, including: a memory and a processor;
[0045] A memory for storing instructions executable by the processor;
[0046] The processor is configured to execute the method provided in the above embodiment.
[0047] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which computer-readable storage medium is stored computer-executable instructions, and when the computer-executable instructions are executed by a processor, they are used to implement the method provided in the above embodiment.
[0048] In a fifth aspect, an embodiment of the present application further provides a computer program product, including a computer program, which, when executed by a processor, implements a method provided in any embodiment corresponding to the first aspect of the present application.
[0049] The SQL statement generation method, device, electronic device and storage medium provided by the present application generate multiple Chinese structured query language SQL sub-statements by responding to the selection operation made by the user in a specified order on the preset interface, wherein the preset interface is constructed based on the Vue framework, so that the user can be guided to select SQL sub-statements in a preset process order through the preset interface, and the SQL sub-statements are Chinese versions, which are convenient for non-professional users to choose. Then, according to the processing requirements of the preset English writing order, multiple Chinese SQL sub-statements are assembled and processed to obtain Chinese SQL statements, so that the Chinese SQL sub-statements are adjusted to the English writing order so that the database can execute. Finally, the Chinese SQL statements are translated into English to obtain SQL statements. In other words, when the user needs to implement the Chinese SQL editor in the Vue project, the preset interface (Vue component) is directly called and selected according to the specified guide process. It is easy to get started, which reduces the difficulty of non-professional users to write SQL statements and improves code development efficiency and code quality. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0051] Figure 1 A flowchart of a method for generating a SQL statement provided in an embodiment of the present application;
[0052] Figure 2 A flowchart of another SQL statement generation method provided in an embodiment of the present application;
[0053] Figure 3 A schematic diagram of the first sub-interface provided in an embodiment of the present application;
[0054] Figure 4 A schematic diagram of the second sub-interface provided in an embodiment of the present application;
[0055] Figure 5 A schematic diagram of the third sub-interface provided in the embodiment of the present application;
[0056] Figure 6 A specific implementation flow chart of the Chinese SQL editor provided in the embodiment of the present application;
[0057] Figure 7 A schematic diagram of the structure of a SQL statement generation device provided in an embodiment of the present application;
[0058] Figure 8 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application;
[0059] Fig. 9It is a block diagram of an electronic device provided in an embodiment of the present application.
[0060] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0061] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0062] With the rapid development of informatization, the application of databases is becoming more and more common. SQL, as a standard computer language for accessing and processing databases, is used to retrieve and update data in databases. The SELECT statement is the most commonly used basic SQL statement, which is used to select data from a table. Its basic syntax is as follows:
[0063] SELECT
[0064] <column name 1>, <column name 2>, <column name 3>,......
[0065] FROM
[0066] WHERE <conditional expression>
[0067] GROUP BY
[0068] <column name 1>, <column name 2>, <column name 3>,......
[0069] HAVING <condition corresponding to the grouping result>
[0070] ORDER BY <sort base column 1>, <sort base column 2>, ...
[0071] According to the above basic syntax, the SELECT statement consists of the SELECT sub-statement, the FROM sub-statement, the WHERE sub-statement, the GROUP BY sub-statement, the HAVING sub-statement, and the ORDER BY sub-statement. In a basic SELECT statement, the SELECT sub-statement and the FROM sub-statement are indispensable, and other sub-statements can be retained or not retained according to the actual situation. It is worth noting that the writing order of SQL sub-statements is fixed and cannot be changed at will. Changing the writing order will cause execution errors. For example: GROUP BY must be written after the FROM statement, and if there is a WHERE sub-statement, it must be written after the WHERE sub-statement.
[0072] In audit business scenarios, business personnel are usually required to write a large number of SQL models for audit verification and analysis. Since writing English SQL requires business personnel to have a certain SQL foundation, it is difficult and challenging for non-SQL technical personnel.
[0073] In the related art, JavaScript programs are usually used to automatically splice the SELECT sub-statement, FROM sub-statement, WHERE sub-statement, and GROUP BY sub-statement of the SQL statement according to the English name of the dragged object to complete the assembly of the SQL statement. However, this method does not support the use of database functions, resulting in the inflexibility of the written SQL statement, limited scope of use, and unable to meet some user query scenarios.
[0074] In addition, the above solution is implemented based on JavaScript, which requires frequent operations on DOM objects during coding. The development process is complicated, and the view code is not separated from the business logic, resulting in high costs for subsequent code maintenance.
[0075] The embodiments of the present application provide a SQL statement generation method, device, electronic device and storage medium, aiming to solve the above technical problems of the prior art. The SQL statement generation method provided in the embodiments of the present application is easy to use, reduces the difficulty of writing SQL statements for non-professional users, and improves code development efficiency and code quality.
[0076] The following is an explanation of the relevant terms involved in this embodiment:
[0077] Vue: is a progressive JavaScript framework for building interfaces.
[0078] SQL: It is the abbreviation of Structured Query Language. Its Chinese name is Structured Query Language. It is a database query and programming language. Its function is to enable us to access the database and to retrieve and update the data in the database.
[0079] MVVM: It is the abbreviation of Model-View-View-Model. MVVM abstracts the state and behavior of the View to separate the view from the business logic.
[0080] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0081] Figure 1 A flowchart of a method for generating a SQL statement provided in an embodiment of the present application is shown in FIG. Figure 1 As shown, the method provided in this embodiment includes:
[0082] 101. In response to a selection operation made by a user in a preset interface in a specified order, a plurality of Chinese structured query language SQL sub-statements are generated, wherein the preset interface is constructed based on a Vue framework.
[0083] Exemplarily, the execution subject of this embodiment can be an electronic device, or a terminal device, or a Chinese SQL editor or device based on Vue, or other devices or equipment that can execute this embodiment, without limitation. This embodiment is described with the execution subject being an electronic device. Among them, the electronic device can be configured with a display component and an input component to enable interaction between a user and the electronic device. Optionally, the display component can include a liquid crystal display, and the input component can include a mouse, a button, etc. Optionally, the display component and the input component can be integrated together, such as a touch screen.
[0084] In some embodiments, the electronic device may display a preset interface through a display component, wherein the preset interface may display different categories of SQL substatement options for the user to select, for example, the SQL substatement options may include multiple options in the table (i.e., FROM substatement) category, multiple options in the display field (i.e., SELECT substatement) category, multiple options in the definition condition (i.e., WHERE substatement) category, etc. The user may make a selection operation on the preset interface through the input component, and when the electronic device receives the selection operation, it may respond to the selection operation and generate a SQL substatement corresponding to the selection operation, thereby selecting a required SQL substatement from each category of SQL substatement options to generate a corresponding SQL substatement.
[0085] Since the writing order of SQL clauses is fixed, changes in the writing order will cause execution errors. Therefore, the preset interface can guide users to make selection operations in the specified order. Since the existence of the WHERE sub-statement requires the existence of a SELECT sub-statement, and the existence of the SELECT sub-statement requires the existence of a FROM sub-statement, the specified order can be to select the FROM sub-statement first, then the SELECT sub-statement, and then the WHERE sub-statement.
[0086] As an example, the preset interface may include multiple interfaces, each of which can be used to select a SQL sub-statement, and after a SQL sub-statement is selected, the user can switch to the next interface to select another SQL sub-statement, thereby ensuring that the user can select SQL sub-statements in a specified order.
[0087] As another example, the electronic device may control the selection permission of another SQL substatement according to the selection of one SQL substatement. For example, after the FROM substatement is selected, the selection permission of the SELECT substatement is opened to ensure that the user can select SQL substatements in a specified order.
[0088] Optionally, the preset interface and SQL sub-statements are pre-localized, that is, the SQL sub-statements originally in English are converted into corresponding Chinese characters, and then displayed in the form of Chinese characters to facilitate viewing by non-professional users.
[0089] 102. According to the processing requirements of the preset English writing order, multiple Chinese SQL sub-statements are assembled and processed to obtain Chinese SQL statements.
[0090] In some implementations, the electronic device may assemble the Chinese SQL sub-statements into Chinese SQL statements based on the completed SQL sub-statement contents in accordance with the writing order of English SQL, wherein the English writing order is the order of writing statements in accordance with English grammar.
[0091] Since the writing order of statements according to Chinese grammar is different from that according to English grammar, and SQL statements are executed in the order written in English, it is necessary to convert the contents of the Chinese SQL sub-statements into the English writing order and then assemble them into Chinese SQL statements.
[0092] 103. Translate the Chinese SQL statement into English to obtain the SQL statement.
[0093] In some implementations, when the electronic device needs to submit the Chinese SQL statement to the database for execution, it only needs to translate the Chinese SQL statement into English SQL.
[0094] In this embodiment, by responding to the selection operation made by the user in the preset interface in a specified order, a plurality of Chinese structured query language SQL sub-statements are generated, wherein the preset interface is constructed based on the Vue framework, so that the user can be guided to select SQL sub-statements in a preset process order through the preset interface, and the SQL sub-statements are Chinese versions, which are convenient for non-professional users to choose. Then, according to the processing requirements of the preset English writing order, a plurality of Chinese SQL sub-statements are assembled and processed to obtain Chinese SQL statements, so that the Chinese SQL sub-statements are adjusted to the English writing order so that the database can execute. Finally, the Chinese SQL statements are translated into English to obtain SQL statements. In other words, when the user needs to implement the Chinese SQL editor in the Vue project, the preset interface (Vue component) is directly called and selected according to the specified guide process. It is easy to get started, reduces the difficulty of non-professional users to write SQL statements, and improves code development efficiency and code quality.
[0095] Figure 2 A flowchart of another SQL statement generation method provided in an embodiment of the present application is shown as follows: Figure 2 As shown, the method provided in this embodiment includes:
[0096] 201. In response to a first operation performed by a user on a first sub-interface of a preset interface, generate a table selection result corresponding to the first operation.
[0097] As an example, Figure 3 As shown, Figure 3 The interface schematic diagram of the first sub-interface is shown. Specifically, taking the account table as an example, the first sub-interface may include a query area and an account table selection area. The user can search for the account table in the query area by selecting the account table type, entering the Chinese table name, and selecting the source system. The account table found can then be displayed in the list of optional account tables in the account table selection area. In addition, the account table that the user has selected can be displayed in the selected account table. Optionally, the first sub-interface also includes add and delete icons. The user can delete the selected account table in the list of selected account tables by clicking the delete icon on the first sub-interface, and add the selected account table in the optional account table to the list of selected account tables by clicking the add icon on the first sub-interface.
[0098] When the user performs a first operation on the first sub-interface, the electronic device can generate a table selection result corresponding to the first operation in response to the first operation performed by the user on the first sub-interface of the preset interface. For example, if the first operation is to select a personal basic information table in the first sub-interface, the table selection result is the personal basic information table. Optionally, the first operation includes but is not limited to: click, slide, character input and other operations.
[0099] 202. Switch the preset interface from the first sub-interface to the second sub-interface of the preset interface.
[0100] When the electronic device detects that the table selection result is determined, the electronic device can switch the preset interface from the first sub-interface to the second sub-interface of the preset interface.
[0101] 203. In response to a second operation performed by the user on a second sub-interface of the preset interface, a field selection result corresponding to the second operation is generated.
[0102] As an example, Figure 4 As shown, Figure 4 The interface schematic diagram of the second sub-interface is shown. Specifically, the second sub-interface may include an optional area and an edit field area. In the optional area, the user can select optional fields (such as selecting fields such as customer number, Chinese name, gender code, etc.), function symbols (such as finding statistical variance, finding sum, finding variance, finding minimum value, etc.), and operation symbols (such as addition, subtraction, multiplication, division, etc.). In the edit field area, the user can enter the field by himself, including entering Chinese field name, English field name, field expression, etc. Optionally, the second sub-interface may also include icons such as clear, add, and modify for the user to adjust the field selected in the second sub-interface. Optionally, after the user makes a selection in the optional area, the edit field area may generate a corresponding field expression based on the selection result.
[0103] When the user performs a second operation on the second sub-interface, the electronic device can generate a table selection result corresponding to the second operation in response to the second operation performed by the user on the second sub-interface of the preset interface. For example, if the second operation is a field expression entered in the edit field area of the second sub-interface, the field expression can be determined as the field selection result. Optionally, the second operation includes but is not limited to: click, slide, character input and other operations.
[0104] 204. Switch the preset interface from the second sub-interface to the third sub-interface of the preset interface.
[0105] When the electronic device detects that the field selection result is determined, the electronic device can switch the preset interface from the second sub-interface to the third sub-interface of the preset interface.
[0106] 205. In response to a third operation performed by the user on a third sub-interface of the preset interface, a definition selection result corresponding to the third operation is generated, and the table selection result, the field selection result, and the definition selection result are determined as Chinese structured query language SQL sub-statements.
[0107] As an example, Figure 5 As shown, Figure 5The schematic diagram of the interface of the third sub-interface is shown. Specifically, taking the definition selection as a specified condition search as an example, the third sub-interface may include an optional area and an editing area. In the optional area, the user can select optional fields, function symbols, symbols, model parameters, etc. In the editing field area, the user can enter the search condition by himself. Optionally, after the user makes a selection in the optional area, the editing area can generate a corresponding search condition expression based on the selectable selection results. For example, the search condition expression can be: CIF_Personal Basic Information Table. Customer Number is equal to CIF_Historical Personal Certificate Identification Table. Customer Number.
[0108] Then, the electronic device may determine the table selection results, field selection results, and definition selection results selected in the first sub-interface, the second sub-interface, and the third sub-interface as Chinese SQL sub-statements.
[0109] In some implementations, the definition selection result includes one or more of a condition definition result, a grouping definition result, a sorting definition result, and a statement information definition result.
[0110] Among them, the selection of condition definition results, grouping definition results, sorting definition results and statement information definition results can be selected by switching the above sub-interfaces, and the user determines a definition result through each sub-interface. Among them, the selection order of condition definition results, grouping definition results, sorting definition results and statement information definition results is condition definition results, grouping definition results, sorting definition results and statement information definition results.
[0111] In some implementations, after step 203, the method further includes: in response to an interface switching operation performed by a user on a preset interface, switching the preset interface to a sub-interface corresponding to the interface switching operation.
[0112] As an example, see again Figure 5 , Figure 5 The third sub-interface includes six step selection icons from 1 to 6. The user can select the icon corresponding to the number and switch to the sub-interface corresponding to the selected number. For example, if the user clicks the icon "2" in the third sub-interface, it can switch to the second sub-interface, so that the user can switch between different sub-interfaces to facilitate editing of SQL sub-statements.
[0113] As a method, before responding to an interface switching operation made by the user on the preset interface and switching the preset interface to the sub-interface corresponding to the interface switching operation, it is also necessary to determine whether there is a table selection result in the first sub-interface and a field selection result in the second sub-interface.
[0114] As an example, the electronic device can detect whether there is a table selection result in the first sub-interface and whether there is a field selection result in the second sub-interface. If there is a table selection result in the first sub-interface and a field selection result in the second sub-interface, the electronic device can execute an interface switching operation in response to the user's operation on the preset interface, and switch the preset interface to a sub-interface corresponding to the interface switching operation. If there is no table selection result in the first sub-interface and / or no field selection result in the second sub-interface, the electronic device can issue a prompt message to prompt the user to select in the corresponding sub-interface.
[0115] It is understandable that in the selection SQL sub-statement, selecting the account table is a prerequisite for selecting the field and defining the conditions. If the account table is not selected, you cannot proceed to the subsequent selection; selecting the display field is a required option after selecting the account table. If the field is not selected, you cannot continue to select the definition condition.
[0116] In some embodiments, the method further includes: if the electronic device detects that the table selection result in the first sub-interface has changed, clearing the field selection result in the second sub-interface and the definition selection result in the third sub-interface.
[0117] In some other embodiments, the method further includes: if the electronic device detects that the table selection result in the second sub-interface has changed, clearing the definition selection result in the third sub-interface.
[0118] 206. According to the processing requirements of the preset English writing order, multiple Chinese SQL sub-statements are assembled and processed to obtain Chinese SQL statements.
[0119] 207. Translate the Chinese SQL statement into English to obtain the SQL statement.
[0120] The specific implementation of step 206 to step 207 may refer to step 102 to step 103, so it will not be repeated here.
[0121] As an example, steps 201 to 207 are described as a whole. In practical applications, Figure 6 As shown, the SQL statement generation method of this embodiment can be regarded as a specific implementation process of a Chinese SQL editor, which includes: step 1: select account table, step 2: select display field, step 3: define condition, step 4: define group, step 5: define sort, step 6: define statement information. Each of the above six steps corresponds to Figures 3 to 5 Specifically, the multiple sub-interfaces shown have a one-to-one correspondence between the step numbers and the sub-interface numbers. For example, step 1 corresponds to the sub-interface numbered 1 (selecting audit accounts and tables), step 2 corresponds to the sub-interface numbered 2 (selecting display fields), step 3 corresponds to the sub-interface numbered 3 (specifying search conditions), and so on.
[0122] Among them, in the above six steps, the specific meaning of each step is as follows:
[0123] Step 1: Select the FROM sub-statement function corresponding to the account table, which is used to select the table name for data.
[0124] Step 2: Select the display field corresponding to the SELECT substatement function, which is used to define the column name of the query, supports the writing of column names, constants, and expressions, supports users to use various functions and operators to process fields, and supports adjusting the order of displayed fields.
[0125] Step 3: Define the search conditions corresponding to the WHERE sub-statement function, which is used to select data that meets certain conditions. When multiple condition combination queries are involved, the AND operator or OR operator can be used to combine the condition expressions.
[0126] Step 4: Define the grouping corresponding to the GROUP BY sub-statement function to achieve group aggregation.
[0127] Step 5: Define the sorting function corresponding to the ORDER BY sub-statement to implement the sorting of query results.
[0128] Step 6: Although the definition statement information does not belong to the SQL sub-statement content, it can be used to describe the role and purpose of this SQL, similar to the comment function of SQL code.
[0129] The above six steps can be used to write Chinese SQL statements. This statement mode can be used to select data from the results of a single table or multiple table associations (including outer joins, inner joins, natural joins, and other joint table methods).
[0130] It can be understood that the Chinese SQL editor proposed in this embodiment is implemented using Vue technology. Therefore, when implementing the Chinese SQL editor, based on the Vue component concept, each step is abstracted into a sub-component with specific functions (equivalent to the above-mentioned sub-interface). When the user switches steps, the content of the functional sub-component can be passed to the parent component through the $emit method, and the legal verification rules of the parent component can be called. If the verification passes, switch to the specified step, otherwise the user is prompted to make modifications.
[0131] Since the objects of SQL operations are mainly accounts and tables and their fields in the database. In this embodiment, selecting an account table is the prerequisite for all steps. If an account table is not selected, the subsequent steps cannot be entered; selecting display fields is a mandatory option after selecting an account table; defining conditions, defining groups, defining sorting, and defining statement information are not mandatory options, and whether to enter them is determined by the functions implemented by the user's SQL. Therefore, the legal verification rules of the parent component mentioned above mean that when the interface with the later sorting needs to be switched, it is necessary to ensure that the sub-interface with the previous sorting already has the selected result.
[0132] Optionally, in order to improve the intelligence of the Chinese SQL editor and reduce the probability of user errors, the Chinese SQL editor can use the Watch property of Vue to monitor the selected account table in step 1 and the selected field in step 2. When the selected account table changes, all selected or entered contents from step 2 to step 6 are automatically cleared; when the selected field changes, all selected or entered contents from step 3 to step 6 are automatically cleared.
[0133] When the user completes the SQL sub-statement content according to the specified process, that is, in the order of selecting account tables, selecting display fields, defining conditions, defining groups, and defining sorting, the present invention assembles the Chinese SQL statement according to the SQL grammar rules and writing order, and generates a Chinese SQL statement with a structure similar to "query...from...conditions...grouping...sorting..." When it needs to be submitted to the database for operation, the Chinese SQL statement can be translated into English SQL.
[0134] It can be seen that the SQL statement generation method of this embodiment can be implemented through the above-described steps. The method guides the user in a process manner to follow the specified steps, that is, select the account table, select the display field, define the condition, define the grouping, and define the sorting to complete the SQL sub-statement selection content. Based on the completed SQL sub-statement content, the Chinese SQL sub-statements in each step are assembled into Chinese SQL statements in the writing order of English SQL. When it is necessary to submit the database for execution, the Chinese SQL statement can be translated into English SQL. On the one hand, this reduces the difficulty of writing SQL for non-SQL technicians, and on the other hand, based on the two-way data binding characteristics of Vue, it supports users to modify the content of a certain step at will and dynamically respond to the content of the steps related to it; and it is implemented in the form of Vue components. When it is necessary to implement the Chinese SQL editor in the Vue project, the Vue component can be directly called, which is convenient to import and easy to get started, reducing the difficulty of implementing the Chinese SQL editor and improving code development efficiency and code quality.
[0135] Figure 7 A schematic diagram of the structure of a SQL statement generation device provided in an embodiment of the present application is shown in FIG. Figure 7As shown, the device comprises:
[0136] The SQL sub-statement generation module 31 is used to generate a plurality of Chinese structured query language SQL sub-statements in response to selection operations made by the user in a specified order on a preset interface, wherein the preset interface is constructed based on the Vue framework.
[0137] The processing module 32 is used to assemble and process multiple Chinese SQL sub-statements according to the processing requirements of the preset English writing order to obtain a Chinese SQL statement.
[0138] The translation module 33 is used to translate the Chinese SQL statement into English to obtain an SQL statement.
[0139] In one example, the SQL substatement generation module 31 includes:
[0140] The table selection result generating unit is used to generate a table selection result corresponding to the first operation in response to a first operation performed by a user on a first sub-interface of a preset interface.
[0141] The first switching unit is used to switch the preset interface from the first sub-interface to the second sub-interface of the preset interface.
[0142] The field selection result generating unit is used to generate a field selection result corresponding to the second operation in response to a second operation performed by the user on the second sub-interface of the preset interface.
[0143] The second switching unit is used to switch the preset interface from the second sub-interface to the third sub-interface of the preset interface.
[0144] The definition selection result generating unit is used to generate a definition selection result corresponding to the third operation in response to the third operation performed by the user on the third sub-interface of the preset interface, and determine the table selection result, field selection result and definition selection result as a Chinese structured query language SQL sub-statement.
[0145] In one example, the definition selection result includes one or more of a condition definition result, a grouping definition result, a sorting definition result, and a statement information definition result.
[0146] In one example, the SQL statement generating device further includes:
[0147] The switching operation response module is used to respond to the interface switching operation performed by the user on the preset interface and switch the preset interface to a sub-interface corresponding to the interface switching operation.
[0148] In one example, the switching operation response module is also used to:
[0149] It is determined that the first sub-interface has table selection results and the second sub-interface has field selection results.
[0150] In one example, the SQL statement generating device further includes:
[0151] The first clearing module is used to clear the field selection results in the second sub-interface and the definition selection results in the third sub-interface if it is detected that the table selection result in the first sub-interface has changed.
[0152] In one example, the SQL statement generating device further includes:
[0153] The second clearing module is used to clear the definition selection result in the third sub-interface if it is detected that the table selection result in the second sub-interface has changed.
[0154] For example, this embodiment can refer to the above method embodiment, and its principles and technical effects are similar and will not be described in detail.
[0155] Figure 8 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application, such as Figure 8 As shown, the electronic device includes a memory 43 and a processor 42 .
[0156] The memory 43 is a memory used for storing instructions executable by the processor 42 .
[0157] The processor 42 is configured to execute the method provided in the above embodiment.
[0158] The electronic device further includes a receiver 40 and a transmitter 41. The receiver 40 is used to receive instructions and data sent by an external device, and the transmitter 41 is used to send instructions and data to the external device.
[0159] Fig. 9 It is a block diagram of an electronic device provided in an embodiment of the present application. The device may be a mobile phone, a computer, a tablet device, a personal digital assistant, etc.
[0160] The device 800 may include one or more of the following components: a processing component 802 , a memory 804 , a power component 806 , a multimedia component 808 , an audio component 810 , an input / output (I / O) interface 812 , a sensor component 814 , and a communication component 816 .
[0161] The processing component 802 generally controls the overall operation of the device 800, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 802 may include one or more processors 820 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 802 may include one or more modules to facilitate the interaction between the processing component 802 and other components. For example, the processing component 802 may include a multimedia module to facilitate the interaction between the multimedia component 808 and the processing component 802.
[0162] The memory 804 is configured to store various types of data to support operations on the device 800. Examples of such data include instructions for any application or method operating on the device 800, contact data, phone book data, messages, pictures, videos, etc. The memory 804 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0163] The power supply component 806 provides power to the various components of the device 800. The power supply component 806 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the device 800.
[0164] The multimedia component 808 includes a screen that provides an output interface between the device 800 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 808 includes a front camera and / or a rear camera. When the device 800 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0165] The audio component 810 is configured to output and / or input audio signals. For example, the audio component 810 includes a microphone (MIC), and when the device 800 is in an operating mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 804 or sent via the communication component 816. In some embodiments, the audio component 810 also includes a speaker for outputting audio signals.
[0166] I / O interface 812 provides an interface between processing component 802 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: home button, volume button, start button, and lock button.
[0167] The sensor assembly 814 includes one or more sensors for providing various aspects of the status assessment of the device 800. For example, the sensor assembly 814 can detect the open / closed state of the device 800, the relative positioning of components, such as the display and keypad of the device 800, and the sensor assembly 814 can also detect the position change of the device 800 or a component of the device 800, the presence or absence of user contact with the device 800, the orientation or acceleration / deceleration of the device 800, and the temperature change of the device 800. The sensor assembly 814 may include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The sensor assembly 814 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 814 may also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0168] The communication component 816 is configured to facilitate wired or wireless communication between the device 800 and other devices. The device 800 can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 816 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 816 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0169] In an exemplary embodiment, the apparatus 800 may be implemented by one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components to perform the above method.
[0170] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 804 including instructions, and the instructions can be executed by the processor 820 of the device 800 to perform the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0171] An embodiment of the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the method provided in the above embodiment.
[0172] An embodiment of the present application provides a computer program product, which includes: a computer program, the computer program is stored in a readable storage medium, at least one processor of an electronic device can read the computer program from the readable storage medium, and at least one processor executes the computer program so that the electronic device executes the solution provided by any of the above embodiments.
[0173] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0174] In summary, the SQL statement generation method, device, electronic device and storage medium provided in this embodiment, on the one hand, are implemented using Vue technology. Vue uses MVVM technology to achieve two-way binding of data, and automatically refreshes the page through data updates, avoiding the tedious DOM operations, simplifying the front-end development process, and improving development efficiency. On the other hand, it guides users to follow the specified steps in a process manner, namely, selecting accounts and tables, selecting display fields, defining conditions, defining groups, and defining sorting to complete the SQL clause content. For users, the operation is simple, easy to get started, and highly readable. There is no need to pay attention to the writing order of English SQL, which reduces the difficulty of writing SQL for non-SQL technicians. On the other hand, when selecting display fields and defining conditions, users are supported to use database functions for field processing, so that the Chinese SQL statements are flexible enough to meet more user query scenarios. Figure 4 The following is a schematic diagram of a selection display field provided by an embodiment of the present invention. Figure 5 Provided is a schematic diagram of definition conditions provided by an embodiment of the present invention, Figure 4 and Figure 5 Function symbols are provided in both, allowing users to use functions to process fields.
[0175] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A method for generating a SQL statement, characterized in that: include: In response to a selection operation made by a user in a specified order on a preset interface, a plurality of Chinese structured query language SQL sub-statements are generated, wherein the preset interface is constructed based on a Vue framework; According to the processing requirements of the preset English writing order, multiple Chinese SQL sub-statements are assembled and processed to obtain Chinese SQL statements; Translating the Chinese SQL statement into English to obtain an SQL statement; In response to the selection operation made by the user in a preset interface in a specified order, a plurality of Chinese structured query language SQL sub-statements are generated, including: In response to a first operation performed by a user on a first sub-interface of the preset interface, generating a table selection result corresponding to the first operation; Switching the preset interface from the first sub-interface to the second sub-interface of the preset interface; In response to a second operation performed by a user on a second sub-interface of the preset interface, generating a field selection result corresponding to the second operation; Switching the preset interface from the second sub-interface to the third sub-interface of the preset interface; In response to a third operation performed by a user on a third sub-interface of the preset interface, generating a definition selection result corresponding to the third operation, and determining the table selection result, the field selection result, and the definition selection result as the Chinese structured query language SQL sub-statement; After generating a field selection result corresponding to a second operation performed by the user on the second sub-interface of the preset interface in response to the second operation performed by the user, the method further includes: In response to an interface switching operation performed by a user on the preset interface, switching the preset interface to a sub-interface corresponding to the interface switching operation; The method further comprises: If it is detected that the table selection result in the first sub-interface is changed, the field selection result in the second sub-interface and the definition selection result in the third sub-interface are cleared.
2. The method according to claim 1, characterized in that The definition selection result includes one or more of a condition definition result, a grouping definition result, a sorting definition result, and a statement information definition result.
3. The method according to claim 1, characterized in that Before the method of switching the preset interface to a sub-interface corresponding to the interface switching operation performed by the user on the preset interface in response to the interface switching operation, the method further includes: It is determined that the first sub-interface has a table selection result and the second sub-interface has a field selection result.
4. The method according to claim 2 or 3, characterized in that: The method further comprises: If it is detected that the table selection result in the second sub-interface is changed, the definition selection result in the third sub-interface is cleared.
5. A SQL statement generating device, characterized in that: The device comprises: An SQL sub-statement generation module, used to generate a plurality of Chinese structured query language SQL sub-statements in response to selection operations made by a user in a preset interface in a specified order, wherein the preset interface is constructed based on a Vue framework; A processing module, used for assembling and processing a plurality of Chinese SQL sub-statements according to a preset processing requirement of an English writing order to obtain a Chinese SQL statement; A translation module, used for translating the Chinese SQL statement into English to obtain an SQL statement; The SQL sub-statement generation module is specifically used to generate a table selection result corresponding to a first operation made by a user on a first sub-interface of the preset interface in response to the first operation made by the user on the first sub-interface of the preset interface; switch the preset interface from the first sub-interface to the second sub-interface of the preset interface; generate a field selection result corresponding to the second operation in response to a second operation made by the user on the second sub-interface of the preset interface; switch the preset interface from the second sub-interface to the third sub-interface of the preset interface; generate a definition selection result corresponding to the third operation in response to a third operation made by the user on the third sub-interface of the preset interface, and determine the table selection result, the field selection result and the definition selection result as the Chinese structured query language SQL sub-statement; A switching operation response module, used for responding to an interface switching operation performed by a user on the preset interface, switching the preset interface to a sub-interface corresponding to the interface switching operation; The first clearing module is used to clear the field selection results in the second sub-interface and the definition selection results in the third sub-interface if it is detected that the table selection result in the first sub-interface has changed.
6. An electronic device, characterized in that: include: Memory and processor; A memory for storing instructions executable by the processor; The processor is configured to execute the method according to any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 4 when executed by a processor.
8. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 4 when being executed by a processor.
Citation Information
Patent Citations
SQL statement generation method and device and computer-readable storage medium
CN109446218A
Chinese database SQL statement generation method and device, and storage medium
CN111414380A