Automatic database mapping method and device based on structural body serialization and deserialization

By defining the serialization and deserialization operators of data structures in C++ and combining template programming technology, automatic mapping of database query structures is achieved, solving the complexity of database integration development caused by the lack of reflection mechanism in C++, and improving development efficiency and code reusability.

CN120045600APending Publication Date: 2025-05-27THE 705TH RES INST OF CHINA SHIPBUILDING IND CORP
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411957835.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-30
Publication Date
2025-05-27

AI Technical Summary

Technical Problem

Due to the lack of reflection mechanism in C++, the process of splicing of SQL statements and assignment of query results in database integration development needs to be manually written, which is cumbersome and error-prone, and it is impossible to achieve general adaptation to different database tables and structure fields, resulting in poor reusability and poor scalability of the code.

Method used

By defining the serialization and deserialization operators of data structure types in the C++ locale environment, serialized overload functions and deserialized overload functions are generated, and query template functions are defined in combination with template programming technology to realize automatic mapping of database query structures.

Benefits of technology

It realizes the mapping of automated database statement synthesis and query results, improves development efficiency, ensures the reliability and reusability of the code, and improves the scope of application of C++.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120045600A_ABST
    Figure CN120045600A_ABST
Patent Text Reader

Abstract

The invention provides an automatic database mapping method and device based on structural body serialization and deserialization, equipment and a medium, and the method comprises the steps: firstly, in a C + + language environment, defining a serialization operator and a deserialization operator of a data structural body type; and generating a serialized heavy-load function and a deserialized heavy-load function. Then, on the basis of the serialized overloading function and the deserialized overloading function, defining a function of the query template through a template programming technology, and generating a query template function; and finally, based on the query template function, performing splicing query on the metadata of the query structural body to generate a database query result, and performing assignment of a structural body field according to the database query result to realize automatic mapping of the database query structural body. According to the embodiment of the invention, synthesis of automatic database statements and mapping of query results are realized, meanwhile, reliable reusability of codes is ensured, and the application range of C + + is expanded.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of database applications, and in particular, to a database automatic mapping method, device, equipment, and medium based on structure serialization and deserialization. Background Art

[0002] At present, the reflection function in programming languages can check, access, and modify type information at runtime, providing capabilities such as type recognition, field access, method invocation, and type conversion. These features have been widely used in languages such as Java and C#, greatly improving the flexibility and maintainability of code. However, due to design and performance considerations, the C++ language has not provided a native reflection mechanism so far, which makes it impossible to dynamically obtain the field information of a structure or class in C++. As a result, in the integrated development of a database, the concatenation of SQL statements and the assignment process of query results need to be manually written, which is cumbersome and error-prone, and is also not conducive to code reuse and maintenance.

[0003] In the prior art, this problem is generally solved by manually defining SQL statements and assignment statements. Although the basic functions can be achieved, these methods lack automation, resulting in low development efficiency and difficult maintenance due to errors in manually written code. In addition, most of the prior art relies on hard-coding methods and cannot achieve general adaptation to different database tables and structure fields, resulting in poor code reusability and scalability.

[0004] Therefore, one or more methods are needed to solve the above problems.

[0005] It should be noted that the information disclosed in the above background art section is only used to enhance the understanding of the background of the present disclosure, and thus may include information that does not constitute the prior art known to those of ordinary skill in the art. Summary of the Invention

[0006] Embodiments of the present invention provide a database automatic mapping method, device, equipment, and medium based on structure serialization and deserialization, thereby at least to some extent overcoming one or more problems caused by the limitations and defects of related technologies.

[0007] According to one aspect of the present disclosure, a database automatic mapping method based on structure serialization and deserialization is provided, including:

[0008] According to the C++ language environment, by defining the serialization operator of the data structure type, a serialization overloaded function is generated;

[0009] According to the C++ language environment, by defining the deserialization operator of the data structure type, a deserialization overloaded function is generated;

[0010] According to the serialization overloading function and the deserialization overloading function, the function of the query template is defined through template programming technology to generate a query template function;

