SQL statement analysis method, device, electronic device and storage medium

By parsing the configuration file and automatically generating SQL statement conversion guidance information using syntax matching rules, the problem of low SQL statement conversion efficiency in database localization transformation is solved, the automatic analysis and conversion of SQL statements is realized, and efficiency is improved.

CN115905286BActive Publication Date: 2025-09-09CHINA CONSTRUCTION BANK +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211494129.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-11-25
Publication Date
2025-09-09
Estimated Expiration
2042-11-25

AI Technical Summary

Technical Problem

During the process of localizing databases, due to the differences in SQL syntax between different database types, the existing technology requires manual analysis of each file and statement one by one, resulting in low SQL statement conversion efficiency and a waste of time and human resources.

Method used

By parsing the configuration file to obtain task description information, the conversion guidance information of the SQL statement is automatically generated using the syntax matching rules and conversion guidance information corresponding to the file type, and the correspondence between the file identifier and the statement conversion guidance information is saved to form the statement analysis result.

Benefits of technology

It realizes the automatic analysis and conversion of SQL statements, improves the conversion efficiency, facilitates the task allocation and inspection of developers, and reduces manual intervention.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115905286B_ABST
    Figure CN115905286B_ABST
Patent Text Reader

Abstract

The present application discloses an SQL statement analysis method, device, electronic device, and storage medium, belonging to the field of data processing technology. The method includes: parsing a configuration file of a statement analysis task to obtain file scanning requirements, multiple syntax matching rules for first-class SQL statements corresponding to each type of file, and syntax conversion guidance information corresponding to each syntax matching rule; obtaining first-class SQL statements from each file that meets the file scanning requirements; generating statement conversion guidance information from the first-class SQL statements in the file to second-class SQL statements based on the multiple syntax matching rules for the first-class SQL statements corresponding to the file type of the file and the syntax conversion guidance information corresponding to the multiple syntax matching rules; saving the corresponding relationship between the file identifier of the file and the first-class SQL statements in the file, and the statement conversion guidance information of the first-class SQL statements, to form a statement analysis result. In this way, the conversion efficiency of SQL statements is accelerated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a SQL statement analysis method, device, electronic device, and storage medium. Background Art

[0002] With the progress of database localization, in order to improve the security of data storage, localization transformation of the original database has gradually become an urgent task for various institutions.

[0003] Taking financial services as an example, during the process of localizing databases, when using different types of database systems, the corresponding Structured Query Language (SQL) needs to be used to access data as well as query, update, and manage the database system. Due to the differences in SQL syntax between different database types, the existing technology usually requires manual analysis of each statement in each file to find the SQL statements that need syntax conversion, and then convert them according to the statement conversion plan. In this process, a lot of time and human resources are wasted, resulting in low SQL statement conversion efficiency.

[0004] Therefore, how to reasonably analyze SQL statements to speed up SQL statement conversion efficiency is a technical problem that needs to be solved urgently. Summary of the Invention

[0005] The embodiments of the present application provide a SQL statement analysis method, device, electronic device and storage medium for reasonably performing SQL statement analysis to accelerate SQL statement conversion efficiency.

[0006] In a first aspect, an embodiment of the present application provides a method for analyzing SQL statements, including:

[0007] Parsing a configuration file of a statement analysis task to obtain task description information, wherein the task description information includes file scanning requirements, multiple syntax matching rules of the first type of SQL statement corresponding to each type of file, and syntax conversion guidance information corresponding to each syntax matching rule;

[0008] Obtain a first type of SQL statement from each file that meets the file scanning requirements;

[0009] Generate statement conversion guidance information from the first type of SQL statement in the file to the second type of SQL statement based on multiple syntax matching rules of the first type of SQL statement corresponding to the file type of the file and syntax conversion guidance information corresponding to the multiple syntax matching rules;

[0010] The corresponding relationship between the file identifier of the file, the first type of SQL statement in the file, and the statement conversion guide information of the first type of SQL statement is saved to form a statement analysis result.

[0011] In some embodiments, obtaining a first type of SQL statement from each file that meets the file scanning requirement includes:

[0012] Scan each file that meets the file scanning requirement to obtain a file object of the file;

[0013] A first type of SQL statement is selected from the file object.

[0014] In some embodiments, generating statement conversion guidance information from the first type of SQL statement in the file to the second type of SQL statement based on multiple syntax matching rules of the first type of SQL statement corresponding to the file type of the file and syntax conversion guidance information corresponding to the multiple syntax matching rules includes:

[0015] Matching each first-category SQL statement in the file using a plurality of syntax matching rules for the first-category SQL statements corresponding to the file type of the file;

[0016] For a target syntax matching any syntax matching rule in the first type of SQL statement, determining the syntax conversion guidance information corresponding to the syntax matching rule as the syntax conversion guidance information corresponding to the target syntax;

[0017] Each target syntax and the syntax conversion guidance information corresponding to each target syntax are used as the sentence conversion guidance information.

[0018] In some embodiments, after forming the statement analysis result, the method further includes:

[0019] responding to a request to display a statement analysis result;

[0020] The correspondence between the file identifier of each file and the first type of SQL statements in the file, as well as the statement conversion guidance information of the first type of SQL statements is displayed.

[0021] In some embodiments, after displaying the correspondence between the file identifier of each file and the first type of SQL statement in the file, and the statement conversion guidance information of the first type of SQL statement, the method further includes:

[0022] responding to an instruction to modify the statement conversion guidance information;

[0023] Based on the modification instruction, the statement conversion guidance information is modified.

[0024] In a second aspect, an embodiment of the present application provides an SQL statement analysis device, comprising:

[0025] A parsing module is used to parse the configuration file of the statement analysis task to obtain task description information, wherein the task description information includes file scanning requirements, multiple syntax matching rules of the first type of SQL statements corresponding to each type of file, and syntax conversion guidance information corresponding to each syntax matching rule;

[0026] An acquisition module, configured to acquire a first type of SQL statement from each file that meets the file scanning requirement;

[0027] a generating module configured to generate statement conversion guidance information from the first category SQL statement in the file to the second category SQL statement based on a plurality of syntax matching rules of the first category SQL statement corresponding to the file type of the file and syntax conversion guidance information corresponding to the plurality of syntax matching rules;

[0028] The saving module is used to save the correspondence between the file identifier of the file and the first type of SQL statement in the file, as well as the statement conversion guidance information of the first type of SQL statement, to form a statement analysis result.

[0029] In some embodiments, the acquisition module is specifically configured to:

[0030] Scan each file that meets the file scanning requirement to obtain a file object of the file;

[0031] A first type of SQL statement is selected from the file object.

[0032] In some embodiments, the generating module is specifically configured to:

[0033] Matching each first-category SQL statement in the file using a plurality of syntax matching rules for the first-category SQL statements corresponding to the file type of the file;

[0034] For a target syntax matching any syntax matching rule in the first type of SQL statement, determining the syntax conversion guidance information corresponding to the syntax matching rule as the syntax conversion guidance information corresponding to the target syntax;

[0035] Each target syntax and the syntax conversion guidance information corresponding to each target syntax are used as the sentence conversion guidance information.

[0036] In some embodiments, a display module is also included:

[0037] The display module is used to display the correspondence between the file identifier of each file and the first type of SQL statement in the file and the statement conversion guidance information of the first type of SQL statement in response to a display request of the statement analysis result after forming the statement analysis result.

[0038] In some embodiments, a modification module is further included:

[0039] The modification module is used to modify the statement conversion guidance information based on a modification instruction in response to the modification instruction after the display module displays the correspondence between the file identifier of each file and the first type of SQL statement in the file and the statement conversion guidance information of the first type of SQL statement.

[0040] In a third aspect, an embodiment of the present application provides an electronic device, comprising: at least one processor, and a memory communicatively connected to the at least one processor, wherein:

[0041] The memory stores instructions that can be executed by at least one processor. The instructions are executed by the at least one processor to enable the at least one processor to execute the above-mentioned SQL statement analysis method.

[0042] In a fourth aspect, an embodiment of the present application provides a storage medium. When instructions in the storage medium are executed by a processor of an electronic device, the electronic device can execute the above-mentioned SQL statement analysis method.

[0043] In a fifth aspect, an embodiment of the present application provides a computer program product, which, when called and executed by an electronic device, enables the electronic device to execute the above-mentioned SQL statement analysis method.

[0044] In an embodiment of the present application, a configuration file of a statement analysis task is parsed to obtain task description information, which includes file scanning requirements, multiple syntax matching rules for first-class SQL statements corresponding to each type of file, and syntax conversion guidance information corresponding to each syntax matching rule. First-class SQL statements are obtained from each file that meets the file scanning requirements. Based on the multiple syntax matching rules for the first-class SQL statements corresponding to the file type of the file and the syntax conversion guidance information corresponding to the multiple syntax matching rules, statement conversion guidance information from the first-class SQL statements in the file to the second-class SQL statements is generated. The correspondence between the file identifier of the file and the first-class SQL statements in the file, as well as the statement conversion guidance information of the first-class SQL statements, is saved to form a statement analysis result. In this way, by parsing the pre-configured configuration file, the first type of SQL statement can be automatically obtained from each type of file, and the statement conversion guidance information of the first type of SQL statement to the second type of SQL statement can be generated according to the syntax matching rules and the corresponding syntax conversion guidance information. The file identifier of the file is corresponded with the first type of SQL statement in the file, and the statement conversion guidance information of the first type of SQL statement is formed to form a statement analysis result, which speeds up the conversion efficiency of the SQL statement. In addition, developers can also reasonably allocate the conversion work of the SQL statement based on the statement analysis results, which provides convenience for task allocation. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0046] Figure 1 A flowchart of a SQL statement analysis method provided in an embodiment of the present application;

[0047] Figure 2 A schematic diagram of an SQL statement analysis process provided in an embodiment of the present application;

