Database table operation method and device, electronic equipment and storage medium

By syntactically analyzing and rewriting the SQL statements requested for database table operations, and adding integrity identification fields and message verification codes, the difficulty in business code transformation caused by changes in the important data range of data entity objects in the existing technology is solved, and the database is implemented Simplified and efficient maintenance of data integrity protection.

CN118535601APending Publication Date: 2024-08-23DIGITAL GUANGDONG NETWORK CONSTR CO LTD
View PDF 0 Cites 7 Cited by

Patent Information

Application Number
CN202410596093.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-14
Publication Date
2024-08-23

AI Technical Summary

Technical Problem

When the existing technology protects the integrity of key data and important data in the database, a large amount of business code modification is required, which makes data maintenance difficult, especially when the important data range of the data entity object changes.

Method used

By determining the original SQL statement corresponding to the database table operation request, perform syntax analysis and rewriting, and add integrity identification fields and message verification codes to ensure that data operations comply with integrity protection standards and avoid repeatedly writing integrity protection logic in business code.

Benefits of technology

This eliminates the need to repeatedly write integrity protection code in program business code, simplifies business data maintenance, and improves the ease of data operation and integrity protection efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118535601A
    Figure CN118535601A
Patent Text Reader

Abstract

The invention discloses a database table operation method and device, electronic equipment and a storage medium, and relates to the technical field of databases. The method comprises the following steps: determining an original structured query language (SQL) statement corresponding to a database table operation request; performing syntactic analysis on the original SQL statement to obtain a data operation type and an SQL syntax tree of the database table operation request; rewriting the original SQL statement based on the data operation type and the SQL syntax tree to obtain a target SQL statement; and executing the target SQL statement to obtain an operation result corresponding to the database table operation request. According to the technical scheme provided by the invention, the integrity protection code does not need to be repeatedly written in each data access object in the program service code, so that the service data maintenance is simple and easy to operate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of database technology, and in particular to a method, device, electronic device and storage medium for operating a database table. Background Art

[0002] In system applications, there is an increasing demand for integrity protection of key data, access control information, log records, and stored important data. The purpose of integrity protection is to prevent attackers from maliciously tampering with data in the database without authorization.

[0003] In addition to access control information, important data in the system is scattered in various data entity objects. Integrity protection transformation will involve integrity writing and verification operations when reading and writing many data tables. If the scope of important data defined by a data entity object has changed, such as: the original email address is not important data, but later the business change requires the use of email to receive verification codes, the email address becomes important data, so it is necessary to prevent the email address from being tampered with and adjust the business code. However, the existing technology usually uses traditional code intrusion to modify the code in order to include the email address in the integrity protection scope, which will result in a large number of business code modifications and difficulty in business data maintenance. Therefore, there is an urgent need for an operation method for database tables that is simple and easy to operate for business data maintenance. Summary of the invention

[0004] The present application provides a method, device, electronic device and storage medium for operating a database table, which eliminates the need to repeatedly write integrity protection code for each data access object in a program business code, thereby making business data maintenance simple and easy to operate.

[0005] In a first aspect, the present application provides a method for operating a database table, the method comprising:

[0006] Determine an original structured query language SQL statement corresponding to a database table operation request, wherein the database table includes a preset protected field, and the protected field includes a plurality of subfields;

[0007] Performing syntax analysis on the original SQL statement to obtain the data operation type and SQL syntax tree of the database table operation request;

[0008] Rewrite the original SQL statement based on the data operation type and the SQL syntax tree to obtain a target SQL statement;

[0009] Execute the target SQL statement to obtain the operation result corresponding to the database table operation request.

[0010] Furthermore, the database table includes pre-set protected fields; when the data operation type is a data query operation, before rewriting the original SQL statement based on the data operation type and the SQL syntax tree to obtain a target SQL statement, it also includes: determining whether the query field list in the SQL syntax tree includes the protected field; if the protected field is not included, determining that the original SQL statement does not meet the statement rewriting standard; if the protected field is included, determining that the original SQL statement meets the statement rewriting standard, and triggering the execution of rewriting the original SQL statement based on the data operation type and the SQL syntax tree to obtain the target SQL statement.

[0011] Further, the protected field includes multiple subfields; the rewriting of the original SQL statement based on the data operation type and the SQL syntax tree to obtain the target SQL statement includes: determining whether the query field list contains all the subfields; if not, adding the subfields not included and the integrity identification field to the query field list to obtain the target SQL statement; if all the subfields are included, adding the integrity identification field to the query field list to obtain the target SQL statement.

