A method, device and apparatus for directly transferring context parameters to SQL statements

The interceptor intercepts user requests and parses the user's unique identifier, and directly injects user information into SQL statements, solving the problems of context parameter delivery complexity and database compatibility, realizing dynamic database query and operation, and improving business flexibility and security.

CN119739737BActive Publication Date: 2025-08-22BEIJING INSIGHT NETWORK CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510245394.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-04
Publication Date
2025-08-22
Estimated Expiration
2045-03-04

AI Technical Summary

Technical Problem

In the prior art, context parameters are complicated when passed to SQL statements and are limited by database support, resulting in complex processing and compatibility issues of SQL statements.

Method used

By using the UserInterceptorHandler interceptor to intercept user requests, parse user unique identifier, obtain user-related information and store it in inheritableThreadLocals variable, rewrite the Intercept method based on the user-defined interceptor MybatisSqlParamInterceptor, and directly inject user information into SQL statements.

Benefits of technology

Simplifies SQL statement processing, improves business flexibility and security, avoids data inconsistency caused by manual parameters, and adapts to different database platforms.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119739737B_ABST
    Figure CN119739737B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, device and equipment for directly passing context parameters into SQL statements, and relates to the technical field of database query and operation. The method is to use an interceptor to intercept all user requests after obtaining a user-defined entity, a context parameter key and a method for passing user-related information, and parse the interception result to obtain a unique user identifier, then access the database based on the identifier to obtain user-related information, and call a setting method to store the user-related information into a variable, and then rewrite the Intercept method based on the user-defined interceptor. Finally, in all SQL statements involving context parameters, use the passing-in method to obtain any user-related information and pass it into the SQL statement. This can meet the demand for dynamically passing context parameters in database queries and operations, simplify SQL statement processing, and no longer be restricted by the database, thereby improving the flexibility and security of the business.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of database query and operation, and particularly relates to a method, apparatus and device for directly transmitting context parameters to SQL statements. Background Art

[0002] Currently, in existing database query and operation technologies, the common way to pass context parameters to SQL (Structured Query Language, a database query and programming language used to access data and query, update, and manage relational database systems) statements is to use placeholders or bind variables. Although these placeholders can be specified in SQL statements and replaced by parameters during execution, there are also the following problems: (1) SQL statement processing is complex, that is, if complex SQL logic is involved, using placeholders or bind variables may require more work to handle parameter passing and replacement; (2) It is limited by database support, that is, different database management systems have different levels of support for placeholders and bind variables, so you may need to pay attention to compatibility issues when crossing database platforms. Summary of the Invention

[0003] The purpose of the present invention is to provide a method, apparatus, computer device, computer-readable storage medium and computer program product for directly passing context parameters to SQL statements, so as to solve the problems of complex SQL statement processing and database support limitations in existing context parameter passing solutions.

[0004] In order to achieve the above object, the present invention adopts the following technical solutions:

[0005] In a first aspect, a method for directly passing context parameters into an SQL statement is provided, comprising:

[0006] Get a user-defined entity, a context parameter key, and a method for passing user-related information, where the entity contains attributes for inheritableThreadLocals variables and methods for setting and getting context parameter keys;

[0007] Use the UserInterceptorHandler interceptor to intercept all user requests, parse the interception results to obtain the user's unique identifier, and then access the database based on the user's unique identifier to obtain user-related information pre-stored in the database and bound to the user's unique identifier. Finally, call the method in the entity that sets the context parameter key to store the user-related information in the inheritableThreadLocals variable.

[0008] Rewrite the Intercept method based on the user-defined interceptor MybatisSqlParamInterceptor;

[0009] In all SQL statements involving context parameters, the method for implementing the input of user-related information is used to obtain any user-related information and input it into the SQL statement.

