Data query method and device, medium and program product

CN119336790APending Publication Date: 2025-01-21WEICHAI POWER CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411379876.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-30
Publication Date
2025-01-21

AI Technical Summary

Technical Problem

目前针对于xml文件中的sql语句是通过手动的方式添加额外查询条件的,若查询语句中包含多个待查询的数据表,手动添加查询条件容易出错,可能已经逻辑删除的数据也会被查询出来,导致查询错误

Benefits of technology

[0039]维护包含表征未逻辑删除数据对应的配置信息的配置文件,能够在得到sql语句对应的待查询的数据表后,基于配置文件判断待查询的数据表中是否存在未逻辑删除的数据,并在确定存在逻辑删除的数据后,基于配置信息构建附加查询条件,并自动拼接到sql语句中,以实现精准查询;而且,本申请实施例还针对特殊存储结构的数据表以及通用存储结构的数据表分别提供了构建附加查询条件的方法,以实现全面、精准的查询;此外,配置文件可以仅包含特殊存储结构的数据表及其对应的配置信息,以避免配置文件中数据的冗余。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119336790A_ABST
    Figure CN119336790A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of databases, in particular to a data query method and device, a medium and a program product. The method comprises the following steps: analyzing a received structured query language sql statement to obtain at least one sub-query statement; for any one sub-query statement, based on a configuration file, determining whether a to-be-queried data table corresponding to the any one sub-query statement contains logically deleted data or not, and if yes, executing the step 2; if yes, splicing an additional query condition constructed based on configuration information corresponding to the to-be-queried data table into the current query condition of any sub-query statement; and querying the data in the to-be-queried data table by utilizing the spliced query conditions. Through the method, the additional query condition can be automatically spliced behind the sql statement, and the data which are not logically deleted can be quickly and accurately queried.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of database technology, and in particular to a data query method, device, medium and program product. Background Art

[0002] After the data in the database is physically deleted, the deleted data cannot be queried, but the logically deleted data can be queried, and the logically deleted data uses a flag to indicate the deletion status, which facilitates data recovery and management.

[0003] However, when querying data using Structured Query Language (SQL) statements, additional query conditions need to be added to filter out logically deleted data. Currently, additional query conditions are added manually for SQL statements in XML files. If the query statement contains multiple data tables to be queried, manually adding query conditions is prone to errors, and data that may have been logically deleted may also be queried, resulting in query errors. Summary of the invention

[0004] The embodiments of the present application provide a data query method, device, medium and program product, which can automatically splice additional query conditions on the original query conditions to accurately query the data in the data table that has not been logically deleted.

[0005] In a first aspect, an embodiment of the present application provides a data query method, the method comprising:

[0006] Parsing the received structured query language SQL statement to obtain at least one sub-query statement, each sub-query statement includes a query condition and a data table to be queried, the data table to be queried includes multiple table items, and each table item corresponds to multiple data;

[0007] For any sub-query statement, based on the configuration file, determine whether the data table to be queried corresponding to the any sub-query statement contains logically deleted data. If so, splice the additional query conditions constructed based on the configuration information corresponding to the data table to be queried into the current query conditions of the any sub-query statement, wherein the configuration file contains the configuration information corresponding to each data table, and the configuration information represents the table items corresponding to the data in the data table that are not currently logically deleted;

[0008] The data in the data table to be queried is queried using the concatenated query conditions.

[0009] In a possible implementation manner, before parsing the received structured query language SQL statement, the method further includes:

[0010] Detect the type of the received SQL statement;

[0011] If the type of the SQL statement is a query type, it is determined to parse the SQL statement; otherwise, it is determined not to process the SQL statement.

[0012] In a possible implementation manner, the subquery statement includes at least one table name, where the table name represents the name of a data table to be queried;

[0013] The determining, based on the configuration file, whether the to-be-queried data table corresponding to any one of the sub-query statements contains logically deleted data includes:

[0014] For any sub-query statement, obtain the table name in the any sub-query statement, and query the configuration information corresponding to the table name from the configuration file. If the configuration information corresponding to the table name is queried, determine that the data table to be queried corresponding to the any sub-query statement contains logically deleted data;

[0015] If the configuration information corresponding to the table name is not found, it is determined that there is no logically deleted data in the data table to be queried corresponding to any one of the sub-query statements.