[0012] Furthermore, the method also includes: for each row of record data of the operation result, obtaining the identification key value of the integrity identification field corresponding to the current row of record data, and searching for the key value corresponding to the protected field in the current row of record data; calculating the first message verification code corresponding to the current row of record data according to the key value corresponding to the protected field; determining the first message verification code corresponding to the current row of record data and verifying it with the identification key value of the integrity identification field corresponding to the current row of record data to obtain the verification result of the current row of record data; traversing all row record data to obtain the verification result corresponding to each row of record data; when the verification results corresponding to each row of record data are all successful, it is determined that the data query operation has passed the integrity check, and the operation result is used as the target query result of the data query operation.

[0013] Furthermore, when the original SQL statement does not meet the statement rewriting standard, the method also includes: executing the original SQL statement to obtain a first query result corresponding to the data query operation; determining whether the query field list contains a preset string; if it contains the preset string, performing an integrity check on the data query operation based on the first query result; when the data query operation passes the integrity check, using the first query result as the target query result of the data query operation; if it does not contain the preset string, using the first query result as the target query result of the data query operation.

[0014] Furthermore, the database table includes a pre-set protected field, and the protected field includes multiple sub-fields; when the data operation type is a data insertion operation, the original SQL statement is rewritten based on the data operation type and the SQL syntax tree to obtain a target SQL statement, including: determining the key value of each sub-field included in the insert field list of the SQL syntax tree from the insert key value list of the SQL syntax tree; calculating a second message verification code according to the key value of each sub-field included in the insert field list; adding an integrity identification field to the insert field list, and adding the second message verification code to the insert key value list, thereby obtaining the target SQL statement.

[0015] Furthermore, the database table includes a pre-set protected field, and the protected field includes multiple subfields; when the data operation type is a data update operation, the original SQL statement is rewritten based on the data operation type and the SQL syntax tree to obtain a target SQL statement, including: when the update field list of the SQL syntax tree includes at least one subfield, searching for the key value of the at least one subfield from the update key value list corresponding to the update field list, and searching for the key value of the subfield included in the where condition statement from the where condition statement, so as to obtain the key value of the first subfield; determining whether the first subfield is all subfields; if it is all subfields, calculating a third message verification code according to the key values ​​of all subfields; adding an integrity identification statement to the original SQL statement, so as to obtain the target SQL statement, and the integrity identification statement is determined by the integrity identification field and the third message verification code.

[0016] Furthermore, after determining whether the first subfield is all the subfields, the method further includes: if the first subfield is not all the subfields, generating a query statement for querying the remaining subfields and primary key values ​​based on the where condition statement and the protected field, the remaining subfields being the fields of all the subfields except the first subfield; calculating a fourth message verification code based on the query execution result of the query statement and the key value of the first subfield; and updating the original SQL statement based on the fourth message verification code to obtain the target SQL statement.

[0017] In a second aspect, the present application provides a device for operating a database table, the device comprising:

[0018] A statement determination module is used to determine the original SQL statement corresponding to the database table operation request;

[0019] A statement analysis module, used for performing syntax analysis on the original SQL statement to obtain a data operation type and an SQL syntax tree of the database table operation request;

[0020] A statement rewriting module, used for rewriting the original SQL statement to obtain a target SQL statement based on the data operation type and the SQL syntax tree;

[0021] The statement execution module is used to execute the target SQL statement to obtain the operation result corresponding to the database table operation request.

[0022] In a third aspect, the present application provides an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the database table operation method described in any embodiment of the present application.

[0023] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the database table operation method described in any embodiment of the present application when executed.

[0024] In order to solve the defects of the prior art in the background technology, the embodiment of the present application provides a method for operating a database table, and the execution of the method can bring the following beneficial effects: the business logic layer in the present application converts the user's database table operation request into the corresponding original SQL statement, and passes the original SQL statement to the integrity protection plug-in; the integrity protection plug-in first interprets the original SQL statement grammatically to determine which data operation type the original SQL statement belongs to, rewrites the SQL statement according to the data operation type and the parameter list in the original SQL statement, and executes the rewritten target SQL statement. The present application does not need to repeatedly write integrity protection code in each data access object in the program business code, which can make business data maintenance simple and easy to operate.

[0025] It should be noted that the above computer instructions may be stored in whole or in part on a computer-readable storage medium, wherein the computer-readable storage medium may be packaged together with the processor of the database table operating device, or may be packaged separately from the processor of the database table operating device, which is not limited in this application.

[0026] The description of the second, third and fourth aspects in this application can refer to the detailed description of the first aspect; and the beneficial effects of the description of the second, third and fourth aspects can refer to the beneficial effect analysis of the first aspect, which will not be repeated here.

[0027] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present application, nor is it intended to limit the scope of the present application. Other features of the present application will become easily understood through the following description.

[0028] It is understandable that before using the technical solutions disclosed in the embodiments of this application, the type, scope of use, and usage scenarios of the personal information involved in this application should be informed to the user and the user's authorization should be obtained in an appropriate manner in accordance with relevant laws and regulations. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0030] Figure 1 A flowchart of a method for operating a database table provided in an embodiment of the present application;

