Database operation statement detection method and device, electronic equipment and storage medium

By acquiring and analyzing parsed data of database operation statements, timing detection is performed using the target execution function, and a statement detection report is generated. This solves the problem of the inability to perform detailed detection in existing technologies, and improves the security and detection accuracy of the database.

CN119025525AActive Publication Date: 2024-11-26PING AN TECH (SHENZHEN) CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202411150156.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-20
Publication Date
2024-11-26
Estimated Expiration
2044-08-20

AI Technical Summary

Technical Problem

Existing technologies can only detect DDL or DML statements in database operations, and cannot perform detailed detection of certain types of SQL statements, which reduces database security.

Method used

By acquiring the parsed data of the target operation statement, the target type rules are selected from the preset rule table based on the statement type label, and the relevant data is written into the target stack. The timing detection is performed using the target execution function, and a statement detection report is generated to analyze abnormal situations.

Benefits of technology

It enables detailed inspection of database operation statements, improving detection accuracy and security. It can promptly capture and analyze errors and anomalies during SQL statement execution, ensuring compliance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119025525A_ABST
    Figure CN119025525A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a database operation statement detection method and device, electronic equipment and a storage medium, and belongs to the technical field of financial science and technology. The method comprises the following steps: acquiring analysis data of a target operation statement, wherein the analysis data comprises execution user data, a statement type label, a target operation object and a statement execution state; screening out a target type rule from a preset rule table based on the statement type label; writing the target operation statement, the execution user data, the target type rule and the statement type label into a target stack; writing the obtained object name, object mode and object type into a target stack based on a statement type label; determining a target execution function from the registration execution functions based on the target type rule; detecting an opportunity detection state based on a preset execution state of the target execution function and the statement execution state; and generating a statement detection report based on the opportunity detection state and the target stack. According to the embodiment of the invention, the detection accuracy of the database operation statement can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of financial technology, and in particular to a method and device for detecting database operation statements, an electronic device, and a storage medium. Background Art

[0002] At present, with the increase in the size and complexity of databases, the security of databases has become increasingly important. Databases usually have a log system. Related technologies can write the Structured Query Language (SQL) statements executed by users in the database into a log file through a log process, so as to detect the SQL statements corresponding to the user's operation behavior based on the log file, thereby ensuring the security of the database. For example, in the insurance field of financial technology, the corresponding database will collect a large number of SQL statements corresponding to user operations in a day. By accurately detecting SQL statements, errors and exceptions that occur during the execution of SQL statements can be captured and analyzed in a timely manner to ensure that the execution of SQL statements complies with relevant security policies and compliance requirements.

[0003] However, the SQL statement detection method of the related art can only detect the large categories of SQL statements such as Data Definition Language (DDL) or Data Manipulation Language (DML), but cannot detect the details of a certain category of SQL statements, which reduces the security of the database. Therefore, how to improve the detection accuracy of database operation statements has become a technical problem that needs to be solved urgently. Summary of the invention

[0004] The main purpose of the embodiments of the present application is to provide a database operation statement detection method and device, electronic device and storage medium, aiming to improve the detection accuracy of database operation statements.

[0005] To achieve the above-mentioned purpose, a first aspect of an embodiment of the present application proposes a database statement detection method, the method comprising:

[0006] Acquire parsed data of a target operation statement, the parsed data including execution user data, statement type label, target operation object and statement execution status, the target operation statement is a database operation statement and is used to perform an operation on data of a target database, and the statement execution status is used to indicate whether the operation performed by the target operation statement on the data of the target database is successful or failed;

[0007] Filtering a target type rule from a preset rule table based on the statement type tag, and writing the target operation statement, the execution user data, the target type rule and the statement type tag into a target stack;

[0008] Acquire the object name, object mode and object type of the target operation object based on the statement type tag, and write the object name, the object mode and the object type into the target stack;

[0009] Determining a target execution function from registered execution functions based on the target type rule;

[0010] Performing timing detection on the target operation statement based on the preset execution state of the target execution function and the statement execution state to obtain the timing detection state of the target operation statement, wherein the preset execution state is the execution state expected to be obtained by calling the target execution function, and the timing detection state is used to indicate whether the detection of the target operation statement is successful or failed;

[0011] A statement detection report of the target operation statement is generated based on the opportunity detection state and the target stack, and the statement detection report is used to analyze abnormal conditions of an execution process of the target operation statement on the data of the target database.

[0012] In some embodiments, before filtering out the target type rule from the preset rule table based on the statement type tag, the method further includes:

[0013] Determine a rule cache state of the preset rule table based on a preset invalidation message function, wherein the rule cache state includes an invalid state, and the invalid state is used to indicate that a rule in a preset cache of the preset rule table has changed;

[0014] If the rule cache state is the invalid state, obtaining currently configured rule data;

[0015] Loading the rule data into the preset cache;

[0016] The preset rule table is constructed based on the mapping relationship between the rule data and the type of the rule data.

[0017] In some embodiments, acquiring the object name, object mode, and object type of the target operation object based on the statement type tag includes:

[0018] If the statement type tag is a preset type tag, obtaining the object name, the object mode and the object type of the target operation object based on the target type rule; or

[0019] If the statement type tag is not the preset type tag, the object name, the object mode and the object type of the target operation object are obtained based on a preset trigger.