[0016] In a possible implementation, the data table includes a data table with a special storage structure and a data table with a general storage structure; the method further includes:

[0017] If the table name corresponding to any of the sub-query statements is not found in the configuration file, determining that the data table corresponding to the table name is a data table of a general storage structure;

[0018] The additional query condition constructed by using the general information is spliced ​​into the current query condition of any one of the sub-query statements, wherein the general information represents the identifier of the data that has not been logically deleted in the data table of the general storage structure.

[0019] In a possible implementation, the parsing of the received structured query language SQL statement to obtain at least one sub-query statement includes:

[0020] Identify the target field in the SQL statement;

[0021] For any target field, the content from the any target field to the last field of the SQL statement is used as a sub-query statement, wherein the sub-query statement corresponding to the front target field in the SQL statement contains the query conditions of the sub-query statement corresponding to the back target field in the SQL statement;

[0022] After obtaining at least one sub-query statement, the method further includes:

[0023] According to the order of the target fields corresponding to the sub-query statements in the SQL statement, each sub-query statement is stored in a pre-built stack.

[0024] In a possible implementation, the current query condition of any sub-query statement is determined in the following manner:

[0025] Reading any one of the sub-query statements from the stack;

[0026] If the any one of the sub-query statements is the first sub-query statement read from the stack, the query condition of the any one of the sub-query statements is used as the current query condition;

[0027] If the any sub-query statement is not the first sub-query statement read from the stack, the original query condition of the any sub-query statement is updated using the current query condition of the last sub-query statement read from the stack to obtain the current query condition of the any sub-query statement.

[0028] In a possible implementation manner, after determining whether the to-be-queried data table corresponding to any one of the sub-query statements contains logically deleted data, the method further includes:

[0029] If it is determined that the data table to be queried corresponding to any sub-query statement does not contain logically deleted data, the data table to be queried is queried using the current query condition.

[0030] In a second aspect, an embodiment of the present application provides a data query device, the device comprising:

[0031] A parsing module is used to parse the received structured query language SQL statement to obtain at least one sub-query statement, each sub-query statement includes a query condition and a data table to be queried, the data table to be queried includes multiple table items, and each table item corresponds to multiple data;

[0032] A splicing module is used to determine, for any sub-query statement, based on a configuration file, whether the data table to be queried corresponding to the any sub-query statement contains logically deleted data, and if so, splice the additional query conditions constructed based on the configuration information corresponding to the data table to be queried into the current query conditions of the any sub-query statement, wherein the configuration file contains configuration information corresponding to each data table, and the configuration information represents the table items corresponding to the data in the data table that are not currently logically deleted;

[0033] The query module is used to query the data in the data table to be queried using the concatenated query conditions.

[0034] In a third aspect, an embodiment of the present application provides an electronic device, the electronic device comprising:

[0035] At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor executes the method as described in the first aspect above.

[0036] In a fourth aspect, an embodiment of the present application provides a computer storage medium, wherein the computer storage medium stores a computer program, and the computer program is used to enable a computer to execute the method in the first aspect as described above.

[0037] In a fifth aspect, an embodiment of the present application provides a computer program product, which implements the method in the first aspect above when the computer program is executed by a processor.

[0038] The data query method provided in the embodiment of the present application has the following beneficial effects:

[0039] Maintaining a configuration file containing configuration information corresponding to non-logically deleted data, after obtaining the data table to be queried corresponding to the SQL statement, it can be determined based on the configuration file whether there is non-logically deleted data in the data table to be queried, and after determining that there is logically deleted data, additional query conditions are constructed based on the configuration information, and automatically spliced ​​into the SQL statement to achieve accurate query; moreover, the embodiment of the present application also provides a method for constructing additional query conditions for data tables with special storage structures and data tables with general storage structures, respectively, to achieve comprehensive and accurate query; in addition, the configuration file can only contain data tables with special storage structures and their corresponding configuration information to avoid redundancy of data in the configuration file. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] Figure 1 A schematic diagram of an application scenario of a data query method according to an exemplary embodiment of the present invention;

[0041] Figure 2 A schematic diagram of a data query method according to an exemplary embodiment of the present invention;

[0042] Figure 3 A schematic diagram of a specific flow chart of a data query method according to an exemplary embodiment of the present invention;

