Online editing method, device and equipment for dynamic SQL (Structured Query Language) and medium

By providing dynamic SQL online editing methods, including real-time syntax verification and parsing, online debugging, saving and calling processes, the problem of real-time verification and parsing in MyBatis dynamic SQL editing methods is solved, and real-time effectiveness and efficient debugging of dynamic SQL scripts are achieved.

CN119847909AActive Publication Date: 2025-04-18FUJIAN ECAN INFORMATION TECH CO LTD
View PDF 9 Cites 0 Cited by

Patent Information

Application Number
CN202411623994.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-14
Publication Date
2025-04-18
Estimated Expiration
2044-11-14

AI Technical Summary

Technical Problem

The existing MyBatis dynamic SQL editing method has problems such as inability to verify the format and parse script parameters in real time, set business attribute values ​​dynamically, and perform dynamic debugging, resulting in inefficient development.

Method used

Provides an online editing method for dynamic SQL, including real-time syntax check and parsing, online debugging, saving and calling procedures, and supports online editing and real-time effect of MyBatis dynamic SQL scripts.

Benefits of technology

Realizes the real-time effect of dynamic SQL scripts, without restarting the application, improves debugging efficiency, and provides real-time verification and parsing functions, enhancing the maintainability of dynamic SQL.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119847909A_ABST
    Figure CN119847909A_ABST
Patent Text Reader

Abstract

The invention provides an online editing method, device and equipment for a dynamic SQL (Structured Query Language) and a medium. The method comprises a real-time grammar verification and analysis process, a debugging script online process, a storage process and a calling process. The method has the capabilities of checking formats and grammar in real time, analyzing parameters in the dynamic SQL in real time, dynamically debugging, dynamically loading, taking effect in real time and the like, and can execute the SQL according to set parameter values and data sources, so that the effects of checking whether the dynamic SQL grammar is correct or not and previewing in real time are achieved. And during execution, different types of dynamic SQL can be selected and executed automatically according to different types of data sources. The application does not need to be restarted, the dynamic SQL script can be edited on line and can take effect in real time, and the debugging efficiency is greatly improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method, device, equipment and medium for editing dynamic SQL. Background Art

[0002] MyBatis is an excellent persistence layer framework that supports custom SQL, stored procedures, and advanced mapping. Dynamic SQL is an important feature of MyBatis. In MyBatis, dynamic SQL allows us to write conditional statements in XML mapping files to determine the specific execution content of SQL based on runtime parameters.

[0003] Generally speaking, the dynamic SQL of MyBatis is stored in the project in the form of a file. If it needs to be modified, the file needs to be modified, the original file needs to be replaced, and the application needs to be restarted for the changed content to take effect. In this process, there are problems such as the inability to verify the format in real time, parse the script parameters, dynamically set the business attribute values, and perform dynamic debugging. And with multiple iterations, the mapper content becomes larger and more complex, which greatly reduces the maintainability. In addition, some simple format problems are often encountered, such as incorrect label syntax, writing an extra comma or semicolon, and incorrect table fields. It is impossible to correct and discover the errors in time, and the service needs to be restarted every time for debugging, which affects development efficiency. Summary of the invention

[0004] The technical problem to be solved by the present invention is to provide a method, device, equipment and medium for online editing of dynamic SQL, which can edit dynamic SQL scripts online and take effect in real time without restarting the application, thereby greatly improving debugging efficiency.

[0005] In a first aspect, the present invention provides an online editing method for dynamic SQL, including a real-time syntax checking and parsing process, an online process for debugging scripts, a saving process, a saving process, and a calling process;

[0006] The real-time syntax verification and parsing process includes: providing an online editing configuration interface, which supports the writing and formatting of MyBatis dynamic SQL script syntax and pure SQL syntax; after the user finishes writing the dynamic SQL script through the online editing configuration interface and clicks on parameter setting, the dynamic SQL script is verified by pre-generated SqlSource objects to see whether it conforms to the MyBatis syntax, and if not, a prompt is given; if yes, the reflection method is used in conjunction with regular expressions to parse out the parameter name and parameter type of the dynamic SQL script in real time (parameter types mainly include string, map, array, number, date and boolean types); then the parameter name, parameter type and parameter default value are displayed on the interface; a constant or variable of the parameter type is set according to the parameter default value, and the variable can be automatically changed according to changes in the business data currently operated by the system;

