Structured query language reverse generation method and device, equipment and medium

By extracting and parsing database metadata, generating domain-specific language DSL, and generating reverse SQL statements based on DSL and original SQL statements, the high cost and complexity of manually writing SQL statements is solved, and the automatic generation of SQL statements and database management is realized.

CN119848070APending Publication Date: 2025-04-18INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411901303.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-23
Publication Date
2025-04-18

AI Technical Summary

Technical Problem

In the prior art, manual writing of SQL statements requires technicians to have a high technical level, consume high labor costs, and it is difficult to achieve automatic generation of SQL statements.

Method used

By extracting metadata from the target database, parsing and processing it to generate domain-specific language DSL, and generate reverse SQL statements based on the DSL language and the original SQL statement.

Benefits of technology

It simplifies the writing process of SQL statements, reduces the difficulty of writing, improves the degree of automation of database management, and reduces the complexity and error rate of manual operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119848070A_ABST
    Figure CN119848070A_ABST
Patent Text Reader

Abstract

The embodiment of the invention relates to the technical field of big data, and discloses a structured query language reverse generation method and device, equipment and a medium. The method comprises the following steps: extracting metadata in a target database; analyzing and processing the metadata to obtain data of the target data structure; according to the data of the target data structure, a domain specific language DSL is generated, and the DSL is used for describing database requirements and a data model; and according to the DSL language and the original structured query language SQL statement, generating a corresponding reverse SQL statement. According to the method, the SQL statement is reversely generated through the DSL, the compiling process of the SQL statement is simplified, the compiling difficulty is reduced, management and rollback of the database are facilitated, and the migration and synchronization process of the database is facilitated to be simplified.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of big data technology and can be applied to the field of financial technology, and in particular to a structured query language reverse generation method, device, equipment and medium. Background Art

[0002] With the continuous development of software development technology, version control of database structure is becoming more and more important. In database management and development, it is necessary to track changes in database objects and be able to manage and roll back these changes. In addition, in database maintenance, it is usually necessary to migrate from one platform to another or synchronize data between databases.

[0003] In the prior art, database administrators and developers mainly perform reverse structured query language (SQL) generation to solve issues in database management such as database document generation, migration and replication, version control and upgrade, and database reconstruction and recovery.

[0004] However, manually writing SQL statements requires technicians to have a high level of skills and consumes high labor costs. Therefore, it is urgent to provide an automatic generation method for reverse SQL statements to simplify the SQL statement writing process and reduce the writing difficulty. Summary of the invention

[0005] The present invention provides a structured query language reverse generation method, device, equipment and medium to reduce the threshold for SQL statement generation and facilitate database management.

[0006] According to one aspect of the present invention, a structured query language reverse generation method is provided, the method comprising:

[0007] Extracting metadata from a target database; parsing and processing the metadata to obtain data of a target data structure;

[0008] Generate a domain specific language DSL according to the data of the target data structure, where the DSL language is used to describe database requirements and data models;

[0009] Generate the corresponding reverse SQL statement based on the DSL language and the original SQL statement.

[0010] According to another aspect of the present invention, a structured query language reverse generation device is provided, the device comprising:

[0011] The metadata processing module is used to extract metadata from the target database; and parse and process the metadata to obtain data of the target data structure;

[0012] A DSL generation module, used to generate a domain specific language DSL according to the data of the target data structure, where the DSL language is used to describe database requirements and data models;

[0013] The reverse SQL statement generation module is used to generate corresponding reverse SQL statements according to the DSL language and the original SQL statement.

[0014] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:

[0015] at least one processor; and

[0016] a memory communicatively connected to the at least one processor; wherein,

[0017] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the structured query language reverse generation method described in any embodiment of the present invention.

[0018] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the structured query language reverse generation method described in any embodiment of the present invention when executed.

[0019] According to another aspect of the present invention, a computer program product is provided, comprising a computer program, wherein when the computer program is executed by a processor, the structured query language reverse generation method according to any embodiment of the present invention is implemented.

[0020] The technical solution of the embodiment of the present invention extracts metadata from the target database; parses and processes the metadata to obtain data of the target data structure; generates a domain specific language DSL based on the data of the target data structure, and the DSL language is used to describe database requirements and data models; generates corresponding reverse SQL statements based on the DSL language and original SQL statements, thereby solving the problem of automatic generation of SQL statements in database management, and reversely generates SQL statements through the DSL language, which simplifies the SQL statement writing process and reduces the writing difficulty, is conducive to realizing database management and rollback, and is conducive to simplifying database migration and synchronization processes.