[0020] In some embodiments, acquiring the object name, the object mode, and the object type of the target operation object based on the target type rule includes:

[0021] Perform object rule matching based on the object name of the target operation object and the target type rule to obtain an object rule matching state; the object rule matching state includes an inclusion state, and the inclusion state indicates that the target type rule includes a rule that matches the object name of the target operation object;

[0022] If the object rule matching result is the inclusion state, the object name, the object mode and the object type of the target operation object are obtained based on a preset data acquisition function.

[0023] In some embodiments, the timing detection state includes a detection success state, and the detection success state indicates that the preset execution state is of the same type as the statement execution state; and generating a statement detection report for the target operation statement based on the timing detection state and the target stack includes:

[0024] If the timing detection state is the detection success state, acquiring the transaction data of the target operation statement, the database name of the target database, and the statement execution data;

[0025] The statement detection report is generated based on the transaction data, the database name, the statement execution data and the data in the target stack.

[0026] In some embodiments, the performing timing detection on the target operation statement based on the preset execution state of the target execution function and the statement execution state to obtain the timing detection state of the target operation statement includes:

[0027] Performing a traversal operation on the target stack to obtain stack data;

[0028] Performing type detection on the stack data to obtain a data type of the stack data, wherein the data type includes a type to be tested, and the type to be tested is used to characterize that the stack data is relevant to statement detection of the target operation statement;

[0029] If the data type is the type to be tested, a timing detection is performed on the target operation statement based on the preset execution state and the statement execution state to obtain the timing detection state.

[0030] In some embodiments, the timing detection state further includes a detection failure state, wherein the detection failure state indicates that the preset execution state is different from the statement execution state in type; and the generating of the statement detection report of the target operation statement based on the timing detection state and the target stack further includes:

[0031] If the timing detection state is the detection failure state, releasing the target stack;

[0032] Perform stack detection on the target stack to obtain a stack state.

[0033] To achieve the above-mentioned purpose, a second aspect of an embodiment of the present application proposes a database operation statement detection device, the device comprising:

[0034] an acquisition module, which acquires parsed data of a target operation statement, wherein the parsed data includes execution user data, a statement type label, a target operation object, and a statement execution status, wherein the target operation statement is a database operation statement and is used to perform an operation on data of a target database, and the statement execution status is used to indicate whether the operation performed by the target operation statement on the data of the target database is successful or failed;

[0035] A first writing module, configured to filter out a target type rule from a preset rule table based on the statement type tag, and write the target operation statement, the execution user data, the target type rule and the statement type tag into a target stack;

[0036] A second writing module is used to obtain the object name, object mode and object type of the target operation object based on the statement type label, and write the object name, the object mode and the object type into the target stack;

[0037] A determination module, configured to determine a target execution function from registered execution functions based on the target type rule;

[0038] a detection module, performing timing detection on the target operation statement based on the preset execution state of the target execution function and the statement execution state, to obtain the timing detection state of the target operation statement, wherein the preset execution state is the execution state expected to be obtained by calling the target execution function, and the timing detection state is used to indicate whether the detection of the target operation statement is successful or failed;

[0039] A generating module is used to generate a statement detection report of the target operation statement based on the opportunity detection state and the target stack, wherein the statement detection report is used to analyze abnormal conditions of the target operation statement in the data execution process of the target database.

[0040] To achieve the above-mentioned purpose, the third aspect of an embodiment of the present application proposes an electronic device, which includes a memory and a processor, the memory stores a computer program, and the processor implements the database operation statement detection method described in the first aspect when executing the computer program.

[0041] To achieve the above-mentioned purpose, the fourth aspect of an embodiment of the present application proposes a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the database operation statement detection method described in the first aspect is implemented.

[0042] The present application proposes a database operation statement detection method and device, electronic device and storage medium, which obtains parsed data of a target operation statement, the parsed data includes execution user data, statement type label, target operation object and statement execution status, the target operation statement is a database operation statement, and is used to perform operations on the data of the target database, and the statement execution status is used to characterize whether the operation performed by the target operation statement on the data of the target database is successful or failed; based on the statement type label, a target type rule is filtered out from a preset rule table; the target operation statement, execution user data, target type rule and statement type label are written into a target stack; based on the statement type label, the target operation object is obtained. The object name, object mode and object type are obtained, and the object name, object mode and object type are written into the target stack; the target execution function is determined from the registered execution function based on the target type rule; the target operation statement is detected at the right time based on the preset execution state and statement execution state of the target execution function to obtain the timing detection state of the target operation statement, the preset execution state is the execution state expected to be obtained by calling the target execution function, and the timing detection state is used to characterize the detection of the target operation statement as successful or failed; a statement detection report of the target operation statement is generated based on the timing detection state and the target stack, and the statement detection report is used to analyze the abnormal situation of the data execution process of the target operation statement on the target database. The embodiment of the present application can perform statement detection from the perspectives of user, object, execution state, matching rules, etc. corresponding to a target operation statement based on the statement type label. Compared with the method in which the related technology can only use log files to detect large categories of operation statements such as DDL and DML, the detection granularity of the present application is finer, and the detailed detection of a certain type of SQL statement can be realized, thereby improving the detection accuracy of database operation statements. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] Figure 1 This is the first flow chart of the database operation statement detection method provided in the embodiment of the present application;

