Database storage process conversion method and device, electronic equipment and storage medium
By obtaining the lexical and grammatical rules of database stored procedures, and directly generating and converting syntax trees, it solves the problem of complexity of stored procedure conversion between heterogeneous databases, improves conversion efficiency and accuracy, and realizes automated migration.
Patent Information
- Application Number
- CN202410633318.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-21
- Publication Date
- 2024-10-01
AI Technical Summary
The conversion of stored procedures between different databases is complex, resulting in low conversion efficiency. Especially due to differences in SQL procedural structured query languages, migration between heterogeneous databases is difficult. There is a lack of automated tool support. Traditional methods require manual comparison and intermediate steps. Mapping syntax, the steps are complex and error-prone.
By obtaining the stored process data and its lexical and grammatical rules, character recognition and grammatical combination are performed to generate a syntax tree, and the preset language mapping database is used to directly convert it into the target program language to avoid intermediate syntax generation and reduce the difficulty of migration.
It improves the speed and accuracy of stored procedure conversion, reduces the difficulty of migration between heterogeneous databases, realizes automated stored procedure migration, and reduces manual intervention and error rates.
Smart Images

Figure CN118733650A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data storage, and in particular to a method, device, electronic device and storage medium for converting a database storage procedure. Background Art
[0002] With the advent of the big data era, in order to make the new database able to be put into use faster and more conveniently, it is necessary to implement the conversion of the database's stored procedures.
[0003] However, due to the great differences in the procedural Structured Query Language (SQL) between different databases, the conversion of stored procedures between heterogeneous databases is relatively complicated, which affects the conversion efficiency. Summary of the invention
[0004] In view of this, the purpose of the present application is to propose a database stored procedure conversion method, device, electronic device and storage medium to solve or partially solve the above technical problems.
[0005] Based on the above purpose, the first aspect of the present application provides a database stored procedure conversion method, comprising:
[0006] Acquire stored process data corresponding to the database to be converted, and lexical rules and grammatical rules corresponding to the stored process data, wherein the lexical rules are used to indicate the formation rules of word symbols of the stored process data, and the grammatical rules are used to describe the composition rules of the language structure of the stored process data;
[0007] Performing character recognition on the stored process data using the lexical rule to obtain a character recognition result;
[0008] The character recognition results are grammatically combined according to the grammatical rules to generate a grammatical tree;
[0009] The syntax tree is converted into a target programming language according to a preset language mapping database, wherein the preset language mapping database includes a plurality of mapping relationships between the syntax tree and the target programming language.
[0010] Optionally, the performing character recognition on the stored process data using the lexical rule to obtain a character recognition result includes:
[0011] Performing byte stream scanning on the stored process data to obtain a character sequence;
[0012] The character sequence is lexically analyzed according to the lexical rules to obtain a plurality of lexical symbols, and the plurality of lexical symbols are used as the character recognition result.
[0013] Optionally, the performing lexical analysis on the character sequence according to the lexical rule to obtain a plurality of lexical symbols includes:
[0014] Acquire all character elements of the character sequence, and use any character element among all the character elements as a target character element;
[0015] The following operations are performed for each target character element:
[0016] Determining whether the target character element meets a preset word element splitting condition;
[0017] In response to the target character element satisfying the word element splitting condition, the target character element is subjected to word element splitting processing to obtain the lexical symbol.
[0018] Optionally, the character recognition result includes a plurality of lexical symbols, each lexical symbol includes a lexical symbol type and a corresponding lexical text;
[0019] The step of grammatically combining the character recognition results according to the grammatical rules to generate a grammatical tree includes:
[0020] For each of the lexical symbols, the following operations are performed:
[0021] Based on the lexical symbol type of the lexical symbol, the lexical text corresponding to the lexical symbol is combined according to the grammar rule to generate the grammar tree.
[0022] Optionally, the combining the lexical texts corresponding to the lexical symbols according to the grammar rules based on the lexical symbol type to generate the grammar tree includes:
[0023] Determining the language structure position of the lexical symbol according to the lexical symbol type of the lexical symbol and the grammatical rule;
[0024] The lexical texts corresponding to the lexical symbols are combined according to the language structure positions to generate the syntax tree.
[0025] Optionally, after converting the syntax tree into a target programming language according to a preset language mapping database, the method further includes:
[0026] Acquire a first storage result corresponding to the target programming language and a second storage result corresponding to the stored procedure of the database to be converted;
[0027] It is determined whether the target program language is accurate based on the first stored result and the second stored result.
[0028] Optionally, determining whether the target program language is accurate based on the first stored result and the second stored result includes:
[0029] In response to the first storage result being the same as the second storage result, determining that the target program language is correct; or,
[0030] In response to the first stored result being different from the second stored result, it is determined that the target program language is inaccurate.
[0031] Based on the same inventive concept, the second aspect of the present application provides a database stored procedure conversion device, comprising:
[0032] An acquisition module is configured to acquire stored process data corresponding to a database to be converted, and lexical rules and grammatical rules corresponding to the stored process data, wherein the lexical rules are used to indicate formation rules of word symbols of the stored process data, and the grammatical rules are used to describe composition rules of a language structure of the stored process data;
[0033] A character recognition module is configured to perform character recognition on the stored process data using the lexical rule to obtain a character recognition result;
[0034] A grammar combination module, configured to perform grammar combination on the character recognition results according to the grammar rules to generate a grammar tree;
[0035] The conversion module is configured to convert the syntax tree into a target program language according to a preset language mapping database, wherein the preset language mapping database includes a plurality of mapping relationships between the syntax tree and the target program language.
[0036] Based on the same inventive concept, the third aspect of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored on the memory and executable by the processor, wherein the processor implements the method described in the first aspect above when executing the computer program.
[0037] Based on the same inventive concept, the fourth aspect of the present application provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions are used to enable a computer to execute the method described in the first aspect above.
[0038] From the above, it can be seen that the database stored procedure conversion method, device, electronic device and storage medium provided by the present application obtain the stored procedure data corresponding to the database to be converted, as well as the lexical rules and grammatical rules corresponding to the stored procedure data, and then use the lexical rules to perform character recognition on the stored procedure data to obtain the character recognition results, and use the grammatical rules to grammatically combine the character recognition results to generate a syntax tree. The present application directly implements the parsing of stored procedures by means of lexical rules and grammatical rules without generating intermediate grammars, and then directly converts the syntax tree into an executable target program language according to a preset language mapping database, thereby avoiding the migration of stored procedures between heterogeneous databases, reducing the difficulty of migration between heterogeneous databases, and thus improving the conversion speed. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the technical solutions in the present application or related technologies, the drawings required for use in the embodiments or related technical descriptions are briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0040] Figure 1 A flowchart of a database stored procedure conversion method according to an embodiment of the present application;
[0041] Figure 2 A schematic diagram of a database storage process conversion process according to an embodiment of the present application;
[0042] Figure 3 A structural diagram of a database stored procedure conversion device according to an embodiment of the present application;
[0043] Figure 4 A schematic diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0044] In order to make the objectives, technical solutions and advantages of the present application more clearly understood, the present application is further described in detail below in combination with specific embodiments and with reference to the accompanying drawings.
[0045] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in the embodiments of the present application should be the usual meanings understood by people with ordinary skills in the field to which the present application belongs. The "first", "second" and similar words used in the embodiments of the present application do not represent any order, quantity or importance, but are only used to distinguish different components. "Including" or "comprising" and similar words mean that the elements or objects appearing in front of the word cover the elements or objects listed after the word and their equivalents, without excluding other elements or objects. "Connect" or "connected" and similar words are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0046] It is understandable that before using the technical solutions of each embodiment of the present application, the type, scope of use, usage scenarios, etc. of the personal information involved will be informed to the user in an appropriate manner, and the user's authorization will be obtained.
[0047] For example, in response to receiving an active request from a user, a prompt message is sent to the user to clearly remind the user that the operation requested to be performed will require obtaining and using the user's personal information. Thus, the user can independently choose whether to provide personal information to the electronic device, application, server, storage medium or other software or hardware that performs the operation of the technical solution of the present application according to the prompt message.
[0048] As an optional but non-limiting implementation, in response to receiving the user's active request, the prompt information may be sent to the user in the form of a pop-up window, in which the prompt information may be presented in text form. In addition, the pop-up window may also carry a selection control for the user to choose "agree" or "disagree" to provide personal information to the electronic device.
[0049] It is understandable that the above notification and the process of obtaining user authorization are merely illustrative and do not constitute a limitation on the implementation method of this application. Other methods that meet relevant laws and regulations may also be applied to the implementation method of this application.
[0050] With the advent of the big data era, in order to make the new database able to be put into use faster and more conveniently, it is necessary to implement the conversion of the database's stored procedures.
[0051] For example, when migrating a relational database (Oracle) to another target database, the migration of stored procedures becomes a difficult point in the database object migration process because of the great differences in the procedural Structured Query Language (SQL) between different databases. In addition, some other distributed databases do not support stored procedures, making it impossible to migrate the relational database (Oracle) stored procedures to other distributed databases.
[0052] At present, the traditional method of stored procedure migration is for professional database personnel to compare the syntax differences of procedural structured query language (SQL) between heterogeneous CNC libraries and manually complete the syntax conversion of stored procedures. It lacks the support of automated migration tools, is difficult, time-consuming, and prone to errors.
[0053] In addition, the existing conversion between languages mostly adopts the intermediate mapping syntax method, which realizes code generation by matching the mapping syntax with keywords to fill in the code template. This conversion method requires the generation of intermediate mapping syntax, which is complicated and requires complex iterative matching based on keywords and weights during the conversion process, resulting in low conversion efficiency.
[0054] The embodiments of the present application provide a database stored procedure conversion method, device, electronic device and storage medium, which obtain stored procedure data corresponding to the database to be converted, as well as lexical rules and grammatical rules corresponding to the stored procedure data, and then use the lexical rules to perform character recognition on the stored procedure data to obtain character recognition results, and use grammatical rules to grammatically combine the character recognition results to generate a syntax tree. The present application directly implements the parsing of stored procedures by means of lexical rules and grammatical rules without generating intermediate grammars, and then directly converts the syntax tree into an executable target program language according to a preset language mapping database, thereby avoiding the migration of stored procedures between heterogeneous databases, reducing the difficulty of migration between heterogeneous databases, and thus improving the conversion speed.
[0055] like Figure 1 As shown, the method of this embodiment includes:
[0056] Step 101, obtain the stored process data corresponding to the database to be converted, as well as the lexical rules and grammatical rules corresponding to the stored process data, wherein the lexical rules are used to indicate the formation rules of the word symbols of the stored process data, and the grammatical rules are used to describe the composition rules of the language structure of the stored process data.
[0057] In this step, the grammar rules are used to indicate the formal rules of the word symbols of the stored procedure data, such as defining the lexical composition of the procedural language (PL / Structured Query Language, SQL) of the database to be converted, including lexical information such as identifiers, literals, characters, keywords, etc.
[0058] The grammar rules are used to describe the composition rules of the language structure of the stored procedure data, such as the rules that define the language structure of the programming language (PL / SQL) of the database to be converted, such as cursor definition rules, SQL statement rules, etc.
[0059] The PL / SQL specification parsing engine parses the PL / SQL language reference (Language Reference) officially provided by Oracle according to the selected database to be converted, for example, if the database to be converted is a relational database (Oracle) version, and generates lexical rules and grammatical rules corresponding to the stored procedure.
[0060] For different versions of the database to be converted, the PL / SQL specification parsing engine only needs to be executed once for each version to generate the lexical rules and grammatical rules of that version.
[0061] Step 102: Perform character recognition on the stored process data using the lexical rules to obtain a character recognition result.
[0062] In this step, the analyzer generation engine generates a lexical analyzer according to the lexical rules by using a top-down recursive descent analysis method. The lexical analyzer is used to perform lexical analysis on the stored procedure.
[0063] For different versions of the database to be converted, the analyzer generation engine only needs to be executed once for each version to generate the lexical analyzer of that version.
[0064] The lexical analyzer can directly perform character recognition on the stored procedure data by using lexical rules, without generating intermediate grammar, and obtain character recognition results, thereby improving the speed of stored procedure parsing.
[0065] Step 103: grammatically combine the character recognition results according to the grammatical rules to generate a grammar tree.
[0066] In this step, the parser generation engine generates a grammar analyzer using a top-down recursive descent analysis method according to grammar rules. The grammar analyzer is used to perform grammar analysis on the stored procedure.
[0067] For different versions of the database to be converted, the analyzer generation engine only needs to be executed once for each version to generate the syntax analyzer of that version.
[0068] The parser can directly combine character results by using grammatical rules without generating intermediate grammars, and generate a syntax tree (Abstract Syntax Tree, AST), which improves the speed of stored procedure parsing.
[0069] Step 104: convert the syntax tree into a target programming language according to a preset language mapping database.
[0070] In this step, the language mapping database may be a conversion rule library between the database to be converted and the target programming language (eg Java code), or a schema mapping library between the database to be converted and the target database.
[0071] The conversion rule library defines general rules for converting the stored procedures of the database to be converted into the target programming language (such as Java code), such as converting stored procedures and functions into classes with only one method; converting packages into classes, and converting the stored procedures and functions in the package into methods of the class; converting initialization blocks into class constructors; converting the built-in functions and stored procedures of the database to be converted (such as Oracle) into the same target programming language methods (such as Java methods) or into methods of helper classes, etc.
[0072] The schema mapping library defines the mapping schema from the stored procedure (PL / SQL) of the database to be converted to the syntax of the target programming language (such as Java syntax), including data type mapping, control statement mapping, exception mapping, etc.
[0073] For example, the typical mapping relationship corresponding to the language mapping database is shown in Table 1 below:
[0074] Table 1 PL / SQL and Java mode mapping table
[0075]
[0076] The grammar conversion is performed according to the pattern mapping relationship. The typical grammar conversion mapping relationship corresponding to the language mapping database is shown in Table 2 below:
[0077] Table 2 PL / SQL and Java syntax conversion mapping relationship
[0078]
[0079]
[0080] The code generator traverses the language mapping database and converts the syntax tree into the target programming language (such as Java code) according to the preset language mapping database. There is no need to generate intermediate syntax. The syntax tree is directly converted into an executable target programming language, avoiding the migration of stored procedures between heterogeneous databases, reducing the difficulty of migration between heterogeneous databases, and thus improving the conversion speed.
[0081] Through the above scheme, the stored procedure data corresponding to the database to be converted, as well as the lexical rules and grammatical rules corresponding to the stored procedure data are obtained, and then the lexical rules are used to perform character recognition on the stored procedure data to obtain the character recognition results, and the character recognition results are grammatically combined through the grammatical rules to generate a syntax tree. The present application directly implements the parsing of stored procedures through lexical rules and grammatical rules without generating intermediate grammars, and then directly converts the syntax tree into an executable target program language according to a preset language mapping database, thereby avoiding the migration of stored procedures between heterogeneous databases, reducing the difficulty of migration between heterogeneous databases, and thus improving the conversion speed.
[0082] In some embodiments, step 102 includes:
[0083] Step A1, scanning the byte stream of the stored process data to obtain a character sequence.
[0084] Step A2, performing lexical analysis on the character sequence according to the lexical rule to obtain a plurality of lexical symbols, and using the plurality of lexical symbols as the character recognition result.
[0085] In the above scheme, the lexical analyzer can aggregate the input character sequence into lexical symbols.
[0086] The lexical analyzer scans the byte stream of the stored procedure data, recognizes the character sequence as characters according to the lexical rules, and cuts the recognized characters into lexical symbols (tokens).
[0087] Each lexical symbol includes a lexical symbol type and a lexical text corresponding to the lexical symbol.
[0088] The lexical rules can be used to directly perform character recognition on the stored procedure data without generating intermediate grammars, and the character recognition results can be obtained, which improves the speed of stored procedure parsing.
[0089] In some embodiments, in step A2, the character sequence is lexically analyzed according to the lexical rule to obtain a plurality of lexical symbols, including:
[0090] Step B1, obtaining all character elements of the character sequence, and taking any character element among all the character elements as a target character element.
[0091] Step B2, performing the following operations on each of the target character elements:
[0092] Step B21, determining whether the target character element meets a preset word element splitting condition.
[0093] Step B22, in response to the target character element satisfying the word element splitting condition, performing word element splitting processing on the target character element to obtain the lexical symbol.
[0094] In the above scheme, the preset word element splitting condition is used to indicate the conditions required for splitting character elements, and can be set according to specific circumstances. No specific limitation is made to the preset word element splitting condition here.
[0095] The state of the lexical analysis state machine is determined by continuously previewing the next character in the character sequence backwards, and determining whether to perform truncation and word segmentation at the current reading position of the target character element or continue to add characters to the buffer, until the previewed character no longer matches the current state machine pattern, a truncation and word segmentation is performed at the corresponding position of the target character element (that is, the preset word element splitting condition is met) to obtain a lexical symbol.
[0096] The process of lexical analysis can be performed quickly to obtain multiple lexical symbols.
[0097] In some embodiments, the character recognition result includes a plurality of lexical symbols, each lexical symbol including a lexical symbol type and a corresponding lexical text.
[0098] Step 103 includes:
[0099] Step C1, performing the following operations on each lexical symbol:
[0100] Step C11, combining the lexical texts corresponding to the lexical symbols according to the grammar rules based on the lexical symbol types of the lexical symbols to generate the grammar tree.
[0101] In the above scheme, the parser combines lexical symbol sequences into different grammatical phrases based on the results of lexical analysis (i.e., character recognition results), that is, based on the lexical symbol type of the lexical symbol, the lexical texts corresponding to the lexical symbols are combined according to the grammatical rules, and adapted to the corresponding grammatical rules to generate a corresponding syntax tree.
[0102] The syntax tree records the process by which the parser identifies the structure of the input sentence and the components of the structure.
[0103] The grammar rules can be used to directly combine the character results, without generating intermediate grammars, to generate a syntax tree (Abstract Syntax Tree, AST), which improves the speed of stored procedure parsing.
[0104] In some embodiments, step C11 includes:
[0105] Step C111, determining the language structure position of the lexical symbol according to the lexical symbol type of the lexical symbol and the grammatical rule.
[0106] Step C112, combining the lexical texts corresponding to the lexical symbols according to the language structure positions to generate the syntax tree.
[0107] In the above scheme, according to the lexical symbol type of the lexical symbol, the language structure position of the lexical symbol can be quickly determined by referring to the grammatical rules, so that the lexical texts corresponding to different lexical symbols can be combined based on the language structure position, and then a syntax tree can be constructed to record the process of inputting the sentence structure and the components of the structure through the syntax tree.
[0108] In some embodiments, after step 104, the method further includes:
[0109] Step D1, obtaining a first storage result corresponding to the target programming language and a second storage result corresponding to the stored procedure of the database to be converted.
[0110] Step D2: determining whether the target program language is accurate based on the first storage result and the second storage result.
[0111] In the above solution, the first storage result represents the execution result of the target programming language in the stored procedure, and the second storage result represents the execution result of the database to be converted in the stored procedure.
[0112] The code checker compares the consistency determined by the first storage result and the second storage result in an automated manner to verify whether the logic of the target program language obtained in the present application is accurate.
[0113] In some embodiments, step D2 comprises:
[0114] Step D21, in response to the first storage result being the same as the second storage result, determining that the target program language is correct. Or,
[0115] Step D22: In response to the first storage result being different from the second storage result, determining that the target program language is inaccurate.
[0116] In the above scheme, when the first stored result is the same as the second stored result, it indicates that the target program language is correct, or when the first stored result is different from the second stored result, it indicates that the target program language is inaccurate.
[0117] The consistency determined by comparing the first stored result with the second stored result in an automated manner ensures the accuracy of the logic of the target program language code obtained in the present application.
[0118] Based on the same inventive concept, the conversion process corresponding to the database stored procedure conversion method of the above embodiment is described in detail. Figure 2 As shown, the details are as follows:
[0119] This application framework includes 8 components: PL / SQL specification parsing engine, analyzer generation engine, lexical analyzer, syntax analyzer, code generator, code verifier, conversion rule library, pattern mapping library, etc.
[0120] The PL / SQL specification parsing engine parses the PL / SQL (i.e., the stored procedure corresponding to the database to be converted) language reference (Language Reference) officially provided by Oracle according to the selected Oracle (i.e., the database to be converted) version, and generates a lexical rule file (i.e., lexical rules) and a grammar rule file (grammar rules). The lexical rule file defines the lexical composition of PL / SQL, including lexical information such as identifiers, literals, characters, and keywords. The grammar rule file defines the rules that describe the PL / SQL language structure, such as cursor definition rules, SQL statement rules, etc. For different versions of Oracle, the PL / SQL specification parsing engine only needs to be executed once for each version to generate the lexical rule file and grammar rule file for that version.
[0121] The analyzer generation engine uses a top-down recursive descent analysis method to generate a lexical analyzer and a grammatical analyzer based on the lexical rule file and the grammatical rule file, which are used to perform lexical analysis and grammatical analysis on stored procedures. For different versions of Oracle, the analyzer generation engine only needs to be executed once for each version to generate the lexical analyzer and grammatical analyzer of that version.
[0122] The lexical analyzer aggregates the input character sequence into lexical tokens. The lexical analyzer scans the stored procedure byte stream, identifies characters according to lexical rules and cuts them into lexical tokens (i.e. multiple lexical tokens). Lexical tokens include the type of lexical token and the text corresponding to the lexical token.
[0123] The parser combines lexical sequences into different grammatical phrases based on the results of lexical analysis (i.e., character recognition results), and adapts them to the corresponding grammatical rules to generate the corresponding abstract syntax tree (i.e., syntax tree). The abstract syntax tree records the process of the parser recognizing the input sentence structure and the various components of the structure.
[0124] The code generator traverses the abstract syntax tree, performs pattern matching according to the pattern mapping rules, and generates Java code (ie, the target programming language) in combination with the conversion rules (ie, the preset language mapping database).
[0125] The code verifier verifies the generated code in an automated manner using a test data set, and ensures the accuracy of the code logic (i.e., the target program language) by comparing the consistency of the stored procedure execution result (i.e., the first stored result) with the program execution result (i.e., the second stored result).
[0126] The conversion rule library (i.e., the preset language mapping database) defines the general rules for converting stored procedures to Java code, such as converting stored procedures and functions into classes with only one method; converting packages into classes, and converting stored procedures and functions in the packages into methods of the class;
[0127] Initialization blocks are converted to class constructors; Oracle built-in functions and stored procedures are converted to the same Java methods or to methods of helper classes, etc.
[0128] The pattern mapping library (i.e., the preset language mapping database) defines the mapping pattern from PL / SQL to Java syntax, including data type mapping, control statement mapping, exception mapping, etc.
[0129] It should be noted that the method of the embodiment of the present application can be performed by a single device, such as a computer or server. The method of this embodiment can also be applied to a distributed scenario and completed by multiple devices cooperating with each other. In the case of such a distributed scenario, one of the multiple devices can only perform one or more steps in the method of the embodiment of the present application, and the multiple devices will interact with each other to complete the described method.
[0130] It should be noted that the above describes some embodiments of the present application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the above embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0131] Based on the same inventive concept, corresponding to any of the above-mentioned embodiment methods, the present application also provides a database stored procedure conversion device.
[0132] refer to Figure 3 , the database stored procedure conversion device comprises:
[0133] The acquisition module 301 is configured to acquire a stored procedure corresponding to the database data to be converted, and a lexical rule and a grammatical rule corresponding to the stored procedure data, wherein the lexical rule is used to indicate a formation rule of a word symbol of the stored procedure data, and the grammatical rule is used to describe a composition rule of a language structure of the stored procedure data;
[0134] A character recognition module 302 is configured to perform character recognition on the stored process data using the lexical rule to obtain a character recognition result;
[0135] A grammar combination module 303 is configured to perform grammar combination on the character recognition results according to the grammar rules to generate a grammar tree;
[0136] The conversion module 304 is configured to convert the syntax tree into a target programming language according to a preset language mapping database, wherein the preset language mapping database includes a plurality of mapping relationships between the syntax tree and the target programming language.
[0137] In some embodiments, the character recognition module 302 includes:
[0138] A scanning unit, configured to perform byte stream scanning on the stored process data to obtain a character sequence;
[0139] The lexical analysis unit is configured to perform lexical analysis on the character sequence according to the lexical rule to obtain a plurality of lexical symbols, and use the plurality of lexical symbols as the character recognition result.
[0140] In some embodiments, the lexical analysis unit is specifically configured to:
[0141] Acquire all character elements of the character sequence, and use any character element among all the character elements as a target character element;
[0142] The following operations are performed for each target character element:
[0143] Determining whether the target character element meets a preset word element splitting condition;
[0144] In response to the target character element satisfying the word element splitting condition, the target character element is subjected to word element splitting processing to obtain the lexical symbol.
[0145] In some embodiments, the character recognition result includes a plurality of lexical symbols, each lexical symbol including a lexical symbol type and a corresponding lexical text;
[0146] The grammar combination module 303 includes:
[0147] The combination unit is configured to perform the following operations on each of the lexical symbols:
[0148] Based on the lexical symbol type of the lexical symbol, the lexical text corresponding to the lexical symbol is combined according to the grammar rule to generate the grammar tree.
[0149] In some embodiments, the combination unit is specifically configured as follows:
[0150] Determining the language structure position of the lexical symbol according to the lexical symbol type of the lexical symbol and the grammatical rule;
[0151] The lexical texts corresponding to the lexical symbols are combined according to the language structure positions to generate the syntax tree.
[0152] In some embodiments, the database stored procedure conversion device further includes a determination module. After converting the syntax tree into the target program language according to a preset language mapping database, the determination module includes:
[0153] an acquisition unit configured to acquire a first storage result corresponding to the target program language and a second storage result corresponding to the storage process of the database to be converted;
[0154] A determination unit is configured to determine whether the target program language is accurate based on the first storage result and the second storage result.
[0155] In some embodiments, the determining unit is specifically configured to:
[0156] In response to the first storage result being the same as the second storage result, determining that the target program language is correct; or,
[0157] In response to the first stored result being different from the second stored result, it is determined that the target program language is inaccurate.
[0158] For the convenience of description, the above device is described in terms of functions divided into various modules. Of course, when implementing the present application, the functions of each module can be implemented in the same or multiple software and / or hardware.
[0159] The device of the above embodiment is used to implement the corresponding database stored procedure conversion method in any of the above embodiments, and has the beneficial effects of the corresponding method embodiment, which will not be repeated here.
[0160] Based on the same inventive concept, corresponding to any of the above-mentioned embodiments and methods, the present application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the database stored procedure conversion method described in any of the above embodiments is implemented.
[0161] Figure 4 A more specific schematic diagram of the hardware structure of an electronic device provided in this embodiment is shown, and the device may include: a processor 401, a memory 402, an input / output interface 403, a communication interface 404, and a bus 405. The processor 401, the memory 402, the input / output interface 403, and the communication interface 404 are connected to each other in communication within the device through the bus 405.
[0162] The processor 401 can be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification.
[0163] The memory 402 can be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 402 can store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program codes are stored in the memory 402 and called and executed by the processor 401.
[0164] The input / output interface 403 is used to connect the input / output module to realize information input and output. The input / output module can be configured in the device as a component (not shown in the figure), or it can be externally connected to the device to provide corresponding functions. The input device may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output device may include a display, a speaker, a vibrator, an indicator light, etc.
[0165] The communication interface 404 is used to connect a communication module (not shown) to realize communication interaction between the device and other devices. The communication module can realize communication through a wired mode (such as USB, network cable, etc.) or a wireless mode (such as mobile network, WIFI, Bluetooth, etc.).
[0166] The bus 405 comprises a pathway for transmitting information between the various components of the device (eg, the processor 401 , the memory 402 , the input / output interface 403 , and the communication interface 404 ).
[0167] It should be noted that, although the above device only shows the processor 401, the memory 402, the input / output interface 403, the communication interface 404 and the bus 405, in the specific implementation process, the device may also include other components necessary for normal operation. In addition, it can be understood by those skilled in the art that the above device may also only include the components necessary for implementing the embodiments of the present specification, and does not necessarily include all the components shown in the figure.
[0168] The electronic device of the above embodiment is used to implement the corresponding database storage process conversion method in any of the above embodiments, and has the beneficial effects of the corresponding method embodiment, which will not be repeated here.
[0169] Based on the same inventive concept, corresponding to any of the above-mentioned embodiment methods, the present application also provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the database stored procedure conversion method described in any of the above embodiments.
[0170] The computer-readable medium of this embodiment includes permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device.
[0171] The computer instructions stored in the storage medium of the above embodiment are used to enable the computer to execute the database stored procedure conversion method described in any of the above embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0172] Those skilled in the art should understand that the discussion of any of the above embodiments is merely illustrative and is not intended to imply that the scope of the present application (including the claims) is limited to these examples. In line with the concept of the present application, the technical features in the above embodiments or different embodiments may be combined, the steps may be implemented in any order, and there are many other variations of the different aspects of the embodiments of the present application as described above, which are not provided in detail for the sake of simplicity.
[0173] In addition, to simplify the description and discussion, and in order not to make the embodiments of the present application difficult to understand, the known power supply / ground connection with the integrated circuit (IC) chip and other components may or may not be shown in the provided drawings. In addition, the device can be shown in the form of a block diagram to avoid making the embodiments of the present application difficult to understand, and this also takes into account the fact that the details of the implementation of these block diagram devices are highly dependent on the platform to be implemented in the embodiments of the present application (that is, these details should be fully within the scope of understanding of those skilled in the art). In the case of elaborating specific details (e.g., circuits) to describe exemplary embodiments of the present application, it is obvious to those skilled in the art that the embodiments of the present application can be implemented without these specific details or when these specific details are changed. Therefore, these descriptions should be considered to be illustrative rather than restrictive.
[0174] Although the present application has been described in conjunction with specific embodiments of the present application, many replacements, modifications and variations of these embodiments will be apparent to those skilled in the art from the foregoing description. For example, other memory architectures (e.g., dynamic RAM (DRAM)) may use the embodiments discussed.
[0175] The embodiments of the present application are intended to cover all such substitutions, modifications and variations that fall within the broad scope of the appended claims. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the embodiments of the present application should be included in the scope of protection of the present application.
Claims
1. A database stored procedure conversion method, It is characterized in that include: Acquire stored process data corresponding to the database to be converted, and lexical rules and grammatical rules corresponding to the stored process data, wherein the lexical rules are used to indicate the formation rules of word symbols of the stored process data, and the grammatical rules are used to describe the composition rules of the language structure of the stored process data; Performing character recognition on the stored process data using the lexical rule to obtain a character recognition result; The character recognition results are grammatically combined according to the grammatical rules to generate a grammatical tree; The syntax tree is converted into a target programming language according to a preset language mapping database, wherein the preset language mapping database includes a plurality of mapping relationships between the syntax tree and the target programming language.
2. The method according to claim 1, It is characterized in that The step of performing character recognition on the stored process data by using the lexical rule to obtain a character recognition result includes: Performing byte stream scanning on the stored process data to obtain a character sequence; The character sequence is lexically analyzed according to the lexical rules to obtain a plurality of lexical symbols, and the plurality of lexical symbols are used as the character recognition result.
3. The method according to claim 2, It is characterized in that The step of performing lexical analysis on the character sequence according to the lexical rule to obtain a plurality of lexical symbols includes: Acquire all character elements of the character sequence, and use any character element among all the character elements as a target character element; The following operations are performed for each target character element: Determining whether the target character element meets a preset word element splitting condition; In response to the target character element satisfying the word element splitting condition, the target character element is subjected to word element splitting processing to obtain the lexical symbol.
4. The method according to claim 1, It is characterized in that The character recognition result includes a plurality of lexical symbols, each lexical symbol includes a lexical symbol type and a corresponding lexical text; The step of grammatically combining the character recognition results according to the grammatical rules to generate a grammatical tree includes: For each of the lexical symbols, the following operations are performed: Based on the lexical symbol type of the lexical symbol, the lexical text corresponding to the lexical symbol is combined according to the grammar rule to generate the grammar tree.
5. The method according to claim 4, It is characterized in that The lexical symbol type based on the lexical symbol combines the lexical text corresponding to the lexical symbol according to the grammar rule to generate the grammar tree, including: Determining the language structure position of the lexical symbol according to the lexical symbol type of the lexical symbol and the grammatical rule; The lexical texts corresponding to the lexical symbols are combined according to the language structure positions to generate the syntax tree.
6. The method according to claim 1, It is characterized in that After converting the syntax tree into a target programming language according to a preset language mapping database, the method further includes: Acquire a first storage result corresponding to the target programming language and a second storage result corresponding to the stored procedure of the database to be converted; It is determined whether the target program language is accurate based on the first stored result and the second stored result.
7. The method according to claim 6, It is characterized in that The determining whether the target program language is accurate based on the first storage result and the second storage result includes: In response to the first storage result being the same as the second storage result, determining that the target program language is correct; or, In response to the first stored result being different from the second stored result, it is determined that the target program language is inaccurate.
8. A database stored procedure conversion device, It is characterized in that include: An acquisition module is configured to acquire stored process data corresponding to the database to be converted, and lexical rules and grammatical rules corresponding to the stored process data, wherein the lexical rules are used to indicate the formation rules of word symbols of the stored process, and the grammatical rules are used to describe the composition rules of the language structure of the stored process data; A character recognition module is configured to perform character recognition on the stored process data using the lexical rule to obtain a character recognition result; A grammar combination module, configured to perform grammar combination on the character recognition results according to the grammar rules to generate a grammar tree; The conversion module is configured to convert the syntax tree into a target program language according to a preset language mapping database, wherein the preset language mapping database includes a plurality of mapping relationships between the syntax tree and the target program language.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the program, the method according to any one of claims 1 to 7 is implemented.
10. A non-transitory computer-readable storage medium storing computer instructions, It is characterized in that The computer instructions are used to enable a computer to execute the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
System interaction method and device, apparatus and storage medium
CN110245002A
Method and device for converting SQL (Structured Query Language) statements between relational databases
CN117290377A
Stored procedure conversion method and apparatus, and device and storage medium
WO2021259290A1
Cited By
Source database storage process migration method and device, electronic equipment and storage medium
CN121705260A