[0010] Based on the above invention content, a new solution is provided for directly passing context parameters into SQL statements to realize dynamic database queries and operations, that is, after obtaining the user-defined entity, context parameter key and the method for implementing the user-related information input, an interceptor is used to intercept all user requests, and the interception result is parsed to obtain the user's unique identifier, and then the database is accessed according to the identifier to obtain the user-related information, and the setting method is called to store the user-related information into a variable, and then the Intercept method is rewritten based on the user-defined interceptor. Finally, in all SQL statements involving context parameters, the input method is used to obtain any user-related information and pass it into the SQL statement. This can meet the demand for dynamically passing context parameters in database queries and operations, simplify SQL statement processing, and no longer be restricted by the database, improve business flexibility and security, and facilitate practical application and promotion.

[0011] In one possible design, before accessing the database according to the user unique identifier to obtain user-related information pre-stored in the database and stored in association with the user unique identifier, the method further includes:

[0012] After the user logs in, all information related to the user is stored in the database, wherein all information includes the user's name, user account, user gender and / or user authority.

[0013] In a possible design, the database uses a Redis database.

[0014] In a possible design, the Intercept method is rewritten based on the user-defined interceptor MybatisSqlParamInterceptor, including:

[0015] Get the parameter array in the target method intercepted by the user-defined interceptor MybatisSqlParamInterceptor, where the parameter array contains all the parameters required by the target method;

[0016] Extracting the first parameter from the parameter array and converting it into a MappedStatement object, wherein the MappedStatement object contains relevant information required to execute the SQL statement;

[0017] Extract the second parameter from the parameter array and convert it into a Map type, and inject the user information into the SQL statement being compiled;

[0018] The second parameter in the parameter array is modified to the Map type, and then the subsequent interceptor chain and SQL operation are continued.

[0019] In one possible design, user information is injected into the SQL statement being compiled, including:

[0020] Injecting common context parameters into the SQL statement being compiled;

[0021] The method in the entity for obtaining the context parameter key is called to store the user information into the Map type.

[0022] In one possible design, injecting user information into the SQL statement being compiled also includes:

[0023] The creation time, modification time and / or operator information are maintained in the Map type.

[0024] In a second aspect, a device for directly passing context parameters to SQL statements is provided, comprising a definition content acquisition unit, a request interception processing unit, a method rewriting processing unit, and a user information input unit, which are sequentially connected in communication;

[0025] The definition content acquisition unit is used to obtain user-defined entities, context parameter keys, and methods for implementing user-related information input, wherein the entity includes attributes of inheritableThreadLocals variables and methods for setting and obtaining context parameter keys;

[0026] The request interception processing unit is used to intercept all user requests using the UserInterceptorHandler interceptor, parse the interception results to obtain the user's unique identifier, then access the database based on the user's unique identifier to obtain user-related information pre-stored in the database and bound to the user's unique identifier, and finally call the method in the entity for setting the context parameter key to store the user-related information into the inheritableThreadLocals variable;

[0027] The method rewriting processing unit is used to rewrite the Intercept method based on the user-defined interceptor MybatisSqlParamInterceptor;

[0028] The user information input unit is used to obtain any user-related information and input it into the SQL statement using the method for implementing user-related information input in all SQL statements that require context parameters.

[0029] In a third aspect, the present invention provides a computer device comprising a memory, a processor, and a transceiver communicatively connected in sequence, wherein the memory is used to store a computer program, the transceiver is used to send and receive messages, and the processor is used to read the computer program and execute the method of directly passing context parameters into an SQL statement as described in the first aspect or any possible design of the first aspect.

[0030] In a fourth aspect, the present invention provides a computer-readable storage medium having instructions stored thereon. When the instructions are executed on a computer, the method of directly passing context parameters to an SQL statement as described in the first aspect or any possible design of the first aspect is executed.

[0031] In a fifth aspect, the present invention provides a computer program product, comprising a computer program or instructions, which, when executed by a computer, implements the method of directly passing context parameters into an SQL statement as described in the first aspect or any possible design of the first aspect.

[0032] Beneficial effects of the above scheme:

[0033] (1) The present invention creatively provides a new solution for directly passing context parameters into SQL statements to realize dynamic database query and operation. That is, after obtaining the user-defined entity, context parameter key and the method for implementing the user-related information input, an interceptor is used to intercept all user requests, and the interception result is parsed to obtain the user's unique identifier. Then, the database is accessed according to the identifier to obtain the user's related information, and the setting method is called to store the user-related information into a variable. Then, the Intercept method is rewritten based on the user-defined interceptor. Finally, in all SQL statements involving context parameters, the input method is used to obtain any user-related information and input the SQL statement. In this way, the demand for dynamic transmission of context parameters in database query and operation can be met, SQL statement processing can be simplified and no longer restricted by the database, the flexibility and security of the business can be improved, and practical application and promotion can be facilitated.

[0034] (2) Using custom interceptors to inject context parameters can provide greater flexibility and code maintainability, making the parameter passing process more concise and convenient;

[0035] (3) It has higher flexibility, that is, through custom interceptors, the parameter injection process can be flexibly controlled according to specific business needs to adapt to different scenarios and needs;

[0036] (4) Reduce code intrusion, that is, encapsulate the parameter injection logic in a custom interceptor, which can reduce the redundant code related to parameter passing in the business code;

[0037] (5) It can avoid manually passing context data every time the MyBatis method is called, simplifying code writing;

[0038] (6) Ensure data consistency. That is, since the context data is directly passed to the SQL statement, data consistency is guaranteed, avoiding the risk of data inconsistency caused by manual parameter passing. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0040] Figure 1 A flowchart of a method for directly passing context parameters to SQL statements provided in an embodiment of the present application.

[0041] Figure 2 A flowchart of rewriting and implementing the Intercept method provided in an embodiment of the present application.

[0042] Figure 3 A flowchart of the user information injection SQL statement provided in an embodiment of the present application.

[0043] Figure 4 A schematic diagram of the structure of an apparatus for directly transmitting context parameters to SQL statements provided in an embodiment of the present application.

[0044] Figure 5 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0045] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the present invention will be briefly introduced below in conjunction with the drawings and the description of the embodiments or the prior art. Obviously, the following description of the structures of the drawings is only some embodiments of the present invention. For those skilled in the art, other embodiments can be obtained based on these embodiments without creative work. It should be noted that the description of these embodiments is used to help understand the present invention, but does not constitute a limitation of the present invention.

[0046] It should be understood that although the terms first, second, etc. may be used herein to describe various objects, these objects should not be limited by these terms. These terms are merely used to distinguish one object from another. For example, a first object can be referred to as a second object, and similarly, a second object can be referred to as a first object without departing from the scope of the exemplary embodiments of the present invention.

[0047] It should be understood that the term "and / or" that may appear in this document is merely a description of the association relationship between associated objects, indicating that there may be three relationships. For example, A and / or B can indicate three situations: A exists alone, B exists alone, or A and B exist at the same time. For another example, A, B and / or C can indicate the existence of any one of A, B and C or any combination of them. The term " / and" that may appear in this document describes another type of association object relationship, indicating that there may be two relationships. For example, A / and B can indicate two situations: A exists alone or A and B exist at the same time. In addition, the character " / " that may appear in this document generally indicates that the previous and next associated objects are in an "or" relationship.

[0048] Example

[0049] like Figure 1 As shown, the method for directly passing context parameters to SQL statements provided in the first aspect of this embodiment can be, but is not limited to, executed by a computer device with certain computing resources, such as a cloud server, a personal computer (PC, a multi-purpose computer with a size, price, and performance suitable for personal use; desktops, laptops, small laptops, tablets, and ultrabooks are all personal computers), a smart phone, a personal digital assistant (PDA), or a wearable device. Figure 1 As shown, the method for directly transmitting context parameters to SQL statements may include, but is not limited to, the following steps S1 to S4.

[0050] S1. Obtain user-defined entities, context parameter keys, and methods for implementing user-related information input, wherein the entities include but are not limited to attributes of inheritableThreadLocals variables and methods for setting and obtaining context parameter keys.

