Sentence query method, sentence query system, computer device and storage medium
Patent Information
- Application Number
- CN202410427792.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-09
- Publication Date
- 2026-11-03
- Estimated Expiration
- 2044-04-09
AI Technical Summary
Existing technologies cannot correctly identify and process query statements containing variable characters, resulting in unreliable data queries.
By receiving the initial query file, the system parses the statement and constructs a syntax tree, modifies the statement using preset character formats and connection markers, and generates the target query statement to achieve correct querying for different types of characters.
It improves the reliability of query statements, accurately identifies and processes query statements containing variable characters, and ensures the accuracy and efficiency of data retrieval.
Smart Images

Figure CN118193580B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of digital medical technology, and in particular to a statement query method, a statement query system, a computer device, and a storage medium. Background Technology
[0002] In digital healthcare data query scenarios, stored medical data includes various types of data such as personal health records, prescriptions, examination reports, hospitalization duration, and expenditure amounts. Querying different types of data allows patients and doctors to obtain the necessary information promptly. For example, electronic medical record systems within digital healthcare systems can use data queries to more accurately statistically analyze monthly and annual patient treatment durations, expenditure amounts, and other information. Alternatively, patient self-service systems can provide patients with more diverse and accurate query results, enabling them to understand their own situations in a timely manner. Currently, when conducting concurrent testing on databases, the query methods executed can only execute simple Structured Query Language (SQL) statements, such as creating, deleting, adding, deleting, modifying, and querying tables based on data. However, if a specific character is used in an SQL statement to represent multiple different data types, the relevant technology cannot correctly recognize the specific character in the statement. Therefore, how to propose an implementation method that can handle query statements containing variable characters to improve the reliability of data querying has become an urgent technical problem to be solved. Summary of the Invention
[0003] The main objective of this application is to propose a statement query method, statement query system, computer device, and storage medium that can correctly query different types of characters in a query statement, thereby improving the reliability of data query.
[0004] To achieve the above objectives, a first aspect of this application proposes a statement query method, the method comprising:
[0005] Receive an initial query file, the initial query file including an initial query statement;
[0006] The initial query statement is parsed to obtain the first parsed character data;
[0007] The statement execution flag of the initial query statement is determined based on the preset character format and the first parsed character data;
[0008] A syntax tree is constructed based on the statement execution flag and the first parsed character data to obtain a first syntax tree;
[0009] Based on the first syntax tree, the initial query statement is marked with a session connection identifier to obtain a first connection identifier;
[0010] The initial query statement is modified according to the first connection identifier, the statement execution flag, and the preset character library to obtain the target query statement;
[0011] Data is queried based on the first syntax tree and the target query statement.
[0012] In some embodiments, the statement execution marker includes a first execution marker, which indicates that the initial query statement needs to be re-parsed. Determining the statement execution marker of the initial query statement based on a preset character format and the first parsed character data includes:
[0013] The first parsed character data is processed to extract characters, resulting in the first starting character;
[0014] The initial query statement is subjected to initial state detection based on the preset starting character and the first starting character to obtain the first statement state, which includes the initial matching state.
[0015] When the first statement is in the initial matching state, the initial query statement is subjected to character state detection according to the preset character format to obtain the character state, which includes the character existence state.
[0016] When the character state is the character existence state, the initial query statement is marked as the first execution mark.
[0017] In some embodiments, the statement execution flag further includes a second execution flag, which indicates that the initial query statement does not need to be re-parsed;
[0018] The step of constructing a syntax tree based on the statement execution marker and the first parsed character data to obtain a first syntax tree includes:
[0019] The initial query statement is divided according to the statement execution flag to obtain a first query statement marked with the first execution flag and a second query statement marked with the second execution flag. Then the first parsed character data includes the first character data of the first query statement and the second character data of the second query statement.
[0020] The first execution marker and the first character data are combined to obtain the first marker character data;
[0021] The second execution flag and the second character data are combined to obtain the second flag character data;
[0022] The first syntax tree is generated based on the first marker character data and the second marker character data.
[0023] In some embodiments, the preset character library includes candidate character units, and the step of modifying the initial query statement according to the first connection identifier, the statement execution flag, and the preset character library to obtain the target query statement includes:
[0024] Based on the first execution marker, the first syntax tree is used to extract characters to obtain the first marker character data, which includes candidate character names;
[0025] The first connection identifier of the first query statement is used as a candidate connection identifier, and the target character unit is selected from the candidate character units according to the candidate connection identifier and the candidate character name. The target character unit includes target character data.
[0026] Based on the target character data, the candidate character names are replaced to obtain the target marker character data;
[0027] The target query statement is generated based on the target marker character data.
[0028] In some embodiments, the first syntax tree includes an initial execution node, and the data query based on the first syntax tree and the target query statement includes:
[0029] The target execution node is selected from the initial execution nodes of the first syntax tree according to the target query statement;
[0030] The statement execution sequence of the target query statement is determined based on the target execution node;
[0031] The target query statement is executed according to the statement execution sequence.
[0032] In some embodiments, before modifying the initial query statement according to the first connection identifier, the statement execution flag, and a preset character library to obtain the target query statement, the method further includes:
[0033] Constructing the preset character library specifically includes:
[0034] Receive an initial character setting file, the initial character setting file including an initial character setting statement, the initial character setting statement including an initial character name and initial character data;
[0035] The initial character setting statement is parsed to obtain the second parsed character data;
[0036] The second parsed character data is used to extract characters to obtain the statement end character;
[0037] The statement type marker of the initial character setting statement is determined based on the preset end character and the statement end character;
[0038] A second syntax tree is constructed based on the second parsed character data and the statement type marker;
[0039] The initial character setting statement is processed with a session connection marker to obtain a second connection identifier;
[0040] Based on the statement type marker, the second connection identifier, the initial character name, and the initial character data are combined to obtain candidate character units;
[0041] The preset character library is constructed based on the candidate character units.
[0042] In some embodiments, before extracting characters from the second parsed character data to obtain the statement end character, constructing the preset character library further includes:
[0043] The second parsed character data is processed to extract characters, resulting in the second starting character;
[0044] The initial character setting statement is checked for initial state based on the preset starting character and the second starting character to obtain the second statement state, which includes the statement start non-compliance state.
[0045] When the second statement is in the initial non-compliance state, a statement type error message is output.
[0046] To achieve the above objectives, a second aspect of this application provides a statement query system, the system comprising:
[0047] The file receiving module is used to receive an initial query file, which includes an initial query statement.
[0048] The statement parsing module is used to parse the initial query statement to obtain the first parsed character data;
[0049] The statement marking module is used to determine the statement execution mark of the initial query statement based on the preset character format and the first parsed character data;
[0050] The tree construction module is used to construct a syntax tree based on the statement execution marker and the first parsed character data to obtain a first syntax tree;
[0051] The connection tagging module is used to perform session connection tagging on the initial query statement according to the first syntax tree to obtain a first connection identifier;
[0052] The statement modification module is used to modify the initial query statement according to the first connection identifier, the statement execution flag and the preset character library to obtain the target query statement;
[0053] The data query module is used to perform data queries based on the first syntax tree and the target query statement.
[0054] To achieve the above objectives, a third aspect of this application provides a computer device, comprising:
[0055] At least one memory;
[0056] At least one processor;
[0057] At least one computer program;
[0058] The at least one computer program is stored in the at least one memory, and the at least one processor executes the at least one computer program to implement the statement query method described in the first aspect above.
[0059] To achieve the above objectives, a fourth aspect of the present application provides a computer-readable storage medium storing a computer program for causing a computer to execute the statement query method described in the first aspect.
[0060] This application proposes a statement query method, system, computer device, and storage medium. The method involves receiving an initial query file, which includes an initial query statement. The initial query statement is parsed to obtain first parsed character data. A statement execution flag is determined based on a preset character format and the first parsed character data. Then, a syntax tree is constructed based on the statement execution flag and the first parsed character data to obtain a first syntax tree. Next, a session connection flag is applied to the initial query statement based on the first syntax tree to obtain a first connection identifier. The initial query statement is modified based on the first connection identifier, the statement execution flag, and a preset character library to obtain a target query statement. Finally, data is queried based on the first syntax tree and the target query statement. This application embodiment enables correct querying of different types of characters in the query statement, improving the reliability of the statement query. Attached Figure Description
[0061] Figure 1 This is a first flowchart of the statement query method provided in the embodiments of this application;
[0062] Figure 2 yes Figure 1 A flowchart of step S130;
[0063] Figure 3 yes Figure 1 A flowchart of step S140;
[0064] Figure 4 yes Figure 1 A flowchart of step S160;
[0065] Figure 5 This is a second flowchart of the statement query method provided in the embodiments of this application;
[0066] Figure 6 This is the third flowchart of the statement query method provided in the embodiments of this application;
[0067] Figure 7 yes Figure 1 A flowchart of step S170;
[0068] Figure 8 This is a schematic diagram of the structure of the statement query system provided in the embodiments of this application;
[0069] Figure 9 This is a schematic diagram of the hardware structure of the computer device provided in the embodiments of this application. Detailed Implementation
[0070] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0071] It should be noted that although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first," "second," etc., in the specification, claims, and the aforementioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.
[0072] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0073] First, let's analyze some of the terms used in this application:
[0074] Structured Query Language (SQL) is a database query and programming language used to access, query, update, and manage relational database systems.
[0075] PostgreSQL is an object-relational database management system (ORDBMS).
[0076] Syntax tree: It is an abstract representation of the syntax structure of source code. The syntax tree represents the syntax structure of a programming language in a tree-like form. Each node in the tree represents a structure in the source code. It is also called an abstract syntax tree.
[0077] Concurrency testing tools are provided by PostgreSQL to allow testers to test the concurrency of database SQL queries. These tools are typically implemented using the `pg_isolation_regress` utility with a `spec` script. `pg_isolation_regress` is the compiled executable file, a binary file from PostgreSQL, and `spec` is the input script file. Unlike single-session testing tools, concurrency testing tools can create multiple sessions simultaneously for testing. Furthermore, they typically include a lexical analyzer, a syntax analyzer, and an executor.
[0078] Currently, in digital healthcare data query scenarios, the stored medical data includes various types of data such as personal health records, prescriptions, examination reports, hospitalization duration, and expenditure amounts. Querying different types of data allows patients and doctors to obtain the necessary information promptly. For example, electronic medical record systems within digital healthcare systems are typically designed based on concurrency testing tools. Such systems can enable simultaneous data queries from multiple target groups and can more accurately statistically analyze monthly and annual patient treatment durations, expenditure amounts, and other information. Alternatively, patient self-service systems can also be designed based on concurrency testing tools, providing patients with more diverse and accurate query results so they can understand their own health status in a timely manner.
[0079] Currently, when conducting concurrent testing on databases, the query methods executed can only handle simple SQL statements, such as creating, deleting, and performing CRUD operations on tables. However, if a specific character is used in an SQL statement to represent multiple different data types, the existing technology cannot correctly recognize this character. Therefore, developing a method to handle query statements containing variable characters, thereby improving the reliability of query results, has become a pressing technical problem.
[0080] Based on this, embodiments of this application provide a statement query method, a statement query system, a computer device, and a storage medium, which can correctly query different types of characters in a query statement and improve the reliability of statement queries.
[0081] The statement query method provided in this application can be applied to a terminal, a server, or software running on either a terminal or a server. In some embodiments, the terminal can be a smartphone, tablet, laptop, desktop computer, etc.; the server can be configured as an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms; the software can be an application implementing the statement query method, but is not limited to the above forms.
[0082] This application can be used in a wide variety of general-purpose or special-purpose computer system environments or configurations. Examples include: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network personal computers (PCs), minicomputers, mainframe computers, and distributed computing environments including any of the above systems or devices. This application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific tasks or implement specific abstract data types. This application can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0083] It should be noted that in all specific embodiments of this application, when processing data related to user identity or characteristics, such as user information, user behavior data, user historical data, user medical data, and user location information, user permission or consent will be obtained first. Furthermore, the collection, use, and processing of this data will comply with relevant laws, regulations, and standards. In addition, when embodiments of this application require obtaining sensitive personal information of users, such as user medical data, separate permission or consent from the user will be obtained through pop-ups or redirects to confirmation pages. Only after explicitly obtaining the user's separate permission or consent will the necessary user-related data for the normal operation of the embodiments of this application be obtained.
[0084] Please see Figure 1 , Figure 1 This is an optional flowchart of the statement query method provided in the embodiments of this application. In some embodiments of this application, the statement query method provided in the embodiments of this application may specifically include, but is not limited to, steps S110 to S170, as described below. Figure 1 These seven steps will be explained in detail.
[0085] Step S110: Receive the initial query file, which includes the initial query statement;
[0086] Step S120: Parse the initial query statement to obtain the first parsed character data;
[0087] Step S130: Determine the statement execution flag of the initial query statement based on the preset character format and the first parsed character data;
[0088] Step S140: Construct a syntax tree based on the statement execution marker and the first parsed character data to obtain the first syntax tree;
[0089] Step S150: Mark the initial query statement with session connection according to the first syntax tree to obtain the first connection identifier;
[0090] Step S160: Modify the initial query statement according to the first connection identifier, the statement execution flag and the preset character library to obtain the target query statement;
[0091] Step S170: Perform a data query based on the first syntax tree and the target query statement.
[0092] In step S110 of some embodiments, firstly, the initial query file is used to represent a statement file containing multiple initial query statements of tester data, or a statement file generated by the computer when other objects perform data queries, and the initial query file includes multiple initial query statements. The statement query method of this application can be set on the client or server. For example, when the statement query method of this application is set on the client, after an object inputs a query request for data on the client, the computer automatically generates an initial query file containing multiple initial query statements based on the query request, and calls the corresponding database to perform data queries based on the initial query file.
[0093] It's important to note that in digital healthcare data storage scenarios, the stored medical data includes personal health records, prescriptions, and examination reports. This data includes both mutable and immutable data. For example, the stored medical data might be statistically analyzed and stored in different fields within a database, including fields such as personal information, examination items, unit price of each item, total cost, and length of hospital stay. While the unit price of each examination for a patient remains constant, the total cost generated for that patient continuously changes; that is, the total cost is a variable type of data.
[0094] It should be noted that in concurrent testing scenarios, for example, if the initial query statement in the initial query file input by the test object is "SELECT:test", and "test" is a character data of variable type, then the specific value of this character data of variable type can be queried by calling the test database. Therefore, the statement query method provided in this application can effectively overcome the situation where related technologies cannot accurately query variable data. That is, this application can effectively identify the character data of variable type in the statement and query the variable value corresponding to the character data, thereby achieving accurate reading of variable data.
[0095] It should be noted that the database used for querying statements in this application can be of different types, such as MySQL, DB2, PostgreSQL, etc., and no specific limitation is made here.
[0096] In step S120 of some embodiments, in a concurrent testing scenario, the tools corresponding to the statement query method of this application include a first parser, a second parser, and an executor. The first parser is equivalent to a lexical parser, which recognizes the characters in the initial query statement as various identifiers defined in a high-level language, such as variables, functions, keywords, commas, semicolons, etc. For example, in the statement, a and b are variables, main is a function, and int and return are keywords. Specifically, the initial query statement is first parsed to obtain a first parsing sequence, which represents the set formed by dividing each character data in the initial query statement. The first parsing sequence includes multiple first parsing character data. For example, if the initial query statement is "SELECT@subject FROM TABLE1;", parsing the initial query statement yields a first parsing sequence of [query instruction method, variable, query keyword, constant, semicolon], then the first parsing character data includes the query instruction method "SELECT", the variable "@subject", the query keyword "FROM", the constant "TABLE1", and the semicolon.
[0097] In step S130 of some embodiments, since this application embodiment is an implementation method for a query statement containing variable characters, it is necessary to determine the statement execution flag of the initial query statement based on the preset character format and the first parsed character data. The preset character format represents a preset character data format containing variable characters (i.e., variables). For example, the preset character format can be ":variable_name" or "@variable_name", etc., without specific limitations here. The statement execution flag indicates whether the initial query statement is a statement containing variables or a statement not containing variables.
[0098] Please see Figure 2 , Figure 2 This is an optional flowchart of step S130 provided in the embodiments of this application. In some embodiments of this application, the statement execution marker includes a first execution marker, which is used to indicate that the initial query statement needs to be re-parsed. Therefore, step S130 may specifically include, but is not limited to, steps S210 to S240. The following describes... Figure 2 These four steps will be explained in detail.
[0099] Step S210: Extract characters from the first parsed character data to obtain the first starting character;
[0100] Step S220: Perform initial state detection on the initial query statement according to the preset starting character and the first starting character to obtain the first statement state, which includes the initial matching state;
[0101] Step S230: When the first statement is in the initial matching state, the initial query statement is subjected to character state detection according to the preset character format to obtain the character state, which includes the character existence state.
[0102] Step S240: When the character state is the character existence state, mark the initial query statement as the first execution mark.
[0103] In step S210 of some embodiments, before performing a statement query on the SQL statement, it is first determined whether the starting data of the initial query file meets the starting character requirements defined by the SQL statement, that is, whether the SQL statement in the initial query file can be executed normally through SQL polling. Therefore, this application first extracts the first starting character from the first parsed character data, which is used to represent the first character data in the initial query file.
[0104] In step S220 of some embodiments, since the preset starting character of the SQL statement definition is curly braces "{", the curly braces "{" are compared with the first starting character, and the initial query statement is checked for a starting state based on the comparison result to obtain the first statement state. Therefore, this first statement state indicates whether SQL polling execution of the statements in the initial query file can be performed normally. The first statement state includes a starting conformance state and a starting non-conformance state. A starting conformance state indicates that the first starting character is the same as the preset starting character, meaning that SQL polling execution of the statements in the initial query file can be performed normally. A starting non-conformance state indicates that the first starting character is different from the preset starting character, meaning that SQL polling execution of the statements in the initial query file cannot be performed normally; in this case, a statement error message is output, and the query for the initial query file is terminated.
[0105] In steps S230 and S240 of some embodiments, since statements containing variable characters need to be re-parsed to obtain the numerical value corresponding to the variable character, when the first statement state is in the initial matching state, character matching of the initial query statement needs to be performed according to the preset character format, sequentially matching other characters of the first parsed character data, thereby realizing character state detection, and marking whether the initial query statement contains variable characters (i.e., variables) through character state. The character state includes a character presence state and a character absence state. The character presence state indicates that the initial query statement contains variable characters, and the character absence state indicates that the initial query statement contains immutable characters. Therefore, when the character state is in the character presence state, a first execution flag is set for the initial query statement, which indicates that the initial query statement needs to be re-parsed. This embodiment of the application marks the initial query statement according to the preset character format, enabling the query to find variable characters in the query statement.
[0106] It should be noted that after an initial query statement is marked, the process continues to match other strings in the first parsed character data until the end character of the initial query statement is detected. The preset start character and preset end character are a corresponding pair of characters; if the preset start character is curly braces "{", then the end character of the initial query statement should be curly braces "}". Therefore, when the end character of the initial query statement is detected as curly braces "}", the first executor parsing process ends.
[0107] In step S140 of some embodiments, after the preset end character of the initial query statement is identified, the first parser sends all the first parsed character data and statement execution flags returned to the second parser.
[0108] It's important to note that the second parser is essentially a syntax parser. This parser performs grammatical checks on the data and constructs a data structure (i.e., an abstract syntax tree) composed of the input character data (equivalent to words, tokens). Furthermore, the syntax parser typically uses a lexer to extract individual words (tokens) from the input string and uses this stream of tokens as its input. In actual development, the syntax parser can be written manually or automatically generated using tools.
[0109] Please see Figure 3 , Figure 3 This is an optional flowchart of step S140 provided in the embodiments of this application. In some embodiments of this application, the statement execution marker further includes a second execution marker, which is used to indicate that the initial query statement does not need to be re-parsed. Therefore, step S140 may specifically include, but is not limited to, steps S310 to S340. The following describes the process in conjunction with... Figure 3 These four steps will be explained in detail.
[0110] Step S310: The initial query statement is divided according to the statement execution flag to obtain a first query statement marked with a first execution flag and a second query statement marked with a second execution flag. Then the first parsed character data includes the first character data of the first query statement and the second character data of the second query statement.
[0111] Step S320: Combine the first execution marker and the first character data to obtain the first marker character data;
[0112] Step S330: Combine the second execution flag and the second character data to obtain the second flag character data;
[0113] Step S340: Generate a first syntax tree based on the first marker character data and the second marker character data.
[0114] In step S310 of some embodiments, to improve statement query efficiency, this application embodiment can concurrently perform statement queries on multiple initial query statements. Specifically, the initial query statements are divided according to the statement execution flags to obtain a first query statement marked with a first execution flag and a second query statement marked with a second execution flag. Therefore, the first parsed character data at this time includes the first character data of the first query statement and the second character data of the second query statement, and the first character data and the second character data respectively contain the corresponding query statement flags to accurately locate the corresponding statements.
[0115] In steps S320 to S330 of some embodiments, since the statement markings from the first parser cannot be passed to the executor, they need to be re-marked in the second parser. Therefore, by combining the first execution mark and the first character data to obtain first marked character data, the corresponding statement can be determined to need re-parsing based on the first marked character data. Similarly, by combining the second execution mark and the second character data to obtain second marked character data, the corresponding statement can be determined to not need re-parsing based on the second marked character data.
[0116] In step S340 of some embodiments, after all initial query statements have been marked by the second parser, a first syntax tree is generated based on the execution logic of the first and second marked character data in the corresponding initial query statements. This first syntax tree is equivalent to a logical plan tree, which can convert the corresponding statement into an executable physical plan, i.e., how to scan data, how to aggregate, etc., effectively improving statement execution efficiency. Then, the second parser sends the first syntax tree to the executor.
[0117] In step S150 of some embodiments, after receiving the first syntax tree, the executor establishes a connection with the database server through the executor's session connection interface. Specifically, when establishing a session connection, the executor assigns a unique connection identifier to each session. This connection identifier is a symbol used to identify a connection and can be letters, numbers, or other characters, etc., without specific limitations. One session connection can correspond to multiple initial query statements, so the first connection identifiers corresponding to different initial query statements may be the same.
[0118] In step S160 of some embodiments, since the initial query statement containing variable characters needs to call the specific variable value corresponding to the variable character, the initial query statement is modified according to the first connection identifier, the statement execution flag, and the preset character library to obtain the target query statement containing the specific variable value. This achieves correct querying of different types of characters in the query statement and improves the reliability of the statement query.
[0119] Please see Figure 4 , Figure 4 This is an optional flowchart of step S160 provided in the embodiments of this application. In some embodiments of this application, the preset character library includes candidate character units, then step S160 may specifically include, but is not limited to, steps S410 to S440, as described below. Figure 4 These four steps will be explained in detail.
[0120] Step S410: Extract characters from the first syntax tree according to the first execution tag to obtain the first tag character data, which includes candidate character names;
[0121] Step S420: The first connection identifier of the first query statement is used as a candidate connection identifier, and the target character unit is selected from the candidate character units according to the candidate connection identifier and the candidate character name. The target character unit includes the target character data.
[0122] Step S430: Replace the candidate character names with characters based on the target character data to obtain the target marker character data;
[0123] Step S440: Generate a target query statement based on the target marker character data.
[0124] In step S410 of some embodiments, since the first execution marker indicates that the initial query statement needs to be re-parsed, the first marker character data extracted from the first syntax tree based on the first execution marker is the statement character data that needs to be re-parsed. The candidate character name is used to represent the variable characters in the initial query statement, i.e., variable names. For example, if the initial query statement is "SELECT:test FROM TABLE1", then the candidate character name is "test".
[0125] In step S420 of some embodiments, this application embodiment stores a preset character library in memory or a storage engine, and the preset character library includes multiple candidate character units. Each candidate character unit is a triple, including a connection identifier to be matched, a variable name to be matched, and a variable value. Since one connection identifier can correspond to different statements, in order to accurately query the variable value, the first connection identifier of the first query statement corresponding to the first execution flag is first used as a candidate connection identifier. Then, unit matching is performed from the candidate character units based on both the candidate connection identifier and the candidate character name. That is, the candidate character unit must contain both the connection identifier to be matched that is the same as the candidate connection identifier and the variable name to be matched that is the same as the candidate character name. Then, the candidate character unit is determined to be the target character unit. Therefore, the variable value contained in the target character unit is the target character data being queried. For example, if the candidate character name is test and the target character data being queried is 12, then the value corresponding to test is 12, and after executing the statement, the output result is 12.
[0126] In steps S430 and S440 of some embodiments, after the variable value, i.e., the target character data, is retrieved, the variable value is used to replace the variable character in the statement. Specifically, the target character data is replaced with the position corresponding to the candidate character name in the first syntax tree to obtain the target marker character data. A new target query statement is generated based on the replaced target marker character data.
[0127] This application embodiment, by simultaneously matching the connector identifier and the variable character name, can more accurately retrieve the corresponding variable value from memory, thereby achieving correct retrieval of different types of characters in the query statement and improving the reliability of the query.
[0128] Please see Figure 5 , Figure 5 This is another optional flowchart of the statement query method provided in the embodiments of this application. In some embodiments of this application, before step S160, the statement query method of this application may further include the step of constructing a preset character library. This step may specifically include, but is not limited to, steps S510 to S580, as described below. Figure 5 These eight steps will be explained in detail.
[0129] Step S510: Receive an initial character setting file. The initial character setting file includes an initial character setting statement, which includes an initial character name and initial character data.
[0130] Step S520: Parse the initial character setting statement to obtain the second parsed character data;
[0131] Step S530: Extract characters from the second parsed character data to obtain the statement end character;
[0132] Step S540: Determine the initial character and set the statement type flag of the statement based on the preset end character and the statement end character;
[0133] Step S550: Construct a syntax tree based on the second parsed character data and statement type tags to obtain a second syntax tree;
[0134] Step S560: Mark the initial character setting statement with a session connection flag to obtain the second connection flag;
[0135] Step S570: Combine the second connection identifier, the initial character name, and the initial character data according to the statement type marker to obtain candidate character units;
[0136] Step S580: Construct a preset character library based on candidate character units.
[0137] In steps S510 to S520 of some embodiments, the preset character library of this application embodiment is used to store the set variable character (variable) information, and the preset character library can be stored in memory or other storage engines. Since this application can realize concurrent operations for setting multiple variables, the initial character setting file can include multiple initial character setting statements. The initial character name is used to represent the name of the set variable character, and the initial character data is used to represent the specific numerical value corresponding to the variable character. Specifically, the first parser first parses the initial character setting statement to obtain a second parsing sequence, which represents the set formed by dividing each character data in the initial query statement. The second parsing sequence includes multiple second parsed character data. The specific description of the second parsed data is the same as that of the first parsed character data, and will not be repeated here.
[0138] In steps S530 and S540 of some embodiments, to improve the variable setting process for the initial character setting statement, this application embodiment extracts the last character of the second parsed character data in the statement, i.e., the statement end character. Then, a character comparison is performed based on the preset end character and the statement end character to determine the statement type marker of the initial character setting statement based on the comparison result.
[0139] It should be noted that statement type tags include variable setting tags and other type tags. Variable setting tags indicate that the corresponding statement is a statement that sets and stores variables, while other type tags indicate that the corresponding statement is not a statement that sets and stores variables.
[0140] It should be noted that the preset end character is used to mark whether the corresponding initial character setting statement is a statement type that sets variable characters. When the preset end character and the statement end character are the same, the initial character setting statement is determined to be a statement that sets variable characters. When the preset end character and the statement end character are different, the initial character setting statement is determined not to be a statement that sets variable characters, that is, it is another type of statement, such as environment configuration. Assuming the preset end character is "\i set", for example, when the initial character setting statement is "SELECT 1AS test\i set", the extracted statement end character is "\i set". Since this preset end character and the statement end character are the same, the statement type marker corresponding to this initial character setting statement is determined to be a variable setting marker.
[0141] In step S550 of some embodiments, after the first parser has parsed all the initial character setting statements, it sends the obtained second parsed character data and the corresponding statement type tag to the second parser. Furthermore, since the statement tagging by the first parser cannot be passed to the executor, it needs to be re-marked in the second parser. The re-marking in the second parser is the same as the process described above for parsing the first parsed character data and executing the statements, and will not be repeated here. Therefore, a syntax tree is constructed based on the second parsed character data and statement type tag to obtain a second syntax tree, and this second syntax tree is sent to the executor. The construction process of the second syntax tree is the same as that of the first syntax tree, and will not be repeated here.
[0142] In some embodiments, steps S560 to S580 involve setting the second connection identifier in the same way as setting the first connection identifier. For the second connection identifier set by the executor for an initial character setting statement containing variable characters, when extracting variable values from the variable characters, the corresponding first and second connection identifiers are identical, ensuring accurate matching of the corresponding variable values in the preset character library. Then, after marking all statements, the executor calls the `libpq` interface function to execute the initial character setting statement after the connection marking. Upon successful statement execution, the executor determines the statement type flag corresponding to the initial character setting statement. If the statement type flag is identified as a variable setting flag, the corresponding second connection identifier, initial character name, and initial character data are combined into a triplet to obtain the candidate character unit. Finally, all candidate character units are stored in memory or another storage engine to construct the preset character library.
[0143] Please see Figure 6 , Figure 6This is another optional flowchart of the statement query method provided in the embodiments of this application. In some embodiments of this application, before step S530, the construction of a preset character library may specifically include, but is not limited to, steps S610 to S630. The following is a detailed description... Figure 6 These three steps will be explained in detail.
[0144] Step S610: Extract characters from the second parsed character data to obtain the second starting character;
[0145] Step S620: Perform a start state detection on the initial character setting statement according to the preset start character and the second start character to obtain the second statement state, which includes the statement start non-compliance state.
[0146] Step S630: When the second statement status is in the initial non-compliance state, output statement type error information.
[0147] In steps S610 to S630 of some embodiments, since the preset starting character of the SQL statement definition is curly braces "{", the initial character setting statement is checked for its initial state based on the preset starting character and the second starting character. The second statement state indicates whether the SQL polling execution of the statements in the initial character setting file can be performed normally. When the second statement state is an initial non-compliance state, a statement type error message is output, and the query for the initial query file is terminated.
[0148] It should be noted that after step S540, i.e., after setting the statement mark for an initial character, the process continues to match other strings in the second parsed character data corresponding to other statements until the end character of the initial query file is identified. The preset start character and the end character of the initial query file are a pair of corresponding characters. When the preset start character is curly braces "{", then the end character of the initial query file should be curly braces "}". Therefore, when the end character of the initial query file is identified as curly braces "}", the first executor parsing process ends.
[0149] In step S170 of some embodiments, after determining the target query statement, the executor calls the li bpq interface function according to the first syntax tree to execute the target query statement and outputs the data query result to a preset output file.
[0150] It should be noted that for the second query statement marked with the second execution flag, the executor will also call the li bpq interface function according to the first syntax tree to execute the corresponding second query statement, and output the data query results to the corresponding preset output file.
[0151] It should be noted that li bpq is a collection of library functions. Calling the li bpq interface functions allows client programs to pass query requests to the corresponding backend servers and receive the output files of these queries.
[0152] Please see Figure 7 , Figure 7 This is an optional flowchart of step S170 provided in the embodiments of this application. In some embodiments of this application, the first syntax tree includes an initial execution node, and step S170 may specifically include, but is not limited to, steps S710 to S730, as described below. Figure 7 These three steps will be explained in detail.
[0153] Step S710: Select the target execution node from the initial execution nodes of the first syntax tree according to the target query statement;
[0154] Step S720: Determine the statement execution sequence of the target query statement based on the target execution node;
[0155] Step S730: Perform a data query operation on the target query statement according to the statement execution sequence.
[0156] In steps S710 to S730 of some embodiments, since the executor executes the statement information corresponding to each node in the syntax tree when executing the statement, this embodiment first filters out the target execution node associated with the target query statement from the initial execution nodes of the first syntax tree. Then, the statement execution sequence of the target query statement is determined based on the target execution node, which represents the statement execution plan for executing the target query statement. Afterwards, the target query statement is executed according to the statement execution sequence, and the output after execution is written to a preset output file, which is then returned to the client.
[0157] Please see Figure 8 , Figure 8 This is a schematic diagram of the structure of the statement query system provided in this application embodiment. The system includes a file receiving module 810, a statement parsing module 820, a statement marking module 830, a tree construction module 840, a connection marking module 850, a statement modification module 860, and a data query module 870.
[0158] The file receiving module 810 is used to receive the initial query file, which includes the initial query statement.
[0159] The statement parsing module 820 is used to parse the initial query statement and obtain the first parsed character data.
[0160] The statement marking module 830 is used to determine the statement execution mark of the initial query statement based on the preset character format and the first parsed character data;
[0161] Tree building module 840 is used to build a syntax tree based on statement execution markers and first parsed character data to obtain a first syntax tree;
[0162] The connection tagging module 850 is used to perform session connection tagging on the initial query statement according to the first syntax tree to obtain the first connection identifier;
[0163] The statement modification module 860 is used to modify the initial query statement according to the first connection identifier, the statement execution flag and the preset character library to obtain the target query statement;
[0164] The data query module 870 is used to perform data queries based on the first syntax tree and the target query statement.
[0165] It should be noted that the statement query system in this application embodiment is used to implement the statement query method in the above embodiment. The statement query system in this application embodiment corresponds to the aforementioned statement query method. For the specific processing procedure, please refer to the aforementioned statement query method, which will not be repeated here.
[0166] This application also provides a computer device, comprising: at least one memory, at least one processor, and at least one computer program. The at least one computer program is stored in the at least one memory, and the at least one processor executes the at least one computer program to implement any of the statement query methods described in the above embodiments. This computer device can be any smart terminal, including tablet computers, in-vehicle computers, etc.
[0167] Please see Figure 9 , Figure 9 The illustration shows the hardware structure of a computer device according to another embodiment, the computer device comprising:
[0168] The processor 910 can be implemented using a general-purpose central processing unit (CPU), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to achieve the technical solutions provided in the embodiments of this application.
[0169] The memory 920 can be implemented as a read-only memory (ROM), static storage device, dynamic storage device, or random access memory (RAM). The memory 920 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 920 and is called and executed by the processor 910 using the statement query method of the embodiments of this application.
[0170] The input / output interface 930 is used to implement information input and output;
[0171] The communication interface 940 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, Ethernet cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).
[0172] Bus 950 transmits information between various components of the device (e.g., processor 910, memory 920, input / output interface 930, and communication interface 940);
[0173] The processor 910, memory 920, input / output interface 930 and communication interface 940 are connected to each other within the device via bus 950.
[0174] This application also provides a computer-readable storage medium storing a computer program for causing a computer to execute the statement query method described in the above embodiments.
[0175] This application provides a statement query method, system, computer device, and storage medium. By simultaneously matching connection identifiers and variable character names, it can more accurately retrieve corresponding variable values from memory, achieving correct querying of different types of characters in the query statement and improving the reliability of the statement query. Compared to related technologies based on PostgreSQL concurrency testing tools, which can only execute simple and commonly used SQL statements and cannot execute when the SQL statement involves variables, this application can modify the storage and retrieval of variables during the parsing process of the lexical parser and syntax parser. Furthermore, this application modifies the way the executor stores and retrieves SQL variable information, ensuring that variables between each session are independent and do not affect each other, thus improving the flexibility and ease of use of the statement query tool.
[0176] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0177] The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.
[0178] Those skilled in the art will understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of this application, and may include more or fewer steps than shown, or combine certain steps, or different steps.
[0179] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; 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.
[0180] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or suitable combinations thereof.
[0181] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0182] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.
[0183] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of the units described above is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0184] The units described above as separate components may or may not be physically separate. The components shown as units 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 units can be selected to achieve the purpose of this embodiment according to actual needs.
[0185] Furthermore, the functional units in the various embodiments of this application 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 as a software functional unit.
[0186] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0187] The preferred embodiments of the present application have been described above with reference to the accompanying drawings, but this does not limit the scope of the claims of the present application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of the present application shall be within the scope of the claims of the present application.
Claims
1. A statement query method, characterized in that, The method includes: Receive an initial query file, the initial query file including an initial query statement; The initial query statement is parsed to obtain the first parsed character data; The statement execution flag of the initial query statement is determined according to the preset character format and the first parsed character data; wherein, the statement execution flag includes a first execution flag and a second execution flag, the first execution flag is used to indicate that the initial query statement needs to be re-parsed, and the second execution flag is used to indicate that the initial query statement does not need to be re-parsed; The initial query statement is divided according to the statement execution marker to obtain a first query statement marked with the first execution marker and a second query statement marked with the second execution marker. The first parsed character data includes the first character data of the first query statement and the second character data of the second query statement. The first execution marker and the first character data are combined to obtain first marked character data. The second execution marker and the second character data are combined to obtain second marked character data. A first syntax tree is generated based on the first marked character data and the second marked character data. Based on the first syntax tree, the initial query statement is marked with a session connection identifier to obtain a first connection identifier; The initial query statement is modified according to the first connection identifier, the statement execution flag, and the preset character library to obtain the target query statement; Data is queried based on the first syntax tree and the target query statement.
2. The method according to claim 1, characterized in that, The step of determining the statement execution flag of the initial query statement based on the preset character format and the first parsed character data includes: The first parsed character data is processed to extract characters, resulting in the first starting character; The initial query statement is subjected to initial state detection based on the preset starting character and the first starting character to obtain the first statement state, which includes the initial matching state. When the first statement is in the initial matching state, the initial query statement is subjected to character state detection according to the preset character format to obtain the character state, which includes the character existence state. When the character state is the character existence state, the initial query statement is marked as the first execution mark.
3. The method according to claim 1, characterized in that, The preset character library includes candidate character units. The step of modifying the initial query statement according to the first connection identifier, the statement execution flag, and the preset character library to obtain the target query statement includes: Based on the first execution marker, the first syntax tree is used to extract characters to obtain the first marker character data, which includes candidate character names; The first connection identifier of the first query statement is used as a candidate connection identifier, and the target character unit is selected from the candidate character units according to the candidate connection identifier and the candidate character name. The target character unit includes target character data. Based on the target character data, the candidate character names are replaced to obtain the target marker character data; The target query statement is generated based on the target marker character data.
4. The method according to any one of claims 1 to 3, characterized in that, The first syntax tree includes an initial execution node, and the data query based on the first syntax tree and the target query statement includes: The target execution node is selected from the initial execution nodes of the first syntax tree according to the target query statement; The statement execution sequence of the target query statement is determined based on the target execution node; The target query statement is executed according to the statement execution sequence.
5. The method according to any one of claims 1 to 3, characterized in that, Before modifying the initial query statement according to the first connection identifier, the statement execution flag, and the preset character library to obtain the target query statement, the method further includes: Constructing the preset character library specifically includes: Receive an initial character setting file, the initial character setting file including an initial character setting statement, the initial character setting statement including an initial character name and initial character data; The initial character setting statement is parsed to obtain the second parsed character data; The second parsed character data is used to extract characters to obtain the statement end character; The statement type marker of the initial character setting statement is determined based on the preset end character and the statement end character; A second syntax tree is constructed based on the second parsed character data and the statement type marker; The initial character setting statement is processed with a session connection marker to obtain a second connection identifier; Based on the statement type marker, the second connection identifier, the initial character name, and the initial character data are combined to obtain candidate character units; The preset character library is constructed based on the candidate character units.
6. The method according to claim 5, characterized in that, Before extracting characters from the second parsed character data to obtain the statement end character, the construction of the preset character library further includes: The second parsed character data is processed to extract characters, resulting in the second starting character; The initial character setting statement is checked for initial state based on the preset starting character and the second starting character to obtain the second statement state, which includes the statement start non-compliance state. When the second statement is in the initial non-compliance state, a statement type error message is output.
7. A statement query system, characterized in that, The system includes: The file receiving module is used to receive an initial query file, which includes an initial query statement. The statement parsing module is used to parse the initial query statement to obtain the first parsed character data; The statement marking module is used to determine the statement execution mark of the initial query statement according to a preset character format and the first parsed character data; wherein, the statement execution mark includes a first execution mark and a second execution mark, the first execution mark is used to indicate that the initial query statement needs to be re-parsed, and the second execution mark is used to indicate that the initial query statement does not need to be re-parsed; A tree construction module is used to divide the initial query statement according to the statement execution marker to obtain a first query statement marked with the first execution marker and a second query statement marked with the second execution marker. The first parsed character data includes the first character data of the first query statement and the second character data of the second query statement. The module combines the first execution marker and the first character data to obtain first marked character data; combines the second execution marker and the second character data to obtain second marked character data; and generates a first syntax tree based on the first marked character data and the second marked character data. The connection tagging module is used to perform session connection tagging on the initial query statement according to the first syntax tree to obtain a first connection identifier; The statement modification module is used to modify the initial query statement according to the first connection identifier, the statement execution flag and the preset character library to obtain the target query statement; The data query module is used to perform data queries based on the first syntax tree and the target query statement.
8. A computer device, characterized in that, include: At least one memory; At least one processor; At least one computer program; The at least one computer program is stored in the at least one memory, and the at least one processor executes the at least one computer program to perform: The 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 a computer program that is used to cause the computer to execute: The method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
SQL analysis method and SQL analyzer
CN110019291A
Query statement generation method and device based on grammar parse tree, equipment and medium
CN116304231A