[0048] Figure 3 A schematic diagram of the structure of an SQL statement analysis device provided in an embodiment of the present application;

[0049] Figure 4 A schematic diagram of the hardware structure of an electronic device for implementing a SQL statement analysis method provided in an embodiment of the present application. DETAILED DESCRIPTION

[0050] In order to reasonably perform SQL statement analysis to accelerate SQL statement conversion efficiency, embodiments of the present application provide a SQL statement analysis method, device, electronic device, and storage medium.

[0051] The following describes the preferred embodiments of the present application in conjunction with the accompanying drawings. It should be understood that the preferred embodiments described herein are intended only to illustrate and explain the present application and are not intended to limit the present application. The embodiments and features of the embodiments in the present application may be combined with each other unless there is a conflict. Furthermore, in the embodiments of the present application, the acquisition, storage, use, and processing of data are in compliance with relevant national laws and regulations.

[0052] The terms "first" and "second" in the specification and claims of this application and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the term "comprising" and any of its variations are intended to cover non-exclusive protection. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally also includes steps or units that are not listed, or optionally also includes other steps or units inherent to these processes, methods, products or devices. "Multiple" in this application can mean at least two, for example, two, three or more, and the embodiments of this application are not limited thereto.

[0053] In addition, the term "and / or" in this document simply describes an association between related objects, indicating that three possible relationships exist. For example, "A and / or B" can represent: A exists alone, A and B exist simultaneously, and B exists alone. Furthermore, the character " / " in this document, unless otherwise specified, generally indicates an "or" relationship between the related objects.

[0054] Before introducing the embodiments of the present application, some technical features of the present application are first introduced to facilitate understanding by those skilled in the art.

[0055] A database is a warehouse built on computer storage devices that organizes, stores, and manages data according to data structures. It is an organized, shareable collection of data stored long-term within a computer. The data in a database is organized, described, and stored using a specific data model, with minimal redundancy, high data independence, and easy scalability, and can be shared by multiple users within a certain range.

[0056] Structured Query Language (SQL) is a database query and programming language used to access data and query, update, and manage relational database systems.

[0057] Before introducing the SQL statement analysis method provided by the embodiment of the present application, in order to facilitate understanding, the technical background of the embodiment of the present application is first introduced in detail.

[0058] Taking the financial sector as an example, with the progress of database localization, in order to improve the security of data storage, database localization transformation is imminent. During the database localization transformation process, there are differences in SQL syntax between different database types, so the conversion of SQL statement syntax is particularly important. However, in the existing technology, the conversion of SQL statement syntax usually requires manual analysis of each file and statement to find the SQL statements that need syntax conversion, and then convert them according to the statement conversion plan. This manual analysis of SQL statements wastes a lot of time and human resources. In addition, for project managers, it is impossible to predict the workload of SQL statement conversion in advance, and it is impossible to reasonably allocate tasks.

[0059] Therefore, in order to solve the above problems, the present application provides a SQL statement analysis method, device, electronic device and storage medium.

[0060] The SQL statement analysis method provided in the embodiments of the present application can be applied to a terminal, a server, or software running in a terminal or a server. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server can be configured as an independent physical server, or as a server cluster or distributed system consisting of multiple physical servers, or as a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application that implements the SQL statement analysis method, etc., but is not limited to the above forms.

[0061] Figure 1 A flowchart of a SQL statement analysis method provided in an embodiment of the present application, the method includes the following steps.

[0062] In step S101, the configuration file of the statement analysis task is parsed to obtain task description information, which includes file scanning requirements, multiple syntax matching rules of the first type of SQL statements corresponding to each type of file, and syntax conversion guidance information corresponding to each syntax matching rule.

[0063] Among them, the syntax conversion guidance information corresponding to each syntax matching rule is used to guide the conversion of the syntax matched by the syntax matching rule in the first type of SQL statement into the syntax in the second type of SQL statement. The first type of SQL statement is the SQL statement used by the source database, and the second type of SQL statement is the SQL statement used by the destination database.

[0064] During specific implementation, the configuration file is pre-configured based on the syntax differences between the first type of SQL statements and the second type of SQL statements. Among them, the file scanning requirements, such as setting the file path of the files to be scanned and the file path of the files that do not need to be scanned, take into account the differences in the SQL statement content of each type of file. Therefore, when configuring the configuration file, multiple syntax matching rules can be configured for each type of file, such as java, c, xml, sh, sql, qry, ctl, etc., as well as syntax conversion guidance information corresponding to each syntax matching rule.

[0065] In step S102 , a first type of SQL statement is obtained from each file that meets the file scanning requirement.

[0066] In some embodiments, each file that meets the file scanning requirement may be scanned to obtain a file object of the file, and then a first type of SQL statement may be selected from the file object.

[0067] In specific implementations, file objects are generated by scanning files in the file path of the to-be-scanned file that meet the file scanning requirements, parsing the scanned files, extracting file features, and then associating and combining the file features. These file features include file type, first-category SQL statements contained in the file, and the number of first-category SQL statements. One file object is generated for each file, and each file object contains N first-category SQL statements, where N is an integer greater than zero. These first-category SQL statements may include those that require conversion and those that do not. The first-category SQL statements are then selected from the file object.