[0043] Figure 4 A schematic diagram of a data query device according to an exemplary embodiment of the present invention;

[0044] Figure 5 The figure is a schematic diagram of an electronic device according to an exemplary embodiment of the present invention. DETAILED DESCRIPTION

[0045] In order to make the purpose, technical scheme and advantages of the present application clearer, the technical scheme in the embodiment of the present application will be clearly and completely described below in conjunction with the drawings in the embodiment of the present application. Obviously, the described embodiment is only a part of the embodiment of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application. In the absence of conflict, the embodiments in the present application and the features in the embodiments can be arbitrarily combined with each other. In addition, although the logical order is shown in the flow chart, in some cases, the steps shown or described can be performed in an order different from that here.

[0046] The acquisition, storage, use, and processing of data in the embodiments of this application comply with the relevant provisions of national laws and regulations.

[0047] First, some concepts involved in the embodiments of the present application are introduced.

[0048] Structured Query Language: It is a special-purpose programming language, a database query and programming language used to access data, query, update and manage database systems; it can also be used as the extension of database script files. Structured Query Language is an advanced non-procedural programming language that allows users to work on high-level data structures. It does not require users to specify the storage method for data, nor does it require users to understand the specific data storage method, so database systems with completely different underlying structures can use the same structured query language as an interface for data input and management. Structured query language statements can be nested, which makes it extremely flexible and powerful.

[0049] Common types of SQL statements include: query type, add type, modify type and delete type. The statements corresponding to query type are also called Data Query Language (DQL), and the statements corresponding to add type, modify type and delete type are also called Data Manipulation Language (DML). For query type, its statement is also called "data retrieval statement", which is used to obtain data from the data table and determine how the data is given in the application. The reserved word select is the most used verb, and other commonly used reserved words include where, order by, groupby and having.

[0050] Where statement: used to filter data that meets specific conditions, also referred to as query conditions in the embodiments of the present application.

[0051] Target field: In the embodiment of the present application, the target field in sql is select.

[0052] Subquery statement: obtained by splitting a SQL statement.

[0053] Configuration file: contains the table name of the data table with a special storage structure and the configuration information corresponding to the data table with a special storage structure. The configuration information represents the table items corresponding to the data in the data table that has not been logically deleted.

[0054] Data table: In the embodiment of the present application, the data table includes a data table of a special storage structure and a data table of a general storage structure. The configuration file may only include the table name of the data table of the special storage structure and its corresponding configuration information (the configuration information of the data table of the special storage structure may also be referred to as a special logical deletion field = a logically undeleted value). The identifier corresponding to the data that has not been logically deleted in the data table of the general storage structure may be general information (also referred to as a general logical deletion field = a logically undeleted value).

[0055] Interceptor: is a technology based on aspect-oriented programming, which can insert custom logic before and after the method execution of the target object. Interceptors can be built through the persistence layer framework (MyBatis). The categories of interceptors can include:

[0056] Executor, intercepts the executor method, which can be used to implement caching, transactions, paging and other functions;

[0057] ParameterHandler: intercepts the parameter processor method, which can be used to convert or encrypt parameters, etc.

[0058] ResultSetHandler: intercepts the result set handler method, which can be used to convert or filter result sets, etc.

[0059] StatementHandler: intercepts the statement processor method, which can be used to modify SQL statements, add parameters, record logs, etc.

[0060] Reflection mechanism: mainly determines the class to which any object belongs at runtime; constructs an object of any class at runtime; determines the member variables and methods of any class at runtime; calls the method of any object at runtime; generates dynamic proxy. In the embodiment of the present application, the sql statement can be obtained through the reflection mechanism MetaObject.forObject.

[0061] The data query method in the embodiment of the present application is described in detail below with reference to the accompanying drawings.

[0062] like Figure 1 The following is an application scenario of a data query method provided by an embodiment of the present application, wherein the application scenario includes an interceptor 101 and at least one SQL statement (such as Figure 1 The sql statements 102_1, sql statement 102_2, ..., sql statement 102_N shown are shown). Among them, the interceptor 101 is used to intercept sql statements, and parse and splice the intercepted sql statements. The interceptor 101 can be built based on the MyBatis framework, and the MyBatis framework can be deployed in a server cluster or distributed system composed of an independent physical server or multiple physical servers, and can also be deployed in a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content distribution networks (Content Delivery Network, CDN), and big data and artificial intelligence platforms. The embodiments of the present application are not specifically limited. In the embodiments of the present application, the sql statements intercepted by the interceptor 101 are query type statements.