[0011] According to the query template function, the metadata of the query structure is spliced and queried to generate a database query result, and the fields of the structure are assigned values based on the database query result to realize the automatic mapping of the database query structure.

[0012] In an exemplary embodiment of the present disclosure, the definition of the serialization operator for the data structure type in the programming language includes:

[0013] Based on the C++ language environment, the metadata of the data structure is recorded through serialization technology to generate metadata information;

[0014] Based on the metadata information, the serialization operator for the data structure type in the programming language is defined to generate a serialization overloading function.

[0015] In an exemplary embodiment of the present disclosure, the definition of the deserialization operator for the basic data type includes:

[0016] Based on the C++ language environment, the given string is parsed through deserialization technology to generate parsed data information;

[0017] Based on the parsed data information, the deserialization operator for the data structure type in the programming language is defined to generate a deserialization overloading function.

[0018] In an exemplary embodiment of the present disclosure, the definition of the function of the query template through template programming technology includes:

[0019] Based on the serialization overloading function, the serialization definition of the query structure in the database is performed through template programming technology to generate serialization parameters;

[0020] Based on the deserialization overloading function, the deserialization definition of the query structure in the database is performed through template programming technology to generate deserialization parameters;

[0021] Based on the sub-variable quantity parameter of the database, the field quantity of the query structure in the database is defined to generate a field quantity parameter;

[0022] Based on the sub-variable order parameter of the database, the field order of the query structure in the database is defined to generate a field order parameter;

[0023] Generate a library table query structure by integrating the serialization parameters, deserialization parameters, field quantity parameters, and field order parameters.

[0024] In an exemplary embodiment of the present disclosure, define functions of a query template through template programming technology, including:

[0025] Based on the field quantity parameters and field order parameters, obtain query conditions of a database query instruction through the serialization parameters, and complete the construction of a search function;

[0026] Deserialize a query result into a given type structure through the deserialization parameters, and complete the construction of an assignment function;

[0027] Integrate the search function and the assignment function to generate a query template function.

[0028] In an exemplary embodiment of the present disclosure, perform a concatenated query on metadata of a query structure, including:

[0029] Based on a preset query structure type, obtain metadata of a query structure through the query template function to generate query structure metadata;

[0030] Based on the query structure metadata, generate a query statement by concatenating structured query language statements;

[0031] Based on the query statement, query a structure in a database to generate a database query result.

[0032] In an exemplary embodiment of the present disclosure, perform assignment of structure fields based on the database query result, including:

[0033] Based on the database query result, perform deserialization assignment on a queried data stream to generate a query structure sub-variable;

[0034] Generate a dynamic array list by storing the query structure sub-variables in a list;

[0035] In one aspect of the present disclosure, provide a database automatic mapping device based on structure serialization and deserialization, including:

[0036] A serialization overloaded function construction module, configured to define a serialization operator of a data structure type in a C++ language environment to generate a serialization overloaded function;

[0037] A deserialization overloaded function construction module, configured to define a deserialization operator of a data structure type in a C++ language environment to generate a deserialization overloaded function;

[0038] A query template function construction module, which is used to define the functions of a query template through template programming technology according to the serialization overloaded function and the deserialization overloaded function, and generate a query template function;

[0039] A database execution module, which is used to generate a database query result by splicing and querying the metadata of a query structure according to the query template function, and assign values to the structure fields based on the database query result, so as to realize the automatic mapping of the database query structure.

[0040] In one aspect of the present disclosure, an electronic device is provided, including:

[0041] A processor; and

[0042] A memory, on which computer-readable instructions are stored, and when the computer-readable instructions are executed by the processor, the method according to any one of the above is implemented.

[0043] In one aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the method according to any one of the above is implemented.

[0045] The beneficial effects brought by the present invention are as follows:

[0046] As can be seen from the above solution, the embodiments of the present invention provide a method for automatic mapping of a database based on structure serialization and deserialization. First, in the C++ language environment, by defining the serialization operator and deserialization operator of the data structure type, a serialization overloaded function and a deserialization overloaded function are generated. Then, based on the serialization overloaded function and the deserialization overloaded function, the functions of the query template are defined through template programming technology to generate a query template function. Finally, based on the query template function, a database query result is generated by splicing and querying the metadata of the query structure, and the structure fields are assigned values according to the database query result, so as to realize the automatic mapping of the database query structure. Thus, the embodiments of the present disclosure utilize template programming technology, structure serialization and deserialization technology to provide a solution for automatic SQL statement synthesis and automatic filling and assignment of query results for a DM database query structure oriented to the C++ programming language. It realizes the synthesis of automatic database statements and the mapping of query results, while ensuring the reliable reuse of code and improving the applicable range of C++.

[0047] It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and cannot limit the present disclosure.

[0048] The technical solutions of the present disclosure will be further described in detail below with reference to the accompanying drawings and embodiments. Description of the Drawings

[0049] Figure 1 It is a flowchart of an automatic database mapping method based on structure serialization and deserialization according to an embodiment of the method of the present disclosure;

[0050] Figure 2 It is a block diagram of an automatic database mapping device based on structure serialization and deserialization according to an embodiment of the method of the present disclosure;

[0051] Figure 3 It is a block diagram of an electronic device according to an embodiment of the method of the present disclosure. Detailed Embodiments

[0052] To make the objectives, technical solutions, and advantages of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Apparently, the described embodiments are some but not all of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.

[0053]

Glossary Explanation

[0054] SQL, Structured Query Language, is a standard programming language for managing relational databases. Its main functions are to query, insert, update, and delete data in the database, and it can also be used to create, modify the database structure, and control the access rights to the database.

[0055] The C++ programming language is a general-purpose and efficient programming language developed by Bjarne Stroustrup in the early 1980s. It is developed on the basis of the C language and incorporates features of object-oriented programming (OOP).

[0056] The template<class AR>AR& serialize(AR& ar){} function is a way of writing a template function widely used in the serialization framework in C++. It enables different types of data objects (such as instances of classes) to save and read data with different types of streams (such as output streams, input streams, or other data formats).

[0057] Stringstream is a standard library class in C++ and belongs to <sstream>Header file for handling string streams. It can write data to a string or read data from a string.

[0058] In an embodiment of the present disclosure, a database automatic mapping method based on structure serialization and deserialization is first provided; referring to Figure 1 as shown, the database automatic mapping method based on structure serialization and deserialization may include the following steps:

[0059] Step S110, according to the C++ language environment, generate a serialization overloaded function by defining the serialization operator for the data structure type;

[0060] Step S120, according to the C++ language environment, generate a deserialization overloaded function by defining the deserialization operator for the data structure type;

[0061] Step S130, according to the serialization overloaded function and the deserialization overloaded function, define the function of the query template through template programming technology to generate a query template function;

[0062] Step S140, according to the query template function, generate a database query result by concatenating and querying the metadata of the query structure, and assign values to the structure fields based on the database query result to achieve automatic mapping of the database query structure.

[0063] Next, a database automatic mapping method based on structure serialization and deserialization in an embodiment of the present disclosure will be further described.

[0064] In step S110, according to the C++ language environment, a serialization overloaded function can be generated by defining the serialization operator for the data structure type.

[0065] In some optional embodiments of this example, by defining a serialization function, the serialization of common basic data structure types in the C++11 programming language is implemented in the function. The purpose of the definition is to add a sequence overloaded function for defining the serialization operator for all common data types. The type and name information of the variables will be recorded during the serialization implementation, and these metadata information play a role of value indexing in the SQL statement synthesis and query result assignment processes.

[0066] Specifically, first, serialization functions can be defined in the buffer class for common basic data types (such as uint32_t, int32_t, uint64_t, int64_t, float, double, etc.). Each data type will have a corresponding overloaded serialization function that implements writing the data to the output stream of the buffer class. The serialization function not only is responsible for converting the data into a suitable storage format but also records the type and name information of each field, which is crucial when synthesizing SQL statements and mapping query results.

[0067] Preferably, on the basis of implementing the serialization of basic data types, the serialization function of the buffer class can be further extended to support more complex data structures, such as container types like std::list, std::map, arrays, etc. For these container types, it is necessary to traverse the elements therein and serialize them separately, and the serialization of each element follows a process similar to that of basic data types. In addition, to support the serialization of structures, a template serialization function can be added to the buffer class to handle the sequential serialization of structure members to ensure that complex types can be stored and restored as needed.

[0068] In addition, for the convenience of debugging and output, the buffer class also provides a function to convert the format of the serialized data, which can make the results clearer and easier to read. Also, to support readability and formatting, the buffer class also supports adding indentation characters to the output, making the generated serialized data structure clearer.

[0069] In step S120, according to the C++ language environment, overloaded deserialization functions can be generated by defining the deserialization operator for the data structure type.

[0070] In some alternative embodiments of this example, overloaded deserialization functions for common data structure types in the C++11 standard are defined to support the parsing of a given string and map and assign the parsed data information to the query result fields, providing the underlying indexing and positioning assignment functions for automatically mapping and assigning the query results required later.

[0071] In a specific example, the parsing class parses the data from the given string and deserializes it into a structure or other data types. When the constructor accepts a string (query result) and an integer (input encoding type) as input parameters. Inside the parsing class, multiple private members are maintained, such as m_sName (used to store the structure name), m_oPath (stores the path information for locating fields), m_sErrMsg (error message), m_oJsonValue (used to store the JSON parsing result), etc. By initializing these members, the parsing class can effectively handle error handling and path parsing problems during the deserialization process.

[0072] Meanwhile, in order to deserialize the query results into the basic data types in the structure, the parsing class provides a series of overloaded deserialization operators. Each basic type (such as uint32_t, int32_t, uint64_t, int64_t, float, double, etc.) requires a corresponding deserialization overloaded function. For example, the data in the string is parsed to assign values to the corresponding fields, and possible encoding or type conversion errors are handled. For each data type, the deserialization function extracts the corresponding value and maps it to the member variables of the structure. In addition, the mapping between the field names in the query results and the structure fields needs to be considered to ensure that the data can be correctly assigned to the corresponding positions in the structure. Error messages and debugging information are recorded in m_sErrMsg to help locate problems in deserialization.

[0073] Preferably, on the basis of implementing the deserialization of basic data types, the parsing class also needs to support the deserialization of more complex data types (such as std::list, std::map, std::vector, etc.). For container types, it is also necessary to traverse each element in the container and deserialize each element into the corresponding data type. In particular, for std::map, it is necessary to deserialize each key-value pair and ensure that the types of the key and value are consistent with the types of the target structure fields.

[0074] Through the above definitions of serialization and deserialization of common data structure types, the field names and field type information in the C++ structure can be extended, enabling external functions to obtain this information.

[0075] In step S130, the query template function can be defined by using template programming technology according to the serialization overloaded function and the deserialization overloaded function to generate the query template function.

[0076] In some alternative embodiments of this example, it is also necessary to define the serialization and deserialization functions of a specific library table query structure. And it is necessary to ensure that the number and order of the added fields in the database library table query structure correspond one by one to the sub-variables in the database library table to be queried.

[0077] In a specific example, it is through template <classar>Implemented by the `AR& serialize(AR& ar){}` function. First, we define the name of the library table query structure, such as `stuct TrainxCateInfo`, which contains multiple fields, such as category ID (`CATE_ID`), category name (`CATE_NAME`), parent ID (`PARENT_ID`), category level (`CATE_LEVEL`), and addition time (`ADD_TIME`). In this structure, we use a template function named `serialize`, which supports serialization and deserialization operations on different types of data through templating.

[0078] Define the serialization of each field of the library table query structure through the `serialize` function to generate serialization parameters. And by calling the macro, each field is sent into the serializer `ar` for processing. Finally, the serializer returns the processed object to complete the deserialization definition and generate deserialization parameters. These fields include different types of data (such as integer type, string type), and the serializer will automatically convert them into appropriate formats according to the field types. In this way, general support for multiple types of fields is achieved, while also ensuring the simplicity and scalability of the code.

[0079] At the same time, the number and order of the added fields in the database library table query structure must correspond one-to-one with the sub-variables in the database library table to be queried. This means that we need to define the field number parameter and field order parameter in the database library table query structure according to the number information and order information of the sub-variables in the database library table to be queried. And changes in the field number and order during serialization may lead to deserialization failure. Therefore, when adding new fields, it is necessary to ensure that the order of the new fields is unified with the existing fields, and the expressions in the serialization function can correctly handle the new field types.

[0080] In some alternative embodiments of this example, the query template function can be divided into two parts, namely the search function and the assignment function. First, obtain the query conditions according to the field number parameter and field order parameter of the library table query structure. Then, using template programming techniques, execute an SQL query based on the serialization parameters according to the query conditions. If the query is successful, enter the processing stage of the query results; otherwise, record the error and return failure. In this way, the construction of the search function is completed.

[0081] When entering the processing stage of the query results, use template programming techniques to deserialize and assign the query results to a structure of a given type through the deserialization parameters, and at the same time update the returned record number (`record_number`). When the entire query process ends, the function closes the database handle and releases resources to complete the construction of the assignment function.

[0082] In step S140, according to the query template function, the metadata of the query structure can be concatenated and queried to generate a database query result, and the structure fields can be assigned based on the database query result to achieve automatic mapping of the database query structure.

[0083] In some alternative embodiments of this example, first, the SQL string array is initialized using the above-mentioned lookup function to make it all zeros. Then, a stringstream object is created to dynamically construct the SQL query statement. If the incoming table name is empty, the lookup function will record an error and return the query fields. If the table name is not empty, the types and names of all variables in the query structure are obtained to generate the query structure metadata. And the obtained query structure metadata is concatenated into the query part of the SQL statement through the reflection mechanism.

[0084] Next, the lookup function constructs the other parts of the SQL query according to the incoming conditions.

[0085] (1) If the condition parameter is not empty, it means that a conditional clause needs to be added, which is concatenated into the SQL statement to filter the query result.

[0086] (2) If a sorting parameter is passed in, a sorting clause will also be added to specify the sorting rule of the query result.

[0087] (3) The lookup function checks the limit parameter. If it is not empty, a limit clause will be concatenated to specify the range of records to be returned. If the limit is empty, the limit default value 0, 20 is used, indicating querying the first 20 records.

[0088] Finally, the generated query statement after concatenating all conditions will include parts such as the lookup statement, query conditions, sorting conditions, and limit conditions, ensuring that the query can be executed according to the specified conditions and the desired database query result can be obtained.

[0089] In some alternative embodiments of this example, according to the database query result, the query data stream is deserialized and assigned, and the sub-variables of the query structure obtained by the assignment are stored in a list to achieve automatic mapping of the database query structure.

[0090] In a specific example, first, the assignment function uses "scroll fetch" to obtain the next row of data of the database query result. If the operation of obtaining data fails, an error message is output and the error code is checked. When there is no more data available for obtaining, the flag is set to true at this time and the loop is exited. If the query is successful and data is returned, the query result is continued to be processed to prepare for the deserialization assignment operation. The key to this part is to capture and handle the situation where the database query fails to ensure that the program can correctly handle exceptions and end conditions when executing the query.

[0091] After the query successfully retrieves the data, the program constructs a string for deserialization and converts the query result into a string that conforms to the format required by the structure.

[0092] Finally, the program uses a parsing class to parse and deserialize it. During the parsing and deserialization process, for each line of data processed, the program increments a record number, indicating the number of successfully processed records. This ensures that all query results can be stored in a list in sequence.

[0093] Through the above technical solution, it can be realized that as long as a specific serialization and deserialization function is added to any structure, the common query template function can be called, the automatic combination of SQL statements and the automatic assignment of query results are completed, and the automatic mapping of the database query structure is realized.

[0094] It should be noted that although the steps of the method in the present disclosure are described in a specific order in the accompanying drawings, this does not require or imply that these steps must be executed in that specific order, or that all the steps shown must be executed to achieve the desired result. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step for execution, and / or one step may be decomposed into multiple steps for execution, etc.

[0095] In addition, in the present exemplary embodiment, a database automatic mapping device based on structure serialization and deserialization is also provided. Referring to Figure 2 As shown, the database automatic mapping device 200 based on structure serialization and deserialization may include: a serialization overloaded function construction module 210, a deserialization overloaded function construction module 220, a query template function construction module 230, and a database execution module 340. Among them:

[0096] The serialization overloaded function construction module 210 is used to define a serialization operator for the data structure type in a C++ language environment to generate a serialization overloaded function;

[0097] The deserialization overloaded function construction module 220 is used to define a deserialization operator for the data structure type in a C++ language environment to generate a deserialization overloaded function;

[0098] The query template function construction module 230 is used to define a query template function through template programming technology according to the serialization overloaded function and the deserialization overloaded function to generate a query template function;

[0099] The database execution module 340 is configured to generate a database query result by concatenating and querying the metadata of the query structure according to the query template function, and perform assignment of structure fields based on the database query result, so as to implement automatic mapping of the database query structure.

[0100] The database automatic mapping device based on structure serialization and deserialization in the embodiments of the present disclosure corresponds to the embodiments of the above-mentioned database automatic mapping method based on structure serialization and deserialization of the present disclosure. The relevant content can be referred to each other, and will not be elaborated here. The beneficial technical effects corresponding to the database automatic mapping device based on structure serialization and deserialization in the embodiments of the present disclosure can be seen in the corresponding beneficial technical effects in the above-mentioned corresponding exemplary method part, and will not be elaborated here.

[0101] It should be noted that although several modules or units of the database automatic mapping device 300 based on structure serialization and deserialization are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of the two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.

[0102] Next, refer to Figure 3 to describe the electronic device according to the embodiments of the present disclosure. The electronic device can be any one or both of the first device and the second device, or a stand-alone device independent of them. The stand-alone device can communicate with the first device and the second device to receive the input signals collected from them.

[0103] Figure 3 The block diagram of the electronic device according to the embodiments of the present disclosure is illustrated.

[0104] As Figure 3 shown, the electronic device includes one or more processors and a memory.

[0105] The processor can be a central processing unit (CPU) or other forms of processing units with data processing capabilities and / or instruction execution capabilities, and can control other components in the electronic device to perform desired functions.

[0106] The memory can store one or more computer program products. The memory can include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory can include, for example, random access memory (RAM) and / or cache memory, etc. The non-volatile memory can include, for example, read-only memory (ROM), hard disk, flash memory, etc. One or more computer program products can be stored on the computer-readable storage media, and the processor can run the computer program products to implement the methods of the various embodiments of the present disclosure described above and / or other desired functions.

[0107] In one example, the electronic device may further include: an input device and an output device, and these components are interconnected through a bus system and / or other forms of connection mechanisms (not shown).

[0108] In addition, the input device may further include, for example, a keyboard, a mouse, and so on.

[0109] The output device can output various information to the outside, including the determined distance information, direction information, etc. The output device can include, for example, a display, a speaker, a printer, and a communication network and its connected remote output devices, and so on.

[0110] Of course, for simplicity, Figure 3 only some of the components related to the present disclosure in the electronic device are shown, and components such as a bus, an input / output interface, etc. are omitted. In addition, according to specific application scenarios, the electronic device may further include any other appropriate components.

[0111] In addition to the above methods and devices, the embodiments of the present disclosure may also be a computer program product, which includes computer program instructions. When the computer program instructions are run by the processor, the processor is caused to execute the steps in the methods according to the various embodiments of the present disclosure described in the above part of this specification.

[0112] The computer program product can be written in any combination of one or more programming languages for programming code to perform the operations of the embodiments of the present disclosure. The programming languages include object-oriented programming languages, such as Java, C++, etc., and also include conventional procedural programming languages, such as the "C" language or similar programming languages. The program code can be executed completely on the user computing device, partially on the user device, executed as an independent software package, partially on the user computing device and partially on a remote computing device, or completely executed on a remote computing device or server.

[0113] In addition, an embodiment of the present disclosure may also be a computer-readable storage medium storing computer program instructions that, when executed by a processor, cause the processor to perform the steps of the methods according to various embodiments of the present disclosure described in the foregoing part of this specification.

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

[0115] The above are the preferred embodiments of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present invention, several improvements and modifications can be made, and these improvements and modifications should also be regarded as the protection scope of the present invention.< / classar> < / sstream>

Claims

1. A database automatic mapping method based on structure serialization and deserialization, characterized in that: include: According to the C++ language environment, a serialization overload function is generated by defining the serialization operator of the data structure type; According to the C++ language environment, the deserialization overload function is generated by defining the deserialization operator of the data structure type; According to the serialization overload function and the deserialization overload function, the function of the query template is defined by template programming technology to generate a query template function; According to the query template function, by performing a concatenation query on the metadata of the query structure, a database query result is generated, and the structure fields are assigned values ​​based on the database query result, thereby realizing automatic mapping of the database query structure.

2. The method according to claim 1, characterized in that By defining serialization operators for data structure types in programming languages, including: Based on the C++ language environment, the metadata of the data structure is recorded through serialization technology to generate metadata information; Based on the metadata information, a serialization overload function is generated by defining a serialization operator of a data structure type in a programming language.

3. The method according to claim 1, characterized in that By defining deserialization operators for basic data types, including: Based on the C++ language environment, the given string is parsed through deserialization technology to generate parsed data information; Based on the parsed data information, a deserialization overload function is generated by defining a deserialization operator of a data structure type in a programming language.

4. The method according to claim 1, characterized in that: The functions of the query template are defined through template programming technology, including: Based on the serialization overload function, the query structure in the database is serialized and defined through template programming technology to generate serialization parameters; Based on the deserialization overload function, the query structure in the database is deserialized and defined through template programming technology to generate deserialization parameters; Based on the sub-variable quantity parameter of the database, the field quantity parameter is generated by defining the field quantity of the query structure in the database; Based on the sub-variable sequence parameters of the database, the field sequence parameters are generated by defining the field sequence of the query structure in the database; By integrating the serialization parameters, deserialization parameters, field quantity parameters, and field order parameters, a library table query structure is generated.

5. The method according to claim 4, characterized in that The functions of the query template are defined through template programming technology, including: Based on the field quantity parameter and the field order parameter, the query condition of the database query instruction is obtained through the serialization parameter to complete the construction of the search function; Deserialize the query result into a given type structure through the deserialization parameter to complete the construction of the assignment function; The search function and the assignment function are integrated to generate a query template function.

6. The method according to claim 1, characterized in that The query is performed by concatenating the metadata of the query structure, including: Based on the preset query structure type, the metadata of the query structure is acquired through the query template function to generate query structure metadata; Based on the query structure metadata, generating a query statement by concatenating structured query language statements; Based on the query statement, a database query result is generated by querying the structure in the database.

7. The method according to claim 6, characterized in that Assigning values ​​to structure fields based on the database query result includes: Based on the database query result, a query structure sub-variable is generated by deserializing and assigning a value to the queried data stream; Generate a dynamic array list by storing the query structure sub-variables in a list; Based on the dynamic array list, automatic mapping of the database query structure is achieved.

8. A database automatic mapping device based on structure serialization and deserialization, characterized in that: include: The serialization overload function building module is used to generate serialization overload functions by defining the serialization operator of the data structure type in the C++ language environment; The deserialization overload function building module is used to generate the deserialization overload function by defining the deserialization operator of the data structure type in the C++ language environment; A query template function building module is used to define the function of the query template through template programming technology according to the serialization overload function and the deserialization overload function, and generate a query template function; The database execution module is used to generate database query results by performing splicing queries on the metadata of the query structure according to the query template function, and to assign values ​​to the structure fields based on the database query results to achieve automatic mapping of the database query structure.

9. An electronic device, characterized in that: include: a memory for storing a computer program product; A processor is used to execute the computer program product stored in the memory, and when the computer program product is executed, it implements the method described in any one of claims 1 to 7.

10. A computer-readable storage medium having computer program instructions stored thereon, characterized in that: When the computer program instructions are executed by a processor, the method described in any one of claims 1 to 7 is implemented.

Citation Information

Cited By

  • Message data serialization packaging and analysis method supporting interface protocol verification

    CN121691508A