[0031] Figure 2 An overall block diagram of the database table operation provided by the embodiment of the present application;

[0032] Figure 3 A schematic diagram of the processing flow of a data query operation provided in an embodiment of the present application;

[0033] Figure 4 A schematic diagram of the processing flow of a data insertion operation provided in an embodiment of the present application;

[0034] Figure 5 A schematic diagram of a processing flow of a data update operation provided in an embodiment of the present application;

[0035] Figure 6 A schematic diagram of the structure of a database table operation device provided in an embodiment of the present application;

[0036] Figure 7 It is a block diagram of an electronic device used to implement a method for operating a database table in an embodiment of the present application. DETAILED DESCRIPTION

[0037] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this application.

[0038] It should be noted that the terms "first", "second", "target", and "original" in the specification and claims 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 that illustrated or described herein. In addition, the terms "including", "having", and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product, or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products, or devices.

[0039] Figure 1 This is a flowchart of a method for operating a database table provided in an embodiment of the present application. This embodiment can be applied to the case where integrity protection is performed on protected fields in a database table when operating a database table. The method for operating a database table provided in this embodiment can be performed by a device for operating a database table provided in an embodiment of the present application. The device can be implemented in software and / or hardware and integrated in an electronic device that executes the method.

[0040] See also Figure 1 The method of this embodiment includes but is not limited to the following steps:

[0041] S110: Determine an original Structured Query Language (SQL) statement corresponding to the database table operation request.

[0042] A database table is a database object that contains all the data in the database. The database table includes pre-set protected fields, which include multiple subfields. A database table operation request is a request entered by a user on the interactive interface to operate the database. The original SQL statement is a machine language for performing various operations on the database, including adding, deleting, modifying, and querying data.

[0043] When writing data to the database table before executing the solution of this application, the configuration module can be used to define which tables need to be integrity protected, what the primary key field of the table is, which fields of the table are integrity protected, and what the algorithm used for integrity protection is. The data exchange format (JavaScript Object Notation, JSON) can also be used to define the storage method and calculation method of the integrity mark field of each table that needs integrity protection. The configuration fields include primary key information (such as pk), a list of field names for integrity protection (such as mac.fromColumn), a field name for saving integrity identifiers (such as mac.column), and an algorithm used for integrity protection (such as mac.macType). Among them, the integrity protection algorithm can include the national secret SM2 signature, hash-based Message Authentication Code (Hash-based Message Authentication Code, HMAC) and SM4 symmetric encryption, etc.

[0044] In the embodiments of the present application, Figure 2 The figure shows the overall block diagram of database table operation. Users can input database table operation requests on the interactive interface; the business logic layer responds to the database table operation request and calls the Dao layer interface through the data object to operate the database table. The Dao layer directly calls the Object Relational Mapping (ORM) interface in the object mode or handwritten SQL mode to perform data access operations. The ORM will convert the user's database table operation request into a raw SQL statement and parameter list (such as Args), and pass the raw SQL statement and parameter list to the integrity protection plug-in.

[0045] S120: Perform syntax analysis on the original SQL statement to obtain a data operation type and an SQL syntax tree of the database table operation request.

[0046] In the embodiment of the present application, the SQL interpretation module first interprets the original SQL statement grammatically, extracts the parameter values ​​in the original SQL statement, and then determines which data operation type the original SQL statement belongs to, so as to perform different logical branch processing according to the data operation type. The data operation type may include SELECT, UPDATE, INSERT, and others.

[0047] S130 . Rewrite the original SQL statement based on the data operation type and the SQL syntax tree to obtain a target SQL statement.

[0048] It should be noted that when the data operation type is a data query operation, before rewriting the original SQL statement based on the data operation type and the SQL syntax tree to obtain the target SQL statement, it is necessary to first determine whether the original SQL statement meets the statement rewriting standard, specifically: determine whether the query field list in the SQL syntax tree contains protected fields; if it does not contain protected fields, determine that the original SQL statement does not meet the statement rewriting standard; if it contains protected fields, determine that the original SQL statement meets the statement rewriting standard, and rewrite the original SQL statement based on the data operation type and the SQL syntax tree to obtain the target SQL statement.

[0049] Specifically, when the data operation type is a data query operation and the original SQL statement meets the statement rewriting standard, the original SQL statement is rewritten based on the data operation type and the SQL syntax tree to obtain a target SQL statement, including: the protected field includes multiple sub-fields, and based on a pre-configured integrity-protected field name list (mac.fromColumn), it is determined whether the query field list contains all the sub-fields; if not all the sub-fields are included, the sub-fields that are not included are determined, and then the sub-fields that are not included and the integrity identification field (such as mac) are added to the query field list to obtain the target SQL statement; if all the sub-fields are included, the integrity identification field is added to the query field list to obtain the target SQL statement.

