CN114047927B - Database code conversion method and system - Google Patents

Database code conversion method and system Download PDF

Info

Publication number
CN114047927B
CN114047927B CN202210023864.XA CN202210023864A CN114047927B CN 114047927 B CN114047927 B CN 114047927B CN 202210023864 A CN202210023864 A CN 202210023864A CN 114047927 B CN114047927 B CN 114047927B
Authority
CN
China
Prior art keywords
database
language
code
statement information
original
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202210023864.XA
Other languages
Chinese (zh)
Other versions
CN114047927A (en
Inventor
王涛
朱春华
曾繁诚
刘捷
车昱晖
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shandong Jerei Digital Technology Co Ltd
Original Assignee
Shandong Jerei Digital Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shandong Jerei Digital Technology Co Ltd filed Critical Shandong Jerei Digital Technology Co Ltd
Priority to CN202210023864.XA priority Critical patent/CN114047927B/en
Publication of CN114047927A publication Critical patent/CN114047927A/en
Application granted granted Critical
Publication of CN114047927B publication Critical patent/CN114047927B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/51Source to source
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/21Design, administration or maintenance of databases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/36Software reuse

Abstract

The invention relates to a database code conversion method and a system, wherein the method comprises the following steps: acquiring an original database code of an application program; determining statement information of each database to be converted in the original database code according to the first database language keyword; the keywords are keywords in addition, deletion, modification and query sentences in the original database language; the first database language is the database language in the original database code; and converting the statement information of each database to be converted into the database code of the second database language according to the database language template of the second database language. The invention improves the conversion efficiency of the database codes.

Description

Database code conversion method and system
Technical Field
The invention relates to the technical field of databases, in particular to a database code conversion method and a database code conversion system.
Background
With the development of internet technology, technology updating is faster and faster, application programs are also faster and faster, the service volume of the application programs is larger and larger, the data volume stored in the database is larger and larger as time goes on, the updating of the application programs is accompanied with the replacement of database languages, and the replacement of the database languages greatly influences the iteration efficiency of the application programs.
The existing database code conversion is usually to rewrite the database code along with the iteration of the application program, and the database carding also needs a large amount of time, so that the development time is greatly increased, and the development efficiency is reduced.
Disclosure of Invention
The invention aims to provide a database code conversion method, which improves the conversion efficiency of database codes.
In order to achieve the purpose, the invention provides the following scheme:
a database transcoding method, comprising:
acquiring an original database code of an application program;
determining statement information of each database to be converted in the original database code according to the first database language keyword; the keywords are keywords in addition, deletion, modification and query sentences in the original database language; the first database language is a database language in the original database code;
and converting the statement information of each database to be converted into the database code of the second database language according to the database language template of the second database language.
Optionally, the determining, according to the first database language keyword, statement information of each database to be converted in the original database code specifically includes:
matching keywords line by line to the original database code according to a first database language, and determining sql statement information of each database; the database sql statement information comprises a database table name, the database sql statement information further comprises at least two items of database operation items, query condition items, grouping items, TOP function items or sorting items, and the database operation items comprise addition, deletion, modification and query.
Optionally, the converting, according to a database language template of a second database language, the statement information of each database to be converted into the database code of the second database language specifically includes:
generating a database language template according to the second database language;
and converting the sql statement information of each database into a database code of the second database language according to the database language template.
Optionally, the generating a database language template according to the second database language specifically includes:
and generating a Freemarker template according to the second database language.
The invention also discloses a database code conversion system, which comprises:
the original database code acquisition module is used for acquiring an original database code of the application program;
the database statement information determining module is used for determining statement information of each database to be converted in the original database code according to the first database language keyword; the keywords are keywords in addition, deletion, modification and query sentences in the original database language; the first database language is a database language in the original database code;
and the language conversion module is used for converting the statement information of each database to be converted into the database code of the second database language according to the database language template of the second database language.
Optionally, the database statement information determining module specifically includes:
the database statement information determining unit is used for matching keywords to the original database codes line by line according to a first database language and determining sql statement information of each database; the database sql statement information comprises a database table name, the database sql statement information further comprises at least two items of database operation items, query condition items, grouping items, TOP function items or sorting items, and the database operation items comprise addition, deletion, modification and query.
Optionally, the language conversion module specifically includes:
the database language template generating unit is used for generating a database language template according to the second database language;
and the language conversion unit is used for converting the information of each database sql statement into the database code of the second database language according to the database language template.
Optionally, the database language template generating unit specifically includes:
and the database language template generating subunit is used for generating a Freemarker template according to the second database language.
According to the specific embodiment provided by the invention, the invention discloses the following technical effects:
the method and the device determine the statement information of each database to be converted in the original database code according to the keywords of the first database language, convert the statement information of each database to be converted into the database code of the second database language according to the database language template of the second database language, convert the database code based on the template, and improve the reusability and conversion efficiency of the database code.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings needed to be used in the embodiments will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings without inventive exercise.
FIG. 1 is a flow chart of a database transcoding method according to the present invention;
FIG. 2 is a diagram illustrating a database transcoding system according to the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The invention aims to provide a database code conversion method, which improves the conversion efficiency of database codes.
In order to make the aforementioned objects, features and advantages of the present invention comprehensible, embodiments accompanied with figures are described in further detail below.
Fig. 1 is a schematic flow chart of a database code conversion method according to the present invention, and as shown in fig. 1, a database code conversion method includes:
step 101: and acquiring the original database code of the application program.
And stripping the database language related information contained in the application program from the complex application program, and scanning, reading and analyzing the database code of the application program.
Step 102: determining statement information of each database to be converted in the original database code according to the first database language keyword; the keywords are keywords in addition, deletion, modification and query sentences in the original database language; the first database language is the database language in the original database code.
The method comprises the steps of confirming a table used in an application program database according to keywords, reading and analyzing to obtain corresponding sql statements, storing language related information of the application program database obtained through scanning, reading and analyzing into the database, and storing processed data into the database, so that complex logic of the application program is separated, the language related information of the database is simple and clear, and subsequent analysis of the sql statements is facilitated.
And (3) according to the database table addition, deletion, modification and statement search keyword analysis in the database language, confirming the operation language, operation condition and other data used by the database table in the application program, and storing the data into the database.
Wherein, step 102 specifically comprises:
matching keywords line by line to the original database code according to a first database language, and determining sql statement information of each database; the database sql statement information comprises a database table name, the database sql statement information further comprises at least two items of database operation items, query condition items, grouping items, TOP function items or sorting items, and the database operation items comprise addition, deletion, modification and query.
And acquiring an original database code by a readLine method of a buffer reader, reading the original database code line by line, and confirming the used database table name according to the database language key words.
Confirming keywords of an application program operation database table, reading each method in the application program, analyzing whether a database operation action exists in the method through the keywords, and if the database operation action exists, acquiring a name of a corresponding database table.
And confirming the addition, deletion, modification and search of sentence keywords of the database table according to the database language used by the application program, and confirming the corresponding conditions of the sentence keywords through the operation language used by the database table in the database language keyword analysis method. And analyzing the operation language conditions to generate a non-universal database table operation statement.
Step 103: and converting the statement information of each database to be converted into the database code of the second database language according to the database language template of the second database language.
And compiling different general database operation templates according to different database languages. And generating a general database query code by using the database table name obtained by the analysis in the steps and the operation language used by the database table, adding a non-general database operation statement to the generated database query code, integrating the database query code into a database code of a new application program, and finishing the whole conversion process.
Wherein, step 103 specifically comprises:
and generating a database language template according to the second database language.
And converting the sql statement information of each database into database codes of a second database language according to the database language template.
Generating a database language template according to a second database language, specifically comprising:
a Freemarker template is generated according to the second database language.
The invention refines the application program into a tiny unit taking the database table as a unit, reduces the time for analyzing the logic of the application program and reduces the development time. The method is based on template conversion database codes, has high reusability, flexible use and strong expansibility, and can analyze the database codes of new application programs by adding keywords according to some special conditions.
The following describes a database transcoding method according to the present invention in an embodiment.
The framework used in this embodiment is SpringBoot, the language used is java, and the SpringBoot database code includes: the database table Entity class Entity, service layer, dao layer and mapper layer specifically comprises the following steps:
step 1: scanning, reading and analyzing an application program database code, confirming a table used in an application program database according to a keyword, reading and analyzing to obtain a corresponding sql statement, storing language-related information of the application program database obtained through scanning, reading and analyzing into the database, analyzing the sql statement according to the table name of the database and the sql statement obtained after processing, and converting to generate a corresponding database code.
Step 2: and (3) according to the database table addition, deletion, modification and statement search keyword analysis in the database language, confirming the operation language, operation condition and other data used by the database table in the application program, and storing the data into the database.
Step 3: and generating a corresponding database code according to a Freemarker template of the new database language.
In Step1, reading the file content of the application program by using a java language writing method, analyzing and matching keywords line by line, and analyzing and matching the confirmed database sql statements, for example: obtaining file contents by a readLine method of a buffer reader, reading the file contents line by line, and confirming used table names according to language keywords of a database, for example: the SELECT in the database sql statement SELECT Q1 FROM TABLE1 is a database language keyword, the TABLE1 is a database TABLE name, and the database sql statement and the TABLE name are stored in the database.
In Step2, the database statements obtained in Step1 are read from the database, and the database statements are analyzed one by one.
Confirming the operation sentences of the database table according to the sentence key words of the database table addition, deletion, modification and search:
if the keyword SELECT is successfully matched, the database table operation is a query operation:
the first step is to judge whether the query condition item exists in the sql statement or not, and if so, the query condition item is recorded. For example: SELECT TOP 10Q 2, COUNT (1) FROM TABLE1 WHERE Q1= "GROUP BY Q2 ORDER BY COUNT (1) DESC, Q2, COUNT (1), WHERE Q1 is the query condition item.
And secondly, judging whether a grouping keyword exists in the sql statement or not, and recording a grouping item and a query item if the grouping keyword exists in the sql statement. For example: SELECT TOP 10Q 2, COUNT (1) FROM TABLE1 WHERE Q1= "GROUP BY Q2 ORDER BY COUNT (1) DESC, Q2, COUNT (1) is query term, Q2 is grouping term.
And thirdly, judging whether the TOP function exists in the sql statement or not, and recording the TOP function if the TOP function exists. For example:
SELECT TOP 10Q 2, COUNT (1) FROM TABLE1 WHERE Q1= "GROUP BY Q2 or BY COUNT (1) DESC, Q2, COUNT (1), get TOP function in sql statement according to TOP key, TOP function in statement is TOP 10, convert TOP function into new database language, for example, into mymit sql database language, TOP 10 is converted into LIMIT 0, 10. And records the post-conversion TOP function terms.
Step four, judging whether the result set is sorted or not in the sql statement, and if the ORDER BY keyword exists, recording a sorting item, for example: SELECT TOP 10Q 2, COUNT (1) FROM TABLE1 WHERE Q1= "GROUP BY Q2 ORDER BY COUNT (1) DESC, WHERE ORDER BY COUNT (1) DESC is the sort entry.
And fifthly, generating a new sql statement according to the new database language needing to be converted. For example, SELECT TOP 10Q 2, COUNT (1) FROM TABLE1 WHERE Q1= "GROUP BY Q2 or der BY COUNT (1) DESC converts to MYSQL query, generates a new sql statement FROM the new database language, SELECT Q2, COUNT (1) FROM TABLE1 WHERE Q1 =" GROUP BY Q2 or der BY COUNT (1) DESC LIMIT 0, 10.
Analyzing the operation language of each database statement, recording the operation language of each database table, analyzing the operation condition of the operation language of the database statement, recording the condition of the operation language of each database statement, and establishing a database table name and a database operation language association relation table thereof.
In Step3, generating a corresponding database language configuration file according to the new database language to be converted, inquiring and injecting database table information acquired in Step2 into a template according to a Freemarker template of the new database language to be converted through the table name and the fields in the table acquired by analysis in Step2, and generating a database table Entity type Entity. And generating a corresponding database table operation implementation class (service layer) through the operation language of each database table in Step 2. And injecting the sql sentences obtained by analysis in Step2 into the corresponding template to generate a dao layer and a mapper layer of the database operation. For example: inquiring TABLE1 about TABLE name and TABLE field obtained through Step2, freemarkerutilis = new freemarkerutilis (folder path); and generating an Entity class Entity of the database table by using a template path, a generated file path and a generated method of FreemarkerUtils for information to be injected.
Fig. 2 is a schematic structural diagram of a database code conversion system according to the present invention, and as shown in fig. 2, the database code conversion system includes:
the original database code obtaining module 201 is configured to obtain an original database code of an application.
A database statement information determining module 202, configured to determine, according to the first database language keyword, statement information of each database to be converted in the original database code; the keywords are keywords in addition, deletion, modification and query sentences in the original database language; the first database language is the database language in the original database code.
The language conversion module 203 is configured to convert the statement information of each database to be converted into the database code of the second database language according to the database language template of the second database language.
The database statement information determining module 202 specifically includes:
the database statement information determining unit is used for matching keywords to the original database codes line by line according to the first database language and determining sql statement information of each database; the database sql statement information comprises a database table name, the database sql statement information further comprises at least two items of database operation items, query condition items, grouping items, TOP function items or sorting items, and the database operation items comprise addition, deletion, modification and query.
The language conversion module 203 specifically includes:
and the database language template generating unit is used for generating a database language template according to the second database language.
And the language conversion unit is used for converting the sql statement information of each database into the database code of the second database language according to the database language template.
The database language template generating unit specifically comprises:
and the database language template generating subunit is used for generating a Freemarker template according to the second database language.
The embodiments in the present description are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other. For the system disclosed by the embodiment, the description is relatively simple because the system corresponds to the method disclosed by the embodiment, and the relevant points can be referred to the method part for description.
The principles and embodiments of the present invention have been described herein using specific examples, which are provided only to help understand the method and the core concept of the present invention; meanwhile, for a person skilled in the art, according to the idea of the present invention, the specific embodiments and the application range may be changed. In view of the above, the present disclosure should not be construed as limiting the invention.

Claims (6)

1. A database transcoding method, comprising:
acquiring an original database code of an application program;
determining statement information of each database to be converted in the original database code according to the first database language keyword; the keywords are keywords in addition, deletion, modification and query sentences in the original database language; the first database language is a database language in the original database code; storing the database sql sentences and the table names in a database for storage;
reading the obtained database statements from a database, and converting the statement information of each database to be converted into database codes of a second database language according to a database language template of the second database language;
the determining of statement information of each database to be converted in the original database code according to the first database language keyword specifically includes:
matching keywords line by line to the original database code according to a first database language, and determining sql statement information of each database; the database sql statement information comprises a database table name, the database sql statement information further comprises at least two items of database operation items, query condition items, grouping items, TOP function items or sorting items, and the database operation items comprise addition, deletion, modification and query.
2. The database code conversion method according to claim 1, wherein the converting, according to the database language template of the second database language, each piece of database statement information to be converted into the database code of the second database language specifically includes:
generating a database language template according to the second database language;
and converting the sql statement information of each database into a database code of the second database language according to the database language template.
3. The database code conversion method according to claim 2, wherein the generating a database language template according to the second database language specifically includes:
and generating a Freemarker template according to the second database language.
4. A database transcoding system, comprising:
the original database code acquisition module is used for acquiring an original database code of the application program;
the database statement information determining module is used for determining statement information of each database to be converted in the original database code according to the first database language keyword; the keywords are keywords in addition, deletion, modification and query sentences in the original database language; the first database language is a database language in the original database code; storing the database sql sentences and the table names in a database for storage;
the language conversion module is used for reading the obtained database statements from the database and converting the statement information of each database to be converted into the database codes of a second database language according to a database language template of the second database language;
the database statement information determining module specifically includes:
the database statement information determining unit is used for matching keywords to the original database codes line by line according to a first database language and determining sql statement information of each database; the database sql statement information comprises a database table name, the database sql statement information further comprises at least two items of database operation items, query condition items, grouping items, TOP function items or sorting items, and the database operation items comprise addition, deletion, modification and query.
5. The database transcoding system of claim 4, wherein the language transformation module specifically comprises:
the database language template generating unit is used for generating a database language template according to the second database language;
and the language conversion unit is used for converting the information of each database sql statement into the database code of the second database language according to the database language template.
6. The database transcoding system of claim 5, wherein the database language template generating unit specifically comprises:
and the database language template generating subunit is used for generating a Freemarker template according to the second database language.
CN202210023864.XA 2022-01-11 2022-01-11 Database code conversion method and system Active CN114047927B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210023864.XA CN114047927B (en) 2022-01-11 2022-01-11 Database code conversion method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210023864.XA CN114047927B (en) 2022-01-11 2022-01-11 Database code conversion method and system

Publications (2)

Publication Number Publication Date
CN114047927A CN114047927A (en) 2022-02-15
CN114047927B true CN114047927B (en) 2022-04-29

Family

ID=80213544

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210023864.XA Active CN114047927B (en) 2022-01-11 2022-01-11 Database code conversion method and system

Country Status (1)

Country Link
CN (1) CN114047927B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102073490A (en) * 2009-11-25 2011-05-25 阿里巴巴集团控股有限公司 Method and device for translating database language
CN109271168A (en) * 2018-08-09 2019-01-25 上海鲸鱼机器人科技有限公司 A kind of code conversion method, device and equipment, storage medium
CN112765209A (en) * 2021-02-07 2021-05-07 浪潮云信息技术股份公司 SQL statement syntax migration method and system between databases
CN113051285A (en) * 2021-03-25 2021-06-29 未鲲(上海)科技服务有限公司 SQL statement conversion method, system, equipment and storage medium

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120124550A1 (en) * 2006-02-22 2012-05-17 Robert Nocera Facilitating database application code translation from a first application language to a second application language
US9274773B2 (en) * 2011-06-23 2016-03-01 Microsoft Technology Licensing, Llc Translating programming language patterns into database schema patterns
CN111061757B (en) * 2019-12-19 2023-03-31 用友网络科技股份有限公司 Language conversion method and device of database, electronic equipment and storage medium

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102073490A (en) * 2009-11-25 2011-05-25 阿里巴巴集团控股有限公司 Method and device for translating database language
CN109271168A (en) * 2018-08-09 2019-01-25 上海鲸鱼机器人科技有限公司 A kind of code conversion method, device and equipment, storage medium
CN112765209A (en) * 2021-02-07 2021-05-07 浪潮云信息技术股份公司 SQL statement syntax migration method and system between databases
CN113051285A (en) * 2021-03-25 2021-06-29 未鲲(上海)科技服务有限公司 SQL statement conversion method, system, equipment and storage medium

Also Published As

Publication number Publication date
CN114047927A (en) 2022-02-15

Similar Documents

Publication Publication Date Title
CN109753909B (en) Resume analysis method based on content blocking and BilSTM model
US5029084A (en) Japanese language sentence dividing method and apparatus
CN108829858A (en) Data query method, apparatus and computer readable storage medium
JP2001167087A (en) Device and method for retrieving structured document, program recording medium for structured document retrieval and index preparing method for structured document retrieval
CN107102993B (en) User appeal analysis method and device
KR102080081B1 (en) Automatic review program of poisonous clauses and omission clauses in international construction contracts
CN110597844B (en) Unified access method for heterogeneous database data and related equipment
CN111651198B (en) Automatic code abstract generation method and device
CN111061882A (en) Knowledge graph construction method
CN111176650B (en) Parser generation method, search method, server, and storage medium
CN102654873A (en) Tourism information extraction and aggregation method based on Chinese word segmentation
CN114266256A (en) Method and system for extracting new words in field
CN114398315A (en) Data storage method, system, storage medium and electronic equipment
CN112380848B (en) Text generation method, device, equipment and storage medium
CN114047927B (en) Database code conversion method and system
CN107291952B (en) Method and device for extracting meaningful strings
CN113849413A (en) Code rule checking method and system based on knowledge base feature matching
CN112488593A (en) Auxiliary bid evaluation system and method for bidding
CN112307235B (en) Naming method and device of front-end page element and electronic equipment
CN109145297B (en) Network vocabulary semantic analysis method and system based on hash storage
CN111309853B (en) Code searching method based on structured information
CN111177312A (en) Open source code searching method with grammar and semantics fused
US6523031B1 (en) Method for obtaining structured information exists in special data format from a natural language text by aggregation
CN111444402A (en) Analysis method for community detection based on index construction and social factor control network
CN1841372A (en) Method and apparatus for helping user to forming structured diagram according to non-structured information source

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant