Search

CN-122018864-A - Structured exchange text generation method and system

CN122018864ACN 122018864 ACN122018864 ACN 122018864ACN-122018864-A

Abstract

The invention provides a method and a system for generating a structured exchange text, wherein the method comprises the steps of loading a template of the structured text, constructing a corresponding database SQL query statement, executing the SQL query statement, splicing query results of the SQL statement in sequence to generate the structured exchange text, and adding an automatic replacement function to corresponding fields in the SQL query statement to replace the structured text retention word with legal escape characters if the query results of the SQL statement contain the structured text retention word. The method and the device can simplify the generation process of the structured exchange text, have less development code quantity and high data conversion efficiency, and can improve the development and execution efficiency of related codes.

Inventors

  • LIU CHANG

Assignees

  • 璞华国际科技(武汉)有限公司

Dates

Publication Date
20260512
Application Date
20251224

Claims (10)

  1. 1. A structured switched text generation method, comprising: loading a template of the structured text, and constructing a corresponding database SQL query statement; Executing the SQL query statement, and splicing the query results of the SQL statement in sequence to generate a structured exchange text; If the query result of the SQL statement contains the structured text reserved word, an automatic replacement function is added to the corresponding field in the SQL query statement to replace the structured text reserved word with legal escape characters.
  2. 2. The method of claim 1, wherein loading templates of structured text, constructing corresponding database SQL query statements further comprises: Loading the format template of the structured text into the SQL query language, and embedding each field of the pre-query in the structured text template into the corresponding position of the SQL query statement.
  3. 3. The method of claim 1, wherein concatenating the query results of the SQL statements in order, generating the structured exchange text comprises: and sequentially and serially connecting each recorded content text in the query result, and adding a summarizing tag to the heads of all the contents after serial connection to obtain the structured exchange text.
  4. 4. The method of claim 1, wherein the automatic replacement function is a replace function embedded in SQL.
  5. 5. A structured switched text generation system, comprising: the query sentence construction module is used for loading templates of the structured text and constructing corresponding database SQL query sentences; the exchange text generation module is used for executing the SQL query statement, splicing the query results of the SQL statement in sequence, and generating a structured exchange text; If the query result of the SQL statement contains the structured text reserved word, an automatic replacement function is added to the corresponding field in the SQL query statement to replace the structured text reserved word with legal escape characters.
  6. 6. The system of claim 5, wherein loading templates of structured text, constructing corresponding database SQL query statements further comprises: Loading the format template of the structured text into the SQL query language, and embedding each field of the pre-query in the structured text template into the corresponding position of the SQL query statement.
  7. 7. The system of claim 5, wherein concatenating the query results of the SQL statement in order, generating the structured exchange text comprises: and sequentially and serially connecting each recorded content text in the query result, and adding a summarizing tag to the heads of all the contents after serial connection to obtain the structured exchange text.
  8. 8. The system of claim 5, wherein the automatic replacement function is a replace function embedded in SQL.
  9. 9. An electronic device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that the processor implements the steps of a structured switched text generation method according to any of claims 1 to 4 when the computer program is executed.
  10. 10. A computer readable storage medium storing a computer program, characterized in that the computer program when executed implements the steps of a structured switched text generation method according to any of claims 1 to 4.

Description

Structured exchange text generation method and system Technical Field The invention belongs to the technical field of computer software, and particularly relates to a method and a system for generating a structured exchange text. Background In the field of computer application software, data storage and exchange are important functions of a software system, and in order to facilitate the application of services such as adding, deleting, checking and the like, a relational database is used for storing massive structured data generally. When the structured data are exchanged between different application systems, a data carrier is needed, and in early days, due to small bandwidth and small storage capacity of a computer network, binary text or binary file mode is widely used for transmission, but the compatibility and the readability are poor. With the development of hardware conditions, the bottleneck of excessively pursuing information size and efficiency has been broken through, and the current carriers used for data exchange between systems have become structured texts, such as csv, xml, json and custom structured texts, wherein xml and json formats are widely used as carriers for data exchange between independent systems due to the advantages of strong readability, simple development and debugging, good compatibility and expansibility and the like. Because of the data exchange requirement between systems, the data stored in the relational database is taken out from the database by the data provider, and is reorganized and format-converted and stored as structural texts such as xml or json. For the receiver of the data, reading/analyzing the structured texts such as xml/json and the like, extracting the data therein, and storing the data in a relational database of the own party or directly carrying out data application is also a necessary function. At present, the method of extracting data from a relational database and converting the data into xml/json format is the most commonly used method, in a development language, an SDK function provided by a database access driver is used, SQL sentences are executed to access the database, data meeting service requirement conditions in the database are retrieved, a record is formed in a memory one by one, each record has corresponding fields, and the record is actually a data table in the memory. And then, calling a corresponding xml/json read-write library function by using a development language, filling the data of each field in the data table into each node of the tree structure of the xml/json one by one in a trunk-branch-leaf mode, and finally, exporting the whole tree structure into a structured text depending on the library function. Obviously, the method for generating the xml/Jason format carrier by reading the data is complex, and because the SQL query result is a two-dimensional table-like structure and the xml/Jason is a tree-like structure, the development of the data conversion code in the middle is complex, and meanwhile, each node in the xml/json tree needs to be accessed one by one and the attributes and the values are filled one by one, so that the conversion efficiency is low. Disclosure of Invention In view of this, the embodiment of the invention provides a method and a system for generating a structured exchange text, which are used for solving the problems of complex construction process and low data conversion efficiency of the current exchange file. In a first aspect of an embodiment of the present invention, there is provided a method for generating a structured exchange text, including: loading a template of the structured text, and constructing a corresponding database SQL query statement; Executing the SQL query statement, and splicing the query results of the SQL statement in sequence to generate a structured exchange text; If the query result of the SQL statement contains the structured text reserved word, an automatic replacement function is added to the corresponding field in the SQL query statement to replace the structured text reserved word with legal escape characters. In a second aspect of an embodiment of the present invention, there is provided a structured switched text generation system, including: the query sentence construction module is used for loading templates of the structured text and constructing corresponding database SQL query sentences; the exchange text generation module is used for executing the SQL query statement, splicing the query results of the SQL statement in sequence, and generating a structured exchange text; If the query result of the SQL statement contains the structured text reserved word, an automatic replacement function is added to the corresponding field in the SQL query statement to replace the structured text reserved word with legal escape characters. In a third aspect of the embodiments of the present invention, there is provided an electronic device comprising a memory, a processor and