[0051] In step S1, the entity (Context) refers to one of the main components used to manage entity objects when accessing data using Entity Framework (i.e., Entity Framework, an object-relational mapping tool launched by Microsoft that allows developers to operate databases in an object-oriented manner; context is one of the core concepts in Entity Framework, which provides a simple and powerful way to access data by mapping the relationship between entity classes and database tables). It acts as a bridge between the application and the database, responsible for tracking the status of entity objects, performing database operations, and managing data changes. In the entity, the inheritableThreadLocals variable is an existing term, which is specifically represented by InheritableThreadLocal <Map<String,Object> >, where Map<String,Object> Is a generic type that represents a collection of key-value pairs, its key is a string type (String), and its value can be any object type (Object). ThreadLocalMap (i.e. Map<String,Object> ) is stored in the inheritableThreadLocals variable of Thread. At the same time, if a new thread needs to be opened under the current main thread, and the inheritableThreadLocals variable exists in the main thread, the new thread will copy the value held by the inheritableThreadLocals variable in the main thread to the inheritableThreadLocals variable of the new thread, similar to the child thread inheriting the inheritableThreadLocals variable of the parent thread. In addition, the entity, the context parameter key and the method for implementing the input of user-related information can be specifically defined by the user through conventional human-computer interaction. The context parameter key is used for subsequent acquisition of specified information through this key in the context. For example, all user information can be uniformly placed in the environment variable $User. This environment variable $User is a key that can be customized in advance by the user. The user-related information includes but is not limited to user name, user account, user gender and / or user permissions.

[0052] S2. Use the UserInterceptorHandler interceptor to intercept all user requests, parse the interception results to obtain the user's unique identifier, and then access the database based on the user's unique identifier to obtain user-related information pre-stored in the database and bound to the user's unique identifier. Finally, call the method in the entity for setting the context parameter key to store the user-related information into the inheritableThreadLocals variable.

[0053] In step S2, the UserInterceptorHandler interceptor is a custom interceptor processor used to intercept user-related requests and process them; in the Spring framework, you can create your own interceptor by implementing the HandlerInterceptor interface. The user unique identifier can specifically include, but is not limited to, the user name and / or user account, etc. The database can specifically include, but is not limited to, Redis (RemoteDictionary Server, i.e., remote dictionary service, is an open source log-type, Key-Value database written in ANSI C language, supporting the network, memory-based or persistent, and providing APIs in multiple languages) database. The method for setting the context parameter key is specifically used to set the context parameter key, and then store the context parameter key and the user-related information used as the context parameter (which is also used as the value) as a pair of key values ​​in the Map<String,Object> In addition, before accessing the database based on the user's unique identifier to obtain user-related information pre-stored in the database and stored in conjunction with the user's unique identifier, the method further includes, but is not limited to: storing all information related to the user in the database after the user logs in, wherein all information includes but is not limited to the user's name, user account, user gender and / or user permissions, etc. (of course, customized additions can also be made based on the actual situation of the login system).

[0054] S3. Rewrite the Intercept method based on the user-defined interceptor MybatisSqlParamInterceptor.

[0055] In step S3, the user-defined interceptor MybatisSqlParamInterceptor is used to intercept the target method during the database query and operation process to obtain the parameter array of the target method and rewrite the Intercept method based on the parameter array. It can be based on the Mybatis persistence layer framework (which is an open source persistence layer framework that can simply encapsulate JDBC, but it is not a complete object-relational mapping and cannot be adapted without the database) and the conventional definition of the human-computer delivery method. The Intercept method is mainly used for aspect-oriented programming (AOP), which can enhance the program without modifying the source code. It is mainly implemented in Java by implementing the Interceptor interface and can be applied to various scenarios, including security checks, logging, and transaction management. In this embodiment, the rewritten Intercept method is called before the SQL statement is executed. That is, if parameter information (such as the user information mentioned above) is to be used in the SQL statement, the user information can be assigned to the SQL statement in advance through the rewritten Intercept method, so that the user information can be used in the SQL statement later. Specifically, such as Figure 2 As shown, the Intercept method is rewritten based on the user-defined interceptor MybatisSqlParamInterceptor, including but not limited to the following steps S31 to S34.