[0007] The script online debugging process includes: setting a parameter test value, transmitting the parameter test value together with the dynamic SQL script, the parameter name, the parameter type and the data source to the background; the background first checks whether the parameter test value matches the parameter type, if not, prompts that it does not match, and if so, assembles the dynamic SQL script into a string in xml format, and checks whether the string conforms to the xml format syntax; if not, prompts; if it conforms, sets the parameter to the parameter default value first, then sets the custom test value, and combines the two to generate a map type input object; uses the dynamic SQL script to generate the MappedStatement required for SQL execution, and then uses MyBatis to execute the dynamic script method with the msId corresponding to the MappedStatement and the map type input object; uses the currently transmitted data source to parse the dynamic script into an SQL statement that can be executed by the database, executes the SQL statement, and returns the SQL statement and the execution result to the front-end interface for display, thereby achieving the effect of online verification of whether the SQL syntax is correct;

[0008] The saving process includes: after debugging, saving the dynamic SQL script to the database, then immediately refreshing the dynamic SQL script content of the current server, and preloading the MappedStatement, while recording the modification time for service call;

[0009] The calling process includes: assembling an execution parameter map according to the executed dynamic SQL script, the configured default parameter value and the parameter value transmitted in real time, then obtaining the data source type according to the data source of the current business execution, searching for the dynamic SQL script of the data source type for execution, and if the search fails, using the general type script for execution to achieve the effect of real-time effectiveness.

[0010] In a second aspect, the present invention provides an online editing device for dynamic SQL, comprising:

[0011] Real-time syntax checking and parsing module: used to provide an online editing configuration interface, which supports the writing and formatting of MyBatis's dynamic SQL script syntax and pure SQL syntax; after the user finishes writing the dynamic SQL script through the online editing configuration interface and clicks on parameter setting, the pre-generated SqlSource object is used to check whether the dynamic SQL script conforms to the MyBatis syntax. If not, a prompt is given; if yes, the reflection method is used in conjunction with regular expressions to parse the parameter name and parameter type of the dynamic SQL script in real time (parameter types mainly include string, map, array, number, date and boolean types); then the parameter name, parameter type and parameter default value are displayed on the interface; the constant or variable of the parameter type is set according to the parameter default value, and the variable can automatically change according to the change of the business data currently operated by the system;

[0012] Script online debugging module: used to set parameter test values, and transmit the parameter test values ​​together with the dynamic SQL script, the parameter name, the parameter type and the data source to the background; the background first checks whether the parameter test value matches the parameter type, if not, prompts that it does not match, and if so, assembles the dynamic SQL script into a string in xml format, and checks whether the string conforms to the xml format syntax; if not, prompts; if it conforms, sets the parameter to the parameter default value first, then sets the custom test value, and combines the two to generate a map type input parameter object; uses the dynamic SQL script to generate the MappedStatement required for SQL execution, and then uses MyBatis to execute the dynamic script method with the msId and map type parameters corresponding to the MappedStatement; uses the currently transmitted data source to parse the dynamic script tag into an SQL statement that can be executed by the database, executes the SQL statement, and returns the SQL statement and the execution result to the front-end interface for display, thereby achieving the effect of online verification of whether the SQL syntax is correct;

[0013] The saving module is used to save the dynamic SQL script to the database after debugging, and then immediately refresh the dynamic SQL script content of the current server, preload the MappedStatement, and record the modification time for service calls;

[0014] Calling process module: It is used to assemble the execution parameter map according to the executed dynamic SQL script, the configured default parameter value and the parameter value transmitted in real time, and then obtain the data source type according to the data source of the current business execution, and search for the dynamic SQL script of the data source type for execution. If the search fails, the general type script is used for execution to achieve the effect of real-time effectiveness.