[0044] Figure 2 is a second flow chart of the database operation statement detection method provided in an embodiment of the present application;

[0045] Figure 3 It is a flow chart of the database startup phase provided by the embodiment of the present application;

[0046] Figure 4 yes Figure 1 A flowchart of step S130 in FIG.

[0047] Figure 5 yes Figure 1 A flowchart of step S150 in FIG.

[0048] Figure 6 yes Figure 1 The first flowchart of step S160 in FIG.

[0049] Figure 7 yes Figure 1 A second flow chart of step S160 in FIG. 1 ;

[0050] Figure 8 It is a specific flow chart of the database operation statement detection method provided in the embodiment of the present application;

[0051] Fig. 9 It is a structural schematic diagram of a database operation statement detection device provided in an embodiment of the present application;

[0052] Fig.10 It is a hardware structure diagram of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION

[0053] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0054] It should be noted that, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.

[0055] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.

[0056] First, some nouns involved in this application are analyzed:

[0057] Structured Query Language (SQL): is a standardized programming language for managing and operating relational databases. SQL is widely used in database systems such as MySQL, PostgreSQL, Oracle, SQL Server, etc. to execute queries, update data, manage database structure, and control database access rights.

[0058] Database: A system for storing, managing and retrieving data. A database is usually composed of a set of organized data and is managed by a database management system (DBMS). Database technology solves application problems such as the organization, storage, management, query and statistics of large amounts of data in the information processing process, making it possible to reduce data redundancy, achieve data sharing, ensure data consistency, and achieve fast data retrieval and statistical analysis in the database system.

[0059] Data Definition Language (DDL): is a language used to describe real-world entities to be stored in a database. DDL is mainly used to define or change the structure of a table, data types, links between tables, and other operations. Common DDL statement keywords include CREATE, DROP, ALTER, etc.

[0060] Data Manipulation Language (DML): is a set of SQL statements used to operate data in a database. DML mainly includes operations such as insert (INSERT), update (UPDATE), delete (DELETE) and query (SELECT).

[0061] Transaction: It is an important concept in database management system. It is a series of operations on the database. These operations are either all executed or not executed at all. It is an indivisible unit of work. The main function of transaction is to ensure the consistency and integrity of data. Through transaction, it can ensure that a group of related data operations are either all successfully submitted or all rolled back to avoid the database being in an intermediate state.

[0062] Databases are the core of organizing and storing a large amount of critical information. As the size and complexity of databases increase, attackers may try to exploit vulnerabilities, perform unauthorized access, or conduct other malicious activities, which pose a threat to the integrity and confidentiality of the database. Therefore, the security of databases is becoming more and more important. Based on the above considerations, databases usually have log systems. Related technologies can write SQL statements executed by users in the database into log files through log processes, so as to detect SQL statements corresponding to user operation behaviors based on the log files, thereby ensuring the security of the database. For example, in the insurance field of financial technology, the corresponding database will collect a large number of SQL statements corresponding to user operation behaviors in a day. By accurately detecting SQL statements, errors and exceptions that occur during the execution of SQL statements can be captured and analyzed in a timely manner to ensure that the execution of SQL statements complies with relevant security policies and compliance requirements.

[0063] However, the SQL statement detection method of the related art can only detect large categories of SQL statements such as DDL or DML, but cannot detect the details of certain types of SQL statements (such as CREATE, DELETE, etc.), which reduces the security of the database. Therefore, how to improve the detection accuracy of database operation statements, thereby improving the security of the database, has become a technical problem that needs to be solved urgently.

[0064] Based on this, the embodiments of the present application provide a method and device for detecting database operation statements, an electronic device, and a storage medium, which can improve the accuracy of detecting database operation statements, thereby improving the security of the database.

[0065] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Artificial Intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.

[0066] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.

[0067] The database operation statement detection method provided in the embodiment of the present application relates to the field of artificial intelligence technology. The database operation statement detection method provided in the embodiment of the present application can be applied to a terminal, can also be applied to a server side, and can also be software running in a terminal or a server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server side can be configured as an independent physical server, or can be configured as a server cluster or a distributed system composed of multiple physical servers, and can also be configured to provide 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 cloud servers for basic cloud computing services such as big data and artificial intelligence platforms; the software can be an application that implements the database operation statement detection method, etc., but is not limited to the above forms.

[0068] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.

[0069] It should be noted that in each specific implementation of the present application, when it comes to the need to perform relevant processing based on user operation behavior information and user information and other data related to user identity or characteristics, the user's permission or consent will be obtained first, and the collection, use and processing of these data will comply with relevant laws, regulations and standards. In addition, when the embodiment of the present application needs to obtain the user's sensitive personal information, the user's separate permission or consent will be obtained through a pop-up window or jump to a confirmation page. After clearly obtaining the user's separate permission or consent, the necessary user-related data for the normal operation of the embodiment of the present application will be obtained.

[0070] See also Figure 1 , Figure 1is an optional flow chart of the database operation statement detection method provided in the embodiment of the present application. In some embodiments, Figure 1 The method may include but is not limited to steps S110 to S160:

[0071] Step S110, obtaining parsed data of the target operation statement;

