SQL (Structured Query Language) query method and device, equipment and medium
By pre-configuring the target dictionary and syntax specifications, SQL statements are recognized and formatted, which solves the problems of low accuracy and poor efficiency caused by statement errors in SQL queries, and realizes flexible and efficient SQL statement inspection and query.
Patent Information
- Application Number
- CN202411367414.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-27
- Publication Date
- 2025-02-14
AI Technical Summary
In the prior art, when performing SQL queries based on SQL statements, if the SQL statement is incorrect, it may cause the SQL query to fail, resulting in the problem of low accuracy and poor efficiency of SQL query.
By preconfiguring the target dictionary and grammatical specifications, the SQL statements to be checked are recognized and formatted to determine whether each character meets the target syntax specifications. If so, SQL query will be conducted.
The SQL statement inspection method that does not depend on specific databases is implemented, which improves the flexibility and efficiency of inspection, reduces the consumption of database resources, and supports syntax inspection of user-defined functions.
Smart Images

Figure CN119441246A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to an SQL query method, device, equipment and medium. Background Art
[0002] In modern database applications, SQL (Structured Query Language) is the standard language for interacting with databases. However, in the process of generating SQL statements, there may be mistakes, which may lead to SQL statement errors.
[0003] In the related art, when an electronic device performs an SQL query based on an SQL statement, if the SQL statement is wrong, the SQL query may fail, thereby causing problems such as low SQL query accuracy and poor efficiency. Summary of the invention
[0004] The present application provides a SQL query method, apparatus, device and medium to solve the problem in the prior art that when performing SQL query based on SQL statement, if the SQL statement is wrong, it may cause the SQL query to fail, thereby resulting in low SQL query accuracy and poor efficiency.
[0005] In a first aspect, an embodiment of the present application provides a SQL query method, the method comprising:
[0006] According to the pre-configured target dictionary, the target SQL statement to be checked is identified, and each target character in each character of the target SQL statement and the corresponding character type are determined;
[0007] If it is determined that each target character conforms to the corresponding target grammar specification according to the pre-configured target grammar specification corresponding to each character type, it is determined that the format of the target SQL statement is correct, and an SQL query is performed based on the SQL statement.
[0008] The above technical solution has the following advantages or beneficial effects: the electronic device is pre-configured with a grammar specification, and the electronic device can check the SQL statement according to the grammar specification, realizing a checking method that does not depend on a specific database, thereby greatly improving the flexibility and efficiency of the check. In addition, the checking method of the embodiment of the present application can also reduce the consumption of database resources, improve the flexibility of service deployment, and support syntax checking of user-defined functions.
[0009] In some embodiments of the present application, the method of determining that each character of the target SQL statement is located before each target character and the corresponding character type of the target dictionary further includes:
[0010] Obtaining the target SQL dialect to which the target SQL statement is saved;
[0011] If the target SQL dialect is a pre-configured SQL dialect that supports recognition, a subsequent step of recognizing the target SQL statement to be checked according to the pre-configured dictionary is performed to determine each target character in each character of the target SQL statement located in the target dictionary and the corresponding character type.
[0012] The above technical solution has the following advantages or beneficial effects: by pre-configuring multiple SQL dialects, the electronic device can support SQL statement checking and SQL query in multiple SQL dialects. One service supports multiple SQL dialects to implement a unified SQL dialect checking service. It is also easy to expand SQL dialect support. Expanding SQL dialects only requires adding corresponding dialect modules without modifying the project architecture.
[0013] In some embodiments of the present application, the method further includes:
[0014] If the target SQL dialect is not a pre-configured SQL dialect that supports recognition, a response message indicating that the SQL statement check failed is output.
[0015] The above technical solution has the following advantages or beneficial effects: for the SQL dialect that cannot be checked in the embodiment of the present application, the electronic device directly outputs the response information of the SQL statement check failure, thereby avoiding the waste of resources.
[0016] In some embodiments of the present application, the process of determining the target dictionary includes:
[0017] Get the first correspondence between the identifier of the saved SQL dialect and the dictionary;
[0018] Determine, according to the first corresponding relationship, a candidate dictionary corresponding to the identifier of the target SQL dialect to which the target SQL statement belongs;
[0019] Using the candidate dictionary as the target dictionary;
[0020] The determining, according to the pre-configured target grammar specification corresponding to each character type, that each target character complies with the corresponding target grammar specification comprises:
[0021] According to the pre-configured target grammar specification corresponding to each character type of the target SQL dialect, it is determined that each target character complies with the corresponding target grammar specification.
[0022] The above technical solution has the following advantages or beneficial effects: a dictionary corresponding to each SQL dialect is stored in the electronic device, and a target grammar specification corresponding to each character type of each SQL dialect is stored, so that SQL statements of multiple dialects can be accurately queried during inspection, avoiding false alarms caused by different SQL dialects and improving the accuracy of inspection.
[0023] In some embodiments of the present application, the character type includes at least one of: a keyword, a syntax, a function, and a data type.
[0024] The above technical solution has the following advantages or beneficial effects: by checking at least one of the keywords, syntax, functions and data types in the SQL statement, the accuracy of the check is improved.
[0025] In some embodiments of the present application, the method further includes:
[0026] If it is determined that at least one target character does not conform to the corresponding target grammar specification according to the pre-configured target grammar specification corresponding to each character type, then the problem type is determined according to the character type corresponding to the at least one target character;
[0027] A modification instruction is generated that carries the identification of the problem type and the target SQL statement.
[0028] The above technical solution has the following advantages or beneficial effects: the electronic device finally outputs modification instructions of the problem type of the SQL statement, including syntax errors, logical errors, etc., to help developers or database administrators understand the health of the SQL statement and modify the SQL statement according to the problem type.
[0029] In some embodiments of the present application, the process of determining the target SQL statement includes:
[0030] Determine whether there is an SQL script in the current directory to be executed;
[0031] If it exists, the SQL script is determined as the target SQL statement.
[0032] The above technical solution has the following advantages or beneficial effects: the electronic device can automatically monitor the new SQL script in the current directory to be executed, and use it as the target SQL statement to be checked, thereby realizing the automation of SQL statement checking.
[0033] In a second aspect, an embodiment of the present application further provides a SQL query device, the device comprising:
[0034] A processing module is used to identify the target SQL statement to be checked according to a pre-configured target dictionary, and determine each target character and the corresponding character type in each character of the target SQL statement; if it is determined according to the pre-configured target grammar specification corresponding to each character type that each target character complies with the corresponding target grammar specification, then it is determined that the format of the target SQL statement is correct;
[0035] A query module is used to perform SQL query based on the SQL statement.
[0036] In a third aspect, an embodiment of the present application further provides an electronic device, which includes at least a processor and a memory, and the processor is used to implement the steps of any of the above-mentioned SQL query methods when executing a computer program stored in the memory.
[0037] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium storing a computer program, which implements the steps of any of the above-mentioned SQL query methods when executed by a processor.
[0038] In an embodiment of the present application, the electronic device identifies the target SQL statement to be checked according to a pre-configured target dictionary, and determines each target character and the corresponding character type in each character of the target SQL statement that is located in the target dictionary; if each target character is determined to conform to the corresponding target grammar specification according to the pre-configured target grammar specification corresponding to each character type, then the target SQL statement is determined to be in the correct format, and an SQL query is performed based on the SQL statement. In an embodiment of the present application, a grammar specification is pre-configured in the electronic device, and the electronic device can check the SQL statement according to the grammar specification, realizing a checking method that is not dependent on a specific database, thereby greatly improving the flexibility and efficiency of the check. In addition, the checking method of the embodiment of the present application can also reduce the consumption of database resources, improve the flexibility of service deployment, and support grammar checking of user-defined functions. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the technical solution of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0040] Figure 1 A schematic diagram of an SQL query process provided in an embodiment of the present application;
[0041] Figure 2A schematic diagram of a flow chart of checking SQL statements by AST provided in an embodiment of the present application;
[0042] Figure 3 A schematic diagram of the structure of a SQL query device provided in an embodiment of the present application;
[0043] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0044] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application.
[0045] In order to improve the accuracy and efficiency of SQL queries, embodiments of the present application provide a SQL query method, apparatus, device and medium.
[0046] In an embodiment of the present application, the electronic device identifies the target SQL statement to be checked according to a pre-configured target dictionary, and determines each target character and the corresponding character type in each character of the target SQL statement; if it is determined that each target character conforms to the corresponding target grammar specification according to the pre-configured target grammar specification corresponding to each character type, then it is determined that the format of the target SQL statement is correct, and an SQL query is performed based on the SQL statement.
[0047] Figure 1 A schematic diagram of an SQL query process provided in an embodiment of the present application, the process includes:
[0048] S101: Identify a target SQL statement to be checked according to a pre-configured target dictionary, and determine each target character in each character of the target SQL statement located in the target dictionary and the corresponding character type.
[0049] An SQL query method provided in an embodiment of the present application is applied to an electronic device, which may be a PC or a server.
[0050] In actual application, when checking SQL statements, the important characters in the SQL statements are mainly checked to see whether the use of the important characters complies with the specification. In order to accurately identify the characters that need to be checked in the SQL statements, in the embodiment of the present application, a target dictionary is pre-configured in the electronic device, and the target dictionary contains characters corresponding to multiple character types, where one character can correspond to one character or multiple characters, which is not limited here.
[0051] In an embodiment of the present application, when an electronic device identifies a target SQL statement to be checked, the electronic device obtains a pre-configured target dictionary and determines the target characters that exist both in the target SQL statement and in the target dictionary based on each character contained in the target dictionary and each character in the target SQL statement.
[0052] The electronic device determines the character type corresponding to the target character according to the character type corresponding to each character recorded in the target dictionary. The number of target characters can be one or more, and the character types corresponding to different target characters can be the same or different.
[0053] In addition, in an embodiment of the present application, before the electronic device identifies the target SQL statement to be checked according to a pre-configured target dictionary, the electronic device may first pre-process the target SQL statement, including basic processing such as removing redundant spaces and normalizing upper and lower cases, to ensure that the target SQL statement can be correctly parsed.
[0054] S102: If it is determined that each target character conforms to the corresponding target grammar specification according to the pre-configured target grammar specification corresponding to each character type, it is determined that the format of the target SQL statement is correct, and an SQL query is performed based on the SQL statement.
[0055] During the application process, when checking different types of characters, the syntax specifications used may be different, such as checking whether the use of data types such as NUMBER and VARCHAR2 complies with Oracle's syntax specifications.
[0056] Based on this, in order to better check the SQL statement, in the embodiment of the present application, the electronic device is also pre-configured with a target syntax specification corresponding to each character type. For each character type, the electronic device checks the characters of the character type in the SQL statement according to the target syntax specification. The target syntax specification can be a requirement for the character format, a requirement for the context of the character, or a requirement for the method of using the character, etc., which is not limited here.
[0057] In an embodiment of the present application, if the electronic device determines that each target character in the target SQL statement conforms to the corresponding target grammar specification, the electronic device determines that the target SQL statement is in a correct format, and the electronic device can perform an SQL query based on the target SQL statement.
[0058] Specifically, the electronic device may input the target SQL statement and related prompt words into a large language model, and the large language model may perform an SQL query on the target SQL statement according to the related prompt words. The specific query process will not be described in detail herein.
[0059] In addition, in the embodiment of the present application, the electronic device may also use other methods to check the target SQL statement, such as checking the SQL statement based on pattern matching, checking the SQL statement based on context-free grammar (CFG), or checking the SQL statement based on machine learning.
[0060] Among them, checking SQL statements based on pattern matching includes: using regular expressions or other pattern matching technologies to gradually parse and check SQL statements. This method can check by pre-defining the syntax rules of different SQL dialects and matching each part of the SQL statement one by one. The specific steps include: pre-processing SQL statements to standardize them; defining corresponding regular expressions or matching patterns for different SQL dialects; checking the keywords, syntactic structures, data types and function usage in SQL statements one by one, and recording and feeding back the types of problems found.
[0061] Checking SQL statements based on context-free grammar includes: using CFG to generate the parse tree of SQL statements, and checking different SQL dialects through a parser. The specific steps include: preprocessing SQL statements and standardizing them; defining corresponding context-free grammar rules for different SQL dialects; using a parser to generate the parse tree of SQL statements; traversing and checking the parse tree to ensure that keywords, syntactic structures, data types and functions use the defined grammar rules, and recording and feedback on the types of problems found.
[0062] Checking SQL statements based on machine learning includes: using machine learning algorithms, especially natural language processing (NLP) technology, to parse and check SQL statements, and identifying and checking the syntax features of different SQL dialects through training models. The specific steps include: collecting and preprocessing a large number of SQL statement samples, covering multiple SQL dialects; extracting features from samples and training machine learning models; inputting SQL statements, parsing and checking the models, identifying syntax errors, and recording and feedback on the types of problems found.
[0063] In the embodiment of the present application, the electronic device is pre-configured with a grammar specification, and the electronic device can check the SQL statement according to the grammar specification, realizing a checking method that does not depend on a specific database, thereby greatly improving the flexibility and efficiency of the check. In addition, the checking method of the embodiment of the present application can also reduce the consumption of database resources, improve the flexibility of service deployment, and support grammar checking of user-defined functions.
[0064] In order to improve the accuracy and efficiency of SQL queries, based on the above embodiments, in the embodiment of the present application, the method of determining that each character of the target SQL statement is located before each target character and the corresponding character type of the target dictionary further includes:
[0065] Obtaining the target SQL dialect to which the target SQL statement is saved;
[0066] If the target SQL dialect is a pre-configured SQL dialect that supports recognition, a subsequent step of recognizing the target SQL statement to be checked according to the pre-configured dictionary is performed to determine each target character in each character of the target SQL statement located in the target dictionary and the corresponding character type.
[0067] In order to enable the SQL query method provided in the embodiment of the present application to be applicable to multiple SQL dialects, in the embodiment of the present application, the electronic device is pre-configured with information on SQL dialects that support being recognized by the electronic device. Before the electronic device checks the target SQL statement, that is, before the electronic device determines each target character in the target dictionary and the corresponding character type for each character of the target SQL statement, the electronic device can first determine whether the target SQL dialect to which the target SQL statement belongs supports being recognized by the electronic device.
[0068] Among them, SQL dialect refers to the specific syntax and functions that are extended or modified by different database systems based on the SQL standard language according to their own characteristics and needs, such as MySQL, PostgreSQL, Oracle, etc.
[0069] Specifically, if the target SQL statement is sent to the electronic device by another device, the electronic device will receive the target SQL dialect to which the target SQL statement belongs when receiving the target SQL statement, and the electronic device will store the target SQL statement and the target SQL dialect in correspondence. If the target SQL statement is generated by the electronic device, the electronic device has determined the target SQL dialect to which the target SQL statement belongs before generating the target SQL statement, and after generating the target SQL statement, the electronic device will store the target SQL statement and the target SQL dialect in correspondence.
[0070] The electronic device obtains information of pre-configured SQL dialects that are supported by the electronic device and determines whether the SQL dialects that are supported by the electronic device include the target SQL dialect. If included, the electronic device performs a subsequent step of identifying the target SQL statement to be checked according to the pre-configured dictionary and determining each target character in the target dictionary and the corresponding character type in each character of the target SQL statement.
[0071] In order to improve the accuracy and efficiency of SQL queries, based on the above embodiments, in the embodiment of the present application, the method further includes:
[0072] If the target SQL dialect is not a pre-configured SQL dialect that supports recognition, a response message indicating that the SQL statement check failed is output.
[0073] In an embodiment of the present application, if the electronic device determines that the target SQL dialect to which the target SQL statement belongs is not a pre-configured SQL dialect that supports being recognized, the electronic device determines that it cannot recognize and check the target SQL statement of the target SQL dialect, and the electronic device outputs response information that the SQL statement check failed.
[0074] In order to improve the accuracy and efficiency of SQL queries, based on the above embodiments, in the embodiment of the present application, the process of determining the target dictionary includes:
[0075] Get the first correspondence between the identifier of the saved SQL dialect and the dictionary;
[0076] Determine, according to the first corresponding relationship, a candidate dictionary corresponding to the identifier of the target SQL dialect to which the target SQL statement belongs;
[0077] Using the candidate dictionary as the target dictionary;
[0078] The determining, according to the pre-configured target grammar specification corresponding to each character type, that each target character complies with the corresponding target grammar specification comprises:
[0079] According to the pre-configured target grammar specification corresponding to each character type of the target SQL dialect, it is determined that each target character complies with the corresponding target grammar specification.
[0080] In order to accurately identify important characters in SQL statements of various SQL dialects, in the embodiment of the present application, the electronic device is pre-configured with a dictionary for each SQL dialect, and the characters stored in the dictionaries corresponding to different SQL dialects are different. The electronic device also stores a first correspondence between the identifier of the SQL dialect and the dictionary, and the electronic device can determine the target dictionary corresponding to the target SQL dialect based on the first correspondence. In order to accurately check the important characters of each SQL dialect, the electronic device stores the target grammar specification corresponding to each character type of each SQL dialect.
[0081] Specifically, the electronic device obtains a first correspondence between a stored SQL dialect identifier and a dictionary, determines a candidate dictionary corresponding to the identifier of the target SQL dialect to which the target SQL statement belongs according to the first correspondence, and uses the candidate dictionary as the target dictionary.
[0082] After determining the target dictionary corresponding to the target SQL dialect, the electronic device determines that each target character complies with the corresponding target grammar specification according to the pre-configured target grammar specification corresponding to each character type of the target SQL dialect.
[0083] In order to improve the accuracy and efficiency of SQL queries, on the basis of the above embodiments, in an embodiment of the present application, the character type includes: at least one of: keywords, syntax, functions and data types.
[0084] In order to improve the accuracy and efficiency of SQL queries, based on the above embodiments, in the embodiment of the present application, the method further includes:
[0085] If it is determined that at least one target character does not conform to the corresponding target grammar specification according to the pre-configured target grammar specification corresponding to each character type, then the problem type is determined according to the character type corresponding to the at least one target character;
[0086] A modification instruction is generated that carries the identification of the problem type and the target SQL statement.
[0087] In the embodiment of the present application, when the electronic device recognizes the target character, the character type corresponding to the target character may be at least one of a keyword, a syntax, a function, and a data type. Generally, an SQL statement contains characters of all the above character types.
[0088] Based on this, when the electronic device checks the target SQL statement, if the electronic device determines that at least one target character does not conform to the corresponding target grammar specification based on the pre-configured target grammar specification corresponding to each character type, the problem type is determined based on the character type corresponding to the at least one target character; and a modification instruction carrying the problem type and the identifier of the target SQL statement is generated.
[0089] In an embodiment of the present application, the electronic device can check SQL statements of multiple SQL dialects based on an Abstract Syntax Tree (AST). Figure 2 The schematic diagram of the process of checking SQL statements by AST provided in the embodiment of the present application specifically includes:
[0090] 1. Parsing and checking of characters whose character type is a keyword in an SQL statement: The electronic device parses and performs syntax checking on the keywords in the SQL statement based on the AST.
[0091] For example, for the MySQL dialect, check whether the use of keywords such as SELECT, FROM, and WHERE conforms to the MySQL syntax specifications.
[0092] If a problem of improper keyword usage is found, the electronic device will identify and record the problem type as a keyword problem; if there is no problem, proceed to the next step.
[0093] 2. Parsing and checking of characters of syntactic type in SQL statements: The electronic device uses AST to perform detailed parsing and checking of the syntactic structure of SQL statements.
[0094] For example, for the PostgreSQL dialect, the electronics verifies whether the use of JOIN operations complies with the PostgreSQL syntax specifications, including the correct use of INNER JOIN, LEFT JOIN, etc.
[0095] If the electronic device finds a syntax problem, it will identify and record the problem type as a syntax problem; if there is no problem, proceed to the next step.
[0096] 3. Parse and check the characters in the SQL statement whose character type is the data type: The electronic device parses and checks the data type in the SQL statement to ensure that the data type is used correctly.
[0097] For example, in the Oracle dialect, the electronic device checks whether the use of data types such as NUMBER and VARCHAR2 complies with the syntax specifications of Oracle.
[0098] If the electronic device finds a problem with the use of a data type, the electronic device will identify and record the problem type as a data type problem; if there is no problem, proceed to the next step.
[0099] 4. Parse and check the characters whose character type is function in the SQL statement: The electronic device checks the functions used in the SQL statement to ensure that they meet the expected syntax and functional requirements.
[0100] For example, in the MySQL dialect, the electronic device checks whether the use of functions such as DATE_FORMAT and CONCAT conforms to the MySQL syntax specifications.
[0101] If the electronic device finds a problem with the use of a function, the electronic device will identify and record the type of problem as a function problem; if there is no problem, the inspection is passed.
[0102] If the electronic device finds a problem in any of the above steps, the electronic device will record and identify the specific problem type (such as a keyword problem, syntax problem, data type problem or function problem), and generate a modification instruction carrying the problem type and the identifier of the target SQL statement, so that the problem can be fed back to the user for modification; if the electronic device determines that there are no problems with all checks, the electronic device will feedback that the SQL statement has passed the check.
[0103] For example, suppose the SQL statement you enter is:
[0104] SELECT DATE_FORMAT(NOW(),'%Y-%m-%d')AS current_date FROM dual;
[0105] In the MySQL dialect, this statement is correct and the electronics will perform the following steps:
[0106] SQL dialect support detection: Confirm that it is the MySQL dialect and continue processing.
[0107] SQL preprocessing: After normalization, it enters the keyword parsing stage.
[0108] SQL keyword analysis and checking: Check that keywords such as SELECT, FROM, and AS are used correctly.
[0109] SQL syntax analysis and checking: Check the syntax structure and confirm that it is correct.
[0110] SQL data type analysis and checking: Check that the data type is correct.
[0111] SQL function analysis and checking: Check that the DATE_FORMAT function complies with MySQL syntax specifications and is correct.
[0112] In order to improve the accuracy and efficiency of SQL queries, based on the above embodiments, in the embodiment of the present application, the process of determining the target SQL statement includes:
[0113] Determine whether there is an SQL script in the current directory to be executed;
[0114] If it exists, the SQL script is determined as the target SQL statement.
[0115] In the embodiment of the present application, the electronic device can automatically obtain, analyze and check the target SQL statement to ensure the correctness of the syntax and logic of the SQL statement. The process of determining the target SQL statement includes: the electronic device determines whether there is an SQL script in the current directory to be executed, and if so, the electronic device determines the SQL script as the target SQL statement.
[0116] The embodiment of the present application also provides an automatic SQL statement checking system, which can automatically obtain, analyze and check SQL statements to ensure the correctness of their syntax and logic. The main functions of the system include:
[0117] Get the latest SQL statement: The system can detect new SQL scripts in the current service or the current directory to be executed, and use them as the target SQL statement to be checked;
[0118] Basic syntax and logic analysis: The system analyzes the target SQL statement to identify keywords, syntax, aggregate functions, and data types. This step is the basis for ensuring that the target SQL statement complies with the SQL language specification.
[0119] Logical relationship mapping: Map the identified logical relationship of the target SQL statement to the pre-established data model. This step helps to match the logical structure of the script with the data model inside the system, thereby conducting a deeper analysis.
[0120] Preset dictionary check: The system checks the logical relationship model of the mapped SQL script based on the preset dictionary. This step can find possible logical errors or unexpected behaviors in the script.
[0121] Check result output: The system finally outputs the check result information of the target SQL statement, including syntax errors, logical errors, etc., to help developers or database administrators understand the health of the script;
[0122] The system of the embodiment of the present application can significantly improve the inspection efficiency and accuracy of SQL statements, reduce failures and data problems caused by SQL statement errors, and through the automated inspection process, can save a lot of manual inspection time and improve the security and reliability of database operations.
[0123] Among them, the SQL query method and system provided in the embodiments of the present application are suitable for fields such as software development, database management, and data migration that require automated checking of SQL statements.
[0124] Based on the above embodiments, Figure 3 A schematic diagram of the structure of a SQL query device provided in an embodiment of the present application, the device comprising:
[0125] The processing module 301 is used to identify the target SQL statement to be checked according to the pre-configured target dictionary, and determine each target character and the corresponding character type in each character of the target SQL statement; if it is determined according to the pre-configured target grammar specification corresponding to each character type that each target character complies with the corresponding target grammar specification, then it is determined that the format of the target SQL statement is correct;
[0126] The query module 302 is used to perform SQL query based on the SQL statement.
[0127] In a possible implementation, the processing module 301 is further used to obtain the target SQL dialect to which the saved target SQL statement belongs; if the target SQL dialect is a pre-configured SQL dialect that supports being recognized, a subsequent step of recognizing the target SQL statement to be checked according to a pre-configured dictionary is performed to determine each target character in each character of the target SQL statement located in the target dictionary and the corresponding character type.
[0128] In a possible implementation manner, the processing module 301 is further configured to output a response message indicating that the SQL statement check has failed if the target SQL dialect is not a pre-configured SQL dialect that supports being recognized.
[0129] In a possible implementation, the processing module 301 is specifically used to obtain a first correspondence between a saved SQL dialect identifier and a dictionary; based on the first correspondence, determine a candidate dictionary corresponding to the identifier of the target SQL dialect to which the target SQL statement belongs; use the candidate dictionary as the target dictionary; and based on a pre-configured target grammar specification corresponding to each character type of the target SQL dialect, determine that each target character complies with the corresponding target grammar specification.
[0130] In a possible implementation, the character type includes at least one of: a keyword, a syntax, a function, and a data type.
[0131] In a possible implementation, the processing module 301 is also used to determine the problem type according to the character type corresponding to the at least one target character if it is determined that at least one target character does not conform to the corresponding target grammar specification according to the pre-configured target grammar specification corresponding to each character type; and generate a modification instruction carrying the identifier of the problem type and the target SQL statement.
[0132] In a possible implementation, the processing module 301 is further configured to determine whether there is an SQL script in the current directory to be executed; if so, determine the SQL script as the target SQL statement.
[0133] Based on the above embodiments, the present application also provides an electronic device, Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application is shown in FIG. Figure 4 As shown, it includes: a processor 401, a communication interface 402, a memory 403 and a communication bus 404, wherein the processor 401, the communication interface 402, and the memory 403 communicate with each other through the communication bus 404;
[0134] The memory 403 stores a computer program. When the program is executed by the processor 401, the processor 401 executes the steps of the SQL query method provided in the above embodiments.
[0135] Since the principle of solving the problem by the above electronic device is similar to the SQL query method, the implementation of the above electronic device can refer to the embodiment of the method, and the repeated parts will not be repeated.
[0136] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The communication interface 402 is used for communication between the above electronic device and other devices. The memory may include a random access memory (RAM) and may also include a non-volatile memory (NVM), such as at least one disk storage. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0137] The above-mentioned processor can be a general-purpose processor, including a central processing unit, a network processor (Network Processor, NP), etc.; it can also be a digital signal processing processor (Digital Signal Processing, DSP), an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, etc.
[0138] Based on the above embodiments, an embodiment of the present invention further provides a computer-readable storage medium, which stores a computer program executable by a processor. When the program runs on the processor, the processor implements the SQL query method steps provided in the above embodiments.
[0139] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0140] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0141] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0142] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0143] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A SQL query method, characterized in that: The method comprises: According to the pre-configured target dictionary, the target SQL statement to be checked is identified, and each target character in each character of the target SQL statement and the corresponding character type are determined; If it is determined that each target character conforms to the corresponding target grammar specification according to the pre-configured target grammar specification corresponding to each character type, it is determined that the format of the target SQL statement is correct, and an SQL query is performed based on the SQL statement.
2. The method according to claim 1, characterized in that The method of determining that each character of the target SQL statement is located before each target character and the corresponding character type of the target dictionary further includes: Obtaining the target SQL dialect to which the target SQL statement is saved; If the target SQL dialect is a pre-configured SQL dialect that supports recognition, a subsequent step of recognizing the target SQL statement to be checked according to the pre-configured dictionary is performed to determine each target character in each character of the target SQL statement located in the target dictionary and the corresponding character type.
3. The method according to claim 2, characterized in that The method further comprises: If the target SQL dialect is not a pre-configured SQL dialect that supports recognition, a response message indicating that the SQL statement check failed is output.
4. The method according to claim 1, characterized in that The process of determining the target dictionary includes: Get the first correspondence between the identifier of the saved SQL dialect and the dictionary; Determine, according to the first corresponding relationship, a candidate dictionary corresponding to the identifier of the target SQL dialect to which the target SQL statement belongs; Using the candidate dictionary as the target dictionary; The determining, according to the pre-configured target grammar specification corresponding to each character type, that each target character complies with the corresponding target grammar specification comprises: According to the pre-configured target grammar specification corresponding to each character type of the target SQL dialect, it is determined that each target character complies with the corresponding target grammar specification.
5. The method according to claim 1, characterized in that The character type includes at least one of a keyword, a syntax, a function, and a data type.
6. The method according to claim 1, characterized in that The method further comprises: If it is determined that at least one target character does not conform to the corresponding target grammar specification according to the pre-configured target grammar specification corresponding to each character type, then the problem type is determined according to the character type corresponding to the at least one target character; A modification instruction is generated that carries the identification of the problem type and the target SQL statement.
7. The method according to claim 1, characterized in that The process of determining the target SQL statement includes: Determine whether there is an SQL script in the current directory to be executed; If it exists, the SQL script is determined as the target SQL statement.
8. A SQL query device, characterized in that: The device comprises: A processing module is used to identify the target SQL statement to be checked according to a pre-configured target dictionary, and determine each target character and the corresponding character type in each character of the target SQL statement; if it is determined according to the pre-configured target grammar specification corresponding to each character type that each target character complies with the corresponding target grammar specification, then it is determined that the format of the target SQL statement is correct; A query module is used to perform SQL query based on the SQL statement.
9. An electronic device, characterized in that: The electronic device comprises at least a processor and a memory, and the processor is used to implement the steps of the SQL query method according to any one of claims 1 to 7 when executing a computer program stored in the memory.
10. A computer-readable storage medium, characterized in that: It stores a computer program, which, when executed by a processor, implements the steps of the SQL query method as described in any one of claims 1 to 7.