[0015] In a third aspect, the present invention provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method described in the first aspect when executing the program.

[0016] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in the first aspect.

[0017] The one or more technical solutions provided by the present invention have at least the following technical effects or advantages: based on online editing of dynamic SQL scripts, it can take effect in real time, reduce the debugging time of developers, speed up the iteration of software, and meet the needs of business. In the process of writing dynamic SQL, a series of auxiliary functions are provided, such as real-time verification format and syntax, real-time analysis of parameters in dynamic SQL, script formatting, historical record viewing, and generating commonly used dynamic SQL scripts based on table structure and dynamic loading, while supporting real-time execution of SQL according to set parameter values ​​and selected data sources, so as to achieve checking whether the dynamic SQL syntax is correct and whether the test execution result meets expectations, providing great convenience for the writing of dynamic SQL, and greatly improving the scalability of application. In addition, the system also supports saving dynamic SQL as different database type scripts (such as mysql, oracle, dameng, etc.), and can automatically select different types of dynamic SQL according to different types of data sources during execution, which provides convenience for the use of applications in heterogeneous databases.

[0018] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] The present invention will be further described below in conjunction with embodiments with reference to the accompanying drawings.

[0020] Figure 1 is a flow chart of the method in Embodiment 1 of the present invention;

[0021] Figure 2 A flowchart of a process for writing dynamic SQL in an embodiment of the present invention;

[0022] Figure 3 A flowchart of a real-time grammar checking and parsing process according to an embodiment of the present invention;

[0023] Figure 4 A flowchart of the script online debugging process of an embodiment of the present invention;

[0024] Figure 5 A flowchart of the saving process and the calling process of the embodiment of the present invention;

[0025] Figure 6 It is a structural schematic diagram of the device in the second embodiment of the present invention;

[0026] Figure 7 This is a schematic diagram of the structure of an electronic device in Embodiment 3 of the present invention;

[0027] Figure 8 Schematic diagram of the structure of the medium in the fourth embodiment of the present invention. DETAILED DESCRIPTION

[0028] The embodiments of the present application provide a method, apparatus, device and medium for online editing of dynamic SQL, which can edit dynamic SQL scripts online and take effect in real time without restarting the application, thereby greatly improving debugging efficiency.

[0029] The technical solution in the embodiment of the present application has the following general idea: a solution for online management and configuration of dynamic SQL is proposed, including real-time syntax verification and parsing process, online process of debugging scripts, saving process and calling process; it has the capabilities of real-time format verification and syntax, real-time parsing of parameters in dynamic SQL, dynamic debugging, dynamic loading, real-time effectiveness, etc., and can execute SQL according to the set parameter values ​​and data sources, so as to achieve the effect of checking whether the dynamic SQL syntax is correct and real-time preview. When executing, it can automatically choose to execute different types of dynamic SQL according to different types of data sources. After debugging, SQL can also be saved as different database types, such as mysql, oracle, DAMO, etc., and when executing, it can automatically choose to execute different types of dynamic SQL according to different types of data sources.

[0030] Embodiment 1

[0031] like Figure 1 As shown, this embodiment provides an online editing method for dynamic SQL, including a dynamic SQL writing process, a real-time syntax checking and parsing process, a script online debugging process, a saving process, and a calling process.

[0032] like Figure 2As shown, the writing process of the dynamic SQL includes: the system provides online selection of a table, obtains the relevant information of this online table through the database, including the table name, primary key and field; selects the pre-configured dynamic SQL script template as needed; replaces the variables in the template with the relevant information of the online table with the help of freemarker variable replacement capability; and generates dynamic SQL in batches. This method can reduce the repetitive work of developing common scripts and improve development efficiency. At the same time, the system also supports dynamic SQL scripts that can have built-in preset fields, such as creator, creation time, operator, operation time, etc. During use, the built-in preset fields are replaced with actual fields such as creator, creation time, operator, operation time, etc. through parameter replacement. The system can recognize the current environment data for dynamic assignment without the need for developers to process, so that developers can focus more on the development of business functions. By using the preset field method, the script content size can be reduced to a certain extent, and the maintainability of dynamic SQL can be increased. And the generated dynamic SQL can support functions such as dynamic parsing parameters, parameter setting, real-time preview, and dynamic loading.