[0072] Step S120, filtering out target type rules from the preset rule table based on the statement type tag, and writing the target operation statement, execution user data, target type rules and statement type tags into the target stack;

[0073] Step S130, obtaining the object name, object mode and object type of the target operation object based on the statement type tag, and writing the object name, object mode and object type into the target stack;

[0074] Step S140, determining a target execution function from registered execution functions based on a target type rule;

[0075] Step S150, performing timing detection on the target operation statement based on the preset execution state and statement execution state of the target execution function to obtain the timing detection state of the target operation statement;

[0076] Step S160: Generate a statement detection report of the target operation statement based on the opportunity detection state and the target stack.

[0077] In steps S110 to S160 of some embodiments, statement detection can be performed on the user, object, execution status, matching rules, etc. corresponding to a target operation statement based on the statement type label. Compared with the related art that can only use log files to detect large types of operation statements such as DDL and DML, the detection granularity of the present application is finer, and detailed detection of a certain type of SQL statement can be achieved, thereby improving the detection accuracy of database operation statements and thus improving the security of the database.

[0078] In step S110 of some embodiments, the target operation statement is a database operation statement (i.e., SQL statement), and is used to perform operations on the data of the target database, that is, the target user performs operations on the data of the target database, such as adding data, deleting data, modifying data, etc. At this time, the corresponding target operation statement will be generated on the server corresponding to the database. Parsed data refers to the data that can be obtained after the target operation statement is parsed. Parsed data includes execution user data, statement type label, target operation object and statement execution status, wherein the execution user data refers to the user who executes the target operation language, that is, the execution user data can be obtained through the account information bound to the target operation statement. The statement type label is used to characterize the command label corresponding to the statement, that is, the specific category to which the statement belongs, including insert (I NSERT), update (UPDATE), delete (DELETE) and query (SELECT), etc. The target operation object refers to the database entity involved in the target operation statement, where the object types of this application include table, view, index, sequence, stored procedure, function, etc., and each object type has its specific properties and behaviors. The statement execution status is used to characterize whether the operation performed by the target operation statement on the data of the target database is successful or failed.

[0079] In step S120 of some embodiments, after obtaining the parsed data of the target operation statement, the target type rule can be screened out from the preset rule table based on the statement type label. Further, if the target type rule is obtained, the target operation statement, the execution user data, the target type rule and the statement type label can be written into the target stack, which refers to the stack structure corresponding to the target operation statement. Among them, different statement types and corresponding type rules are loaded in the preset rule table. The present application can match the statement type label corresponding to the target operation statement with the statement type in the preset rule table to determine the target type rule corresponding to the target operation statement. For example, when the statement type label is SELECT, the type rule corresponding to SELECT can be taken from the preset rule table as the target type rule. In addition, the preset rule table of the present application can be a hash table, without limitation.

[0080] It should be noted that if the type rule corresponding to the statement type label is not matched in the preset rule table, it means that the user operation behavior corresponding to the type does not need to be detected and the process can be ended directly.

[0081] It should be noted that when this application detects the behavior of user operations on the database, the database administrator needs to set the detection rules in advance according to the internally provided method, and the rules are at the library level. The rules between different databases are isolated from each other and do not affect each other. In addition, this application implements the detection of user operation statements with two characteristics: one is to register the corresponding methods and functions during the database startup phase, and the other is to detect the user's operation statements according to the set detection rules after the database server is started and write them into the corresponding detection report (i.e. file), and the written results can include user name, database name, IP address, rule ID, SQL statement, execution status (success or failure), etc., without limitation.

[0082] In some embodiments, see Figure 2 , Figure 2 This is another optional flow chart of the database operation statement detection method provided by the embodiment of the present application. Before step S120, the database operation statement detection method of the present application may also include steps S210 to S240:

[0083] Step S210, determining a rule cache state of a preset rule table based on a preset invalidation message function;

[0084] Step S220, if the rule cache state is invalid, obtain the currently configured rule data;

[0085] Step S230, loading the rule data into a preset cache;

[0086] Step S240: construct a preset rule table based on the mapping relationship between the rule data and the type of the rule data.

[0087] In step S210 of some embodiments, the preset invalidation message function refers to a function that is pre-registered and configured in the startup phase of the target database and is used to be called when the type rule changes. The rule cache state is used to characterize whether the rules in the preset cache of the preset rule table have changed, and the rule cache state may include an invalid state and a valid state, the invalid state is used to indicate that the rules in the preset cache of the preset rule table have changed, and the valid state is used to indicate that the rules in the preset cache of the preset rule table have not changed.

[0088] It should be noted that the rules are preloaded into the cache, but the rules may change, so here determining whether the cache is valid is to determine whether the rules have changed. Specifically, if the rules have changed, an invalidation message will be received, so that it can be determined whether the rules of the preset rule table have changed.

[0089] In some embodiments, in steps S220 to S240, if the rule cache state is invalid, the currently configured rule data can be obtained, the rule data can be loaded into the preset cache, and a preset rule table can be constructed based on the mapping relationship between the rule data and the type of the rule data. The currently configured rule data refers to all rule data including the changed rules, so as to avoid simply loading the changed rule data and causing duplication of rule data.

[0090] It should be noted that if the rule cache status is valid, the current preset rule table can be used to perform subsequent operations.

