A method, apparatus, electronic device, and medium for data synchronization between databases.

By acquiring the metadata information and JDBC encoding of database fields, the system automatically verifies the field compatibility between heterogeneous databases, solving the problem of low efficiency in manual verification in existing technologies and achieving efficient and accurate data synchronization.

CN120492545BActive Publication Date: 2025-11-14CSC FINANCIAL CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510932953.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-07-08
Publication Date
2025-11-14
Estimated Expiration
2045-07-08

AI Technical Summary

Technical Problem

Existing technologies rely on manual verification during data synchronization between heterogeneous databases, resulting in a huge workload, low efficiency, and a high risk of errors, especially when there are many fields, leading to high labor costs.

Method used

By acquiring field metadata information from the source and target databases and utilizing the preset correspondence between JDBC encoding and type types, the system automatically verifies whether the source and target fields are compatible and performs data synchronization when they are compatible, reducing manual operations.

Benefits of technology

It achieves automated compatibility verification, reduces labor costs, improves the efficiency and accuracy of data synchronization, and reduces omissions and errors in manual verification.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120492545B_ABST
    Figure CN120492545B_ABST
Patent Text Reader

Abstract

This application provides a method, apparatus, electronic device, and medium for data synchronization between databases, relating to the field of data storage technology. The technical solution includes: acquiring metadata information of source fields from a source data table in a source database, and metadata information of target fields from a target data table in a target database. Then, based on a preset correspondence between type codes and type categories, determining a first type category corresponding to the type code of the source field and a second type category corresponding to the type code of the target field. When the first type category and the second type category are the same, verifying compatibility between the source field and the target field based on their metadata information. If the verification result indicates compatibility, synchronizing the source field and the target field. This reduces the manual operations required for data synchronization between databases.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data storage technology, and in particular to a method, apparatus, electronic device, and medium for data synchronization between databases. Background Technology

[0002] In today's rapidly developing environment of big data and information technology, enterprises and organizations commonly use multiple databases to store and manage business data generated from their operations. The types of databases used by enterprises or organizations at different historical stages, or within their business departments, are often heterogeneous; that is, different databases generally differ in data types, length units, encoding methods, and storage structures. With the increasing demands for data analysis and cross-system collaboration, achieving stable, efficient, and accurate data synchronization between these heterogeneous databases has become a highly challenging issue.

[0003] Currently, the common practice for data synchronization between heterogeneous databases is to manually map fields between them. This means that implementers need a deep understanding of the field types in both the source and target databases to determine whether data in a specific field of the source database can be synchronized to a specific field of the target database. In other words, they manually verify the compatibility between these two fields; if compatible, data synchronization proceeds. However, this method relies heavily on manual labor. If the data synchronization process involves many fields, such as hundreds, the workload is enormous, resulting in high labor costs, low efficiency, and, due to limited human experience and energy, potential for omissions or errors in verification. Summary of the Invention

[0004] The purpose of this application is to provide a data synchronization method, apparatus, electronic device, and medium between databases, so as to reduce the manual operations required for data synchronization between databases. The specific technical solution is as follows:

[0005] In a first aspect, embodiments of this application provide a data synchronization method between databases, including:

[0006] Obtain metadata information of source fields from source tables in source database and metadata information of target fields from target tables in target database. The metadata information includes: field type and type encoding, wherein the type encoding is: the Java database connection JDBC encoding corresponding to the field type determined according to the database type.

[0007] Based on the preset correspondence between each type code and type category, determine the first type category corresponding to the type code of the source field and the second type category corresponding to the type code of the target field;

[0008] When the first type and the second type are the same, the compatibility between the source field and the target field is verified based on the metadata information of the source field and the metadata information of the target field.

[0009] If the verification result is compatible, the source field and the target field are synchronized.

[0010] Optionally, both the first type and the second type represent string types, and the metadata information further includes: column size, string length unit, and encoding method; the step of verifying whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field includes:

[0011] If the column size of the source field is not a preset value, the column size of the source field is converted to the target column size based on the string length unit and encoding method of the source field and the string length unit and encoding method of the target field. It is then determined whether the target column size is less than or equal to the column size of the target field, where the target column size represents the column size required to store the data in the source field into the target field. If yes, the verification result is determined to be compatible; otherwise, the verification result is determined to be incompatible.

[0012] If the column size of the source field is a preset value, determine whether the column size of the target field is greater than or equal to the preset value; if so, determine that the verification result is compatible; otherwise, determine that the verification result is incompatible.

[0013] Optionally, both the first type and the second type represent integer types; the step of verifying the compatibility between the source field and the target field based on the metadata information of the source field and the metadata information of the target field includes:

[0014] Based on the preset correspondence between the type codes and range codes of integer types, the first range code corresponding to the type code of the source field and the second range code corresponding to the type code of the target field are determined; wherein, the range of values ​​that the field type corresponding to the type code can support storing is positively correlated with the size of the range code corresponding to the type code;

[0015] Determine whether the first range code is less than or equal to the second range code;

[0016] If so, then the verification result is confirmed as compatible;

[0017] Otherwise, the verification result is determined to be incompatible.

[0018] Optionally, both the first type and the second type represent non-integer types, including floating-point and fixed-point types. The metadata information further includes column size and decimal places. Verifying the compatibility between the source field and the target field based on the metadata information of the source field and the target field includes:

[0019] If both the source field and the target field are of fixed-point type, then determine whether the column size of the source field is less than or equal to the column size of the target field, and whether the number of decimal places in the source field is less than or equal to the number of decimal places in the target field; if both are true, then the verification result is determined to be compatible; otherwise, the verification result is determined to be incompatible.

[0020] If both the source field and the target field are of floating-point type, then the verification result is determined to be compatible.

[0021] If the source field is of type fixed-point and the target field is of type floating-point, then the verification result is determined to be incompatible.

[0022] If the source field is of floating-point type and the target field is of fixed-point type, then determine whether the range of values ​​that the source field type supports storing is less than or equal to the range of values ​​that the target field type supports storing; if so, the verification result is determined to be compatible; otherwise, the verification result is determined to be incompatible.

[0023] Optionally, both the first type and the second type are other types, including: date type, binary type, and boolean type; the step of verifying the compatibility between the source field and the target field based on the metadata information of the source field and the metadata information of the target field includes:

[0024] Determine whether the type code of the source field is the same as the type code of the target field, or whether there is an equivalent mapping relationship between the type code of the source field and the type code of the target field in the preset equivalence mapping table;

[0025] If any judgment result is yes, then the verification result is determined to be compatible;

[0026] Otherwise, the verification result is determined to be incompatible.

[0027] Optionally, after verifying the compatibility between the source field and the target field based on the metadata information of the source field and the metadata information of the target field, if the verification result is incompatibility, the method further includes:

[0028] If the column size of the source field is a preset value, then a field type with a column size greater than or equal to the preset value is selected as the suggested field type for the target field.

[0029] If the column size of the source field is not a preset value, then determine whether the target column size of the source field is greater than the upper limit of the column size of the target field's field type; if yes, then select the parent field type of the target field's field type as the suggested field type; if no, then select the target field's field type as the suggested field type, and determine the target column size as the suggested column size.

[0030] Optionally, after verifying the compatibility between the source field and the target field based on the metadata information of the source field and the metadata information of the target field, the method further includes:

[0031] If the verification result is incompatible, candidate field types whose supported storage value range is greater than or equal to the supported storage value range of the source field are determined from the field types corresponding to the first type category.

[0032] Select a candidate field type as the suggested field type.

[0033] Secondly, embodiments of this application provide a data synchronization device between databases, comprising:

[0034] The acquisition module is used to acquire metadata information of source fields of source data tables in source database and metadata information of target fields of target data tables in target database. The metadata information includes: field type and type encoding, wherein the type encoding is: the Java database connection JDBC encoding corresponding to the field type determined according to the database type.

[0035] The determination module is used to determine the first type corresponding to the type code of the source field and the second type corresponding to the type code of the target field based on the preset correspondence between each type code and type category;

[0036] The verification module is used to verify whether the source field and the target field are compatible, based on the metadata information of the source field and the metadata information of the target field, when the first type and the second type are the same.

[0037] The synchronization module is used to synchronize the source field and the target field when the verification result of the verification module is compatible.

[0038] Optionally, both the first type and the second type represent string types, and the metadata information further includes: column size, string length unit, and encoding method; the verification module is specifically used for:

[0039] If the column size of the source field is not a preset value, the column size of the source field is converted to the target column size based on the string length unit and encoding method of the source field and the string length unit and encoding method of the target field. It is then determined whether the target column size is less than or equal to the column size of the target field, where the target column size represents the column size required to store the data in the source field into the target field. If yes, the verification result is determined to be compatible; otherwise, the verification result is determined to be incompatible.

[0040] If the column size of the source field is a preset value, determine whether the column size of the target field is greater than or equal to the preset value; if so, determine that the verification result is compatible; otherwise, determine that the verification result is incompatible.

[0041] Optionally, both the first type and the second type represent integer types; the verification module is specifically used for:

[0042] Based on the preset correspondence between the type codes and range codes of integer types, the first range code corresponding to the type code of the source field and the second range code corresponding to the type code of the target field are determined; wherein, the range of values ​​that the field type corresponding to the type code can support storing is positively correlated with the size of the range code corresponding to the type code;

[0043] Determine whether the first range code is less than or equal to the second range code;

[0044] If so, then the verification result is confirmed as compatible;

[0045] Otherwise, the verification result is determined to be incompatible.

[0046] Optionally, both the first type and the second type represent non-integer types, including floating-point and fixed-point types. The metadata information further includes column size and decimal places. The verification module is specifically used for:

[0047] If both the source field and the target field are of fixed-point type, then determine whether the column size of the source field is less than or equal to the column size of the target field, and whether the number of decimal places in the source field is less than or equal to the number of decimal places in the target field; if both are true, then the verification result is determined to be compatible; otherwise, the verification result is determined to be incompatible.

[0048] If both the source field and the target field are of floating-point type, then the verification result is determined to be compatible.

[0049] If the source field is of type fixed-point and the target field is of type floating-point, then the verification result is determined to be incompatible.

[0050] If the source field is of floating-point type and the target field is of fixed-point type, then determine whether the range of values ​​that the source field type supports storing is less than or equal to the range of values ​​that the target field type supports storing; if so, the verification result is determined to be compatible; otherwise, the verification result is determined to be incompatible.

[0051] Optionally, both the first type and the second type are other types, including: date type, binary type, and boolean type; the verification module is specifically used for:

[0052] Determine whether the type code of the source field is the same as the type code of the target field, or whether there is an equivalent mapping relationship between the type code of the source field and the type code of the target field in the preset equivalence mapping table;

[0053] If any judgment result is yes, then the verification result is determined to be compatible;

[0054] Otherwise, the verification result is determined to be incompatible.

[0055] Optionally, the device may also include:

[0056] The selection module is used to, after verifying whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field, if the verification result is incompatible, select a field type with a column size greater than or equal to the preset value as the suggested field type for the target field if the column size of the source field is a preset value.

[0057] The generation module is used to, after verifying the compatibility between the source field and the target field based on the metadata information of the source field and the metadata information of the target field, if the verification result is incompatible, determine whether the target column size of the source field is greater than the upper limit of the column size of the target field's field type if the column size of the source field is not a preset value; if yes, select the parent field type of the target field's field type as the suggested field type; if no, select the target field's field type as the suggested field type and determine the target column size as the suggested column size.

[0058] Optionally, the determining module is further configured to:

[0059] After verifying whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field, if the verification result is incompatible, candidate field types whose supported storage value range is greater than or equal to the supported storage value range of the source field are determined from the field types corresponding to the first type category.

[0060] Select a candidate field type as the suggested field type.

[0061] Thirdly, embodiments of this application provide an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;

[0062] Memory, used to store computer programs;

[0063] A processor, when executing a program stored in memory, implements the method described in any of the first aspects.

[0064] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the method described in any of the first aspects.

[0065] Fifthly, embodiments of this application also provide a computer program product containing instructions that, when run on a computer, cause the computer to execute the data synchronization method between databases described in any of the first aspects above.

[0066] Beneficial effects of the embodiments in this application:

[0067] The data synchronization method, apparatus, electronic device, and medium between databases provided in this application can obtain the JDBC codes corresponding to the field types of the source and target fields, and further determine the type category to which the JDBC codes belong. This application uniformly maps field types to JDBC codes, eliminating the impact on compatibility judgment caused by different field type names for the same field type in different databases. Furthermore, this application divides each field type into multiple categories. Thus, when the first and second categories are the same, it automatically verifies whether the source and target fields are compatible based on the metadata information of the source and target fields. If the verification result is compatible, it performs data synchronization between the source and target fields, achieving automatic compatibility verification without manual verification. Therefore, it reduces the manual operations required for data synchronization between databases, not only reducing labor costs but also improving verification efficiency and accuracy.

[0068] Of course, implementing any product or method of this application does not necessarily require achieving all of the advantages described above at the same time. Attached Figure Description

[0069] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other embodiments can be obtained based on these drawings.

[0070] Figure 1 A flowchart illustrating a data synchronization method between databases provided in this application embodiment;

[0071] Figure 2 An exemplary schematic diagram illustrating a data synchronization process between databases provided in an embodiment of this application;

[0072] Figure 3 A flowchart illustrating a method for generating suggestions provided in an embodiment of this application;

[0073] Figure 4 A schematic diagram of a data synchronization device between databases provided in an embodiment of this application;

[0074] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0075] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art based on this application are within the scope of protection of this application.

[0076] To reduce the manual operations required for data synchronization between databases, this application provides a data synchronization method between databases. This method is applied to electronic devices, such as servers, desktop computers, or laptops, which are devices with data processing capabilities. Figure 1 As shown, the data synchronization method between databases provided in this application embodiment includes the following steps:

[0077] S101. Obtain the metadata information of the source fields of the source data table in the source database, and the metadata information of the target fields of the target data table in the target database.

[0078] In this embodiment, the user can configure a data synchronization task through a visual system interface provided by the electronic device. For example, the user can select a source field from a source table in the source database and a target field from a target table in the target database within the visual system interface. There can be multiple source fields, each corresponding to one target field. The processing method for each set of source and target fields is the same. This embodiment uses a set of source and target fields as an example for illustration.

[0079] Electronic devices are pre-configured with connection information for both the source and target databases. These connections allow the devices to access and manipulate data within the databases. This connection information may include, for example, a connection address, authentication credentials, and Java Database Connectivity (JDBC) driver information.