[0033] like Figure 3 As shown, the real-time syntax verification and parsing process includes: providing an online editing configuration interface, which supports the writing and formatting of MyBatis's dynamic SQL script syntax and pure SQL syntax; after the user finishes writing the dynamic SQL script through the online editing configuration interface and clicks on parameter setting, the dynamic SQL script is verified by pre-generated SqlSource objects to see whether it conforms to the MyBatis syntax, and if not, a prompt is given; if yes, the reflection method is used in conjunction with regular expressions to parse out the parameter name and parameter type of the dynamic SQL script in real time, and the parameter types mainly include string, map, array, number, date and boolean types; then the parameter name, the parameter type and the parameter default value are displayed on the interface; the constant or variable of the parameter type is set according to the parameter default value, and the variable can automatically change according to the change of the business data currently operated by the system.

[0034] Among them, parameter default values ​​support the setting of constants and variables. Constants are set according to parameter types, such as abc for strings, and {"name":"lilei","age":20} for map types. Variables use built-in variables, such as business year, month, and date, current operating user, and organization number to set default values. Built-in variable values ​​can automatically obtain current variable values ​​based on the business data currently operated by the system, and as business data changes, variable values ​​can automatically change, so variable values ​​are also called business values. This method is more flexible than setting default values ​​directly in SQL scripts and can reduce some code.

[0035] After setting the parameter data, click on the online script debugging to enter the script online debugging process. Figure 4 As shown, the script online debugging process includes: setting the parameter test value, transmitting the parameter test value together with the dynamic SQL script, the parameter name, the parameter type and the data source to the background; the background first checks whether the parameter test value matches the parameter type, if not, prompts that it does not match, and if so, assembles the dynamic SQL script into a string in xml format, and checks whether the string conforms to the xml format syntax; if not, prompts, adjusts the dynamic SQL script and debugs online again; if it conforms, sets the parameter to the parameter default value first, then sets the custom test value, and combines the two to generate a map type input object, so that the ability to debug using the default value without setting the test value can be achieved. Use the dynamic SQL script to generate the MappedStatement required for SQL execution, and then use MyBatis to execute the dynamic script method with the msId corresponding to the MappedStatement and the map type input object; use the currently transmitted data source to parse the dynamic script into a SQL statement that the database can execute, execute the SQL statement, and return the SQL statement and the execution result to the front-end interface for display, so as to achieve the effect of online verification of whether the SQL syntax is correct.

[0036] The saving process includes: after the online debugging of the dynamic SQL script is completed, the dynamic SQL script is saved to the database, and then the dynamic SQL script content of the current server is immediately refreshed, and the MappedStatement is preloaded, and the modification time is recorded at the same time, so that other cluster services can call it, and the dynamic SQL script changes can be monitored, thereby updating the cache of the service, so that other services can use the dynamic SQL script normally. When the dynamic SQL script is saved to the database, the dynamic SQL script is also set as a running script for different types of databases to support the use of different heterogeneous database environments, or is set as a general type script to be applicable to all database executions. After saving, the version record corresponding to the dynamic SQL script is also stored for historical version backtracking and one-click restoration of historical versions.

[0037] like Figure 5As shown, the calling process includes: assembling an execution parameter map according to the executed dynamic SQL script, the configured default parameter value and the parameter value transmitted in real time, then obtaining the data source type according to the data source of the current business execution, searching for the dynamic SQL script of the data source type for execution, and if the search fails, using the general type script for execution, after finding the script to be executed, using the pre-loaded MappedStatement to execute the dynamic SQL script, so as to achieve the effect of real-time effectiveness.