[0091] In some embodiments, see Figure 3 , Figure 3 It is a flowchart of the database startup phase provided by the embodiment of the present application. Before step S110, the present application will first start the database, and the steps of the database startup phase of the present application may specifically include steps S310 to S350:

[0092] Step S310, start;

[0093] Step S320, a method for registering configuration rules.

[0094] Among them, this step is to register a method for use by a database administrator, which is called when the database administrator configures the detection rules to generate a preset rule table.

[0095] Step S330, registering a preset invalidation message function;

[0096] Step S340, register the function when the transaction is submitted.

[0097] The function for registering transaction submission in this step refers to the registration execution function, which also indicates the function for executing the registration transaction SQL statement successfully or unsuccessfully, and is called during the transaction submission phase.

[0098] Step S350, end.

[0099] In step S130 of some embodiments, after the target type rule is determined, the object name, object mode and object type of the target operation object can be obtained based on the statement type tag, and the object name, object mode and object type are written into the target stack. Among them, the object name refers to the name of a specific entity in the database. For example, if the object is a table, the object name is the name of the table, and for other database objects, such as views, indexes, stored procedures, etc., the object name also refers to the corresponding name. The object mode is a logical concept that defines the namespace and structure of objects in the database. In a relational database, a mode usually contains a set of related tables, views, indexes and other database objects. The mode name is used to uniquely identify different parts of the database, especially in a multi-user environment, to prevent naming conflicts. For example, in PostgreSQL, users can use public as the default mode, or create a custom mode to organize the user's database objects. The object type refers to the type of entity in the database. In SQL, common object types include tables (TABLE), views (VIEW), indexes (INDEX), sequences (SEQUENCE), stored procedures (PROCEDURE), functions (FUNCTION), etc.

[0100] In some embodiments, obtaining the object name, object mode, and object type of the target operation object based on the statement type tag in step S130 may specifically include the following steps:

[0101] If the statement type tag is a preset type tag, obtaining the object name, object mode, and object type of the target operation object based on the target type rule; or,

[0102] If the statement type label is not a preset type label, the object name, object mode, and object type of the target operation object are obtained based on the preset trigger.

[0103] Among them, due to the differences in the way different statement types obtain data, the present application can first determine the statement type of the target operation statement based on the preset type label, so as to further obtain the object name, object mode and object type of the target operation object under the statement type. Specifically, the preset type label can be the type corresponding to the DML statement, that is, if the statement type label is a preset type label, it can be determined that the target operation statement is a DML statement, and the object name, object mode and object type of the target operation object can be obtained based on the target type rule; if the statement type label is not a preset type label, it can be determined that the target operation statement is not a DML statement, and the object name, object mode and object type of the target operation object can be directly obtained based on the preset trigger, and the obtained object name, object mode and object type are further written into the target stack. The preset trigger is a stored procedure automatically executed by the database management system, and the preset trigger can be associated with a specific table event, such as I NSERT, UPDATE or DELETE operation. In this way, when these events occur, the trigger will automatically execute the predefined SQL code block.

[0104] In some embodiments, see Figure 4 , Figure 4 This is an optional flowchart of step S130 provided in an embodiment of the present application. In step S130, the object name, object mode and object type of the target operation object are obtained based on the target type rule, which may specifically include steps S410 to S420:

[0105] Step S410, performing object rule matching based on the object name and target type rule of the target operation object to obtain an object rule matching state;

[0106] Step S420: If the object rule matching result is an inclusion state, the object name, object mode and object type of the target operation object are obtained based on a preset data acquisition function.

[0107] In step S410 of some embodiments, if the statement type label is a preset type label, object rule matching can be further performed based on the object name of the target operation object and the target type rule to obtain an object rule matching state that can reflect whether the object name of the target operation object satisfies the detection rule. Among them, the object rule matching state includes an inclusion state and a non-inclusion state. The inclusion state indicates that the target type rule contains a rule that matches the object name of the target operation object, and the non-inclusion state indicates that the target type rule does not contain a rule that matches the object name of the target operation object. For example, if the object is a table, the target type rule may have rules corresponding to different tables loaded. Then, the object rule matching state can be determined by comparing the object name of the target operation object with the table name loaded in the target type rule.

[0108] In step S420 of some embodiments, if the object rule matching result is an inclusion state, the object name, object mode and object type of the target operation object are obtained based on a preset data acquisition function, wherein the preset data acquisition function is used by the user to obtain the required data, and the preset acquisition function can be a C function.

[0109] It should be noted that if the result of the object rule matching is a non-inclusion state, the target stack can be released. Releasing the stack means returning all the allocated memory space in the target stack to the system so that the system can reuse the memory. In C language, when a stack is created, a continuous memory space is usually allocated for it. This space is used to store the elements in the stack. When the stack is no longer needed, the memory space should be released by calling the corresponding release function to avoid memory leaks.

[0110] In step S140 of some embodiments, at the transaction commit stage, the present application may determine a target execution function from registered execution functions based on a target type rule. The target execution function is used to indicate whether the target operation statement is executed successfully or failed when the transaction is committed.