[0021] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0023] Figure 1 is a flow chart of a structured query language reverse generation method provided according to an embodiment of the present invention;

[0024] Figure 2 It is a schematic diagram of another process of reversely generating structured query language according to an embodiment of the present invention;

[0025] Figure 3 is a flow chart of another structured query language reverse generation method provided according to an embodiment of the present invention;

[0026] Figure 4 It is a schematic diagram of the structure of a structured query language reverse generation device provided according to an embodiment of the present invention;

[0027] Figure 5 It is a schematic diagram of the structure of an electronic device for implementing the structured query language reverse generation method according to an embodiment of the present invention. DETAILED DESCRIPTION

[0028] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0029] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0030] Figure 1This is a flowchart of a structured query language reverse generation method provided according to an embodiment of the present invention. This embodiment is applicable to the situation of reverse generation of SQL statements during database management and rollback, or database migration and database synchronization. The method can be executed by a structured query language reverse generation device. The structured query language reverse generation device can be implemented in the form of hardware and / or software. The structured query language reverse generation device can be configured in an electronic device. The electronic device can be a mobile device such as a mobile phone, a tablet computer (PAD), a wearable device, or a personal computer (PC, Personal Computer), etc. Figure 1 As shown, the method includes:

[0031] Step 110: extract metadata from the target database; and parse and process the metadata to obtain data of the target data structure.

[0032] Metadata extraction is a crucial step in database management and software development. Metadata extraction is used to obtain information about database objects and their properties, providing basic data for subsequent operations. When performing metadata extraction, you can first establish a connection with the target database. For example, you can use a database connection tool or a database connection library provided by a programming language to establish a connection with the target database. Metadata extraction can be to extract information about database objects from the system tables or views of the target database by executing specific SQL query statements. Metadata includes but is not limited to: table structure, column definition, constraints, and index information. The structure of a table may include: table name, field name, field type, primary key, foreign key relationship and other information. In different databases, metadata may differ due to different database types. Therefore, when performing metadata extraction, you can select the corresponding query statement to execute according to the specific database system.

[0033] During the entire metadata extraction process, error handling mechanisms can also be considered to ensure that abnormal situations can be properly handled and relevant log information can be recorded. In the process of implementing metadata extraction, attention can be paid to security, such as permission control and protection of sensitive information. After these steps are completed, valid database object information can be provided, laying the foundation for subsequent database management, software development, and data analysis.

[0034] The extracted metadata can be parsed and processed as necessary to generate SQL scripts or perform other operations. Metadata parsing and processing can convert raw data into a usable format or structure. Metadata parsing and processing can be to segment text data into fields to understand specific data structures or markup languages. Metadata parsing and processing can also perform logical processing on data, such as mapping specific database object information to corresponding data structures. When performing metadata parsing and processing, the differences between different database management systems can be considered to ensure that the parsed data can correctly express the required meaning in the target database. For example, metadata can be parsed into a data structure corresponding to a relational database (MySQL).

[0035] When parsing and processing metadata, you can also filter, clean, or convert the data to ensure that the final data structure meets expectations and meets actual needs. During the entire parsing and processing process, you can also consider error handling and response to abnormal situations. For example, ensure that the program gives clear prompts and records relevant log information when encountering problems. By parsing and processing metadata, you can effectively convert raw metadata into a usable data structure, providing a good foundation for further operations.

[0036] In an optional implementation of an embodiment of the present invention, metadata is parsed and processed to obtain data of a target data structure, including: parsing and processing relationships between tables, between tables and views, and foreign key relationships in the metadata to obtain data of the target data structure.

[0037] By extracting, parsing and processing the metadata in the target database, the compatibility between databases can be considered, which facilitates the generation of reverse SQL for the database.

[0038] When exporting existing data in the database, you can generate a data file containing all table data. For example, you can generate a plain text file format file (Comma-Separated Values, CSV) or other formats for storing table data. At the same time, according to the size and complexity of the data, you can choose to export in batches or process in parallel to improve efficiency.

[0039] Step 120: Generate DSL language according to the data of the target data structure.