[0080] Electronic devices can obtain the metadata information of fields through the database's JDBC interface, based on the database's schema, the source table's table name, and the field names.

[0081] The metadata information includes: field types and type codes. The type code is the JDBC code corresponding to the field type, determined based on the database type. That is, each database type corresponds to a pre-defined mapping between field types and JDBC codes. Based on the pre-defined mapping for the source database type, the JDBC code corresponding to the source field type can be determined; similarly, based on the pre-defined mapping for the target database type, the JDBC code corresponding to the target field type can be determined.

[0082] S102. Based on the preset correspondence between each type code and type category, determine the first type category corresponding to the type code of the source field and the second type category corresponding to the type code of the target field.

[0083] Each type code represents a field type, and there may be multiple field types that are similar, which belong to the same type category. For example, TINYINT, SMALLINT, and INT all belong to the integer type.

[0084] S103. If the first type and the second type are the same, verify whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field.

[0085] For specific verification methods, please refer to the description below.

[0086] S104. If the verification result is compatible, synchronize the data between the source field and the target field.

[0087] If the verification result is compatible, it means that the data in the source field can be completely synchronized to the target field, so data synchronization between the source field and the target field can be performed.

[0088] The data synchronization method between databases provided in this application can obtain the JDBC codes corresponding to the field types of the source and target fields, and further determine the type category to which the JDBC codes belong. This application uniformly maps field types to JDBC codes, eliminating the impact on compatibility judgment caused by different field type names for the same field type in different databases. Furthermore, this application divides each field type into multiple type categories. Therefore, when the first type category and the second type category are the same, it automatically verifies whether the source and target fields are compatible based on the metadata information of the source and target fields. If the verification result is compatible, it performs data synchronization between the source and target fields, thus achieving automatic compatibility verification without manual verification. This reduces the manual operations required for data synchronization between databases, not only lowering labor costs but also improving verification efficiency and accuracy.

[0089] The following provides a detailed description of the data synchronization method between databases provided in the embodiments of this application:

[0090] Before synchronizing data in a database, you can pre-obtain the database configuration information and field synchronization configuration information for each type of database. These database types include MySQL, Oracle, and SQL Server. MySQL is a relational database management system that uses Structured Query Language (SQL) to access the database; Oracle is a relational database management system with a distributed database core; and SQL Server is a scalable and high-performance relational database management system.

[0091] Database configuration information includes: basic database attributes and database field types.

[0092] Taking MySQL as an example, basic database attributes include: database type, database encoding detection SQL statement, string length unit, maximum length of variable-length string (VARCHAR) fields, field type change syntax template, field addition syntax template, field comment template and table comment template, primary key or distributed key template, and table creation statement template. The database encoding detection SQL statement is used to query the encoding method of the data stored in the database. Encoding methods include GBK, Universal Character Set (UTF)-8, and UTF-16. GBK is a Chinese internal code extension specification representing the Chinese Internal Code Specification. The string length unit can be characters or bytes. The field type change syntax template is used to construct SQL statements to modify the field type in the database. When using this template, the modified field type and required parameters can be set within it. For example, when the modified field type is a string type, the required parameters include the maximum number of characters that can be stored in the field; when the modified field type is a fixed-point number type, the required parameters include the precision and scale of the data that can be stored in the field. The field addition syntax template is used to construct SQL statements for adding fields to a database. When using this template, you can specify the field name, field type, and required parameters. The field comment template is used to construct SQL statements for storing descriptive text information about a field. The table comment template is used to construct SQL statements for storing descriptive text information about a specified data table. The primary key or distribution key template is used to construct SQL statements for specifying the primary key or distribution key of a data table. The table creation statement template is used to construct table creation statements for creating data tables in the database.

[0093] Database field types indicate the field types supported by the database table. For example, field types include: TINYINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DECIMAL, and NUMERIC.

[0094] The field synchronization configuration information includes: the field types supported by this database type, the correspondence between each field type and JDBC encoding, the conversion strategy for each field type, and the correspondence between each field type and type category.

[0095] Taking MySQL as an example, the field synchronization configuration information includes:

[0096] TINYINT, JDBC encoding is -6, conversion strategy is no conversion, type is long integer.

[0097] Character (CHAR), JDBC encoding is 1, conversion strategy is length conversion, type is string (STRING);

[0098] VARCHAR, JDBC encoding is 12, the conversion strategy is the same as the length conversion, and the type is STRING.

[0099] Length conversion refers to converting the column size (COLUMN_SIZE) of the source field, where COLUMN_SIZE represents the maximum length of data that can be stored within the field. Length conversion includes the following three cases:

[0100] When both the source and target fields have string lengths in bytes, and the source field is encoded in GBK while the target field is encoded in UTF-8, the source field's COLUMN_SIZE is multiplied by 2 to obtain the converted COLUMN_SIZE. This can be achieved by obtaining the string length unit from the database configuration information and executing a database encoding detection SQL statement to determine the field's encoding, thus leading to a more accurate converted COLUMN_SIZE.

[0101] If the length of the source field is in characters, the length of the target field is in bytes, and the target field is encoded in GBK, then the COLUMN_SIZE of the source field is multiplied by 2 to obtain the converted COLUMN_SIZE.

[0102] If the length of the source field is in characters and the length of the target field is in bytes, and the target field is encoded in UTF-8, then the COLUMN_SIZE of the source field is multiplied by 4 to obtain the converted COLUMN_SIZE.

[0103] The above three cases are merely examples of length conversion strategies provided in the embodiments of this application. The length conversion strategy may also include conversion methods in other cases, which can be set based on the actual application scenario.

[0104] In this embodiment of the application, the conversion strategy for a field type of string can be set to length conversion, and the conversion strategy for an integer field type can be set to no conversion.

[0105] After receiving the data synchronization task configured by the user, the electronic device can obtain the database type of the source database and the database type of the target database, thereby obtaining the database configuration information corresponding to the database type of the source database and the database configuration information corresponding to the database type of the target database.

[0106] In some embodiments of this application, in S101 above, the electronic device can obtain metadata information of the source field and the target field through the JDBC interface. For example, the metadata information includes: column name (COLUMN_NAME), data type (DATA_TYPE), type name (TYPE_NAME), COLUMN_SIZE, decimal places (DECIMAL_DIGITS), floating-point base (NUM_PREC_RADIX), and remarks (REMARKS). Here, DATA_TYPE is the JDBC encoding, TYPE_NAME is the field type, DECIMAL_DIGITS indicates the number of decimal places in the field value, NUM_PREC_RADIX can be decimal or binary, and REMARKS can include information such as the field's purpose and meaning.

[0107] In step S102 above, since the electronic device has pre-acquired the database configuration information corresponding to the database type of the source database, including the preset correspondence between the field types and type categories supported by that data type, the first type category corresponding to the type code of the source field can be determined based on this. Similarly, based on the database configuration information corresponding to the database type of the target database, the second type category corresponding to the type code of the target field can be determined.

[0108] The types include: STRING, LONG, DOUBLE, DATE, BYTES, and BOOLEAN.

[0109] Based on this, in some embodiments of this application, when the first type and the second type are the same, the above-mentioned S103 verifies whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field, including the following situations.

[0110] Scenario 1: Both the first and second type categories represent string types, denoted as STRING. In this case, the field's metadata information may also include: column size, string length unit, and encoding method.