[0050] For example, for example, mac.fromColumn = [field1, field2, field3], mac.Column = mac is configured, the original SQL statement is: SELECT field2 FROM table WHERE where_condition, and the target SQL statement after rewriting is: SELECT field2, field1, field3, mac FROM table WHERE where_condition.

[0051] Furthermore, when the original SQL statement does not meet the statement rewriting standard, the operation method of the database table of the present application also includes: executing the original SQL statement to obtain the first query result corresponding to the data query operation; determining whether the query field list contains a preset string; if it contains the preset string, performing an integrity check on the data query operation based on the first query result; when the data query operation passes the integrity check, using the first query result as the target query result of the data query operation; if it does not contain the preset string, indicating that no integrity check is required, avoiding resource waste and improving system performance, the first query result is used as the target query result of the data query operation. Among them, the preset string can be any character set by the user, which can be '*'.

[0052] S140: Execute the target SQL statement to obtain the operation result corresponding to the database table operation request.

[0053] In the embodiment of the present application, the database DB-driver program is called to execute the target SQL statement obtained after rewriting, and the execution result of the target SQL statement is used as the operation result corresponding to the database table operation request. In the case that the protected field needs to be changed due to business changes, the present application does not need to modify the business code, but only needs to modify the configuration to achieve it.

[0054] Furthermore, the operation method of the database table of the present application also includes: for each row of record data of the operation result, obtaining the identification key value of the integrity identification field corresponding to the current row of record data, such as mac; finding the key value corresponding to each subfield in the protected field in the current row of record data. Calculate the first message verification code corresponding to the current row of record data according to the key value corresponding to each subfield, such as macCalValue. Compare mac and macCalValue to see if they are equal, and obtain the verification result of the current row of record data, specifically: if mac is equal to macCalValue, then the verification result is verification success; if mac is not equal to macCalValue, then the verification result is verification failure. Based on the same method, traverse all rows of record data to obtain the verification result corresponding to each row of record data. If the verification results corresponding to each row of record data are all verification success, it is determined that the data query operation has passed the integrity check, and the operation result is used as the target query result of the data query operation. If there is a verification failure in the verification results corresponding to these row record data, then a prompt of the failure of the integrity check is returned.

[0055] The calculation method of the first message authentication code is the same as the calculation method of the identification key value corresponding to the integrity identification field, specifically: in the order of configuring mac.fromColumn, the values ​​of all protected fields are string concatenated, and then the corresponding interface of the cryptographic resource is called to obtain the integrity identification value according to the algorithm defined by mac.macType in the configuration. For example: fromColumn = [field1, field2, field3], for the data {field1 = "field_value1", filed2 = 2, field3 = 4.5}, the string "field_value124.5" is obtained after concatenation.

[0056] The technical solution provided in this embodiment determines the original SQL statement corresponding to the database table operation request, performs syntax analysis on the original SQL statement to obtain the data operation type and SQL syntax tree of the database table operation request, rewrites the original SQL statement based on the data operation type and SQL syntax tree to obtain the target SQL statement, and executes the target SQL statement to obtain the operation result corresponding to the database table operation request. In this application, the business logic layer converts the user's database table operation request into the corresponding original SQL statement, and passes the original SQL statement to the integrity protection plug-in; the integrity protection plug-in first performs syntax interpretation on the original SQL statement to determine which data operation type the original SQL statement belongs to, rewrites the SQL statement according to the data operation type and the parameter list in the original SQL statement, and executes the rewritten target SQL statement. This application does not need to repeatedly write integrity protection code in each data access object in the program business code, which can make business data maintenance simple and easy to operate.

[0057] In a preferred embodiment, the program corresponding to the SQL statement rewriting process in step S130 can be integrated into an integrity protection plug-in, such as an ORM plug-in. The query and execution methods of the database connection object can be rewritten by customizing the plug-in through the ORM Hook capability, intercepting the SQL request to rewrite the SQL to implement the integrity protection mark writing, and intercepting the SQL query to complete the integrity check. Figure 2 As shown, the integrity protection plug-in can realize the functions of including a configuration module, an SQL interpretation module, an SQL rewriting module and a mac calculation module.

[0058] Among them, the SQL interpretation module is used to perform syntax tree analysis on the original SQL statement, extract parameter values, and determine which data operation type (query, update, insert, delete, etc.) the SQL belongs to, so as to perform branch processing for different data operation types. The SQL rewrite module is used to add a mac field that saves the integrity identifier by rewriting SQL for data query operations and to perform integrity verification on other protected fields that do not appear in SQL. For data insertion operations and data update operations, the mac field is added by rewriting SQL. The mac calculation module is used to extract the value of the integrity-protected field in SQL based on the interpretation of the SQL statement, and according to the integrity protection algorithm (HMAC / SM2 signature) defined in the configuration, call the interface corresponding to the cryptographic resource to calculate the mac value, and is also used to perform mac verification on the query results.