[0063] In view of the problem that manually concatenating query conditions in sql statements in xml files is prone to errors, the present application embodiment provides a data query method, such as Figure 2 shown.

[0064] S201: Parse the received structured query language SQL statement to obtain at least one sub-query statement.

[0065] After receiving the sql statement, it is first necessary to determine the type of the sql statement. If the type of the sql statement is a query type, the sql statement is parsed. If the type of the sql statement is not a query type, the subsequent parsing operation is not performed. Specifically, if it is detected that the sql statement contains a "select" field, it can be indicated that the type of the sql statement is a query type. In an embodiment of the present application, the interceptor 101 constructed by MyBatis can be used to detect the type of the sql statement, and the type of the sql statement can be obtained specifically through the CCJSqlParserUtil.parse parser in the interceptor.

[0066] After determining that the received SQL statement is a query type statement, the interceptor 101 may be used to parse the SQL statement, which may be specifically implemented as follows:

[0067] Identify the target field in the SQL statement; for any target field, use the content from the any target field to the last field of the SQL statement as a sub-query statement, wherein the sub-query statement corresponding to the front target field in the SQL statement contains the query conditions of the sub-query statement corresponding to the back target field in the SQL statement.

[0068] Moreover, after obtaining at least one sub-query statement, each sub-query statement is further stored in a pre-built stack according to the sequence of the target fields corresponding to the sub-query statement in the SQL statement.

[0069] For example, interceptor 101 intercepts the following SQL statement:

[0070] Select * from table_a A

[0071] Where id in(select id from table_b B where item_id in(select id fromtable_cC where name like'%wang%'))

[0072] It contains three target fields "select", that is, the subquery statement obtained is:

[0073] The first subquery statement:

[0074] Select * from table_a A

[0075] Where id in(select id from table_b B where item_id in(select id from table_cC where name like'%wang%'));

[0076] The second subquery statement:

[0077] select id from table_b B where item_id in(select id from table_c Cwhere name like'%wang%');

[0078] The third subquery statement:

[0079] select id from table_c C where name like'%wang%'.

[0080] Afterwards, the obtained multiple sub-query statements are put into a stack in the order of the first sub-query statement, the second sub-query statement, and the third sub-query statement, wherein the sub-query statement put into the stack first contains the query condition of the sub-query statement put into the stack later.

[0081] As shown above, each sub-query statement contains a query condition. In an embodiment of the present application, the query condition is the content after the "where" field. For example, the query condition in the first sub-query statement is: Where id in(select id from table_b B where item_id in(select id from table_c C wherename like'%wang%')); the query condition in the second sub-query statement is: where item_id in(select idfrom table_c C where name like'%wang%'); the query condition in the second sub-query statement is: wherename like'%wang%'. The second sub-query statement contains the query condition of the third sub-query statement, and the first sub-query statement contains the query conditions of the second sub-query statement and the third sub-query statement.

[0082] In addition, each subquery statement also includes data tables to be queried, for example, the data tables included in the first subquery statement are table_a A, table_b B, and table_c C; the data tables included in the second subquery statement are table_bB and table_c C; the data table included in the third subquery statement is table_c C. When using sql statements to query data tables, the same data table will not be queried repeatedly because it is included in different subquery statements, that is, the data table to be queried corresponding to the third subquery statement is table_cC, the data table to be queried corresponding to the second subquery statement is table_b B, and the data table to be queried corresponding to the first subquery statement is table_a A.

[0083] The data tables to be queried corresponding to the above SQL statements are table_a A, table_b B, and table_c C. The data table to be queried can contain multiple table items, and each table item corresponds to multiple data.

[0084] S202: For any sub-query statement, based on the configuration file, determine whether the data table to be queried corresponding to the any sub-query statement contains logically deleted data. If so, splice the additional query conditions constructed based on the configuration information corresponding to the data table to be queried into the current query conditions of the any sub-query statement.