[0111] Because different database drivers do not fully unify their implementation of the JDBC specification, the metadata information obtained from different databases through JDBC interfaces such as Database MetaData or ResultSet MetaData may differ. For example, for the COLUMN_SIZE of a large text field, some database drivers return the actual column size, while others return a fixed extreme value. Taking MySQL as an example, when the source field's type is TEXT, MEDIUMTEXT, or LONGTEXT, the MySQL database driver may return COLUMN_SIZE values ​​such as 65535, 16777215, or 2147483647, representing the maximum number of bytes that the data in the field may contain.

[0112] During verification, the electronic device can convert the column size of the source field to the target column size, even if the column size of the source field is not a preset value (the aforementioned fixed extreme value). The preset value is determined by the string length unit and encoding method of both the source and target fields. The device then checks if the target column size is less than or equal to the target field size. The target column size represents the column size required to store the data from the source field into the target field. If so, the verification result is considered compatible; otherwise, the verification result is considered incompatible.

[0113] The method for converting the column size of the source field to the target column size can be found in the length conversion strategy described above, and will not be repeated here.

[0114] Alternatively, the electronic device can determine whether the column size of the target field is greater than or equal to the preset value if the column size of the source field is the preset value; if so, the verification result is determined to be compatible; otherwise, the verification result is determined to be incompatible.

[0115] Understandably, since the preset value can include a variety of values, such as 65535, 16777215 or 2147483647, when the column size of the source field is a preset value, it is possible to determine whether the column size of the target field is greater than or equal to that preset value.

[0116] It should be noted that some databases may return the same DATA_TYPE as a regular string type in JDBC encoding (e.g., 12) for a certain field, but with a larger COLUMN_SIZE (e.g., 2147483647). This indicates that the field type is a large text field type, not a regular string type. Therefore, this embodiment does not directly use DATA_TYPE to determine whether a field type is a large text field type, but rather uses COLUMN_SIZE to improve the accuracy of determining large text field types.

[0117] When both the first type and the second type are string types, after the compatibility verification in S103 above, if the verification result is incompatible, the electronic device can still generate suggestion information for the target field. The generation method includes the following two cases:

[0118] If the column size of the source field is a preset value, then a field type with a column size greater than or equal to the preset value is selected as the suggested field type for the target field. Specifically, the electronic device can select a field type with the smallest maximum COLUMN_SIZE that is greater than the preset value, based on the maximum COLUMN_SIZE of each string field type in the target database, as the suggested field type, and determine the target column size as the suggested column size.

[0119] If the column size of the source field is not a preset value, then determine whether the target column size of the source field is greater than the upper limit of the column size of the target field's field type; if yes, then select the parent field type of the target field's field type as the suggested field type; if no, then select the target field's field type as the suggested field type and determine the target column size as the suggested column size.

[0120] The parent field type of the target field must be a field type whose maximum COLUMN_SIZE is greater than the size of the target column after conversion from the source field. For example, if the source field is of type LONGTEXT, you can choose one of the parent field types such as LONGTEXT, VARCHAR(MAX), Character Large Object (CLOB), or National Character Large Object (NCLOB). The suggested parent field type is the one with the smallest maximum COLUMN_SIZE. In VARCHAR(MAX), MAX represents the maximum number of characters / bytes that can be stored in the VARCHAR field.

[0121] Using the above method, this application embodiment can generate suggested field types and suggested column sizes for the target field when both the source field and the target field are string types and the verification results show incompatibility. This helps users modify the target field, improves modification efficiency and accuracy, and enhances the accuracy of data synchronization after modification.

[0122] Scenario 2: Both the first and second type categories represent integer types, denoted as LONG. In this case, the verification process for the electronic device includes the following steps:

[0123] Step 1: Based on the preset correspondence between the type codes and range codes of integer types, determine the first range code corresponding to the type code of the source field and the second range code corresponding to the type code of the target field.

[0124] In this application embodiment, a range code corresponding to each type encoding of integer type can be pre-set, wherein the range code corresponding to each type encoding is different. The range of values ​​that the field type corresponding to the type encoding can support storing is positively correlated with the size of the range code corresponding to the type encoding; that is, the larger the range of values ​​that the field type corresponding to the type encoding can support storing, the larger the range code corresponding to the type encoding.

[0125] For example, TINYINT supports storing values ​​in the range [-128, 127], with a corresponding JDBC code of -6, and the range code for -6 is 0. SMALLINT supports storing values ​​in the range [-32768, 32767], with a corresponding JDBC code of 5, and the range code for 5 is 1. INT supports storing values ​​in the range [-2147483648, 2147483647], with a corresponding JDBC code of 4, and the range code for 4 is 2.

[0126] Step 2: Determine whether the first range code is less than or equal to the second range code.

[0127] Step 3: If yes, then the verification result is confirmed as compatible.

[0128] Step 4: Otherwise, the verification result is determined to be incompatible.

[0129] If the first range code is less than or equal to the second range code, it means the range of values ​​that the source field's field type supports is less than or equal to the range of values ​​that the target field's field type supports. In this case, the data in the source field can be completely stored in the target field, thus the verification result is considered compatible. Conversely, if the first range code is greater than the second range code, it means the range of values ​​that the source field's field type supports is greater than the range of values ​​that the target field's field type supports. In this case, the data in the source field may not be completely stored in the target field, thus the verification result is considered incompatible. When the verification result is compatible, synchronizing the source and target fields can reduce the risk of truncation or overflow when synchronizing data from the source field to the target field due to insufficient range of values ​​supported by the target field, thereby improving the accuracy of data synchronization.

[0130] When both the first type and the second type are integer types, after the compatibility verification is performed in S103 above, if the verification result is incompatible, the electronic device can also generate a suggested field type for the target field, including: determining, from the field types corresponding to the first type, a candidate field type whose supported storage value range is greater than or equal to the supported storage value range of the source field, and selecting a candidate field type as the suggested field type.

[0131] For example, if the source field is of type SMALLINT and the target field is of type TINYINT, you can choose SMALLINT, INT, or BIGINT as candidate field types, and then select one of the candidate field types as the suggested field type. For example, you can choose SMALLINT, which supports the smallest range of stored values, as the suggested field type.

[0132] Using the above method, this application embodiment can generate a suggested field type for the target field when both the source field and the target field are integer types and the verification result is incompatible. This helps users modify the target field, improves modification efficiency and accuracy, and enhances the accuracy of data synchronization after modification.

[0133] Scenario 3: Both the first and second types represent non-integer types, denoted as DOUBLE. Non-integer types include floating-point and fixed-point types. For example, floating-point types include FLOAT and DOUBLE, while fixed-point types include DECIMAL and NUMERIC. In this case, the field type's metadata information can also include: column size and decimal places. The column size is COLUMN_SIZE, also known as precision (p); the decimal places are DECIMAL_DIGITS, also known as scale (s), representing the maximum number of decimal places that can be stored in the field.

[0134] Both floating-point and fixed-point numbers can include integer and decimal places. The number of decimal places in a floating-point number is not fixed; for example, FLOAT has 8 significant digits and DOUBLE has 16 significant digits, where the significant digits are the sum of the integer decimal places.

[0135] Fixed-point numbers have a fixed number of decimal places. For example, in relational databases, fixed-point number types are typically represented by DECIMAL(p,s) or NUMERIC(p,s), where the maximum number of integer digits is ps, the maximum number of decimal digits is s, and the maximum positive value that can be stored is ps. The minimum negative value is -MAX.

[0136] For example, DECIMAL(5,2) means that the number of significant digits is 5, that is, precision=5, the maximum number of integer digits is 5, the maximum number of decimal digits is 2, that is, scale=2, and the range of values ​​that can be represented is [-999.99, 999.99].

[0137] For example, DECIMAL(10,0) means: precision=10, scale=0, and the range of values ​​that can be represented is [-9999999999, 9999999999].

[0138] For example, DECIMAL(8,3) means precision=8, scale=3, and the range of values ​​that can be represented is [-99999.999, 99999.999].

[0139] Electronic devices can determine whether a field is a floating-point or fixed-point type by its JDBC encoding. If both the first and second type categories represent non-integer types, the electronic device verifies compatibility between the source and target fields in the following four ways.

[0140] Scenario 1: If both the source and target fields are of fixed-point type, then determine whether the column size of the source field is less than or equal to the column size of the target field, and whether the number of decimal places in the source field is less than or equal to the number of decimal places in the target field. If both conditions are met, the verification result is considered compatible; otherwise, the verification result is considered incompatible.

[0141] If the precision of the source field's field type is less than or equal to the precision of the target field's field type, and the scale of the source field's field type is less than or equal to the scale of the target field's field type, then the data in the source field can be completely stored in the target field, and therefore the verification result is determined to be compatible.

[0142] In this embodiment, if the verification result of case 1 is incompatible, a suggested column size for the target field can be generated if the precision of the source field's field type is greater than or equal to the precision of the source field's field type. If the scale of the source field's field type is greater than or equal to the scale of the target field's field type, a suggested number of decimal places for the target field can be generated if the scale of the source field's field type is greater than or equal to the scale of the source field's field type. For example, when the source field's field type is DECIMAL(28, 8), the suggested field type is DECIMAL(38, 10).

[0143] Case 2: If both the source field and the target field are of floating-point type, then the verification result is considered compatible.

[0144] In practical applications, since complete data synchronization can generally be performed between fields of various floating-point types, the verification result can be determined to be compatible if both the source field and the target field are floating-point types.

[0145] Case 3: If the source field is of fixed-point type and the target field is of floating-point type, then the verification result is determined to be incompatible.

[0146] In practical applications, it is generally difficult to completely synchronize data from a fixed-point field to a floating-point field, so the verification result can be determined to be incompatible.

[0147] In this embodiment of the application, if the verification result of case 3 is incompatible, the type of the source field can be encoded in the corresponding field type in the target database as the suggested field type of the target field.

[0148] Case 4: If the source field is a floating-point number and the target field is a fixed-point number, determine whether the range of values ​​that the source field's field type supports is less than or equal to the range of values ​​that the target field's field type supports. If so, the verification result is considered compatible; otherwise, the verification result is considered incompatible.

[0149] In practical applications, while synchronizing data from floating-point fields to fixed-point fields generally achieves complete data synchronization, incomplete synchronization may occur when the range of values ​​supported by the floating-point type is greater than that supported by the fixed-point type. For example, if the size of a floating-point column is larger than that of a fixed-point column, or if the number of decimal places in a floating-point number is greater than that in a fixed-point number, incomplete data synchronization may not be possible. Therefore, this embodiment determines whether the range of values ​​supported by the source field's field type is less than or equal to the range of values ​​supported by the target field's field type. If so, the verification result is determined to be compatible; otherwise, the verification result is determined to be incompatible.

[0150] In this embodiment of the application, if the verification result of case 4 is incompatible, the type of the source field can be encoded in the corresponding field type in the target database as the suggested field type of the target field.

[0151] When both the first type and the second type represent non-integer types, the embodiments of this application can perform different compatibility judgments for different situations, thereby improving the accuracy of compatibility judgment.

[0152] Case 4: Both the first and second types are other types, including date, binary, and boolean types.

[0153] The verification process for the electronic device can then be implemented as follows: Determine whether the type codes of the source field and the target field are the same, or whether an equivalent mapping relationship exists between the type codes of the source field and the target field in a pre-defined equivalence mapping table. If either determination is yes, the verification result is determined to be compatible. Otherwise, the verification result is determined to be incompatible.

[0154] The equivalence mapping table stores multiple pre-defined equivalence mapping relationships. Each equivalence mapping relationship represents a mapping between two JDBC codes, and each relationship corresponds to a database type. In other words, each equivalence mapping relationship indicates that a field type in a database supports equivalence mapping with another field type. Therefore, after obtaining the JDBC codes of the source field in the source database and the target field in the target database, the equivalence mapping table can be used to check if a mapping relationship exists between these two JDBC codes. If it does, the verification result is determined to be compatible.

[0155] For example, an equivalence mapping table includes an equivalence mapping relation of -7. 16, and the database type corresponding to this equivalence mapping is MySQL. That is, this equivalence mapping indicates that it is set for MySQL, and MySQL supports equivalence mapping between BIT and BOOLEAN. If the source database is SQL Server, the source field's field type is BIT, and the corresponding JDBC code is -7; and the target database is MySQL, the target field's field type is BOOLEAN, and the corresponding JDBC code is 16. Because the equivalence mapping table includes the equivalence mapping set for MySQL: -7 16. Therefore, it can be determined that there is an equivalent mapping relationship from SQL Server BIT to MySQL BOOLEAN, thus confirming that the two are compatible.

[0156] In practical applications, data synchronization is generally successful when the source and target field type codes are the same, thus confirming a compatible verification result. Furthermore, the pre-defined equivalence mapping table records the mapping relationships between type codes that allow for complete data synchronization. Therefore, if an equivalence mapping exists between the source and target field type codes in the pre-defined equivalence mapping table, the verification result is confirmed as compatible. Conversely, if the source and target field type codes are different, and no equivalence mapping exists in the pre-defined equivalence mapping table, synchronizing data from the source field to the target field may not be successful, resulting in an incompatible verification result and improving the accuracy of the verification.

[0157] In this embodiment of the application, if the verification result of case four is incompatible, the type of the source field can be encoded in the corresponding field type in the target database as the suggested field type of the target field.

[0158] In some embodiments of this application, after determining the first type and the second type in S102 above, the electronic device may further perform the following: if the first type and the second type are different, generate a suggested field type for the target field based on the metadata information of the source field.

[0159] Specifically, the JDBC encoding of the source field can be used as the corresponding field type in the second target database as a suggested field type; or, the field type in the second target database that supports storing a numerical range greater than or equal to the numerical range supported by the source field under the first type can be used as a suggested field type.

[0160] Optionally, when the suggested field type is a non-integer type, the suggested column size and suggested decimal places in the suggested field type can also be generated, wherein the suggested column size is greater than or equal to the column size of the source field, and the suggested decimal places are greater than or equal to the decimal places of the source field.

[0161] This application embodiment can generate suggested information based on the metadata information of the source field when the first type and the second type are different. This makes it easier for users to modify or set the target field more quickly based on the suggested information, reducing manual workload and improving the accuracy of data synchronization after modification.

[0162] In this embodiment, when the target data table does not exist (i.e., the target data table has not been created), suggested information can be generated in the manner described above to assist the user in creating the target data table and improve table creation efficiency. Specifically, when creating a table, the user can reference the table creation statement template in the target database's database configuration information. When modifying field types, the user can reference the field type change syntax template in the target database's database configuration information and set the target field's field type to the suggested field type in the template. This automatically generates and executes the corresponding SQL statement, saving a significant amount of manual work and improving the efficiency of creating and modifying the target data table.