[0056] S31. Obtain a parameter array in the target method intercepted by the user-defined interceptor MybatisSqlParamInterceptor, wherein the parameter array includes but is not limited to all parameters required by the target method.

[0057] In step S31, the actual parameters of the target method when it is called can be obtained through the line of code "Object[] args = invocation.getArgs()" (the strings in this code represent existing knowledge, such as the invocation object and the getArgs method). These parameters can then be used for various custom processing, such as performing unified format verification or encryption on the incoming parameters, or determining whether the parameters comply with expected business rules. The following is a simple example: recording the parameters when intercepting the Executor executing the query method (i.e., the target method) (this is just a demonstration; actual use requires configuration in the MyBatis interceptor chain and other related environments).

[0058] S32. Extract the first parameter from the parameter array and convert it into a MappedStatement object, wherein the MappedStatement object includes but is not limited to relevant information required to execute the SQL statement.

[0059] In step S32, the first parameter extraction and object conversion can be implemented specifically through the line of code "MappedStatement ms=(MappedStatement) args[0]".

[0060] S33. Extract the second parameter from the parameter array and convert it into a Map type, while injecting the user information into the SQL statement being compiled.

[0061] In step S33, the second parameter can be extracted by the line of code "Object parameter = args[1]". The Map type is a key-value pair type so that the value can be accessed by the key, that is, the Map in the inheritableThreadLocals variable<String,Object> In programming, the Map type is often called an associative array or dictionary, whose elements consist of unique keys and related values. The corresponding values ​​can be quickly found, inserted, and deleted through the key. ‌Specifically, Figure 3 As shown, injecting user information into the SQL statement being compiled includes but is not limited to the following steps S331 to S332.

[0062] S331. Inject common context parameters into the SQL statement being compiled.

[0063] In step S331, the public context parameters specifically include but are not limited to user information customized by the user in the environment variable $User (after the user logs into the system, the user information can be queried and stored in the environment variable $User. All context parameters are as described above. When the user needs certain information, the user can customize the corresponding parameters).

[0064] S332. Call the method in the entity for obtaining the context parameter key to store the user information into the Map type.

[0065] After step S332, information such as creation time, modification time and / or operator information may also be maintained in the Map type.

[0066] S34. Modify the second parameter in the parameter array to the Map type, and then continue to execute subsequent interceptor chains and SQL operations.

[0067] In step S34, the second parameter is modified by the line "args[1] = parameter" so that these parameters can be used directly in subsequent SQL statements without having to rewrite these common parameters each time a SQL statement is written. The subsequent interceptor chain and SQL operations can be continued by calling "invocation.proceed()".

[0068] S4. In all SQL statements involving context parameters, use the method for implementing the input of user-related information to obtain any user-related information and input it into the SQL statement.

[0069] In step S4, since the parameter object has been modified before, after obtaining data from this object, the required information can be directly obtained in the SQL statement through the #{$User.} method.

[0070] Therefore, based on the method of directly passing context parameters into SQL statements described in the aforementioned steps S1 to S4, a new solution is provided for directly passing context parameters into SQL statements to realize dynamic database queries and operations, that is, after obtaining the user-defined entity, context parameter key and the method for implementing the user-related information input, an interceptor is used to intercept all user requests, and the interception result is parsed to obtain the user's unique identifier, and then the database is accessed according to the identifier to obtain user-related information, and the setting method is called to store the user-related information into a variable, and then the Intercept method is rewritten based on the user-defined interceptor. Finally, in all SQL statements involving context parameters, the input method is used to obtain any user-related information and pass it into the SQL statement. This can meet the demand for dynamically passing context parameters in database queries and operations, simplify SQL statement processing, and no longer be restricted by the database, improve business flexibility and security, and facilitate practical application and promotion.

[0071] like Figure 4 As shown, the second aspect of this embodiment provides a virtual device for implementing the method of directly passing context parameters to SQL statements described in the first aspect, comprising a definition content acquisition unit, a request interception processing unit, a method rewriting processing unit, and a user information input unit that are sequentially communicatively connected;

