A database table definition method based on XML file

By adding the information required for database table creation in XML files and combining data table definition commands with XML file structure, the automatic definition and automatic creation of database table structure is achieved, solving the problem of manual creation of database table definition dependencies in the existing technology, and improving the scalability and adaptability of the software.

CN114936304BActive Publication Date: 2025-05-20TIANJIN NAVIGATION INSTR RES INST
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210605985.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-31
Publication Date
2025-05-20
Estimated Expiration
2042-05-31

AI Technical Summary

Technical Problem

In the prior art, the definition of database tables is mostly created manually by developers, resulting in limited software scalability and adaptability, and there is no way to define database tables using XML files.

Method used

By setting the XML file structure, defining variables store XML file information, reading the XML file root node information, and combining data table definition commands based on the read information, realizing automatic definition and automatic creation of database table structure.

Benefits of technology

It realizes automatic definition and automatic creation of database table structure, improves the scalability and adaptability of the software, and solves the problem of manual creation of database table definition dependency in the existing technology.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114936304B_ABST
    Figure CN114936304B_ABST
Patent Text Reader

Abstract

The present invention relates to a database table definition method based on XML files, which realizes automatic generation of database table definition statements by setting XML file structure; defining variables for storing XML file information; reading XML file root node information; and combining data table definition commands according to the read root node information. The present invention improves and innovates the database table creation process, combines the configuration files required in software engineering, adds various information required for database table creation to the original XML file, and realizes automatic definition of database table structure and automatic creation of database tables.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of software data management, and in particular, to a method for defining database tables based on XML files. Background Art

[0002] In existing methods, the definition of database tables is mostly manually created and implemented by developers, which greatly limits the scalability and adaptability of software. In software engineering, configuration files mostly use XML files, and various information required for defining database tables can be stored in XML files. The equipment software can automatically generate database table definition statements by reading and storing the information in XML and combining them according to specific syntax. However, in the prior art, there has not been a method for defining database tables using XML files. Summary of the Invention

[0003] The object of the present invention is to overcome the deficiencies of the prior art and propose a method for defining database tables based on XML files. By improving the process of creating database tables and combining the configuration files necessary in software engineering, various information required for creating database tables is added to the original XML file to achieve automatic definition of database table structures and automatic creation of database tables.

[0004] The present invention solves its technical problems by adopting the following technical solutions:

[0005] A method for defining database tables based on XML files includes the following steps:

[0006] Step 1, set the XML file structure;

[0007] Step 2, define variables to store XML file information according to the XML file structure set in Step 1;

[0008] Step 3, read the root node information of the XML file according to the variables defined in Step 2;

[0009] Step 4, combine the data table definition commands according to the root node information read in Step 3.

[0010] Moreover, the XML file structure in step 1 is as follows: root represents the root node, and only 1 root node is defined. The datanode node represents the information volume, and the information volume includes: longitude, latitude, and working duration. The next level under the datanode node includes the colname sub-node, the tableColumnName sub-node, and the tableType sub-node; the colname sub-node represents the Chinese meaning of the information volume, the tableColumnName sub-node represents the variable name of the information volume in the data table generation statement, and the tableType sub-node represents the data type of the information volume in the data table generation statement. Different datanode nodes represent different types of information volumes. The tableName node represents the name of the data table to be created, and the isUpdated node represents the data table update valid flag bit. When the isUpdated node is 0, it means an update is to be performed, and when the isUpdated node is 1, it means no update.

[0011] Moreover, step 2 includes the following steps:

[0012] Step 2.1: Define a structure DataStruct, which includes the variable colname, the variable tableType, and the variable tableColumnName. The variable colname is used to store the Chinese meaning of the information volume, the variable tableType is the data type of the information volume in the data table construction statement, and the variable tableColumnName is the variable name of the information volume in the data table.

[0013] Step 2.2: Define an information storage class XmlClass for storing all node information obtained from a single XML file. XmlClass includes the member variable tableName, the member variable datanode, and the member variable updateSymbol. The member variable tableName of the QString type is used to store the data table name, the member variable datanode of the QMap<int, DataStruct> type is used to store the information volume of multiple DataStruct structures, and the member variable updateSymbol of the bool type is used to store the content stored in the isUpdated node.

[0014] Step 2.3: Define a variable allXmlData of the QMap<int, XmlClass> type to store information of multiple XML files.

[0015] Moreover, step 3 includes the following steps:

[0016] Step 3.1: Define a nodeList object through QDomNodeList to represent the root node root;

[0017] Step 3.2: Determine whether the root node represented by nodeList exists. Use the QDomNodeList general function nodeList.count() to represent the number of root nodes. If nodeList.count() is greater than 0, it means the root node exists, and proceed to Step 3.3; otherwise, end the operation.

[0018] Step 3.3: Define a variable childNodeList through QDomNodeList to represent the information of the only root node. Let childNodeList = nodeList.at(0).childNodes();

[0019] Step 3.4: If the return value of childNodeList.count() is greater than 0, it means there are multiple child nodes in the childNodeList node. Determine whether the childNodeList node matches the datanode, tableName, and isUpdated nodes. If the return value of childNodeList.count() is less than or equal to 0, then end the operation.

[0020] Step 3.5: If the match with the tableName and isUpdated nodes is successful, directly obtain the content under this node and output the content to the corresponding variables defined by the software, make childNodeList represent the next node, and return to Step 3.4;

[0021] Step 3.6: If the match result is datanode, define a new child node d = childNodeList.at(i).childNodes(), where i is a node in the next level of childNodeList, and read the information of the lowest-level node into the software buffer.

[0022] Moreover, the said Step 4 includes the following steps:

[0023] Step 4.1: Calculate the number of elements n in the variable allXmlData defined in Step 2. If the number of elements is greater than 0, then let i = 0, and define a variable strToSql of QString type;

[0024] Step 4.2: Compose a data table deletion statement in the software. The software pre - defines a data table deletion instruction "DROP TABLE IF EXISTS %1 CASCADE;", replaces the value stored in allXmlData[i].XmlClass.tableName in the information storage class with "%1" in the instruction, and stores the instruction in the strToSql string;

[0025] Step 4.3: Define a data table creation statement in the software. Define a data table creation instruction "CREATE TABLE %1 (%2);", replace the value stored in allXmlData[i].XmlClass.tableName with "%1" in the instruction, make the string variable str += "%1 %2,--%3", loop through the allXmlData[i].XmlClass.datanode variable, and replace "%1", "%2", and "%3" in str with tableColumnName, tableType, and colname in the datanode structure in sequence. After the loop ends, delete the last "," in str, and replace "%2" in the database instruction with str;

[0026] Step 4.4: If the value in allXmlData[i].XmlClass.isUpdated is 0, store the two instructions obtained in Step 4.2 and Step 4.3 in strToSql. Otherwise, discard the database instructions obtained in Steps 4.2 and 4.3, let i = i + 1, and return to Step 4.2 until i >= n and the operation ends.

[0027] The advantages and positive effects of the present invention are:

[0028] By setting the XML file structure, defining variables to store XML file information, reading the root node information of the XML file, and combining data table definition commands according to the read root node information, the present invention realizes the automatic generation of database table definition statements. The present invention improves and innovates the database table creation process, combines the configuration files necessary in software engineering, adds various information required for database table creation in the original XML file, and realizes the automatic definition of database table structures and the automatic creation of database tables. Brief Description of the Drawings

[0029] Figure 1 It is the storage structure diagram of the XML file information of the present invention in the software;

[0030] Figure 2 It is the software reading process of the root node information of the XML file of the present invention;

[0031] Figure 3This is the flowchart of the statement combination for the data table of the present invention. Detailed implementation manners

[0032] The present invention will be further described in detail below with reference to the accompanying drawings.

[0033] A method for defining a database table based on an XML file, characterized by comprising the following steps:

[0034] Step 1: Set the XML file structure.

[0035] The data table generation statement needs to contain information such as data name, data type, and data table name. All information of a single device is stored in an XML file, and the file structure is designed as follows:

[0036]

[0037] Among them, root represents the root node, and only 1 root node is defined. The above design file contains 3 datanode nodes. The datanode node represents the amount of information, and the amount of information includes: longitude, latitude, and working duration. The next level of the datanode node includes the colname sub-node, the tableColumnName sub-node, and the tableType sub-node; the colname sub-node represents the Chinese meaning of the amount of information, the tableColumnName sub-node represents the variable name of the amount of information in the data table generation statement, the tableType sub-node represents the data type of the amount of information in the data table generation statement. Different datanode nodes represent different types of information. The tableName node represents the name of the data table to be created, and the isUpdated node represents the data table update valid flag bit. When the isUpdated node is 0, it means an update is performed. When the isUpdated node is 1, it means no update is performed.

[0038] Step 2: Define variables to store the XML file information according to the XML file structure set in Step 1.

[0039] As Figure 1 shown, this step includes the following steps:

[0040] Step 2.1: Define a structure DataStruct, where the structure DataStruct is subdivided into 3 variables: variable olname, variable tableType, and variable tableColumnName. The variable colname stores the Chinese meaning of the amount of information, the variable tableType is the data type of the amount of information in the data table construction statement, and the variable tableColumnName is the variable name of the amount of information in the data table.

[0041] Step 2.2: Define an information storage class XmlClass for storing all node information obtained from a single XML file. Define three member variables in XmlClass: member variable tableName, member variable datanode, and member variable updateSymbol. Among them, the member variable tableName of QString type is used to store the data table name, the member variable datanode of QMap<int, DataStruct> type is used to store the information volume of multiple DataStruct structures, and the member variable updateSymbol of bool type is used to store the content stored in the isUpdated node. The variable updateSymbol represents a valid identifier for data table update.

[0042] Step 2.3: Define a variable allXmlData of QMap<int, XmlClass> type to store information of multiple XML files.

[0043] Step 3: Read the root node information of the XML file according to the variables defined in Step 2.

[0044] As Figure 2 shown, this step includes the following steps:

[0045] Step 3.1: Define a nodeList object through QDomNodeList to represent the root root node;

[0046] Step 3.2: Determine whether the root root node represented by nodeList exists. Use the QDomNodeList general function nodeList.count() to represent the number of root root nodes. If nodeList.count() is greater than 0, it means the root root node exists, and proceed to Step 3.3; otherwise, end the operation.

[0047] Step 3.3: Define a variable childNodeList through QDomNodeList to represent the information of the only root root node, and set childNodeList = nodeList.at(0).childNodes();

[0048] Step 3.4: If the return value of childNodeList.count() is greater than 0, it means there are multiple child nodes in the childNodeList node. Determine whether the child nodes at all levels of childNodeList match the datanode, tableName, and isUpdated nodes. If the return value of childNodeList.count() is less than or equal to 0, then end the operation.

[0049] Step 3.5: If the match with the nodes tableName and isUpdated is successful, directly obtain the content under this node, output the content to the corresponding variables defined by the software, make childNodeList represent the next node, and return to Step 3.4;

[0050] Step 3.6: If the match result is datanode, define a new child node d = childNodeList.at(i).childNodes(), where i is a node in the next level of childNodeList, and read the information of the lowest-level node into the software buffer.

[0051] Step 4: Combine the data table definition commands according to the root node information read in Step 3.

[0052] As Figure 3 shown, this step includes the following steps:

[0053] Step 4.1: Calculate the number of elements n in the variable allXmlData defined in Step 2. If the number of elements is greater than 0, set i = 0 and define a variable strToSql of type QString;

[0054] Step 4.2: Assemble the data table deletion statement in the software. The software pre-defines the data table deletion instruction "DROP TABLE IF EXISTS %1 CASCADE;", replace the value stored in allXmlData[i].XmlClass.tableName in the information storage class with "%1" in the instruction, and store the instruction in the strToSql string;

[0055] Step 4.3: Define the data table creation statement in the software. Define the data table creation instruction "CREATE TABLE %1 (%2);", replace the value stored in allXmlData[i].XmlClass.tableName in the instruction with "%1", set the string variable str += "%1 %2,--%3", loop through the allXmlData[i].XmlClass.datanode variable, and replace "%1", "%2", and "%3" in str with tableColumnName, tableType, and colname in the datanode structure in turn. After the loop ends, delete the last "," in str, and replace "%2" in the database instruction with str;

[0056] Step 4.4: If the value in allXmlData[i].XmlClass.isUpdated is 0, store the two instructions obtained in Steps 4.2 and 4.3 into strToSql; otherwise, discard the database instructions obtained in Steps 4.2 and 4.3, set i = i + 1, and return to Step 4.2 until the operation ends when i >= n.

[0057] It should be emphasized that the embodiments described in the present invention are illustrative rather than restrictive. Therefore, the present invention includes, but is not limited to, the embodiments described in the specific implementation manners. Any other implementation manners obtained by those skilled in the art based on the technical solutions of the present invention also fall within the scope of protection of the present invention.

Claims

1. A database table definition method based on XML file, characterized in that: The following steps are involved: Step 1. Set up the XML file structure; Step 2: According to the XML file structure set in step 1, define variables to store XML file information; Step 3: Read the root node information of the XML file according to the variables defined in step 2; Step 4: Combining data table definition commands according to the root node information read in step 3; Step 4.1, calculate the number of elements n in the variable allXmlData defined in step 2, if the number of elements is greater than 0, set i = 0, and define a variable strToSql of QString type; Step 4.2, construct a data table deletion statement in the software. The software predefines the data table deletion instruction "DROP TABLE IFEXISTS%1CASCADE;", replaces the value stored in allXmlData[i].XmlClass.tableName in the information storage class with "%1" in the instruction, and stores the instruction in the strToSql string; Step 4.3, define the data table creation statement in the software, define the data table creation instruction "CREATE TABLE %1(%2);", let the value stored in allXmlData[i].XmlClass.tableName replace the "%1" in the instruction, let the string variable str+="%1%2,--%3", loop allXmlData[i].XmlClass.datanode variable, replace the tableColumnName, tableType, colname in the datanode structure with "%1", "%2", "%3" in str in turn, delete the last ""," in str after the loop ends, and use str to replace the "%2" in the database instruction; Step 4.4: If the value in allXmlData[i].XmlClass.isUpdated is 0, store the two instructions obtained in steps 4.2 and 4.3 into strToSql, otherwise discard the database instructions obtained in steps 4.2 and 4.3, set i=i+1, return to step 4.2, and the operation ends when i>=n.

2. The method for defining a database table based on an XML file according to claim 1, characterized in that: The XML file structure in step 1 is as follows: root represents the root node, only one root node is defined, datanode node represents the amount of information, and the amount of information includes: longitude, latitude and working duration, and the next level of the datanode node includes colname child node, tableColumnName child node and tableType child node; the colname child node represents the Chinese meaning of the amount of information, the tableColumnName child node represents the variable name of the amount of information in the data table generation statement, the tableType child node represents the data type of the amount of information in the data table generation statement, different datanode nodes represent different types of information, the tableName node represents the name of the data table to be created, the isUpdated node represents the data table update validity flag, when the isUpdated node is 0, it indicates an update, and when the isUpdated node is 1, it indicates no update.

3. The method for defining a database table based on an XML file according to claim 1, characterized in that: The step 2 comprises the following steps: Step 2.1, define a structure DataStruct, which includes variables colname, tableType and tableColumnName. Variable colname is the Chinese meaning of the amount of information stored, variable tableType is the data type of the amount of information in the data table construction statement, and variable tableColumnName is the variable name of the amount of information in the data table; Step 2.2, define an information storage class XmlClass, which is used to store all node information obtained from a single XML file. XmlClass includes member variables tableName, member variables datanode and member variables updateSymbol. The member variable tableName of QString type is used to store the data table name, QMap<int,DataStruct> The member variable datanode of type is used to store the information of multiple DataStruct structures, and the member variable updateSymbol of bool type is used to store the content stored in the isUpdated node; Step 2.3, define a QMap<int,XmlClass> The type variable allXmlData is used to store multiple XML file information.

4. The method for defining a database table based on an XML file according to claim 1, characterized in that: The step 3 comprises the following steps: Step 3.1, define a nodeList object through QDomNodeList to represent the root node; Step 3.

2. Determine whether the root node represented by nodeList exists, and use the QDomNodeList general function nodeList.count() to indicate the number of root nodes. If nodeList.count() is greater than 0, it means that the root node exists, and proceed to step 3.3, otherwise end the operation; Step 3.3, define the variable childNodeList through QDomNodeList to represent the unique root node information, let childNodeList = nodeList.at(0).childNodes(); Step 3.4, if the return value of childNodeList.count() is greater than 0, it means that there are multiple child nodes in the childNodeList node. Determine whether the child nodes at all levels of childNodeList match the datanode, tableName, and isUpdated nodes. If the return value of childNodeList.count() is less than or equal to 0, end the operation; Step 3.5, if the match with the node tableName and isUpdated is successful, directly obtain the content under the node and output the content to the corresponding variable defined by the software, so that childNodeList represents the next node and return to step 3.4; Step 3.6: If the matching result is datanode, define a new child node d=childNodeList.at(i).childNodes(), where i is a node in the next level of childNodeList, and read the lowest level node information into the software cache.

Citation Information

Patent Citations

  • Method for automatically converting network management information base MIB file into XML file

    CN109510728A

  • Dynamic library building method for managing a system database

    CN109582662A