[0111] In step S150 of some embodiments, further, the target operation statement can be subjected to timing detection based on the preset execution state and statement execution state of the target execution function to obtain the timing detection state of the target operation statement, and the timing detection state at this time is also used to indicate whether the current target operation statement meets the detection timing. Among them, the preset execution state is the execution state expected to be obtained by calling the target execution function, and the timing detection state is used to characterize whether the detection of the target operation statement is successful or failed.

[0112] In some embodiments, see Figure 5 , Figure 5 It is an optional flow chart of step S150 provided in the embodiment of the present application. Among them, step S150 may specifically include steps S510 to S530:

[0113] Step S510, traverse the target stack to obtain stack data;

[0114] Step S520, performing type detection on the stack data to obtain the data type of the stack data;

[0115] Step S530: If the data type is the type to be tested, a timing detection is performed on the target operation statement based on the preset execution state and the statement execution state to obtain a timing detection state.

[0116] In steps S510 to S530 of some embodiments, when performing timing detection, the target stack can be traversed first to determine whether the current target stack still contains stack data for user detection. It should be noted that after each detection of a stack data, the stack data can be marked as having been detected, so whether the target stack still contains data for user detection can be determined based on the mark of the stack data. Specifically, for each stack data obtained, the stack data will first be type-detected to obtain the data type of the stack data, and the stack data may be data that is irrelevant to the user corresponding to the target operation statement. The data type includes a type to be tested, and the type to be tested is used to characterize that the stack data is related to the statement detection of the target operation statement. Further, if the data type is a type to be tested, that is, the stack data is data related to the user corresponding to the target operation statement, the target operation statement can be timing-detected based on the preset execution state and the statement execution state to obtain the timing detection state.

[0117] It should be noted that if the data type is not the type to be tested, the stack data can be directly released to avoid affecting subsequent judgments, and the process returns to re-execute step S510.

[0118] In step S160 of some embodiments, after obtaining the timing detection status, a statement detection report of the target operation statement can be generated based on the timing detection status and the target stack, and the statement detection report is used to analyze abnormal situations in the data execution process of the target operation statement on the target database.

[0119] In some embodiments, see Figure 6 , Figure 6 It is an optional flow chart of step S160 provided in the embodiment of the present application. Among them, step S160 may specifically include steps S610 to S620:

[0120] Step S610, if the opportunity detection state is a detection success state, obtain the transaction data of the target operation statement, the database name of the target database and the statement execution data;

[0121] Step S620, generating a statement detection report based on the transaction data, database name, statement execution data and data in the target stack.

[0122] In steps S610 to S620 of some embodiments, the timing detection state includes a detection success state and a detection failure state, wherein the detection success state indicates that the preset execution state is of the same type as the statement execution state, and the detection failure state indicates that the preset execution state is of a different type than the statement execution state. Specifically, if the timing detection state is a detection success state, the transaction data of the target operation statement, the database name of the target database, and the statement execution data can be obtained. Among them, the transaction data may include the transaction number, virtual transaction number, etc. corresponding to the target operation statement, and the statement execution data may include the process number, IP address, etc. Further, the transaction data, database name, statement execution data, and data in the target stack may be combined to generate a statement detection file corresponding to the target operation statement. Therefore, the statement detection file may include rule ID, status, transaction number, virtual transaction number, database name, process number, IP address, etc.

[0123] It should be noted that during the database startup phase, when the database administrator configures the detection rules, he can configure a detection function for the success or failure of the user's SQL statement execution, that is, register the execution function. Then, when the transaction is committed, if the successful function is executed and the configuration is to detect the user's successful operation, the detection timing is met, and vice versa.

[0124] It should be noted that the present application detects statements corresponding to user operation behaviors to obtain statement detection files, which can quickly identify SQL statements that are slow to execute or consume high resources, perform performance tuning, and ensure that the query optimizer selects the optimal execution path. It can also detect potential SQL injection attacks and other malicious SQL statements, audit access and modification operations of sensitive data, and ensure data security. In addition, it is also possible to obtain and analyze errors and anomalies that occur during the execution of SQL statements, provide error reports and alarms, and help to discover and solve problems in a timely manner. In addition, the statement detection report obtained by the present application can also implement compliance verification, that is, ensure that the execution of SQL statements complies with relevant security policies and compliance requirements, and verify the legality and compliance of database operations through statement detection reports.

[0125] In some embodiments, see Figure 7 , Figure 7 is another optional flow chart of step S160 provided in the embodiment of the present application. Wherein, step S160 may further include steps S710 to S720:

[0126] Step S710, if the timing detection state is a detection failure state, release the target stack;

[0127] Step S720: Perform stack detection on the target stack to obtain the stack status.

[0128] In steps S710 to S720 of some embodiments, if the opportunity detection state is a detection failure state, the data corresponding to the target stack is released, and the stack detection is performed on the target stack again to obtain the stack state.

[0129] In one specific embodiment, see Figure 8 , Figure 8 It is a specific flow chart of the database operation statement detection method provided by the embodiment of the present application. Among them, the database operation statement detection method can specifically include a semantic phase, an execution phase and a transaction submission phase, and the database operation statement detection method of the present application can specifically include:

[0130] Step S801, start;

[0131] Step S802, determining whether the preset cache of the preset rule table is valid, if so, executing step S803; if not, executing step S804;

[0132] Step S803, traverse the preset rule table, match the target type rule, and further execute step S805;

