String field type mapping method and apparatus, computer device, and storage medium
Patent Information
- Application Number
- CN202211649233.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-21
- Publication Date
- 2026-08-18
- Estimated Expiration
- 2042-12-21
AI Technical Summary
[0003]在当前的字段类型映射方式中,基本都没有考虑到字符集不一致的情况,没有考虑到不同数据库之间的字符集差异,如果是不同的字符集,随着正常的字段映射,可能导致后续数据同步过程中发生数据落库异常的情况
[0038]本发明与现有技术相比的有益效果是:本发明通过确定数据库连接信息以及表格,根据确定的内容获取候选集合,对候选集合的字段类型为字符串的字段列表进行字符串映射,实现基于字符集不一致的数据库字符串字段类型的映射方式,避免数据同步过程中发生数据落库异常的情况。
Smart Images

Figure CN116049201B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a field type mapping method, and more specifically to a string field type mapping method, apparatus, computer device, and storage medium. Background Technology
[0002] With increasing emphasis on information privacy, it is necessary to manage and de-identify existing data before re-entering the database. This may result in the managed data being stored in different databases, and inconsistencies in character sets between different databases often occur. Therefore, it is particularly important to consider character set inconsistencies when handling field type mapping.
[0003] The current field type mapping method basically does not take into account the situation of inconsistent character sets, nor does it consider the differences in character sets between different databases. If different character sets are used, normal field mapping may lead to data loss anomalies during subsequent data synchronization.
[0004] Therefore, it is necessary to design a new method to implement a mapping method for database string field types with inconsistent character sets, so as to avoid data loss anomalies during data synchronization. Summary of the Invention
[0005] The purpose of this invention is to overcome the shortcomings of the prior art and provide a string field type mapping method, apparatus, computer device and storage medium.
[0006] To achieve the above objectives, the present invention adopts the following technical solution: a string field type mapping method, comprising:
[0007] Obtain the connection information between the source and target databases, as well as the tables that need to be mapped, to obtain the database connection information and tables;
[0008] Based on the database connection information and the table, obtain the relevant character set to get the candidate set;
[0009] Determine a list of fields of type string in the candidate set to obtain the fields to be mapped;
[0010] Perform string mapping on the field to be mapped to obtain the mapping result;
[0011] Send the mapping result to the terminal.
[0012] The further technical solution is as follows: obtaining the connection information of the source database and the target database, as well as the tables to be mapped, to obtain the database connection information and tables, includes:
[0013] Obtain the connection information of the source and target databases for which field mapping is required, as well as the tables in the source database that need to be mapped, in order to obtain the database connection information and tables.
[0014] Its further technical solution is as follows: the step of obtaining relevant character sets based on database connection information and tables to obtain a candidate set includes:
[0015] Connect the source database and the target database according to the database connection information, and obtain the character set of the source database, the character set of the target database, the character set of the table, the character set of each field of the table, and the field list of the table according to the table to obtain the candidate set.
[0016] A further technical solution is as follows: the string mapping of the field to be mapped to obtain the mapping result includes:
[0017] Determine whether there are Chinese characters in the field to be mapped;
[0018] If the field to be mapped contains Chinese characters, determine the number of bytes containing the Chinese characters to obtain the length of the field type;
[0019] Get the type of the target field;
[0020] Determine whether the maximum length supported by the target field type exceeds the length of the field type;
[0021] If the maximum length supported by the target field type exceeds the length of the field type, then the target field type and the length of the field type are determined as the mapping result.
[0022] The further technical solution is as follows: after determining whether there are Chinese characters in the field to be mapped, it also includes:
[0023] If there are no Chinese characters in the field to be mapped, the number of bytes occupied by English characters is determined to obtain the length of the field type, and the process of obtaining the target field type is executed.
[0024] A further technical solution is as follows: after determining whether the maximum length supported by the target field type exceeds the length of the field type, the method further includes:
[0025] If the maximum length supported by the target field type does not exceed the length of the field type, then the target field type is updated according to the field type in the database where the target field type is located, and the process of determining the target field type and the length of the field type is executed as the mapping result.
[0026] The further technical solution is as follows: updating the target field type according to the field type in the database where the target field type is located includes:
[0027] Determine whether the maximum length supported by the field type in the database containing the target field type exceeds the length of the field type.
[0028] If the maximum length supported by the field type in the database where the target field type is located exceeds the length of the field type, then the target field type will be replaced by the field type with the smallest length difference in the database where the target field type is located.
[0029] If the maximum length supported by the field type in the database containing the target field type does not exceed the length of the field type, then the target field type will be replaced with a field type provided by default in each database for storing massive amounts of string data.
[0030] The present invention also provides a string field type mapping device, comprising:
[0031] The acquisition unit is used to configure the connection information of the source database and the target database, as well as the tables that need to be mapped, in order to obtain the database connection information and the tables.
[0032] The character set acquisition unit is used to obtain relevant character sets based on database connection information and tables to obtain a candidate set;
[0033] The field acquisition unit is used to determine a list of fields of type string in the candidate set to obtain the fields to be mapped;
[0034] The mapping unit is used to perform string mapping on the field to be mapped in order to obtain the mapping result;
[0035] A sending unit is used to send the mapping result to the terminal.
[0036] The present invention also provides a computer device, the computer device including a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the above-described method.
[0037] The present invention also provides a storage medium storing a computer program that, when executed by a processor, can implement the above-described method.
[0038] The beneficial effects of this invention compared with the prior art are as follows: This invention determines the database connection information and tables, obtains a candidate set based on the determined content, and performs string mapping on the list of fields of type string in the candidate set, thereby realizing a mapping method for database string field types based on inconsistent character sets, and avoiding data loss anomalies during data synchronization.
[0039] The present invention will be further described below with reference to the accompanying drawings and specific embodiments. Attached Figure Description
[0040] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0041] Figure 1 This is a schematic diagram illustrating an application scenario of the string field type mapping method provided in this embodiment of the invention;
[0042] Figure 2 A flowchart illustrating the string field type mapping method provided in an embodiment of the present invention;
[0043] Figure 3 A schematic diagram of a sub-process of the string field type mapping method provided in an embodiment of the present invention;
[0044] Figure 4 A schematic diagram of a sub-process of the string field type mapping method provided in an embodiment of the present invention;
[0045] Figure 5 A schematic block diagram of a string field type mapping device provided in an embodiment of the present invention;
[0046] Figure 6 A schematic block diagram of the mapping unit of the string field type mapping device provided in an embodiment of the present invention;
[0047] Figure 7 A schematic block diagram of the update subunit of the string field type mapping device provided in an embodiment of the present invention;
[0048] Figure 8 A schematic block diagram of a computer device provided for an embodiment of the present invention. Detailed Implementation
[0049] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0050] It should be understood that, when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.
[0051] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.
[0052] It should also be further understood that the term "and / or" as used in this specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0053] Please see Figure 1 and Figure 2 , Figure 1 This is a schematic diagram illustrating an application scenario of the string field type mapping method provided in an embodiment of the present invention. Figure 2 This is a schematic flowchart illustrating a string field type mapping method provided in an embodiment of the present invention. This string field type mapping method is applied in a server. The server interacts with the terminal to resolve the problem of difficult field type mapping between different databases with inconsistent character sets.
[0054] Figure 2 This is a flowchart illustrating the string field type mapping method provided in an embodiment of the present invention. For example... Figure 2 As shown, the method includes the following steps S110 to S150.
[0055] S110. Obtain the connection information of the source database and the target database, as well as the tables that need to be mapped, to obtain the database connection information and tables.
[0056] In this embodiment, database connection information refers to the connection information between the source database and the target database, including the connection method and connection channel, and tables refer to the tables in the source database that need to be mapped to the target database.
[0057] Specifically, obtain the connection information of the source database and target database that need to be mapped, as well as the table in the source database that needs to be mapped, in order to obtain the database connection information and the table.
[0058] S120. Obtain the relevant character set based on the database connection information and the table to obtain the candidate set.
[0059] In this embodiment, the candidate set refers to the character set of the source database, the character set of the target database, the character set of the table, the character set of each field of the table, and the list of fields of the table.
[0060] Specifically, the source database and the target database are connected according to the database connection information, and the character set of the source database, the character set of the target database, the character set of the table, the character set of each field of the table, and the field list of the table are obtained according to the table to obtain a candidate set.
[0061] S130. Determine a list of fields of type string in the candidate set to obtain the fields to be mapped.
[0062] In this embodiment, the fields to be mapped refer to the list of fields in the table whose field type is string.
[0063] Additionally, for fields in the table's field list whose field type is not string, perform a normal field type mapping directly.
[0064] S140. Perform string mapping on the field to be mapped to obtain the mapping result.
[0065] In this embodiment, the mapping result includes the target field type and its corresponding length.
[0066] In one embodiment, please refer to Figure 3 The above-mentioned step S140 may include steps S141 to S147.
[0067] S141. Determine whether there are Chinese characters in the field to be mapped.
[0068] In this embodiment, the containsChinese() function is used to determine whether Chinese characters exist in the field to be mapped in the database.
[0069] S142. If there are Chinese characters in the field to be mapped, determine the number of bytes containing the Chinese characters to obtain the length of the field type.
[0070] In this embodiment, the character set is differentiated based on whether Chinese characters are present. If no Chinese characters are present, the number of bytes occupied by English characters is used for calculation. If Chinese characters are present, the number of bytes occupied by Chinese characters is used for calculation. Formula: x represents the length that the target field type in the target database should be assigned, s represents the number of bytes corresponding to the character set of the source database, t represents the number of bytes corresponding to the character set of the target database, and l represents the actual length corresponding to the target field type in the source database.
[0071] S143. Get the type of the target field.
[0072] In this embodiment, the target field type is obtained through a general field type mapping method.
[0073] S144. Determine whether the maximum length supported by the target field type exceeds the length of the field type;
[0074] S145. If the maximum length supported by the target field type exceeds the length of the field type, then the target field type and the length of the field type are determined as the mapping result.
[0075] S146. If there are no Chinese characters in the field to be mapped, determine the number of bytes occupied by English characters to obtain the length of the field type, and then execute step S143.
[0076] S147. If the maximum length supported by the target field type does not exceed the length of the field type, then update the target field type according to the field type in the database where the target field type is located, and execute step S145.
[0077] In one embodiment, please refer to Figure 4 The above step S147 may include steps S1471 to S1473.
[0078] S1471. Determine whether the maximum length supported by the field type in the database where the target field type is located exceeds the length of the field type;
[0079] S1472. If the maximum length supported by the field type in the database where the target field type is located exceeds the length of the field type, then replace the target field type with the field type in the database where the target field type is located with the smallest length difference.
[0080] S1473. If the maximum length supported by the field type in the database where the target field type is located does not exceed the length of the field type, then the target field type is replaced by the field type provided by default in each database for storing massive amounts of string data.
[0081] Determine whether the maximum length supported by the target field type exceeds the length of the field type. If it does, use the length of the field type; otherwise, the field type needs to be upgraded. During the upgrade process, determine whether the maximum length supported by the target string field type and the field type in the database where the target field type is located exceeds the length of the field type. If so, return the field type with the smallest difference as the result. If not, use the default field type provided by each database for storing massive amounts of string data.
[0082] S150. Send the mapping result to the terminal.
[0083] For example: Table 1 below shows the obtained candidate set.
[0084] Table 1. Candidate Set
[0085] Character set encoding bytes occupied by English bytes occupied by Chinese characters UTF-8 1 3 GBK 1 2 ISO 8859-1 1 1 GB2312 1 3 UTF-16 4 4
[0086] Assume the source database is MySQL and the target database is Oracle. The source database uses UTF-8 character set, and the target database uses GBK character set. The source database contains a table named "test" with UTF-8 character set and the following fields: col1 varchar(4000), col2... The int and col1 fields are in UTF-8, and the database stores data containing Chinese characters. First, based on the connection information of the source and target databases, the character sets of both databases, the source table field list, and the table and field character sets are obtained. Since col1 stores strings, character set inconsistency handling logic is required. col2, which is not a string, follows normal field mapping logic. Because the source col1 field stores data containing Chinese characters, according to the table above, one Chinese character occupies 3 bytes in the database and 2 bytes in the target. The calculated field type length for the target is 3 / 2 * 4000 = 6000. Normally, the target field type should be varchar2, but since Oracle databases can only accept a maximum length of 4000 for varchar2, an upgrade is needed. Since the target Oracle database does not have a string field type with a length greater than or equal to 6000, the CLOB field type, which stores large amounts of strings in Oracle, is chosen to form the mapping result.
[0087] The string field type mapping method described above determines the database connection information and tables, obtains a candidate set based on the determined content, and performs string mapping on the list of fields of type string in the candidate set. This achieves a mapping method for string field types in databases with inconsistent character sets, avoiding data loss anomalies during data synchronization.
[0088] Figure 5 This is a schematic block diagram of a string field type mapping device 300 provided in an embodiment of the present invention. Figure 5 As shown, corresponding to the above string field type mapping method, the present invention also provides a string field type mapping apparatus 300. This string field type mapping apparatus 300 includes a unit for executing the above string field type mapping method, and the apparatus can be configured in a server. Specifically, please refer to... Figure 5The string field type mapping device 300 includes an acquisition unit 301, a character set acquisition unit 302, a field acquisition unit 303, a mapping unit 304, and a sending unit 305.
[0089] The acquisition unit 301 is used to configure the connection information of the source database and the target database, as well as the tables to be mapped, to obtain the database connection information and the tables; the character set acquisition unit 302 is used to obtain the relevant character set according to the database connection information and the tables to obtain a candidate set; the field acquisition unit 303 is used to determine the list of fields of type string in the candidate set to obtain the fields to be mapped; the mapping unit 304 is used to perform string mapping on the fields to be mapped to obtain the mapping result; and the sending unit 305 is used to send the mapping result to the terminal.
[0090] In one embodiment, the acquisition unit 301 is used to acquire the connection information of the source database and the target database that need to be mapped to the fields, as well as the table of the source database that needs to be mapped, so as to obtain the database connection information and the table.
[0091] In one embodiment, the character set acquisition unit 302 is used to connect the source database and the target database according to the database connection information, and to acquire the character set of the source database, the character set of the target database, the character set of the table, the character set of each field of the table, and the field list of the table according to the table, so as to obtain a candidate set.
[0092] In one embodiment, such as Figure 6 As shown, the mapping unit 304 includes a field judgment subunit 3041, a Chinese character length determination subunit 3042, a type acquisition subunit 3043, a length judgment subunit 3044, a result determination subunit 3045, an English character length determination subunit 3046, and an update subunit 3047.
[0093] The following subunits are defined: Field Judgment Subunit 3041, used to determine whether Chinese characters exist in the field to be mapped; Chinese character length determination Subunit 3042, used to determine the number of bytes occupied by the Chinese characters if they exist in the field to be mapped, to obtain the length of the field type; Type Acquisition Subunit 3043, used to acquire the target field type; Length Judgment Subunit 3044, used to determine whether the maximum length supported by the target field type exceeds the length of the field type; Result Determination Subunit 3045, used to determine the target field type and its length as the mapping result if the maximum length supported by the target field type exceeds the length of the field type. English Length Determination Subunit 3046, used to determine the number of bytes occupied by English characters if no Chinese characters exist in the field to be mapped, to obtain the length of the field type, and executes the acquisition of the target field type. Update Subunit 3047, used to update the target field type according to the field type in the database where the target field type is located if the maximum length supported by the target field type does not exceed the length of the field type, and executes the determination of the target field type and its length as the mapping result.
[0094] In one embodiment, such as Figure 7 As shown, the update subunit 3047 includes a length judgment module 30471, a first replacement module 30472, and a second replacement module 30473.
[0095] The length determination module 30471 is used to determine whether the maximum length supported by the field type in the database where the target field type is located exceeds the length of the field type; the first replacement module 30472 is used to replace the target field type with the field type in the database where the target field type is located if the maximum length supported by the field type in the database where the target field type is located exceeds the length of the field type; the second replacement module 30473 is used to replace the target field type with the field type for storing massive amounts of string data provided by default in each database if the maximum length supported by the field type in the database where the target field type is located does not exceed the length of the field type.
[0096] It should be noted that those skilled in the art can clearly understand that the specific implementation process of the above-mentioned string field type mapping device 300 and each unit can be referred to the corresponding description in the foregoing method embodiments. For the sake of convenience and brevity, it will not be repeated here.
[0097] The aforementioned string field type mapping device 300 can be implemented as a computer program, which can, for example... Figure 8 It runs on the computer device shown.
[0098] Please see Figure 8 , Figure 8 This is a schematic block diagram of a computer device provided in an embodiment of this application. The computer device 500 can be a server, wherein the server can be a standalone server or a server cluster composed of multiple servers.
[0099] See Figure 8 The computer device 500 includes a processor 502, a memory, and a network interface 505 connected via a system bus 501. The memory may include a non-volatile storage medium 503 and internal memory 504.
[0100] The non-volatile storage medium 503 may store an operating system 5031 and a computer program 5032. The computer program 5032 includes program instructions that, when executed, cause the processor 502 to perform a string field type mapping method.
[0101] The processor 502 provides computing and control capabilities to support the operation of the entire computer device 500.
[0102] The internal memory 504 provides an environment for the execution of the computer program 5032 in the non-volatile storage medium 503. When the computer program 5032 is executed by the processor 502, the processor 502 can execute a string field type mapping method.
[0103] This network interface 505 is used for network communication with other devices. Those skilled in the art will understand that... Figure 8 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device 500 to which the present application is applied. The specific computer device 500 may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0104] The processor 502 is used to run a computer program 5032 stored in the memory to perform the following steps:
[0105] Obtain the connection information of the source database and the target database, as well as the tables that need to be mapped, to obtain the database connection information and tables; obtain the relevant character sets based on the database connection information and tables to obtain a candidate set; determine the list of fields in the candidate set whose field type is string to obtain the fields to be mapped; perform string mapping on the fields to be mapped to obtain the mapping result; and send the mapping result to the terminal.
[0106] In one embodiment, when the processor 502 implements the step of obtaining the connection information of the source database and the target database, as well as the tables that need to be mapped, to obtain the database connection information and the tables, the specific implementation steps are as follows:
[0107] Obtain the connection information of the source and target databases for which field mapping is required, as well as the tables in the source database that need to be mapped, in order to obtain the database connection information and tables.
[0108] In one embodiment, when implementing the step of obtaining the relevant character set based on the database connection information and the table to obtain the candidate set, the processor 502 specifically implements the following steps:
[0109] Connect the source database and the target database according to the database connection information, and obtain the character set of the source database, the character set of the target database, the character set of the table, the character set of each field of the table, and the field list of the table according to the table to obtain the candidate set.
[0110] In one embodiment, when implementing the step of performing string mapping on the field to be mapped to obtain the mapping result, the processor 502 specifically implements the following steps:
[0111] Determine whether there are Chinese characters in the field to be mapped; if there are Chinese characters in the field to be mapped, determine the number of bytes containing the Chinese characters to obtain the length of the field type; obtain the target field type; determine whether the maximum length supported by the target field type exceeds the length of the field type; if the maximum length supported by the target field type exceeds the length of the field type, determine the target field type and the length of the field type as the mapping result.
[0112] In one embodiment, after performing the step of determining whether a Chinese character exists in the field to be mapped, the processor 502 further performs the following steps:
[0113] If there are no Chinese characters in the field to be mapped, the number of bytes occupied by English characters is determined to obtain the length of the field type, and the process of obtaining the target field type is executed.
[0114] In one embodiment, after performing the step of determining whether the maximum length supported by the target field type exceeds the length of the field type, the processor 502 further performs the following steps:
[0115] If the maximum length supported by the target field type does not exceed the length of the field type, then the target field type is updated according to the field type in the database where the target field type is located, and the process of determining the target field type and the length of the field type is executed as the mapping result.
[0116] In one embodiment, when implementing the step of updating the target field type according to the field type in the database where the target field type is located, the processor 502 specifically implements the following steps:
[0117] Determine whether the maximum length supported by the field type in the database containing the target field type exceeds the length of the field type; if the maximum length supported by the field type in the database containing the target field type exceeds the length of the field type, replace the target field type with the field type in the database containing the target field type that has the smallest length difference; if the maximum length supported by the field type in the database containing the target field type does not exceed the length of the field type, replace the target field type with the field type that each database provides by default for storing massive amounts of string data.
[0118] It should be understood that in the embodiments of this application, the processor 502 may be a central processing unit (CPU), or it may be other general-purpose processors, 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, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.
[0119] It will be understood by those skilled in the art that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program includes program instructions and can be stored in a storage medium, which is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the process steps of the embodiments of the above methods.
[0120] Therefore, the present invention also provides a storage medium. This storage medium can be a computer-readable storage medium. The storage medium stores a computer program, wherein when executed by a processor, the computer program causes the processor to perform the following steps:
[0121] Obtain the connection information of the source database and the target database, as well as the tables that need to be mapped, to obtain the database connection information and tables; obtain the relevant character sets based on the database connection information and tables to obtain a candidate set; determine the list of fields in the candidate set whose field type is string to obtain the fields to be mapped; perform string mapping on the fields to be mapped to obtain the mapping result; and send the mapping result to the terminal.
[0122] In one embodiment, when the processor executes the computer program to obtain the connection information of the source database and the target database, as well as the tables to be mapped, to obtain the database connection information and the tables, the processor specifically implements the following steps:
[0123] Obtain the connection information of the source and target databases for which field mapping is required, as well as the tables in the source database that need to be mapped, in order to obtain the database connection information and tables.
[0124] In one embodiment, when the processor executes the computer program to implement the step of obtaining the relevant character set based on the database connection information and the table to obtain the candidate set, it specifically implements the following steps:
[0125] Connect the source database and the target database according to the database connection information, and obtain the character set of the source database, the character set of the target database, the character set of the table, the character set of each field of the table, and the field list of the table according to the table to obtain the candidate set.
[0126] In one embodiment, when the processor executes the computer program to perform string mapping on the field to be mapped to obtain the mapping result, it specifically implements the following steps:
[0127] Determine whether there are Chinese characters in the field to be mapped; if there are Chinese characters in the field to be mapped, determine the number of bytes containing the Chinese characters to obtain the length of the field type; obtain the target field type; determine whether the maximum length supported by the target field type exceeds the length of the field type; if the maximum length supported by the target field type exceeds the length of the field type, determine the target field type and the length of the field type as the mapping result.
[0128] In one embodiment, after executing the computer program to perform the step of determining whether a Chinese character exists in the field to be mapped, the processor further performs the following steps:
[0129] If there are no Chinese characters in the field to be mapped, the number of bytes occupied by English characters is determined to obtain the length of the field type, and the process of obtaining the target field type is executed.
[0130] In one embodiment, after executing the computer program to perform the step of determining whether the maximum length supported by the target field type exceeds the length of the field type, the processor further performs the following steps:
[0131] If the maximum length supported by the target field type does not exceed the length of the field type, then the target field type is updated according to the field type in the database where the target field type is located, and the process of determining the target field type and the length of the field type is executed as the mapping result.
[0132] In one embodiment, when the processor executes the computer program to implement the step of updating the target field type according to the field type in the database where the target field type resides, it specifically implements the following steps:
[0133] Determine whether the maximum length supported by the field type in the database containing the target field type exceeds the length of the field type; if the maximum length supported by the field type in the database containing the target field type exceeds the length of the field type, replace the target field type with the field type in the database containing the target field type that has the smallest length difference; if the maximum length supported by the field type in the database containing the target field type does not exceed the length of the field type, replace the target field type with the field type that each database provides by default for storing massive amounts of string data.
[0134] The storage medium can be any computer-readable storage medium capable of storing program code, such as a USB flash drive, portable hard drive, read-only memory (ROM), magnetic disk, or optical disk.
[0135] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0136] In the several embodiments provided by this invention, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For example, the division of each unit is merely a logical functional division, and there may be other division methods in actual implementation. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed.
[0137] The steps in the method of this invention can be adjusted, merged, or reduced in order according to actual needs. The units in the device of this invention can be merged, divided, or reduced according to actual needs. Furthermore, the functional units in the various embodiments of this invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0138] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, a terminal, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention.
[0139] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and these modifications or substitutions should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A string field type mapping method, characterized in that, include: Obtain the connection information between the source and target databases, as well as the tables that need to be mapped, to obtain the database connection information and tables; Based on the database connection information and the table, obtain the relevant character set to get the candidate set; Determine a list of fields of type string in the candidate set to obtain the fields to be mapped; Perform string mapping on the field to be mapped to obtain the mapping result; Send the mapping result to the terminal; The process of obtaining the connection information between the source and target databases, as well as the tables to be mapped, to obtain the database connection information and tables includes: Obtain the connection information of the source and target databases for which field mapping is required, as well as the tables in the source database that need to be mapped, in order to obtain the database connection information and tables; The process of performing string mapping on the field to be mapped to obtain the mapping result includes: Determine whether there are Chinese characters in the field to be mapped; If the field to be mapped contains Chinese characters, determine the number of bytes containing the Chinese characters to obtain the length of the field type; Get the type of the target field; Determine whether the maximum length supported by the target field type exceeds the length of the field type; If the maximum length supported by the target field type exceeds the length of the field type, then the target field type and the length of the field type are determined as the mapping result. After determining whether the maximum length supported by the target field type exceeds the length of the field type, the method further includes: If the maximum length supported by the target field type does not exceed the length of the field type, then the target field type is updated according to the field type in the database where the target field type is located, and the process of determining the target field type and the length of the field type is executed as the mapping result. The step of updating the target field type according to the field type in the database where the target field type is located includes: Determine whether the maximum length supported by the field type in the database containing the target field type exceeds the length of the field type. If the maximum length supported by the field type in the database where the target field type is located exceeds the length of the field type, then the target field type will be replaced by the field type with the smallest length difference in the database where the target field type is located. If the maximum length supported by the field type in the database containing the target field type does not exceed the length of the field type, then the target field type will be replaced with a field type provided by default in each database for storing massive amounts of string data.
2. The string field type mapping method according to claim 1, characterized in that, The step of obtaining relevant character sets based on database connection information and tables to obtain a candidate set includes: Connect the source database and the target database according to the database connection information, and obtain the character set of the source database, the character set of the target database, the character set of the table, the character set of each field of the table, and the field list of the table according to the table to obtain the candidate set.
3. The string field type mapping method according to claim 1, characterized in that, After determining whether a Chinese character exists in the field to be mapped, the method further includes: If there are no Chinese characters in the field to be mapped, the number of bytes occupied by English characters is determined to obtain the length of the field type, and the process of obtaining the target field type is executed.
4. A string field type mapping device, characterized in that, The string field type mapping method according to any one of claims 1 to 3 includes: The acquisition unit is used to configure the connection information of the source database and the target database, as well as the tables that need to be mapped, in order to obtain the database connection information and the tables. The character set acquisition unit is used to obtain relevant character sets based on database connection information and tables to obtain a candidate set; The field acquisition unit is used to determine a list of fields of type string in the candidate set to obtain the fields to be mapped; The mapping unit is used to perform string mapping on the field to be mapped in order to obtain the mapping result; A sending unit is used to send the mapping result to the terminal.
5. A computer device, characterized in that, The computer device includes a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the method as described in any one of claims 1 to 3.
6. A storage medium, characterized in that, The storage medium stores a computer program that, when executed by a processor, can implement the method as described in any one of claims 1 to 3.
Citation Information
Patent Citations
Messy code processing method and device and storage medium
CN115080535A