[0038] In the process of executing the dynamic SQL script, it will first check whether the set parameter type is consistent with the type of the parameter value transmitted in real time, and if not, a prompt will be given to avoid index failure due to inconsistency, thereby improving execution efficiency.

[0039] Embodiment 2

[0040] Based on the same inventive concept, the present application also provides a device corresponding to the method in Example 1, see Example 2 for details.

[0041] like Figure 6 As shown, in this embodiment, a dynamic SQL online editing device is provided, including:

[0042] like Figure 2 As shown, the dynamic SQL writing module is used to generate dynamic SQL in batches. Specifically, the relevant information of an online table, including table name, primary key and field, is obtained through the database; a pre-configured dynamic SQL script template is selected as needed; and with the help of freemarker variable replacement capability, the relevant information of the online table is used to replace the variables in the template to generate dynamic SQL in batches.

[0043] like Figure 3 As shown, the real-time syntax verification and parsing module is used to provide an online editing configuration interface, which supports the writing and formatting of MyBatis dynamic SQL script syntax and pure SQL syntax; after the user finishes writing the dynamic SQL script through the online editing configuration interface and clicks on the parameter setting, the dynamic SQL script is verified by the pre-generated SqlSource object to see if it conforms to the MyBatis syntax, and if not, a prompt is given; if yes, the reflection method is used in conjunction with regular expressions to parse the parameter name and parameter type of the dynamic SQL script in real time (parameter types mainly include string, map, array, number, date and boolean types); then the parameter name, parameter type and parameter default value are displayed on the interface; the constant or variable of the parameter type is set according to the parameter default value, and the variable can automatically change according to the change of the business data currently operated by the system;

[0044] like Figure 4 As shown, the script online debugging module is used to set the parameter test value, and transmit the parameter test value together with the dynamic SQL script, the parameter name, the parameter type and the data source to the background; the background first checks whether the parameter test value matches the parameter type, if not, prompts that it does not match, and if so, assembles the dynamic SQL script into a string in xml format, and checks whether the string conforms to the xml format syntax; if not, prompts; if it conforms, sets the parameter to the parameter default value first, then sets the custom test value, and combines the two to generate a map type input object; uses the dynamic SQL script to generate the MappedStatement required for SQL execution, and then uses MyBatis to execute the dynamic script method with the msId corresponding to the MappedStatement and the map type parameters; uses the currently transmitted data source to parse the dynamic script tag into an SQL statement that can be executed by the database, executes the SQL statement, and returns the SQL statement and the execution result to the front-end interface for display, thereby achieving the effect of online verification of whether the SQL syntax is correct;

[0045] The saving module is used to save the dynamic SQL script to the database after debugging, and then immediately refresh the dynamic SQL script content of the current server, preload the MappedStatement, and record the modification time for service calls; when the saving module saves the dynamic SQL script to the database, it also sets the dynamic SQL script as a running script for different types of databases or as a general type script; after saving, it also stores the version record corresponding to the dynamic SQL script for historical version backtracking and one-click restoration of historical versions.

[0046] like Figure 5 As shown, the calling process module is used to assemble an execution parameter map according to the executed dynamic SQL script, the configured default parameter value and the parameter value transmitted in real time, and then obtain the data source type according to the data source of the current business execution, and search for the dynamic SQL script of the data source type for execution. If the search fails, the general type script is used for execution to achieve the effect of real-time effectiveness.

[0047] When executing the dynamic SQL script, the calling process module will first check whether the set parameter type is consistent with the type of the parameter value transmitted in real time. If they are inconsistent, a prompt will be given.

[0048] Since the device introduced in the second embodiment of the present invention is a device used to implement the method of the first embodiment of the present invention, those skilled in the art can understand the specific structure and deformation of the device based on the method introduced in the first embodiment of the present invention, so it is not described here in detail. All devices used in the method of the first embodiment of the present invention belong to the scope of protection of the present invention.

[0049] Embodiment 3

[0050] Based on the same inventive concept, the present application provides an electronic device embodiment corresponding to the first embodiment, see the third embodiment for details. This embodiment provides an electronic device, such as Figure 7 As shown, it includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, any implementation method in the first embodiment can be implemented.