[0068] In step S103, statement conversion guidance information from the first type of SQL statement in the file to the second type of SQL statement is generated based on multiple syntax matching rules of the first type of SQL statement corresponding to the file type of the file and syntax conversion guidance information corresponding to the multiple syntax matching rules.

[0069] The statement conversion guidance information is used to guide the conversion of the first type of SQL statements into the second type of SQL statements.

[0070] In some embodiments, multiple syntax matching rules of the first type of SQL statements corresponding to the file type of the file can be used to match each first type SQL statement in the file. For the target syntax in the first type of SQL statement that matches any syntax matching rule, the syntax conversion guidance information corresponding to the syntax matching rule is determined as the syntax conversion guidance information corresponding to the target syntax, and each target syntax and the syntax conversion guidance information corresponding to each target syntax are used as statement conversion guidance information.

[0071] For example, the first type of SQL statement in a file of type XML has three syntax matching rules: syntax matching rule 1, syntax matching rule 2, and syntax matching rule 3. The syntax conversion guidance information corresponding to syntax matching rule 1 is information 1, the syntax conversion guidance information corresponding to syntax matching rule 2 is information 2, and the syntax conversion guidance information corresponding to syntax matching rule 3 is information 3.

[0072] Assume that statement analysis is performed on statement a belonging to the first category of SQL statements in file F. If the file type of file F is xml, then statement a is matched with syntax matching rule 1, syntax matching rule 2, and syntax matching rule 3 corresponding to the xml file type respectively. If syntax 1 in statement a matches syntax matching rule 1, and syntax 2 matches syntax matching rule 3, then information 1 is determined as the syntax conversion guidance information corresponding to syntax 1, and information 3 is determined as the syntax conversion guidance information corresponding to syntax 2. Then, syntax 1 and information 1, syntax 2 and information 3 are used as statement conversion guidance information for statement a.

[0073] For another example, the first type of SQL statement in a file of file type ctl has two syntax matching rules, namely syntax matching rule 4 and syntax matching rule 5. The syntax conversion guidance information corresponding to syntax matching rule 4 is information 4, and the syntax conversion guidance information corresponding to syntax matching rule 5 is information 5.

[0074] Assume that statement analysis is performed on statement a belonging to the first category of SQL statements in file F. If the file type of file F is ctl, statement a is matched with syntax matching rule 4 and syntax matching rule 5 corresponding to the ctl file type respectively. If syntax 1 in statement a matches syntax matching rule 4, and syntax 2 matches syntax matching rule 5, then information 4 is determined as the syntax conversion guidance information corresponding to syntax 1, and information 5 is determined as the syntax conversion guidance information corresponding to syntax 2. Then, syntax 1 and information 4, syntax 2 and information 5 are used as statement conversion guidance information for statement a.

[0075] In step S104, the correspondence between the file identifier of the file and the first type of SQL statement in the file and the statement conversion guidance information of the first type of SQL statement is saved to form a statement analysis result.

[0076] During specific implementation, the statement analysis results are as follows: file identifier: file F, the first type of SQL statement in the file: statement a, statement conversion guidance information of the first type of SQL statement: the syntax conversion guidance information of syntax 1 in statement a is information 1, and the syntax conversion guidance information of syntax 2 in statement a is information 3.

[0077] During specific implementation, you can also configure a result storage path in the configuration file, and then store the generated statement analysis results in the result storage path.

[0078] In some embodiments, after forming the statement analysis results, the correspondence between the file identifier of each file and the first type of SQL statement in the file, as well as the statement conversion guidance information of the first type of SQL statement, can also be displayed in response to a request to display the statement analysis results.

[0079] For example, the analysis results of the above statements are displayed in a table, as shown in Table 1:

[0080] Table 1

[0081]

[0082] In this way, you can see the statement analysis results more clearly and intuitively, which facilitates subsequent checking of the statement analysis results.

[0083] Moreover, after displaying the correspondence between the file identifier of each file and the first type of SQL statement in the file, as well as the statement conversion guidance information of the first type of SQL statement, the statement conversion guidance information can also be modified based on the modification indication in response to the modification indication of the statement conversion guidance information.

[0084] This is beneficial when checking the statement analysis results. If any statement conversion guide information is found to be incorrect, it can be modified in time, making the statement analysis results more accurate.

[0085] In addition, to further speed up the analysis of SQL statements, you can also enable multi-threading and queue working modes, such as configuring the thread pool capacity and queue depth in the configuration file. The larger the thread pool capacity, the more threads can be created, the more tasks can be executed simultaneously, and the faster the task processing speed. For example, if the thread pool capacity is 6, it means that up to 6 task threads can be created. The queue is a container for storing task objects, that is, file objects. The larger the queue depth, the more file objects can be stored. For example, if the queue depth is 100, it means that up to 100 file objects can be stored.

