Data reading method and device, electronic equipment and storage medium
Patent Information
- Application Number
- CN202011138384.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-22
- Publication Date
- 2026-10-30
- Estimated Expiration
- 2040-10-22
AI Technical Summary
[0004]在上述过程中,一旦业务需要查询其他的数据项,在修改查询的功能逻辑时,需要整体修改DAO工具所编写的脚本程序,然后重新基于修改后的脚本程序再生成一次C++代码,导致C++代码的扩展性较差、数据读取效率低且修改成本高
[0016]本申请实施例提供的技术方案带来的有益效果至少包括:
Smart Images

Figure CN114385723B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a data reading method, apparatus, electronic device, and storage medium. Background Technology
[0002] With the development of computer technology, when developers are doing their work, they often need to call data items stored in the database from the program code (such as C++ code). They usually use DAO (Data Access Object) tools to access these data items from the database.
[0003] For general-purpose DAO tools, it is usually necessary to first establish a mapping relationship between the attributes of the structure in C++ and the fields of the database table (referring to the data table in the database). At this time, it is necessary to write complex C++ code through the DAO tool, and then read the data items stored in the corresponding fields of the database table based on the written C++ code.
[0004] In the above process, if the business needs to query other data items, when modifying the query function logic, the script program written by the DAO tool needs to be modified as a whole, and then the C++ code needs to be regenerated based on the modified script program. This results in poor extensibility of the C++ code, low data reading efficiency and high modification cost. Summary of the Invention
[0005] This application provides a data reading method, apparatus, electronic device, and storage medium, which can simplify the cumbersome data reading process and improve data reading efficiency. The technical solution is as follows: On the one hand, a data reading method is provided, which includes: Get the target table name of the data table containing the data item to be read; Based on the target table name, obtain the mapping information between the data table and the structure of the target program; Based on the mapping information, a mapping relationship is established between the data table and the structure; Based on the mapping relationship, the data item to be read is imported into the target program.
[0006] On the one hand, a data reading device is provided, the device comprising: The first acquisition module is used to obtain the target table name of the data table where the data item to be read is located; The second acquisition module is used to acquire the mapping information between the data table and the structure of the target program based on the target table name; A module is established to establish a mapping relationship between the data table and the structure based on the mapping information; The import module is used to import the data item to be read into the target program based on the mapping relationship.
[0007] In some embodiments, the mapping information includes the source file, header file, and common header file of the structure. The source file is used to define functions for constructing the mapping of at least one field in the structure. The header file is used to declare the data format of the structure. The common header file is used to define global initialization functions.
[0008] In some embodiments, the establishment module is used for: When initializing the target program, the global initialization function of the public header file is called to establish the mapping relationship.
[0009] In some embodiments, the second acquisition module includes: An acquisition unit is configured to acquire at least one offset between at least one field of the structure and the starting address of the structure; A creation unit is used to create a mapping table between the target table name and the at least one field based on the at least one offset; A determining unit is used to determine the mapping table as the mapping information.
[0010] In some embodiments, the creation unit is used for: For any field, create a target triplet based on the field name, field type, and offset between the field and the starting address; The target table name is used as the key name, and the target triplet is used as the key value. The key-value pairs formed by the key name and the key value are stored in the mapping table.
[0011] In some embodiments, the import module is used for: According to the structured query statement, the data item to be read is obtained from the data table; Based on the mapping relationship, determine the target storage location of the data item to be read in the structure; The data item to be read is stored in the target storage location.
[0012] In some embodiments, the apparatus further includes: The configuration module is used to set the field name of the first field of the structure to the target table name when the structure is created.
[0013] On one hand, an electronic device is provided, comprising one or more processors and one or more memories, wherein at least one piece of program code is stored in the one or more memories, the at least one piece of program code being loaded and executed by the one or more processors to implement a data reading method as described in any of the possible implementations above.
[0014] On the one hand, a storage medium is provided that stores at least one piece of program code, which is loaded and executed by a processor to implement a data reading method as described in any of the possible implementations above.
[0015] On one hand, a computer program product or computer program is provided, the computer program product or computer program comprising one or more lines of program code stored in a computer-readable storage medium. One or more processors of an electronic device are capable of reading the one or more lines of program code from the computer-readable storage medium, and the one or more processors execute the one or more lines of program code, enabling the electronic device to perform the data reading method of any of the above possible embodiments.
[0016] The beneficial effects of the technical solutions provided in this application include at least the following: By using the target table name corresponding to the data item to be read, a mapping relationship between the data table and the structure of the target program is automatically constructed. When running the target program, the data item to be read can be imported based on this mapping relationship. This means that when modifying the query function logic, the target program does not need to be modified as a whole, which improves the code extensibility of the target program, greatly reduces the modification cost of the data reading process, and thus improves the data reading efficiency. Attached Figure Description
[0017] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0018] Figure 1 This is a schematic diagram of the implementation environment of a data reading method provided in an embodiment of this application; Figure 2 This is a flowchart of a data reading method provided in an embodiment of this application; Figure 3 This is a flowchart of a data reading method provided in an embodiment of this application; Figure 4 This is a schematic diagram of the structure of a data reading device provided in an embodiment of this application; Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0019] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0020] In this application, the terms "first," "second," etc., are used to distinguish identical or similar items with essentially the same function. It should be understood that there is no logical or temporal dependency between "first," "second," and "nth," nor are there any restrictions on quantity or execution order.
[0021] In this application, the term "at least one" means one or more, and "multiple" means two or more, for example, multiple first positions means two or more first positions.
[0022] Before introducing the embodiments of this application, it is necessary to introduce some basic concepts in the field of cloud technology: Cloud technology refers to a hosting technology that unifies hardware, software, and network resources within a wide area network (WAN) or local area network (LAN) to achieve data computation, storage, processing, and sharing. It encompasses network technologies, information technologies, integration technologies, management platform technologies, and application technologies based on cloud computing business models. These technologies can form resource pools, allowing for on-demand, flexible, and convenient use. Cloud computing technology will become a crucial support in the cloud technology field. Backend services of technical network systems require substantial computing and storage resources, such as those for video websites, image websites, and various portal websites. With the rapid development and application of the internet industry, every item may have its own identification mark in the future, requiring transmission to backend systems for logical processing. Data at different levels will be processed separately, and various industry data will require robust system support, all of which can be achieved through cloud computing.
[0023] Cloud storage is a new concept that has been extended and developed from the concept of cloud computing. A distributed cloud storage system (hereinafter referred to as a storage system) refers to a storage system that uses cluster applications, grid technology and distributed storage file systems to bring together a large number of storage devices of various types in the network (storage devices are also called storage nodes) to work together through application software or application interfaces to provide data storage and business access functions to the outside world.
[0024] Database: Simply put, a database can be viewed as an electronic filing cabinet—a place to store electronic files, where users can perform operations such as adding, querying, updating, and deleting data. A "database" is a collection of data stored together in a certain way, capable of being shared by multiple users, with minimal redundancy, and independent of application programs.
[0025] A relational database is a database that uses a relational model to organize data. It stores data in rows and columns for user understanding. These rows and columns are called tables (also known as data tables or database tables), and a set of tables makes up a database. Users retrieve data from the database through queries, which are executable codes used to limit specific areas of the database. The relational model can be simply understood as a two-dimensional table model, and a relational database is a data organization composed of two-dimensional tables and the relationships between them. In short, a relational database is a database composed of multiple interconnected two-dimensional row-and-column tables. Currently, mainstream relational databases include Oracle, DB2, Microsoft SQL Server, Microsoft Access, and MySQL.
[0026] This application embodiment relates to the above-mentioned relational database. The relational database stores multiple data tables. Each record (i.e., each row) in the data table is called a tuple. Each field (i.e., each column) in the data table is called an attribute. The data item stored in each field is called the attribute value. The field name of each field (i.e., the column name of each column) is called the attribute name.
[0027] Data Table: A data table in a database is a unit for organizing structured data in the database. Data tables can be used to organize multi-dimensional data under the same logic.
[0028] Field: A table can include multiple fields, each representing a single dimension of data in the table. In a two-dimensional table, one field corresponds to one column of data.
[0029] Structured Query Language (SQL): A standard computer language used for relational database management and data manipulation. SQL is used to query, insert, update, and modify data in a database.
[0030] Application Programming Interface (API): refers to a set of predefined functions that provide applications and developers with the ability to access a set of routines based on certain software or hardware.
[0031] Data Access Object (DAO): A data access interface that provides the ability to access data from a storage platform (i.e., a database) in an abstract way.
[0032] Figure 1 This is a schematic diagram illustrating the implementation environment of a data reading method provided in an embodiment of this application. See also... Figure 1 The implementation environment includes a terminal 101 and a server 102, both of which are electronic devices.
[0033] Terminal 101 is used to run the target program. When writing the C++ code of the target program, technicians can use script tools to automatically import the database query result set into the C++ structure, that is, to realize the automatic import of the data items to be read.
[0034] Terminal 101 and server 102 can be connected directly or indirectly via wired or wireless communication, and this application does not impose any restrictions on this.
[0035] Server 102 is used to provide a storage platform to terminal 101. Optionally, server 102 can be a standalone device, an electronic device with a primary / backup structure, or a cloud database, distributed storage cluster, etc. This application embodiment does not specifically limit the type of server 102. In some embodiments, server 102 can be integrated with terminal 101 on the same physical machine.
[0036] Optionally, server 102 may be an independent physical server, a server cluster or distributed system consisting of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms.
[0037] Optionally, terminal 101 refers to one of a plurality of terminals, the device type of which includes at least one of the following: smartphone, tablet computer, e-book reader, MP3 (Moving Picture Experts Group Audio Layer III) player, MP4 (Moving Picture Experts Group Audio Layer IV) player, laptop computer, desktop computer, smart speaker, or smartwatch. For example, terminal 101 is a laptop computer, or other portable electronic device.
[0038] Those skilled in the art will understand that the number of terminals 101 described above can be more or less. For example, there may be only one terminal 101, or there may be dozens or hundreds of terminals 101, or even more. This application does not limit the number or type of terminals 101 in the embodiments.
[0039] Figure 2 This is a flowchart illustrating a data reading method provided in an embodiment of this application. See also... Figure 2 This embodiment is applied to an electronic device, and the embodiment includes: 201. The electronic device obtains the target table name of the data table containing the data item to be read.
[0040] Optionally, the electronic device runs on a Linux or Windows platform and supports C++98 or later compilers. The electronic device can be a desktop computer, laptop computer, tablet computer, or other electronic device.
[0041] It should be noted that the electronic device communicates with the server via a wired or wireless network. The server provides a data access interface based on a database, which stores the data table containing the data item to be read.
[0042] In some embodiments, the electronic device is equipped with a target program, which is a script program written in a scripting language. For example, when the scripting language is Python, the script program is a program that runs in the Python 3.0 compilation environment. In other embodiments, the target program is an application program written in other programming languages. For example, the other programming languages include JS (JavaScript, a lightweight, interpreted or just-in-time compiled high-level programming language with function priority), VBS (Visual Basic Script, VB scripting language), etc., or the other programming languages include computer programming languages that do not depend on scripting tools, such as C, C++, C#, etc. The embodiments of this application do not specifically limit the type of the target program.
[0043] In one example, an electronic device only needs to reference the `deserialize_helper.h` header file and compile and link the `deserialize_helper.cpp` source file to use the target program. Optionally, the target program runs in a Python 3 compilation environment. The target program sets the IP address (Internet Protocol Address) and communication port of the server providing the database. After the target program establishes a data connection with the server, the user can also provide the target program with the username and password required to access the server during the data connection establishment process, so that the server can perform authentication and verification. After successful verification, the server grants the target program the corresponding data access permissions.
[0044] In some embodiments, the user inputs the target database name of the database containing the data item to be read and the target table name of the data table in that database into the target program. Optionally, the user inputs the target database name and the target table name into the target program via a command line. In one example, the command line is . / gen_bo.py --table t_pay_list --db ia_exc_zwdb, where the parameter "t_pay_list" after "-table" is the target table name (taking the balance sheet as an example), the parameter "ia_exc_zwdb" after "-db" is the target database name (taking the zw database as an example), and "gen_bo.py" is the program name of the target program. After inputting the target database name and the target table name, the following step 202 is executed to automatically generate the structure definition code corresponding to the data table (that is, the mapping information in step 202 below).
[0045] 202. Based on the target table name, the electronic device obtains the mapping information between the data table and the structure of the target program.
[0046] In some embodiments, the mapping information includes the source file, header file, and common header file of the structure. The source file is used to define functions for constructing the mapping of at least one field in the structure. The header file is used to declare the data format of the structure. The common header file is used to define a global initialization function. The global initialization function is used to aggregate the construction functions defined in the source file.
[0047] It should be noted that when the target program generates multiple structures for multiple data tables (i.e., library tables), although one data table corresponds to one structure, only one common header file will be generated. That is to say, the structures of multiple data tables share the same common header file. Therefore, defining a global initialization function in the common header file can complete the construction of the mapping relationship between all data tables and all structures.
[0048] In some embodiments, the electronic device may first obtain at least one offset between at least one field of the structure and the starting address of the structure, then create a mapping table between the target table name and the at least one field based on the at least one offset, and finally determine the mapping table as the mapping information.
[0049] Alternatively, the electronic device can call a C++ macro function #define offset(type, member)(size_t)&(((type)) The offset corresponding to each field is obtained by using 0)->member). In one example, taking the user table (User table) as an example, the User table includes at least the following fields: user identifier (ID), username (Name), user gender (Sex), etc. Fields with different meanings can be set in different application scenarios. For example, a user balance field can be added in the payment scenario, and a user score field can be added in the examination scenario. This application embodiment does not specifically limit the number and meaning of each field.
[0050] In some embodiments, for any field, the electronic device creates a target triplet based on the field name, field type, and offset between the field and the starting address. The target table name is used as the key, and the target triplet as the value. The key-value pair consisting of the key name and value is stored in the mapping table. It should be noted that the starting address refers to the starting address of the structure, that is, the memory address of the first field (i.e., attribute) of the structure. In other words, since the storage unit in memory is a byte, and each byte has its own sequence number called its memory address, a structure occupies a contiguous storage space in memory (corresponding to a series of contiguous memory addresses). During storage, the fields (i.e., attributes) of the structure are arranged sequentially in this storage space. Therefore, the memory address of the first field is the same as the memory address of the entire structure.
[0051] In one example, the electronic device can build a mapping table based on C++'s native map (graph) structure. That is, after obtaining the target triple <field name, field type, address offset of corresponding attribute> for each field, the electronic device creates a mapping table with table name - <field name, field type, address offset of corresponding attribute> based on these target triples, and stores the mapping table in a map structure. The map structure is a data structure supported by the electronic device's native library, which stores data in key-value pairs. Building a mapping table based on the map structure means using the target table name (a string) as the key and the target triple <field name, field type, address offset of corresponding attribute> as the value, thereby storing the target table name and the target triples of each field to construct the above mapping information.
[0052] In the above process, a single target table name can correspond to multiple field information (i.e., target triples). In each field information, the field name can be bound to the address offset of the structure attribute. By combining the attribute address offset and the structure pointer address passed when calling the API function, the storage address of all attributes in the structure can be located, that is, the storage address of all fields in the structure can be located, thus facilitating the automatic construction of the mapping relationship between the data table and the structure.
[0053] 203. Based on this mapping information, the electronic device establishes a mapping relationship between the data table and the structure.
[0054] In some embodiments, the electronic device can call the global initialization function of the public header file to establish the mapping relationship when initializing the target program. This mapping relationship refers to the association between a data table in a remote database and a structure created in the local target program. For example, if multiple User tables are stored and maintained in a cloud database, and the local target program needs to access the User table of the target user, a structure is created locally and associated with the User table of the target user in the cloud database. This establishes a mapping relationship between the structure and the User table of the target user. Only after establishing this mapping relationship can the target program successfully read the various data items stored in the cloud database. In one example, the target table name is set to the type name of the structure, and the field names of each field in the data table are set to the field names of each field in the structure, making the data table and the structure correspond to each other.
[0055] Optionally, if the data items to be read are stored in multiple data tables, the electronic device can obtain a mapping information for each data table, and the mapping information of each data table shares the same common header file. In this way, the mapping relationship for each data table can be established by calling the common header file only once during initialization, thereby saving the time of establishing the mapping relationship.
[0056] In some embodiments, the electronic device may also add its own header file to the mapping information of each data table, and call the local initialization function in its respective header file during the initialization process, thereby establishing the mapping relationship between each data table and the corresponding structure. This application embodiment does not specifically limit the way the mapping relationship is established.
[0057] 204. Based on this mapping relationship, the electronic device imports the data item to be read into the target program.
[0058] In some embodiments, the electronic device can retrieve the data item to be read from the data table according to a structured query statement (SQL statement), determine the target storage location corresponding to the data item to be read in the structure according to the mapping relationship, and store the data item to be read in the target storage location. Optionally, the query SQL statement is directly embedded in the program code of the target program, so that the query SQL statement can be executed when the target program is run, and the data item to be read can be imported. Optionally, the query SQL statement can be input to the target program through the command line, so that the query SQL statement can be input in an external manner, and the data item to be read can be imported.
[0059] Optionally, since the target program can parse the target table name from the user's SQL query statement, but the pointer passed when calling the API function is a void pointer type. Unable to pass void The pointer is used to obtain the table name corresponding to the structure it points to. Therefore, when creating the structure, the electronic device can set the name of the first field of the structure to this table name; that is, set the first property of the structure to the string representing the table name.
[0060] In the above process, since the memory distribution order of C++ struct attributes is the same as the attribute definition order, the memory location of the table name string attribute is placed at the beginning of the memory space of each struct, and the storage address of the table name string attribute is the same as the starting address of the struct. Therefore, by using a null pointer passed when calling the API function, the first string (i.e., the table name string) in the struct's memory space can be directly read, thus obtaining the table name corresponding to the struct pointed to by that pointer. After obtaining the table name corresponding to the struct, if the table name matches the target table name specified in the query SQL statement, then that struct is used as the data structure to store the data items to be read subsequently.
[0061] Next, the electronic device retrieves the data items to be read from the server according to the query SQL statement. These data items can form a query result set (referred to as the query result set). The order of the query result values in the query result set is consistent with the order of the field names specified in the query SQL semantics. Therefore, by parsing the query SQL semantics, the field names to be obtained and their order are obtained. Based on the mapping relationship between field names and attribute addresses in the mapping table (i.e., mapping information), the query result values in the query result set can be filled into the corresponding attributes of the structure in order. In this way, when importing data items into the structure of the target program, automatic import can be achieved without the user having to do extra manual work, which greatly saves development costs.
[0062] In some embodiments, since the query result values (i.e., the data items to be read) in the query result set are all stored in string type, the electronic device can also convert the data items to be read into the actual attribute type indicated by the field type according to the mapping relationship from field to field type in the mapping table (the target triplet stores not only the field but also the field type), so as to achieve a more intelligent and accurate data import effect.
[0063] The method provided in this application automatically constructs a mapping relationship between the target table and the structure of the target program by using the target table name corresponding to the data item to be read. When running the target program, the data item to be read can be imported based on the mapping relationship, so that when modifying the query function logic, the target program does not need to be modified as a whole, which improves the code extensibility of the target program, greatly reduces the modification cost of the data reading process, and thus improves the data reading efficiency.
[0064] Furthermore, since the mapping relationship can be automatically constructed using only the target table name, it is equivalent to completing the construction of the mapping relationship without specifying complex library and table information. In addition, data can be read without passing in additional parameters when running the target program, which greatly simplifies the cumbersome data reading process. Moreover, in multi-person collaborative scenarios, it is convenient for technical personnel to review each other's program code, reducing the understanding cost of the target program's program code.
[0065] All of the above-mentioned optional technical solutions can be combined in any way to form optional embodiments of this disclosure, and will not be described in detail here.
[0066] Figure 3 This is a flowchart of a data reading method provided in an embodiment of this application. Please refer to it. Figure 3 This method is applied to electronic devices and includes the following steps: 301. The electronic device obtains the target table name of the data table containing the data item to be read.
[0067] Step 301 above is similar to step 201 above, and will not be described in detail here.
[0068] 302. An electronic device obtains at least one offset between at least one field of a structure of a target program and the starting address of that structure.
[0069] Alternatively, the electronic device can call a C++ macro function #define offset(type, member)(size_t)&(((type)) Use )0)->member) to get the offsets corresponding to each field.
[0070] In some embodiments, the electronic device may also call other macro functions to obtain the above offsets. This application embodiment does not specifically limit the method of obtaining each offset.
[0071] 303. The electronic device creates a mapping table between the target table name and the at least one field based on the at least one offset.
[0072] In some embodiments, for any field, the electronic device creates a target triplet based on the field name, field type, and offset between the field and the starting address, and stores the key-value pair consisting of the target table name as the key name and the target triplet as the key value in the mapping table.
[0073] In one example, the electronic device can build a mapping table based on the native map (graph) structure of C++. That is, after the electronic device obtains the target triple <field name, field type, address offset of the corresponding attribute> for each field, it creates a mapping table with table name-<field name, field type, address offset of the corresponding attribute> based on these target triples, and stores the mapping table in a map structure.
[0074] In the above process, a single target table name can correspond to multiple field information (i.e., target triples). In each field information, the field name can be bound to the address offset of the structure attribute. By combining the attribute address offset and the structure pointer address passed when calling the API function, the storage address of all attributes in the structure can be located, that is, the storage address of all fields in the structure can be located, thus facilitating the automatic construction of the mapping relationship between the data table and the structure.
[0075] 304. The electronic device determines the mapping table as the mapping information between the data table and the structure of the target program.
[0076] In steps 302-304 above, the electronic device obtains the mapping information between the data table and the structure of the target program based on the target table name. In some embodiments, in addition to storing the mapping table in a map structure, other data structures such as hash tables, bitmaps, and arrays can also be used to store the mapping table, thereby constructing mapping information with different data structures. This application embodiment does not impose specific limitations on the data structure of the mapping information.
[0077] Optionally, the mapping information includes the source file, header file, and public header file of the structure. The source file is used to define the function that constructs the mapping of at least one field in the structure. The header file is used to declare the data format of the structure. The public header file is used to define the global initialization function.
[0078] In some embodiments, the electronic device stores the above mapping table into the source file of the structure, thereby defining the function for constructing the mapping relationship of each field based on the mapping table.
[0079] 305. Based on the mapping information, the electronic device establishes a mapping relationship between the data table and the structure.
[0080] In some embodiments, the electronic device may call the global initialization function of the public header file to establish the mapping relationship when initializing the target program.
[0081] Optionally, if the data items to be read are stored in multiple data tables, the electronic device can obtain a mapping information for each data table, and the mapping information of each data table shares the same common header file. In this way, the mapping relationship for each data table can be established by calling the common header file only once during initialization, thereby saving the time of establishing the mapping relationship.
[0082] In some embodiments, the electronic device may also add its own header file to the mapping information of each data table, and call the local initialization function in its respective header file during the initialization process, thereby establishing the mapping relationship between each data table and the corresponding structure. This application embodiment does not specifically limit the way the mapping relationship is established.
[0083] 306. The electronic device retrieves the data item to be read from the data table based on the structured query statement.
[0084] In the above process, the electronic device retrieves the data items to be read as indicated by the query SQL statement from the server. These data items to be read can constitute a query result set (referred to as the query result set).
[0085] 307. The electronic device determines the target storage location of the data item to be read in the structure based on the mapping relationship.
[0086] In the above process, the electronic device obtains the field names and their order by parsing the SQL query semantics. Based on the mapping relationship between field names and attribute addresses in the mapping table (i.e., mapping information), the attribute address (i.e., target storage location) of each attribute in the structure can be determined.
[0087] 308. The electronic device stores the data item to be read into the target storage location.
[0088] In the above process, since the order of the query result values in the query result set is consistent with the order of the field names specified in the query SQL semantics, the field names to be obtained and their order are obtained by parsing the query SQL semantics. Based on the mapping relationship from field names to attribute addresses in the mapping table (i.e., mapping information), the query result values in the query result set can be filled into the corresponding attributes of the structure in order. In this way, when importing data items into the structure of the target program, the import can be automated without requiring users to do extra manual work, which greatly saves development costs.
[0089] In some embodiments, since the query result values (i.e., the data items to be read) in the query result set are all stored in string type, the electronic device can also convert the data items to be read into the actual attribute type indicated by the field type according to the mapping relationship from field to field type in the mapping table (the target triplet stores not only the field but also the field type), so as to achieve a more intelligent and accurate data import effect.
[0090] It should be noted that while the target program can parse the target table name from the user's SQL query statement, the pointer passed when calling the API function is a void pointer. Unable to pass void The pointer is used to obtain the table name corresponding to the structure pointed to by this pointer. In view of this, when the electronic device creates the structure, it can set the field name of the first field of the structure to the table name (i.e., the target table name), that is, set the first property of the structure to the table name string corresponding to the structure.
[0091] In the above process, since the memory distribution order of C++ struct attributes is the same as the attribute definition order, the memory location of the table name string attribute is placed at the beginning of the memory space of each struct, and the storage address of the table name string attribute is the same as the starting address of the struct. Therefore, by using a null pointer passed when calling the API function, the first string (i.e., the table name string) in the struct's memory space can be directly read, thus obtaining the table name corresponding to the struct pointed to by that pointer. After obtaining the table name corresponding to the struct, if the table name matches the target table name specified in the query SQL statement, then that struct is used as the data structure to store the data items to be read subsequently.
[0092] In steps 306-308 above, the electronic device imports the data item to be read into the target program based on the mapping relationship. In some embodiments, the electronic device may also import the data item to be read using other DAO script tools. This application embodiment does not specifically limit the method of importing the data item to be read.
[0093] In the above process, for any query SQL statement input by the user, after the server returns a query result set based on the query SQL statement, it can automatically import each data item to be read (equivalent to the query result value) into a C++ structure based on the query result set. Furthermore, the target program (e.g., a script tool) automatically constructs a logical mapping relationship between data table fields and offsets. This offset refers to the offset between the structure attribute and the starting address of the structure. This logical mapping relationship can solve the problem that C++ cannot locate specific attributes by attribute name or field name when it is not running. Then, by parsing the query SQL statement, it can fill each data item to be read in the query result set into the corresponding attribute of the structure. Thus, it can not only support full query scenarios, but also flexible non-full query scenarios, and greatly facilitate code review work.
[0094] In addition, no additional input parameters are required after querying the SQL code. It can automatically build mapping relationships with the help of the target program, making it easy to use and simple to pass in parameters. It is deeply decoupled from database queries and does not depend on any third-party library files. Users can easily customize personalized query schemes through query SQL statements, such as adding error alerts and logging, which has higher flexibility, applicability and portability.
[0095] In some exemplary scenarios, when changes in requirements lead to changes in the structure of a data table, such as adding or deleting fields, it is only necessary to call the target program to regenerate the structure definition files corresponding to the data table once. Other code logic does not need to be modified at all. The target program can automatically determine the build status under the current project folder and thus adapt the logic that needs to be modified (such as adding or deleting the mapping information of a certain attribute in the mapping table). This allows for the regeneration and replacement of the structure header file and source file, and adaptive modification of the common header file, making incremental changes very convenient.
[0096] The method provided in this application automatically constructs a mapping relationship between the target table and the structure of the target program by using the target table name corresponding to the data item to be read. When running the target program, the data item to be read can be imported based on the mapping relationship, so that when modifying the query function logic, the target program does not need to be modified as a whole, which improves the code extensibility of the target program, greatly reduces the modification cost of the data reading process, and thus improves the data reading efficiency.
[0097] All of the above-mentioned optional technical solutions can be combined in any way to form optional embodiments of this disclosure, and will not be described in detail here.
[0098] Figure 4 This is a schematic diagram of the structure of a data reading device provided in an embodiment of this application. Please refer to it. Figure 4 The device includes: The first acquisition module 401 is used to acquire the target table name of the data table where the data item to be read is located; The second acquisition module 402 is used to acquire the mapping information between the data table and the structure of the target program based on the target table name; Module 403 is established to establish a mapping relationship between the data table and the structure based on the mapping information. Import module 404 is used to import the data item to be read into the target program based on the mapping relationship.
[0099] The apparatus provided in this application automatically constructs a mapping relationship between the data table and the structure of the target program based on the target table name corresponding to the data item to be read. When running the target program, the data item to be read can be imported based on the mapping relationship, so that when modifying the query function logic, the target program does not need to be modified as a whole, which improves the code extensibility of the target program, greatly reduces the modification cost of the data reading process, and thus improves the data reading efficiency.
[0100] In some embodiments, the mapping information includes the source file, header file, and public header file of the structure. The source file is used to define functions for constructing the mapping of at least one field in the structure. The header file is used to declare the data format of the structure. The public header file is used to define global initialization functions.
[0101] In some embodiments, the establishment module 403 is used for: When initializing the target program, the global initialization function of the public header file is called to establish the mapping relationship.
[0102] In some embodiments, based on Figure 4 The device comprises, wherein the second acquisition module 402 includes: A retrieval unit is used to retrieve at least one offset between at least one field of the structure and the starting address of the structure; Create a unit for creating a mapping table between the target table name and the at least one field based on the at least one offset; The determining unit is used to determine the mapping table as the mapping information.
[0103] In some embodiments, the creation unit is used for: For any field, create a target triplet based on the field name, field type, and offset between the field and the starting address; The target table name is used as the key name, and the target triplet is used as the key value. The key-value pair consisting of the key name and the key value is stored in the mapping table.
[0104] In some embodiments, the import module 404 is used for: Based on the structured query statement, retrieve the data item to be read from the data table; Based on this mapping relationship, the target storage location of the data item to be read in the structure is determined; Store the data item to be read into the target storage location.
[0105] In some embodiments, based on Figure 4 The device comprises: The configuration module is used to set the name of the first field of the structure to the name of the target table when the structure is created.
[0106] All of the above-mentioned optional technical solutions can be combined in any way to form optional embodiments of this disclosure, and will not be described in detail here.
[0107] It should be noted that the data reading device provided in the above embodiments is only illustrated by the division of the above functional modules. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the electronic device can be divided into different functional modules to complete all or part of the functions described above. In addition, the data reading device and the data reading method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process can be found in the data reading method embodiments, which will not be repeated here.
[0108] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. In this embodiment, terminal 500 is used as an example for description. The device types of terminal 500 include: smartphones, tablets, MP3 players (Moving Picture Experts Group Audio Layer III), MP4 players (Moving Picture Experts Group Audio Layer IV), laptops, or desktop computers. Terminal 500 may also be referred to as user equipment, portable terminals, laptop terminals, desktop terminals, or other names.
[0109] Typically, terminal 500 includes a processor 501 and a memory 502.
[0110] Optionally, processor 501 includes one or more processing cores, such as a quad-core processor, an octa-core processor, etc. Optionally, processor 501 is implemented using at least one hardware form selected from DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). In some embodiments, processor 501 includes a main processor and a coprocessor. The main processor, also known as a CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, processor 501 integrates a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content required to be displayed on the screen. In some embodiments, processor 501 also includes an AI (Artificial Intelligence) processor, which is used to handle computational operations related to machine learning.
[0111] In some embodiments, memory 502 includes one or more computer-readable storage media, optionally non-transitory. Optionally, memory 502 also includes high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In some embodiments, the non-transitory computer-readable storage media in memory 502 is used to store at least one program code, which is executed by processor 501 to implement the data reading methods provided in the various embodiments of this application.
[0112] In some embodiments, the terminal 500 may also optionally include a peripheral device interface 503 and at least one peripheral device. The processor 501, memory 502, and peripheral device interface 503 can be connected via a bus or signal line. Each peripheral device can be connected to the peripheral device interface 503 via a bus, signal line, or circuit board. Specifically, the peripheral device includes at least one of the following: a radio frequency circuit 504, a display screen 505, a camera assembly 506, an audio circuit 507, and a power supply 509.
[0113] Peripheral device interface 503 can be used to connect at least one I / O (Input / Output) related peripheral device to processor 501 and memory 502. In some embodiments, processor 501, memory 502 and peripheral device interface 503 are integrated on the same chip or circuit board; in some other embodiments, any one or two of processor 501, memory 502 and peripheral device interface 503 are implemented on separate chips or circuit boards, which is not limited in this embodiment.
[0114] The radio frequency (RF) circuit 504 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The RF circuit 504 communicates with communication networks and other communication devices via electromagnetic signals. The RF circuit 504 converts electrical signals into electromagnetic signals for transmission, or converts received electromagnetic signals back into electrical signals. Optionally, the RF circuit 504 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, etc. Optionally, the RF circuit 504 communicates with other terminals via at least one wireless communication protocol. This wireless communication protocol includes, but is not limited to: metropolitan area networks (MANs), various generations of mobile communication networks (2G, 3G, 4G, and 5G), wireless local area networks (WLANs), and / or WiFi (Wireless Fidelity) networks. In some embodiments, the RF circuit 504 also includes circuitry related to NFC (Near Field Communication), which is not limited in this application.
[0115] Display screen 505 is used to display a UI (User Interface). Optionally, the UI includes graphics, text, icons, videos, and any combination thereof. When display screen 505 is a touch display screen, display screen 505 also has the ability to collect touch signals on or above the surface of display screen 505. The touch signals can be input to processor 501 for processing as control signals. Optionally, display screen 505 is also used to provide virtual buttons and / or virtual keyboards, also known as soft buttons and / or soft keyboards. In some embodiments, there is one display screen 505, which is set on the front panel of terminal 500; in other embodiments, there are at least two display screens 505, which are respectively set on different surfaces of terminal 500 or have a folded design; in still other embodiments, display screen 505 is a flexible display screen, which is set on the curved surface or folded surface of terminal 500. Furthermore, optionally, display screen 505 is set as a non-rectangular irregular shape, that is, an irregularly shaped screen. Optionally, the display screen 505 is made of materials such as LCD (Liquid Crystal Display) or OLED (Organic Light-Emitting Diode).
[0116] The camera assembly 506 is used to acquire images or videos. Optionally, the camera assembly 506 includes a front-facing camera and a rear-facing camera. Typically, the front-facing camera is located on the front panel of the terminal, and the rear-facing camera is located on the back of the terminal. In some embodiments, there are at least two rear-facing cameras, which are any one of a main camera, a depth-sensing camera, a wide-angle camera, and a telephoto camera, to achieve background blurring by fusion of the main camera and the depth-sensing camera, panoramic shooting by fusion of the main camera and the wide-angle camera, VR (Virtual Reality) shooting, or other fusion shooting functions. In some embodiments, the camera assembly 506 also includes a flash. Optionally, the flash is a single-color temperature flash or a dual-color temperature flash. A dual-color temperature flash refers to a combination of a warm-light flash and a cool-light flash, used for light compensation at different color temperatures.
[0117] In some embodiments, the audio circuit 507 includes a microphone and a speaker. The microphone is used to collect sound waves from the user and the environment, and convert the sound waves into electrical signals that are input to the processor 501 for processing, or input to the radio frequency circuit 504 to realize voice communication. For stereo acquisition or noise reduction purposes, multiple microphones are used, respectively located at different parts of the terminal 500. Optionally, the microphone is an array microphone or an omnidirectional acquisition microphone. The speaker is used to convert the electrical signals from the processor 501 or the radio frequency circuit 504 into sound waves. Optionally, the speaker is a conventional film speaker or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can not only convert electrical signals into sound waves that are audible to humans, but also convert electrical signals into sound waves that are inaudible to humans for purposes such as distance measurement. In some embodiments, the audio circuit 507 also includes a headphone jack.
[0118] Power supply 509 is used to power the various components in terminal 500. Optionally, power supply 509 is AC power, DC power, a disposable battery, or a rechargeable battery. When power supply 509 includes a rechargeable battery, the rechargeable battery supports wired or wireless charging. The rechargeable battery also supports fast charging technology.
[0119] In some embodiments, the terminal 500 further includes one or more sensors 510. The one or more sensors 510 include, but are not limited to, an acceleration sensor 511, a gyroscope sensor 512, a pressure sensor 513, an optical sensor 515, and a proximity sensor 516.
[0120] In some embodiments, the accelerometer 511 detects the magnitude of acceleration along the three coordinate axes of a coordinate system established with respect to the terminal 500. For example, the accelerometer 511 is used to detect the components of gravitational acceleration along the three coordinate axes. Optionally, the processor 501 controls the display screen 505 to display the user interface in either a landscape or portrait view based on the gravitational acceleration signal acquired by the accelerometer 511. The accelerometer 511 is also used for acquiring motion data from games or the user.
[0121] In some embodiments, the gyroscope sensor 512 detects the orientation and rotation angle of the terminal 500. The gyroscope sensor 512 and the accelerometer sensor 511 work together to collect the user's 3D movements on the terminal 500. Based on the data collected by the gyroscope sensor 512, the processor 501 implements the following functions: motion sensing (e.g., changing the UI based on the user's tilt operation), image stabilization during shooting, game control, and inertial navigation.
[0122] Optionally, the pressure sensor 513 is disposed on the side bezel of the terminal 500 and / or on the lower layer of the display screen 505. When the pressure sensor 513 is disposed on the side bezel of the terminal 500, it can detect the user's grip signal on the terminal 500, and the processor 501 performs left / right hand recognition or quick operation based on the grip signal collected by the pressure sensor 513. When the pressure sensor 513 is disposed on the lower layer of the display screen 505, the processor 501 controls the operable controls on the UI interface based on the user's pressure operation on the display screen 505. The operable controls include at least one of button controls, scroll bar controls, icon controls, and menu controls.
[0123] An optical sensor 515 is used to collect ambient light intensity. In one embodiment, the processor 501 controls the display brightness of the display screen 505 based on the ambient light intensity collected by the optical sensor 515. Specifically, when the ambient light intensity is high, the display brightness of the display screen 505 is increased; when the ambient light intensity is low, the display brightness of the display screen 505 is decreased. In another embodiment, the processor 501 also dynamically adjusts the shooting parameters of the camera assembly 506 based on the ambient light intensity collected by the optical sensor 515.
[0124] The proximity sensor 516, also known as a distance sensor, is typically located on the front panel of the terminal 500. The proximity sensor 516 is used to detect the distance between the user and the front of the terminal 500. In one embodiment, when the proximity sensor 516 detects that the distance between the user and the front of the terminal 500 is gradually decreasing, the processor 501 controls the display screen 505 to switch from a screen-on state to a screen-off state; when the proximity sensor 516 detects that the distance between the user and the front of the terminal 500 is gradually increasing, the processor 501 controls the display screen 505 to switch from a screen-off state to a screen-on state.
[0125] Those skilled in the art will understand that Figure 5 The structure shown does not constitute a limitation on terminal 500, which may include more or fewer components than shown, or combine certain components, or use different component arrangements.
[0126] In an exemplary embodiment, a computer-readable storage medium is also provided, such as a memory including at least one line of program code, which can be executed by a processor in an electronic device to perform the data reading method described above. For example, the computer-readable storage medium includes ROM (Read-Only Memory), RAM (Random-Access Memory), CD-ROM (Compact Disc Read-Only Memory), magnetic tape, floppy disk, and optical data storage devices, etc.
[0127] In an exemplary embodiment, a computer program product or computer program is also provided, including one or more lines of program code stored in a computer-readable storage medium. One or more processors of an electronic device are capable of reading the one or more lines of program code from the computer-readable storage medium, and the one or more processors execute the one or more lines of program code, enabling the electronic device to perform the data reading method described in the above embodiments.
[0128] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. Optionally, the program is stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.
[0129] The above description is merely an optional embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A data reading method, characterized in that, The method includes: Get the target table name of the data table containing the data item to be read in the remote database; Obtain at least one offset between at least one field of a structure created in the local target program and the starting address of the structure, wherein the starting address is the memory address of the first field of the structure; For any field, a target triplet is created based on the field name, field type, and offset between the field and the starting address. The target table name is used as the key, and the target triplet as the key value; key-value pairs consisting of the key name and the key value are stored in a mapping table. The mapping table is defined as the mapping information between the target table name and at least one field. The mapping information is the structure definition code corresponding to the data table, the target table name is the type name of the structure, and the field names of each field in the data table are the field names of each field in the structure. A single target table name corresponds to multiple target triplets. In each target triplet, the field name is bound to the address offset of a field in the structure. The storage address of all fields in the structure can be located based on the field's address offset and the structure pointer address passed when calling the application programming interface function, thereby realizing the mapping relationship between the data table and the structure. Based on the mapping information, a mapping relationship is established between the data table and the structure; Based on the mapping relationship, the data items to be read are automatically imported into the structure.
2. The method according to claim 1, characterized in that, The mapping information includes the source file, header file, and common header file of the structure. The source file is used to define functions for constructing the mapping of at least one field in the structure. The header file is used to declare the data format of the structure. The common header file is used to define global initialization functions.
3. The method according to claim 2, characterized in that, The step of establishing the mapping relationship between the data table and the structure based on the mapping information includes: When initializing the target program, the global initialization function of the public header file is called to establish the mapping relationship.
4. The method according to claim 1, characterized in that, The automatic import of the data item to be read into the structure based on the mapping relationship includes: According to the structured query statement, the data item to be read is obtained from the data table; Based on the mapping relationship, determine the target storage location of the data item to be read in the structure; The data item to be read is stored in the target storage location.
5. The method according to claim 1, characterized in that, The method further includes: When creating the structure, the name of the first field of the structure is set to the name of the target table.
6. A data reading device, characterized in that, The device includes: The first acquisition module is used to obtain the target table name of the data table containing the data item to be read in the remote database. The acquisition unit included in the second acquisition module is used to acquire at least one offset between at least one field of a structure created in the local target program and the starting address of the structure, wherein the starting address is the memory address of the first field of the structure. The second acquisition module is further configured to create a target triplet for any field based on the field name, field type, and offset between the field and the starting address; store the key-value pairs formed by the target table name as the key and the target triplet as the key value in a mapping table; define the mapping table as the mapping information between the target table name and the at least one field, wherein the mapping information is the structure definition code corresponding to the data table, the target table name is the type name of the structure, and the field names of each field in the data table are the field names of each field in the structure; wherein a single target table name corresponds to multiple target triplets, and in each target triplet, the field name is bound to the address offset of the field in the structure, and the storage address of all fields in the structure can be located based on the address offset of the field and the structure pointer address passed when calling the application programming interface function, so as to realize the construction of the mapping relationship between the data table and the structure; A module is established to establish a mapping relationship between the data table and the structure based on the mapping information; The import module is used to automatically import the data items to be read into the structure based on the mapping relationship.
7. The apparatus according to claim 6, characterized in that, The mapping information includes the source file, header file, and common header file of the structure. The source file is used to define functions for constructing the mapping of at least one field in the structure. The header file is used to declare the data format of the structure. The common header file is used to define global initialization functions.
8. The apparatus according to claim 7, characterized in that, The establishment module is used for: When initializing the target program, the global initialization function of the public header file is called to establish the mapping relationship.
9. The apparatus according to claim 6, characterized in that, The import module is used for: According to the structured query statement, the data item to be read is obtained from the data table; Based on the mapping relationship, determine the target storage location of the data item to be read in the structure; The data item to be read is stored in the target storage location.
10. The apparatus according to claim 6, characterized in that, The device further includes a setting module for: When creating the structure, the name of the first field of the structure is set to the name of the target table.
11. An electronic device, characterized in that, The electronic device includes one or more processors and one or more memories, wherein at least one piece of program code is stored in the one or more memories, and the at least one piece of program code is loaded and executed by the one or more processors to implement the data reading method as described in any one of claims 1 to 5.
12. A storage medium, characterized in that, The storage medium stores at least one piece of program code, which is loaded and executed by a processor to implement the data reading method as described in any one of claims 1 to 5.
13. A computer program product comprising one or more lines of program code stored in a computer-readable storage medium, wherein one or more processors of an electronic device are capable of reading the one or more lines of program code from the computer-readable storage medium, and wherein the one or more processors execute the one or more lines of program code such that the electronic device is capable of performing a data reading method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Data structure generation method and device and calling method and device
CN110990411A
