Database operation statement conversion method, medium, product and equipment
By using the splitting and filling method of matching templates and replacement templates in database operation statements, the problem of insufficient flexibility of conversion rules in existing technologies is solved, realizing flexible conversion and efficient execution of database operation statements, and adapting to cross-database compatibility and dynamic business adjustments.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CETC JINCANG (BEIJING) TECH CO LTD
- Filing Date
- 2025-12-31
- Publication Date
- 2026-04-10
AI Technical Summary
In existing technologies, database operation statement conversion schemes can only support the matching and replacement of constant types, resulting in insufficient flexibility of conversion rules. They cannot accurately match and flexibly replace non-constant content such as table names, target columns, and subquery expressions, making it difficult to meet the needs of cross-database compatibility and dynamic business adjustments, increasing operation and maintenance costs and reducing conversion efficiency.
By acquiring database operation statements and their preset conversion rules, and using matching and replacement templates for splitting and matching, variable content fragments are extracted and filled according to the target replacement template, thereby realizing the conversion of constants and other fields and improving conversion flexibility.
It enables flexible conversion of database operation statements, improves execution efficiency, adapts to multiple scenario requirements, reduces operation and maintenance costs, and ensures business stability without changing the application code.
Smart Images

Figure CN121833748A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of database technology, and in particular to a method, medium, product, and device for converting database operation statements. Background Technology
[0002] In the current database technology field, database operation statements, as the core tools for data interaction, are widely used in data access, management, and analysis scenarios of various business systems. Enterprises often face the need for multi-database deployment, cross-platform data migration, and dynamic adjustment of business rules in practical applications. Different databases (such as relational databases and distributed databases) have significant differences in function names, syntax formats, and pagination logic, making it difficult for the same SQL statement to be compatible across databases, requiring targeted adaptation and modification. At the same time, during business development, frequent needs arise for data structure adjustments, changes in statistical definitions, and upgrades to access control, requiring batch adjustments to the query logic and filtering conditions of existing SQL statements to adapt to new business scenarios.
[0003] In existing technologies, relevant database SQL conversion schemes only support matching and replacement of constant types. This design flaw results in a severe lack of flexibility in conversion rules, making it impossible to accurately match and flexibly replace non-constant elements such as table names, target columns, and subquery expressions. This not only significantly increases operational costs but also reduces the efficiency and adaptability of SQL conversion, making it difficult to meet the actual needs of cross-database compatibility and dynamic business adjustments. Therefore, developing a database operation statement conversion technology with a wider matching range and higher flexibility has become an urgent problem to be solved in this field. Summary of the Invention
[0004] In view of the above problems, the present invention proposes a method, medium, product and device for converting database operation statements to overcome the above problems or at least partially solve the above problems.
[0005] One objective of this invention is to improve the flexibility of database operation statement conversion.
[0006] A further objective of this invention is to meet various conversion requirements in actual business operations.
[0007] Specifically, the present invention provides a method for converting database operation statements, including: Retrieve database operation statements and preset conversion rules, including matching templates and replacement templates; Determine whether the database operation statement conforms to the preset conversion rules based on the matching template; Extract variable content fragments from database operation statements that conform to preset transformation rules. Retrieve the target replacement template corresponding to the database operation statement; The target replacement template is populated with variable content fragments to obtain the transformed database operation statements.
[0008] Optionally, the steps for determining whether a database operation statement conforms to preset conversion rules based on the matching template include: The database operation statement is broken down to obtain the common keywords to be matched in the database operation statement; Retrieve the common keyword combinations recorded in the matching template; Determine whether the generic keyword to be matched is consistent with the combination of generic keywords; If the general keyword to be matched matches the combination of general keywords, the database operation statement is determined to conform to the preset conversion rules.
[0009] Optionally, the steps for extracting variable content fragments from database operation statements include: Retrieve the fuzzy matching identifiers corresponding to different positions in the matching template; Extract variable content fragments that are at the same position as the fuzzy match identifier in the database operation statement, and establish a mapping relationship between the fuzzy match identifier and the variable content fragments.
[0010] Optionally, the step of populating the target replacement template based on variable content fragments includes: Obtain the target fuzzy match identifier at the corresponding position in the target replacement template; Obtain the target variable content fragment corresponding to the target fuzzy matching identifier; The target variable content fragment is filled into the position of the fuzzy matching identifier to obtain the transformed database operation statement.
[0011] Optionally, the fuzzy matching identifier includes: an identifier prefix and a sequence number; The identifier prefix includes special characters; The sequence number is a constant, used to uniquely associate the corresponding variable content fragment.
[0012] Optionally, the variable content fragment includes one or more of the following: table name, column name, constant, subquery expression, and function expression.
[0013] Optionally, after obtaining the transformed database operation statement, the process may also include: Perform syntax validation on the converted database operation statements; If there is a syntax error in the database operation statement, generate an error message.
[0014] According to another aspect of the present invention, a computer-readable storage medium is also provided, on which a computer program is stored, wherein the computer program, when executed by a processor, implements the steps of the database operation statement conversion method described above.
[0015] According to another aspect of the present invention, a computer program product is also provided, comprising a computer program that, when executed by a processor, implements the steps of the database operation statement conversion method described above.
[0016] According to another aspect of the present invention, a computer device is also provided, including a memory, a processor, and a machine-executable program stored in the memory and running on the processor, wherein the processor executes the machine-executable program to implement the steps of the database operation statement conversion method described above.
[0017] The database operation statement conversion method of the present invention first obtains the database operation statement and preset conversion rules, including a matching template and a replacement template; then, it determines whether the database operation statement conforms to the preset conversion rules based on the matching template; if the database operation statement conforms to the preset conversion rules, it extracts variable content fragments from the database operation statement; it obtains the target replacement template corresponding to the database operation statement; and it fills the target replacement template according to the variable content fragments, thereby obtaining the converted database operation statement. This method can convert not only constants but also other fields, greatly improving the flexibility of database operation statement conversion and thus improving the execution efficiency of database operation statements.
[0018] The above and other objects, advantages and features of the present invention will become more apparent to those skilled in the art from the following detailed description of specific embodiments of the invention in conjunction with the accompanying drawings. Attached Figure Description
[0019] The following sections will describe some specific embodiments of the invention in detail by way of example and not limitation, with reference to the accompanying drawings. The same reference numerals in the drawings denote the same or similar parts or portions. Those skilled in the art should understand that these drawings are not necessarily drawn to scale. In the drawings: Figure 1 This is a flowchart illustrating a method for converting database operation statements according to an embodiment of the present invention; Figure 2 This is a flowchart illustrating a method for converting database operation statements according to another embodiment of the present invention; Figure 3 This is a schematic diagram of the matching process of a database operation statement conversion method according to an embodiment of the present invention; Figure 4This is a schematic diagram of the replacement process of a database operation statement conversion method according to an embodiment of the present invention; Figure 5 This is a schematic diagram of a computer program product according to an embodiment of the present invention; Figure 6 This is a schematic diagram of a computer-readable storage medium according to an embodiment of the present invention; and Figure 7 This is a schematic diagram of a computer device according to an embodiment of the present invention. Detailed Implementation
[0020] Those skilled in the art should understand that the embodiments described below are merely a part of the embodiments of the present invention, and not all of the embodiments of the present invention. These partial embodiments are intended to explain the technical principles of the present invention and are not intended to limit the scope of protection of the present invention. Based on the embodiments provided by the present invention, all other embodiments obtained by those skilled in the art without creative effort should still fall within the scope of protection of the present invention.
[0021] It should be noted that the logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be specifically implemented in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus or device (such as a computer-based system, a processor-included system or other system that can fetch and execute instructions from, an instruction execution system, apparatus or device).
[0022] In the current database technology field, SQL (Structured Query Language) is an alternative example of database operation statements. SQL statements have multiple functions such as data manipulation and data definition. This language is interactive and can provide users with great convenience. In specific query processing, the join operation of SQL statements is the core means to realize multi-table data association and complex logical queries, but some SQL statements have room for optimization.
[0023] Figure 1 This is a flowchart illustrating a method for converting database operation statements according to an embodiment of the present invention, as shown below. Figure 1 As shown, the method for converting database operation statements includes at least the following steps S101 to S104.
[0024] Step S101: Obtain database operation statements and preset conversion rules. In this step, the database operation statements can generally be obtained through user input or automatically generated by the database program during operation due to business needs. Those skilled in the art can decide on the method of obtaining the database operation statements based on the actual situation. The preset conversion rules are the core conversion criteria that are pre-configured and stored. Each rule includes a matching template and a replacement template, which together define "which SQL statements need to be converted" and "what kind of SQL statements they need to be converted to."
[0025] In practice, the original database operation statements sent by the client may have compatibility issues (such as incompatibility with cross-database syntax) or efficiency issues (such as redundant query logic), or the actual business may change. Directly modifying the client code in these situations would increase maintenance costs and affect business continuity. Pre-defined conversion rules allow for automatic conversion on the database side, without requiring client awareness, thus ensuring business stability and reducing adaptation costs.
[0026] Step S102: Determine whether the database operation statement conforms to the preset conversion rules. The preset conversion rules are generally set by those skilled in the art based on the actual state of the database or actual business needs.
[0027] In some optional embodiments, the step of determining whether a database operation statement conforms to a preset conversion rule based on a matching template generally includes: splitting the database operation statement to obtain the general keywords to be matched in the database operation statement; obtaining the general keyword combinations recorded in the matching template; determining whether the general keywords to be matched are consistent with the general keyword combinations; and determining that the database operation statement conforms to the preset conversion rule if the general keywords to be matched are consistent with the general keyword combinations. The operation of splitting the database operation statement generally includes: parsing the received original SQL to separate the general keywords to be matched (such as standard SQL keywords like select, from, where, and join); then extracting the keyword combinations from the matching template: extracting predefined general keyword combinations (i.e., fixed SQL keyword sequences in the template) from the matching template of the preset conversion rule; and then performing a consistency check: comparing the general keywords to be matched in the original SQL with the keyword combinations in the matching template; if the types, order, and logical relationships of the two are completely consistent, then determining that the SQL statement conforms to the preset conversion rule.
[0028] This is because existing technologies often limit SQL matching to complete string matching or only support constant substitution, resulting in SQL statements with similar structures but different variable content requiring repeated rule definitions. This method, using a combination of general keywords, can accurately identify SQL statements with similar structures, avoiding invalid matching of irrelevant SQL statements, and breaking through the limitation of "constant-only matching," thus expanding the matching scope.
[0029] Step S103: If the determination in step S102 is yes, extract the variable content fragments from the database operation statement. Variable content fragments generally refer to the variable parts of the SQL statement other than common keywords, including table names, column names, constants, subquery expressions, function expressions, etc. These fragments are the core business carriers of the SQL statement and are also the content that needs to be retained and accurately substituted into the replacement template during the conversion process.
[0030] Optionally, the steps for extracting variable content fragments from database operation statements generally include: obtaining fuzzy matching identifiers corresponding to different positions in the matching template; extracting variable content fragments at the same positions as the fuzzy matching identifiers in the database operation statements, and establishing a mapping relationship between the fuzzy matching identifiers and the variable content fragments. Fuzzy matching identifiers generally adopt a combination structure of "identifier prefix + sequence number," where the identifier prefix is a special character such as #, and the sequence number is a continuous constant (e.g., #1, #2). This identifier is used to mark the position of variable content in the matching and replacement templates, and simultaneously establishes the association between the variable content and the template through the sequence number. It is the core identifier for achieving flexible matching and accurate filling.
[0031] Specifically, when an SQL statement conforms to preset conversion rules, the following operations are performed: First, obtain the fuzzy matching identifiers set in different positions in the matching template; then, extract the content in the original SQL statement that is at the same position as the fuzzy matching identifier as variable content fragments. These fragments include table names, column names, constants, subquery expressions, function expressions, etc.; then, based on the sequence number of the fuzzy matching identifier, establish a one-to-one mapping relationship between the identifier and the corresponding variable content fragment to ensure accurate correspondence during subsequent filling.
[0032] This operation enables precise extraction and ordered association of variable content, overcoming the limitations of existing technologies in flexibly matching complex content such as table names and subqueries. Establishing the mapping relationship provides a clear basis for subsequent replacement and population, ensuring that variable content can be accurately substituted into the replacement template and avoiding content mismatches or omissions.
[0033] Step S104: Obtain the target replacement template corresponding to the database operation statement. The target replacement template is a predefined transformed SQL structure containing a fuzzy matching identifier that matches the matching template sequence number, used to indicate the location where variable content is filled. Furthermore, the standardized design of the replacement template makes the transformation logic highly customizable, allowing for flexible configuration based on differences in database syntax (such as function differences between MySQL and Oracle) or changes in business rules (such as adjustments to statistical standards), adapting to multiple transformation needs. Simultaneously, the template and matching rule correspond one-to-one, ensuring the consistency of the transformation logic.
[0034] Step S105: Fill the target replacement template with the variable content fragments to obtain the transformed database operation statement.
[0035] Optionally, the step of populating the target replacement template based on the variable content fragments generally includes: obtaining the target fuzzy match identifier at the corresponding position in the target replacement template; obtaining the target variable content fragment corresponding to the target fuzzy match identifier; and filling the target variable content fragment into the position where the fuzzy match identifier is located, thereby obtaining the transformed database operation statement. The variable content fragments generally include one or more of the following: table name, column name, constant, subquery expression, and function expression.
[0036] In the target replacement template, find the target fuzzy matching identifier that corresponds one-to-one with the matching template number; according to the identifier number, retrieve the corresponding target variable content fragment from the mapping relationship; substitute the variable content fragment into the position of the corresponding identifier in the replacement template, replace the identifier and reorganize the SQL statement to finally obtain the transformed database operation statement.
[0037] Furthermore, to ensure the correctness of the conversion result, the steps after obtaining the converted database operation statement generally include: performing syntax validity checks on the converted database operation statement; and generating error messages if there are syntax errors in the database operation statement.
[0038] This method enables automated conversion with "fixed structure and flexible content," moving beyond the limitations of constant judgment and replacement. The replacement process preserves the core data of the original SQL while supplementing business logic as needed, greatly improving the flexibility of database operation statements and thus enhancing their execution efficiency.
[0039] Figure 2 This is a flowchart illustrating a method for converting database operation statements according to another embodiment of the present invention, as shown below. Figure 2 As shown, the method for converting database operation statements includes at least the following steps S201 to S209.
[0040] Step S201: Obtain database operation statements and preset conversion rules.
[0041] An example of an optional SQL statement is shown in equation (1): Select count(*) from (select distinct * from t1) v where v.id != 10 Formula (1) In this step, the database server receives the original database operation statement as shown in Equation 1 from the client; simultaneously, it retrieves the corresponding preset transformation rule from the preset query transformation rule table, which includes: Matching template: select #1 from #2 where #3 (where #1 is a fuzzy matching identifier "prefix + sequence number", used to mark the position of variable content in the SQL); Replace template: select 1 from #2 where #3 and v.id = 1 (includes #2 and #3 identifiers that match the template sequence number, used to supplement business logic).
[0042] Step S202: The database operation statement is split to obtain the general keywords to be matched in the database operation statement.
[0043] In this step, the original SQL in equation (1) is parsed and split to extract the common keywords to be matched. The specific process is as follows: Figure 3 As shown, Figure 3 This is a schematic diagram of the matching process of a database operation statement conversion method according to an embodiment of the present invention. First, the three standard SQL keywords, select, from, and where, are extracted from equation (1); then, variable content is excluded. Specifically, count(*) (column statistical expression), (select distinct * from t1) v (subquery), and v.id != 10 (filter condition) are all variable content and are not included in the scope of general keywords. The final sequence of general keywords to be matched is: select→from→where.
[0044] Step S203: Obtain the common keyword combinations recorded in the matching template. Extract the predefined common keyword combinations from the matching template (select #1 from #2 where #3) with preset conversion rules. Specifically: split the matching template according to the fuzzy matching identifiers (#1, #2, #3), exclude the fuzzy areas corresponding to the identifiers; extract the remaining fixed keyword sequence: select → from → where.
[0045] Step S204: Determine whether the general keyword to be matched is consistent with the general keyword combination. Compare the "general keyword to be matched (select→from→where)" extracted in step S202 with the "matching template keyword combination (select→from→where)" obtained in step S203. After comparison, it is found that the two are completely consistent. Therefore, the original SQL shown in the judgment formula (1) conforms to this preset conversion rule.
[0046] Step S205 involves obtaining fuzzy match identifiers corresponding to different positions in the matching template. Specifically, this process typically involves locating and extracting fuzzy match identifiers from different positions within the matching template (select #1 from #2 where #3). The template is then split according to its syntax position; for example, #1 is after select, #2 after from, and #3 after where. #1, #2, and #3 are all in the structure "# (special character prefix) + numeric sequence number," where the sequence number is used to establish a unique association between the identifier and the variable content. This step overcomes the limitation of existing technologies that can only match constants, thus covering complex content such as table names and subqueries, providing technical support for the subsequent flexible extraction of variable content.
[0047] Step S206: Extract the variable content fragment at the same position as the fuzzy matching identifier from the database operation statement, and establish a mapping relationship between the fuzzy matching identifier and the variable content fragment.
[0048] The specific process is as follows: Extract content according to the identifier position: #1 corresponds to count(*) (the statistical expression after select), #2 corresponds to (select distinct * from t1) v (the subquery after from), and #3 corresponds to v.id != 10 (the filter condition after where); then establish the mapping relationship between the identifier and the content (e.g. Figure 3 (The fuzzy matching list in the middle) ensures that each identifier uniquely corresponds to the corresponding variable content.
[0049] Step S207: Obtain the target replacement template corresponding to the database operation statement, and obtain the target fuzzy matching identifier at the corresponding position.
[0050] An optional target replacement template is as follows: Figure 4 As shown, Figure 4 This is a schematic diagram illustrating the replacement process of a database operation statement conversion method according to an embodiment of the present invention. Figure 4 As can be seen, the target replacement template corresponding to the database operation statement is select 1 from #2 where #3 and v.id = 1.
[0051] First, identify the identifiers in the replacement template, specifically #2 (corresponding to the subquery position) and #3 (corresponding to the filter condition position). Then, confirm that the identifier numbers #2 and #3 in the replacement template are completely consistent with those in the matching template to ensure the correct positions during subsequent population. This demonstrates that the replacement template is the vehicle for implementing business logic adjustments. In this step, the replacement template optimizes the original SQL filter condition from "v.id != 10" to "v.id != 10 and v.id = 1" by adding "and v.id = 1", satisfying the business's need for precise queries without requiring modification to the client-side code.
[0052] Step S208: Obtain the target variable content fragment corresponding to the target fuzzy matching identifier. Based on the mapping relationship between identifiers and content established in step S206, retrieve the variable content corresponding to the target fuzzy matching identifier, as follows: Target identifier #2: Match the corresponding variable content fragment from the mapping table (select distinct * fromt1) v; Target identifier #3: Matches the corresponding variable content fragment v.id != 10 from the mapping table; Exclude irrelevant identifiers: Since there is no #1 identifier in the replacement template, the count(*) corresponding to #1 will not be retrieved to avoid invalid content being included.
[0053] Step S209 involves filling the target variable content fragment into the position of the fuzzy matching identifier to obtain the transformed database operation statement. Specifically, the variable content fragment obtained in step S208 is substituted into the corresponding position of the replacement template to generate the transformed database operation statement, such as... Figure 4 As shown, first, fill position #2: substitute (select distinct * from t1) v into position #2 of the replacement template to get "select 1 from (select distinct * from t1) vwhere #3 and v.id = 1"; then fill position #3: substitute v.id != 1 into position #3 of the replacement template to get the final transformation result: select 1 from (select distinct * from t1) v where v.id != 1 and v.id = 1.
[0054] In this transformation result, the replacement SQL changes `select #1` to `select 1`. This is an optimization based on a specific business scenario (e.g., only confirming the existence of records is needed, without returning the original fields). If other data needs to be returned, the replacement template can be modified accordingly. In short, the change in the returned fields in this example is for business scenario adaptation, not a mandatory requirement of the solution. The core of this method is the matching and reorganization logic, and the replacement SQL template can be flexibly defined according to business needs.
[0055] In addition, compared to existing technologies that can only match constants, the #n fuzzy matching identifier of this method can cover complex content such as table names, subqueries, and function expressions.
[0056] This method can not only convert constants, but also other fields, greatly improving the flexibility of database operation statements and thus improving the execution efficiency of database operation statements.
[0057] This invention not only supports scenarios involving adjustments to business logic (such as supplementing filtering conditions in Equation 1), but also adapts to scenarios such as cross-database compatibility (e.g., function conversion from MySQL to Oracle) and data anonymization (e.g., fuzzy processing of mobile phone numbers). Through the innovative design of # + constant fuzzy matching identifiers, this invention breaks through the matching range limitations of existing SQL conversion technologies. Through a concise logic of "split-match-recombination," it achieves batch optimization and conversion of complex SQL statements. Its core value lies in improving database query efficiency while reducing rule maintenance costs without changing the application code.
[0058] The flowchart provided in this embodiment is not intended to indicate that the operations of the method will be performed in any particular order, or that all operations of the method are included in every case. Furthermore, the method may include additional operations. Within the scope of the technical concept provided by the method in this embodiment, additional variations can be made to the above method.
[0059] It should be understood that in some embodiments, the components may be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods may be implemented using software or firmware stored in memory and executed by a suitable instruction execution system.
[0060] This embodiment also provides a computer program product 10, a computer-readable storage medium 20, and a computer device 30. Figure 5 This is a schematic diagram of a computer program product 10 according to an embodiment of the present invention. Figure 6 This is a schematic diagram of a computer-readable storage medium 20 according to an embodiment of the present invention. Figure 7This is a schematic diagram of a computer device 30 according to an embodiment of the present invention. The computer program product 10 includes a computer program 11, which, when executed by the processor 32, implements the steps of the database operation statement conversion method described above. A computer-readable storage medium 20 stores the computer program 11 thereon, which, when executed by the processor 32, implements the steps of the database operation statement conversion method described above. The computer device 30 may include a memory 31, a processor 32, and the computer program 11 stored in the memory 31 and running on the processor 32.
[0061] The computer program 11 used to perform the operations of this invention may be assembly instructions, Instruction Set Architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, state setting data, integrated circuit configuration data, or source code or object code written in any combination of one or more programming languages and procedural programming languages. The computer program 11 may execute entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the latter case, the remote computer may be connected to the user's computer via any type of network, including a Local Area Network (LAN) or Wide Area Network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider). In some embodiments, to perform aspects of this invention, electronic circuits, including, for example, programmable logic circuits, Field-Programmable Gate Arrays (FPGAs), or Programmable Logic Arrays (PLAs), may execute computer-readable program instructions to personalize the electronic circuits by utilizing state information from computer-readable program instructions.
[0062] For the purposes of this embodiment, computer program product 10 is a related product containing computer program 11. For the purposes of this embodiment, computer-readable storage medium 20 is a tangible device capable of holding and storing computer program 11, and can be any device capable of containing, storing, communicating, propagating, or transmitting program 11 for use by or in conjunction with an instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of computer-readable storage medium 20 include: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), static random access memory (SRAM), portable optical disc read-only memory (CD-ROM), digital versatile disc (DVD), memory stick, floppy disk, mechanical encoding device, and any suitable combination thereof.
[0063] Computer device 30 can be, for example, a server, desktop computer, laptop computer, tablet computer, or smartphone. In some examples, computer device 30 can be a cloud computing node. Computer device 30 can be described in the general context of computer system executable instructions (such as program modules) executed by a computer system. Typically, program modules can include routines, programs, object programs, components, logic, data structures, etc., that perform specific tasks or implement specific abstract data types. Computer device 30 can be implemented in a distributed cloud computing environment where tasks are performed by remote processing devices linked through a communication network. In a distributed cloud computing environment, program modules can reside on local or remote computing system storage media, including storage devices.
[0064] Computer device 30 may include a processor 32 adapted to execute stored instructions and a memory 31 that provides temporary storage space for the operation of said instructions during operation. The processor 32 may be a single-core processor, a multi-core processor, a computing cluster, or any other configuration. The memory 31 may include random access memory (RAM), read-only memory, flash memory, or any other suitable storage system.
[0065] Computer device 30 may also include a network adapter / interface and an input / output (I / O) interface. The I / O interface allows external devices that can be connected to the computer device to input and output data. The network adapter / interface provides communication between the computer device and a network, typically represented as a communication network.
[0066] Therefore, those skilled in the art should recognize that although numerous exemplary embodiments of the present invention have been shown and described in detail herein, many other variations or modifications conforming to the principles of the present invention can be directly determined or derived from the disclosure of the present invention without departing from the spirit and scope of the invention. Thus, the scope of the present invention should be understood and construed as covering all such other variations or modifications.
Claims
1. A method for converting database operation statements, comprising: Obtain database operation statements and preset conversion rules, wherein the preset conversion rules include matching templates and replacement templates; Based on the matching template, determine whether the database operation statement conforms to the preset conversion rule; If the database operation statement conforms to the preset conversion rules, extract the variable content fragments in the database operation statement; Obtain the target replacement template corresponding to the database operation statement; The target replacement template is populated with the variable content fragments to obtain the transformed database operation statements.
2. The method for converting database operation statements according to claim 1, wherein, The step of determining whether the database operation statement conforms to the preset conversion rule based on the matching template includes: The database operation statement is split into parts to obtain the general keywords to be matched in the database operation statement; Retrieve the common keyword combinations recorded in the matching template; Determine whether the general keyword to be matched is consistent with the combination of general keywords; If the general keyword to be matched matches the combination of general keywords, the database operation statement is determined to conform to the preset conversion rule.
3. The method for converting database operation statements according to claim 1, wherein, The step of extracting variable content fragments from the database operation statement includes: Obtain the fuzzy matching identifiers corresponding to different positions in the matching template; Extract the variable content fragment at the same position as the fuzzy matching identifier from the database operation statement, and establish a mapping relationship between the fuzzy matching identifier and the variable content fragment to obtain the fuzzy matching list.
4. The method for converting database operation statements according to claim 3, wherein, The step of filling the target replacement template according to the variable content fragment includes: Obtain the target fuzzy matching identifier at the corresponding position from the target replacement template; Obtain the target variable content fragment corresponding to the target fuzzy match identifier from the fuzzy match list; The target variable content fragment is filled into the position of the fuzzy matching identifier to obtain the transformed database operation statement.
5. The method for converting database operation statements according to claim 3, wherein, The fuzzy matching identifier includes: an identifier prefix and a sequence number; The identifier prefix includes special characters; The sequence number is a constant and is used to uniquely associate the corresponding variable content fragment.
6. The method for converting database operation statements according to claim 3, wherein, The variable content fragments include one or more of the following: table name, column name, constant, subquery expression, and function expression.
7. The method for converting database operation statements according to claim 1, wherein, The step of obtaining the converted database operation statement also includes: Perform syntax validity checks on the converted database operation statements; If there is a syntax error in the database operation statement, an error message will be generated.
8. A computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the database operation statement conversion method according to any one of claims 1 to 7.
9. A computer program product comprising a computer program that, when executed by a processor, implements the steps of the method for converting database operation statements according to any one of claims 1 to 7.
10. A computer device comprising a memory, a processor, and a machine-executable program stored in the memory and running on the processor, wherein the processor, when executing the machine-executable program, implements the steps of the database operation statement conversion method according to any one of claims 1 to 7.