Structured query statement processing method and apparatus, device, and storage medium
By recognizing the marked status of input commands and using preset end-of-line markers for detection, the problem of database server errors caused by incomplete SQL statements input by users is solved, achieving efficient processing of structured query statements, reducing network load and improving the accuracy of execution results.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- PING AN TECH (SHENZHEN) CO LTD
- Filing Date
- 2023-05-24
- Publication Date
- 2026-04-17
AI Technical Summary
In existing technologies, incomplete or non-compliant SQL statements input by users can cause the database server to issue syntax error alerts, and the randomness and complexity of user input can increase network load.
By recognizing the marked state of the input instruction, a preset end-of-statement character is used to detect whether the stored instruction is a termination statement. If the marked state is not the preset state, the target instruction is written into the buffer, the server execution statement is extracted, and sent to the database server.
It accurately identifies and processes structured query statements input by users, reduces network load, avoids database server errors, improves the accuracy of execution results, and meets the needs of statement interaction in various scenarios.
Smart Images

Figure CN116628005B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of data processing and financial technology, and in particular to a method, apparatus, device and storage medium for processing structured query statements. Background Technology
[0002] In the fintech field, with the rapid development of computer technology, database applications are becoming increasingly widespread. For example, databases can be used in insurance systems, banking systems, trading systems, and order systems. To reduce the network burden caused by inter-process communication between clients on different machines and database servers, procedural languages have expanded accordingly. Typically, a procedural language consists of multiple statements.
[0003] Currently, to improve the processing efficiency of database servers, it is generally required that the received user input statements must be one or more complete SQL statements, or one or more complete procedural language statements supported by the database server; otherwise, the database server will issue a related syntax error warning. However, user input statements are highly random and complex. A single SQL statement may be entered multiple times, multiple SQL statements may be entered at once, or one or more procedural language statements may be entered at once.
[0004] Therefore, how to accurately identify the statements that the database server can support from user input has become a technical problem that urgently needs to be solved. Summary of the Invention
[0005] In view of the above, it is necessary to provide a method, apparatus, device and storage medium for processing structured query statements, which can accurately identify the statements that the database server can support from user input statements.
[0006] On one hand, this invention proposes a structured query statement processing method applied to an electronic device that communicates with a database server. The structured query statement processing method includes:
[0007] In response to a statement processing request, identify the flag status of the input command read from the preset input interface;
[0008] If the marked state is not a preset state, then the target instruction is read from the preset input interface based on the input instruction, and the target instruction is written into the preset buffer;
[0009] If the stored instruction in the preset buffer is not a local command, then the storage instruction is checked to see if it is a closing statement based on the preset end character;
[0010] If the stored instruction is a termination statement, then based on the preset termination character, the server execution statement is extracted from the stored instruction;
[0011] The server executes the statement and sends it to the database server, and receives the execution result generated by the database server based on the statement.
[0012] According to a preferred embodiment of the present invention, the step of identifying the marking state of the input instruction read from the preset input interface in response to the statement processing request includes:
[0013] Based on the generation time of the statement processing request, the target log is filtered out from the read log of the preset input interface;
[0014] Obtain the read instruction from the target log;
[0015] Based on the read instruction, the input instruction is obtained from the preset input interface;
[0016] Detect whether the input command includes an interrupt signal;
[0017] If the input instruction includes the interrupt signal, then the marked state is determined to be the preset state.
[0018] According to a preferred embodiment of the present invention, the preset terminator includes a first terminator and a second terminator, and the step of detecting whether the storage instruction is a termination statement based on the preset terminator includes:
[0019] If the system configuration terminator of the preset input interface is the initial configuration, then it is detected whether the storage instruction includes the first terminator;
[0020] If the storage instruction includes the first terminator, then lexical analysis is performed on the storage instruction to obtain multiple instruction keywords;
[0021] Obtain the target keyword from the plurality of instruction keywords;
[0022] Detect whether the stored instruction is a procedural statement based on the target keyword;
[0023] If the stored instruction is a procedural statement, then it is determined that the stored instruction is not a termination statement; or
[0024] If the stored instruction is not a procedural statement, or if the stored instruction includes the second terminator, then the stored instruction is determined to be a terminator statement.
[0025] According to a preferred embodiment of the present invention, detecting whether the stored instruction is a procedural statement based on the target keyword includes:
[0026] When the target keyword is a first preset keyword, it is detected whether the storage instruction contains a package statement;
[0027] If the storage instruction does not contain the package statement, then it is detected whether the storage instruction includes a user-defined function statement;
[0028] If the storage instruction does not include the custom function statement, then check whether the storage instruction includes a storage creation statement;
[0029] If the storage instruction does not include the storage creation statement, then it is detected whether the storage instruction includes a trigger creation statement;
[0030] If the stored instruction does not include the trigger creation statement, it is determined that the stored instruction is not a procedural statement; or
[0031] If the stored instruction contains the package statement, the user-defined function statement, or the trigger creation statement, the stored instruction is determined to be a procedural statement.
[0032] According to a preferred embodiment of the present invention, the step of detecting whether the stored instruction is a procedural statement based on the target keyword further includes:
[0033] When the target keyword is the second preset keyword, detect whether the storage instruction contains an anonymous block statement based on the second preset keyword;
[0034] If the storage instruction does not contain an anonymous block statement based on the second preset keyword, then the storage instruction is determined not to be a procedural statement; or
[0035] If the storage instruction contains an anonymous block statement based on the second preset keyword, then the storage instruction is determined to be a procedural statement.
[0036] According to a preferred embodiment of the present invention, the step of detecting whether the stored instruction is a procedural statement based on the target keyword further includes:
[0037] When the target keyword is a third preset keyword, detect whether the storage instruction contains an anonymous block statement based on the third preset keyword;
[0038] If the storage instruction does not contain an anonymous block statement based on the third preset keyword, then the storage instruction is determined not to be a procedural statement; or
[0039] If the storage instruction contains an anonymous block statement based on the third preset keyword, then the storage instruction is determined to be a procedural statement.
[0040] According to a preferred embodiment of the present invention, extracting server execution statements from the stored instructions based on the preset terminator includes:
[0041] If the system configuration terminator is the initial configuration or the second terminator, then the instruction whose character position is before the end position of the second terminator is extracted from the stored instruction and used as the server execution statement; or
[0042] If the system configuration terminator is the first terminator, then the server execution statement is extracted from the stored instructions based on the first terminator.
[0043] On the other hand, the present invention also proposes a structured query statement processing device, which operates on an electronic device and communicates with a database server. The structured query statement processing device includes:
[0044] The recognition unit is used to recognize the marking status of the input command read from the preset input interface in response to the statement processing request;
[0045] The writing unit is used to read the target instruction from the preset input interface based on the input instruction and write the target instruction into a preset buffer if the marked state is not a preset state.
[0046] The detection unit is used to detect whether the stored instruction is a termination statement based on a preset terminator if the stored instruction in the preset buffer is not a local command.
[0047] The extraction unit is used to extract server execution statements from the stored instructions based on the preset end character if the stored instructions are end statements;
[0048] The receiving unit is used to send the server execution statement to the database server and receive the execution result generated by the database server based on the server execution statement.
[0049] On the other hand, the present invention also proposes an electronic device, the electronic device comprising:
[0050] Memory, which stores computer-readable instructions; and
[0051] The processor executes computer-readable instructions stored in the memory to implement the structured query processing method.
[0052] On the other hand, the present invention also proposes a computer-readable storage medium storing computer-readable instructions, which are executed by a processor in an electronic device to implement the structured query statement processing method.
[0053] As can be seen from the above technical solutions, this application, by identifying the marked state of the input instruction and comparing it with the preset state, can detect whether the input instruction is a complete structured query statement. If the marked state is not the preset state, it indicates that the input instruction is not a complete structured query statement. By reading the target instruction from the preset input interface and writing it into the preset buffer, the electronic device can easily send multiple complete structured query statements to the database server for processing, reducing the network burden caused by process communication between clients and the database server on different machines. By detecting whether the stored instruction is a local command, unnecessary process communication can be avoided. When the stored instruction is not a local command and is a closing statement, the server execution statement is extracted using the preset closing character, accurately extracting multiple complete structured query statements supported by the database server, thereby avoiding database server errors and improving the accuracy of the execution results. This application, through the preset closing character, allows users to set closing statements for different scenarios according to their own habits, thus satisfying statement interaction in various scenarios. Attached Figure Description
[0054] Figure 1 This is an application environment diagram of the structured query statement processing method of the present invention.
[0055] Figure 2 This is a flowchart of a preferred embodiment of the structured query statement processing method of the present invention.
[0056] Figure 3 This is a flowchart of the method for processing structured query statements in this invention for detecting whether the stored instruction is a procedural statement.
[0057] Figure 4 This is a functional block diagram of a preferred embodiment of the structured query statement processing device of the present invention.
[0058] Figure 5 This is a schematic diagram of the structure of an electronic device that implements the structured query statement processing method of the present invention. Detailed Implementation
[0059] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be described in detail below with reference to the accompanying drawings and specific embodiments.
[0060] like Figure 1The diagram illustrates the application environment of the structured query processing method of this invention. The structured query processing method is applied to electronic device 1, which communicates with a database server. Electronic device 1 can be a client, allowing any user to input query commands. The database server is primarily responsible for transaction processing and data access between databases.
[0061] like Figure 2 The diagram shown is a flowchart of a preferred embodiment of the structured query statement processing method of the present invention. The order of the steps in this flowchart can be changed, and some steps can be omitted, depending on different requirements.
[0062] The structured query processing method is applied to one or more electronic devices. The electronic device is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored computer-readable instructions. Its hardware includes, but is not limited to, microprocessors, application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), digital signal processors (DSPs), embedded devices, etc.
[0063] The electronic device can be any electronic product that can interact with the user, such as a personal computer, tablet computer, smartphone, personal digital assistant (PDA), game console, interactive network television (IPTV), smart wearable device, etc.
[0064] The electronic devices may include network devices and / or user devices. The network devices include, but are not limited to, single network electronic devices, groups of multiple network electronic devices, or cloud computing-based systems consisting of a large number of hosts or network electronic devices.
[0065] The network in which the electronic device is located includes, but is not limited to: the Internet, wide area network, metropolitan area network, local area network, virtual private network (VPN), etc.
[0066] 101. In response to a statement processing request, identify the flag status of the input command read from the preset input interface.
[0067] In at least one embodiment of the present invention, the statement processing request can be triggered when there is a need to process a structured query statement. The structured query statement need may include a query request for user table information, etc.
[0068] The preset input interface refers to the display interface in the electronic device where the user inputs a structured query statement.
[0069] The input instruction refers to the instruction located on the next line of the target log in the preset input interface. The target log refers to the read instruction corresponding to the moment when the electronic device reads the statement from the preset input interface, and the moment the statement processing request is generated, where the difference is minimal.
[0070] The marked states include exit state, pending input state, etc.
[0071] In at least one embodiment of the present invention, the electronic device, in response to a statement processing request, identifies the marked state of an input instruction read from a preset input interface, including:
[0072] Based on the generation time of the statement processing request, the target log is filtered out from the read log of the preset input interface;
[0073] Obtain the read instruction from the target log;
[0074] Based on the read instruction, the input instruction is obtained from the preset input interface;
[0075] Detect whether the input command includes an interrupt signal;
[0076] If the input instruction includes the interrupt signal, then the marked state is determined to be a preset state.
[0077] The generation time refers to the time when the statement processing request is generated.
[0078] The read log refers to the log information generated when the electronic device reads instructions from the preset input interface.
[0079] The read instruction refers to the specific statement instruction contained in the target log.
[0080] The interrupt signal can be any character representing an interruption, for example, the interrupt signal can be stop, etc.
[0081] The preset state is usually set to the exit state.
[0082] By using the generation time, the target log can be reasonably filtered out, and the read instruction can be accurately obtained from the target log. Then, the input instruction can be accurately obtained from the read instruction. By determining whether the input instruction includes the interrupt signal, the recognition accuracy of the marked state can be improved.
[0083] In this embodiment, the electronic device reads each line of instructions in the preset input interface each time it reads a statement instruction from the preset input interface.
[0084] In other embodiments, if the input instruction does not include the interrupt signal, then the flag state is determined not to be the preset state.
[0085] 102. If the marked state is not the preset state, then the target instruction is read from the preset input interface based on the input instruction, and the target instruction is written into the preset buffer.
[0086] In at least one embodiment of the present invention, the target instruction refers to a statement instruction located on the next line after the input instruction in the preset input interface.
[0087] The preset buffer can be a BUFFER buffer.
[0088] 103. If the storage instruction in the preset buffer is not a local command, then the storage instruction is detected as a termination statement based on the preset terminator.
[0089] In at least one embodiment of the present invention, the stored instructions refer to all instruction statements stored in the preset buffer.
[0090] In at least one embodiment of the present invention, before detecting whether the stored instruction is a termination statement based on a preset terminator, the method further includes:
[0091] Detect whether the first character of the storage instruction is a configuration character;
[0092] If the first character of the storage instruction is the configuration character, then the storage instruction is determined to be a local command; or
[0093] If the first character of the storage instruction is not the configuration character, then the storage instruction is determined not to be a local command.
[0094] The configuration character can be set to "\".
[0095] The configuration characters can be used to quickly identify whether the stored instructions are local commands.
[0096] In at least one embodiment of the present invention, the preset terminator includes a first terminator and a second terminator. For example, the first terminator can be set to ";", and the second terminator can be set to " / ".
[0097] In at least one embodiment of the present invention, the electronic device detects whether the storage instruction is a termination statement based on a preset terminator, including:
[0098] If the system configuration terminator of the preset input interface is the initial configuration, then it is detected whether the storage instruction includes the first terminator;
[0099] If the storage instruction includes the first terminator, then lexical analysis is performed on the storage instruction to obtain multiple instruction keywords;
[0100] Obtain the target keyword from the plurality of instruction keywords;
[0101] Detect whether the stored instruction is a procedural statement based on the target keyword;
[0102] If the stored instruction is a procedural statement, then it is determined that the stored instruction is not a termination statement; or
[0103] If the stored instruction is not a procedural statement, or if the stored instruction includes the second terminator, then the stored instruction is determined to be a terminator statement.
[0104] The initial configuration can be set to "auto".
[0105] The multiple instruction keywords can be obtained by running the storage instructions based on the Flex tool.
[0106] The target keyword is usually the first instruction keyword in the storage instruction.
[0107] The procedural statements may include for loop statements, while loop statements, etc.
[0108] By combining the system configuration terminator, the first terminator, and the second terminator, it is possible to accurately identify whether the stored instruction is a closing statement. By setting the system configuration terminator to the initial configuration, it is possible to automatically identify the end of single-sentence structured statements and multi-sentence statements in procedural languages, thereby improving the ease of use for users on the preset input interface.
[0109] Specifically, the electronic device detects whether the stored instruction is a procedural statement based on the target keyword, including:
[0110] When the target keyword is a first preset keyword, it is detected whether the storage instruction contains a package statement;
[0111] If the storage instruction does not contain the package statement, then it is detected whether the storage instruction includes a user-defined function statement;
[0112] If the storage instruction does not include the custom function statement, then check whether the storage instruction includes a storage creation statement;
[0113] If the storage instruction does not include the storage creation statement, then it is detected whether the storage instruction includes a trigger creation statement;
[0114] If the stored instruction does not include the trigger creation statement, it is determined that the stored instruction is not a procedural statement; or
[0115] If the stored instruction contains the package statement, the user-defined function statement, or the trigger creation statement, the stored instruction is determined to be a procedural statement.
[0116] The first preset keyword can be set to the CREATE keyword.
[0117] The package statement can be set to the CREATEPACKAGE statement.
[0118] The custom function statement can be set as a CREATE FUNCTION statement.
[0119] The storage creation statement can be set to the CREATE PROCEDURE statement.
[0120] The trigger creation statement can be set to the CREATE TRIGGER statement.
[0121] In this embodiment, when the target keyword is the first preset keyword, by detecting whether the storage instruction contains the package statement, the custom function statement, or the trigger creation statement, it is possible to accurately determine whether the storage instruction is a procedural statement.
[0122] Specifically, the electronic device's detection of whether the stored instruction is a procedural statement based on the target keyword further includes:
[0123] When the target keyword is the second preset keyword, detect whether the storage instruction contains an anonymous block statement based on the second preset keyword;
[0124] If the storage instruction does not contain an anonymous block statement based on the second preset keyword, then the storage instruction is determined not to be a procedural statement; or
[0125] If the storage instruction contains an anonymous block statement based on the second preset keyword, then the storage instruction is determined to be a procedural statement.
[0126] The second preset keyword can be set to the DECALRE keyword.
[0127] In this embodiment, when the target keyword is the second preset keyword, the storage instruction can be accurately determined as a procedural statement by detecting whether the storage instruction contains an anonymous block statement based on the second preset keyword.
[0128] Specifically, the electronic device's detection of whether the stored instruction is a procedural statement based on the target keyword further includes:
[0129] When the target keyword is a third preset keyword, detect whether the storage instruction contains an anonymous block statement based on the third preset keyword;
[0130] If the storage instruction does not contain an anonymous block statement based on the third preset keyword, then the storage instruction is determined not to be a procedural statement; or
[0131] If the storage instruction contains an anonymous block statement based on the third preset keyword, then the storage instruction is determined to be a procedural statement.
[0132] The third preset keyword can be set to the BEGIN keyword.
[0133] In this embodiment, when the target keyword is the third preset keyword, the storage instruction can be accurately determined as a procedural statement by detecting whether the storage instruction contains an anonymous block statement based on the third preset keyword.
[0134] like Figure 3 The diagram shown is a flowchart of the method for processing structured query statements according to the present invention, which detects whether the stored instruction is a procedural statement.
[0135] exist Figure 3In this context, the target keyword of the storage instruction is the first Token. When the first Token is the CREATE keyword, it is checked whether the storage instruction includes the CREATEPACKAGE statement. If not, it is checked whether the storage instruction includes the CREATE FUNCTION statement. If not, it is checked whether the storage instruction includes the CREATE PROCEDURE statement. If not, it is checked whether the storage instruction includes the CREATE TRIGGER statement. If not, it is determined that the storage instruction is not a procedural statement. If the storage instruction includes the CREATEPACKAGE statement, or the CREATE FUNCTION statement, or the CREATE PROCEDURE statement, or the CREATE TRIGGER statement, it is determined that the storage instruction is a procedural statement.
[0136] When the first Token is the DECALRE keyword, it is checked whether the storage instruction includes an anonymous block statement with the DECALRE keyword. If not, it is determined that the storage instruction is not a procedural statement; if the storage instruction includes an anonymous block statement with the DECALRE keyword, it is determined that the storage instruction is a procedural statement.
[0137] When the first Token is the BEGIN keyword, it is checked whether the storage instruction includes an anonymous block statement with the BEGIN keyword. If not, it is determined that the storage instruction is not a procedural statement; if the storage instruction includes an anonymous block statement with the BEGIN keyword, it is determined that the storage instruction is a procedural statement.
[0138] When the first Token is any other keyword, it is determined that the storage instruction is not a procedural statement.
[0139] In at least one embodiment of the present invention, the electronic device further includes detecting whether the storage instruction is a termination statement based on a preset terminator:
[0140] If the system configuration terminator is the first terminator, then it is detected whether the storage instruction includes the first terminator;
[0141] If the storage instruction includes the first terminator, then the storage instruction is determined to be a termination statement; or
[0142] If the storage instruction does not include the first terminator, then the storage instruction is determined not to be a termination statement.
[0143] By customizing the system configuration terminator, users can specify different statement terminators to meet the real-time interactive input of statements with different terminators in various scenarios.
[0144] In at least one embodiment of the present invention, the electronic device further includes detecting whether the storage instruction is a termination statement based on a preset terminator:
[0145] If the system configuration terminator is the second terminator, then check whether the storage instruction includes the second terminator;
[0146] If the storage instruction includes the second terminator, then the storage instruction is determined to be a termination statement; or
[0147] If the storage instruction does not include the second terminator, then the storage instruction is determined not to be a termination statement.
[0148] In at least one embodiment of the present invention, if the storage instruction is not a closing statement, the electronic device reads the next line of the target instruction from the preset input interface.
[0149] 104. If the storage instruction is a termination statement, then based on the preset termination character, the server execution statement is extracted from the storage instruction.
[0150] In at least one embodiment of the present invention, the server execution statement can be a single structured statement or multiple statements in a procedural language.
[0151] In at least one embodiment of the present invention, the electronic device extracts server execution statements from the stored instructions based on the preset terminator, including:
[0152] If the system configuration terminator is the initial configuration or the second terminator, then the instruction whose character position is before the end position of the second terminator is extracted from the stored instruction and used as the server execution statement; or
[0153] If the system configuration terminator is the first terminator, then the server execution statement is extracted from the stored instructions based on the first terminator.
[0154] Through the above implementation method, the server execution statement can be accurately extracted from the stored instructions.
[0155] 105. Send the server execution statement to the database server and receive the execution result generated by the database server based on the server execution statement.
[0156] It should be emphasized that, to further ensure the privacy and security of the above execution results, the execution results can also be stored in a blockchain node.
[0157] In at least one embodiment of the present invention, the execution result refers to the result generated by the database after running the server execution statement. For example, the server execution statement may be to query information from all user tables, then the execution result is: information from all user tables, wherein the information from the user tables may include transaction data, payment data, business data, purchase data, and other data information.
[0158] As can be seen from the above technical solutions, this application, by identifying the marked state of the input instruction and comparing it with the preset state, can detect whether the input instruction is a complete structured query statement. If the marked state is not the preset state, it indicates that the input instruction is not a complete structured query statement. By reading the target instruction from the preset input interface and writing it into the preset buffer, the electronic device can easily send multiple complete structured query statements to the database server for processing, reducing the network burden caused by process communication between clients and the database server on different machines. By detecting whether the stored instruction is a local command, unnecessary process communication can be avoided. When the stored instruction is not a local command and is a closing statement, the server execution statement is extracted using the preset closing character, accurately extracting multiple complete structured query statements supported by the database server, thereby avoiding database server errors and improving the accuracy of the execution results. This application, through the preset closing character, allows users to set closing statements for different scenarios according to their own habits, thus satisfying statement interaction in various scenarios.
[0159] like Figure 4 The diagram shown is a functional block diagram of a preferred embodiment of the structured query statement processing device of the present invention. The structured query statement processing device 11 includes an identification unit 110, a writing unit 111, a detection unit 112, an extraction unit 113, and a receiving unit 114. The module / unit referred to in this invention refers to a series of computer-readable instruction segments that can be acquired by the processor 13 and perform a fixed function, and are stored in the memory 12. In this embodiment, the functions of each module / unit will be described in detail in subsequent embodiments.
[0160] The structured query processing device 11 operates on an electronic device, which communicates with a database server.
[0161] The recognition unit 110 is used to recognize the marking status of the input command read from the preset input interface in response to the statement processing request;
[0162] The writing unit 111 is used to read the target instruction from the preset input interface based on the input instruction and write the target instruction into a preset buffer if the marked state is not a preset state.
[0163] The detection unit 112 is used to detect whether the stored instruction is a termination statement based on a preset terminator if the stored instruction in the preset buffer is not a local command.
[0164] Extraction unit 113 is used to extract server execution statements from the stored instructions based on the preset end character if the stored instructions are end statements;
[0165] The receiving unit 114 is used to send the server execution statement to the database server and receive the execution result generated by the database server based on the server execution statement.
[0166] In at least one embodiment of the present invention, the identification unit 110 is further configured to filter out target logs from the reading logs of the preset input interface based on the generation time of the statement processing request.
[0167] Obtain the read instruction from the target log;
[0168] Based on the read instruction, the input instruction is obtained from the preset input interface;
[0169] Detect whether the input command includes an interrupt signal;
[0170] If the input instruction includes the interrupt signal, then the marked state is determined to be the preset state.
[0171] In at least one embodiment of the present invention, the preset end symbol includes a first end symbol and a second end symbol, and the detection unit 112 is further configured to detect whether the storage instruction includes the first end symbol if the system configuration end symbol of the preset input interface is the initial configuration.
[0172] If the storage instruction includes the first terminator, then lexical analysis is performed on the storage instruction to obtain multiple instruction keywords;
[0173] Obtain the target keyword from the plurality of instruction keywords;
[0174] Detect whether the stored instruction is a procedural statement based on the target keyword;
[0175] If the stored instruction is a procedural statement, then it is determined that the stored instruction is not a termination statement; or
[0176] If the stored instruction is not a procedural statement, or if the stored instruction includes the second terminator, then the stored instruction is determined to be a terminator statement.
[0177] In at least one embodiment of the present invention, the detection unit 112 is further configured to detect whether the storage instruction contains a package statement when the target keyword is a first preset keyword;
[0178] If the storage instruction does not contain the package statement, then it is detected whether the storage instruction includes a user-defined function statement;
[0179] If the storage instruction does not include the custom function statement, then check whether the storage instruction includes a storage creation statement;
[0180] If the storage instruction does not include the storage creation statement, then it is detected whether the storage instruction includes a trigger creation statement;
[0181] If the stored instruction does not include the trigger creation statement, it is determined that the stored instruction is not a procedural statement; or
[0182] If the stored instruction contains the package statement, the user-defined function statement, or the trigger creation statement, the stored instruction is determined to be a procedural statement.
[0183] In at least one embodiment of the present invention, the detection unit 112 is further configured to detect whether the storage instruction contains an anonymous block statement based on the second preset keyword when the target keyword is a second preset keyword;
[0184] If the storage instruction does not contain an anonymous block statement based on the second preset keyword, then the storage instruction is determined not to be a procedural statement; or
[0185] If the storage instruction contains an anonymous block statement based on the second preset keyword, then the storage instruction is determined to be a procedural statement.
[0186] In at least one embodiment of the present invention, the detection unit 112 is further configured to detect whether the storage instruction contains an anonymous block statement based on the third preset keyword when the target keyword is a third preset keyword;
[0187] If the storage instruction does not contain an anonymous block statement based on the third preset keyword, then the storage instruction is determined not to be a procedural statement; or
[0188] If the storage instruction contains an anonymous block statement based on the third preset keyword, then the storage instruction is determined to be a procedural statement.
[0189] In at least one embodiment of the present invention, the extraction unit 113 is further configured to, if the system configuration terminator is the initial configuration or the second terminator, extract from the stored instructions the instruction whose character position is before the end position of the second terminator as the server execution statement; or
[0190] If the system configuration terminator is the first terminator, then the server execution statement is extracted from the stored instructions based on the first terminator.
[0191] As can be seen from the above technical solutions, this application, by identifying the marked state of the input instruction and comparing it with the preset state, can detect whether the input instruction is a complete structured query statement. If the marked state is not the preset state, it indicates that the input instruction is not a complete structured query statement. By reading the target instruction from the preset input interface and writing it into the preset buffer, the electronic device can easily send multiple complete structured query statements to the database server for processing, reducing the network burden caused by process communication between clients and the database server on different machines. By detecting whether the stored instruction is a local command, unnecessary process communication can be avoided. When the stored instruction is not a local command and is a closing statement, the server execution statement is extracted using the preset closing character, accurately extracting multiple complete structured query statements supported by the database server, thereby avoiding database server errors and improving the accuracy of the execution results. This application, through the preset closing character, allows users to set closing statements for different scenarios according to their own habits, thus satisfying statement interaction in various scenarios.
[0192] like Figure 5 The diagram shown is a schematic representation of the structure of an electronic device that implements the structured query statement processing method of the present invention.
[0193] In one embodiment of the present invention, the electronic device 1 includes, but is not limited to, a memory 12, a processor 13, and computer-readable instructions stored in the memory 12 and executable on the processor 13, such as a structured query statement processor.
[0194] Those skilled in the art will understand that the schematic diagram is merely an example of electronic device 1 and does not constitute a limitation on electronic device 1. It may include more or fewer components than shown in the diagram, or combine certain components, or different components. For example, electronic device 1 may also include input / output devices, network access devices, buses, etc.
[0195] The processor 13 can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor. The processor 13 is the computing core and control center of the electronic device 1, connecting various parts of the electronic device 1 through various interfaces and lines, and executing the operating system of the electronic device 1, as well as various installed application programs and program code.
[0196] For example, the computer-readable instructions can be divided into one or more modules / units, which are stored in the memory 12 and executed by the processor 13 to complete the present invention. The one or more modules / units can be a series of computer-readable instruction segments capable of performing a specific function, which describe the execution process of the computer-readable instructions in the electronic device 1. For example, the computer-readable instructions can be divided into an identification unit 110, a writing unit 111, a detection unit 112, an extraction unit 113, and a receiving unit 114.
[0197] The memory 12 can be used to store the computer-readable instructions and / or modules. The processor 13 implements various functions of the electronic device 1 by running or executing the computer-readable instructions and / or modules stored in the memory 12 and calling the data stored in the memory 12. The memory 12 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device, etc. The memory 12 may include non-volatile and volatile memory, such as: hard disk, memory, plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, at least one disk storage device, flash memory device, or other storage devices.
[0198] The memory 12 can be the external memory and / or internal memory of the electronic device 1. Furthermore, the memory 12 can be a physical memory, such as a memory module, a TF card (Trans-flash Card), etc.
[0199] If the modules / units integrated in the electronic device 1 are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of the present invention can also be implemented by instructing related hardware through computer-readable instructions. The computer-readable instructions can be stored in a computer-readable storage medium, and when executed by a processor, the computer-readable instructions can implement the steps of the various method embodiments described above.
[0200] The computer-readable instructions include computer-readable instruction code, which may be in the form of source code, object code, executable file, or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer-readable instruction code, recording medium, USB flash drive, portable hard drive, magnetic disk, optical disk, computer memory, read-only memory (ROM), and random access memory (RAM).
[0201] The blockchain referred to in this invention is a novel application model of computer technologies such as distributed structured query processing, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. Essentially, a blockchain is a decentralized database, a chain of data blocks linked together using cryptographic methods. Each data block contains information about a batch of network transactions, used to verify the validity of the information (anti-counterfeiting) and generate the next block. A blockchain can include an underlying blockchain platform, a platform product service layer, and an application service layer.
[0202] Combination Figure 2 The memory 12 in the electronic device 1 stores computer-readable instructions to implement a structured query statement processing method, and the processor 13 can execute the computer-readable instructions to achieve:
[0203] In response to a statement processing request, identify the flag status of the input command read from the preset input interface;
[0204] If the marked state is not a preset state, then the target instruction is read from the preset input interface based on the input instruction, and the target instruction is written into the preset buffer;
[0205] If the stored instruction in the preset buffer is not a local command, then the storage instruction is checked to see if it is a closing statement based on the preset end character;
[0206] If the stored instruction is a termination statement, then based on the preset termination character, the server execution statement is extracted from the stored instruction;
[0207] The server executes the statement and sends it to the database server, and receives the execution result generated by the database server based on the statement.
[0208] Specifically, the specific implementation method of the processor 13 for the above-mentioned computer-readable instructions can be found in [reference needed]. Figure 1 The descriptions of the relevant steps in the corresponding embodiments are not repeated here.
[0209] In the several embodiments provided by this invention, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and other division methods may be used in actual implementation.
[0210] The computer-readable storage medium stores computer-readable instructions, which, when executed by the processor 13, are used to perform the following steps:
[0211] In response to a statement processing request, identify the flag status of the input command read from the preset input interface;
[0212] If the marked state is not a preset state, then the target instruction is read from the preset input interface based on the input instruction, and the target instruction is written into the preset buffer;
[0213] If the stored instruction in the preset buffer is not a local command, then the storage instruction is checked to see if it is a closing statement based on the preset end character;
[0214] If the stored instruction is a termination statement, then based on the preset termination character, the server execution statement is extracted from the stored instruction;
[0215] The server executes the statement and sends it to the database server, and receives the execution result generated by the database server based on the statement.
[0216] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0217] Furthermore, the functional modules in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or in the form of hardware plus software functional modules.
[0218] Therefore, the embodiments should be considered exemplary and non-limiting in all respects, and the scope of the invention is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be embraced within the invention. No appended diagram markings in the claims should be construed as limiting the scope of the claims.
[0219] Furthermore, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. The multiple units or devices described may also be implemented by a single unit or device through software or hardware. Terms such as "first," "second," etc., are used to indicate names and do not indicate any specific order.
[0220] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.
Claims
1. A method for processing structured query statements, applied to an electronic device, the electronic device being in communication with a database server, the method comprising: The structured query processing method includes: In response to a statement processing request, identify the flag status of the input command read from the preset input interface; If the marked state is not a preset state, then the target instruction is read from the preset input interface based on the input instruction, and the target instruction is written into the preset buffer; If the stored instruction in the preset buffer is not a local command, then the storage instruction is checked to see if it is a closing statement based on a preset end character. The preset end character includes a first end character and a second end character. The process of checking whether the stored instruction is a closing statement based on the preset end character includes: if the system configuration end character of the preset input interface is initial configuration, then checking whether the stored instruction includes the first end character; if the stored instruction includes the first end character, then performing lexical analysis on the stored instruction to obtain multiple instruction keywords; obtaining a target keyword from the multiple instruction keywords; checking whether the stored instruction is a procedural statement based on the target keyword; if the stored instruction is a procedural statement, then determining that the stored instruction is not a closing statement; or if the stored instruction is not a procedural statement, or if the stored instruction includes the second end character, then determining that the stored instruction is a closing statement. If the stored instruction is a termination statement, then based on the preset termination character, the server execution statement is extracted from the stored instruction; The server executes the statement and sends it to the database server, and receives the execution result generated by the database server based on the statement. Before detecting whether the storage instruction is a termination statement based on a preset terminator, the method further includes: Detect whether the first character of the storage instruction is a configuration character; If the first character of the storage instruction is the configuration character, then the storage instruction is determined to be a local command; or If the first character of the storage instruction is not the configuration character, then the storage instruction is determined not to be a local command.
2. The method of claim 1, wherein, The flag state for recognizing the input command read from the preset input interface in response to the statement processing request includes: Based on the generation time of the statement processing request, the target log is filtered out from the read log of the preset input interface; Obtain the read instruction from the target log; Based on the read instruction, the input instruction is obtained from the preset input interface; Detect whether the input command includes an interrupt signal; If the input instruction includes the interrupt signal, then the marked state is determined to be the preset state.
3. The method of claim 1, wherein the structured query statement is a SQL statement. The step of detecting whether the stored instruction is a procedural statement based on the target keyword includes: When the target keyword is a first preset keyword, it is detected whether the storage instruction contains a package statement; If the storage instruction does not contain the package statement, then it is detected whether the storage instruction includes a user-defined function statement; If the storage instruction does not include the custom function statement, then check whether the storage instruction includes a storage creation statement; If the storage instruction does not include the storage creation statement, then it is detected whether the storage instruction includes a trigger creation statement; If the stored instruction does not include the trigger creation statement, it is determined that the stored instruction is not a procedural statement; or If the stored instruction contains the package statement, the user-defined function statement, or the trigger creation statement, the stored instruction is determined to be a procedural statement.
4. The method of claim 1, wherein the structured query statement is a SQL statement. The step of detecting whether the stored instruction is a procedural statement based on the target keyword also includes: When the target keyword is the second preset keyword, detect whether the storage instruction contains an anonymous block statement based on the second preset keyword; If the storage instruction does not contain an anonymous block statement based on the second preset keyword, then the storage instruction is determined not to be a procedural statement; or If the storage instruction contains an anonymous block statement based on the second preset keyword, then the storage instruction is determined to be a procedural statement.
5. The method of claim 1, wherein the structured query statement is a SQL statement. The step of detecting whether the stored instruction is a procedural statement based on the target keyword also includes: When the target keyword is a third preset keyword, detect whether the storage instruction contains an anonymous block statement based on the third preset keyword; If the storage instruction does not contain an anonymous block statement based on the third preset keyword, then the storage instruction is determined not to be a procedural statement; or If the storage instruction contains an anonymous block statement based on the third preset keyword, then the storage instruction is determined to be a procedural statement.
6. The structured query statement processing method as described in claim 1, characterized in that, The step of extracting server execution statements from the stored instructions based on the preset terminator includes: If the system configuration terminator is the initial configuration or the second terminator, then the instruction whose character position is before the end position of the second terminator is extracted from the stored instruction and used as the server execution statement; or If the system configuration terminator is the first terminator, then the server execution statement is extracted from the stored instructions based on the first terminator.
7. A structured query statement processing device, operating in an electronic device, the electronic device communicating with a database server, characterized in that, The structured query processing device includes: The recognition unit is used to recognize the marking status of the input command read from the preset input interface in response to the statement processing request; The writing unit is used to read the target instruction from the preset input interface based on the input instruction and write the target instruction into a preset buffer if the marked state is not a preset state. A detection unit is configured to, if the stored instruction in the preset buffer is not a local command, detect whether the stored instruction is a termination statement based on a preset terminator. The preset terminator includes a first terminator and a second terminator. Detecting whether the stored instruction is a termination statement based on the preset terminator includes: if the system configuration terminator of the preset input interface is initial configuration, detecting whether the stored instruction includes the first terminator; if the stored instruction includes the first terminator, performing lexical analysis on the stored instruction to obtain multiple instruction keywords; obtaining a target keyword from the multiple instruction keywords; detecting whether the stored instruction is a procedural statement based on the target keyword; if the stored instruction is a procedural statement, determining that the stored instruction is not a termination statement; or if the stored instruction is not a procedural statement, or if the stored instruction includes the second terminator, determining that the stored instruction is a termination statement. The extraction unit is used to extract server execution statements from the stored instructions based on the preset end character if the stored instructions are end statements; The receiving unit is configured to send the server execution statement to the database server and receive the execution result generated by the database server based on the server execution statement; Before detecting whether the stored instruction is a termination statement based on a preset terminator, the device further includes: The detection unit is also used to detect whether the first character of the storage instruction is a configuration character; The detection unit is further configured to determine that the storage instruction is a local command if the first character of the storage instruction is the configuration character; or The detection unit is further configured to determine that the storage instruction is not a local command if the first character of the storage instruction is not the configuration character.
8. An electronic device, characterized in that, The electronic device includes: Memory, which stores computer-readable instructions; and The processor executes computer-readable instructions stored in the memory to implement the structured query processing method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, which are executed by a processor in an electronic device to implement the structured query statement processing method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Systems, methods, and apparatus to augment process control with virtual assistant
CN111324093A
Distributed cross-regional database transaction processing
CN114207600A