[0059] In another embodiment, if Figure 3The figure shows a processing flow diagram of the data query operation. After the original SQL statement is interpreted grammatically to obtain the SQL syntax tree, the query field list in the SQL syntax tree is analyzed to see whether it contains the protected field or the preset string '*'. If neither is contained, no integrity check is required and the original SQL statement is executed directly. If only the preset string is contained, indicating that the SQL statement does not need to be rewritten, the original SQL statement is directly executed and then an integrity check is performed. If all subfields are not contained, when rewriting the SQL statement, the subfields not contained and the integrity identification field (such as mac) are added to the query field list to obtain the target SQL statement, and then an integrity check is performed; if all subfields are contained, when rewriting the SQL statement, the integrity identification field is added to the query field list to obtain the target SQL statement, and then an integrity check is performed.

[0060] The following further optimizes the above embodiment, specifically: when the data operation type is a data insertion operation, the rewriting process of the SQL statement is explained in detail. Figure 4 The figure shows a processing flow diagram of a data insertion operation, which includes the following steps:

[0061] The first step is to determine the key value of each subfield included in the insert field list of the SQL syntax tree from the insert key value list of the SQL syntax tree.

[0062] In the embodiment of the present application, when the data operation type is a data insertion operation, the SQL interpretation module first performs syntax interpretation on the original SQL statement to obtain the syntax tree of the INSERT SQL. According to the order of the protected fields in the mac.fromColumn pre-configured for the protected fields, the key value of each subfield contained in the insert field list (such as col_name) is extracted from the insert key value list (such as value_list) corresponding to the insert field list (such as col_name) of the SQL syntax tree.

[0063] Step 2: Calculate a second message authentication code according to the key value of each subfield included in the inserted field list.

[0064] In an embodiment of the present application, the key value of each subfield contained in the inserted field list is spliced ​​in the order of configuring mac.fromColumn, and then the corresponding interface of the cryptographic resource is called according to the algorithm defined by mac.macType in the configuration to obtain the second message verification code, recorded as mac2Value.

[0065] Step 3: Add the integrity identification field to the insert field list and add the second message verification code to the insert key value list to obtain the target SQL statement.

[0066] In an embodiment of the present application, when rewriting an SQL statement, an integrity identification field mac is added to the insert field list col_name, and a second message verification code mac2Value is added to the insert key value list value_list. For example, the original SQL statement is: INSERT INTO table(field1,field2,field3)VALUES(field_value1,field_value2,field_value3), and the target SQL statement after rewriting is: INSERT INTO table(field1,field2,field3,mac)VALUES(field_value1,field_value2,field_value3,mac2Value).

[0067] The following further optimizes the above embodiment, specifically: when the data operation type is a data update operation, the rewriting process of the SQL statement is explained in detail. Figure 5 The figure shows a processing flow diagram of a data update operation, which includes the following steps:

[0068] The first step is to find the key value of the at least one subfield from the update key value list corresponding to the update field list when the update field list of the SQL syntax tree contains at least one subfield, and find the key value of the subfield contained in the where condition statement from the where condition statement, so as to obtain the key value of the first subfield.

[0069] In an embodiment of the present application, when the data operation type is a data update operation, the original SQL statement is first grammatically interpreted by the SQL interpretation module to obtain the syntax tree of the UPDATE SQL. According to the mac.fromColumn pre-configured for the protected field, check whether the update field list (such as assignment_list) contains at least one subfield. If it does not contain at least one subfield, the original SQL statement is directly executed to obtain the target update result corresponding to the data update operation; if it contains at least one subfield, the key value of the at least one subfield is extracted from the update key value list col_name value corresponding to the update field list assignment_list, and the key value of the protected subfield is extracted from the '=' condition in where_condition. The subfields contained in the update field list assignment_list and the subfields contained in the where condition statement are recorded as the first subfield, thereby obtaining the key value of the first subfield.

[0070] The second step is to determine whether the first subfield is a complete subfield.

[0071] In the embodiment of the present application, according to the mac.fromColumn pre-configured for the protected field, it is determined whether the first subfield is all the subfields. If it is all the subfields, the third step is executed; if it is not all the subfields, the fifth step is executed.

[0072] Step 3: If the first subfield is all subfields, calculate the third message authentication code according to the key values ​​of all subfields.

[0073] In the embodiment of the present application, the key values ​​of all subfields are concatenated in the order of configuring mac.fromColumn, and then the corresponding interface of the cryptographic resource is called according to the algorithm defined by mac.macType in the configuration to obtain the third message verification code, recorded as mac3Value.

[0074] Step 4: Add an integrity identification statement to the original SQL statement to obtain the target SQL statement.

[0075] The integrity identification statement is determined by the integrity identification field and the third message verification code, such as mac=mac3Value.