[0086] For example, if the thread pool capacity is Q, then N scanning threads and M analysis threads can be created, M+N=Q.

[0087] Among them, N scanning threads are used to scan each file that meets the file scanning requirements to obtain the file object of the file, and the obtained file object is stuffed into a queue, and then M analysis threads are used to obtain the file object from the queue, and the first type of SQL statement is selected from the file object, and then based on multiple syntactic matching rules of the first type of SQL statement corresponding to the file type of the file and syntactic conversion guidance information corresponding to the multiple syntactic matching rules, statement conversion guidance information from the first type of SQL statement in the file to the second type of SQL statement is generated.

[0088] In this way, by adopting a multi-threaded working mode, the number of threads can be flexibly controlled according to the system requirements and hardware environment, and all threads can be uniformly managed and controlled, thereby improving the system's operating efficiency and reducing the system's operating pressure. Multiple threads can execute tasks simultaneously, which can further speed up the analysis of SQL statements.

[0089] In an embodiment of the present application, by parsing the configuration file, by parsing the pre-configured configuration file, the first type of SQL statement can be automatically obtained from each type of file, and the statement conversion guidance information of the first type of SQL statement to the second type of SQL statement is generated according to the syntax matching rules and the corresponding syntax conversion guidance information, and the file identifier of the file is corresponded with the first type of SQL statement in the file, and the statement conversion guidance information of the first type of SQL statement to form a statement analysis result, which speeds up the conversion efficiency of the SQL statement. In addition, the developer can also reasonably allocate the conversion work of the SQL statement based on the statement analysis result, providing convenience for task allocation.

[0090] Figure 2 A schematic diagram of the SQL statement analysis process is provided for an embodiment of the present application.

[0091] Step 1: Parse the configuration file.

[0092] During specific implementation, the configuration file is pre-configured based on the syntax differences between the first type of SQL statements and the second type of SQL statements.

[0093] For example, the contents of the configuration file are:

[0094] 1. app.name = sqlstat

[0095] 2. app.baseDir=H: / javacode / plat-1.8 / FMETS

[0096] 3. app.baseDir.isProject=true

[0097] 4. app.basedir.excludeDir=fmets-test-web

[0098] 5. app.workers = 6

[0099] 6. app.queue.depth=100

[0100] 7. app.source.file.extensions=.java;.c;.sh;.pl;.sql

[0101] 8. app.rule.sql.common[1].regex = Regular expression 1

[0102] 9. app.rule.sql.common[1].suggeston = Modify instruction information 1

[0103] 10. app.rule.sql.common[2].regex = Regular expression 2

[0104] 11. app.rule.sql.common[2].suggeston = Modify instruction information 2

[0105] Among them, app.name=sqlstat represents the project name;

[0106] app.baseDir=H: / javacode / plat-1.8 / FMETS represents the path of the file to be scanned;

[0107] app.basedir.excludeDir=fmets-test-web represents other file paths that do not need to be scanned;

[0108] app.workers=6 means the thread pool capacity is 6;

[0109] app.queue.depth=100 means the queue depth is 100;

[0110] app.source.file.extentions = .java; .c; .sh; .pl; .sql represents the file types supported for scanning;

[0111] app.rule.sql.common[1].regex = regular expression 1, representing the first regular expression of the sql file type (multiple syntactic matching rules for the first type of SQL statements);

[0112] app.rule.sql.common[1].suggeston = Conversion guidance information 1 represents the conversion guidance information corresponding to the first regular expression (the syntactic conversion guidance information corresponding to the syntactic matching rule);

[0113] app.rule.sql.common[2].regex = regular expression 2, representing the second regular expression of the sql file type;

[0114] app.rule.sql.common[2].suggeston=Conversion guidance information 2 represents the conversion guidance information corresponding to the second regular expression.

[0115] Therefore, by parsing the configuration file, we can obtain information such as thread pool capacity, file paths to be scanned, file paths that do not need to be scanned, result storage paths, queue depth, supported file types such as java, c, xml, sh, sql, qry, and ctl, multiple regular expressions for the first type of SQL statements, and conversion guidance information corresponding to the regular expressions.

[0116] In specific implementation, since the content of SQL statements is different for different file types, the regular expressions of SQL statements for different types of files and the conversion guidance information corresponding to the regular expressions are also different. Therefore, it is also possible to parse the configuration file according to the file type in the configuration file, and then load the multiple regular expressions corresponding to each file type and the conversion guidance information corresponding to the regular expressions into the rule mapping table corresponding to the file type.

[0117] For example, the rule mapping table of the Java class file is {(regular expression 1, conversion guide information 1), (regular expression 2, conversion guide information 2), (regular expression 3, conversion guide information 3)...}, and the rule mapping table of the C class file is {(regular expression 4, conversion guide information 4), (regular expression 5, conversion guide information 5), (regular expression 6, conversion guide information 6)...}.

[0118] In this way, different rule mapping tables can be selected according to different file types, which can reduce the number of SQL statement matches and shorten the SQL statement matching time.