[0085] The configuration file contains the table names of multiple data tables and the configuration information corresponding to each table name. The configuration information can be used to construct additional query conditions, as shown in Table 1.

[0086] Table 1

[0087]

[0088]

[0089] In a possible implementation, the value corresponding to the logical deletion field is a logical value, and the SQL operation conditions generated according to the logical deletion field include two categories, one is the condition that the corresponding data item is logically deleted, and the other is the condition that the corresponding data item is not logically deleted. Configuration information 1 in the embodiment of the present application is a logical deletion field, and configuration information 2 is the corresponding logical non-deleted value. Configuration information 1 and configuration information 2 represent the undeleted table items in the data table. In addition, the configuration file can be further stored in the form of a Map, such as {{table_b:deleted1=0},{table_c:null},...,{table_d:deleted2=0}}.

[0090] For any subquery statement, first determine the table name contained in any subquery statement, then query the matching table name in the configuration file as shown in Table 1 or as described above, and determine whether the table name corresponds to the configuration information. If it corresponds to the configuration information, it is determined that there is logically deleted data in the data table corresponding to the table name, that is, it may be necessary to add additional query conditions when querying the table; if the configuration information is empty, it is determined that there is no logically deleted data in the data table corresponding to the table name, that is, it is not necessary to add additional query conditions when querying the table. For example, table_b corresponds to the configuration information, and table_c does not have the corresponding configuration information. Therefore, if you want to query the data in table_b, you need to filter out the logically deleted data. However, if the original query statement contains query conditions for data that are not logically deleted, you do not need to add additional query conditions; if you want to query the data in table_c, you do not need to add additional query conditions.

[0091] In a possible implementation, the configuration file may include a data table of a general storage structure and its configuration information, and a data table of a special storage structure and its configuration information. For the data table of the general storage structure, the corresponding configuration information is the same. For example, the general information del_flag=1 may be used to identify the data in the data table of the general storage structure that has not been logically deleted. Therefore, the configuration file may only include the data table of the special storage structure and its configuration information to avoid data redundancy in the configuration file. In other words, when the table name cannot be queried from the configuration file, the general information del_flag=1 may be directly used as an additional query condition.

[0092] Taking the SQL statement in S201 above as an example, after obtaining the sub-query statements, it is first necessary to determine the data table to be queried in each sub-query statement. Since the multiple sub-query statements obtained are stored in a stack, it is necessary to read the sub-query statements from the stack. Because the stack is first-in-last-out, it is read in the order of the third sub-query statement - the second sub-query statement - the first sub-query statement. When splicing the query conditions of the sub-query statements, it is necessary to splice them in the order of reading. The specific implementation is as follows:

[0093] Reading any one of the sub-query statements from the stack;

[0094] If the any one of the sub-query statements is the first sub-query statement read from the stack, the query condition of the any one of the sub-query statements is used as the current query condition;

[0095] If the any sub-query statement is not the first sub-query statement read from the stack, the original query condition of the any sub-query statement is updated using the current query condition of the last sub-query statement read from the stack to obtain the current query condition of the any sub-query statement.

[0096] Take the multiple sub-query statements in S201 above as an example.

[0097] First, read the third sub-query statement. The data table to be queried contained in the third sub-query statement is table_c. It can be seen from Table 1 that there is no logically deleted data in table_c. Therefore, no additional query condition is added to the query condition of the third sub-query statement, that is, the query condition of the third sub-query statement is where name like'%wang%'.

[0098] Then, the second sub-query statement is read. The data table to be queried contained in the second sub-query statement is table_b. The current query condition of the second sub-query statement is where item_id in (select id from table_c C where name like'%wang%'). It can be seen from Table 1 that there is logically deleted data in table_b. Therefore, an additional query condition is constructed using the configuration information: B.deleted1=0, and then the additional query condition is spliced ​​into the current query condition to obtain the spliced ​​second sub-query statement select id from table_b B where item_id in (selectid from table_c C where name like'%wang%')and B.deleted1=0.

[0099] Finally, read the first subquery statement, and update the original query conditions of the first subquery statement with the concatenated second subquery statement to obtain Select*from table_a A