[0076] For example, assuming that mac.fromColumn is configured as [field1, field2, field3], the original SQL statement is: UPDATE table SET field1 = field1_value, field2 = field2_value2 WHERE field3 = field3_value, and the target SQL statement after rewriting is: UPDATE table SET field1 = field1_value, field2 = field2_value2, mac = mac3Value WHERE field3 = field3_value.

[0077] Step 5: If the first subfield is not all subfields, a query statement for querying the remaining subfields and primary key values ​​is generated based on the where condition statement and the protected field.

[0078] The remaining subfields are fields in all subfields except the first subfield, and the number of subfields in the remaining subfields may be at least one.

[0079] In the embodiment of the present application, when the first subfield is not all subfields, a query statement is generated using the WHERE condition of the original SQL statement, such as: SELECT pk, mac.fromColumn FROM table WHERE where_condition. The protected fields and primary key mapping set of the data set affected by the SQL update are obtained by executing the query statement.

[0080] Step 6: Calculate a fourth message verification code based on the query execution result of the query statement and the key value of the first subfield.

[0081] In an embodiment of the present application, the query execution result includes multiple query records. The key values ​​of the remaining subfields in the current query record are determined, and the key values ​​of the remaining subfields and the key value of the first subfield are concatenated into a string in the order of the protected fields in mac.fromColumn. Then, according to the algorithm defined by mac.macType in the configuration, the corresponding interface of the cryptographic resource is called to obtain the fourth message verification code, recorded as mac4Value.

[0082] Step 7: Update the original SQL statement based on the fourth message verification code to obtain the target SQL statement.

[0083] In the embodiment of the present application, when rewriting an SQL statement, the target SQL statement template after rewriting may be: UPDATE table SET original assignment_list, mac=mac4Value WHERE pk=pkValue.

[0084] Exemplarily, assuming that mac.fromColumn is configured as [field1, field2, field3], the original SQL statement is: UPDATE table SET field1 = field1_value WHERE field4 = field4_value. The query SQL statement generated based on the where condition statement and the protected field is: SELECT field1, field2, field3, pk FROM table WHERE field4 = field4_value. The query SQL statement is executed to obtain the result set: [{field1_old1, field2_value1, filed3_value1, pk_value1}, {field1_old2, field2_value2, filed3_value2, pk_value2}]; the fourth message authentication code is calculated, mac4Value1 = mac(field1_value, field2_value1, field3_value1), mac4Value2 = mac(field1_value, field2_value2, field3_value2). When rewriting SQL statements, the target SQL statements after rewriting are: ["UPDATE table SET field1=field1_value,mac=mac4Value1WHERE pk=pk_value1", "UPDATE table SET field1=field1_value,mac=mac4Value2 WHERE pk=pk_value2"].

[0085] Figure 6 A schematic diagram of a database table operation device provided in an embodiment of the present application is shown in FIG. Figure 6 As shown, the apparatus 600 may include:

[0086] A statement determination module 610, used to determine the original SQL statement corresponding to the database table operation request;

[0087] A statement analysis module 620 is used to perform syntax analysis on the original SQL statement to obtain a data operation type and an SQL syntax tree of the database table operation request;

[0088] A statement rewriting module 630, configured to rewrite the original SQL statement based on the data operation type and the SQL syntax tree to obtain a target SQL statement;

[0089] The statement execution module 640 is used to execute the target SQL statement to obtain the operation result corresponding to the database table operation request.

[0090] Furthermore, the above-mentioned database table operation device may further include: a rewriting standard judgment module;

[0091] Optionally, the database table includes a pre-set protected field;

[0092] The rewriting standard judgment module is used to determine whether the query field list in the SQL syntax tree includes the protected field before rewriting the original SQL statement based on the data operation type and the SQL syntax tree to obtain the target SQL statement when the data operation type is a data query operation; if the protected field is not included, it is determined that the original SQL statement does not meet the statement rewriting standard; if the protected field is included, it is determined that the original SQL statement meets the statement rewriting standard, and triggers the execution of rewriting the original SQL statement based on the data operation type and the SQL syntax tree to obtain the target SQL statement.

[0093] Optionally, the protected field includes multiple subfields;

[0094] Furthermore, the statement rewriting module 630 can be specifically used to: determine whether the query field list contains all subfields; if not, add the subfields not included and the integrity identification field to the query field list to obtain the target SQL statement; if all subfields are included, add the integrity identification field to the query field list to obtain the target SQL statement.

[0095] Furthermore, the above-mentioned database table operation device may also include: an integrity verification module;