[0119] Step 2: Create N scanning threads to scan files, generate file objects, and store the file objects in the queue.

[0120] During specific implementation, the number of scanning threads is configured according to the thread pool capacity. For example, two scanning threads are created. These two scanning threads can scan the files under the scanning path at the same time, parse the scanned files, extract the file features of the files, and then associate and combine the file features to obtain file objects. The file features include file, file type, the first type of SQL statements contained in the file, and the number of first type SQL statements, etc. The file objects are then stored in the queue for analysis by the analysis thread.

[0121] Step 3: Create M analysis threads to analyze the SQL statements in the file object and generate statement conversion guidance information.

[0122] During specific implementation, the number of analysis threads is configured according to the thread pool capacity. For example, if the thread pool capacity is Q, then M+N=Q. For example, 4 analysis threads are created. These 4 analysis threads can obtain file objects from the queue at the same time. Based on the file type in the file object, the analyzer corresponding to the file type is called to analyze the SQL statement in the file object, and each SQL statement is matched with the regular expression in the rule mapping table corresponding to the file type. If the syntactic element of any SQL statement successfully matches any regular expression, the conversion guidance information corresponding to this regular expression is determined as the conversion guidance information of this syntax, and each syntax and the conversion guidance information corresponding to each syntax is determined as the statement conversion guidance information of this SQL statement.

[0123] Step 4: Save the statement analysis results.

[0124] During specific implementation, the correspondence between the file identifier, the first type of SQL statement in the file, and the statement conversion guidance information of the first type of SQL statement can be saved, and the saving form can be a table form.

[0125] In addition, the result storage path can also be configured in the configuration file to store statement analysis results.

[0126] For example, the configuration information of the result storage path in the configuration file is: app.result.dir = H:\\goldenDB.

[0127] In this way, through the pre-configured configuration file, the preset type of files under the preset path can be automatically scanned, and based on the regular expressions of the SQL statements of various types of files and the corresponding conversion guidance information, the SQL statement analysis results with conversion guidance information are automatically generated, thereby improving the conversion efficiency of SQL statement syntax conversion.

[0128] In addition, saving the analysis results of SQL statements in the form of a table helps task assigners to confirm the workload more clearly and intuitively based on the table, facilitates task assignment, and further provides convenience for checking the analysis results of SQL statements. In addition, it also facilitates timely modification when any statement conversion guidance information is found to be incorrect.

[0129] When the method provided in the embodiments of the present application is implemented by software or hardware or a combination of software and hardware, the electronic device may include multiple functional modules, and each functional module may include software, hardware or a combination thereof.

[0130] Based on the same technical concept, an embodiment of the present application also provides a SQL statement analysis device. The principle of solving the problem by the SQL statement analysis device is similar to that of the above-mentioned SQL statement analysis method. Therefore, the implementation of the SQL statement analysis device can refer to the implementation of the SQL statement analysis method, and the repeated parts will not be repeated. Figure 3 A structural diagram of an SQL statement analysis device provided in an embodiment of the present application includes a parsing module 301, an acquisition module 302, a generation module 303, and a storage module 304.

[0131] Parsing module 301 is used to parse the configuration file of the statement analysis task to obtain task description information, wherein the task description information includes file scanning requirements, multiple syntax matching rules of the first type of SQL statement corresponding to each type of file, and syntax conversion guidance information corresponding to each syntax matching rule;

[0132] An acquisition module 302 is configured to acquire a first type of SQL statement from each file that meets the file scanning requirement;

[0133] A generating module 303 is configured to generate statement conversion guidance information from the first category SQL statement in the file to the second category SQL statement based on a plurality of syntax matching rules of the first category SQL statement corresponding to the file type of the file and syntax conversion guidance information corresponding to the plurality of syntax matching rules;

[0134] The saving module 304 is configured to save the correspondence between the file identifier of the file and the first type of SQL statement in the file, as well as the statement conversion guidance information of the first type of SQL statement, to form a statement analysis result.

[0135] In some embodiments, the acquisition module 302 is specifically configured to:

[0136] Scan each file that meets the file scanning requirement to obtain a file object of the file;

[0137] A first type of SQL statement is selected from the file object.

[0138] In some embodiments, the generating module 303 is specifically configured to:

[0139] Matching each first-category SQL statement in the file using a plurality of syntax matching rules for the first-category SQL statements corresponding to the file type of the file;

[0140] For a target syntax matching any syntax matching rule in the first type of SQL statement, determining the syntax conversion guidance information corresponding to the syntax matching rule as the syntax conversion guidance information corresponding to the target syntax;

[0141] Each target syntax and the syntax conversion guidance information corresponding to each target syntax are used as the sentence conversion guidance information.

[0142] In some embodiments, a display module 305 is further included:

[0143] The display module 305 is used to display the correspondence between the file identifier of each file and the first type of SQL statement in the file and the statement conversion guidance information of the first type of SQL statement in response to a display request of the statement analysis result after forming the statement analysis result.