[0163] After verifying and generating the recommendation information, the electronic device can generate a list of field model inference results, which includes: the column name of each source field, the column name of the target field corresponding to each source field, the verification result of whether each source field and target field are compatible, and the recommended field type.

[0164] Because this application embodiment performs compatibility verification on the source and target fields before data synchronization, if the verification result is compatible, the data in the source field can most likely be completely synchronized to the target field, thus ensuring accurate data synchronization. If the verification result is incompatible, suggested field types can be generated, thereby reducing the risk of floating-point synchronization errors or data precision truncation during the data synchronization process. Furthermore, since the verification results can be provided to the user, allowing them to understand the incompatible source and target fields, the user can modify the target field before data synchronization, thereby reducing the possibility of abnormal interruptions or data loss during the data synchronization process.

[0165] The following example illustrates the data synchronization method between databases provided in this application:

[0166] Example 1: The user configures the source database for the data synchronization task as MySQL, with the source field's COLUMN_NAME set to 'name', and the target database as Oracle, with the target field's COLUMN_NAME set to 'name', through the visual system interface provided by the electronic device. Based on the data synchronization task, the electronic device obtains the metadata information of the source field from the source table in the source database via the JDBC interface. The source field's field type is CHAR(20), where 20 represents COLUMN_SIZE and its JDBC encoding is 1. The device also obtains the metadata information of the target field from the target table in the target database via the JDBC interface. The target field's field type is VARCHAR2(50), where 50 represents COLUMN_SIZE and its JDBC encoding is 12. Then, based on the preset correspondence between type codes and type categories, the electronic device determines that type 1 corresponds to STRING, and type 12 also corresponds to STRING. Therefore, both the source and target fields are of type STRING. Since the source field's COLUMN_SIZE is 20 instead of the preset value, the metadata shows that the source field's string length is in characters and its encoding is GBK, while the target field's string length is in bytes and its encoding is UTF-8. Therefore, multiplying the source field's COLUMN_SIZE by 2 equals 40, meaning that storing 20 characters encoded in UTF-8 requires 40 bytes. Since the target field's COLUMN_SIZE is 50 > 40, the verification results for the source and target fields are confirmed to be compatible, and data synchronization between the source and target fields can proceed.

[0167] Example 2: Assume the source database for the data synchronization task is MySQL, and the source field of the source table in the source database has a data type of DECIMAL(12,4), where 12 represents COLUMN_SIZE and 4 represents DECIMAL_DIGITS. The target database is Oracle, and the target field of the target table in the target database has a data type of NUMBER(10,3), where 10 represents COLUMN_SIZE and 3 represents DECIMAL_DIGITS. Since both the source and target fields are non-integer types, and 12>10, 4>3, the verification result of the source and target fields is determined to be incompatible. The electronic device then generates a suggested field type of NUMBER(12,4), where 12 represents COLUMN_SIZE and 4 represents DECIMAL_DIGITS, and displays the suggested field type to the user. If the user agrees to adopt the suggested field type, the electronic device can modify the target field's data type to NUMBER(12,4) and synchronize the data between the source and target fields.

[0168] This application embodiment pre-configures database configuration information and field synchronization configuration information for each type of database. Before data synchronization, it obtains the metadata information of the upstream field (source field) and downstream field (target field) for data synchronization through the JDBC interface. Based on this information, it determines the type of the upstream and downstream fields from six categories, thereby performing fine-grained compatibility verification of the upstream and downstream fields. This can significantly reduce manual operations in the data synchronization process and reduce errors caused by human subjective error in the data synchronization process. It provides an efficient, automatically upgraded, and prompting field synchronization strategy for data exchange between heterogeneous databases in enterprises.

[0169] See Figure 2 The following describes the complete process of the data synchronization method between databases provided in the embodiments of this application:

[0170] S201. Obtain the database configuration information and field synchronization configuration information corresponding to each type of database.

[0171] Electronic devices can pre-acquire database configuration information and field synchronization configuration information for each type of database, and use the pre-acquired database configuration information and field synchronization configuration information each time a data synchronization task is executed. Alternatively, electronic devices can acquire the database configuration information and field synchronization configuration information for each type of database set for this data synchronization task before each data synchronization task is executed.

[0172] S202. Obtain the metadata information of the source fields of the source data table in the source database and the metadata information of the target fields of the target data table in the target database through the JDBC interface.

[0173] S203. Determine if there are any unvalidated source and target fields. If yes, proceed to S204; otherwise, confirm the end of validation.

[0174] Each data synchronization task can include one or more source fields, and each source field corresponds to a target field.

[0175] S204. Obtain a set of unverified source and target fields.

[0176] S205. Determine if the source field and target field have the same data type. If they are the same, proceed to S206; otherwise, generate suggested field types.

[0177] S206. Determine whether the source and target fields are of string type. If yes, proceed to S207; otherwise, proceed to S209.

[0178] S207. Determine if the column size of the source field is a preset value. If yes, determine that the column size of the source field does not need to be converted; otherwise, convert the column size of the source field. Regardless of whether the result of S207 is yes or no, S208 will be executed next.

[0179] S208. Determine if the column size of the source field is less than or equal to the column size of the target field. If yes, the validation result is determined to be compatible; otherwise, the validation result is determined to be incompatible, and a suggested field type is generated. Regardless of whether the result of S208 is yes or no, return to S203.

[0180] The verification methods for S207 and S208 can be found in the description of Case 1 above, and will not be repeated here.

[0181] S209. Determine whether the source and target fields are integer types. If yes, proceed to S210; otherwise, proceed to S211.

[0182] S210: Determine whether the first range code corresponding to the type code of the source field is less than or equal to the second range code corresponding to the type code of the target field. If yes, the verification result is determined to be compatible; if no, the verification result is determined to be incompatible, and a suggested field type is generated. Regardless of whether the judgment result of S210 is yes or no, the process returns to S203.

[0183] The verification method for S210 can be found in the description of Case 2 above, and will not be repeated here.

[0184] S211. Determine whether the source and target fields are non-integer types. If yes, proceed to S212; otherwise, proceed to S213.

[0185] S212. Verify whether the source field and the target field are compatible. If yes, determine the verification result as compatible; if no, determine the verification result as incompatible and generate suggested field types. Regardless of whether the judgment result of S212 is yes or no, return to S203.

[0186] The verification method for S212 can be found in the description of Case 3 above, and will not be repeated here.

[0187] S213. Determine whether the type codes of the source field and the target field are the same, or whether an equivalent mapping relationship exists between the type codes of the source field and the target field in the preset equivalence mapping table. If yes, the verification result is determined to be compatible; if no, the verification result is determined to be incompatible, and a suggested field type is generated. Regardless of whether the judgment result of S213 is yes or no, the process returns to S203.

[0188] The verification method for S213 can be found in the description of Case 4 above, and will not be repeated here.

[0189] See Figure 3 The following describes the overall process for generating suggested field types for electronic devices:

[0190] S301. Obtain the type of the source database and the type of the target database.

[0191] S302. Obtain the database configuration information and field synchronization configuration information corresponding to the type of the source database, and the database configuration information and field synchronization configuration information corresponding to the type of the target database.

[0192] S303. Determine the JDBC encoding corresponding to the field type of the source field, and determine whether the JDBC encoding corresponds to the conversion strategy. If yes, proceed to S304. If no, proceed to S312.