[0096] The integrity verification module is used to obtain the identification key value of the integrity identification field corresponding to the current row of record data for each row of record data of the operation result, and search for the key value corresponding to the protected field in the current row of record data; calculate the first message verification code corresponding to the current row of record data according to the key value corresponding to the protected field; determine the first message verification code corresponding to the current row of record data and verify it with the identification key value of the integrity identification field corresponding to the current row of record data to obtain the verification result of the current row of record data; traverse all row record data to obtain the verification result corresponding to each row of record data; when the verification results corresponding to each row of record data are all successful, it is determined that the data query operation has passed the integrity check, and the operation result is used as the target query result of the data query operation.

[0097] Furthermore, the integrity verification module can also be used to execute the original SQL statement when the original SQL statement does not meet the statement rewriting standard to obtain a first query result corresponding to the data query operation; determine whether the query field list contains a preset string; if it contains the preset string, perform an integrity check on the data query operation based on the first query result; when the data query operation passes the integrity check, use the first query result as the target query result of the data query operation; if it does not contain the preset string, use the first query result as the target query result of the data query operation.

[0098] Furthermore, the above statement rewriting module 630 may include: an insert statement execution unit and an update statement execution unit;

[0099] The insert statement execution unit is used to, when the data operation type is a data insertion operation, determine the key value of each subfield included in the insert field list of the SQL syntax tree from the insert key value list of the SQL syntax tree; calculate the second message verification code according to the key value of each subfield included in the insert field list; add an integrity identification field to the insert field list, and add the second message verification code to the insert key value list, so as to obtain the target SQL statement.

[0100] The update statement execution unit is used to, when the data operation type is a data update operation and when the update field list of the SQL syntax tree includes at least one subfield, search for a key value of the at least one subfield from an update key value list corresponding to the update field list, and search for a key value of the subfield included in the where condition statement from a where condition statement, thereby obtaining a key value of a first subfield; determine whether the first subfield is all subfields; if it is all subfields, calculate a third message verification code according to the key values ​​of all subfields; and add an integrity identification statement to the original SQL statement to obtain the target SQL statement, wherein the integrity identification statement is determined by the integrity identification field and the third message verification code.

[0101] The update statement execution unit is further used to, after determining whether the first subfield is all the subfields, if the first subfield is not all the subfields, generate a query statement for querying the remaining subfields and primary key values ​​based on the where condition statement and the protected field, wherein the remaining subfields are the fields of all the subfields except the first subfield; calculate a fourth message verification code based on a query execution result of the query statement and the key value of the first subfield; and update the original SQL statement based on the fourth message verification code to obtain the target SQL statement.

[0102] The database table operation device provided in this embodiment can be applied to the database table operation method provided in any of the above embodiments, and has corresponding functions and beneficial effects.

[0103] Figure 7 It is a block diagram of an electronic device for implementing a method for operating a database table of an embodiment of the present application. Electronic device 10 is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present application described and / or required herein.

[0104] like Figure 7 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0105] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0106] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as the operation method of the database table.

[0107] In some embodiments, the method for operating the database table may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the method for operating the database table described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the method for operating the database table in any other appropriate manner (e.g., by means of firmware).

[0108] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0109] The computer programs for implementing the methods of the present application may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer programs are executed by the processor, the functions / operations specified in the flow charts and / or block diagrams are implemented. The computer programs may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0110] In the context of the present application, a computer readable storage medium may be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, device, or equipment. A computer readable storage medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. Alternatively, a computer readable storage medium may be a machine readable signal medium. A more specific example of a machine readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0111] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).

[0112] The systems and techniques described herein can be implemented in a computing system that includes backend components (e.g., as a data server) or a computing system that includes middleware components (e.g., an application server) or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein) or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0113] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.

[0114] Note that the above are only preferred embodiments of the present application and the technical principles used. Those skilled in the art will understand that the present application is not limited to the specific embodiments described herein, and that various obvious changes, readjustments, and substitutions can be made by those skilled in the art without departing from the scope of protection of the present application. For example, those skilled in the art can use the various forms of processes shown above to reorder, add, or delete steps; the steps recorded in the present application can be performed in parallel, sequentially, or in different orders, as long as the desired results of the technical solution of the present application can be achieved, and this document does not limit them here.

[0115] The above specific implementations do not constitute a limitation on the protection scope of this application. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of this application should be included in the protection scope of this application.

Claims

1. A method for operating a database table, characterized in that: The method comprises: Determine the original structured query language SQL statement corresponding to the database table operation request; Performing syntax analysis on the original SQL statement to obtain the data operation type and SQL syntax tree of the database table operation request; Rewrite the original SQL statement based on the data operation type and the SQL syntax tree to obtain a target SQL statement; Execute the target SQL statement to obtain the operation result corresponding to the database table operation request.

2. The method for operating a database table according to claim 1, characterized in that: The database table includes a pre-set protected field; when the data operation type is a data query operation, before rewriting the original SQL statement based on the data operation type and the SQL syntax tree to obtain a target SQL statement, it also includes: Determine whether the query field list in the SQL syntax tree includes the protected field; If the protected field is not included, determining that the original SQL statement does not meet the statement rewriting standard; If the protected field is included, it is determined that the original SQL statement meets the statement rewriting standard, and triggers execution to rewrite the original SQL statement based on the data operation type and the SQL syntax tree to obtain a target SQL statement.