[0040] Domain-Specific Language (DSL) includes but is not limited to the creation of tables (CREATE TABLE) and modification of tables (ALTER TABLE) in SQL statements. DSL language can be customized according to the needs and characteristics of a specific domain. When generating DSL language, the parsed data can be accurately mapped to the corresponding SQL syntax structure. DSL language is used to describe database requirements and data models. For example, the user table (ouers) and the order table (orders) can be defined through DSL language, including the field name, field type and length of each table, as well as the relationship between tables. DSL can automatically generate corresponding SQL statements based on the domain-related information provided by the user, such as data models, business rules, etc.

[0041] Step 130: Generate a corresponding reverse SQL statement according to the DSL language and the original SQL statement.

[0042] Through DSL language, computers can understand the data relationship between metadata in the database, and based on the grammatical structure of the original SQL statement, they can generate SQL statements in reverse. Among them, the reverse SQL statement can be understood as the reverse operation of the original SQL statement. For example, the reverse operation of the insert operation is the delete operation. The reverse operation of the create table operation is to delete the table.

[0043] In an optional implementation of the embodiment of the present invention, a corresponding reverse SQL statement is generated according to the DSL language and the original SQL statement, including: converting the DSL language into AST through a DSL parser, where the AST is used to display the relationship between data tables and field attributes; generating a corresponding reverse SQL statement according to the AST, the original SQL statement, and the database convention rules.

[0044] Among them, the Abstract Syntax Tree (AST) is a tree-like data structure that can accurately represent the structure of the DSL language. AST is a format that can be processed by computers and can clearly show the relationship between tables and field attributes. The DSL parser can read the DSL language, understand the description, and convert the DSL language into AST.

[0045] The database convention rules may be the best practices and common conventions for database design. Optionally, in an embodiment of the present invention, the database convention rules include: structure definition statements, and initial data insertion statements (INSERT INTO); wherein the structure definition statements include: table creation statements (CREATE TABLE), primary key setting statements (PRIMARY KEY), and foreign key constraint statements (FOREIGN KEY).

[0046] In an embodiment of the present invention, the computer can use the original SQL statement as input, traverse the AST, combine the database convention rules, convert the original SQL statement, and generate the corresponding reverse SQL statement. The reverse SQL statement generated in this way can accurately reflect the original DSL description intention and follow the best practices and common conventions of database design. It not only improves the automation level of database management, but also effectively reduces the complexity and error rate of manually writing reverse operations.

[0047] In an optional implementation, a corresponding reverse SQL statement is generated based on AST, original SQL statements, and database convention rules, including: parsing the AST to obtain the table name, fields, and corresponding values ​​involved in the operation corresponding to the original SQL statement; based on the AST parsing result, determining the reverse operation corresponding to the reverse SQL statement and the reverse operation generation condition; generating a reverse SQL statement based on the reverse operation and the reverse operation generation condition.

[0048] Among them, AST parsing can be to understand the table name, field and corresponding value involved in the operation corresponding to the original SQL statement. For example, AST parsing can understand the table name, field and corresponding value involved in the insert operation. Based on the AST parsing result, the reverse operation corresponding to the original SQL statement can be determined. The reverse operation generation condition can be determined based on the record corresponding to the original SQL statement. For example, the reverse operation of the insert operation is the delete operation. The unique identifier in the insert operation (such as id=1) is used as the delete condition to ensure that the delete operation is targeted at a specific record. Therefore, a reverse SQL statement can be generated based on the reverse operation and the reverse operation generation condition. For example, the generated reverse SQL statement is DELETE FROM users WHERE id=1.

[0049] To explain the generation process of reverse SQL statements in detail, Figure 2 FIG. 1 is another flow chart of reversely generating structured query language according to an embodiment of the present invention. Figure 2 As shown, the process of reverse SQL generation is: generate DSL according to the data of the target data structure (such as table structure, field type, and association relationship); DSL can be generated as AST; and reverse SQL statements can be generated according to AST.

[0050] For example, a user table and an order table can be defined through DSL. The user table is defined as:

[0051] table users{ / / user table

[0052] id INT PRIMARY KEY, / / Define user ID, data type is integer, as the primary key (PRIMARY KEY), which means the value of this field is unique and cannot be empty

[0053] username VARCHAR(50)UNIQUE, / / Defines the user name. The data type is a variable-length string type with a maximum length of 50 characters and a unique constraint

[0054] email VARCHAR(100), / / defines the email address. The data type is a variable-length string type with a maximum length of 100 characters.

[0055] reg_date DATE / / Define the date type to record the user registration date

[0056] }

[0057] The order table is defined as:

[0058] table orders{ / / Order table

[0059] order_id INT PRIMARY KEY, / / Define the order ID, the data type is integer, as the primary key (PRIMARYKEY), used to uniquely identify each order

[0060] user_id INT, / / The id field in the application user table, the data type is integer

[0061] order_date DATE, / / Define the date type and record the date when the order was created

[0062] total_amount DECIMAL(10,2), / / Decimal type (DECIMAL), precision is 10 digits, there are 2 digits after the decimal point, the user stores the total amount of the order

[0063] FOREIGN KEY(user_id)REFERENCES users(id) / / The id field in the user table is a foreign key (FOREIGN KEY), which establishes a relationship between the user table and the order table to indicate which user placed the order

[0064] }

[0065] DSL parser can convert DSL language into AST. AST can clearly show the relationship between tables and field attributes. For example, the above user table and order table are converted into AST (AST for users table):

[0066] AST for users table:

[0067]

[0068] Among them, Table is the table name, user table (users); Field is the field name, representing each column of data in the table, such as ID, user name (username), email (email), and storage user registration date (reg_date); Type is the data type of the field, such as integer type (INT), variable length string type (VARCHAR), date type (DATE); Constraint is the constraint condition, such as primary key constraint (PRIMARY KEY) and unique constraint (UNIQUE).

[0069] According to AST, the SQL statement for creating a table can be converted into the reverse operation of deleting the table and its constraints.

[0070] Exemplary:

[0071]

[0072]

[0073] --Reverse SQL (generated) / / Generate SQL statements in reverse

[0074] DROP TABLE users; / / Delete the user table and all its data

[0075] In another exemplary embodiment, the original SQL statement is an insert statement, and the reverse-generated SQL statement is a delete statement.

[0076] --Forward SQL (original)

[0077] INSERT INTO users(id,username,email,reg_date)VALUES(1,'john_doe','john@example.com','2023-01-01'); / / Insert a new record into the user table, where the ID is 1, the username is 'john_doe', the email address is 'john@example.com', and the user's registration date is '2023-01-01'.

[0078] The corresponding AST is:

[0079] AST for INSERT operation:

[0080]

[0081] The generated reverse SQL statement is:

[0082] --Reverse SQL (generated) / / The opposite operation of the insert operation, that is, to undo or roll back the insert

[0083] DELETE FROM users WHERE id=1; / / Delete the record with id 1 in the user table

[0084] Through the above exemplary method, it is possible to ensure that the reverse SQL statement accurately reflects the intention of the original DSL description and follows the best practices and common conventions of database design. This not only improves the automation of database management, but also effectively reduces the complexity and error rate of manually writing reverse operations.

[0085] During the conversion process, we can also consider effectively handling transactions, ensuring data consistency, avoiding SQL injection risks, and selecting the most appropriate syntax construction according to the characteristics of the database management system (DBMS) used. This requires intelligent recognition of SQL patterns and automatic application of optimization rules to ensure that the generated reverse SQL statements are not only syntactically correct, but also meet high standards in terms of execution efficiency and security.

[0086] The embodiment of the present invention adopts a structured query language reverse generation method, which eliminates the need for users to directly write SQL statements. Instead, requirements are expressed in a more intuitive and field-specific language. Due to the flexibility of DSL, it can be customized according to the requirements of different fields, thereby improving the flexibility and accuracy of generating SQL statements, simplifying the SQL generation process, and helping to reduce the possibility of errors. In particular, for users who are not familiar with SQL syntax, a more friendly and intuitive way to interact with the database is provided.

[0087] On the basis of the above implementation, it is optional to add additional information to the generated SQL statements. For example, specify the tablespace, select the appropriate storage engine, etc. In the entire SQL generation process, the compatibility of SQL statements with various database platforms can also be considered, while making them easy to read and understand, and complying with the coding standards within the team. In the implementation of SQL generation, an error handling mechanism can be considered to ensure that abnormal situations are handled in a timely manner and relevant log information is recorded. In this way, the parsed metadata can be effectively converted into executable SQL statements, providing important support for the management and maintenance of database objects.

[0088] On the basis of the above implementation, optionally, after generating the corresponding reverse SQL statement according to the DSL language and the original SQL statement, it also includes: performing data formatting processing on the reverse SQL statement, the data formatting processing includes: structuring the data layout; determining the output method of the reverse SQL statement according to the needs, the output method includes: text file, database table, report and direct application interface output; outputting the reverse SQL statement according to the data formatting processing result and the output method.