[0100] Where id in(select id from table_b B where item_id in(select id fromtable_cC where name like'%wang%'))and B.deleted1=0. The data table to be queried in the first subquery statement is table_a, which is not in the configuration file. Therefore, table_a is determined to be a data table with a general storage structure. After the query condition, the preset general information is directly spliced ​​into the current subquery statement to obtain Select*fromtable_a A

[0101] Where id in(select id from table_b B where item_id in(select id from table_cC where name like'%wang%')and B.deleted=0)and A.del_flag=1.

[0102] The entire process of adding additional query conditions does not require developers to pay attention to specific details, thereby decoupling the addition of business and logical deletion fields, avoiding incorrect queries caused by forgetting to add logical deletion field filtering conditions.

[0103] S203: Query the data in the data table to be queried using the concatenated query conditions.

[0104] Through the above analysis and concatenation process of S201 to S202, a new SQL statement is obtained:

[0105] Select * from table_a A

[0106] Where id in(select id from table_b B where item_id in(select id fromtable_cC where name like'%wang%')and B.deleted=0)and A.del_flag=1. Then use the new SQL statement to query the data in the database that has not been logically deleted.

[0107] The following is based on Figure 3 A data query method provided in an embodiment of the present application is described in detail.

[0108] S301: Detect the type of the received SQL statement. In the embodiment of the present application, the SQL statement can be obtained through the reflection mechanism MetaObject.forObject in the interceptor 101, and then the type of the SQL statement is obtained through the CCJSqlParserUtil.parse parser in the interceptor 101;

[0109] S302: Determine whether it is a query type, that is, determine whether it is a Select type. If so, execute S303; otherwise, execute S312;

[0110] S303: Parse the SQL statement to obtain at least one sub-query statement. Specifically, the SQL statement may be parsed by regular expressions, as described in the implementation of S201 above, which will not be described in detail here.

[0111] S304: Put the sub-query statements into the structure stack in sequence and traverse them;

[0112] S305: Obtain the table names of all data tables in each sub-query statement, as well as the query conditions. Specifically, the table name and alias, as well as the where statement, can be obtained through the relevant methods of the parser plainSelect in the interceptor 101. For example, if the SQL statement is select * from table_A, then the alias of the table is table_A. If it is select * from table_Aa, then the alias of the table is a.

[0113] S306: Determine whether the table name in the subquery statement is in the configuration file. If so, execute S308; otherwise, execute S307;

[0114] S307: splicing the additional query condition constructed using the general information into the current query condition, and then executing S312;

[0115] S308: Determine whether it corresponds to the configuration information, that is, determine whether the table name corresponds to the configuration information in the configuration file. If so, execute S309, otherwise execute S311;

[0116] S309: Determine whether the query condition contains additional query conditions. If so, execute S311, otherwise execute S310; after parsing the SQL statement, it is determined that the original query condition already contains the additional query condition, which means that the current SQL statement queries the data that has not been logically deleted. At this time, there is no need to add additional query conditions.

[0117] S310: splicing the additional query condition constructed using the configuration information into the current query condition, and then executing S312;

[0118] S311: No additional query conditions are added, and then S312 is executed;

[0119] S312: Execute SQL statements.

[0120] The process of splicing additional query conditions is as described in the implementation of S202 above, and will not be repeated here.

[0121] An embodiment of the present application provides a data query method, which can automatically splice the filtering conditions of the logical deletion identifier after the SQL statement. The developer does not need to write the filtering conditions separately in each SQL statement. It is compatible with the mybatis-plus framework and also supports the SQL statements in the XML file. In other words, it supports querying the data in multiple data tables at the same time, which can meet the developer's query for the data that is logically deleted. In addition, it can also be flexibly configured, and there is no mandatory requirement for the field name of the logically deleted field.

[0122] Based on the same inventive concept, the present application embodiment provides a data query device, such as Figure 4 As shown, the device comprises:

[0123] The parsing module 401 is used to parse the received structured query language SQL statement to obtain at least one sub-query statement, each of which contains a query condition and a data table to be queried, and the data table to be queried contains multiple table items, each of which corresponds to multiple data;

[0124] The splicing module 402 is used to determine, for any sub-query statement, based on a configuration file, whether the data table to be queried corresponding to the any sub-query statement contains logically deleted data, and if so, splice the additional query condition constructed based on the configuration information corresponding to the data table to be queried into the current query condition of the any sub-query statement, wherein the configuration file contains configuration information corresponding to each data table, and the configuration information represents the table items corresponding to the data in the data table that are not currently logically deleted;