3. The method for operating a database table according to claim 2, characterized in that: The protected field includes a plurality of subfields; and the rewriting of the original SQL statement based on the data operation type and the SQL syntax tree to obtain a target SQL statement includes: Determine whether the query field list contains all subfields; If all the subfields are not included, the subfields not included and the integrity identification field are added to the query field list to obtain the target SQL statement; If all the sub-fields are included, the integrity identification field is added to the query field list to obtain the target SQL statement.

4. The method for operating a database table according to claim 2, characterized in that: The method further comprises: For each row of record data of the operation result, obtain the identification key value of the integrity identification field corresponding to the current row of record data, and search for the key value corresponding to the protected field in the current row of record data; Calculate the first message verification code corresponding to the current row record data according to the key value corresponding to the protected field; Determine the first message verification code corresponding to the current row of record data and verify it with the identification key value of the integrity identification field corresponding to the current row of record data to obtain the verification result of the current row of record data; Traversing all rows of record data, thereby obtaining the verification result corresponding to each row of record data; When the verification result corresponding to each row of record data is successful, it is determined that the data query operation has passed the integrity check, and the operation result is used as the target query result of the data query operation.

5. The method for operating a database table according to claim 2, characterized in that: When the original SQL statement does not meet the statement rewriting standard, the method further includes: Execute the original SQL statement to obtain a first query result corresponding to the data query operation; Determine whether the query field list contains a preset character string; If the preset character string is included, performing integrity check on the data query operation based on the first query result; When the data query operation passes the integrity check, taking the first query result as the target query result of the data query operation; If the preset character string is not included, the first query result is used as the target query result of the data query operation.

6. The method for operating a database table according to claim 1, characterized in that: The database table includes a pre-set protected field, and the protected field includes a plurality of subfields; when the data operation type is a data insert operation, rewriting the original SQL statement based on the data operation type and the SQL syntax tree to obtain a target SQL statement includes: Determine, from the insert key value list of the SQL syntax tree, the key value of each subfield included in the insert field list of the SQL syntax tree; Calculating a second message authentication code according to the key value of each subfield included in the inserted field list; An integrity identification field is added to the insert field list, and the second message verification code is added to the insert key value list, so as to obtain the target SQL statement.

7. The method for operating a database table according to claim 1, characterized in that: The database table includes a preset protected field, and the protected field includes a plurality of subfields; when the data operation type is a data update operation, rewriting the original SQL statement based on the data operation type and the SQL syntax tree to obtain a target SQL statement includes: When the update field list of the SQL syntax tree includes at least one subfield, searching for a key value of the at least one subfield from an update key value list corresponding to the update field list, and searching for a key value of the subfield included in the where condition statement from a where condition statement, thereby obtaining a key value of the first subfield; Determine whether the first subfield is a complete subfield; If it is all subfields, calculating the third message authentication code according to the key values ​​of all subfields; An integrity identification statement is added to the original SQL statement to obtain the target SQL statement, wherein the integrity identification statement is determined by an integrity identification field and the third message verification code.

8. The method for operating a database table according to claim 7, characterized in that: After determining whether the first subfield is a complete subfield, the method further includes: If the first subfield is not all subfields, a query statement for querying remaining subfields and primary key values ​​is generated based on the where condition statement and the protected field, and the remaining subfields are fields in all subfields except the first subfield; Calculating a fourth message authentication code based on a query execution result of the query statement and a key value of the first subfield; The original SQL statement is updated based on the fourth message verification code to obtain the target SQL statement.

9. A database table operation device, characterized in that: The device comprises: A statement determination module is used to determine the original SQL statement corresponding to the database table operation request; A statement analysis module, used for performing syntax analysis on the original SQL statement to obtain a data operation type and an SQL syntax tree of the database table operation request; A statement rewriting module, used for rewriting the original SQL statement to obtain a target SQL statement based on the data operation type and the SQL syntax tree; The statement execution module is used to execute the target SQL statement to obtain the operation result corresponding to the database table operation request.

10. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the database table operation method described in any one of claims 1 to 8.

11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the database table operation method described in any one of claims 1 to 8 when executed.

Citation Information

Cited By

  • Distributed incremental data synchronization method and device based on Flink

    CN119149648A

  • Data encryption method, electronic device, storage medium and program product

    CN119312363A

  • Data encryption method, electronic device, storage medium, and program product

    CN119312363B

  • Data processing method based on SQL (Structured Query Language) statement, electronic equipment and storage medium

    CN119691814A

  • Method for carrying out data processing on multiple list sets by using SQL (Structured Query Language) statements

    CN120470023A