A method and device for processing SQL statements
By identifying and processing keyword information in SQL statements and determining its visual display structure, the problem of poor readability and maintainability of existing SQL statements is solved, and the effect of quickly positioning target fields and improving data processing efficiency is achieved.
Patent Information
- Application Number
- CN202210421378.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-21
- Publication Date
- 2025-05-16
- Estimated Expiration
- 2042-04-21
AI Technical Summary
Due to the large number of fields, existing SQL statements have problems such as poor readability, poor maintainability, difficulty in quickly positioning target fields, low data processing efficiency, and poor user experience.
By obtaining the SQL statement to be processed, it determines its corresponding first keyword information, including keyword type, position relationship and first field, and performs identification processing to extract the second field, and determines the visual display structure of the SQL statement based on this information.
It improves the readability and maintainability of SQL statements, can quickly locate target fields, improves data processing efficiency, and improves user experience.
Smart Images

Figure CN114969088B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and device for processing SQL statements. Background Art
[0002] With the development of big data technology and the rapid growth of data, how to mine and analyze data quickly and accurately has received more and more attention.
[0003] In the process of data mining and analysis, reading and writing SQL statements are essential. In businesses with large amounts of data, it is common to connect several tables and have hundreds of lines of SQL statements. When R&D is writing SQL statements with complex logic, if a certain section of logic is vague, it is necessary to check a large number of related SQL statements to ensure correctness.
[0004] There are at least the following problems in the prior art:
[0005] Due to the large number of fields, existing SQL statements have technical problems such as poor readability, poor maintainability, difficulty in quickly locating target fields, low data processing efficiency, and poor user experience. Summary of the invention
[0006] In view of this, an embodiment of the present invention provides a method and device for processing SQL statements, which can identify and process SQL statements in combination with keywords, and then determine a visual display structure, improve the readability and maintainability of SQL statements, can quickly locate target fields, improve data processing efficiency, and enhance user experience.
[0007] To achieve the above object, according to one aspect of an embodiment of the present invention, a method for processing an SQL statement is provided, comprising:
[0008] Obtaining a SQL statement to be processed, and determining first keyword information corresponding to the SQL statement; wherein the first keyword information includes the first keyword, the keyword type of the first keyword, the positional relationship between the first keywords, and the first field between the first keywords;
[0009] Performing recognition processing on the first field, and extracting the second field according to the recognition processing result;
[0010] Determine a field queue corresponding to the second field according to the positional relationship between the first keywords;
[0011] The visual display structure of the SQL statement is determined based on the keyword type, position relationship, and field queue.
[0012] Furthermore, the position relationship indicates the relative position and nesting relationship of the first keyword in the SQL statement; and determining the visual display structure of the SQL statement based on the keyword type, the position relationship and the field queue includes:
[0013] Determine a nesting relationship between the second fields according to the keyword type, the position relationship, and the plurality of second fields in the field queue;
[0014] According to the nested relationship between the second fields, a visual display structure of the SQL statement is determined.
[0015] Further, according to the keyword type, the position relationship, and the plurality of second fields in the field queue, determining the nesting relationship between the second fields includes:
[0016] Build a stack structure;
[0017] According to the keyword type and position relationship, the second field in the field queue is placed into the stack structure for stack circulation;
[0018] The nesting relationship between the second fields is determined according to the stack loop result.
[0019] Further, obtaining the SQL statement to be processed and determining the first keyword information corresponding to the SQL statement includes:
[0020] Get the SQL statement to be processed and determine the table connection method of the SQL statement;
[0021] The first keyword information corresponding to the SQL statement is determined according to the table connection mode.
[0022] Furthermore, after the step of determining the first keyword information corresponding to the SQL statement according to the table connection mode, the method further includes:
[0023] Simplify the first keyword;
[0024] The character string corresponding to the first keyword is determined according to the simplified first keyword, the keyword type of the first keyword, and the position relationship between the first keywords.
[0025] Further, performing recognition processing on the first field and extracting the second field according to the recognition processing result includes:
[0026] Determine the target keyword and target keyword type corresponding to the first field;
[0027] Determine the separator and the second keyword based on the target keyword and target keyword type;
[0028] The first field is divided according to the separator, the divided first field is identified according to the second keyword, and the second field is extracted according to the identification result.
[0029] Further, determining the field queue corresponding to the second field according to the position relationship between the first keywords also includes:
[0030] Determine the arrangement order corresponding to the second field according to the position relationship between the first keywords;
[0031] The second field is placed in a queue according to the arrangement order to obtain a field queue corresponding to the second field.
[0032] According to another aspect of an embodiment of the present invention, there is provided a device for processing a SQL statement, comprising:
[0033] An acquisition module, used to acquire the SQL statement to be processed and determine the first keyword information corresponding to the SQL statement; wherein the first keyword information includes the first keyword, the keyword type of the first keyword, the position relationship between the first keywords, and the first field between the first keywords;
[0034] An identification processing module, used to perform identification processing on the first field and extract the second field according to the identification processing result;
[0035] A queue determination module, used to determine a field queue corresponding to the second field according to the position relationship between the first keywords;
[0036] The display structure determination module is used to determine the visual display structure of the SQL statement based on the keyword type, position relationship and field queue.
[0037] According to another aspect of the embodiments of the present invention, there is provided an electronic device, including:
[0038] one or more processors;
[0039] a storage device for storing one or more programs,
[0040] When one or more programs are executed by one or more processors, the one or more processors implement any of the above-mentioned SQL statement processing methods.
[0041] According to another aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored. When the program is executed by a processor, the method for processing any one of the above-mentioned SQL statements is implemented.
[0042] An embodiment of the above invention has the following advantages or beneficial effects: because the SQL statement to be processed is obtained, the first keyword information corresponding to the SQL statement is determined; wherein the first keyword information includes the first keyword, the keyword type of the first keyword, the positional relationship between the first keywords, and the first field between the first keywords; the first field is identified and processed, and the second field is extracted according to the identification result; the field queue corresponding to the second field is determined according to the positional relationship between the first keywords; the technical means of determining the visual display structure of the SQL statement based on the keyword type, the positional relationship and the field queue overcomes the technical problems of the existing SQL statements due to the large number of fields, resulting in poor readability, poor maintainability, difficulty in quickly locating the target field, low data processing efficiency, and poor user experience, thereby achieving the technical effect of being able to identify and process the SQL statement in combination with the keywords, and then determine the visual display structure, improve the readability and maintainability of the SQL statement, and be able to quickly locate the target field, improve data processing efficiency, and improve user experience.
[0043] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0045] Figure 1 It is a schematic diagram of the main process of the method for processing SQL statements provided according to an embodiment of the present invention;
[0046] Figure 2a is a schematic diagram of the main process of a method for processing an SQL statement provided according to another embodiment of the present invention;
[0047] Figure 2b yes Figure 2a The method obtains a schematic diagram of a visual display structure;
[0048] Figure 3 is a schematic diagram of main modules of a device for processing SQL statements provided according to an embodiment of the present invention;
[0049] Figure 4 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0050] Figure 5 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0051] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0052] Figure 1 Schematic diagram of the main process of the method for processing SQL statements according to an embodiment of the present invention; Figure 1 As shown, the SQL statement processing method provided by the embodiment of the present invention mainly includes:
[0053] Step S101, obtain the SQL statement to be processed, and determine the first keyword information corresponding to the SQL statement; wherein the first keyword information includes the first keyword, the keyword type of the first keyword, the position relationship between the first keywords, and the first field between the first keywords.
[0054] Specifically, according to an embodiment of the present invention, the above-mentioned obtaining the SQL statement to be processed and determining the first keyword information corresponding to the SQL statement includes:
[0055] Get the SQL statement to be processed and determine the table connection method of the SQL statement;
[0056] The first keyword information corresponding to the SQL statement is determined according to the table connection mode.
[0057] Among them, the table connection methods of SQL statements include left join (left join, returning all records in the left table and records with equal connection fields in the right table), right join (right join, returning all records in the right table and records with equal connection fields in the left table), inner join (inner join, also called equivalue join, only returns rows with equal connection fields in two tables), full join (outer join, returning rows in two tables: left join + right join), and cross join (the result is a Cartesian product, which is the number of rows in the first table multiplied by the number of rows in the second table). According to a specific implementation method of an embodiment of the present invention, the present invention is applicable to lengthy SQL statements with table connection relationships. For lengthy SQL statements, the method provided by an embodiment of the present invention helps to improve the readability of SQL statements, and the table connection method helps to determine the first keyword information so as to identify and process the SQL statement based on the first keyword information.
[0058] Further, according to an embodiment of the present invention, after the step of determining the first keyword information corresponding to the SQL statement according to the table connection mode, the method further includes:
[0059] Simplify the first keyword;
[0060] The character string corresponding to the first keyword is determined according to the simplified first keyword, the keyword type of the first keyword, and the position relationship between the first keywords.
[0061] According to a specific implementation of an embodiment of the present invention, the simplified processing process can use the first letter to represent the first keyword (only as an example), and then determine the character string corresponding to the first keyword based on the first letter, the keyword type of the first keyword, and the positional relationship between the first keywords. Through the above settings, the determined character string can more intuitively reflect the relative position and nested relationship of each first keyword in the SQL statement, which is helpful for the subsequent identification and processing of the first field between the first keywords, and then determine the visual display structure of the SQL statement, further improve the readability of the SQL statement, and improve data processing efficiency.
[0062] Step S102: perform recognition processing on the first field, and extract the second field according to the recognition processing result.
[0063] Specifically, according to an embodiment of the present invention, the above-mentioned identification processing is performed on the first field, and the second field is extracted according to the identification processing result, including:
[0064] Determine the target keyword and target keyword type corresponding to the first field;
[0065] Determine the separator and the second keyword based on the target keyword and target keyword type;
[0066] The first field is divided according to the separator, the divided first field is identified according to the second keyword, and the second field is extracted according to the identification result.
[0067] For example, for the second keyword "as", the words before and after it represent different names of the field. You can only retain the final field name after "as". By identifying and processing the first field, you can extract the second field. This will help to further streamline the SQL statement, improve the readability of the SQL statement, and facilitate quick positioning of the target field, thereby improving the user experience.
[0068] Step S103: determining a field queue corresponding to the second field according to the positional relationship between the first keywords.
[0069] Specifically, according to an embodiment of the present invention, the method of determining the field queue corresponding to the second field according to the position relationship between the first keywords further includes:
[0070] Determine the arrangement order corresponding to the second field according to the position relationship between the first keywords;
[0071] The second field is placed in a queue according to the arrangement order to obtain a field queue corresponding to the second field.
[0072] Through the above settings, the field queue of the second field is determined. Since the queue is a data structure in which data is first-in-first-out, it is helpful to combine the first-in-last-out property of the stack structure later to quickly and accurately determine the visual display structure of the SQL statement.
[0073] Step S104, determining a visual display structure of the SQL statement based on the keyword type, position relationship, and field queue.
[0074] Specifically, according to an embodiment of the present invention, the above position relationship indicates the relative position and nesting relationship of the first keyword in the SQL statement; determining the visual display structure of the SQL statement based on the keyword type, the position relationship and the field queue includes:
[0075] Determine a nesting relationship between the second fields according to the keyword type, the position relationship, and the plurality of second fields in the field queue;
[0076] According to the nested relationship between the second fields, a visual display structure of the SQL statement is determined.
[0077] The visual display structure shows the nested hierarchical relationship of the final field of the SQL statement (the second field after identification processing), which helps users quickly locate the target field and improves the readability and maintainability of the SQL statement.
[0078] Further, according to an embodiment of the present invention, the above-mentioned determining the nesting relationship between the second fields according to the keyword type, the position relationship and the plurality of second fields in the field queue includes:
[0079] Build a stack structure;
[0080] According to the keyword type and position relationship, the second field in the field queue is placed into the stack structure for stack circulation;
[0081] The nesting relationship between the second fields is determined according to the stack loop result.
[0082] Based on the first-in-last-out feature of the stack structure, the second field in the field queue is placed in the stack structure for stack loop according to the relative position and nested relationship of the first field indicated by the keyword type and position relationship, so as to determine the nested relationship corresponding to the second field (the streamlined field after the identification processing), so as to determine the visual display structure of the SQL statement according to the nested relationship between the second fields, so as to improve the readability of the SQL statement and improve the data processing efficiency.
[0083] According to the technical solution of the embodiment of the present invention, the SQL statement to be processed is obtained to determine the first keyword information corresponding to the SQL statement; wherein the first keyword information includes the first keyword, the keyword type of the first keyword, the positional relationship between the first keywords and the first field between the first keywords; the first field is identified and processed, and the second field is extracted according to the identification result; the field queue corresponding to the second field is determined according to the positional relationship between the first keywords; the technical means of determining the visual display structure of the SQL statement based on the keyword type, the positional relationship and the field queue overcomes the technical problems of the existing SQL statements due to the large number of fields, such as poor readability, poor maintainability, difficulty in quickly locating the target field, low data processing efficiency and poor user experience, thereby achieving the technical effect of being able to identify and process the SQL statement in combination with the keywords, and then determine the visual display structure, improve the readability and maintainability of the SQL statement, and be able to quickly locate the target field, improve the data processing efficiency and improve the user experience.
[0084] Figure 2a FIG. 1 is a schematic diagram of the main flow of a method for processing an SQL statement according to another embodiment of the present invention; Figure 2a As shown, the processing method of the left-join SQL statement provided by the embodiment of the present invention mainly includes:
[0085] Step S201, obtaining a SQL statement to be processed, determining a table connection mode of the SQL statement; and determining first keyword information corresponding to the SQL statement according to the table connection mode.
[0086] The first keyword information includes the first keywords, keyword types of the first keywords, positional relationships between the first keywords, and first fields between the first keywords.
[0087] Taking the left join SQL statement (select * from TableA left join TableB onTableA.id=TableB.id) as an example, determine the first keywords "SELECT", "FROM", "LEFT JOIN", "ON", and at the same time determine the keyword type, the positional relationship between the first keywords, and the first field between the first keywords.
[0088] Step S202, simplifying the first keyword; determining the character string corresponding to the first keyword according to the simplified first keyword, the keyword type of the first keyword, and the position relationship between the first keywords.
[0089] Since the SQL statement to be processed is generally long (with dozens or hundreds of lines of fields), the first keyword is distributed in different rows and columns. For easy viewing, the first keyword can be simplified, for example, the first keyword is represented by an abbreviation, that is, SELECT = S, FROM = F, LEFT JOIN = L, ON = O. Thus, combined with the positional relationship between the first keywords, the string corresponding to the first keyword is obtained (only for example):
[0090] (SF(SF)L(SF(SF)L(SF)OL(SF(SF(SF)))O)OL(SF(SF))O).
[0091] Through the above settings, the determined character string can more intuitively reflect the relative position and nested relationship of each first keyword in the SQL statement, which is helpful for the subsequent identification and processing of the first field between the first keywords, and then determine the visual display structure of the SQL statement, further improve the readability of the SQL statement, and improve data processing efficiency.
[0092] Step S203, determine the target keyword and target keyword type corresponding to the first field; determine the separator and the second keyword according to the target keyword and the target keyword type; divide the first field according to the separator, identify the divided first field according to the second keyword, and extract the second field according to the identification result.
[0093] First, different recognition processing methods are determined according to the type of the first keyword type.
[0094] For example, for the fields between S (SELECT) and F (FROM), the separator is determined to be "," and the second keyword is "as" and ".". The specific identification and processing steps are as follows:
[0095] (1) Using "," as the separator, if there are n "," in the first field between S and F, it is divided into n+1 candidate second fields;
[0096] (2) For each candidate second field, determine whether the second keyword "as" exists in the field. If so, it means that the field has multiple aliases. The field after "as" can be directly taken, and spaces and lowercase letters can be removed to obtain the final field.
[0097] (3) If the second keyword "as" does not exist in the candidate second field, determine whether the second keyword "." exists. If so, take the field after the second keyword ".", remove spaces and convert it to lowercase to obtain the final field;
[0098] (4) If the second keyword "as" and "." do not exist in the candidate second field, it means that there is no need to process this part of the field, and the spaces are directly removed and lowercase to obtain the final field;
[0099] The final fields corresponding to the n+1 candidate second fields are merged to obtain the second field after the first field is identified. By identifying the first field and extracting the second field, it helps to further streamline the SQL statement, improve the readability of the SQL statement, and facilitate quick positioning of the target field to improve the user experience.
[0100] Step S204, determining the arrangement order corresponding to the second field according to the positional relationship between the first keywords; placing the second field in a queue according to the arrangement order, and obtaining a field queue corresponding to the second field.
[0101] The second fields are marked with symbols ①②③④⑤…, and it is assumed that there are 10 second fields. The field queue corresponding to the second field is determined according to the arrangement order:
[0102]
[0103] Through the above settings, the field queue of the second field is determined. Since the queue is a data structure in which data is first-in-first-out, it is helpful to combine the first-in-last-out property of the stack structure later to quickly and accurately determine the visual display structure of the SQL statement.
[0104] Step S205, constructing a stack structure; placing the second field in the field queue into the stack structure for stack loop according to the keyword type and position relationship indicated by the character string; and determining the nesting relationship between the second fields according to the stack loop result.
[0105] After determining the string corresponding to the first keyword and the field queue corresponding to the second field obtained after the recognition process, a stack structure with a first-in, last-out feature is introduced.
[0106] (1) Take the first element (the first second field ①) from the field queue. Since the first element is the field between the first SF, it can be seen that ① is the first level in the nesting level of the SQL statement, and its expression is obtained: "①←"
[0107] (2) Then, the “(” corresponding to the second field ① (according to the above string, ① is located between the first SF, and there is an outermost “(” on its left) is placed into the stack structure;
[0108] (3) Push the two characters after "(" into the stack in sequence, starting with the next digit of SF (which occupies two characters) corresponding to ①. Combined with the keyword type and the positional relationship between keywords, the specific steps are as follows:
[0109] i. If "(" is adjacent to "SF", that is, "(SF" is encountered, it is determined that the field between "SF" belongs to the nested field in ①, and the second field ② is taken out. Improve the expression to get "①←②", and then execute step ii;
[0110] ii. If only "("")" is encountered afterwards, push it into the stack again, and if there is an adjacent "("")", remove the "("")" until the position relationship indicated by the string shows that there is only one "(", end step ii, and execute step iii;
[0111] iii. If the first keyword "L" is encountered, go to step (4); if "(SF" is encountered, go to step (5); if the first keyword "O" is encountered, go to step (6), and when adjacent "(" and ")" are encountered, take them out until the stack is empty, completing a stack loop; then continue to execute step (1) until all fields in the field queue complete the stack loop.
[0112] (4) Continue to push the first keyword “L” into the stack. Instead of pushing it into the stack, replace it with “+” and add it into the expression to obtain the expression “①←②+”.
[0113] (5) Continue to push into the stack. When "(" and "SF" are adjacent, execute step (3) and get the expression: ①←②+③;
[0114] (6) Continue to push the first keyword "O" into the stack. Instead of pushing it into the stack, build a connection between the second field ③ of the last SF and the previous expression combination to obtain a new expression:
[0115] In combination with the above steps, ten second fields in the field queue are placed into a stack structure for stack loop; and the nesting relationship between the second fields is determined according to the stack loop result as follows:
[0116] Indicates that the nested fields under the second field ① include the second fields ②, ③, and ⑨;
[0117] ②←, indicating that the second field ② is constructed independently;
[0118] Indicates that the nested fields under the second field ③ include the second fields ④, ⑤, and ⑥;
[0119] ④←, indicating that the second field ④ is constructed independently;
[0120] ⑤←, indicating that the second field ⑤ is constructed independently;
[0121] ⑥←⑦, indicating that the nested field under the second field ⑥ is ⑦;
[0122] ⑦←⑧, indicating that the nested field under the second field ⑦ is ⑧;
[0123] ⑧←, indicating that the second field ⑧ is constructed independently;
[0124] ⑨←⑩, indicating that the nested field under the second field ⑨ is ⑩;
[0125] ⑩←, indicating that the second field ⑩ is constructed independently.
[0126] Based on the expressions obtained by the above multiple stack loops, determine the visual display structure corresponding to the SQL statement, as follows: Figure 2b Through the above visual display structure, the target field can be determined quickly and accurately, which improves the readability of SQL statements and the user experience.
[0127] Step S206: Determine the visual display structure of the SQL statement according to the nested relationship between the second fields.
[0128] The visual display structure shows the nested hierarchical relationship of the final field of the SQL statement (the second field after identification processing), which helps users quickly locate the target field and improves the readability and maintainability of the SQL statement.
[0129] According to the technical solution of the embodiment of the present invention, the SQL statement to be processed is obtained to determine the first keyword information corresponding to the SQL statement; wherein the first keyword information includes the first keyword, the keyword type of the first keyword, the positional relationship between the first keywords and the first field between the first keywords; the first field is identified and processed, and the second field is extracted according to the identification result; the field queue corresponding to the second field is determined according to the positional relationship between the first keywords; the technical means of determining the visual display structure of the SQL statement based on the keyword type, the positional relationship and the field queue overcomes the technical problems of the existing SQL statements due to the large number of fields, such as poor readability, poor maintainability, difficulty in quickly locating the target field, low data processing efficiency and poor user experience, thereby achieving the technical effect of being able to identify and process the SQL statement in combination with the keywords, and then determine the visual display structure, improve the readability and maintainability of the SQL statement, and be able to quickly locate the target field, improve the data processing efficiency and improve the user experience.
[0130] Figure 3 Schematic diagram of the main modules of the SQL statement processing device provided by the embodiment of the present invention; Figure 3 As shown, the SQL statement processing device 300 provided in the embodiment of the present invention mainly includes:
[0131] The acquisition module 301 is used to acquire the SQL statement to be processed and determine the first keyword information corresponding to the SQL statement; wherein the first keyword information includes the first keyword, the keyword type of the first keyword, the position relationship between the first keywords, and the first field between the first keywords.
[0132] Specifically, according to an embodiment of the present invention, the acquisition module 301 is further used for:
[0133] Get the SQL statement to be processed and determine the table connection method of the SQL statement;
[0134] The first keyword information corresponding to the SQL statement is determined according to the table connection mode.
[0135] Among them, the table connection methods of SQL statements include left join (left join, returning all records in the left table and records with equal connection fields in the right table), right join (right join, returning all records in the right table and records with equal connection fields in the left table), inner join (inner join, also called equivalue join, only returns rows with equal connection fields in two tables), full join (outer join, returning rows in two tables: left join + right join), and cross join (the result is a Cartesian product, which is the number of rows in the first table multiplied by the number of rows in the second table). According to a specific implementation method of an embodiment of the present invention, the present invention is applicable to lengthy SQL statements with table connection relationships. For lengthy SQL statements, the method provided by an embodiment of the present invention helps to improve the readability of SQL statements, and the table connection method helps to determine the first keyword information so as to identify and process the SQL statement based on the first keyword information.
[0136] Further, according to an embodiment of the present invention, the SQL statement processing device 300 further includes a character string determination module, which is used to:
[0137] Simplify the first keyword;
[0138] The character string corresponding to the first keyword is determined according to the simplified first keyword, the keyword type of the first keyword, and the position relationship between the first keywords.
[0139] According to a specific implementation of an embodiment of the present invention, the simplified processing process can use the first letter to represent the first keyword (only as an example), and then determine the character string corresponding to the first keyword based on the first letter, the keyword type of the first keyword, and the positional relationship between the first keywords. Through the above settings, the determined character string can more intuitively reflect the relative position and nested relationship of each first keyword in the SQL statement, which is helpful for the subsequent identification and processing of the first field between the first keywords, and then determine the visual display structure of the SQL statement, further improve the readability of the SQL statement, and improve data processing efficiency.
[0140] The recognition processing module 302 is used to perform recognition processing on the first field and extract the second field according to the recognition processing result.
[0141] Specifically, according to an embodiment of the present invention, the identification processing module 302 is further used for:
[0142] Determine the target keyword and target keyword type corresponding to the first field;
[0143] Determine the separator and the second keyword based on the target keyword and target keyword type;
[0144] The first field is divided according to the separator, the divided first field is identified according to the second keyword, and the second field is extracted according to the identification result.
[0145] For example, for the second keyword "as", the words before and after it represent different names of the field. You can only retain the final field name after "as". By identifying and processing the first field, you can extract the second field. This will help to further streamline the SQL statement, improve the readability of the SQL statement, and facilitate quick positioning of the target field, thereby improving the user experience.
[0146] The queue determination module 303 is used to determine the field queue corresponding to the second field according to the position relationship between the first keywords.
[0147] Specifically, according to an embodiment of the present invention, the queue determination module 303 is further used to:
[0148] Determine the arrangement order corresponding to the second field according to the position relationship between the first keywords;
[0149] The second field is placed in a queue according to the arrangement order to obtain a field queue corresponding to the second field.
[0150] Through the above settings, the field queue of the second field is determined. Since the queue is a data structure in which data is first-in-first-out, it is helpful to combine the first-in-last-out property of the stack structure later to quickly and accurately determine the visual display structure of the SQL statement.
[0151] The display structure determination module 304 is used to determine the visual display structure of the SQL statement based on the keyword type, position relationship and field queue.
[0152] Specifically, according to an embodiment of the present invention, the position relationship indicates the relative position and nesting relationship of the first keyword in the SQL statement; the display structure determination module 304 is used to:
[0153] Determine a nesting relationship between the second fields according to the keyword type, the position relationship, and the plurality of second fields in the field queue;
[0154] According to the nested relationship between the second fields, a visual display structure of the SQL statement is determined.
[0155] The visual display structure shows the nested hierarchical relationship of the final field of the SQL statement (the second field after identification processing), which helps users quickly locate the target field and improves the readability and maintainability of the SQL statement.
[0156] Further, according to an embodiment of the present invention, the display structure determination module 304 is further configured to:
[0157] Build a stack structure;
[0158] According to the keyword type and position relationship, the second field in the field queue is placed into the stack structure for stack circulation;
[0159] The nesting relationship between the second fields is determined according to the stack loop result.
[0160] Based on the first-in-last-out feature of the stack structure, the second field in the field queue is placed in the stack structure for stack loop according to the relative position and nested relationship of the first field indicated by the keyword type and position relationship, so as to determine the nested relationship corresponding to the second field (the streamlined field after the identification processing), so as to determine the visual display structure of the SQL statement according to the nested relationship between the second fields, so as to improve the readability of the SQL statement and improve the data processing efficiency.
[0161] According to the technical solution of the embodiment of the present invention, the SQL statement to be processed is obtained to determine the first keyword information corresponding to the SQL statement; wherein the first keyword information includes the first keyword, the keyword type of the first keyword, the positional relationship between the first keywords and the first field between the first keywords; the first field is identified and processed, and the second field is extracted according to the identification result; the field queue corresponding to the second field is determined according to the positional relationship between the first keywords; the technical means of determining the visual display structure of the SQL statement based on the keyword type, the positional relationship and the field queue overcomes the technical problems of the existing SQL statements due to the large number of fields, such as poor readability, poor maintainability, difficulty in quickly locating the target field, low data processing efficiency and poor user experience, thereby achieving the technical effect of being able to identify and process the SQL statement in combination with the keywords, and then determine the visual display structure, improve the readability and maintainability of the SQL statement, and be able to quickly locate the target field, improve the data processing efficiency and improve the user experience.
[0162] Figure 4 An exemplary system architecture 400 is shown to which the SQL statement processing method or SQL statement processing device according to the embodiment of the present invention can be applied.
[0163] like Figure 4 As shown, the system architecture 400 may include terminal devices 401, 402, 403, a network 404 and a server 405 (this architecture is only an example, and the components included in the specific architecture may be adjusted according to the specific application). The network 404 is used to provide a medium for a communication link between the terminal devices 401, 402, 403 and the server 405. The network 404 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0164] Users can use terminal devices 401, 402, 403 to interact with server 405 through network 404 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 401, 402, 403, such as data processing applications, web browser applications, search applications, SQL statement processing tools, etc. (only as examples).
[0165] The terminal devices 401 , 402 , and 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.
[0166] The server 405 may be a server that provides various services, such as a server that processes data (only as an example) for users using the terminal devices 401, 402, and 403. The server may analyze the SQL statements and other data to be processed, and feed back the processing results (such as the first keyword information, the second field, and the visual display structure - only as an example) to the terminal device.
[0167] It should be noted that the SQL statement processing method provided in the embodiment of the present invention is generally executed by the server 405 , and accordingly, the SQL statement processing device is generally set in the server 405 .
[0168] It should be understood that Figure 4 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to the implementation requirements.
[0169] Reference below Figure 5 , which shows a schematic diagram of the structure of a computer system 500 of a terminal device or a server suitable for implementing an embodiment of the present invention. Figure 5 The terminal device or server shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0170] like Figure 5 As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage part 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the system 500 are also stored. The CPU 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0171] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, etc.; an output section 507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN card, a modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 510 as needed, so that a computer program read therefrom is installed into the storage section 508 as needed.
[0172] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 509, and / or installed from the removable medium 511. When the computer program is executed by the central processing unit (CPU) 501, the above-mentioned functions defined in the system of the present invention are executed.
[0173] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0174] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0175] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be set in a processor. For example, they may be described as: a processor including an acquisition module, an identification processing module, a queue determination module, and a display structure determination module. The names of these modules do not, in some cases, constitute a limitation on the modules themselves. For example, the acquisition module may also be described as "a module for acquiring the SQL statement to be processed and determining the first keyword information corresponding to the SQL statement".
[0176] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently and not be assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: obtaining a SQL statement to be processed, and determining the first keyword information corresponding to the SQL statement; wherein the first keyword information includes the first keyword, the keyword type of the first keyword, the positional relationship between the first keywords, and the first field between the first keywords; performing recognition processing on the first field, and extracting the second field according to the recognition processing result; determining the field queue corresponding to the second field according to the positional relationship between the first keywords; and determining the visual display structure of the SQL statement based on the keyword type, the positional relationship, and the field queue.
[0177] According to the technical solution of the embodiment of the present invention, the SQL statement to be processed is obtained to determine the first keyword information corresponding to the SQL statement; wherein the first keyword information includes the first keyword, the keyword type of the first keyword, the positional relationship between the first keywords and the first field between the first keywords; the first field is identified and processed, and the second field is extracted according to the identification result; the field queue corresponding to the second field is determined according to the positional relationship between the first keywords; the technical means of determining the visual display structure of the SQL statement based on the keyword type, the positional relationship and the field queue overcomes the technical problems of the existing SQL statements due to the large number of fields, such as poor readability, poor maintainability, difficulty in quickly locating the target field, low data processing efficiency and poor user experience, thereby achieving the technical effect of being able to identify and process the SQL statement in combination with the keywords, and then determine the visual display structure, improve the readability and maintainability of the SQL statement, and be able to quickly locate the target field, improve the data processing efficiency and improve the user experience.
[0178] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for processing SQL statements, characterized in that: include: Acquire a SQL statement to be processed, and determine first keyword information corresponding to the SQL statement; wherein the first keyword information includes a first keyword, a keyword type of the first keyword, a positional relationship between the first keywords, and a first field between the first keywords; the positional relationship indicates a relative position and a nested relationship of the first keyword in the SQL statement; Determine a target keyword and a target keyword type corresponding to the first field; determine a separator and a second keyword according to the target keyword and the target keyword type; divide the first field according to the separator, perform recognition processing on the divided first field according to the second keyword, and extract the second field according to the recognition processing result; Determine a field queue corresponding to the second field according to the position relationship between the first keywords; According to the keyword type, the position relationship and the multiple second fields in the field queue, the nesting relationship between the second fields is determined; according to the nesting relationship between the second fields, the visual display structure of the SQL statement is determined.
2. The method for processing SQL statements according to claim 1, characterized in that: The determining the nesting relationship between the second fields according to the keyword type, the position relationship, and the plurality of second fields in the field queue includes: Build a stack structure; According to the keyword type and the position relationship, placing the second field in the field queue into the stack structure for stack circulation; The nesting relationship between the second fields is determined according to the stack loop result.
3. The method for processing SQL statements according to claim 1, characterized in that: The obtaining of the SQL statement to be processed and determining the first keyword information corresponding to the SQL statement includes: Obtaining a SQL statement to be processed, and determining a table connection method of the SQL statement; The first keyword information corresponding to the SQL statement is determined according to the table connection mode.
4. The method for processing SQL statements according to claim 3, characterized in that: After the step of determining the first keyword information corresponding to the SQL statement according to the table connection mode, the method further includes: Simplifying the first keyword; The character string corresponding to the first keyword is determined according to the simplified first keyword, the keyword type of the first keyword, and the position relationship between the first keywords.
5. The method for processing SQL statements according to claim 1, characterized in that: The step of determining the field queue corresponding to the second field according to the positional relationship between the first keywords further includes: Determining an arrangement order corresponding to the second fields according to the position relationship between the first keywords; The second field is placed in a queue according to the arrangement order to obtain a field queue corresponding to the second field.
6. A SQL statement processing device, characterized in that: include: an acquisition module, configured to acquire a SQL statement to be processed and determine first keyword information corresponding to the SQL statement; wherein the first keyword information includes a first keyword, a keyword type of the first keyword, a positional relationship between the first keywords, and a first field between the first keywords; the positional relationship indicates a relative position and a nested relationship of the first keyword in the SQL statement; an identification processing module, configured to determine a target keyword and a target keyword type corresponding to the first field; determine a separator and a second keyword according to the target keyword and the target keyword type; divide the first field according to the separator, perform identification processing on the divided first field according to the second keyword, and extract the second field according to the identification processing result; a queue determination module, configured to determine a field queue corresponding to the second field according to a positional relationship between the first keywords; A display structure determination module is used to determine the nesting relationship between the second fields according to the keyword type, the position relationship and the multiple second fields in the field queue; and determine the visual display structure of the SQL statement according to the nesting relationship between the second fields.
7. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 5.
8. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Method and device for correcting database statement spelling errors
CN111435406A
Method and device for identifying client environment by user agent
CN112241621A