[0072] The definition content acquisition unit is used to obtain user-defined entities, context parameter keys, and methods for implementing user-related information input, wherein the entity includes attributes of inheritableThreadLocals variables and methods for setting and obtaining context parameter keys;

[0073] The request interception processing unit is used to intercept all user requests using the UserInterceptorHandler interceptor, parse the interception results to obtain the user's unique identifier, then access the database based on the user's unique identifier to obtain user-related information pre-stored in the database and bound to the user's unique identifier, and finally call the method in the entity for setting the context parameter key to store the user-related information into the inheritableThreadLocals variable;

[0074] The method rewriting processing unit is used to rewrite the Intercept method based on the user-defined interceptor MybatisSqlParamInterceptor;

[0075] The user information input unit is used to obtain any user-related information and input it into the SQL statement using the method for implementing user-related information input in all SQL statements that require context parameters.

[0076] The working process, working details and technical effects of the aforementioned device provided in the second aspect of this embodiment can be referred to the method for directly transferring context parameters to SQL statements described in the first aspect, and will not be repeated here.

[0077] like Figure 5 As shown, a third aspect of this embodiment provides a computer device for executing the method for directly transferring context parameters to SQL statements as described in the first aspect, comprising a memory, a processor, and a transceiver communicatively connected in sequence, wherein the memory is used to store a computer program, the transceiver is used to send and receive messages, and the processor is used to read the computer program and execute the method for directly transferring context parameters to SQL statements as described in the first aspect. Specifically, the memory may include, but is not limited to, random-access memory (RAM), read-only memory (ROM), flash memory, first-input-first-output (FIFO), and / or first-input-last-output (FILO) memory, etc.; the processor may include, but is not limited to, a microprocessor from the STM32F105 series. Furthermore, the computer device may include, but is not limited to, a power module, a display screen, and other necessary components.

[0078] The working process, working details and technical effects of the aforementioned computer device provided in the third aspect of this embodiment can be referred to the method for directly transferring context parameters to SQL statements described in the first aspect, and will not be repeated here.

[0079] A fourth aspect of this embodiment provides a computer-readable storage medium storing instructions including the method for implementing the method for directly passing context parameters to SQL statements as described in the first aspect. Specifically, the computer-readable storage medium stores instructions that, when executed on a computer, execute the method for implementing the method for directly passing context parameters to SQL statements as described in the first aspect. The computer-readable storage medium refers to a data storage medium and may include, but is not limited to, a floppy disk, an optical disk, a hard disk, a flash memory, a USB flash drive, and / or a memory stick. The computer may be a general-purpose computer, a dedicated computer, a computer network, or other programmable device.

[0080] The working process, working details and technical effects of the aforementioned computer-readable storage medium provided in the fourth aspect of this embodiment can be referred to the method for directly transferring context parameters to SQL statements as described in the first aspect, and will not be repeated here.

[0081] A fifth aspect of this embodiment provides a computer program product, including a computer program or instructions. When executed by a computer, the computer program or instructions implement the method for directly passing context parameters to SQL statements as described in the first aspect. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device.

[0082] Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention shall be included in the scope of protection of the present invention.

Claims

1. A method for directly passing context parameters to SQL statements, characterized in that: include: Get a user-defined entity, a context parameter key, and a method for passing user-related information, where the entity contains attributes for inheritableThreadLocals variables and methods for setting and getting context parameter keys; Use the UserInterceptorHandler interceptor to intercept all user requests, parse the interception results to obtain the user's unique identifier, and then access the database based on the user's unique identifier to obtain user-related information pre-stored in the database and bound to the user's unique identifier. Finally, call the method in the entity that sets the context parameter key to store the user-related information in the inheritableThreadLocals variable. Rewrite the Intercept method based on the user-defined interceptor MybatisSqlParamInterceptor, specifically including: obtaining the parameter array in the target method intercepted by the user-defined interceptor MybatisSqlParamInterceptor, wherein the parameter array contains all the parameters required by the target method; extracting the first parameter from the parameter array and converting it into a MappedStatement object, wherein the MappedStatement object contains the relevant information required to execute the SQL statement; extracting the second parameter from the parameter array and converting it into a Map type, and injecting user-related information into the SQL statement being compiled, wherein the Map type is a key-value pair type so that the value can be accessed by key, that is, the Map in the inheritableThreadLocals variable<String,Object> form; modify the second parameter in the parameter array to the Map type, and then continue to execute subsequent interceptor chains and SQL operations; In all SQL statements involving context parameters, the method for implementing the input of user-related information is used to obtain any user-related information and input it into the SQL statement.