[0133] Step S804, loading the currently configured rule data to update the preset rule table, and further executing step S805;

[0134] Step S805, determine whether there is a rule corresponding to the statement type tag in the preset rule table, if so, execute step S806; if not, execute step S817;

[0135] Step S806, writing the target operation statement, execution user data, target type rule and statement type tag into the target stack;

[0136] Step S807, determine whether the sentence type tag meets the preset type tag, if yes, execute step S808, if no, execute step S811;

[0137] Step S808, determining whether the object name of the target operation object matches the object name included in the target type rule, if so, executing step S809, if not, executing step S810;

[0138] Step S809, obtaining the object name, object mode and object type of the target operation object, and writing them into the target stack;

[0139] Step S810, releasing the undetected SQL stack, and further executing step S812;

[0140] Step S811, obtaining the object name, object mode and object type through a preset trigger, and writing them into the target stack;

[0141] Step S812, traverse the target stack;

[0142] Step S813, determine whether the target stack has stack data of the type to be tested, if so, execute step S814, if not, execute step S817;

[0143] Step S814, determining whether the preset execution state of the target execution function and the statement execution state match the timing detection of the target operation statement, if so, executing step S815, if not, executing step S816;

[0144] Step S815, generating a statement detection report of the target operation statement;

[0145] Step S816, releasing stack data;

[0146] Step S817, end.

[0147] A database operation statement detection method provided in an embodiment of the present application is compared with the native fixed method of the database that can only record the DDL and DML statements. In this application, the database administrator first configures the detection rules for a specific SQL statement, a user, a mode or a specific object according to the SQL method provided internally, and the database server then detects the user's operation according to the rules. The detection granularity of this method is higher, and the detailed detection of a certain type of SQL statement can be realized, thereby improving the detection accuracy of the database operation statement, improving the flexibility of the user's operation of the database, and also improving the security of the database.

[0148] See also Fig. 9 The embodiment of the present application also provides a database operation statement detection device, which can implement the above-mentioned database operation statement detection method, and the device includes:

[0149] The acquisition module 910 acquires parsed data of the target operation statement, the parsed data including execution user data, statement type label, target operation object and statement execution status, the target operation statement is a database operation statement and is used to perform an operation on the data of the target database, and the statement execution status is used to indicate whether the operation performed by the target operation statement on the data of the target database is successful or failed;

[0150] A first writing module 920, configured to filter out a target type rule from a preset rule table based on a statement type tag, and write a target operation statement, execution user data, target type rule and statement type tag into a target stack;

[0151] A second writing module 930 is used to obtain the object name, object mode and object type of the target operation object based on the statement type label, and write the object name, object mode and object type into the target stack;

[0152] A determination module 940, configured to determine a target execution function from registered execution functions based on a target type rule;

[0153] A detection module 950 performs a timing detection on a target operation statement based on a preset execution state and a statement execution state of a target execution function to obtain a timing detection state of the target operation statement, wherein the preset execution state is an execution state expected to be obtained by calling the target execution function, and the timing detection state is used to indicate whether the detection of the target operation statement is successful or failed;

[0154] The generating module 960 is used to generate a statement detection report of the target operation statement based on the opportunity detection state and the target stack, and the statement detection report is used to analyze the abnormal situation of the target operation statement in the data execution process of the target database.

[0155] The specific implementation of the database operation statement detection device is basically the same as the specific implementation of the above-mentioned database operation statement detection method, and will not be repeated here.

[0156] The embodiment of the present application also provides an electronic device, the electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the above database operation statement detection method when executing the computer program. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.

[0157] See also Fig.10 , Fig.10 The hardware structure of an electronic device of another embodiment is illustrated, and the electronic device includes:

[0158] The processor 1010 may be implemented by a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application.

[0159] The memory 1020 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 1020 can store an operating system and other application programs. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 1020, and the processor 1010 calls and executes the database operation statement detection method of the embodiment of this application;

[0160] Input / output interface 1030, used to implement information input and output;

[0161] The communication interface 1040 is used to realize the communication interaction between the device and other devices. The communication can be realized through a wired manner (such as USB, network cable, etc.) or a wireless manner (such as mobile network, WI FI, Bluetooth, etc.);

[0162] Bus 1050 , which transmits information between various components of the device (e.g., processor 1010 , memory 1020 , input / output interface 1030 , and communication interface 1040 );

[0163] The processor 1010 , the memory 1020 , the input / output interface 1030 , and the communication interface 1040 are connected to each other in communication within the device via a bus 1050 .

[0164] An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the above-mentioned database operation statement detection method is implemented.

[0165] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0166] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0167] Those skilled in the art will appreciate that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.

[0168] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0169] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.

[0170] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0171] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.

[0172] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0173] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0174] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0175] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.

[0176] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.

Claims