[0125] The query module 403 is used to query the data in the data table to be queried using the concatenated query conditions.

[0126] In a possible implementation, the device further includes a detection module, which is used to: detect the type of the received SQL statement;

[0127] If the type of the SQL statement is a query type, it is determined to parse the SQL statement; otherwise, it is determined not to process the SQL statement.

[0128] In a possible implementation manner, the subquery statement includes at least one table name, where the table name represents the name of a data table to be queried;

[0129] The splicing module 402 is used for:

[0130] For any sub-query statement, obtain the table name in the any sub-query statement, and query the configuration information corresponding to the table name from the configuration file. If the configuration information corresponding to the table name is queried, determine that the data table to be queried corresponding to the any sub-query statement contains logically deleted data;

[0131] If the configuration information corresponding to the table name is not found, it is determined that there is no logically deleted data in the data table to be queried corresponding to any one of the sub-query statements.

[0132] In a possible implementation, the data table includes a data table with a special storage structure and a data table with a general storage structure;

[0133] The splicing module 402 is also used for:

[0134] When it is determined that the table name corresponding to any one of the sub-query statements is not found in the configuration file, determining that the data table corresponding to the table name is a data table of a general storage structure;

[0135] The additional query condition constructed by using the general information is spliced ​​into the current query condition of any one of the sub-query statements, wherein the general information represents the identifier of the data that has not been logically deleted in the data table of the general storage structure.

[0136] In a possible implementation, the parsing module 401 is used to:

[0137] Identify the target field in the SQL statement;

[0138] For any target field, the content from the any target field to the last field of the SQL statement is used as a sub-query statement, wherein the sub-query statement corresponding to the front target field in the SQL statement contains the query conditions of the sub-query statement corresponding to the back target field in the SQL statement;

[0139] The device also includes a storage module for:

[0140] According to the order of the target fields corresponding to the sub-query statements in the SQL statement, each sub-query statement is stored in a pre-built stack.

[0141] In a possible implementation, the splicing module 402 is used to:

[0142] Reading any one of the sub-query statements from the stack;

[0143] If the any one of the sub-query statements is the first sub-query statement read from the stack, the query condition of the any one of the sub-query statements is used as the current query condition;

[0144] If the any sub-query statement is not the first sub-query statement read from the stack, the original query condition of the any sub-query statement is updated using the current query condition of the last sub-query statement read from the stack to obtain the current query condition of the any sub-query statement.

[0145] In a possible implementation manner, after determining whether the to-be-queried data table corresponding to any one of the sub-query statements contains logically deleted data, the concatenation module 401 is further configured to:

[0146] When it is determined that the data table to be queried corresponding to any sub-query statement does not contain logically deleted data, the data table to be queried is queried using the current query condition.

[0147] Based on the same inventive concept, an embodiment of the present application provides an electronic device, the device comprising:

[0148] At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute any data query method provided in the embodiments of the present application.

[0149] Refer to the following Figure 5 An electronic device 50 according to this embodiment of the present application will be described. Figure 5 The electronic device 50 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0150] like Figure 5 As shown, the electronic device 50 is in the form of a general electronic device. The components of the electronic device 50 may include but are not limited to: at least one processor 51, at least one memory 52, and a bus 53 connecting different system components (including the memory 52 and the processor 51).

[0151] The processor 51 is used to read and execute instructions in the memory 52, so that the at least one processor can execute a data query method provided by the above embodiment.

[0152] Bus 53 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, a processor or local bus using any of a variety of bus architectures.

[0153] The memory 52 may include a readable medium in the form of a volatile memory, such as a random access memory (RAM) 521 and / or a cache memory 522 , and may further include a read-only memory (ROM) 523 .

[0154] The memory 52 may also include a program / utility 525 having a set (at least one) of program modules 524, such program modules 524 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.