[0144] In some embodiments, a modification module 306 is further included:

[0145] The modification module 306 is used to modify the statement conversion guidance information based on the modification instruction in response to the modification instruction of the statement conversion guidance information after the display module displays the correspondence between the file identifier of each file and the first type of SQL statement in the file, and the statement conversion guidance information of the first type of SQL statement.

[0146] The division of modules in the embodiments of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation. In addition, the functional modules in the embodiments of the present application may be integrated into one processor, or may exist physically separately, or two or more modules may be integrated into one module. The coupling between the modules can be achieved through some interfaces, which are usually electrical communication interfaces, but it is not ruled out that they may be mechanical interfaces or other forms of interfaces. Therefore, the modules described as separate components may or may not be physically separated, and may be located in one place or distributed to different locations of the same or different devices. The above-mentioned integrated modules can be implemented in the form of hardware or in the form of software functional modules.

[0147] After introducing the SQL statement analysis method and apparatus according to an exemplary embodiment of the present application, an electronic device according to another exemplary embodiment of the present application will be introduced next.

[0148] In some possible implementations, the electronic device of the present application may include at least one processor and at least one memory, wherein the memory stores program code that, when executed by the processor, causes the processor to perform the methods described above in this specification according to various exemplary embodiments of the present application.

[0149] Refer to the following Figure 4 The electronic device 130 implemented according to this embodiment of the present application is described. Figure 4 The electronic device 130 shown is merely an example and should not limit the functions and scope of use of the embodiments of the present application.

[0150] like Figure 4 As shown, the electronic device 130 is a general electronic device. Components of the electronic device 130 may include, but are not limited to, the at least one processor 131, the at least one memory 132, and a bus 133 connecting different system components (including the memory 132 and the processor 131).

[0151] Bus 133 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, and a processor or local bus using any of a variety of bus architectures.

[0152] The memory 132 may include a readable medium in the form of a volatile memory, such as a random access memory (RAM) 1321 and / or a cache memory 1322 , and may further include a read-only memory (ROM) 1323 .

[0153] The memory 132 may also include a program / utility 1325 having a set (at least one) of program modules 1324, such program modules 1324 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.

[0154] The electronic device 130 may also communicate with one or more external devices 134 (e.g., a keyboard, pointing device, etc.), one or more devices that enable a user to interact with the electronic device 130, and / or any device that enables the electronic device 130 to communicate with one or more other electronic devices (e.g., a router, a modem, etc.). Such communication may occur via an input / output (I / O) interface 135. Furthermore, the electronic device 130 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network such as the Internet) via a network adapter 136. As shown, the network adapter 136 communicates with other modules of the electronic device 130 via a bus 133. It should be understood that, although not shown, other hardware and / or software modules may be used in conjunction with the electronic device 130, including but not limited to microcode, device drivers, redundant processors, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0155] In an exemplary embodiment, a computer-readable storage medium including instructions is further provided, such as a memory 132 including instructions. The instructions can be executed by the processor 131 to implement the above-described SQL statement analysis method. Alternatively, the storage medium can be a non-transitory computer-readable storage medium, such as a ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, or optical data storage device.

[0156] In an exemplary embodiment, a computer program product is further provided. When the computer program product is called and executed by an electronic device, the electronic device is caused to execute any exemplary method provided in this application.

[0157] Furthermore, the computer program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or component, or any combination thereof. More specific examples (a non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, RAM, ROM, an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.

[0158] In the embodiments of the present application, the program product for SQL statement analysis may be a CD-ROM containing program code and may be run on a computing device. However, the program product of the present application is not limited thereto. In this document, a readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.

[0159] A readable signal medium may include a data signal transmitted in baseband or as part of a carrier wave, which carries readable program code. Such a transmitted data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A readable signal medium may also be any readable medium other than a readable storage medium that can transmit, propagate, or transfer a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0160] The program code contained on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, radio frequency (RF), etc., or any suitable combination of the foregoing.

[0161] The program code for performing the operations of the present application can be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java, C++, etc., and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code can be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, such as a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (e.g., via the Internet using an Internet service provider).

[0162] It should be noted that although several units or subunits of the device are mentioned in the detailed description above, this division is merely exemplary and not mandatory. In fact, depending on the embodiment of the application, the features and functions of two or more units described above can be embodied in a single unit. Conversely, the features and functions of a single unit described above can be further divided and embodied by multiple units.

[0163] Furthermore, although the operations of the method of the present application are described in a particular order in the accompanying drawings, this does not require or imply that the operations must be performed in this particular order, or that all illustrated operations must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps.

[0164] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0165] The present application is described with reference to the flowcharts and / or block diagrams of the methods, apparatus (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the steps in the flowchart and / or block diagram. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0166] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.

[0167] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0168] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present application.

[0169] Obviously, those skilled in the art may make various changes and modifications to this application without departing from the spirit and scope of this application. Thus, if these modifications and variations of this application fall within the scope of the claims of this application and their equivalents, this application is intended to include these modifications and variations.

Claims