1. A method for detecting database operation statements, characterized in that: The method comprises: Acquire parsed data of a target operation statement, the parsed data including execution user data, statement type label, target operation object and statement execution status, the target operation statement is a database operation statement and is used to perform an operation on data of a target database, and the statement execution status is used to indicate whether the operation performed by the target operation statement on the data of the target database is successful or failed; Filtering a target type rule from a preset rule table based on the statement type tag, and writing the target operation statement, the execution user data, the target type rule and the statement type tag into a target stack; Acquire the object name, object mode and object type of the target operation object based on the statement type tag, and write the object name, the object mode and the object type into the target stack; Determining a target execution function from registered execution functions based on the target type rule; Performing timing detection on the target operation statement based on the preset execution state of the target execution function and the statement execution state to obtain the timing detection state of the target operation statement, wherein the preset execution state is the execution state expected to be obtained by calling the target execution function, and the timing detection state is used to indicate whether the detection of the target operation statement is successful or failed; A statement detection report of the target operation statement is generated based on the opportunity detection state and the target stack, and the statement detection report is used to analyze abnormal conditions of an execution process of the target operation statement on the data of the target database.

2. The method according to claim 1, characterized in that Before filtering out the target type rule from the preset rule table based on the statement type tag, the method further includes: Determine a rule cache state of the preset rule table based on a preset invalidation message function, wherein the rule cache state includes an invalid state, and the invalid state is used to indicate that a rule in a preset cache of the preset rule table has changed; If the rule cache state is the invalid state, obtaining currently configured rule data; Loading the rule data into the preset cache; The preset rule table is constructed based on the mapping relationship between the rule data and the type of the rule data.

3. The method according to claim 1, characterized in that The acquiring the object name, object mode and object type of the target operation object based on the statement type label includes: If the statement type tag is a preset type tag, obtaining the object name, the object mode and the object type of the target operation object based on the target type rule; or If the statement type tag is not the preset type tag, the object name, the object mode and the object type of the target operation object are obtained based on a preset trigger.

4. The method according to claim 3, characterized in that The acquiring the object name, the object mode, and the object type of the target operation object based on the target type rule includes: Perform object rule matching based on the object name of the target operation object and the target type rule to obtain an object rule matching state; the object rule matching state includes an inclusion state, and the inclusion state indicates that the target type rule includes a rule that matches the object name of the target operation object; If the object rule matching result is the inclusion state, the object name, the object mode and the object type of the target operation object are obtained based on a preset data acquisition function.

5. The method according to any one of claims 1 to 4, characterized in that: The timing detection state includes a detection success state, and the detection success state indicates that the preset execution state is of the same type as the statement execution state; The generating a statement detection report of the target operation statement based on the opportunity detection state and the target stack includes: If the timing detection state is the detection success state, acquiring the transaction data of the target operation statement, the database name of the target database, and the statement execution data; The statement detection report is generated based on the transaction data, the database name, the statement execution data and the data in the target stack.

6. The method according to claim 5, characterized in that The performing timing detection on the target operation statement based on the preset execution state of the target execution function and the statement execution state to obtain the timing detection state of the target operation statement includes: Performing a traversal operation on the target stack to obtain stack data; Performing type detection on the stack data to obtain a data type of the stack data, wherein the data type includes a type to be tested, and the type to be tested is used to characterize that the stack data is relevant to statement detection of the target operation statement; If the data type is the type to be tested, a timing detection is performed on the target operation statement based on the preset execution state and the statement execution state to obtain the timing detection state.

7. The method according to claim 6, characterized in that The timing detection state also includes a detection failure state, where the detection failure state indicates that the preset execution state is different from the statement execution state; and the statement detection report for the target operation statement generated based on the timing detection state and the target stack further includes: If the timing detection state is the detection failure state, releasing the target stack; Perform stack detection on the target stack to obtain a stack state.

8. A database statement detection device, characterized in that: The device comprises: an acquisition module, which acquires parsed data of a target operation statement, wherein the parsed data includes execution user data, a statement type label, a target operation object, and a statement execution status, wherein the target operation statement is a database operation statement and is used to perform an operation on data of a target database, and the statement execution status is used to indicate whether the operation performed by the target operation statement on the data of the target database is successful or failed; A first writing module, configured to filter out a target type rule from a preset rule table based on the statement type tag, and write the target operation statement, the execution user data, the target type rule and the statement type tag into a target stack; A second writing module is used to obtain the object name, object mode and object type of the target operation object based on the statement type label, and write the object name, the object mode and the object type into the target stack; A determination module, configured to determine a target execution function from registered execution functions based on the target type rule; a detection module, performing timing detection on the target operation statement based on the preset execution state of the target execution function and the statement execution state, to obtain the timing detection state of the target operation statement, wherein the preset execution state is the execution state expected to be obtained by calling the target execution function, and the timing detection state is used to indicate whether the detection of the target operation statement is successful or failed; A generating module is used to generate a statement detection report of the target operation statement based on the opportunity detection state and the target stack, wherein the statement detection report is used to analyze abnormal conditions of the target operation statement in the data execution process of the target database.

9. An electronic device, characterized in that: The electronic device comprises a memory and a processor, the memory stores a computer program, and the processor implements the method according to any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium storing 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.

Citation Information

Patent Citations

  • Database management method and device, electronic equipment and storage medium

    CN113722347A

  • Mybatis framework SQL (Structured Query Language) statement anomaly detection method, server and system

    CN114116765A

  • Exception handling method and device for cloud database and computing device cluster

    CN115952153A

  • SQL (Structured Query Language) statement detection method and device, equipment, medium and program product

    CN117827883A

  • Transaction processing method and apparatus for distributed database system

    WO2016078423A1