[0089] Formatted output is to present the processed data in a clear and readable form and output it to a specified location or system as needed. The structured layout in formatted output can involve formatting data types such as text, numbers or dates to ensure consistency and readability of the data.

[0090] When the output mode is text file output, you can consider line breaks, indentation, and adding appropriate separators to make the data layout clear and easy to read. When the output mode is database table or report output, you can design a suitable template according to the target format and fill the data into the corresponding position. At the same time, before output, you can also consider operations such as sorting, filtering or grouping of data so that the data can be presented in a final form that meets the requirements. When implementing the output process, you can also pay attention to the error handling mechanism to ensure that abnormal situations can be handled and relevant log information can be recorded. Through the data formatting processing results and output mode settings, the processed reverse SQL statements can be effectively presented and output to the specified location in a standardized manner, providing a neat and reliable data foundation for subsequent use and analysis.

[0091] Figure 3 FIG. 1 is a flowchart of another structured query language reverse generation method provided according to an embodiment of the present invention. Figure 3 As shown, the process of reversely generating SQL statements can be to extract metadata from the database, parse and process the metadata, reversely generate SQL, and format and output the reversely generated SQL statements. The technical solution of the embodiment of the present invention extracts metadata from the target database; parses and processes the metadata to obtain data of the target data structure; generates a domain-specific language DSL based on the data of the target data structure, and the DSL language is used to describe database requirements and data models; generates corresponding reverse SQL statements based on the DSL language and the original SQL statements, which solves the problem of automatic generation of SQL statements in database management. Reversely generating SQL statements through the DSL language simplifies the SQL statement writing process, reduces the writing difficulty, is conducive to the management and rollback of the database, and is conducive to simplifying the database migration and synchronization process.

[0092] When the generated SQL script is applied to the target database, automatic database initialization can be achieved. In the backup and recovery scenario, you can first clear or create a new database instance, and then execute the reverse-generated SQL statement to quickly restore the database structure and data to the state at the time of backup. In order to ensure the correctness and execution efficiency of the reverse-generated SQL statement, you can also introduce script optimization algorithms, such as statement reordering and batch insertion. At the same time, you can also provide a script verification tool to allow users to preview and verify the SQL script before execution to ensure the accuracy of the recovery process.

[0093] The MySQL-based SQL reverse generation method provided by the embodiment of the present invention significantly simplifies the process of database initialization and backup recovery, and reduces the complexity and error rate of manual operation. By automatically generating SQL statements, not only the work efficiency is improved, but also the consistency of database structure and data is guaranteed. It is particularly suitable for large-scale or frequently changing database environments, and has high practical value and promotion prospects.

[0094] In order to verify the effect of the present invention, the inventor selected a medium-sized database containing dozens of tables for experiment. The results show that compared with traditional manual operation, the reverse generation of SQL statements using the method of the present invention can shorten the database initialization time by more than 80%, the accuracy of backup and recovery reaches 100%, and no data loss or erroneous insertion was found in multiple tests, which fully proves its effectiveness and reliability. In summary, the present invention provides an efficient and reliable SQL reverse generation method, which provides a new solution for database initialization and backup and recovery. This method is not only applicable to MySQL databases, but can also be applied to other relational database systems after appropriate adjustments, and has broad application prospects.

[0095] Figure 4 Schematic diagram of a structured query language reverse generation device provided according to an embodiment of the present invention. Figure 4 As shown, the device includes: a metadata processing module 410, a DSL generation module 420 and a reverse SQL statement generation module 430. Among them:

[0096] The metadata processing module 410 is used to extract metadata from the target database; and parse and process the metadata to obtain data of the target data structure;

[0097] A DSL generation module 420 is used to generate a domain specific language DSL according to the data of the target data structure, where the DSL language is used to describe database requirements and data models;

[0098] The reverse SQL statement generating module 430 is used to generate a corresponding reverse SQL statement according to the DSL language and the original SQL statement.

[0099] Optionally, the reverse SQL statement generating module 430 includes:

[0100] AST generation unit, used to convert DSL language into abstract syntax tree AST through DSL parser. AST is used to show the relationship between data tables and field attributes.

[0101] The reverse SQL statement generation unit is used to generate corresponding reverse SQL statements according to AST, original SQL statements, and database convention rules.

[0102] Optional, reverse SQL statement generation unit, specifically used for:

[0103] Parse the AST to obtain the table name, field, and corresponding value involved in the operation corresponding to the original SQL statement;