[0051] Since the electronic device introduced in this embodiment is a device used to implement the method in the first embodiment of the present application, based on the method introduced in the first embodiment of the present application, a person skilled in the art can understand the specific implementation of the electronic device of the present embodiment and its various variations, so how the electronic device implements the method in the embodiment of the present application is not described in detail here. As long as a person skilled in the art implements the device used by the method in the embodiment of the present application, it belongs to the scope of protection of the present application.

[0052] Embodiment 4

[0053] Based on the same inventive concept, this application provides a storage medium corresponding to Embodiment 1, see Embodiment 4 for details. This embodiment provides a computer-readable storage medium, such as Figure 8 As shown, a computer program is stored thereon, and when the computer program is executed by a processor, any implementation method in Example 1 can be implemented.

[0054] Although the specific implementation modes of the present invention are described above, those skilled in the art should understand that the specific implementation modes described are only illustrative and are not intended to limit the scope of the present invention. Equivalent modifications and changes made by those skilled in the art in accordance with the spirit of the present invention should be included in the scope of protection of the claims of the present invention.

Claims

1. A method for online editing of dynamic SQL, characterized in that: Including real-time syntax checking and parsing process, online script debugging process, saving process and calling process; The real-time syntax verification and parsing process includes: providing an online editing configuration interface, which supports the writing and formatting of MyBatis dynamic SQL script syntax and pure SQL syntax; after the user finishes writing the dynamic SQL script through the online editing configuration interface and clicks on parameter setting, the dynamic SQL script is verified by pre-generated SqlSource objects to see whether it conforms to MyBatis syntax, and if not, a prompt is given; if yes, the reflection method is used in conjunction with regular expressions to parse out the parameter name and parameter type of the dynamic SQL script in real time; then the parameter name, the parameter type and the parameter default value are displayed on the interface; a constant or variable of the parameter type is set according to the parameter default value, and the variable can be automatically changed according to the change of the business data currently operated by the system; The script online debugging process includes: setting a parameter test value, transmitting the parameter test value together with the dynamic SQL script, the parameter name, the parameter type and the data source to the background; the background first checks whether the parameter test value matches the parameter type, if not, prompts that it does not match, and if so, assembles the dynamic SQL script into a string in xml format, and checks whether the string conforms to the xml format syntax; if not, prompts; if it conforms, sets the parameter to the parameter default value first, then sets the custom test value, and combines the two to generate a map type input object; uses the dynamic SQL script to generate the MappedStatement required for SQL execution, and then uses MyBatis to execute the dynamic script method with the msId corresponding to the MappedStatement and the map type input object; uses the currently transmitted data source to parse the dynamic script into an SQL statement that can be executed by the database, executes the SQL statement, and returns the SQL statement and the execution result to the front-end interface for display, thereby achieving the effect of online verification of whether the SQL syntax is correct; The saving process includes: after debugging, saving the dynamic SQL script to the database, then immediately refreshing the dynamic SQL script content of the current server, and preloading the MappedStatement, while recording the modification time for service call; The calling process includes: assembling an execution parameter map according to the executed dynamic SQL script, the configured default parameter value and the parameter value transmitted in real time, then obtaining the data source type according to the data source of the current business execution, searching for the dynamic SQL script of the data source type for execution, and if the search fails, using the general type script for execution to achieve the effect of real-time effectiveness.

2. The online editing method of dynamic SQL according to claim 1, characterized in that: It also includes a dynamic SQL writing process, which includes: obtaining relevant information of an online form through a database, including table name, primary key and field; selecting a pre-configured dynamic SQL script template as needed; using freemarker variable replacement capability to replace variables in the template with relevant information of the online form; and generating dynamic SQL in batches.

3. The online editing method of dynamic SQL according to claim 1, characterized in that: When the dynamic SQL script is saved to the database, the dynamic SQL script is also set as a running script for different types of databases or as a general type script; after saving, the version record corresponding to the dynamic SQL script is also stored for historical version backtracking and one-click restoration of historical versions.

