Code conversion method and device based on sentence pair equivalent replacement, equipment and medium
By removing the logical NOT operator from the PL/SQL code and replacing it with an equivalent Java logical statement, the error caused by the Null logical NOT operation during the PL/SQL to Java conversion was resolved, ensuring the system runs normally.
Patent Information
- Application Number
- CN202210361948.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-07
- Publication Date
- 2026-02-10
- Estimated Expiration
- 2042-04-07
AI Technical Summary
Existing technologies cannot effectively handle null logical NOT operations when converting PL/SQL statements to Java statements, leading to logical errors and affecting the normal operation of the system.
By obtaining the statement to be transformed in the PL/SQL code, removing the logical NOT operator, and replacing it with an equivalent Java logical statement, we can ensure consistent logical operation results and avoid null logical NOT operations.
It achieves error-free conversion from PL/SQL code to Java code, ensuring the normal operation and logical consistency of the system and avoiding logical errors.
Smart Images

Figure CN114661759B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of database technology, and in particular relates to a code conversion method, apparatus, device, and medium based on statement equivalent replacement. Background Technology
[0002] Procedural Language Structured Query Language (PLSQL) is a programming language that extends SQL statements by adding logical judgments and loops to ordinary SQL statements, enabling more complex data reading and is widely used in system development.
[0003] As the business logic of the database system begins to use Java, it becomes necessary to automatically convert the written PL / SQL statements into Java statements. In PL / SQL statements, Boolean values include True, False, and Null, and logical operations can be performed on Null. However, Java statements do not include Null as a Boolean value. Common code conversion methods only convert between the description methods of the two languages. In PL / SQL, the result of a logical NOT operation on Null is False, while in Java it is True. Directly converting the logical NOT expression for Null may result in logical errors after conversion, affecting the normal operation of the system. Summary of the Invention
[0004] The following is an overview of the subject matter described in detail herein. This overview is not intended to limit the scope of the claims.
[0005] This invention provides a code conversion method, apparatus, device, and medium based on statement equivalent substitution, which can perform equivalent conversion of PL / SQL statement expressions, eliminate logical NOT operations involving null, avoid logical errors after conversion to Java, and ensure the normal operation of the database system.
[0006] In a first aspect, embodiments of the present invention provide a code transformation method based on statement equivalent replacement, including:
[0007] Obtain the statement to be converted from the PL / SQL code to be converted. The statement to be converted includes a first operator and a first logical statement. The first operator is used to perform a logical NOT operation on the logical operation result of the first logical statement. The logical operation result of the first logical statement is Null.
[0008] Obtain the target logical operation result of the statement to be converted;
[0009] Remove the first operator and convert the first logical statement into a second logical statement. The logical operation result of the second logical statement is the target logical operation result.
[0010] Replace the statement to be converted in the PLSQL code with the second logical statement to obtain the target PLSQL code;
[0011] The target PL / SQL code is converted into the target Java code.
[0012] In some embodiments, the first logical statement includes a first operation expression, a second operation expression, and a second operator, wherein the second operator is used to perform logical operations on the operation result of the first operation expression and the operation result of the second operation expression, and the step of converting the first logical statement into a second logical statement includes:
[0013] A third operator and a fourth operator are generated. The third operator is used to perform a logical NOT operation on the result of the first operation expression, and the fourth operator is used to perform a logical NOT operation on the result of the second operation expression.
[0014] When the second operator is a logical AND operator, change the second operator to a logical OR operator; or, when the second operator is a logical OR operator, change the second operator to a logical AND operator.
[0015] The second logical statement is obtained based on the first operation expression, the second operation expression, the second operator, the third operator, and the fourth operator.
[0016] In some embodiments, obtaining the second logical statement based on the first operation expression, the second operation expression, the second operator, the third operator, and the fourth operator includes:
[0017] The first operation expression and the third operator are converted into a third operation expression, the result of which is the opposite of the result of the first operation expression;
[0018] The second operation expression and the fourth operator are transformed into a fourth operation expression, the result of which is the opposite of the result of the second operation expression;
[0019] The third operation expression, the second operator, and the fourth operation expression are combined to form the second logical statement.
[0020] In some embodiments, the operation type of the first logical statement is an assignment operation, and the step of converting the first logical statement into a second logical statement includes:
[0021] Retrieve the pre-defined wrapper class;
[0022] The first logical statement is converted into the second logical statement belonging to the assignment wrapper class.
[0023] In some embodiments, converting the first logical statement into a second logical statement belonging to the assignment wrapper class includes:
[0024] The fifth operation expression is determined from the first logical statement, and the operation type corresponding to the fifth operation expression is an assignment operation;
[0025] Obtain the description rules of the assignment wrapper class, wherein the description rules record the description method of each assignment operation in the assignment wrapper class;
[0026] The fifth operation expression is rewritten according to the description rules to obtain the sixth operation expression belonging to the assignment wrapper class;
[0027] The second logical statement is obtained by performing a logical NOT operation on the sixth operational expression.
[0028] In some embodiments, the first logical statement includes at least two logical sub-statements, and the step of converting the first logical statement into a second logical statement includes:
[0029] Each of the aforementioned logical sub-statements is converted into an intermediate sub-statement;
[0030] The second logical statement is obtained based on all the intermediate sub-statements.
[0031] In some embodiments, before replacing the statement to be converted in the PLSQL code with the second logical statement, the method further includes:
[0032] Convert the second logical statement into an alternative Java statement;
[0033] The result of the operation of the candidate Java statement is determined to be the result of the target logical operation.
[0034] Secondly, embodiments of the present invention provide a code conversion apparatus based on statement-to-statement substitution, comprising:
[0035] The statement acquisition unit is used to acquire the statement to be converted in the PLSQL code to be converted. The statement to be converted includes a first operator and a first logical statement. The first operator is used to perform a logical NOT operation on the logical operation result of the first logical statement. The logical operation result of the first logical statement is Null.
[0036] The result determination unit is used to obtain the target logical operation result of the statement to be converted;
[0037] The statement conversion unit is used to remove the first operator and convert the first logical statement into a second logical statement, wherein the logical operation result of the second logical statement is the target logical operation result.
[0038] The statement replacement unit is used to replace the statement to be converted in the PLSQL code to be converted with the second logical statement to obtain the target PLSQL code;
[0039] The code conversion unit is used to convert the target PL / SQL code into target Java code.
[0040] Thirdly, embodiments of the present invention provide an electronic device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the code conversion method based on statement-to-statement substitution as described in the first aspect.
[0041] Fourthly, embodiments of the present invention provide a computer-readable storage medium storing a computer program for performing the code conversion method based on statement-to-statement substitution as described in the first aspect.
[0042] This invention includes the following steps: obtaining a statement to be converted from PL / SQL code, the statement to be converted including a first operator and a first logical statement, the first operator being used to perform a logical NOT operation on the logical operation result of the first logical statement, the logical operation result of the first logical statement being Null; obtaining the target logical operation result of the statement to be converted; removing the first operator, converting the first logical statement into a second logical statement, the logical operation result of the second logical statement being the target logical operation result; replacing the statement to be converted in the PL / SQL code with the second logical statement to obtain target PL / SQL code; and converting the target PL / SQL code into target Java code. According to the technical solution of this embodiment, when the logical operation result of the first logical statement in the statement to be converted is Null, the statement to be converted can be replaced by an equivalent second logical statement, avoiding logical NOT operations on Null in the PL / SQL code to be converted, ensuring that the operation logic remains unchanged after conversion to Java statements, and ensuring normal system operation.
[0043] Other features and advantages of the invention will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention may be realized and obtained by means of the structures particularly pointed out in the description, claims, and drawings. Attached Figure Description
[0044] The accompanying drawings are provided to further understand the technical solutions of the present invention and constitute a part of the specification. They are used together with the embodiments of the present invention to explain the technical solutions of the present invention, and do not constitute a limitation on the technical solutions of the present invention.
[0045] Figure 1 This is a flowchart of a code conversion method based on statement equivalent replacement provided in an embodiment of the present invention;
[0046] Figure 2 This is a flowchart of the conversion of a first logical statement into a second logical statement provided in another embodiment of the present invention;
[0047] Figure 3 This is a flowchart illustrating the conversion of an operational expression into a second logical statement, provided in another embodiment of the present invention.
[0048] Figure 4 This is a flowchart of converting a wrapper class into a second logical statement through assignment, provided in another embodiment of the present invention;
[0049] Figure 5 This is a flowchart of the conversion process for the assignment wrapper class provided in another embodiment of the present invention;
[0050] Figure 6This is a flowchart of the transformation of logical substatements provided in another embodiment of the present invention;
[0051] Figure 7 This is a flowchart of the verification of the operation result after the transformation of the second logical statement provided in another embodiment of the present invention;
[0052] Figure 8 This is a structural diagram of a code conversion device based on statement equivalent replacement provided in another embodiment of the present invention;
[0053] Figure 9 This is a device diagram of an electronic device provided in another embodiment of the present invention. Detailed Implementation
[0054] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0055] It should be noted that although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. Terms such as "first," "objective," etc., in the specification, claims, or the aforementioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.
[0056] This invention provides a code conversion method, apparatus, device, and medium based on statement equivalent replacement. The method includes: obtaining a statement to be converted from PL / SQL code to be converted, the statement to be converted including a first operator and a first logical statement, the first operator being used to perform a logical NOT operation on the logical operation result of the first logical statement, the logical operation result of the first logical statement being Null; obtaining a target logical operation result of the statement to be converted; removing the first operator, converting the first logical statement into a second logical statement, the logical operation result of the second logical statement being the target logical operation result; replacing the statement to be converted in the PL / SQL code to be converted with the second logical statement to obtain target PL / SQL code; and converting the target PL / SQL code into target Java code. According to the technical solution of this embodiment, when the logical operation result of the first logical statement in the statement to be converted is Null, the statement to be converted can be equivalently replaced by the second logical statement, avoiding the logical NOT operation for Null in the PL / SQL code to be converted, ensuring that the operation logic remains unchanged after conversion to Java statements, and ensuring normal system operation.
[0057] In this application, a database refers to an organized and shareable collection of data stored in a computer. The data in the database refers to data organized using a specific data model.
[0058] Database operation statements are programming languages used to manipulate data in a database. For example, database operation statements can be, but are not limited to, programming languages used to add, delete, modify, and query data in a database. They can also be, but are not limited to, SQL statements in MySQL or Oracle databases. Online data processing requests are requests made by users in a specific business scenario to request corresponding services. The type of database operation statement requested in an online data processing request can be determined based on its content. This request type includes, but is not limited to, adding, deleting, modifying, and querying data. Specifically, the database operation statement can be determined based on the content of the online data processing request. For example, an online data processing request might be for adding data to a database, querying data in a database, or deleting or modifying data in a database.
[0059] It should be noted that the database in this embodiment of the invention can be deployed on a server. The server can be an independent server or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms.
[0060] like Figure 1 As shown, Figure 1 This is a flowchart of a code conversion method based on statement equivalent substitution provided in an embodiment of the present invention. The code conversion method based on statement equivalent substitution includes, but is not limited to, the following steps:
[0061] Step S110: Obtain the statement to be converted from the PLSQL code to be converted. The statement to be converted includes a first operator and a first logical statement. The first operator is used to perform a logical NOT operation on the logical operation result of the first logical statement. The logical operation result of the first logical statement is Null.
[0062] Step S120: Obtain the target logical operation result of the statement to be converted;
[0063] Step S130: Remove the first operator and convert the first logical statement into a second logical statement. The logical operation result of the second logical statement is the target logical operation result.
[0064] Step S140: Replace the statement to be converted in the PLSQL code to be converted with the second logical statement to obtain the target PLSQL code;
[0065] Step S150: Convert the target PL / SQL code into the target Java code.
[0066] It should be noted that the PL / SQL code to be converted can be a code segment composed of multiple PL / SQL statements, or a PL / SQL file containing multiple PL / SQL statements. This embodiment does not impose excessive limitations on the specific way the PL / SQL code to be converted is recorded; the goal is simply to obtain the statements to be converted from the PL / SQL code. It is understood that the PL / SQL code to be converted can include any number of statements to be converted. When multiple statements to be converted are obtained, the method of this embodiment can be executed for each individual statement, which will not be repeated hereafter.
[0067] It should be noted that the statement to be converted in this embodiment is a Bool type statement. Since the value of a non-Bool type statement does not involve Null, it will not involve logical NOT operations on Null. Therefore, no logical error will occur after conversion to Java statement. Thus, non-Bool type statements to be converted are not within the scope of this embodiment and will not be repeated hereafter.
[0068] It should be noted that the statement to be converted is a statement written in PL / SQL. The first operator is used to perform a logical NOT operation on the first logical statement. Therefore, the first operator can be the "Not" operator in PL / SQL. The logical operation result of the first logical statement is Null, so the first logical statement can be a conditional statement in an If / Case statement, or an assignment statement of type Boolean. For example, the statement to be converted can be if(not(a>b)). In this statement, the first logical statement is a>b, and the first operator is not. When either a or b is Null, the logical operation result of a>b is Null. In PL / SQL, the logical operation result of Not Null is False, while in Java, the logical operation result is True, resulting in a logical error. However, logical statements other than Not Null will not produce logical errors after conversion. Therefore, after obtaining the statement to be converted, it is necessary to eliminate the Not operator through statement equivalence conversion to ensure that the converted Java statement is logically the same as the PL / SQL statement, ensuring the normal operation of the system.
[0069] It should be noted that, as described above, the target logical operation result of the statement to be converted needs to be determined first. After the statement is converted to its equivalent form, it is used to verify the correctness of the second logical statement. The target logical operation result can be determined according to the logical operation method of PL / SQL statements, which will not be elaborated here.
[0070] It's important to note that since the first operator is the logical NOT operator, after removing it, the remaining first logical statement has the opposite logical operation result to the statement to be transformed. Therefore, the first logical statement needs to be transformed so that the result of the resulting second logical statement is the same as the target logical operation result. Furthermore, the second logical statement has a different form than the statement to be transformed; that is, the outermost logical operator of the second logical statement is not NOT. For example, if the statement to be transformed is `if(not(a=b))`, the target logical operation result is `a ≠ b`. After removing the first operator, the resulting statement is `If(a=b)`. Therefore, the first logical statement needs to be transformed into the second logical statement `a != b`, whose logical operation result is `a ≠ b`, the same as the target logical operation result. Of course, the second logical statement can also be transformed into other forms, as long as the NOT NULL statement is avoided. By replacing the statement to be transformed with the second logical statement, equivalent statement transformation is achieved, eliminating the logical NOT operation for NULL in the PL / SQL code and ensuring that the logic remains consistent after the target PL / SQL code is converted into Java code.
[0071] It should be noted that the process of converting the target PL / SQL code into Java code after performing equivalent substitution of statements is a technique well known to those skilled in the art, and will not be elaborated here for the sake of simplicity.
[0072] In another embodiment, the first logical statement includes a first operation expression, a second operation expression, and a second operator. The second operator is used to perform logical operations on the result of the first operation expression and the result of the second operation expression, as shown below. Figure 2 , Figure 1 Step S130 of the illustrated embodiment also includes, but is not limited to, the following steps:
[0073] Step S210: Generate a third operator and a fourth operator. The third operator is used to perform a logical NOT operation on the result of the first operation expression, and the fourth operator is used to perform a logical NOT operation on the result of the second operation expression.
[0074] Step S220: When the second operator is a logical AND operator, change the second operator to a logical OR operator; or, when the second operator is a logical OR operator, change the second operator to a logical AND operator.
[0075] Step S230: Obtain the second logical statement based on the first operation expression, the second operation expression, the second operator, the third operator, and the fourth operator.
[0076] It should be noted that the operation expression can be a single variable or a statement that can perform data processing. For example, the operation expression can be a variable a or a = "1". This embodiment does not impose too many restrictions on the specific form of the operation expression.
[0077] It should be noted that when the first logical statement includes at least two operation expressions, removing the first operator is equivalent to taking the NOT set of the result of the first logical statement. Therefore, the second operator between the two operation expressions needs to be converted to ensure that the logical operation result of the second logical statement is the same as the target logical operation result. The conversion of the second logical statement can be based on the following rules: not(a||b) = (not a)&&(not b), or not(a&&b) = (not a)||(not b), where a is the first operation expression, b is the second operation expression, the second operator is the logical OR operator "||" or the logical AND operator "&&", and the third and fourth operators are both not operators. According to the above rules, the Not operator of the statement to be converted can be pushed down to the innermost atomic expression, thereby removing the first operator and avoiding logical operation errors.
[0078] To better illustrate the technical solution of this embodiment, a specific example is given below. In this example, the statement to be converted is if not(a||b). The first operator is not, the first operation expression is a, the second operator is the logical OR operator "||", and the second operation expression is b. According to the above rules, the second logical statement can be obtained as (not a)&&(not b). When a is Null and b is True, the target logical operation result obtained by not(a||b) is False. The logical operation result of the second logical statement is False&&False=False. Therefore, the statement can be replaced by if((not a)&&(not b)) and converted into a Java statement. In the Java statement, the logical operation result of (not a)&&(not b) is True&&False=False. After conversion, the logical operation remains consistent.
[0079] Additionally, in one embodiment, reference is made to Figure 3 , Figure 2 Step S230 of the illustrated embodiment also includes, but is not limited to, the following steps:
[0080] Step S310: Convert the first operation expression and the third operator into a third operation expression, the result of which is the opposite of the result of the first operation expression;
[0081] Step S320: Convert the second operation expression and the fourth operator into a fourth operation expression, the result of which is the opposite of the result of the second operation expression;
[0082] Step S330: Combine the third operation expression, the second operator, and the fourth operation expression to form the second logical statement.
[0083] It should be noted that after removing the first operator, to further ensure the logical operation of NotNull occurs, the third and fourth operators can be removed according to pre-defined rules. As described in the above embodiment, the third and fourth operators are Not operators. Therefore, removing the third and fourth operators is equivalent to inverting the first and second operation expressions. Thus, it is necessary to ensure that the resulting third operation expression is the opposite of the first operation expression, and the fourth operation expression is the opposite of the second operation expression. For example, for the statement not(a=b), the first operation expression is a=b, and the third operator is not. The resulting third operation expression can be a!=b, where "!=" represents the inequality sign. Similarly, for the statement Not(x is not null), the second operation expression is "x is not null", and the fourth operator is Not. The resulting fourth operation expression can be "x is null". Regarding a! The conversion of =b and x is null into Java statements can effectively avoid logical errors. The above conversion process is only an example and does not limit the technical solution of this embodiment. It is sufficient to ensure that the outermost operator of the converted third and fourth operation expressions is not the not operator.
[0084] In another embodiment, the operation type of the first logical statement is an assignment operation, see reference. Figure 4 , Figure 1 Step S130 of the illustrated embodiment also includes, but is not limited to, the following steps:
[0085] Step S410: Obtain the pre-defined assignment wrapper class;
[0086] Step S420: Convert the first logical statement into a second logical statement belonging to the assignment wrapper class.
[0087] It should be noted that, Figure 2 and Figure 3The implementation example targets a logical operation type for the first logical statement, while the Bool type can also be an assignment operation. For example, the first logical statement could be `bool v_flag := (p_no>0||p_type != 5)`. When the result of `(p_no>0||p_type != 5)` is Null, the statement to be converted, combined with the first operator, is `Not Null`, which cannot be correctly converted into a Java statement. Furthermore, assignment operations cannot be applied. Figure 2 The rules of the illustrated embodiment are transformed. Therefore, in order to ensure that the assignment operation remains logically correct during the transformation process, an assignment wrapper class can be set in advance to transform the first logical statement into a second logical statement belonging to the assignment wrapper class. This way, after being transformed into a Java statement, the parsing of the second logical statement calls the assignment wrapper class instead of directly parsing the second logical statement, thereby ensuring that the result of the target logical operation remains consistent.
[0088] It should be noted that the wrapper class is a class commonly used by those skilled in the art in the process of PL / SQL programming. The specific setting method can be set according to the logical operators involved in the PL / SQL code. This embodiment will not elaborate on this.
[0089] Additionally, in one embodiment, reference is made to Figure 5 , Figure 4 Step S420 of the illustrated embodiment also includes, but is not limited to, the following steps:
[0090] Step S510: Determine the fifth operation expression from the first logical statement. The operation type corresponding to the fifth operation expression is an assignment operation.
[0091] Step S520: Obtain the description rules of the assignment wrapper class. The description rules record the description method of each assignment operation in the assignment wrapper class.
[0092] Step S530: Rewrite the fifth operation expression according to the description rules to obtain the sixth operation expression belonging to the assignment wrapper class;
[0093] Step S540: Perform a logical NOT operation on the sixth operation expression to obtain the second logical statement.
[0094] It should be noted that for the first logical statement of the assignment operation, the assignment operator usually has a variable definition on one side and an assignment logical operation on the other side. The variable definition does not involve specific logical operations and there is no possibility of errors after conversion to Java. Therefore, for the first logical statement of the assignment operation, only the assignment logical operation part needs to be converted, that is, the fifth operation expression of the first logical statement needs to be converted.
[0095] It should be noted that since the transformation of the fifth operation expression is implemented through an assignment wrapper class, and the assignment wrapper class can be a pre-configured class, the description rules of the assignment wrapper class can be obtained. Based on these description rules, the fifth operation expression is transformed into a statement equivalent to obtain the sixth operation expression. Since the sixth operation expression and the fifth operation expression are equivalent transformations, and the second logical statement is the negation set of the first logical statement, after obtaining the sixth operation expression, a logical NOT operation is performed on the sixth operation expression to obtain the second logical statement. To better illustrate the technical solution of this embodiment, a specific example is provided below:
[0096] In this example, the description rules for the assignment wrapper class are defined for different operators. For example, the logical NOT operator is defined as `not`, the logical OR operator as `orOp`, the logical AND operator as `andOp`, and the Bool type numeric value as `toBool`. For the first logical statement `boolv_flag := (p_no>0||p_type != 5)`, the fifth operation expression can be obtained by traversing the syntax tree. For example, starting from "=", the traversal continues until the statements within the parentheses are described, i.e., the fifth operation expression is `(p_no>0||p_type != 5)`. In this case, if the logical operator in the fifth operation expression is the logical OR operation "||", then according to the description rules of the wrapper class, the sixth expression can be (p_no>0orOpp_type!=5). After the sixth expression is converted to a Java statement, it becomes: (p_no.bgt(0).orOp(p_type.bne(5))). During the logical operation of orOp, the assignment wrapper class is called to determine that the operation is a logical OR operation, thereby ensuring that the sixth operation expression is consistent with the fifth operation expression, effectively avoiding logical errors after the statement of the assignment operation class is converted to Java.
[0097] In another embodiment, the first logical statement includes at least two logical sub-statements, as shown below. Figure 6 , Figure 1 Step S130 of the illustrated embodiment also includes, but is not limited to, the following steps:
[0098] Step S610: Convert each logical substatement into an intermediate substatement;
[0099] Step S620: Obtain the second logical statement based on all intermediate sub-statements.
[0100] It should be noted that when the first logical statement includes at least two logical substatements, it can be based on... Figure 2 and Figure 3The illustrated embodiment performs equivalent conversion for each logical sub-statement. For example, if the first logical statement is not(not(a=b)||not(c=d)), the first logical sub-statement is not(a=b), and the second logical sub-statement is not(c=d), then it can be converted according to... Figure 2 and Figure 3 The illustrated embodiment transforms the first logical substatement into the first intermediate substatement a!=b and the second intermediate substatement c!=d. The two intermediate substatements are then merged to obtain not((a!=b)||(c!=d)). The execution of the above statement... Figure 2 and Figure 3 The equivalent conversion described in the embodiment yields the final second logical statement; the specific process will not be repeated here.
[0101] Additionally, in one embodiment, reference is made to Figure 7 In execution Figure 1 Before step S140 in the illustrated embodiment, the following steps may also be included, but are not limited to:
[0102] Step S710: Convert the second logical statement into an alternative Java statement;
[0103] Step S720: Determine the operation result of the candidate Java statement as the target logical operation result.
[0104] It should be noted that after obtaining the second logical statement, although its logical operation result is the target logical operation result, in order to ensure that the logical operation remains consistent after conversion into Java statements, the second logical statement can be converted into an alternative Java statement, and the operation result of the alternative Java statement can be determined. For example, if the second logical statement is x! = b, the alternative Java statement is x.ne(b), and its operation result is consistent with the target logical operation result, then the second logical statement can replace the statement to be converted to obtain the target PL / SQL code.
[0105] Reference Figure 8 The present invention also provides a code conversion device based on statement equivalent substitution, the code conversion device 800 based on statement equivalent substitution includes, but is not limited to, the following devices:
[0106] The statement acquisition unit 810 is used to acquire the statement to be converted in the PLSQL code to be converted. The statement to be converted includes a first operator and a first logical statement. The first operator is used to perform a logical NOT operation on the logical operation result of the first logical statement. The logical operation result of the first logical statement is Null.
[0107] Result determination unit 820 is used to obtain the target logical operation result of the statement to be converted;
[0108] The statement conversion unit 830 is used to remove the first operator and convert the first logical statement into a second logical statement. The logical operation result of the second logical statement is the target logical operation result.
[0109] Statement replacement unit 840 is used to replace the statement to be converted in the PLSQL code to be converted with the second logical statement to obtain the target PLSQL code;
[0110] Code conversion unit 850 is used to convert target PL / SQL code into target Java code.
[0111] Additionally, refer to Figure 9 An embodiment of the present invention also provides an electronic device 900, which includes: a memory 910, a processor 920, and a computer program stored in the memory 910 and executable on the processor 920.
[0112] The processor 920 and memory 910 can be connected via a bus or other means.
[0113] The non-transient software program and instructions required to implement the code conversion method based on statement substitution in the above embodiments are stored in memory 910. When executed by processor 920, the code conversion method based on statement substitution in the above embodiments is executed, for example, the method described above is executed. Figure 1 Method steps S110 to S150 Figure 2 Method steps S210 to S230, Figure 3 Method steps S310 to S330, Figure 4 Method steps S410 to S420 Figure 5 Method steps S510 to S530, Figure 6 Method steps S610 to S620 Figure 7 Method steps S710 to S720.
[0114] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0115] Furthermore, one embodiment of the present invention provides a computer-readable storage medium storing a computer program that is executed by a processor or controller, for example, by a processor in the above-described electronic device embodiment, causing the processor to perform the code transformation method based on statement-to-statement substitution in the above-described embodiments, for example, performing the above-described... Figure 1 Method steps S110 to S150 Figure 2 Method steps S210 to S230, Figure 3 Method steps S310 to S330, Figure 4 Method steps S410 to S420 Figure 5 Method steps S510 to S530, Figure 6 Method steps S610 to S620 Figure 7 The method steps S710 to S720 are described above. Those skilled in the art will understand that all or some of the steps and apparatus in the methods disclosed above can be implemented as software, firmware, hardware, and suitable combinations thereof. Some or all physical components can be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit. Such software can be distributed on a computer-readable storage medium, which can include computer storage media (or non-transitory storage media) and communication storage media (or temporary storage media). As is known to those skilled in the art, the term computer storage medium includes volatile and non-volatile, removable and non-removable storage media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disc (DVD) or other optical disc storage, magnetic cartridges, magnetic tape, disk storage or other magnetic storage devices, or any other storage medium that can be used to store desired information and is accessible by a computer. Furthermore, as is known to those skilled in the art, communication storage media typically contain computer-readable instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery storage medium.
[0116] This embodiment can be used in numerous general-purpose or special-purpose computer device environments or configurations. Examples include: personal computers, server computers, handheld or portable electronic devices, tablet-type electronic devices, multiprocessor devices, microprocessor-based devices, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above devices or electronic devices, etc. This application can be described in the general context of a computer program executed by a computer, such as a program module. Generally, a program module includes routines, programs, objects, components, data structures, etc., that perform a specific task or implement a specific abstract data type. This application can also be practiced in distributed computing environments where tasks are performed by remote processing electronic devices connected via a communication network. In a distributed computing environment, program modules can reside in local and remote computer storage media, including storage electronic devices.
[0117] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. Each block in the flowchart or block diagram may represent a module, segment, or portion of code, which includes one or more programs for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, or they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that individual blocks in the block diagram or flowchart, and combinations of blocks in the block diagram or flowchart, can be implemented using dedicated hardware-based devices that perform the specified functions or operations, or using a combination of dedicated hardware and computer instructions.
[0118] The units described in the embodiments of this application can be implemented in software or hardware, and the described units can also be located in a processor. The names of these units do not necessarily limit the specific unit itself.
[0119] It should be noted that although several modules or units for the electronic device used to perform actions have been mentioned in the detailed description above, this division is not mandatory. In fact, according to the embodiments of this application, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.
[0120] Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions according to the embodiments of this application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, external hard drive, etc.) or on a network, including several instructions to cause a computing electronic device (such as a personal computer, server, touch terminal, or network electronic device, etc.) to execute the method according to the embodiments of this application.
[0121] The electronic device in this embodiment may include components such as: radio frequency (RF) circuitry, memory, input unit, display unit, sensor, audio circuitry, wireless fidelity (WiFi) module, processor, and power supply. The RF circuitry can be used for receiving and transmitting signals during information transmission or calls, specifically receiving downlink information from the base station and processing it with the processor; additionally, it can send uplink data to the base station. Typically, the RF circuitry includes, but is not limited to, an antenna, at least one amplifier, a transceiver, a coupler, a low-noise amplifier (LNA), and a duplexer. Furthermore, the RF circuitry can also communicate wirelessly with networks and other devices. The aforementioned wireless communication can use any communication standard or protocol, including but not limited to Global System for Mobile Communications (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Long Term Evolution (LTE), email, and Short Messaging Service (SMS). The memory can be used to store software programs and modules. The processor executes various functional applications and data processing of the electronic device by running the software programs and modules stored in the memory. The memory can mainly include a program storage area and a data storage area. The program storage area can store the operating system, applications required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area can store data created according to the use of the electronic device (such as audio data, telephone book, etc.). In addition, the memory can include high-speed random access memory, and can also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. The input unit can be used to receive input digital or character information, and generate key signal input related to the settings and function control of the electronic device. Specifically, the input unit can include a touch panel and other input devices. The touch panel, also known as a touch screen, can collect touch operations on or near it (such as operations using fingers, styluses, or any suitable object or accessory on or near the touch panel) and drive the corresponding connected devices according to a pre-set program. Optionally, the touch panel can include two parts: a touch detection device and a touch controller.The touch detection device detects the touch location and the signal generated by the touch operation, transmitting the signal to the touch controller. The touch controller receives touch information from the touch detection device, converts it into touch point coordinates, sends it to the processor, and can receive and execute commands from the processor. Furthermore, various types of touch panels can be implemented, including resistive, capacitive, infrared, and surface acoustic wave touch panels. Besides the touch panel, the input unit can also include other input devices. Specifically, other input devices can include, but are not limited to, one or more of physical keyboards, function keys (such as volume control buttons, power buttons, etc.), trackballs, mice, and joysticks. The display unit can be used to display input or provided information and various menus of the electronic device. The display unit can include a display panel, optionally configured as a Liquid Crystal Display (LCD), Organic Light-Emitting Diode (OLED), or similar display panel. Further, the touch panel can cover the display panel. When the touch panel detects a touch operation on or near it, it transmits the information to the processor to determine the type of touch event. Subsequently, the processor provides corresponding visual output on the display panel based on the type of touch event. The touch panel and display panel are two separate components for implementing input and output functions of the electronic device. However, in some embodiments, the touch panel and display panel can be integrated to achieve the input and output functions of the electronic device. The electronic device may also include at least one sensor, such as a light sensor, motion sensor, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor. The ambient light sensor can adjust the brightness of the display panel according to the ambient light level, and the proximity sensor can turn off the display panel and / or backlight when the electronic device is moved to the ear. As a type of motion sensor, an accelerometer sensor can detect the magnitude of acceleration in various directions (generally three axes). When stationary, it can detect the magnitude and direction of gravity, and can be used for applications that identify the posture of the electronic device (such as landscape / portrait switching, related games, magnetometer posture calibration), vibration recognition functions (such as pedometers, tapping), etc. Other sensors that may be configured in the electronic device, such as gyroscopes, barometers, hygrometers, thermometers, and infrared sensors, will not be elaborated here. Audio circuitry, speakers, and microphones provide an audio interface. The audio circuit can convert the received audio data into electrical signals and transmit them to the speaker, where the speaker converts them into sound signals for output. On the other hand, the microphone converts the collected sound signals into electrical signals, which are then received by the audio circuit and converted into audio data. The audio data is then output to the processor for processing and then sent to another electronic device, such as another electronic device, via the RF circuit, or output to the memory for further processing.
[0122] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the embodiments disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein.
[0123] The above is a detailed description of the preferred embodiments of the present invention. However, the present invention is not limited to the above embodiments. Those skilled in the art can make various equivalent modifications or substitutions without departing from the spirit of the present invention. All such equivalent modifications or substitutions are included within the scope defined by the claims of the present invention.
Claims
1. A code conversion method based on statement equivalent substitution, characterized in that, include: Obtain the statement to be converted from the PL / SQL code to be converted. The statement to be converted includes a first operator and a first logical statement. The first operator is used to perform a logical NOT operation on the logical operation result of the first logical statement. The logical operation result of the first logical statement is Null. Obtain the target logical operation result of the statement to be converted; Remove the first operator and convert the first logical statement into a second logical statement. The logical operation result of the second logical statement is the target logical operation result. Wherein, when the operation type of the first logical statement is an assignment operation, the step of converting the first logical statement into a second logical statement includes: Retrieve the pre-defined wrapper class; A fifth operation expression is determined from the first logical statement, wherein the operation type corresponding to the fifth operation expression is an assignment operation; wherein the first logical statement is an assignment operation statement including variable definition and assignment logical operation, and the fifth operation expression is the assignment logical operation; the step of determining the fifth operation expression includes: determining the fifth operation expression by performing a syntax tree traversal on the first logical statement. Obtain the description rules of the assignment wrapper class, and rewrite the fifth operation expression according to the description rules to obtain the sixth operation expression belonging to the assignment wrapper class; The second logical statement is obtained by performing a logical NOT operation on the sixth operational expression. Replace the statement to be converted in the PLSQL code with the second logical statement to obtain the target PLSQL code; The target PL / SQL code is converted into the target Java code.
2. The code conversion method based on statement equivalent replacement according to claim 1, characterized in that, The first logical statement includes a first operation expression, a second operation expression, and a second operator. The second operator is used to perform logical operations on the operation results of the first operation expression and the second operation expression. The step of converting the first logical statement into a second logical statement includes: A third operator and a fourth operator are generated. The third operator is used to perform a logical NOT operation on the result of the first operation expression, and the fourth operator is used to perform a logical NOT operation on the result of the second operation expression. When the second operator is a logical AND operator, change the second operator to a logical OR operator; or, when the second operator is a logical OR operator, change the second operator to a logical AND operator. The second logical statement is obtained based on the first operation expression, the second operation expression, the second operator, the third operator, and the fourth operator.
3. The code conversion method based on statement equivalent replacement according to claim 2, characterized in that, The step of obtaining the second logical statement based on the first operation expression, the second operation expression, the second operator, the third operator, and the fourth operator includes: The first operation expression and the third operator are converted into a third operation expression, the result of which is the opposite of the result of the first operation expression; The second operation expression and the fourth operator are transformed into a fourth operation expression, the result of which is the opposite of the result of the second operation expression; The third operation expression, the second operator, and the fourth operation expression are combined to form the second logical statement.
4. The code conversion method based on statement equivalent substitution according to any one of claims 1 to 3, characterized in that, The first logical statement includes at least two logical substatements, and the step of converting the first logical statement into a second logical statement includes: Each of the aforementioned logical sub-statements is converted into an intermediate sub-statement; The second logical statement is obtained based on all the intermediate sub-statements.
5. The code conversion method based on statement equivalent replacement according to claim 1, characterized in that, Before replacing the statement to be converted in the PLSQL code with the second logical statement, the method further includes: Convert the second logical statement into an alternative Java statement; The result of the operation of the candidate Java statement is determined to be the result of the target logical operation.
6. A code conversion device based on statement equivalent substitution, characterized in that, include: The statement acquisition unit is used to acquire the statement to be converted in the PLSQL code to be converted. The statement to be converted includes a first operator and a first logical statement. The first operator is used to perform a logical NOT operation on the logical operation result of the first logical statement. The logical operation result of the first logical statement is Null. The result determination unit is used to obtain the target logical operation result of the statement to be converted; The statement conversion unit is used to remove the first operator and convert the first logical statement into a second logical statement, wherein the logical operation result of the second logical statement is the target logical operation result; wherein, when the operation type of the first logical statement is an assignment operation, the conversion of the first logical statement into the second logical statement includes: Retrieve the pre-defined wrapper class; The fifth operation expression is determined from the first logical statement, and the operation type corresponding to the fifth operation expression is an assignment operation; Obtain the description rules of the assignment wrapper class, and rewrite the fifth operation expression according to the description rules to obtain the sixth operation expression belonging to the assignment wrapper class; wherein, the first logical statement is an assignment operation statement including variable definition and assignment logical operation, the fifth operation expression is the assignment logical operation, and the step of determining the fifth operation expression includes: determining the fifth operation expression by performing a syntax tree traversal on the first logical statement. The second logical statement is obtained by performing a logical NOT operation on the sixth operational expression. The statement replacement unit is used to replace the statement to be converted in the PLSQL code to be converted with the second logical statement to obtain the target PLSQL code; The code conversion unit is used to convert the target PL / SQL code into target Java code.
7. An electronic device, comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, when the processor executes the computer program, it implements the code conversion method based on statement equivalent substitution as described in any one of claims 1 to 5.
8. A computer-readable storage medium storing a computer program, characterized in that, The computer program is used to execute the code transformation method based on statement equivalent substitution as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Method and device for converting SQL language into DSL language, computer equipment and storage medium
CN110175031A
JAVA conversion method and device of SQL codes, computer equipment and storage medium
CN112363727A