2. The method for directly transferring context parameters to SQL statements according to claim 1, characterized in that: Before accessing the database according to the user unique identifier to obtain user related information pre-stored in the database and stored in binding with the user unique identifier, the method further includes: After the user logs in, all information related to the user is stored in the database, wherein all information includes the user's name, user account, user gender and / or user authority.

3. The method for directly transferring context parameters to SQL statements according to claim 1, characterized in that: The database adopts Redis database.

4. The method for directly transferring context parameters to SQL statements according to claim 1, characterized in that: Inject user-related information into the SQL statement being compiled, including: Injecting common context parameters into the SQL statement being compiled; The method in the entity for obtaining the context parameter key is called to store the user related information into the Map type.

5. The method for directly transferring context parameters to SQL statements according to claim 4, characterized in that: Injecting user-related information into the SQL statement being compiled also includes: The creation time, modification time and / or operator information are maintained in the Map type.

6. A device for directly transferring context parameters to SQL statements, characterized in that: It includes a definition content acquisition unit, a request interception processing unit, a method rewriting processing unit and a user information input unit which are sequentially connected in communication; The definition content acquisition unit is used to obtain user-defined entities, context parameter keys, and methods for implementing user-related information input, wherein the entity includes attributes of inheritableThreadLocals variables and methods for setting and obtaining context parameter keys; The request interception processing unit is used to intercept all user requests using the UserInterceptorHandler interceptor, parse the interception results to obtain the user's unique identifier, then access the database based on the user's unique identifier to obtain user-related information pre-stored in the database and bound to the user's unique identifier, and finally call the method in the entity for setting the context parameter key to store the user-related information into the inheritableThreadLocals variable; The method rewriting processing unit is used to rewrite the Intercept method based on the user-defined interceptor MybatisSqlParamInterceptor, specifically including: obtaining the parameter array in the target method intercepted by the user-defined interceptor MybatisSqlParamInterceptor, wherein the parameter array contains all the parameters required by the target method; extracting the first parameter from the parameter array and converting it into a MappedStatement object, wherein the MappedStatement object contains the relevant information required to execute the SQL statement; extracting the second parameter from the parameter array and converting it into a Map type, and injecting user-related information into the SQL statement being compiled, wherein the Map type is a key-value pair type so that the value can be accessed by the key, that is, the Map in the inheritableThreadLocals variable<String,Object> form; modify the second parameter in the parameter array to the Map type, and then continue to execute subsequent interceptor chains and SQL operations; The user information input unit is used to obtain any user-related information and input it into the SQL statement using the method for implementing user-related information input in all SQL statements that require context parameters.

7. A computer device, characterized in that: The invention comprises a memory, a processor and a transceiver which are communicatively connected in sequence, wherein the memory is used to store a computer program, the transceiver is used to send and receive messages, and the processor is used to read the computer program and execute the method for directly passing context parameters to SQL statements as described in any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that The computer-readable storage medium stores instructions. When the instructions are executed on a computer, the method for directly transferring context parameters to SQL statements as described in any one of claims 1 to 5 is executed.

9. A computer program product comprising a computer program or instructions, characterized in that When the computer program or the instruction is executed by a computer, the method for directly passing context parameters to SQL statements as claimed in any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Database data processing method and device, computer equipment and storage medium

    CN112988787A

  • Interface access log acquisition record query method and device and storage medium

    CN114595201A