CN117667926A - Correction method and device for database table establishment statement, electronic equipment and medium - Google Patents

Correction method and device for database table establishment statement, electronic equipment and medium Download PDF

Info

Publication number
CN117667926A
CN117667926A CN202311600880.1A CN202311600880A CN117667926A CN 117667926 A CN117667926 A CN 117667926A CN 202311600880 A CN202311600880 A CN 202311600880A CN 117667926 A CN117667926 A CN 117667926A
Authority
CN
China
Prior art keywords
field
name
field definition
database
definition
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.)
Pending
Application number
CN202311600880.1A
Other languages
Chinese (zh)
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.)
China Construction Bank Corp
CCB Finetech Co Ltd
Original Assignee
China Construction Bank Corp
CCB Finetech 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 China Construction Bank Corp, CCB Finetech Co Ltd filed Critical China Construction Bank Corp
Priority to CN202311600880.1A priority Critical patent/CN117667926A/en
Publication of CN117667926A publication Critical patent/CN117667926A/en
Pending legal-status Critical Current

Links

Abstract

The disclosure provides a correction method, a correction device, electronic equipment and a correction medium for database table-building sentences, which can be applied to the technical field of data processing. The method comprises the following steps: respectively analyzing table construction sentences of a source database and a target database to generate a first structure body and a second structure body, wherein the first structure body comprises a table name and a first field definition corresponding to the table name, and the second structure body comprises the table name and a second field definition corresponding to the table name; respectively comparing the first field definition and the second field definition corresponding to the same table name; in response to the first field definition corresponding to the table name not being consistent with the second field definition, correcting the second field definition by utilizing a field definition conversion rule between the source database and the target database; and correcting the table-building statement of the target database according to the corrected second field definition.

Description