[0104] Based on the AST parsing results, determine the reverse operation corresponding to the reverse SQL statement and the reverse operation generation conditions;

[0105] Generate a reverse SQL statement according to the reverse operation and the reverse operation generation condition.

[0106] Optional, database convention rules, including: structure definition statements, and initial data insertion statements;

[0107] The structure definition statements include: table creation statements, primary key setting statements, and foreign key constraint statements.

[0108] Optionally, the metadata processing module 410 includes:

[0109] The metadata processing unit is used to parse and process the relationships between tables, between tables and views, and foreign key relationships in the metadata to obtain data of the target data structure.

[0110] Optionally, the device further includes:

[0111] The formatting processing module is used to perform data formatting processing on the reverse SQL statement after generating the corresponding reverse SQL statement according to the DSL language and the original SQL statement. The data formatting processing includes: structuring the data layout;

[0112] The output mode determination module is used to determine the output mode of the reverse SQL statement according to the requirements. The output modes include: text file, database table, report and direct application program interface output;

[0113] The reverse SQL statement output module is used to output the reverse SQL statement according to the data formatting processing result and the output mode.

[0114] The SQL reverse generation device provided in the embodiment of the present invention can execute the SQL reverse generation method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0115] Figure 5 A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.

[0116] like Figure 5 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0117] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0118] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The processor 11 executes the various methods and processes described above, such as the structured query language reverse generation method.

[0119] In some embodiments, the structured query language reverse generation method can be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the structured query language reverse generation method described above can be performed. Alternatively, in other embodiments, the processor 11 can be configured to execute the structured query language reverse generation method in any other appropriate manner (for example, by means of firmware).

[0120] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0121] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0122] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0123] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).

[0124] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0125] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.

[0126] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.

[0127] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A structured query language reverse generation method, characterized in that: include: Extract metadata from the target database; and parsing and processing the metadata to obtain data of the target data structure; Generate a domain specific language DSL according to the data of the target data structure, where the DSL language is used to describe database requirements and data models; Generate corresponding reverse SQL statements based on the DSL language and the original structured query language SQL statement.

2. The method according to claim 1, characterized in that Generate the corresponding reverse SQL statements based on the DSL language and the original structured query language SQL statements, including: The DSL language is converted into an abstract syntax tree (AST) through a DSL parser. The AST is used to display the relationship between data tables and field attributes. Generate the corresponding reverse SQL statement based on AST, original SQL statement, and database convention rules.

3. The method according to claim 2, characterized in that Generate the corresponding reverse SQL statement based on AST, original SQL statement, and database convention rules, including: Parse the AST to obtain the table name, field, and corresponding value involved in the operation corresponding to the original SQL statement; Based on the AST parsing results, determine the reverse operation corresponding to the reverse SQL statement and the reverse operation generation conditions; A reverse SQL statement is generated according to the reverse operation and the reverse operation generation condition.

4. The method according to claim 2, characterized in that: The database convention rules include: structure definition statements and initial data insertion statements; The structure definition statements include: table creation statements, primary key setting statements, and foreign key constraint statements.

5. The method according to claim 1, characterized in that Parse and process the metadata to obtain data of the target data structure, including: The relationships between tables, between tables and views, and between foreign keys in the metadata are parsed and processed to obtain data of the target data structure.

6. The method according to claim 1, characterized in that After generating the corresponding reverse SQL statement according to the DSL language and the original structured query language SQL statement, it also includes: Performing data formatting processing on the reverse SQL statement, the data formatting processing comprising: structuring the data layout; Determine the output method of the reverse SQL statement according to the requirements, the output method includes: text file, database table, report and direct application program interface output; According to the data formatting processing result and the output method, a reverse SQL statement is output.

7. A structured query language reverse generation device, characterized in that: include: A metadata processing module, used to extract metadata from a target database; and parsing and processing the metadata to obtain data of the target data structure; A DSL generation module, used to generate a domain specific language DSL according to the data of the target data structure, where the DSL language is used to describe database requirements and data models; The reverse SQL statement generation module is used to generate corresponding reverse SQL statements according to the DSL language and the original structured query language SQL statement.

8. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the structured query language reverse generation method according to any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the structured query language reverse generation method according to any one of claims 1 to 6 when executed.

10. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the structured query language reverse generation method according to any one of claims 1 to 6.

Citation Information

Cited By

  • NL2SQL method and system based on large language model and retrieval enhancement

    CN121326959A