1. A SQL statement analysis method, characterized in that: include: Parsing a configuration file of a statement analysis task to obtain task description information, wherein the task description information includes file scanning requirements, multiple syntax matching rules of the first type of SQL statement corresponding to each type of file, and syntax conversion guidance information corresponding to each syntax matching rule; Obtain a first type of SQL statement from each file that meets the file scanning requirements; Generate statement conversion guidance information from the first type of SQL statement in the file to the second type of SQL statement based on multiple syntax matching rules of the first type of SQL statement corresponding to the file type of the file and syntax conversion guidance information corresponding to the multiple syntax matching rules; saving a correspondence between the file identifier of the file and the first type of SQL statement in the file, and statement conversion guidance information of the first type of SQL statement, to form a statement analysis result; Generating statement conversion guidance information from the first type of SQL statement in the file to the second type of SQL statement in the file based on multiple syntax matching rules of the first type of SQL statement corresponding to the file type of the file and syntax conversion guidance information corresponding to the multiple syntax matching rules, including: Matching each first-category SQL statement in the file using a plurality of syntax matching rules for the first-category SQL statements corresponding to the file type of the file; For a target syntax matching any syntax matching rule in the first type of SQL statement, determining the syntax conversion guidance information corresponding to the syntax matching rule as the syntax conversion guidance information corresponding to the target syntax; Each target syntax and the syntax conversion guidance information corresponding to each target syntax are used as the statement conversion guidance information; wherein the first type of SQL statements are SQL statements used by the source database, and the second type of SQL statements are SQL statements used by the destination database.

2. The method according to claim 1, wherein Obtain the first type of SQL statements from each file that meets the file scanning requirements, including: Scan each file that meets the file scanning requirement to obtain a file object of the file; A first type of SQL statement is selected from the file object.

3. The method according to claim 1, wherein After forming the statement analysis results, it also includes: responding to a request to display a statement analysis result; The correspondence between the file identifier of each file and the first type of SQL statements in the file, as well as the statement conversion guidance information of the first type of SQL statements is displayed.

4. The method according to claim 3, wherein After displaying the correspondence between the file identifier of each file and the first type of SQL statement in the file, and the statement conversion guidance information of the first type of SQL statement, the method further includes: responding to an instruction to modify the statement conversion guidance information; Based on the modification instruction, the statement conversion guidance information is modified.

5. A SQL statement analysis device, characterized in that: include: A parsing module is used to parse the configuration file of the statement analysis task to obtain task description information, wherein the task description information includes file scanning requirements, multiple syntax matching rules of the first type of SQL statements corresponding to each type of file, and syntax conversion guidance information corresponding to each syntax matching rule; An acquisition module, configured to acquire a first type of SQL statement from each file that meets the file scanning requirement; a generating module configured to generate statement conversion guidance information from the first category SQL statement in the file to the second category SQL statement based on a plurality of syntax matching rules of the first category SQL statement corresponding to the file type of the file and syntax conversion guidance information corresponding to the plurality of syntax matching rules; a saving module, configured to save a correspondence between the file identifier of the file and the first type of SQL statement in the file, and statement conversion guidance information of the first type of SQL statement, to form a statement analysis result; The generation module is specifically used to: Matching each first-category SQL statement in the file using a plurality of syntax matching rules for the first-category SQL statements corresponding to the file type of the file; For a target syntax matching any syntax matching rule in the first type of SQL statement, determining the syntax conversion guidance information corresponding to the syntax matching rule as the syntax conversion guidance information corresponding to the target syntax; Each target syntax and the syntax conversion guidance information corresponding to each target syntax are used as the statement conversion guidance information; wherein the first type of SQL statements are SQL statements used by the source database, and the second type of SQL statements are SQL statements used by the destination database.

6. The device according to claim 5, characterized in that The acquisition module is specifically used to: Scan each file that meets the file scanning requirement to obtain a file object of the file; A first type of SQL statement is selected from the file object.

7. The device according to claim 5, characterized in that Also includes display modules: The display module is used to display the correspondence between the file identifier of each file and the first type of SQL statement in the file and the statement conversion guidance information of the first type of SQL statement in response to a display request of the statement analysis result after forming the statement analysis result.

8. The device according to claim 7, wherein Also includes modification modules: The modification module is used to modify the statement conversion guidance information based on a modification instruction in response to the modification instruction after the display module displays the correspondence between the file identifier of each file and the first type of SQL statement in the file and the statement conversion guidance information of the first type of SQL statement.

9. An electronic device, characterized in that: include: at least one processor, and a memory communicatively coupled to the at least one processor, wherein: The memory stores instructions that can be executed by the at least one processor. The instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 4.

10. A storage medium, characterized in that: When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device can execute the method according to any one of claims 1 to 4.

11. A computer program product, characterized in that When the computer program product is called and executed by an electronic device, the electronic device is caused to execute the method according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • SQL dialect conversion method, device and system and storage medium

    CN114764558A

  • Method for verifying conversion, apparatus and program of the same

    US20130151479A1