Correction method and device for database table establishment statement, electronic equipment and medium
Technical Field
The disclosure relates to the technical field of data processing, and in particular relates to a correction method, a correction device, an electronic device, a medium and a program product of a database table establishment statement.
Background
The existing system often faces changing databases, for example, the database of the manufacturer A is changed into the database of the manufacturer B, the data types are often defined between the two databases, a developer can manually complete the reconstruction work of the table-building sentence, but the number of data tables of one system is hundreds, fields are even thousands, and how to recheck the correctness of the table-building sentence reconstruction is a great problem.
The two text files can be effectively compared by using a "Beyond complete" file comparison tool, but the method is suitable for comparing two text files with the same sequence of most contents, and if the two text files with the same sequence of the two text files cannot be compared, and then the correction of the table building file cannot be completed.
Disclosure of Invention
In view of the foregoing, the present disclosure provides a method, apparatus, electronic device, medium, and program product for correcting a database build statement.
According to a first aspect of the present disclosure, there is provided a method for correcting a database build statement, including: respectively analyzing table construction sentences of a source database and a target database to generate a first structure body and a second structure body, wherein the first structure body comprises a table name and a first field definition corresponding to the table name, and the second structure body comprises the table name and a second field definition corresponding to the table name; respectively comparing the first field definition and the second field definition corresponding to the same table name; in response to the first field definition corresponding to the table name not being consistent with the second field definition, correcting the second field definition by utilizing a field definition conversion rule between the source database and the target database; and correcting the table-building statement of the target database according to the corrected second field definition.
According to an embodiment of the present disclosure, parsing a build statement of a source database and a target database, respectively, to generate a first structure and a second structure, includes: analyzing a table establishing statement of a source database, and extracting a table name, a first field name corresponding to the table name and a first field type; analyzing a table establishing statement of the target database, and extracting a table name, a second field name corresponding to the table name and a second field type; generating a first LinkedHashMap structure body according to the table name, the first field name and the first field type, wherein the first field name and the first field type form a first field definition; and generating a second LinkedHashMap structure according to the table name, the second field name and the second field type, wherein the second field name and the second field type form a second field definition.
According to an embodiment of the present disclosure, in response to a first field definition and a second field definition corresponding to a table name not being identical, correcting the second field definition using a field definition conversion rule between a source database and a target database, includes: comparing the first field name with the second field name, and comparing the first field type with the second field type; reading a field definition conversion rule from the source database to the target database in the case that the first field name and the second field name are not identical and/or in the case that the first field type and the second field type are not identical; and correcting the second field name and/or the second field type according to the field definition conversion rule.
According to an embodiment of the present disclosure, the first LinkedHashMap structure and the second LinkedHashMap structure are in the form of nested key-value pairs, wherein keys of an outer layer of the key-value pairs represent table names, corresponding values are key-value pairs of an inner layer, keys of the inner layer represent first field names or second field names, and corresponding values are first field types or second field types.
According to an embodiment of the present disclosure, comparing the first field definition and the second field definition corresponding to the same table name, respectively, includes: and respectively comparing the first field definition and the second field definition corresponding to the same table name by taking the table name as a key.
According to an embodiment of the present disclosure, before comparing the first field definition and the second field definition corresponding to the same table name, respectively, the method further includes: generating a table establishing statement corresponding to the table name according to the second field definition corresponding to the table name in response to the table name in the source database not existing in the target database; and creating a table corresponding to the table name in the target database according to the table creating statement corresponding to the table name.
According to an embodiment of the present disclosure, the correction method of the database table-building statement further includes: storing the corrected list-building sentence as comma separated value file format; and applying the list-establishing sentence in comma separated value file format to the target database, and executing the list-establishing sentence to update the target database.
According to an embodiment of the present disclosure, in response to the first field definition and the second field definition corresponding to the table name not being identical, correcting the second field definition using a field definition conversion rule between the source database and the target database, further comprising: comparing the field length, the default value and the field constraint in the first field definition and the second field definition respectively; reading a field definition conversion rule from the source database to the target database in response to the fact that the field lengths, the default values and the field constraints in the first field definition and the second field definition are inconsistent; and correcting the field length, the default value and the field constraint in the second field definition according to the field definition conversion rule.
A second aspect of the present disclosure provides a correction device for a database tabulation statement, including: the generating module is used for respectively analyzing the table establishing sentences of the source database and the target database to generate a first structure body and a second structure body, wherein the first structure body comprises a table name and a first field definition corresponding to the table name, and the second structure body comprises the table name and a second field definition corresponding to the table name; the comparison module is used for respectively comparing the first field definition and the second field definition corresponding to the same table name; the first correction module is used for correcting the second field definition by utilizing a field definition conversion rule between the source database and the target database in response to the inconsistency of the first field definition and the second field definition corresponding to the table name; and the second correction module is used for correcting the table establishment statement of the target database according to the corrected second field definition.
A third aspect of the present disclosure provides an electronic device, comprising: one or more processors; and a memory for storing one or more programs, wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to perform the method described above.
A fourth aspect of the present disclosure also provides a computer-readable storage medium having stored thereon executable instructions that, when executed by a processor, cause the processor to perform the above-described method.
A fifth aspect of the present disclosure also provides a computer program product comprising a computer program which, when executed by a processor, implements the above method.
According to the correction method, the correction device, the electronic equipment, the medium and the program product for the database table construction statement, the disordered data information can be organized into an ordered data structure through analyzing the table construction statement generation structure, the data comparison of the source database and the target database is facilitated, and the field definition conversion rule is utilized to correct the field definition with difference, so that the fact that in the data conversion process, the attribute of each element in the source database can be correctly mapped to the corresponding attribute in the target database is ensured, and the accuracy and the consistency of the data are maintained, so that the accuracy of the table construction statement in the correction process can be improved.
Drawings
The foregoing and other objects, features and advantages of the disclosure will be more apparent from the following description of embodiments of the disclosure with reference to the accompanying drawings, in which:
FIG. 1 schematically illustrates an application scenario diagram of a method and apparatus for correction of database build statements according to an embodiment of the disclosure;
FIG. 2 schematically illustrates a flow chart of a method of correction of a database build statement in accordance with an embodiment of the disclosure;
FIG. 3 schematically illustrates a flow chart of first and second structure generation in a method of correction of a database build statement in accordance with an embodiment of the disclosure;
FIG. 4 schematically illustrates a flow chart of modifying a second field definition using field definition conversion rules in a method of modifying a database build statement in accordance with an embodiment of the disclosure;
FIG. 5 schematically illustrates a schematic diagram of a method of correction of a database build statement in accordance with an embodiment of the disclosure;
FIG. 6 schematically illustrates a block diagram of a correction apparatus of a database build statement according to an embodiment of the disclosure; and
fig. 7 schematically illustrates a block diagram of an electronic device adapted to implement a method of correction of a database build statement, according to an embodiment of the disclosure.
Detailed Description
Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. It should be understood that the description is only exemplary and is not intended to limit the scope of the present disclosure. In the following detailed description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the embodiments of the present disclosure. It may be evident, however, that one or more embodiments may be practiced without these specific details. In addition, in the following description, descriptions of well-known structures and techniques are omitted so as not to unnecessarily obscure the concepts of the present disclosure.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. The terms "comprises," "comprising," and/or the like, as used herein, specify the presence of stated features, steps, operations, and/or components, but do not preclude the presence or addition of one or more other features, steps, operations, or components.
All terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art unless otherwise defined. It should be noted that the terms used herein should be construed to have meanings consistent with the context of the present specification and should not be construed in an idealized or overly formal manner.
Where expressions like at least one of "A, B and C, etc. are used, the expressions should generally be interpreted in accordance with the meaning as commonly understood by those skilled in the art (e.g.," a system having at least one of A, B and C "shall include, but not be limited to, a system having a alone, B alone, C alone, a and B together, a and C together, B and C together, and/or A, B, C together, etc.).
In the technical scheme of the disclosure, the related data (such as including but not limited to personal information of a user) are collected, stored, used, processed, transmitted, provided, disclosed, applied and the like, all conform to the regulations of related laws and regulations, necessary security measures are adopted, and the public welcome is not violated.
Keyword introduction:
the structure body comprises: a structure (Struct) is a type of data in a programming language that is used to combine multiple different types of data members to represent a complex data structure. The structure may contain different types of data, such as integers, floating point numbers, characters, pointers, etc., which may be grouped together in a custom order.
LinkedHashMap: chinese is translated into a linked-list hash map, hash, i.e. HashMap, generally meaning a hash, simply by a function that maps one value to another, better value. Essentially, the HashMap and doubly linked list are combined into one, namely LinkedHashMap, but HashMap is unordered and LinkedHashMap is ordered.
The field defines the conversion rule: a field definition conversion rule is a rule that defines a field definition conversion relationship between a source database and a target database. It describes how to convert field definitions in the source database into field definitions in the target database, including the conversion of information such as field names, field types, lengths, constraints, etc. The field definition conversion rule generally exists in the form of a mapping relationship, which includes a correspondence relationship between a source database field definition and a target database field definition. These mappings may be defined according to specific requirements and database types, common transformation rules include:
field name mapping: and defining the corresponding relation between the field names of the source database and the field names of the target database. For example, the "ID" field in the source database is mapped to the "ID_COLUMN" field in the target database.
Field type mapping: a correspondence between the source database field type and the target database field type is defined. For example, the "VARCHAR" type in the source database is mapped to the "VARCHAR 2" type in the target database.
Field length mapping: and defining the corresponding relation between the field length of the source database and the field length of the target database. For example, the "VARCHAR (50)" length in the source database is mapped to the "VARCHAR 2 (100)" length in the target database.
Constraint mapping: a correspondence between the source database field constraints and the target database field constraints is defined. For example, the "NOT NULL" constraint in the source database is mapped to the "NN" constraint in the target database.
The field definition conversion rules may be defined and extended according to specific database types and requirements. In the scenes of database migration, data synchronization or data conversion, etc., the field definition conversion rule is used to ensure that the field definition between the source database and the target database is consistent, so as to avoid data inconsistency or error caused by the difference of the field definition.
The embodiment of the disclosure provides a correction method of a database table-building statement, which comprises the following steps: respectively analyzing table construction sentences of a source database and a target database to generate a first structure body and a second structure body, wherein the first structure body comprises a table name and a first field definition corresponding to the table name, and the second structure body comprises the table name and a second field definition corresponding to the table name; respectively comparing the first field definition and the second field definition corresponding to the same table name; in response to the first field definition corresponding to the table name not being consistent with the second field definition, correcting the second field definition by utilizing a field definition conversion rule between the source database and the target database; and correcting the table-building statement of the target database according to the corrected second field definition. According to the correction method for the database table-building statement, the structure body is generated by analyzing the table-building statement, disordered data information can be organized into an ordered data structure, data comparison of a source database and a target database is facilitated, field definition conversion rules are utilized to correct field definitions with differences, the fact that in the data conversion process, the properties of elements in the source database can be correctly mapped to the corresponding properties in the target database is ensured, and the accuracy and consistency of the data are maintained, so that the accuracy of the table-building statement in the correction process can be improved.
Fig. 1 schematically illustrates an application scenario diagram of a method and an apparatus for correcting a database build statement according to an embodiment of the present disclosure.
As shown in fig. 1, an application scenario 100 according to this embodiment may include a first terminal device 101, a second terminal device 102, and a third terminal device 103. The network 104 is a medium used to provide a communication link between the first terminal device 101, the second terminal device 102, the third terminal device 103, and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
The user may interact with the server 105 through the network 104 using at least one of the first terminal device 101, the second terminal device 102, the third terminal device 103, to receive or send messages, etc. Various communication client applications, such as a shopping class application, a web browser application, a search class application, an instant messaging tool, a mailbox client, social platform software, etc. (by way of example only) may be installed on the first terminal device 101, the second terminal device 102, and the third terminal device 103.
The first terminal device 101, the second terminal device 102, the third terminal device 103 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablets, laptop and desktop computers, and the like.
The server 105 may be a server providing various services, such as a background management server (by way of example only) providing support for websites browsed by the user using the first terminal device 101, the second terminal device 102, and the third terminal device 103. The background management server may analyze and process the received data such as the user request, and feed back the processing result (e.g., the web page, information, or data obtained or generated according to the user request) to the terminal device.
It should be noted that, the method for correcting the database table-building statement provided in the embodiment of the disclosure may be generally executed by the server 105. Accordingly, the correction device for database table creation statement provided in the embodiment of the present disclosure may be generally disposed in the server 105. The correction method of the database tabulation statement provided by the embodiments of the present disclosure may also be performed by a server or a server cluster which is different from the server 105 and is capable of communicating with the first terminal device 101, the second terminal device 102, the third terminal device 103 and/or the server 105. Accordingly, the correction device of the database tabulation statement provided in the embodiment of the present disclosure may also be provided in a server or a server cluster which is different from the server 105 and is capable of communicating with the first terminal device 101, the second terminal device 102, the third terminal device 103 and/or the server 105.
It should be understood that the number of terminal devices, networks and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
The method of correcting the database build statement according to the disclosed embodiment will be described in detail below with reference to fig. 2 to 5 based on the scenario described in fig. 1.
Fig. 2 schematically illustrates a flowchart of a method of correction of a database build statement according to an embodiment of the disclosure.
As shown in fig. 2, the correction method of the database construction statement of this embodiment includes operations S210 to S240.
In operation S210, table building sentences of the source database and the target database are respectively parsed to generate a first structure and a second structure, wherein the first structure includes a table name and a first field definition corresponding to the table name, and the second structure includes a table name and a second field definition corresponding to the table name.
The table name is a name for uniquely identifying one table, and is specified when creating a table in the database for uniquely identifying one table in the database.
A field definition is a complete description of a field, including a field name and a field type, which combine to define a field in a table. The field definition may also include other attributes such as field length, default values, field constraints, and the like.
In this embodiment, for example, SQL (structured query language) statements of the source database and the target database may be parsed respectively, table names and field definitions may be extracted, and a first structure and a second structure which are orderly and convenient to retrieve may be generated according to the table names and the field definitions, respectively, where the first structure includes the table names and the first field definitions corresponding to the table names, and the second structure includes the table names and the second field definitions corresponding to the table names.
In operation S220, the first field definition and the second field definition corresponding to the same table name are compared, respectively.
In this embodiment, a first structure of the source database is traversed, for example, there are 100 tables in the source database, the table name of each table and the first field definition corresponding to each table name are obtained respectively, then the second field definition corresponding to the table name is queried in the target database according to each table name, and whether the first field definition and the second field definition are different is compared.
In operation S230, in response to the first field definition and the second field definition corresponding to the table name not being identical, the second field definition is revised using a field definition conversion rule between the source database and the target database.
In this embodiment, if there is a difference between the first field definition corresponding to each table in the source database and the second field definition corresponding to each table in the target database, a field definition conversion rule, such as float, between the source database and the target database is read: binary_float, double: binary_double, longtext: clob, … …; and correcting the second field definition according to the field definition conversion rule.
In operation S240, the table-building statement of the target database is revised according to the revised second field definition.
In this embodiment, the table-building statement of the target database is modified according to the second field definition modified by the field definition conversion rule, and each element attribute in the source database is correctly mapped to the corresponding attribute in the target database, so as to maintain the accuracy and consistency of the data.
Fig. 3 schematically illustrates a flowchart of the generation of the first structure and the second structure in the correction method of the database build statement according to the embodiment of the present disclosure.
As shown in fig. 3, the correction method of the database construction statement of this embodiment includes operations S310 to S340.
In operation S310, a table-building statement of the source database is parsed, and a table name, a first field name corresponding to the table name, and a first field type are extracted.
In operation S320, the table-building statement of the target database is parsed, and the table name, the second field name corresponding to the table name, and the second field type are extracted.
In this embodiment, the SQL statement of the source database is parsed first, and the table name, the first field name corresponding to the table name, and the first field type are extracted. And analyzing the SQL sentence of the target database, and extracting the table name, the second field name corresponding to the table name and the second field type.
In operation S330, a first LinkedHashMap structure is generated from the table name, the first field name, and the first field type, wherein the first field name and the first field type constitute a first field definition.
In operation S340, a second LinkedHashMap structure is generated according to the table name, the second field name, and the second field type, wherein the second field name and the second field type constitute a second field definition.
In this embodiment, a first LinkedHashMap structure body that is orderly and convenient for retrieval is generated according to the table name, the first field name and the first field type. And generating a second LinkedHashMap structure body which is orderly convenient to search according to the table name, the second field name and the second field type.
For example, the following formats are possible:
{ 'Table name 1': { 'field name 11': 'type definition 11', 'field name 12': 'type definition 12', … …, 'field name 1N': 'type definition 1N', 'table name 2': { 'field name 21': 'type definition 21', 'field name 22': 'type definition 22', … …, 'field name 2N': 'type definition 2N' }, … …, 'table name N': { 'field name N1': 'type definition N1', 'field name N2': 'type definition N2', … …, 'field name NN': the 'type defines NN' }.
The LinkedHashMap structure has outstanding advantages in terms of insertion sequence or access sequence, and is very suitable for scenes needing to keep element sequence, so that table names, field names and field types in table-building sentences are extracted to generate the LinkedHashMap structure, and the accuracy in the retrieval process can be improved.
Fig. 4 schematically illustrates a flowchart of correcting a second field definition using a field definition conversion rule in a correction method of a database build statement according to an embodiment of the present disclosure.
As shown in fig. 4, the correction method of the database construction statement of this embodiment includes operations S410 to S430.
In operation S410, the first field name is compared with the second field name, and the first field type is compared with the second field type.
The field name is a name for uniquely identifying a field, which is specified when a field is defined in a table, for uniquely identifying a field in the table.
The field type refers to a data type to which a field belongs, and defines the type and format of data that the field can store, and different field types support different data types, such as integer types, character types, date types, and the like.
In this embodiment, the field names and field types corresponding to each table in the source database and the target database are compared respectively.
In operation S420, in case the first field name and the second field name are not identical, and/or in case the first field type and the second field type are not identical, a field definition conversion rule from the source database to the target database is read.
In the present embodiment, in the case where there is a difference in either of the field name and the field type, the field definition conversion rule from the source database to the target database is read.
In operation S430, the second field name and/or the second field type are modified according to the field definition conversion rule.
In this embodiment, by comparing the field names with the field types, the tables having differences in the source database and the target database can be retrieved more accurately, and further, the field names and the field types having differences can be corrected more accurately according to the field definition conversion rule.
According to an embodiment of the present disclosure, the first LinkedHashMap structure and the second LinkedHashMap structure are in the form of nested key-value pairs, wherein keys of an outer layer of the key-value pairs represent table names, corresponding values are key-value pairs of an inner layer, keys of the inner layer represent first field names or second field names, and corresponding values are first field types or second field types.
For example, for table a in the source database, containing fields name and age, the corresponding type definitions are varchar and int, respectively. The resulting structure can be expressed as:
{ "Table A": { "name": "varchar", "age": "int" }.
The structure body is generated in a nested key value pair mode, the corresponding field type can be conveniently searched according to the table name and the field name, and the processing efficiency and accuracy are improved.
According to an embodiment of the present disclosure, comparing the first field definition and the second field definition corresponding to the same table name, respectively, includes: and respectively comparing the first field definition and the second field definition corresponding to the same table name by taking the table name as a key.
In this embodiment, since the table name, the field name and the field type are generated in advance in the form of nested key value pairs, the table name can be directly used as a key in the comparison process, and the field definitions corresponding to the table names in the target database and the source database can be compared with each other efficiently and quickly.
According to an embodiment of the present disclosure, before comparing the first field definition and the second field definition corresponding to the same table name, respectively, the method further includes: generating a table establishing statement corresponding to the table name according to the second field definition corresponding to the table name in response to the table name in the source database not existing in the target database; and creating a table corresponding to the table name in the target database according to the table creating statement corresponding to the table name.
In this embodiment, when traversing the table-building statement of the source database, for each table, checking whether a corresponding table exists in the target database according to the table name, if no corresponding table exists, indicating that the table needs to be created in the target database, generating a corresponding table-building statement to build the table, for example, 100 tables exist in the source database, 99 tables exist in the target database, indicating that one table is missing in the target database, generating a table-building statement according to the field definition corresponding to the 100 th table, and creating the table in the target database according to the generated table-building statement. If a corresponding table exists, indicating that the table already exists in the target database, then a further field comparison may be performed.
According to an embodiment of the present disclosure, the correction method of the database table-building statement further includes: storing the corrected list-building sentence as comma separated value file format; and applying the list-establishing sentence in comma separated value file format to the target database, and executing the list-establishing sentence to update the target database.
In this embodiment, the modified list-building sentence is saved as a CSV (comma separated value file format) and then applied to the target database, and the CSV file is read to generate a LinkedHashMap structure body which is orderly and convenient to search. For example, it may be: { 'Table name 1': { 'field name 11': 'type definition 11', 'field name 12': 'type definition 12', … …, 'field name 1N': 'type definition 1N', 'table name 2': { 'field name 21': 'type definition 21', 'field name 22': 'type definition 22', … …, 'field name 2N': 'type definition 2N' }, … …, 'table name N': { 'field name N1': 'type definition N1', 'field name N2': 'type definition N2', … …, 'field name NN': the 'type defines NN' }. Reading the original building table text file to generate a structural body { 'table name 1': the { 'column defines start position': startIndex1, 'column defines end position': endIndex1, 'table name 2': the { 'column defines start position': startIndex2, 'column defines end position': endIndex2, ' … …, ' table name N ': the { 'column defines start position': startIndexN, 'column defines end position': endidexn }. Traversing the LinkedHashMap structure body, and replacing the definition in the file to update the target database.
Since CSV stores table data (numbers and text) in plain text, meaning that the file is a sequence of characters, without data that must be interpreted as binary digits, updating the table structure in the target database according to the table-building statement in CSV format can increase the compatibility of the target database during the updating process.
According to an embodiment of the present disclosure, in response to the first field definition and the second field definition corresponding to the table name not being identical, correcting the second field definition using a field definition conversion rule between the source database and the target database, further comprising: comparing the field length, the default value and the field constraint in the first field definition and the second field definition respectively; reading a field definition conversion rule from the source database to the target database in response to the fact that the field lengths, the default values and the field constraints in the first field definition and the second field definition are inconsistent; and correcting the field length, the default value and the field constraint in the second field definition according to the field definition conversion rule.
In this embodiment, in addition to the important elements such as the field name and the field type, other differences may exist in the comparison of the table-building statement, such as the field length, the default value, the field constraint, and the like, and correcting the differences of these attributes can ensure that the table structure in the target database is kept consistent with the source database in all directions.
Fig. 5 schematically illustrates a schematic diagram of a method of correcting a database build statement according to an embodiment of the disclosure.
As shown in fig. 5, the correction method of the database table-building statement in this embodiment is as follows: and (3) acquiring the list-building sentence texts of the source database and the target database, respectively analyzing the list-building sentence texts of the source database and the target database to generate a structure, wherein the list-building sentence texts of the source database and the target database have no consistent sequence, so that the list-building sentence is analyzed into a structure which is orderly and convenient to search, and comparison is convenient. Traversing the structure body of the source database, searching field definitions corresponding to the surface in the target database according to the table names, correcting the inconsistent field definitions by utilizing a field definition conversion rule from the source database to the target database under the condition that the field definitions are inconsistent, correcting table-building sentences, storing the corrected table-building sentences into CSV format files, and applying the CSV format files to the target database to update the table structure of the target database.
Based on the correction method of the database table-building statement, the invention also provides a correction device of the database table-building statement. The device will be described in detail below in connection with fig. 6.
Fig. 6 schematically shows a block diagram of a correction apparatus of a database tabulation statement according to an embodiment of the present disclosure.
As shown in fig. 6, the correction device 600 of the database tabulation statement of this embodiment includes: a generation module 610, a comparison module 620, a first correction module 630, and a second correction module 640.
The generating module 610 is configured to parse the table-building statements of the source database and the target database, respectively, to generate a first structure and a second structure, where the first structure includes a table name and a first field definition corresponding to the table name, and the second structure includes a table name and a second field definition corresponding to the table name. In an embodiment, the generating module 610 may be configured to perform the operation S210 described above, which is not described herein.
The comparison module 620 is configured to compare the first field definition and the second field definition corresponding to the same table name respectively. In an embodiment, the comparison module 620 may be configured to perform the operation S220 described above, which is not described herein.
The first correction module 630 is configured to correct the second field definition by using a field definition conversion rule between the source database and the target database in response to the first field definition corresponding to the table name and the second field definition not being identical. In an embodiment, the first correction module 630 may be used to perform the operation S230 described above, which is not described herein.
The second correction module 640 is configured to correct the table-building statement of the target database according to the corrected second field definition. In an embodiment, the second correction module 640 may be used to perform the operation S240 described above, which is not described herein.
According to the embodiment of the disclosure, the correction device 600 for database table construction sentence of the embodiment can organize disordered data information into an ordered data structure by analyzing the table construction sentence generation structure, is convenient for comparing the data of the source database and the target database, and corrects the field definition with difference by using the field definition conversion rule, thereby ensuring that each element attribute in the source database can be correctly mapped to the corresponding attribute in the target database in the data conversion process, and improving the accuracy of the table construction sentence in the correction process due to maintaining the accuracy and consistency of the data.
Any of the generation module 610, the comparison module 620, the first modification module 630, and the second modification module 640 may be combined in one module to be implemented, or any of the modules may be split into a plurality of modules, according to embodiments of the present disclosure. Alternatively, at least some of the functionality of one or more of the modules may be combined with at least some of the functionality of other modules and implemented in one module. According to embodiments of the present disclosure, at least one of the generation module 610, the comparison module 620, the first correction module 630, and the second correction module 640 may be implemented at least in part as hardware circuitry, such as a Field Programmable Gate Array (FPGA), a Programmable Logic Array (PLA), a system on a chip, a system on a substrate, a system on a package, an Application Specific Integrated Circuit (ASIC), or may be implemented in hardware or firmware in any other reasonable manner of integrating or packaging the circuitry, or in any one of or a suitable combination of three of software, hardware, and firmware. Alternatively, at least one of the generation module 610, the comparison module 620, the first modification module 630, and the second modification module 640 may be at least partially implemented as computer program modules that, when executed, perform the corresponding functions.
Fig. 7 schematically illustrates a block diagram of an electronic device adapted to implement a method of correction of a database build statement, according to an embodiment of the disclosure.
As shown in fig. 7, an electronic device 700 according to an embodiment of the present disclosure includes a processor 701 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 702 or a program loaded from a storage section 708 into a Random Access Memory (RAM) 703. The processor 701 may include, for example, a general purpose microprocessor (e.g., a CPU), an instruction set processor and/or an associated chipset and/or a special purpose microprocessor (e.g., an Application Specific Integrated Circuit (ASIC)), or the like. The processor 701 may also include on-board memory for caching purposes. The processor 701 may comprise a single processing unit or a plurality of processing units for performing different actions of the method flows according to embodiments of the disclosure.
In the RAM 703, various programs and data necessary for the operation of the electronic apparatus 700 are stored. The processor 701, the ROM 702, and the RAM 703 are connected to each other through a bus 704. The processor 701 performs various operations of the method flow according to the embodiments of the present disclosure by executing programs in the ROM 702 and/or the RAM 703. Note that the program may be stored in one or more memories other than the ROM 702 and the RAM 703. The processor 701 may also perform various operations of the method flow according to embodiments of the present disclosure by executing programs stored in the one or more memories.
According to an embodiment of the present disclosure, the electronic device 700 may further include an input/output (I/O) interface 705, the input/output (I/O) interface 705 also being connected to the bus 704. The electronic device 700 may also include one or more of the following components connected to the I/O interface 705: an input section 706 including a keyboard, a mouse, and the like; an output portion 707 including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, a speaker, and the like; a storage section 708 including a hard disk or the like; and a communication section 709 including a network interface card such as a LAN card, a modem, or the like. The communication section 709 performs communication processing via a network such as the internet. The drive 710 is also connected to the I/O interface 705 as needed. A removable medium 711 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 710 as necessary, so that a computer program read therefrom is mounted into the storage section 708 as necessary.
The present disclosure also provides a computer-readable storage medium that may be embodied in the apparatus/device/system described in the above embodiments; or may exist alone without being assembled into the apparatus/device/system. The computer-readable storage medium carries one or more programs which, when executed, implement methods in accordance with embodiments of the present disclosure.
According to embodiments of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium, which may include, for example, but is not limited to: a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this disclosure, a computer-readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. For example, according to embodiments of the present disclosure, the computer-readable storage medium may include ROM 702 and/or RAM 703 and/or one or more memories other than ROM 702 and RAM 703 described above.
Embodiments of the present disclosure also include a computer program product comprising a computer program containing program code for performing the methods shown in the flowcharts. The program code, when executed in a computer system, causes the computer system to perform the methods provided by embodiments of the present disclosure.
The above-described functions defined in the system/apparatus of the embodiments of the present disclosure are performed when the computer program is executed by the processor 701. The systems, apparatus, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the disclosure.
In one embodiment, the computer program may be based on a tangible storage medium such as an optical storage device, a magnetic storage device, or the like. In another embodiment, the computer program may also be transmitted, distributed over a network medium in the form of signals, downloaded and installed via the communication section 709, and/or installed from the removable medium 711. The computer program may include program code that may be transmitted using any appropriate network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the foregoing.
In such an embodiment, the computer program may be downloaded and installed from a network via the communication portion 709, and/or installed from the removable medium 711. The above-described functions defined in the system of the embodiments of the present disclosure are performed when the computer program is executed by the processor 701. The systems, devices, apparatus, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the disclosure.
According to embodiments of the present disclosure, program code for performing computer programs provided by embodiments of the present disclosure may be written in any combination of one or more programming languages, and in particular, such computer programs may be implemented in high-level procedural and/or object-oriented programming languages, and/or assembly/machine languages. Programming languages include, but are not limited to, such as Java, c++, python, "C" or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, partly on a remote computing device, or entirely on the remote computing device or server. In the case of remote computing devices, the remote computing device may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., connected via the Internet using an Internet service provider).
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
Those skilled in the art will appreciate that the features recited in the various embodiments of the disclosure and/or in the claims may be provided in a variety of combinations and/or combinations, even if such combinations or combinations are not explicitly recited in the disclosure. In particular, the features recited in the various embodiments of the present disclosure and/or the claims may be variously combined and/or combined without departing from the spirit and teachings of the present disclosure. All such combinations and/or combinations fall within the scope of the present disclosure.
The embodiments of the present disclosure are described above. However, these examples are for illustrative purposes only and are not intended to limit the scope of the present disclosure. Although the embodiments are described above separately, this does not mean that the measures in the embodiments cannot be used advantageously in combination. The scope of the disclosure is defined by the appended claims and equivalents thereof. Various alternatives and modifications can be made by those skilled in the art without departing from the scope of the disclosure, and such alternatives and modifications are intended to fall within the scope of the disclosure.

Claims (12)

1. A correction method of database table-building sentences comprises the following steps:
respectively analyzing table construction sentences of a source database and a target database to generate a first structure body and a second structure body, wherein the first structure body comprises a table name and a first field definition corresponding to the table name, and the second structure body comprises the table name and a second field definition corresponding to the table name;
Respectively comparing the first field definition and the second field definition corresponding to the same table name;
in response to the first field definition and the second field definition corresponding to the table name not being consistent, correcting the second field definition using a field definition conversion rule between the source database and the target database; and
and correcting the table-building statement of the target database according to the corrected second field definition.
2. The method for correcting a database table-building statement according to claim 1, wherein the parsing the table-building statement of the source database and the target database to generate a first structure and a second structure comprises:
analyzing a table establishing statement of a source database, and extracting a table name, a first field name corresponding to the table name and a first field type;
analyzing a table establishing statement of a target database, and extracting a table name, a second field name corresponding to the table name and a second field type;
generating a first LinkedHashMap structure body according to the table name, the first field name and the first field type, wherein the first field name and the first field type form the first field definition; and
And generating a second LinkedHashMap structure body according to the table name, the second field name and the second field type, wherein the second field name and the second field type form the second field definition.
3. The method for correcting a database build statement according to claim 2, wherein said correcting the second field definition using a field definition conversion rule between the source database and the target database in response to the first field definition and the second field definition corresponding to the table name not being identical, comprises:
comparing the first field name with the second field name, and comparing the first field type with the second field type;
reading a field definition conversion rule from the source database to the target database in the case that the first field name and the second field name are not identical and/or in the case that the first field type and the second field type are not identical; and
and correcting the second field name and/or the second field type according to the field definition conversion rule.
4. The method for correcting a database construction statement according to claim 2, wherein the first LinkedHashMap structure and the second LinkedHashMap structure are in the form of nested key-value pairs, wherein an outer key of the key-value pairs represents the table name, a corresponding value is an inner key-value pair, an inner key represents the first field name or the second field name, and a corresponding value is the first field type or the second field type.
5. The method for correcting a database construction statement according to claim 4, wherein the comparing the first field definition and the second field definition corresponding to the same table name respectively includes:
and respectively comparing the first field definition and the second field definition corresponding to the same table name by taking the table name as a key.
6. The method for correcting a database build statement according to claim 5, wherein before comparing the first field definition and the second field definition corresponding to the same table name, respectively, the method further comprises:
generating a table building statement corresponding to the table name according to the second field definition corresponding to the table name in response to the table name in the source database not existing in the target database; and
and creating a table corresponding to the table name in the target database according to the table creating sentence corresponding to the table name.
7. The correction method of a database construction statement according to claim 1, further comprising:
storing the corrected list-building sentence as comma separated value file format; and
and applying the list-establishing sentence in the comma separated value file format to the target database, and executing the list-establishing sentence to update the target database.
8. The method for correcting a database build statement according to claim 1, wherein in response to the first field definition and the second field definition corresponding to the table name not being identical, correcting the second field definition using a field definition conversion rule between the source database and the target database, further comprising:
comparing the field length, the default value and the field constraint in the first field definition and the second field definition respectively;
reading a field definition conversion rule from the source database to the target database in response to the field length, the default value, and the field constraint in the first field definition and the second field definition being inconsistent; and
and correcting the field length, the default value and the field constraint in the second field definition according to the field definition conversion rule.
9. A database table-building statement correction device, comprising:
the generation module is used for respectively analyzing the table establishing sentences of the source database and the target database to generate a first structure body and a second structure body, wherein the first structure body comprises a table name and a first field definition corresponding to the table name, and the second structure body comprises the table name and a second field definition corresponding to the table name;
The comparison module is used for respectively comparing the first field definition and the second field definition corresponding to the same table name;
a first correction module, configured to correct, in response to the first field definition and the second field definition corresponding to the table name being inconsistent, the second field definition by using a field definition conversion rule between the source database and the target database; and
and the second correction module is used for correcting the table-building statement of the target database according to the corrected second field definition.
10. An electronic device, comprising:
one or more processors;
storage means for storing one or more programs,
wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to perform the method of any of claims 1-8.
11. A computer readable storage medium having stored thereon executable instructions which, when executed by a processor, cause the processor to perform the method according to any of claims 1-8.
12. A computer program product comprising a computer program which, when executed by a processor, implements the method according to any one of claims 1 to 8.
CN202311600880.1A 2023-11-28 2023-11-28 Correction method and device for database table establishment statement, electronic equipment and medium Pending CN117667926A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311600880.1A CN117667926A (en) 2023-11-28 2023-11-28 Correction method and device for database table establishment statement, electronic equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311600880.1A CN117667926A (en) 2023-11-28 2023-11-28 Correction method and device for database table establishment statement, electronic equipment and medium

Publications (1)

Publication Number Publication Date
CN117667926A true CN117667926A (en) 2024-03-08

Family

ID=90078248

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311600880.1A Pending CN117667926A (en) 2023-11-28 2023-11-28 Correction method and device for database table establishment statement, electronic equipment and medium

Country Status (1)

Country Link
CN (1) CN117667926A (en)

Similar Documents

Publication Publication Date Title
US20230259502A1 (en) Query Processor
US11366856B2 (en) System and method for updating target schema of graph model
US9740698B2 (en) Document merge based on knowledge of document schema
CN112506946A (en) Service data query method, device, equipment and storage medium
US8032544B2 (en) Methods and apparatus for generating dynamic program files based on input queries that facilitate use of persistent query services
US8103705B2 (en) System and method for storing text annotations with associated type information in a structured data store
AU2012271085B2 (en) Recommending data enrichments
US7725466B2 (en) High accuracy document information-element vector encoding server
US11030242B1 (en) Indexing and querying semi-structured documents using a key-value store
CN109710220B (en) Relational database query method, relational database query device, relational database query equipment and storage medium
US6985910B2 (en) Tilting tree spinning cones method and system for mapping XML to n-dimensional data structure using a single dimensional mapping array
US11514697B2 (en) Probabilistic text index for semi-structured data in columnar analytics storage formats
US20170262498A1 (en) Source independent query language
CN115599386A (en) Code generation method, device, equipment and storage medium
CN108694172B (en) Information output method and device
US11868362B1 (en) Metadata extraction from big data sources
CN116414855A (en) Information processing method and device, electronic equipment and computer readable storage medium
CN117667926A (en) Correction method and device for database table establishment statement, electronic equipment and medium
US11550777B2 (en) Determining metadata of a dataset
US11467752B2 (en) Data migration system and data migration method
CN114089976B (en) Method, apparatus, and medium for generating database operation statements
US20240046214A1 (en) Systems and methods for facilitating modifications and updates to shared content
US20230342558A1 (en) Systems and methods for generalized entity matching
CN116483954A (en) Data processing method, device, equipment and storage medium
CN117407002A (en) Transcoding method, transcoding device, computer equipment and storage medium

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