[0193] S304. Determine whether the conversion strategy is length conversion. If yes, proceed to S305; otherwise, proceed to S309.

[0194] S305. Obtain the string length unit and encoding method of the source field and the string length unit and encoding method of the target field.

[0195] S306. Determine if the column size of the source field is the preset value. If yes, proceed to S307; otherwise, proceed to S308.

[0196] S307. Select a field type whose column size is greater than or equal to a preset value as the suggested field type for the target field.

[0197] S308. Determine whether the target column size after converting the source field column size based on the obtained string length unit and encoding method of the source field and the target field column size is greater than the upper limit of the column size of the target field's field type. If yes, select the parent field type of the target field's field type as the suggested field type; if not, select the target field's field type as the suggested field type and determine the target column size as the suggested column size.

[0198] S309. Determine whether the conversion strategy is a precision conversion. If yes, execute S310; otherwise, execute S311.

[0199] S310. Select a value that is greater than or equal to the column size of the source field as the suggested column size, and select a value that is greater than or equal to the number of decimal places of the source field as the suggested number of decimal places.

[0200] S311. Encode the type of the source field into the corresponding field type in the target database, and use it as the suggested field type for the target field.

[0201] S312. Generate a prompt message indicating that the source field and the target field are incompatible and the user needs to manually modify the target field.

[0202] First, traditional compatibility verification methods generally rely on manual work or simple matching based solely on field types. These methods cannot deeply verify compatibility between fields, nor can they detect potential precision loss and truncation risks during data synchronization. This leads to frequent errors or data anomalies during data synchronization, requiring manual field modification, increasing repetitive work and introducing instability into the data synchronization system. In contrast, this application maintains the mapping relationship between JDBC encoding and field types in the field synchronization configuration information, abstracting various field types into six categories: STRING, LONG, DOUBLE, DATE, BYTES, and BOOLEAN. This avoids the limitations of point-to-point mapping for each field type and fully utilizes logic such as column size conversion, fixed-point vs. floating-point type difference judgment, and preset column size judgment. This provides a more intelligent and flexible solution to common problems in real-world business scenarios, such as precision truncation, numerical range overflow, and character encoding mismatches.

[0203] Secondly, this application separates the field compatibility verification process from the automatic table creation or data synchronization process, thereby ensuring that field compatibility verification has been performed before data synchronization. Furthermore, when the verification result indicates incompatibility, a suggested field type for the target field can be provided, thereby reducing the likelihood of data synchronization task failure or errors due to field incompatibility.

[0204] Furthermore, this application embodiment utilizes a field type classification and verification reasoning mechanism. Even if the column size obtained from the database through the JDBC interface has a special preset value, verification reasoning can be automatically performed through the judgment logic of the preset value, thereby ensuring the accuracy of the verification result.

[0205] Furthermore, the embodiments of this application utilize the concept of "n→JDBC encoding→n", that is, to uniformly map the field types of different databases to the JDBC encoding dimension, thereby centrally managing and configuring the field types of various databases and providing a visual configuration method. This is not only applicable to the current mainstream databases, but can also be extended to new types of databases or new field types in databases, making the evolution process of compatibility verification more maintainable and the implementation cost lower.

[0206] Furthermore, in related technologies, when fields are incompatible, users are either directly prompted to reconfigure the fields, or the field type with the largest supported numerical range is suggested indiscriminately. This leads to wasted storage resources, reduced system performance, and increased difficulty in subsequent analysis and maintenance. In contrast, the embodiments of this application can select different suggested field generation methods for different situations. Moreover, when selecting suggested field types, it can choose field types that are compatible with the first field and occupy fewer storage resources, reducing storage resource waste, improving system performance, and lowering the difficulty of subsequent analysis and maintenance.

[0207] In summary, the data synchronization method between databases provided in this application can improve the accuracy and robustness of the data synchronization process while reducing manual workload, making the data distribution and exchange process between large-scale, multi-source heterogeneous databases more efficient and convenient.

[0208] Based on the same inventive concept, and corresponding to the above method embodiments, this application also provides a data synchronization device between databases, such as... Figure 4 As shown, the device includes: an acquisition module 401, a determination module 402, a verification module 403, and a synchronization module 404;

[0209] The acquisition module 401 is used to acquire metadata information of source fields of source data tables in source database and metadata information of target fields of target data tables in target database. The metadata information includes: field type and type encoding. The type encoding is: the Java database connection JDBC encoding corresponding to the field type determined according to the database type.

[0210] The determination module 402 is used to determine the first type of the source field's type code and the second type of the target field's type code based on the preset correspondence between the type codes and type categories.

[0211] The verification module 403 is used to verify whether the source field and the target field are compatible, based on the metadata information of the source field and the metadata information of the target field, when the first type and the second type are the same.

[0212] Synchronization module 404 is used to synchronize the source field and the target field when the verification result of verification module 403 is compatible.

[0213] Optionally, both the first and second type categories represent string types, and the metadata information also includes: column size, string length unit, and encoding method; verification module 403 is specifically used for:

[0214] If the column size of the source field is not a preset value, the column size of the source field is converted to the target column size based on the string length unit and encoding method of the source field and the string length unit and encoding method of the target field. It is then determined whether the target column size is less than or equal to the target field size, where the target column size represents the column size required to store the data in the source field into the target field. If so, the verification result is determined to be compatible; otherwise, the verification result is determined to be incompatible.

[0215] If the column size of the source field is a preset value, determine whether the column size of the target field is greater than or equal to the preset value; if so, determine that the verification result is compatible; otherwise, determine that the verification result is incompatible.

[0216] Optionally, both the first type and the second type represent integer types; verification module 403 is specifically used for:

[0217] Based on the preset correspondence between the type codes and range codes of integer types, the first range code corresponding to the type code of the source field and the second range code corresponding to the type code of the target field are determined; wherein, the range of values ​​that the field type corresponding to the type code can support to be stored is positively correlated with the size of the range code corresponding to the type code;

[0218] Determine whether the first range code is less than or equal to the second range code;

[0219] If so, then the verification result is confirmed as compatible;

[0220] Otherwise, the verification result is determined to be incompatible.

[0221] Optionally, both the first and second type categories represent non-integer types, including floating-point and fixed-point types. Metadata information also includes column size and decimal places. Verification module 403 is specifically used for:

[0222] If both the source field and the target field are of fixed-point type, then determine whether the column size of the source field is less than or equal to the column size of the target field, and whether the number of decimal places in the source field is less than or equal to the number of decimal places in the target field; if both of these conditions are met, then the verification result is considered compatible; otherwise, the verification result is considered incompatible.

[0223] If both the source field and the target field are of floating-point type, then the verification result is considered compatible.

[0224] If the source field is of fixed-point type and the target field is of floating-point type, then the verification result is determined to be incompatible.

[0225] If the source field is of floating-point type and the target field is of fixed-point type, then determine whether the range of values ​​that the source field type supports storing is less than or equal to the range of values ​​that the target field type supports storing; if so, the verification result is determined to be compatible; otherwise, the verification result is determined to be incompatible.

[0226] Optionally, both the first and second types can be other types, including: date type, binary type, and boolean type; verification module 403 is specifically used for:

[0227] Determine whether the type codes of the source field and the target field are the same, or whether there is an equivalent mapping relationship between the type codes of the source field and the target field in the preset equivalence mapping table;