4. The online editing method of dynamic SQL according to claim 3, characterized in that: During the execution of the dynamic SQL script, it is first checked whether the set parameter type is consistent with the type of the parameter value transmitted in real time. If they are inconsistent, a prompt is given.

5. An online editing device for dynamic SQL, characterized in that: include: Real-time syntax checking and parsing module: used to provide an online editing configuration interface, which supports the writing and formatting of MyBatis' dynamic SQL script syntax and pure SQL syntax; After the user finishes writing the dynamic SQL script through the online editing configuration interface and clicks on parameter setting, the pre-generated SqlSource object is used to check whether the dynamic SQL script conforms to the MyBatis syntax. If not, a prompt is given; if yes, the reflection method is used in conjunction with regular expressions to parse the parameter name and parameter type of the dynamic SQL script in real time; then the parameter name, parameter type and parameter default value are displayed on the interface; the constant or variable of the parameter type is set according to the parameter default value, and the variable can be automatically changed according to the change of the business data currently operated by the system; Script online debugging module: used to set parameter test values, and transmit the parameter test values ​​together with the dynamic SQL script, the parameter name, the parameter type and the data source to the background; The backend first checks whether the parameter test value matches the parameter type. If not, it prompts that it does not match. If so, the dynamic SQL script is assembled into a string in XML format, and the string is checked to see if it conforms to the XML format syntax. If not, it prompts. If it conforms, the parameter is first set to the parameter default value, and then the custom test value is set, and the two are combined to generate a map type input parameter object. The dynamic SQL script is used to generate the MappedStatement required for SQL execution, and then the msId corresponding to the MappedStatement and the map type parameters are used by MyBatis to execute the dynamic script method. Using the currently transmitted data source, the dynamic script tag is parsed into an SQL statement that can be executed by the database, the SQL statement is executed, and the SQL statement and the execution result are returned to the front-end interface for display, thereby achieving the effect of online verification of whether the SQL syntax is correct; The saving module is used to save the dynamic SQL script to the database after debugging, and then immediately refresh the dynamic SQL script content of the current server, preload the MappedStatement, and record the modification time for service calls; Calling process module: It is used to assemble the execution parameter map according to the executed dynamic SQL script, the configured default parameter value and the parameter value transmitted in real time, and then obtain the data source type according to the data source of the current business execution, and search for the dynamic SQL script of the data source type for execution. If the search fails, the general type script is used for execution to achieve the effect of real-time effectiveness.

6. The online editing device for dynamic SQL according to claim 5, characterized in that: Also includes: The dynamic SQL writing module is used to generate dynamic SQL in batches. Specifically, the relevant information of an online table, including table name, primary key and field, is obtained from the database; a pre-configured dynamic SQL script template is selected as needed; and the variables in the template are replaced with the relevant information of the online table by means of freemarker variable replacement capability to generate dynamic SQL in batches.

7. The online editing device for dynamic SQL according to claim 5, characterized in that: When the saving module saves the dynamic SQL script to the database, it also sets the dynamic SQL script as a running script for different types of databases or as a general type script; after saving, it also stores the version record corresponding to the dynamic SQL script for historical version backtracking and one-click restoration of historical versions.

8. The online editing device for dynamic SQL according to claim 5, characterized in that: When executing the dynamic SQL script, the calling process module will first check whether the set parameter type is consistent with the type of the parameter value transmitted in real time. If they are inconsistent, a prompt will be given.

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: When the processor executes the program, the method according to any one of claims 1 to 4 is implemented.

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

Citation Information

Patent Citations

  • Dynamic query method and system

    CN111259042A

  • Functional SQL query method and device supporting dynamic variables, equipment and medium

    CN111984669A

  • Data service API implementation method and device based on MyBatis

    CN114816363A

  • Method for realizing configurable dynamic SQL (Structured Query Language) based on Mybatis

    CN116561157A

  • Method for online integrating SQL (Structured Query Language) based on low-code platform

    CN118860361A