[0155] The electronic device 50 may also communicate with one or more external devices 54 (e.g., keyboards, pointing devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 50, and / or may communicate with any device that enables the electronic device 50 to communicate with one or more other electronic devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 55. Furthermore, the electronic device 50 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter 56. As shown, the network adapter 56 communicates with other modules for the electronic device 50 via a bus 53. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 50, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0156] In some possible implementations, various aspects of a data query method provided by the present application may also be implemented in the form of a program product, which includes program code. When the program product is run on a computer device, the program code is used to enable the computer device to execute the steps of a data query method according to various exemplary implementations of the present application described above in this specification.

[0157] In addition, the present application also provides a computer-readable storage medium, wherein the computer storage medium stores a computer program, wherein the computer program is used to enable a computer to execute any of the methods described in the above embodiments.

[0158] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0159] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0160] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.

[0161] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. A data query method, characterized in that: The method comprises: Parsing the received structured query language SQL statement to obtain at least one sub-query statement, each sub-query statement includes a query condition and a data table to be queried, the data table to be queried includes multiple table items, and each table item corresponds to multiple data; For any sub-query statement, based on the configuration file, determine whether the data table to be queried corresponding to the any sub-query statement contains logically deleted data. If so, splice the additional query conditions constructed based on the configuration information corresponding to the data table to be queried into the current query conditions of the any sub-query statement, wherein the configuration file contains the configuration information corresponding to each data table, and the configuration information represents the table items corresponding to the data in the data table that are not currently logically deleted; The data in the data table to be queried is queried using the concatenated query conditions.

2. The method according to claim 1, characterized in that Before parsing the received structured query language SQL statement, the method further includes: Detect the type of the received SQL statement; If the type of the SQL statement is a query type, it is determined to parse the SQL statement; otherwise, it is determined not to process the SQL statement.

3. The method according to claim 1, characterized in that The subquery statement includes at least one table name, where the table name represents the name of the data table to be queried; The determining, based on the configuration file, whether the to-be-queried data table corresponding to any one of the sub-query statements contains logically deleted data includes: For any sub-query statement, obtain the table name in the any sub-query statement, and query the configuration information corresponding to the table name from the configuration file. If the configuration information corresponding to the table name is queried, determine that the data table to be queried corresponding to the any sub-query statement contains logically deleted data; If the configuration information corresponding to the table name is not found, it is determined that there is no logically deleted data in the data table to be queried corresponding to any one of the sub-query statements.

4. The method according to claim 3, characterized in that The data table includes a data table with a special storage structure and a data table with a general storage structure; the method further includes: If the table name corresponding to any of the sub-query statements is not found in the configuration file, determining that the data table corresponding to the table name is a data table of a general storage structure; The additional query condition constructed by using the general information is spliced ​​into the current query condition of any one of the sub-query statements, wherein the general information represents the identifier of the data that has not been logically deleted in the data table of the general storage structure.

5. The method according to claim 1, characterized in that The step of parsing the received structured query language SQL statement to obtain at least one sub-query statement includes: Identify the target field in the SQL statement; For any target field, the content from the any target field to the last field of the SQL statement is used as a sub-query statement, wherein the sub-query statement corresponding to the first target field in the SQL statement contains the query conditions of the sub-query statement corresponding to the last target field in the SQL statement; After obtaining at least one sub-query statement, the method further includes: According to the order of the target fields corresponding to the sub-query statements in the SQL statement, each sub-query statement is stored in a pre-built stack.

6. The method according to claim 5, characterized in that Determine the current query condition of any subquery statement in the following ways: Reading any one of the sub-query statements from the stack; If the any one of the sub-query statements is the first sub-query statement read from the stack, the query condition of the any one of the sub-query statements is used as the current query condition; If the any sub-query statement is not the first sub-query statement read from the stack, the original query condition of the any sub-query statement is updated using the current query condition of the last sub-query statement read from the stack to obtain the current query condition of the any sub-query statement.

7. The method according to any one of claims 1 to 6, characterized in that: After determining whether the to-be-queried data table corresponding to any one of the sub-query statements contains logically deleted data, the method further includes: If it is determined that the data table to be queried corresponding to any sub-query statement does not contain logically deleted data, the data table to be queried is queried using the current query condition.

8. An electronic device, characterized in that: The electronic device comprises: At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor so that the at least one processor executes a method as claimed in any one of claims 1 to 7.

9. A computer storage medium, characterized in that: The computer storage medium stores a computer program, and the computer program is used to make a computer execute any one of the methods according to claims 1-7.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.