[0228] If any judgment result is yes, then the verification result is determined to be compatible;

[0229] Otherwise, the verification result is determined to be incompatible.

[0230] Optionally, the device may also include:

[0231] The selection module is used to verify whether the source field and the target field are compatible based on the metadata information of the source field and the target field. If the verification result is incompatible, and the column size of the source field is a preset value, then a field type with a column size greater than or equal to the preset value is selected as the suggested field type for the target field.

[0232] The generation module is used to verify the compatibility between the source field and the target field based on the metadata information of the source field and the target field. If the verification result is incompatible, and the column size of the source field is not a preset value, it determines whether the target column size of the source field is greater than the upper limit of the column size of the target field's field type. If so, it selects the parent field type of the target field's field type as the suggested field type. If not, it selects the field type of the target field as the suggested field type and determines the target column size as the suggested column size.

[0233] Optionally, module 402 is also used for:

[0234] After verifying the compatibility between the source field and the target field based on the metadata information of the source field and the target field, if the verification result is incompatible, candidate field types whose supported storage value range is greater than or equal to the supported storage value range of the source field are determined from the field types corresponding to the first type category.

[0235] Select a candidate field type as the suggested field type.

[0236] This application also provides an electronic device, such as... Figure 5 As shown, it includes a processor 501, a communication interface 502, a memory 503, and a communication bus 504, wherein the processor 501, the communication interface 502, and the memory 503 communicate with each other through the communication bus 504.

[0237] Memory 503 is used to store computer programs;

[0238] When the processor 501 executes the program stored in the memory 503, it implements the method steps in the above method embodiments.

[0239] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.

[0240] The communication interface is used for communication between the aforementioned electronic devices and other devices.

[0241] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.

[0242] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.

[0243] In another embodiment provided in this application, a computer-readable storage medium is also provided, which stores a computer program that, when executed by a processor, implements the steps of the data synchronization method between any of the above databases.

[0244] In another embodiment provided in this application, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to perform the data synchronization method between any of the databases described in the above embodiments.

[0245] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially as a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk (SSD)).

[0246] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0247] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the apparatus embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.

[0248] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application are included within the scope of protection of this application.

Claims

1. A method for data synchronization between databases, characterized in that, include: Obtain metadata information of source fields from source tables in source database and metadata information of target fields from target tables in target database. The metadata information includes: field type and type encoding, wherein the type encoding is: the Java database connection JDBC encoding corresponding to the field type determined according to the database type. Based on the preset correspondence between each type code and type category, determine the first type category corresponding to the type code of the source field and the second type category corresponding to the type code of the target field; When the first type and the second type are the same, the compatibility between the source field and the target field is verified based on the metadata information of the source field and the metadata information of the target field. If the verification result is compatible, the source field and the target field are synchronized.

2. The method according to claim 1, characterized in that, Both the first type and the second type represent string types. The metadata information also includes: column size, string length unit, and encoding method. Verifying the compatibility between the source field and the target field based on the metadata information of the source field and the target field includes: If the column size of the source field is not a preset value, the column size of the source field is converted to the target column size based on the string length unit and encoding method of the source field and the string length unit and encoding method of the target field. It is then determined whether the target column size is less than or equal to the column size of the target field, where the target column size represents the column size required to store the data in the source field into the target field. If yes, the verification result is determined to be compatible; otherwise, the verification result is determined to be incompatible. If the column size of the source field is a preset value, determine whether the column size of the target field is greater than or equal to the preset value; if so, determine that the verification result is compatible; otherwise, determine that the verification result is incompatible.

3. The method according to claim 1, characterized in that, Both the first type and the second type represent integer types; The step of verifying whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field includes: Based on the preset correspondence between the type codes and range codes of integer types, the first range code corresponding to the type code of the source field and the second range code corresponding to the type code of the target field are determined; wherein, the range of values ​​that the field type corresponding to the type code can support storing is positively correlated with the size of the range code corresponding to the type code; Determine whether the first range code is less than or equal to the second range code; If so, then the verification result is confirmed as compatible; Otherwise, the verification result is determined to be incompatible.

4. The method according to claim 1, characterized in that, Both the first type and the second type represent non-integer types, including floating-point and fixed-point types. The metadata information also includes column size and decimal places. Verifying the compatibility between the source field and the target field based on the source field's metadata information and the target field's metadata information includes: If both the source field and the target field are of fixed-point type, then determine whether the column size of the source field is less than or equal to the column size of the target field, and whether the number of decimal places in the source field is less than or equal to the number of decimal places in the target field; if both are true, then the verification result is determined to be compatible; otherwise, the verification result is determined to be incompatible. If both the source field and the target field are of floating-point type, then the verification result is determined to be compatible. If the source field is of type fixed-point and the target field is of type floating-point, then the verification result is determined to be incompatible. If the source field is of floating-point type and the target field is of fixed-point type, then determine whether the range of values ​​that the source field type supports storing is less than or equal to the range of values ​​that the target field type supports storing; if so, the verification result is determined to be compatible; otherwise, the verification result is determined to be incompatible.

5. The method according to claim 1, characterized in that, Both the first type and the second type are other types, including: date type, binary type, and boolean type; the step of verifying the compatibility between the source field and the target field based on the metadata information of the source field and the metadata information of the target field includes: Determine whether the type code of the source field is the same as the type code of the target field, or whether there is an equivalent mapping relationship between the type code of the source field and the type code of the target field in the preset equivalence mapping table; If any judgment result is yes, then the verification result is determined to be compatible; Otherwise, the verification result is determined to be incompatible.

6. The method according to claim 2, characterized in that, After verifying the compatibility between the source field and the target field based on the metadata information of the source field and the target field, if the verification result is incompatibility, the method further includes: If the column size of the source field is a preset value, then a field type with a column size greater than or equal to the preset value is selected as the suggested field type for the target field. If the column size of the source field is not a preset value, then determine whether the target column size of the source field is greater than the upper limit of the column size of the target field's field type; if yes, then select the parent field type of the target field's field type as the suggested field type; if no, then select the target field's field type as the suggested field type, and determine the target column size as the suggested column size.

7. The method according to claim 3, characterized in that, After verifying the compatibility between the source field and the target field based on the metadata information of the source field and the target field, the method further includes: If the verification result is incompatible, candidate field types whose supported storage value range is greater than or equal to the supported storage value range of the source field are determined from the field types corresponding to the first type category. Select a candidate field type as the suggested field type.

8. A data synchronization device between databases, characterized in that, include: The acquisition module is used to acquire metadata information of source fields of source data tables in source database and metadata information of target fields of target data tables in target database. The metadata information includes: field type and type encoding, wherein the type encoding is: the Java database connection JDBC encoding corresponding to the field type determined according to the database type. The determination module is used to determine the first type corresponding to the type code of the source field and the second type corresponding to the type code of the target field based on the preset correspondence between each type code and type category; The verification module is used to verify whether the source field and the target field are compatible, based on the metadata information of the source field and the metadata information of the target field, when the first type and the second type are the same. The synchronization module is used to synchronize the source field and the target field when the verification result of the verification module is compatible.

9. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the method described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method described in any one of claims 1-7.

Citation Information

Patent Citations

  • Database communication method and device, equipment and storage medium

    CN116303365A

  • Heterogeneous database data field synchronization method and system

    CN118170851A