WO2021022702A1 - Log insertion method and apparatus, computer apparatus and storage medium - Google Patents

Log insertion method and apparatus, computer apparatus and storage medium Download PDF

Info

Publication number
WO2021022702A1
WO2021022702A1 PCT/CN2019/117234 CN2019117234W WO2021022702A1 WO 2021022702 A1 WO2021022702 A1 WO 2021022702A1 CN 2019117234 W CN2019117234 W CN 2019117234W WO 2021022702 A1 WO2021022702 A1 WO 2021022702A1
Authority
WO
WIPO (PCT)
Prior art keywords
command
statement
global variable
comment
sql statement
Prior art date
Application number
PCT/CN2019/117234
Other languages
French (fr)
Chinese (zh)
Inventor
李斌
Original Assignee
平安科技(深圳)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2021022702A1 publication Critical patent/WO2021022702A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/13File access structures, e.g. distributed indices
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/18File system types
    • G06F16/1805Append-only file systems, e.g. using logs or journals to store data
    • G06F16/1815Journaling file systems

Definitions

  • This application relates to the technical field of logs, and in particular to a log insertion method, device, computer device, and non-volatile readable storage medium.
  • the first aspect of the application provides a log insertion method, the method includes: setting a task configuration file, the task configuration file includes a first command comment statement, a second command comment statement, and a comment statement with the second command Corresponding SQL statement; read the first command comment statement, parse the command ID and command parameter of the first command comment statement; initialize the task configuration file according to the command ID and command parameter of the first command comment statement Corresponding global variable group; read the second command comment sentence, parse the command identifier and command parameter of the second command comment sentence, and determine the second command comment sentence according to the command identifier of the second command comment sentence If the category of the second command comment sentence is an insert command comment sentence, insert the command parameter of the insert command comment sentence into the log table through the global variable group, and the command parameter of the insert command comment sentence includes and Log information of the SQL statement corresponding to the insert command comment statement; read the SQL statement corresponding to the second command comment statement, execute the SQL statement; if the SQL statement fails to execute, generate an execution error of the SQL statement Information,
  • a second aspect of the present application provides a log insertion device, the device includes: a setting module for setting a task configuration file, the task configuration file includes a first command comment sentence, a second command comment sentence, and The SQL statement corresponding to the second command comment statement; the first parsing module is used to read the first command comment statement, and parse the command identifier and command parameters of the first command comment statement; the initialization module is used to The command identifier and command parameters of the first command comment statement initialize the global variable group corresponding to the task configuration file; the second parsing module is used to read the second command comment statement and parse the second command comment statement The command identifier and the command parameter are used to determine the type of the second command comment sentence according to the command identifier of the second command comment sentence; the first insert module is used to insert the command comment sentence if the type of the second command comment sentence , Insert the command parameter of the insert command comment sentence into the log table through the global variable group, the command parameter of the insert command comment sentence includes log information of the SQL sentence corresponding
  • a third aspect of the present application provides a computer device that includes a processor, and the processor is configured to implement the log insertion method when executing computer-readable instructions stored in a memory.
  • a fourth aspect of the present application provides a non-volatile readable storage medium having computer readable instructions stored thereon, and when the computer readable instructions are executed by a processor, the log insertion method is implemented.
  • This application can improve the efficiency of inserting SQL statement execution error information into the log table.
  • Fig. 1 is a flowchart of a log insertion method provided by an embodiment of the present application.
  • Figure 2 is a structural diagram of a log insertion device provided by an embodiment of the present application.
  • Fig. 3 is a schematic diagram of a computer device provided by an embodiment of the present application.
  • the log insertion method of this application is applied to one or more computer devices.
  • the computer device may be a computing device such as a desktop computer, a notebook, a palmtop computer, and a cloud server.
  • the computer device can interact with the user through a keyboard, a mouse, a remote control, a touch panel, or a voice control device.
  • FIG. 1 is a flowchart of a log insertion method provided in Embodiment 1 of the present application.
  • the log insertion method is applied to a computer device.
  • the log insertion method of this application is used to insert the log information of the SQL statement execution failure in the log table.
  • the log insertion method includes:
  • the task configuration file includes a first command comment statement, a second command comment statement, and a SQL (Structured Query Language) statement, the SQL statement and the second command comment
  • the sentence corresponds.
  • each task configuration file describes a database operation task, such as importing specified data into the database.
  • Each task configuration file includes one first command comment statement and multiple second command comment statements, and each second command comment statement corresponds to at least one SQL statement.
  • the structure of the task configuration file should satisfy: the first command comment sentence is the first sentence of the task configuration file, and the second command comment sentence is adjacent to its corresponding SQL sentence, And the second command comment statement is before its corresponding SQL statement. It can be detected whether the task configuration file meets the structural requirements, and if the task configuration file meets the structural requirements, the subsequent steps are executed. Otherwise, if the task configuration file does not meet the structural requirements, the process ends.
  • Each of the first command comment statement or the second command comment statement includes at least one command.
  • the command includes a command for updating the log table.
  • the command also includes a command for controlling the commit of the database transaction corresponding to the SQL statement.
  • the command may also include a command for controlling the output of log information.
  • the SQL statement is used to implement specific business logic of database operation tasks.
  • the task configuration file may also include other comment statements.
  • the task configuration file may also include SQL statement comment statements, which are used to explain the SQL statements in the task configuration file to facilitate users to understand the SQL statements.
  • comment recognition characters may be used to mark the first command comment sentence and the second command comment sentence.
  • the comment recognition character "-" may be used to indicate the first command comment sentence and the second command comment sentence. Therefore, if the code line includes a comment recognition character, the code line is the first command comment statement or the second command comment statement; if the code line does not include the comment recognition character, the code line is a SQL statement.
  • the command recognition characters of the first command comment sentence and the second command comment sentence may be the same or different.
  • the first command comment sentence includes a first command recognition character
  • the second command comment sentence includes a second command recognition character.
  • the commands in the first command comment sentence and the second command comment sentence can be marked with command recognition characters.
  • the command recognition character "-#" may be used to indicate the commands in the first command comment sentence and the second command comment sentence.
  • the first command comment sentence is the first sentence of the task configuration file, then the first sentence of the task configuration file is read.
  • the first command comment sentence includes a first command recognition character, and the first command comment sentence is read according to the first command recognition character.
  • the first command comment sentence has a fixed format, and the command identifier and command parameters of the first command comment sentence are parsed according to the format of the first command comment sentence.
  • the first command comment statement may include multiple command identifiers and multiple command parameters, where the command identifiers and command parameters have a one-to-one correspondence.
  • the command "@task_desc backup user table once a day” Used to set the task description as "Back up user table once a day”.
  • S103 Initialize the global variable group corresponding to the task configuration file according to the command identifier and the command parameter of the first command comment statement.
  • the initialization of the global variable group corresponding to the task configuration file according to the command identifier and the command parameter of the first command comment statement includes:
  • the command parameter corresponding to the command identifier of the first command comment sentence is assigned to the first command parameter in the global variable group.
  • the command identification of a command comment statement corresponds to the global variable.
  • the preset command identifier-global variable table is "@task_name-task_name; @autocommit-autocommit; @task_desc-task_desc”, indicating that the command identifiers "@task_name”, “@autocommit”, "@task_desc” correspond to
  • the global variables are "task_name”, "autocommit”, and "task_desc”.
  • the global variable group corresponding to the task configuration file contains the global variable "task_name” corresponding to the command identifier "@task_name” of the first command comment statement, and the global variable “autocommit” corresponding to the command identifier "@autocommit” containing the first command comment statement , And the global variable "task_desc” corresponding to the command identifier "@task_desc” containing the first command comment statement.
  • the command parameter "T001" corresponding to the command identifier "@task_name” of the first command comment statement is assigned to the global variable "task_name” corresponding to the command identifier of the first command comment statement in the global variable group, and the first command comment statement
  • the command parameter "true” corresponding to the command identifier "@autocommit” is assigned to the global variable “autocommit” corresponding to the command identifier of the first command comment statement in the global variable group
  • the command identifier "@task_desc” of the first command comment statement corresponds to
  • the command parameter "Backup user table once a day” is assigned to the global variable "task_desc” corresponding to the command identifier of the first command comment statement in the global variable group.
  • S104 Read the second command comment sentence, analyze the command identifier and command parameter of the second command comment sentence, and determine the type of the second command comment sentence according to the command identifier of the second command comment sentence.
  • the second command comment sentence includes a second command recognition character, and the second command comment sentence is read according to the second command recognition character.
  • the second command comment sentence has a fixed format, and the command identifier and command parameter of the second command comment sentence are parsed according to the format of the second command comment sentence.
  • the second command comment statement may include multiple command identifiers and multiple command parameters, where the command identifiers and the command parameters have a one-to-one correspondence.
  • the judging the category of the second command comment sentence according to the command identifier of the second command comment sentence includes:
  • the category of the second command comment sentence is an insert command comment sentence
  • the category of the second command comment sentence is a submit command comment sentence.
  • the inserting the command parameter of the insert command comment statement into the log table through the global variable group includes:
  • the first log insert statement is executed, and the global variable corresponding to the command identifier of the insert command comment statement in the global variable group is inserted into the log table.
  • the first log insert statement is executed, and the global variable corresponding to the command identifier of the command comment statement inserted in the global variable group is inserted into the log table.
  • the SQL sentence corresponding to the second command comment sentence is a code line that does not include the command recognition character and the comment recognition character.
  • Executing the SQL statement is to operate the database according to the SQL statement to realize the database operation task described in the task configuration file, such as importing given data into the database.
  • generating execution error information of the SQL statement includes:
  • a third execution error message is generated. If the parameters in the SQL statement are correct and the tables in the SQL statement are correct, it means that other errors have occurred during the execution of the SQL statement, and a third execution error message is generated.
  • the inserting the execution error information into the log table through the global variable group includes:
  • the log insertion method of the first embodiment sets a task configuration file, the task configuration file includes a first command comment statement, a second command comment statement, and a SQL statement corresponding to the second command comment statement; read the first Command comment sentence, parse the command identifier and command parameter of the first command comment sentence; initialize the global variable group corresponding to the task configuration file according to the command identifier and command parameter of the first command comment sentence; read the first command comment sentence Second command comment sentence, parse the command identifier and command parameter of the second command comment sentence, and judge the category of the second command comment sentence according to the command identifier of the second command comment sentence; if the second command comment sentence The category of the insert command comment statement is the insert command comment statement.
  • the command parameter of the insert command comment statement is inserted into the log table through the global variable group.
  • the command parameter of the insert command comment statement includes the SQL statement corresponding to the insert command comment statement.
  • Log information read the SQL statement corresponding to the second command comment statement, execute the SQL statement; if the SQL statement fails to execute, generate the execution error information of the SQL statement, and replace the execution error information of the SQL statement Assign a value to the global variable corresponding to the execution error information in the global variable group, and insert the execution error information into the log table through the global variable group.
  • the first embodiment can improve the efficiency of inserting SQL statement execution error information into the log table.
  • the method may further include:
  • the category of the second command comment sentence is a submit command comment sentence, it is determined whether the command parameter in the submit command comment sentence is "true";
  • the method may further include:
  • the method before the initialization of the global variable group corresponding to the task configuration file according to the command identifier and the command parameter of the first command comment statement, the method further includes:
  • command identifier in the first command comment sentence is included in the command identifier-global variable table, initialize the global variable group corresponding to the task configuration file according to the command identifier and command parameters of the first command comment sentence .
  • the method may further include:
  • the type of the second command comment sentence is determined according to the command identifier of the second command comment sentence.
  • Fig. 2 is a structural diagram of a log insertion device provided in the second embodiment of the present application.
  • the log insertion device 20 is applied to a computer device.
  • the log insertion of this device is to insert the log information of the SQL statement execution failure in the log table.
  • the log insertion device 20 may include a setting module 201, a first analysis module 202, an initialization module 203, a second analysis module 204, a first insertion module 205, and a second insertion module 206.
  • the setting module 201 is used to set a task configuration file.
  • the task configuration file includes a first command comment statement, a second command comment statement, and SQL (Structured Query Language) statements.
  • the comment statement of the second command corresponds to that.
  • each task configuration file describes a database operation task, such as importing specified data into the database.
  • Each task configuration file includes one first command comment statement and multiple second command comment statements, and each second command comment statement corresponds to at least one SQL statement.
  • the structure of the task configuration file should satisfy: the first command comment sentence is the first sentence of the task configuration file, and the second command comment sentence is adjacent to its corresponding SQL sentence, And the second command comment statement is before its corresponding SQL statement. It can be detected whether the task configuration file meets the structural requirements, and if the task configuration file meets the structural requirements, the subsequent steps are executed. Otherwise, if the task configuration file does not meet the structural requirements, the process ends.
  • Each of the first command comment statement or the second command comment statement includes at least one command.
  • the command includes a command for updating the log table.
  • the command also includes a command for controlling the commit of the database transaction corresponding to the SQL statement.
  • the command may also include a command for controlling the output of log information.
  • the SQL statement is used to implement specific business logic of database operation tasks.
  • the task configuration file may also include other comment statements.
  • the task configuration file may also include SQL statement comment statements, which are used to explain the SQL statements in the task configuration file, so as to facilitate users to understand the SQL statements.
  • comment recognition characters may be used to mark the first command comment sentence and the second command comment sentence.
  • the comment recognition character "-" may be used to indicate the first command comment sentence and the second command comment sentence. Therefore, if the code line includes a comment recognition character, the code line is the first command comment statement or the second command comment statement; if the code line does not include the comment recognition character, the code line is a SQL statement.
  • the command recognition characters of the first command comment sentence and the second command comment sentence may be the same or different.
  • the first command comment sentence includes a first command recognition character
  • the second command comment sentence includes a second command recognition character.
  • the commands in the first command comment sentence and the second command comment sentence can be marked with command recognition characters.
  • the command recognition character "-#" may be used to indicate the commands in the first command comment sentence and the second command comment sentence.
  • the first parsing module 202 is configured to read the first command comment sentence and parse the command identifier and command parameters of the first command comment sentence.
  • the first command comment sentence is the first sentence of the task configuration file, then the first sentence of the task configuration file is read.
  • the first command comment sentence includes a first command recognition character, and the first command comment sentence is read according to the first command recognition character.
  • the first command comment sentence has a fixed format, and the command identifier and command parameters of the first command comment sentence are parsed according to the format of the first command comment sentence.
  • the first command comment statement may include multiple command identifiers and multiple command parameters, where the command identifiers and command parameters have a one-to-one correspondence.
  • the command "@task_desc backup user table once a day” Used to set the task description as "Back up user table once a day”.
  • the initialization module 203 is configured to initialize the global variable group corresponding to the task configuration file according to the command identifier and the command parameter of the first command comment statement.
  • the initialization of the global variable group corresponding to the task configuration file according to the command identifier and the command parameter of the first command comment statement includes:
  • the command parameter corresponding to the command identifier of the first command comment sentence is assigned to the first command parameter in the global variable group.
  • the command identification of a command comment statement corresponds to the global variable.
  • the preset command identifier-global variable table is "@task_name-task_name; @autocommit-autocommit; @task_desc-task_desc”, indicating that the command identifiers "@task_name”, “@autocommit”, "@task_desc” correspond to
  • the global variables are "task_name”, "autocommit”, and "task_desc”.
  • the global variable group corresponding to the task configuration file contains the global variable "task_name” corresponding to the command identifier "@task_name” of the first command comment statement, and the global variable “autocommit” corresponding to the command identifier "@autocommit” containing the first command comment statement , And the global variable "task_desc” corresponding to the command identifier "@task_desc” containing the first command comment statement.
  • the command parameter "T001" corresponding to the command identifier "@task_name” of the first command comment statement is assigned to the global variable "task_name” corresponding to the command identifier of the first command comment statement in the global variable group, and the first command comment statement
  • the command parameter "true” corresponding to the command identifier "@autocommit” is assigned to the global variable “autocommit” corresponding to the command identifier of the first command comment statement in the global variable group
  • the command identifier "@task_desc” of the first command comment statement corresponds to
  • the command parameter "Backup user table once a day” is assigned to the global variable "task_desc” corresponding to the command identifier of the first command comment statement in the global variable group.
  • the second parsing module 204 is configured to read the second command comment sentence, parse the command identifier and command parameter of the second command comment sentence, and determine the second command according to the command identifier of the second command comment sentence The category of the comment statement.
  • the second command comment sentence includes a second command recognition character, and the second command comment sentence is read according to the second command recognition character.
  • the second command comment sentence has a fixed format, and the command identifier and command parameter of the second command comment sentence are parsed according to the format of the second command comment sentence.
  • the second command comment statement may include multiple command identifiers and multiple command parameters, where the command identifiers and the command parameters have a one-to-one correspondence.
  • the judging the category of the second command comment sentence according to the command identifier of the second command comment sentence includes:
  • the category of the second command comment sentence is an insert command comment sentence
  • the category of the second command comment sentence is a submit command comment sentence.
  • the first insert module 205 is configured to insert the command parameter of the insert command comment sentence into the log table through the global variable group if the type of the second command comment sentence is the insert command comment sentence, the insert command comment sentence
  • the command parameter of includes the log information of the SQL statement corresponding to the insert command comment statement.
  • the inserting the command parameter of the insert command comment statement into the log table through the global variable group includes:
  • the first log insert statement is executed, and the global variable corresponding to the command identifier of the insert command comment statement in the global variable group is inserted into the log table.
  • the first log insert statement is executed, and the global variable corresponding to the command identifier of the command comment statement inserted in the global variable group is inserted into the log table.
  • the second insert module 206 is configured to read the SQL statement corresponding to the second command comment statement, and execute the SQL statement.
  • the SQL sentence corresponding to the second command comment sentence is a code line that does not include the command recognition character and the comment recognition character.
  • Executing the SQL statement is to operate the database according to the SQL statement to realize the database operation task described in the task configuration file, such as importing given data into the database.
  • the second insert module 206 is further configured to generate execution error information of the SQL statement if the execution of the SQL statement fails, and assign the execution error information of the SQL statement to the execution error information corresponding to the global variable group The execution error information is inserted into the log table through the global variable group.
  • generating execution error information of the SQL statement includes:
  • a third execution error message is generated. If the parameters in the SQL statement are correct and the tables in the SQL statement are correct, it means that other errors have occurred during the execution of the SQL statement, and a third execution error message is generated.
  • the inserting the execution error information into the log table through the global variable group includes:
  • the log insertion device 20 of the second embodiment sets a task configuration file, the task configuration file includes a first command comment sentence, a second command comment sentence and a SQL sentence corresponding to the second command comment sentence; reads the first command comment sentence A command comment sentence, parsing the command identifier and command parameter of the first command comment sentence; initialize the global variable group corresponding to the task configuration file according to the command identifier and command parameter of the first command comment sentence; read the The second command comment sentence, parse the command identifier and command parameter of the second command comment sentence, and judge the category of the second command comment sentence according to the command identifier of the second command comment sentence; if the second command comment The category of the sentence is the insert command comment sentence, the command parameter of the insert command comment sentence is inserted into the log table through the global variable group, and the command parameter of the insert command comment sentence includes the SQL sentence corresponding to the insert command comment sentence Read the SQL statement corresponding to the comment statement of the second command, execute the SQL statement; if the SQL statement fails to execute, generate the execution error
  • the log insertion device 20 may further include: a submit module, configured to determine the command parameters in the submit command comment sentence if the type of the second command comment sentence is a submit command comment sentence Whether it is "true”; if the command parameter in the submit command comment statement is "true", then the database transaction corresponding to the SQL statement is submitted.
  • a submit module configured to determine the command parameters in the submit command comment sentence if the type of the second command comment sentence is a submit command comment sentence Whether it is "true”; if the command parameter in the submit command comment statement is "true", then the database transaction corresponding to the SQL statement is submitted.
  • the log insertion device 20 may further include: an output module, configured to determine whether the command parameter used to control the output of the log information in the first command comment statement if the SQL statement fails to execute Is "true”, if the command parameter used to control the output of log information in the first command comment statement is "true”, then the execution failure information of the SQL statement in the log table is output.
  • the log insertion device 20 may further include: a first judgment module configured to initialize the global corresponding to the task configuration file according to the command identifier and command parameters of the first command comment statement. Before the variable group, it is judged whether the command identifier in the first command comment sentence is included in the command identifier-global variable table. If the command identifier in the first command comment sentence is included in the command identifier-global variable table, the initialization module 203 initializes the task configuration file according to the command identifier and command parameters of the first command comment sentence The corresponding global variable group.
  • a first judgment module configured to initialize the global corresponding to the task configuration file according to the command identifier and command parameters of the first command comment statement.
  • the log insertion device 20 may further include: a second judgment module, configured to, before judging the category of the second command comment sentence according to the command identifier of the second command comment sentence, It is determined whether the command identifier in the second command comment sentence is included in the command identifier-global variable table. If the command identifier in the second command comment sentence is included in the command identifier-global variable table, the second parsing module 204 determines the second command comment according to the command identifier of the second command comment sentence The category of the statement.
  • a second judgment module configured to, before judging the category of the second command comment sentence according to the command identifier of the second command comment sentence, It is determined whether the command identifier in the second command comment sentence is included in the command identifier-global variable table. If the command identifier in the second command comment sentence is included in the command identifier-global variable table, the second parsing module 204 determines the second command comment according to the command identifier of the second command comment sentence The category of the statement
  • This embodiment provides a non-volatile readable storage medium having computer readable instructions stored on the non-volatile readable storage medium, and when the computer readable instructions are executed by a processor, the above log insertion method embodiment is implemented For example, the steps S101-S107 shown in FIG. 1; or, when the computer-readable instructions are executed by the processor, the functions of the modules in the above-mentioned device embodiment are realized, for example, the modules 201-206 in FIG.
  • FIG. 3 is a schematic diagram of a computer device provided in Embodiment 4 of this application.
  • the computer device 30 includes a memory 301, a processor 302, and computer-readable instructions 303 stored in the memory 301 and running on the processor 302, such as a log insertion program.
  • the processor 302 executes the computer-readable instruction 303, the steps in the log insertion method embodiment are implemented, for example, steps S101-S107 shown in FIG. 1; or, the computer-readable instruction is executed by the processor to implement the foregoing steps.
  • the function of each module in the device embodiment is, for example, the modules 201-206 in FIG. 2.
  • the computer-readable instruction 303 may be divided into one or more modules, and the one or more modules are stored in the memory 301 and executed by the processor 302 to complete the method .
  • the computer-readable instruction 303 can be divided into the setting module 201, the first analysis module 202, the initialization module 203, the second analysis module 204, the first insertion module 205, and the second insertion module 206 in FIG. 2.
  • the setting module 201 the first analysis module 202, the initialization module 203, the second analysis module 204, the first insertion module 205, and the second insertion module 206 in FIG. 2.
  • the computer-readable instruction 303 can be divided into the setting module 201, the first analysis module 202, the initialization module 203, the second analysis module 204, the first insertion module 205, and the second insertion module 206 in FIG. 2.
  • the first insertion module 205 the initialization module
  • the second insertion module 206 the second insertion module
  • the computer device 30 may be a computing device such as a desktop computer, a notebook, a palmtop computer, and a cloud server.
  • a computing device such as a desktop computer, a notebook, a palmtop computer, and a cloud server.
  • the schematic diagram 3 is only an example of the computer device 30 and does not constitute a limitation on the computer device 30. It may include more or less components than those shown in the figure, or combine certain components, or be different.
  • the computer device 30 may also include input and output devices, network access devices, buses, etc.
  • the so-called processor 302 may be a central processing unit (Central Processing Unit, CPU), other general-purpose processors, digital signal processors (Digital Signal Processor, DSP), application specific integrated circuits (ASIC), Field-Programmable Gate Array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc.
  • the general-purpose processor can be a microprocessor or the processor 302 can also be any conventional processor, etc.
  • the processor 302 is the control center of the computer device 30 and connects the entire computer device 30 with various interfaces and lines. Various parts.
  • the memory 301 may be used to store the computer-readable instructions 303, and the processor 302 executes or executes the computer-readable instructions or modules stored in the memory 301, and calls data stored in the memory 301 to implement Various functions of the computer device 30.
  • the memory 301 may mainly include a program storage area and a data storage area.
  • the program storage area may store an operating system, an application program required by at least one function (such as a sound playback function, an image playback function, etc.), etc.; The data created according to the use of the computer device 30 is stored.
  • the memory 301 may include non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a Secure Digital (SD) card, a flash memory card (Flash Card), At least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device.
  • non-volatile memory such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a Secure Digital (SD) card, a flash memory card (Flash Card), At least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device.
  • the integrated module of the computer device 30 may be stored in a non-volatile readable storage medium.
  • this application implements all or part of the processes in the above-mentioned embodiments and methods, and can also be completed by instructing relevant hardware through computer-readable instructions.
  • the computer-readable instructions can be stored in a non-volatile memory. In the read storage medium, when the computer-readable instructions are executed by the processor, the steps of the foregoing method embodiments can be implemented.
  • the computer-readable instructions may be in the form of source code, object code, executable file, or some intermediate forms, etc.
  • the non-volatile readable storage medium may include: any entity or device capable of carrying the computer-readable instruction code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, read-only memory (ROM, Read- Only Memory).

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

A log insertion method and a related device. The method comprises: setting a task configuration file; reading a first command annotation statement in the task configuration file; initializing a global variable group corresponding to the task configuration file according to a command identifier and a command parameter of the first command annotation statement; reading a second command annotation statement in the task configuration file, analyzing a command identifier and a command parameter of the second command annotation statement, and determining the type of the second command annotation statement according to the command identifier of the second command annotation statement; if the type of the second command annotation statement is an insertion command annotation statement, inserting the command parameter of the insertion command annotation statement into a log table by means of the global variable group; reading an SQL statement corresponding to the second command annotation statement in the task configuration file, and executing the SQL statement; and if the SQL statement fails to be executed, inserting execution error information into the log table by means of the global variable group. The efficiency of inserting the execution error information of the SQL statement into the log table can be improved.

Description

日志插入方法、装置、计算机装置及存储介质Log insertion method, device, computer device and storage medium
本申请要求于2019年08月07日提交中国专利局,申请号为201910727085.6申请名称为“日志插入方法、装置、计算机装置及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims to be submitted to the Chinese Patent Office on August 7, 2019. The application number is 201910727085.6. The application titled "Log insertion method, device, computer device and storage medium" is the priority of the Chinese patent application, the entire content of which is incorporated by reference In this application.
技术领域Technical field
本申请涉及日志技术领域,具体涉及一种日志插入方法、装置、计算机装置及非易失性可读存储介质。This application relates to the technical field of logs, and in particular to a log insertion method, device, computer device, and non-volatile readable storage medium.
背景技术Background technique
普通SQL脚本文件以及存储过程,如果要插入日志表。需要手工写相应插入语句,增加开发复杂度。在数据库开发过程中,经常出现SQL语句执行失败的情况。为了记录SQL语句执行失败的日志信息,开发人员需要在SQL脚本文件或存储过程中插入报错语句,从而产生了额外的工作量,增加了开发复杂度。因此,需要一种能够简单高效地记录SQL语句执行失败的日志信息的方法。Ordinary SQL script files and stored procedures, if you want to insert the log table. Need to manually write the corresponding insert statement, increasing the complexity of development. In the database development process, SQL statements often fail to execute. In order to record the log information of SQL statement execution failures, developers need to insert error statements in SQL script files or stored procedures, which generates additional workload and increases development complexity. Therefore, there is a need for a method that can simply and efficiently record the log information of the SQL statement execution failure.
发明内容Summary of the invention
鉴于以上内容,有必要提出一种日志插入方法、装置、计算机装置及非易失性可读存储介质,其可以提升将SQL语句执行错误信息插入日志表的效率。In view of the above, it is necessary to provide a log insertion method, device, computer device, and non-volatile readable storage medium, which can improve the efficiency of inserting SQL statement execution error information into the log table.
本申请的第一方面提供一种日志插入方法,所述方法包括:设定任务配置文件,所述任务配置文件包括第一命令注释语句,第二命令注释语句和与所述第二命令注释语句对应的SQL语句;读取所述第一命令注释语句,解析所述第一命令注释语句的命令标识和命令参数;根据所述第一命令注释语句的命令标识和命令参数初始化所述任务配置文件对应的全局变量组;读取所述第二命令注释语句,解析所述第二命令注释语句的命令标识和命令参数,根据所述第二命令注释语句的命令标识判断所述第二命令注释语句的类别;若所述第二命令注释语句的类别为插入命令注释语句,通过所述全局变量组将所述插入命令注释语句的命令参数插入日志表,所述插入命令注释语句的命令参数包括与所述插入命令注释语句对应的SQL语句的日志信息;读取所述第二命令注释语句对应的SQL语句,执行所述SQL语句;若所述 SQL语句执行失败,生成所述SQL语句的执行错误信息,将所述SQL语句的执行错误信息赋值给所述全局变量组中所述执行错误信息对应的全局变量,通过所述全局变量组将所述执行错误信息插入所述日志表。The first aspect of the application provides a log insertion method, the method includes: setting a task configuration file, the task configuration file includes a first command comment statement, a second command comment statement, and a comment statement with the second command Corresponding SQL statement; read the first command comment statement, parse the command ID and command parameter of the first command comment statement; initialize the task configuration file according to the command ID and command parameter of the first command comment statement Corresponding global variable group; read the second command comment sentence, parse the command identifier and command parameter of the second command comment sentence, and determine the second command comment sentence according to the command identifier of the second command comment sentence If the category of the second command comment sentence is an insert command comment sentence, insert the command parameter of the insert command comment sentence into the log table through the global variable group, and the command parameter of the insert command comment sentence includes and Log information of the SQL statement corresponding to the insert command comment statement; read the SQL statement corresponding to the second command comment statement, execute the SQL statement; if the SQL statement fails to execute, generate an execution error of the SQL statement Information, the execution error information of the SQL statement is assigned to the global variable corresponding to the execution error information in the global variable group, and the execution error information is inserted into the log table through the global variable group.
本申请的第二方面提供一种日志插入装置,所述装置包括:设定模块,用于设定任务配置文件,所述任务配置文件包括第一命令注释语句,第二命令注释语句和与所述第二命令注释语句对应的SQL语句;第一解析模块,用于读取所述第一命令注释语句,解析所述第一命令注释语句的命令标识和命令参数;初始化模块,用于根据所述第一命令注释语句的命令标识和命令参数初始化所述任务配置文件对应的全局变量组;第二解析模块,用于读取所述第二命令注释语句,解析所述第二命令注释语句的命令标识和命令参数,根据所述第二命令注释语句的命令标识判断所述第二命令注释语句的类别;第一插入模块,用于若所述第二命令注释语句的类别为插入命令注释语句,通过所述全局变量组将所述插入命令注释语句的命令参数插入日志表,所述插入命令注释语句的命令参数包括与所述插入命令注释语句对应的SQL语句的日志信息;第二插入模块,用于读取所述第二命令注释语句对应的SQL语句,执行所述SQL语句,若所述SQL语句执行失败,生成所述SQL语句的执行错误信息,将所述SQL语句的执行错误信息赋值给所述全局变量组中所述执行错误信息对应的全局变量,通过所述全局变量组将所述执行错误信息插入所述日志表。A second aspect of the present application provides a log insertion device, the device includes: a setting module for setting a task configuration file, the task configuration file includes a first command comment sentence, a second command comment sentence, and The SQL statement corresponding to the second command comment statement; the first parsing module is used to read the first command comment statement, and parse the command identifier and command parameters of the first command comment statement; the initialization module is used to The command identifier and command parameters of the first command comment statement initialize the global variable group corresponding to the task configuration file; the second parsing module is used to read the second command comment statement and parse the second command comment statement The command identifier and the command parameter are used to determine the type of the second command comment sentence according to the command identifier of the second command comment sentence; the first insert module is used to insert the command comment sentence if the type of the second command comment sentence , Insert the command parameter of the insert command comment sentence into the log table through the global variable group, the command parameter of the insert command comment sentence includes log information of the SQL sentence corresponding to the insert command comment sentence; the second insert module , Used to read the SQL statement corresponding to the second command comment statement, execute the SQL statement, if the SQL statement fails to execute, generate the execution error information of the SQL statement, and convert the execution error information of the SQL statement Assign a value to the global variable corresponding to the execution error information in the global variable group, and insert the execution error information into the log table through the global variable group.
本申请的第三方面提供一种计算机装置,所述计算机装置包括处理器,所述处理器用于执行存储器中存储的计算机可读指令时实现所述日志插入方法。A third aspect of the present application provides a computer device that includes a processor, and the processor is configured to implement the log insertion method when executing computer-readable instructions stored in a memory.
本申请的第四方面提供一种非易失性可读存储介质,其上存储有计算机可读指令,所述计算机可读指令被处理器执行时实现所述日志插入方法。A fourth aspect of the present application provides a non-volatile readable storage medium having computer readable instructions stored thereon, and when the computer readable instructions are executed by a processor, the log insertion method is implemented.
本申请能够提升将SQL语句执行错误信息插入日志表的效率。This application can improve the efficiency of inserting SQL statement execution error information into the log table.
附图说明Description of the drawings
图1是本申请实施例提供的日志插入方法的流程图。Fig. 1 is a flowchart of a log insertion method provided by an embodiment of the present application.
图2是本申请实施例提供的日志插入装置的结构图。Figure 2 is a structural diagram of a log insertion device provided by an embodiment of the present application.
图3是本申请实施例提供的计算机装置的示意图。Fig. 3 is a schematic diagram of a computer device provided by an embodiment of the present application.
具体实施方式detailed description
优选地,本申请的日志插入方法应用在一个或者多个计算机装置中。所述计算机装置可以是桌上型计算机、笔记本、掌上电脑及云端服务器等计算设备。所述计算机装置可以与用户通过键盘、鼠标、遥控器、触摸板或声控设备等方式进行人机交互。Preferably, the log insertion method of this application is applied to one or more computer devices. The computer device may be a computing device such as a desktop computer, a notebook, a palmtop computer, and a cloud server. The computer device can interact with the user through a keyboard, a mouse, a remote control, a touch panel, or a voice control device.
实施例一Example one
图1是本申请实施例一提供的日志插入方法的流程图。所述日志插入方法应用于计算机装置。FIG. 1 is a flowchart of a log insertion method provided in Embodiment 1 of the present application. The log insertion method is applied to a computer device.
本申请日志插入方法用于在日志表中插入SQL语句执行失败的日志信息。The log insertion method of this application is used to insert the log information of the SQL statement execution failure in the log table.
如图1所示,所述日志插入方法包括:As shown in Figure 1, the log insertion method includes:
S101,设定任务配置文件,所述任务配置文件包括第一命令注释语句、第二命令注释语句和SQL(Structured Query Language,结构化查询语言)语句,所述SQL语句与所述第二命令注释语句相对应。S101. Set a task configuration file. The task configuration file includes a first command comment statement, a second command comment statement, and a SQL (Structured Query Language) statement, the SQL statement and the second command comment The sentence corresponds.
在本实施例中,每个任务配置文件描述一个数据库操作任务,如将指定数据导入数据库。每个任务配置文件包括一个第一命令注释语句、多个第二命令注释语句,每个第二命令注释语句对应至少一个SQL语句。In this embodiment, each task configuration file describes a database operation task, such as importing specified data into the database. Each task configuration file includes one first command comment statement and multiple second command comment statements, and each second command comment statement corresponds to at least one SQL statement.
在本实施例中,所述任务配置文件的结构要满足:所述第一命令注释语句为所述任务配置文件的首条语句,所述第二命令注释语句和与其对应的SQL语句相邻,并且所述第二命令注释语句在其对应的SQL语句之前。可以检测所述任务配置文件是否满足结构要求,若所述任务配置文件满足结构要求,则执行后续步骤。否则,若所述任务配置文件不满足结构要求,则流程结束。In this embodiment, the structure of the task configuration file should satisfy: the first command comment sentence is the first sentence of the task configuration file, and the second command comment sentence is adjacent to its corresponding SQL sentence, And the second command comment statement is before its corresponding SQL statement. It can be detected whether the task configuration file meets the structural requirements, and if the task configuration file meets the structural requirements, the subsequent steps are executed. Otherwise, if the task configuration file does not meet the structural requirements, the process ends.
每个第一命令注释语句或第二命令注释语句包括至少一个命令。在本实施例中,所述命令包括用于更新日志表的命令。用于更新日志表的命令可以包括“@task_name=XXX”、“@task_desc=XXX”、“@step_name=XXX”、“@step_desc=XXX”等。其中,“@task_name=XXX”用于设置任务名称,“@task_desc=XXX”用于设置任务描述,“@step_name=XXX”用于设置步骤名称,“@step_desc=XXX”用于设置步骤描述。Each of the first command comment statement or the second command comment statement includes at least one command. In this embodiment, the command includes a command for updating the log table. The commands used to update the log table may include "@task_name=XXX", "@task_desc=XXX", "@step_name=XXX", "@step_desc=XXX", and so on. Among them, "@task_name="XXX" is used to set the task name, "@task_desc="XXX" is used to set the task description, "@step_name="XXX" is used to set the step name, and "@step_desc=XXX" is used to set the step description.
所述命令还包括用于控制SQL语句对应的数据库事务提交的命令。用于控制SQL语句对应的数据库事务提交的命令可以包括“@autocommit=true|false”,用于设置执行完SQL语句后是否提交该SQL语句对应的数据库事务。The command also includes a command for controlling the commit of the database transaction corresponding to the SQL statement. The command used to control the submission of the database transaction corresponding to the SQL statement may include "@autocommit=true|false", which is used to set whether to submit the database transaction corresponding to the SQL statement after the SQL statement is executed.
在另一实施例中,所述命令还可以包括用于控制输出日志信息的命令。用于控制输出日志信息的命令可以为“@debug=true|false”,用于设置是否输出日志表中SQL语句的执行失败信息。In another embodiment, the command may also include a command for controlling the output of log information. The command used to control the output of log information can be "@debug=true|false", which is used to set whether to output the execution failure information of the SQL statement in the log table.
所述SQL语句用于实现数据库操作任务的具体业务逻辑。The SQL statement is used to implement specific business logic of database operation tasks.
可选的,所述任务配置文件还可以包括其他的注释语句。例如,所述任务配置文件还可以包括SQL语句注释语句,用于对所述任务配置文件中的SQL语句进行解释说明, 以方便用户理解所述括SQL语句。Optionally, the task configuration file may also include other comment statements. For example, the task configuration file may also include SQL statement comment statements, which are used to explain the SQL statements in the task configuration file to facilitate users to understand the SQL statements.
所述第一命令注释语句和所述第二命令注释语句中可以用注释识别字符标示所述第一命令注释语句和所述第二命令注释语句。例如,可以用注释识别字符“-”标示所述第一命令注释语句和所述第二命令注释语句。因此,若代码行包括注释识别字符,则所述代码行为第一命令注释语句或第二命令注释语句;若代码行不包括注释识别字符,则所述代码行为SQL语句。In the first command comment sentence and the second command comment sentence, comment recognition characters may be used to mark the first command comment sentence and the second command comment sentence. For example, the comment recognition character "-" may be used to indicate the first command comment sentence and the second command comment sentence. Therefore, if the code line includes a comment recognition character, the code line is the first command comment statement or the second command comment statement; if the code line does not include the comment recognition character, the code line is a SQL statement.
所述第一命令注释语句和所述第二命令注释语句的命令识别字符可以相同也可以不同。例如,所述第一命令注释语句包括第一命令识别字符,所述第二命令注释语句包括第二命令识别字符。The command recognition characters of the first command comment sentence and the second command comment sentence may be the same or different. For example, the first command comment sentence includes a first command recognition character, and the second command comment sentence includes a second command recognition character.
可以用命令识别字符标示所述第一命令注释语句和所述第二命令注释语句中的命令。例如,可以用命令识别字符“-#”标示所述第一命令注释语句和所述第二命令注释语句中的命令。The commands in the first command comment sentence and the second command comment sentence can be marked with command recognition characters. For example, the command recognition character "-#" may be used to indicate the commands in the first command comment sentence and the second command comment sentence.
S102,读取所述第一命令注释语句,解析所述第一命令注释语句的命令标识和命令参数。S102: Read the first command comment sentence, and parse the command identifier and command parameter of the first command comment sentence.
在一实施例中,所述第一命令注释语句为所述任务配置文件的首条语句,则读取所述任务配置文件的首条语句。In an embodiment, if the first command comment sentence is the first sentence of the task configuration file, then the first sentence of the task configuration file is read.
或者,在另一实施例中,所述第一命令注释语句包括第一命令识别字符,则根据所述第一命令识别字符读取所述第一命令注释语句。Or, in another embodiment, the first command comment sentence includes a first command recognition character, and the first command comment sentence is read according to the first command recognition character.
所述第一命令注释语句具有固定的格式,根据所述第一命令注释语句的格式解析所述第一命令注释语句的命令标识和命令参数。所述第一命令注释语句可以包括多个命令标识和多个命令参数,其中,命令标识和命令参数一一对应。The first command comment sentence has a fixed format, and the command identifier and command parameters of the first command comment sentence are parsed according to the format of the first command comment sentence. The first command comment statement may include multiple command identifiers and multiple command parameters, where the command identifiers and command parameters have a one-to-one correspondence.
举例来说,第一命令注释语句为“@task_name=T001;@autocommit=true;@task_desc=每天备份一次用户表”。该第一命令注释语句包括命令“@task_name=T001”、“@autocommit=true”和“@task_desc=每天备份一次用户表”。命令“@task_name=T001”用于设置任务名称为T001,命令“@autocommit=true”用于设置执行完SQL语句后提交该SQL语句对应的数据库事务,命令“@task_desc=每天备份一次用户表”用于设置任务描述为“每天备份一次用户表”。字符“@”到字符“=”之间的字符串为命令标识,字符“=”之后分号“;”之前的为命令参数,解析得到第一命令注释语句的三个命令标识为“@task_name”、“@autocommit”、“@task_desc”,所述三个命令标识对应的三个命令参数分别为“T001”、“true”、“每天备份一次用户表”。For example, the comment sentence of the first command is "@task_name=T001; @autocommit=true; @task_desc=Back up the user table once a day". The first command comment statement includes the commands "@task_name=T001", "@autocommit=true", and "@task_desc=Back up the user table once a day". The command "@task_name="T001" is used to set the task name to T001, the command "@autocommit="true" is used to set the SQL statement to submit the database transaction corresponding to the SQL statement after the SQL statement is executed, the command "@task_desc = backup user table once a day" Used to set the task description as "Back up user table once a day". The character string between the character "@" and the character "=" is the command identifier, the semicolon ";" after the character "=" is the command parameter, and the three command identifiers of the first command comment statement are parsed as "@task_name" ", "@autocommit", "@task_desc", the three command parameters corresponding to the three command identifiers are "T001", "true", and "Back up the user table once a day".
在一实施例中,所述第一命令注释语句包括用于控制输出日志信息的命令,例如包 括“@debug=true”,则解析得到第一命令注释语句的命令标识为“@debug”,所述命令标识对应的命令参数为“true”。In one embodiment, the first command comment statement includes a command for controlling output of log information, for example, including "@debug=true", and the command identifier of the first command comment statement is parsed as "@debug", so The command parameter corresponding to the command identifier is "true".
S103,根据所述第一命令注释语句的命令标识和命令参数初始化所述任务配置文件对应的全局变量组。S103: Initialize the global variable group corresponding to the task configuration file according to the command identifier and the command parameter of the first command comment statement.
在一具体实施例中,所述根据所述第一命令注释语句的命令标识和命令参数初始化所述任务配置文件对应的全局变量组包括:In a specific embodiment, the initialization of the global variable group corresponding to the task configuration file according to the command identifier and the command parameter of the first command comment statement includes:
将所述全局变量组中的全局变量初始化为空值;Initializing the global variables in the global variable group to a null value;
查询预设的命令标识-全局变量表,判断所述全局变量组中是否包含所述第一命令注释语句的命令标识对应的全局变量;Query the preset command identifier-global variable table, and determine whether the global variable group contains the global variable corresponding to the command identifier of the first command comment sentence;
若所述全局变量组中包含所述第一命令注释语句的命令标识对应的全局变量,则将所述第一命令注释语句的命令标识对应的命令参数赋值给所述全局变量组中所述第一命令注释语句的命令标识对应的全局变量。If the global variable group contains the global variable corresponding to the command identifier of the first command comment sentence, the command parameter corresponding to the command identifier of the first command comment sentence is assigned to the first command parameter in the global variable group. The command identification of a command comment statement corresponds to the global variable.
举例来说,预设的命令标识-全局变量表为“@task_name-task_name;@autocommit-autocommit;@task_desc-task_desc”,表示命令标识“@task_name”、“@autocommit”、“@task_desc”对应的全局变量分别为“task_name”、“autocommit”、“task_desc”。将任务配置文件对应的全局变量组中的全局变量初始化为“task_name=null;autocommit=null;task_desc=null”。任务配置文件中的第一命令注释语句为“@task_name=T001;@autocommit=true;@task_desc=每天备份一次用户表”。任务配置文件对应的全局变量组中包含第一命令注释语句的命令标识“@task_name”对应的全局变量“task_name”,包含第一命令注释语句的命令标识“@autocommit”对应的全局变量“autocommit”,以及包含第一命令注释语句的命令标识“@task_desc”对应的全局变量“task_desc”。因此,将第一命令注释语句的命令标识“@task_name”对应的命令参数“T001”赋值给全局变量组中第一命令注释语句的命令标识对应的全局变量“task_name”,将第一命令注释语句的命令标识“@autocommit”对应的命令参数“true”赋值给全局变量组中第一命令注释语句的命令标识对应的全局变量“autocommit”,将第一命令注释语句的命令标识“@task_desc”对应的命令参数“每天备份一次用户表”赋值给全局变量组中第一命令注释语句的命令标识对应的全局变量“task_desc”,赋值后的全局变量组为“task_name=T001;autocommit=true;task_desc=每天备份一次用户表”。For example, the preset command identifier-global variable table is "@task_name-task_name; @autocommit-autocommit; @task_desc-task_desc", indicating that the command identifiers "@task_name", "@autocommit", "@task_desc" correspond to The global variables are "task_name", "autocommit", and "task_desc". Initialize the global variables in the global variable group corresponding to the task configuration file to "task_name=null; autocommit=null; task_desc=null". The first command comment statement in the task configuration file is "@task_name=T001; @autocommit=true; @task_desc=Back up the user table once a day". The global variable group corresponding to the task configuration file contains the global variable "task_name" corresponding to the command identifier "@task_name" of the first command comment statement, and the global variable "autocommit" corresponding to the command identifier "@autocommit" containing the first command comment statement , And the global variable "task_desc" corresponding to the command identifier "@task_desc" containing the first command comment statement. Therefore, the command parameter "T001" corresponding to the command identifier "@task_name" of the first command comment statement is assigned to the global variable "task_name" corresponding to the command identifier of the first command comment statement in the global variable group, and the first command comment statement The command parameter "true" corresponding to the command identifier "@autocommit" is assigned to the global variable "autocommit" corresponding to the command identifier of the first command comment statement in the global variable group, and the command identifier "@task_desc" of the first command comment statement corresponds to The command parameter "Backup user table once a day" is assigned to the global variable "task_desc" corresponding to the command identifier of the first command comment statement in the global variable group. The global variable group after assignment is "task_name=T001; autocommit=true; task_desc= Back up the user table once a day".
S104,读取所述第二命令注释语句,解析所述第二命令注释语句的命令标识和命令参数,根据所述第二命令注释语句的命令标识判断所述第二命令注释语句的类别。S104: Read the second command comment sentence, analyze the command identifier and command parameter of the second command comment sentence, and determine the type of the second command comment sentence according to the command identifier of the second command comment sentence.
在一实施例中,所述第二命令注释语句包括第二命令识别字符,则根据所述第二命 令识别字符读取所述第二命令注释语句。In an embodiment, the second command comment sentence includes a second command recognition character, and the second command comment sentence is read according to the second command recognition character.
所述第二命令注释语句具有固定的格式,根据所述第二命令注释语句的格式解析所述第二命令注释语句的命令标识和命令参数。所述第二命令注释语句可以包括多个命令标识和多个命令参数,其中,命令标识和命令参数一一对应。The second command comment sentence has a fixed format, and the command identifier and command parameter of the second command comment sentence are parsed according to the format of the second command comment sentence. The second command comment statement may include multiple command identifiers and multiple command parameters, where the command identifiers and the command parameters have a one-to-one correspondence.
所述根据所述第二命令注释语句的命令标识判断所述第二命令注释语句的类别包括:The judging the category of the second command comment sentence according to the command identifier of the second command comment sentence includes:
若所述第二命令注释语句的命令标识为@step_name或@step_desc,则所述第二命令注释语句的类别为插入命令注释语句;If the command identifier of the second command comment sentence is @step_name or @step_desc, the category of the second command comment sentence is an insert command comment sentence;
若所述第二命令注释语句的命令标识为@autocommit,则所述第二命令注释语句的类别为提交命令注释语句。If the command identifier of the second command comment sentence is @autocommit, the category of the second command comment sentence is a submit command comment sentence.
S105,若所述第二命令注释语句的类别为插入命令注释语句,通过所述全局变量组将所述插入命令注释语句的命令参数插入日志表,所述插入命令注释语句的命令参数包括与所述插入命令注释语句对应的SQL语句的日志信息。S105: If the category of the second command comment sentence is an insert command comment sentence, insert the command parameter of the insert command comment sentence into the log table through the global variable group, and the command parameter of the insert command comment sentence includes Describe the log information of the SQL statement corresponding to the insert command comment statement.
在一具体实施例中,所述通过所述全局变量组将所述插入命令注释语句的命令参数插入日志表包括:In a specific embodiment, the inserting the command parameter of the insert command comment statement into the log table through the global variable group includes:
查询预设的命令标识-全局变量表,确定所述全局变量组中所述插入命令注释语句的命令标识对应的全局变量;Query the preset command identifier-global variable table, and determine the global variable corresponding to the command identifier of the inserted command comment sentence in the global variable group;
将所述插入命令注释语句的命令参数赋值给所述全局变量组中所述插入命令注释语句的命令标识对应的全局变量,其中所述插入命令注释语句的命令参数与所述插入命令注释语句的命令标识一一对应;Assign the command parameter of the insert command comment sentence to the global variable corresponding to the command identifier of the insert command comment sentence in the global variable group, wherein the command parameter of the insert command comment sentence is the same as that of the insert command comment sentence. One-to-one correspondence between command identifiers;
根据所述全局变量组生成第一日志插入语句;Generating a first log insertion statement according to the global variable group;
执行所述第一日志插入语句,将所述全局变量组中所述插入命令注释语句的命令标识对应的全局变量插入所述日志表。The first log insert statement is executed, and the global variable corresponding to the command identifier of the insert command comment statement in the global variable group is inserted into the log table.
例如,插入命令注释语句为“@step_name=backup_table;@step_desc=备份表”。查询预设的命令标识-全局变量表,确定全局变量组中插入命令注释语句的命令标识对应的全局变量为“step_name=null;step_desc=null”。将插入命令注释语句的命令参数“backup_table”赋值给全局变量组中插入命令注释语句的命令标识“@step_name”对应的全局变量“step_name”,将插入命令注释语句的命令参数“备份表”赋值给全局变量组中插入命令注释语句的命令标识“@step_desc”对应的全局变量“step_desc”,赋值后的与插入命令注释语句的命令标识对应的全局变量为“step_name=backup_table;step_desc=备份表”。根据全局变量组 “task_name=T001;autocommit=true;task_desc=每天备份一次用户表;step_name=backup_table;step_desc=备份表”生成第一日志插入语句“Insert into etl_task_log(task_name,step_name,step_desc,start_time)values(T001,backup_table,’备份表’,now())”,其中“now()”为获取当前时间的函数。执行第一日志插入语句,将全局变量组中插入命令注释语句的命令标识对应的全局变量插入日志表。For example, the insert command comment statement is "@step_name=backup_table; @step_desc=backup table". Query the preset command ID-global variable table, and determine that the global variable corresponding to the command ID of the command comment statement inserted in the global variable group is "step_name=null; step_desc=null". Assign the command parameter "backup_table" of the inserted command comment statement to the global variable "step_name" corresponding to the command ID "@step_name" of the command comment statement inserted in the global variable group, and assign the command parameter "backup table" of the inserted command comment statement to The global variable "step_desc" corresponding to the command identifier "@step_desc" of the inserted command comment statement in the global variable group, and the global variable corresponding to the command identifier of the inserted command comment statement after assignment is "step_name=backup_table; step_desc=backup table". According to the global variable group "task_name = T001; autocommit = true; task_desc = backup user table once a day; step_name = backup_table; step_desc = backup table" to generate the first log insert statement "Insert into etl_task_log(task_name, step_name, step_desc, start_time) values (T001,backup_table,'backup table',now())", where "now()" is a function to get the current time. The first log insert statement is executed, and the global variable corresponding to the command identifier of the command comment statement inserted in the global variable group is inserted into the log table.
S106,读取所述第二命令注释语句对应的SQL语句,执行所述SQL语句。S106: Read the SQL statement corresponding to the second command comment statement, and execute the SQL statement.
所述第二命令注释语句对应的SQL语句是不包括所述命令识别字符和所述注释识别字符的代码行。The SQL sentence corresponding to the second command comment sentence is a code line that does not include the command recognition character and the comment recognition character.
执行所述SQL语句就是根据所述SQL语句对数据库进行操作,以实现所述任务配置文件描述的数据库操作任务,如将给定数据导入数据库中。Executing the SQL statement is to operate the database according to the SQL statement to realize the database operation task described in the task configuration file, such as importing given data into the database.
S107,若所述SQL语句执行失败,生成所述SQL语句的执行错误信息,将所述SQL语句的执行错误信息赋值给所述全局变量组中所述执行错误信息对应的全局变量,通过所述全局变量组将所述执行错误信息插入所述日志表。S107: If the execution of the SQL statement fails, generate execution error information of the SQL statement, assign the execution error information of the SQL statement to the global variable corresponding to the execution error information in the global variable group, and pass the The global variable group inserts the execution error information into the log table.
在一具体实施例中,生成所述SQL语句的执行错误信息包括:In a specific embodiment, generating execution error information of the SQL statement includes:
(1)将所述SQL语句的执行标识信息赋值为“false”。所述SQL语句的执行标识信息初始值为“true”,将所述SQL语句的执行标识信息赋值为“false”,表明所述SQL语句执行失败。(1) Assign the execution identification information of the SQL statement to "false". The initial value of the execution identification information of the SQL statement is "true", and the execution identification information of the SQL statement is assigned a value of "false", indicating that the execution of the SQL statement failed.
(2)判断所述SQL语句中的参数是否正确,若所述SQL语句中的参数不正确,生成第一执行错误信息。可以判断所述SQL语句中的参数的数据类型是否正确,以及判断所述SQL语句中的参数的数值是否为预设值。若所述SQL语句中的参数的数据类型不正确,或者所述SQL语句中的参数的参数不是预设值,则所述SQL语句中的参数不正确,生成第一执行错误信息。(2) Determine whether the parameters in the SQL statement are correct, and if the parameters in the SQL statement are incorrect, generate a first execution error message. It can be judged whether the data type of the parameter in the SQL statement is correct, and whether the value of the parameter in the SQL statement is a preset value. If the data type of the parameter in the SQL statement is incorrect, or the parameter of the parameter in the SQL statement is not a preset value, the parameter in the SQL statement is incorrect, and a first execution error message is generated.
(3)判断所述SQL语句中的表是否正确,若所述SQL语句中的表不正确,生成第二执行错误信息。可以判断所述SQL语句中的表是否存在,以及判断是否有所述SQL语句中的表的访问权限,若所述SQL语句中的表不存在,或者没有所述SQL语句中的表的访问权限,则所述SQL语句中的表不正确,生成第二执行错误信息。(3) Determine whether the table in the SQL statement is correct, and if the table in the SQL statement is incorrect, generate a second execution error message. It can be judged whether the table in the SQL statement exists, and whether there is access permission to the table in the SQL statement, if the table in the SQL statement does not exist, or there is no access permission to the table in the SQL statement , The table in the SQL statement is incorrect, and a second execution error message is generated.
(4)若所述SQL语句中的参数正确且所述SQL语句中的表正确,生成第三执行错误信息。若所述SQL语句中的参数正确且所述SQL语句中的表正确,表示执行所述SQL语句的过程中出现了其他错误,则生成第三执行错误信息。(4) If the parameters in the SQL statement are correct and the tables in the SQL statement are correct, a third execution error message is generated. If the parameters in the SQL statement are correct and the tables in the SQL statement are correct, it means that other errors have occurred during the execution of the SQL statement, and a third execution error message is generated.
将所述SQL语句的执行错误信息赋值给所述全局变量组中所述执行错误信息对应的全局变量就是将所述执行错误信息转换为字符串赋值给所述全局变量组中与所述执行 错误信息对应的全局变量。例如,将包括执行标识信息“false”、第一执行错误信息“false001”、第二执行错误信息“false002”转换为字符串“false$false001$false002”赋值给全局变量组中与执行错误信息对应的全局变量“status=false$false001$false002”。或者,将包括执行标识信息“false”、第三执行错误信息“false003”转换为字符串“false$false003”赋值给全局变量组中与执行错误信息对应的全局变量“status=false$false003”,其中“status”为与执行错误信息对应的全局变量。Assigning the execution error information of the SQL statement to the global variable corresponding to the execution error information in the global variable group is to convert the execution error information into a string and assign it to the global variable group and the execution error The global variable corresponding to the information. For example, convert the execution identification information "false", the first execution error information "false001", and the second execution error information "false002" into the string "false$false001$false002" and assign them to the global variable group corresponding to the execution error information The global variable "status=false$false001$false002". Or, converting the execution identification information "false" and the third execution error information "false003" into a character string "false$false003" and assigning it to the global variable "status=false$false003" corresponding to the execution error information in the global variable group, Among them, "status" is a global variable corresponding to the execution error message.
所述通过所述全局变量组将所述执行错误信息插入所述日志表包括:The inserting the execution error information into the log table through the global variable group includes:
(1)根据所述全局变量组生成第二日志插入语句。举例来说,根据所述全局变量组“task_name=T001;autocommit=true;task_desc=每天备份一次用户表;step_name=backup_table;step_desc=备份表;status=false$false003”生成第二日志插入语句“Insert into etl_task_log(task_name,step_name,step_desc,start_time,status)values(T001,backup_table,’备份表’,now(),false$false003)”。(1) Generate a second log insertion statement according to the global variable group. For example, according to the global variable group "task_name=T001; autocommit=true; task_desc=backup user table once a day; step_name=backup_table; step_desc=backup table; status=false$false003" to generate the second log insert statement "Insert" into etl_task_log(task_name,step_name,step_desc,start_time,status)values(T001,backup_table,'backup table',now(),false$false003)".
(2)执行所述第二日志插入语句,将所述全局变量中所述执行错误信息对应的全局变量插入所述日志表。(2) Execute the second log insertion statement, and insert the global variable corresponding to the execution error information in the global variable into the log table.
例如,执行“Insert into etl_task_log(task_name,step_name,step_desc,start_time,status)values(T001,backup_table,’备份表’,now(),false$false003)”,将所述全局变量中所述执行错误信息对应的全局变量插入所述日志表。For example, execute "Insert into etl_task_log(task_name,step_name,step_desc,start_time,status)values(T001,backup_table,'backup table',now(),false$false003)", and set the execution error information in the global variable The corresponding global variable is inserted into the log table.
实施例一的日志插入方法设定任务配置文件,所述任务配置文件包括第一命令注释语句,第二命令注释语句和与所述第二命令注释语句对应的SQL语句;读取所述第一命令注释语句,解析所述第一命令注释语句的命令标识和命令参数;根据所述第一命令注释语句的命令标识和命令参数初始化所述任务配置文件对应的全局变量组;读取所述第二命令注释语句,解析所述第二命令注释语句的命令标识和命令参数,根据所述第二命令注释语句的命令标识判断所述第二命令注释语句的类别;若所述第二命令注释语句的类别为插入命令注释语句,通过所述全局变量组将所述插入命令注释语句的命令参数插入日志表,所述插入命令注释语句的命令参数包括与所述插入命令注释语句对应的SQL语句的日志信息;读取所述第二命令注释语句对应的SQL语句,执行所述SQL语句;若所述SQL语句执行失败,生成所述SQL语句的执行错误信息,将所述SQL语句的执行错误信息赋值给所述全局变量组中所述执行错误信息对应的全局变量,通过所述全局变量组将所述执行错误信息插入所述日志表。实施例一能够提升将SQL语句执行错误信息插入日志表的效率。The log insertion method of the first embodiment sets a task configuration file, the task configuration file includes a first command comment statement, a second command comment statement, and a SQL statement corresponding to the second command comment statement; read the first Command comment sentence, parse the command identifier and command parameter of the first command comment sentence; initialize the global variable group corresponding to the task configuration file according to the command identifier and command parameter of the first command comment sentence; read the first command comment sentence Second command comment sentence, parse the command identifier and command parameter of the second command comment sentence, and judge the category of the second command comment sentence according to the command identifier of the second command comment sentence; if the second command comment sentence The category of the insert command comment statement is the insert command comment statement. The command parameter of the insert command comment statement is inserted into the log table through the global variable group. The command parameter of the insert command comment statement includes the SQL statement corresponding to the insert command comment statement. Log information; read the SQL statement corresponding to the second command comment statement, execute the SQL statement; if the SQL statement fails to execute, generate the execution error information of the SQL statement, and replace the execution error information of the SQL statement Assign a value to the global variable corresponding to the execution error information in the global variable group, and insert the execution error information into the log table through the global variable group. The first embodiment can improve the efficiency of inserting SQL statement execution error information into the log table.
在另一实施例中,所述方法还可以包括:In another embodiment, the method may further include:
若所述第二命令注释语句的类别为提交命令注释语句,则判断所述提交命令注释语句中的命令参数是否为“true”;If the category of the second command comment sentence is a submit command comment sentence, it is determined whether the command parameter in the submit command comment sentence is "true";
若所述提交命令注释语句中的命令参数为“true”,则提交所述SQL语句对应的数据库事务。If the command parameter in the comment statement of the submit command is "true", then the database transaction corresponding to the SQL statement is submitted.
在另一实施例中,所述方法还可以包括:In another embodiment, the method may further include:
若所述SQL语句执行失败,则判断所述第一命令注释语句中用于控制输出日志信息的命令参数是否为“true”;If the execution of the SQL statement fails, it is determined whether the command parameter used to control the output log information in the first command comment statement is "true";
若所述第一命令注释语句中用于控制输出日志信息的命令参数为“true”,则输出所述日志表中所述SQL语句的执行失败信息。If the command parameter used to control the output of log information in the first command comment statement is "true", then the execution failure information of the SQL statement in the log table is output.
在另一实施例中,在所述根据所述第一命令注释语句的命令标识和命令参数初始化所述任务配置文件对应的全局变量组之前,所述方法还包括:In another embodiment, before the initialization of the global variable group corresponding to the task configuration file according to the command identifier and the command parameter of the first command comment statement, the method further includes:
判断所述第一命令注释语句中的命令标识是否包含在所述命令标识-全局变量表中。It is determined whether the command identifier in the first command comment sentence is included in the command identifier-global variable table.
若所述第一命令注释语句中的命令标识包含在所述命令标识-全局变量表中,则根据所述第一命令注释语句的命令标识和命令参数初始化所述任务配置文件对应的全局变量组。If the command identifier in the first command comment sentence is included in the command identifier-global variable table, initialize the global variable group corresponding to the task configuration file according to the command identifier and command parameters of the first command comment sentence .
在另一实施例中,在所述根据所述第二命令注释语句的命令标识判断所述第二命令注释语句的类别之前,所述方法还可以包括:In another embodiment, before the judging the category of the second command comment sentence according to the command identifier of the second command comment sentence, the method may further include:
判断所述第二命令注释语句中的命令标识是否包含在所述命令标识-全局变量表中。It is determined whether the command identifier in the second command comment sentence is included in the command identifier-global variable table.
若所述第二命令注释语句中的命令标识包含在所述命令标识-全局变量表中,则根据所述第二命令注释语句的命令标识判断所述第二命令注释语句的类别。If the command identifier in the second command comment sentence is included in the command identifier-global variable table, the type of the second command comment sentence is determined according to the command identifier of the second command comment sentence.
实施例二Example two
图2是本申请实施例二提供的日志插入装置的结构图。所述日志插入装置20应用于计算机装置。本装置的日志插入是在日志表中插入SQL语句执行失败的日志信息。如图2所示,所述日志插入装置20可以包括设定模块201、第一解析模块202、初始化模块203、第二解析模块204、第一插入模块205、第二插入模块206。Fig. 2 is a structural diagram of a log insertion device provided in the second embodiment of the present application. The log insertion device 20 is applied to a computer device. The log insertion of this device is to insert the log information of the SQL statement execution failure in the log table. As shown in FIG. 2, the log insertion device 20 may include a setting module 201, a first analysis module 202, an initialization module 203, a second analysis module 204, a first insertion module 205, and a second insertion module 206.
设定模块201,用于设定任务配置文件,所述任务配置文件包括第一命令注释语句、第二命令注释语句和SQL(Structured Query Language,结构化查询语言)语句,所述SQL语句与所述第二命令注释语句相对应。The setting module 201 is used to set a task configuration file. The task configuration file includes a first command comment statement, a second command comment statement, and SQL (Structured Query Language) statements. The comment statement of the second command corresponds to that.
在本实施例中,每个任务配置文件描述一个数据库操作任务,如将指定数据导入数据库。每个任务配置文件包括一个第一命令注释语句、多个第二命令注释语句,每个第二命令注释语句对应至少一个SQL语句。In this embodiment, each task configuration file describes a database operation task, such as importing specified data into the database. Each task configuration file includes one first command comment statement and multiple second command comment statements, and each second command comment statement corresponds to at least one SQL statement.
在本实施例中,所述任务配置文件的结构要满足:所述第一命令注释语句为所述任务配置文件的首条语句,所述第二命令注释语句和与其对应的SQL语句相邻,并且所述第二命令注释语句在其对应的SQL语句之前。可以检测所述任务配置文件是否满足结构要求,若所述任务配置文件满足结构要求,则执行后续步骤。否则,若所述任务配置文件不满足结构要求,则流程结束。In this embodiment, the structure of the task configuration file should satisfy: the first command comment sentence is the first sentence of the task configuration file, and the second command comment sentence is adjacent to its corresponding SQL sentence, And the second command comment statement is before its corresponding SQL statement. It can be detected whether the task configuration file meets the structural requirements, and if the task configuration file meets the structural requirements, the subsequent steps are executed. Otherwise, if the task configuration file does not meet the structural requirements, the process ends.
每个第一命令注释语句或第二命令注释语句包括至少一个命令。在本实施例中,所述命令包括用于更新日志表的命令。用于更新日志表的命令可以包括“@task_name=XXX”、“@task_desc=XXX”、“@step_name=XXX”、“@step_desc=XXX”等。其中,“@task_name=XXX”用于设置任务名称,“@task_desc=XXX”用于设置任务描述,“@step_name=XXX”用于设置步骤名称,“@step_desc=XXX”用于设置步骤描述。Each of the first command comment statement or the second command comment statement includes at least one command. In this embodiment, the command includes a command for updating the log table. The commands used to update the log table may include "@task_name=XXX", "@task_desc=XXX", "@step_name=XXX", "@step_desc=XXX", and so on. Among them, "@task_name="XXX" is used to set the task name, "@task_desc="XXX" is used to set the task description, "@step_name="XXX" is used to set the step name, and "@step_desc=XXX" is used to set the step description.
所述命令还包括用于控制SQL语句对应的数据库事务提交的命令。用于控制SQL语句对应的数据库事务提交的命令可以包括“@autocommit=true|false”,用于设置执行完SQL语句后是否提交该SQL语句对应的数据库事务。The command also includes a command for controlling the commit of the database transaction corresponding to the SQL statement. The command used to control the submission of the database transaction corresponding to the SQL statement may include "@autocommit=true|false", which is used to set whether to submit the database transaction corresponding to the SQL statement after the SQL statement is executed.
在另一实施例中,所述命令还可以包括用于控制输出日志信息的命令。用于控制输出日志信息的命令可以为“@debug=true|false”,用于设置是否输出日志表中SQL语句的执行失败信息。In another embodiment, the command may also include a command for controlling the output of log information. The command used to control the output of log information can be "@debug=true|false", which is used to set whether to output the execution failure information of the SQL statement in the log table.
所述SQL语句用于实现数据库操作任务的具体业务逻辑。The SQL statement is used to implement specific business logic of database operation tasks.
可选的,所述任务配置文件还可以包括其他的注释语句。例如,所述任务配置文件还可以包括SQL语句注释语句,用于对所述任务配置文件中的SQL语句进行解释说明,以方便用户理解所述括SQL语句。Optionally, the task configuration file may also include other comment statements. For example, the task configuration file may also include SQL statement comment statements, which are used to explain the SQL statements in the task configuration file, so as to facilitate users to understand the SQL statements.
所述第一命令注释语句和所述第二命令注释语句中可以用注释识别字符标示所述第一命令注释语句和所述第二命令注释语句。例如,可以用注释识别字符“-”标示所述第一命令注释语句和所述第二命令注释语句。因此,若代码行包括注释识别字符,则所述代码行为第一命令注释语句或第二命令注释语句;若代码行不包括注释识别字符,则所述代码行为SQL语句。In the first command comment sentence and the second command comment sentence, comment recognition characters may be used to mark the first command comment sentence and the second command comment sentence. For example, the comment recognition character "-" may be used to indicate the first command comment sentence and the second command comment sentence. Therefore, if the code line includes a comment recognition character, the code line is the first command comment statement or the second command comment statement; if the code line does not include the comment recognition character, the code line is a SQL statement.
所述第一命令注释语句和所述第二命令注释语句的命令识别字符可以相同也可以不同。例如,所述第一命令注释语句包括第一命令识别字符,所述第二命令注释语句包括第二命令识别字符。The command recognition characters of the first command comment sentence and the second command comment sentence may be the same or different. For example, the first command comment sentence includes a first command recognition character, and the second command comment sentence includes a second command recognition character.
可以用命令识别字符标示所述第一命令注释语句和所述第二命令注释语句中的命令。例如,可以用命令识别字符“-#”标示所述第一命令注释语句和所述第二命令注释语 句中的命令。The commands in the first command comment sentence and the second command comment sentence can be marked with command recognition characters. For example, the command recognition character "-#" may be used to indicate the commands in the first command comment sentence and the second command comment sentence.
第一解析模块202,用于读取所述第一命令注释语句,解析所述第一命令注释语句的命令标识和命令参数。The first parsing module 202 is configured to read the first command comment sentence and parse the command identifier and command parameters of the first command comment sentence.
在一实施例中,所述第一命令注释语句为所述任务配置文件的首条语句,则读取所述任务配置文件的首条语句。In an embodiment, if the first command comment sentence is the first sentence of the task configuration file, then the first sentence of the task configuration file is read.
或者,在另一实施例中,所述第一命令注释语句包括第一命令识别字符,则根据所述第一命令识别字符读取所述第一命令注释语句。Or, in another embodiment, the first command comment sentence includes a first command recognition character, and the first command comment sentence is read according to the first command recognition character.
所述第一命令注释语句具有固定的格式,根据所述第一命令注释语句的格式解析所述第一命令注释语句的命令标识和命令参数。所述第一命令注释语句可以包括多个命令标识和多个命令参数,其中,命令标识和命令参数一一对应。The first command comment sentence has a fixed format, and the command identifier and command parameters of the first command comment sentence are parsed according to the format of the first command comment sentence. The first command comment statement may include multiple command identifiers and multiple command parameters, where the command identifiers and command parameters have a one-to-one correspondence.
举例来说,第一命令注释语句为“@task_name=T001;@autocommit=true;@task_desc=每天备份一次用户表”。该第一命令注释语句包括命令“@task_name=T001”、“@autocommit=true”和“@task_desc=每天备份一次用户表”。命令“@task_name=T001”用于设置任务名称为T001,命令“@autocommit=true”用于设置执行完SQL语句后提交该SQL语句对应的数据库事务,命令“@task_desc=每天备份一次用户表”用于设置任务描述为“每天备份一次用户表”。字符“@”到字符“=”之间的字符串为命令标识,字符“=”之后分号“;”之前的为命令参数,解析得到第一命令注释语句的三个命令标识为“@task_name”、“@autocommit”、“@task_desc”,所述三个命令标识对应的三个命令参数分别为“T001”、“true”、“每天备份一次用户表”。For example, the comment sentence of the first command is "@task_name=T001; @autocommit=true; @task_desc=Back up the user table once a day". The first command comment statement includes the commands "@task_name=T001", "@autocommit=true", and "@task_desc=Back up the user table once a day". The command "@task_name="T001" is used to set the task name to T001, the command "@autocommit="true" is used to set the SQL statement to submit the database transaction corresponding to the SQL statement after the SQL statement is executed, the command "@task_desc = backup user table once a day" Used to set the task description as "Back up user table once a day". The character string between the character "@" and the character "=" is the command identifier, the semicolon ";" after the character "=" is the command parameter, and the three command identifiers of the first command comment statement are parsed as "@task_name" ", "@autocommit", "@task_desc", the three command parameters corresponding to the three command identifiers are "T001", "true", and "Back up the user table once a day".
在一实施例中,所述第一命令注释语句包括用于控制输出日志信息的命令,例如包括“@debug=true”,则解析得到第一命令注释语句的命令标识为“@debug”,所述命令标识对应的命令参数为“true”。In one embodiment, the first command comment statement includes a command for controlling output of log information, for example, including "@debug=true", and the command identifier of the first command comment statement is parsed as "@debug", so The command parameter corresponding to the command identifier is "true".
初始化模块203,用于根据所述第一命令注释语句的命令标识和命令参数初始化所述任务配置文件对应的全局变量组。The initialization module 203 is configured to initialize the global variable group corresponding to the task configuration file according to the command identifier and the command parameter of the first command comment statement.
在一具体实施例中,所述根据所述第一命令注释语句的命令标识和命令参数初始化所述任务配置文件对应的全局变量组包括:In a specific embodiment, the initialization of the global variable group corresponding to the task configuration file according to the command identifier and the command parameter of the first command comment statement includes:
将所述全局变量组中的全局变量初始化为空值;Initializing the global variables in the global variable group to a null value;
查询预设的命令标识-全局变量表,判断所述全局变量组中是否包含所述第一命令注释语句的命令标识对应的全局变量;Query the preset command identifier-global variable table, and determine whether the global variable group contains the global variable corresponding to the command identifier of the first command comment sentence;
若所述全局变量组中包含所述第一命令注释语句的命令标识对应的全局变量,则将所述第一命令注释语句的命令标识对应的命令参数赋值给所述全局变量组中所述第一命 令注释语句的命令标识对应的全局变量。If the global variable group contains the global variable corresponding to the command identifier of the first command comment sentence, the command parameter corresponding to the command identifier of the first command comment sentence is assigned to the first command parameter in the global variable group. The command identification of a command comment statement corresponds to the global variable.
举例来说,预设的命令标识-全局变量表为“@task_name-task_name;@autocommit-autocommit;@task_desc-task_desc”,表示命令标识“@task_name”、“@autocommit”、“@task_desc”对应的全局变量分别为“task_name”、“autocommit”、“task_desc”。将任务配置文件对应的全局变量组中的全局变量初始化为“task_name=null;autocommit=null;task_desc=null”。任务配置文件中的第一命令注释语句为“@task_name=T001;@autocommit=true;@task_desc=每天备份一次用户表”。任务配置文件对应的全局变量组中包含第一命令注释语句的命令标识“@task_name”对应的全局变量“task_name”,包含第一命令注释语句的命令标识“@autocommit”对应的全局变量“autocommit”,以及包含第一命令注释语句的命令标识“@task_desc”对应的全局变量“task_desc”。因此,将第一命令注释语句的命令标识“@task_name”对应的命令参数“T001”赋值给全局变量组中第一命令注释语句的命令标识对应的全局变量“task_name”,将第一命令注释语句的命令标识“@autocommit”对应的命令参数“true”赋值给全局变量组中第一命令注释语句的命令标识对应的全局变量“autocommit”,将第一命令注释语句的命令标识“@task_desc”对应的命令参数“每天备份一次用户表”赋值给全局变量组中第一命令注释语句的命令标识对应的全局变量“task_desc”,赋值后的全局变量组为“task_name=T001;autocommit=true;task_desc=每天备份一次用户表”。For example, the preset command identifier-global variable table is "@task_name-task_name; @autocommit-autocommit; @task_desc-task_desc", indicating that the command identifiers "@task_name", "@autocommit", "@task_desc" correspond to The global variables are "task_name", "autocommit", and "task_desc". Initialize the global variables in the global variable group corresponding to the task configuration file to "task_name=null; autocommit=null; task_desc=null". The first command comment statement in the task configuration file is "@task_name=T001; @autocommit=true; @task_desc=Back up the user table once a day". The global variable group corresponding to the task configuration file contains the global variable "task_name" corresponding to the command identifier "@task_name" of the first command comment statement, and the global variable "autocommit" corresponding to the command identifier "@autocommit" containing the first command comment statement , And the global variable "task_desc" corresponding to the command identifier "@task_desc" containing the first command comment statement. Therefore, the command parameter "T001" corresponding to the command identifier "@task_name" of the first command comment statement is assigned to the global variable "task_name" corresponding to the command identifier of the first command comment statement in the global variable group, and the first command comment statement The command parameter "true" corresponding to the command identifier "@autocommit" is assigned to the global variable "autocommit" corresponding to the command identifier of the first command comment statement in the global variable group, and the command identifier "@task_desc" of the first command comment statement corresponds to The command parameter "Backup user table once a day" is assigned to the global variable "task_desc" corresponding to the command identifier of the first command comment statement in the global variable group. The global variable group after assignment is "task_name=T001; autocommit=true; task_desc= Back up the user table once a day".
第二解析模块204,用于读取所述第二命令注释语句,解析所述第二命令注释语句的命令标识和命令参数,根据所述第二命令注释语句的命令标识判断所述第二命令注释语句的类别。The second parsing module 204 is configured to read the second command comment sentence, parse the command identifier and command parameter of the second command comment sentence, and determine the second command according to the command identifier of the second command comment sentence The category of the comment statement.
在一实施例中,所述第二命令注释语句包括第二命令识别字符,则根据所述第二命令识别字符读取所述第二命令注释语句。In an embodiment, the second command comment sentence includes a second command recognition character, and the second command comment sentence is read according to the second command recognition character.
所述第二命令注释语句具有固定的格式,根据所述第二命令注释语句的格式解析所述第二命令注释语句的命令标识和命令参数。所述第二命令注释语句可以包括多个命令标识和多个命令参数,其中,命令标识和命令参数一一对应。The second command comment sentence has a fixed format, and the command identifier and command parameter of the second command comment sentence are parsed according to the format of the second command comment sentence. The second command comment statement may include multiple command identifiers and multiple command parameters, where the command identifiers and the command parameters have a one-to-one correspondence.
所述根据所述第二命令注释语句的命令标识判断所述第二命令注释语句的类别包括:The judging the category of the second command comment sentence according to the command identifier of the second command comment sentence includes:
若所述第二命令注释语句的命令标识为@step_name或@step_desc,则所述第二命令注释语句的类别为插入命令注释语句;If the command identifier of the second command comment sentence is @step_name or @step_desc, the category of the second command comment sentence is an insert command comment sentence;
若所述第二命令注释语句的命令标识为@autocommit,则所述第二命令注释语句的类别为提交命令注释语句。If the command identifier of the second command comment sentence is @autocommit, the category of the second command comment sentence is a submit command comment sentence.
第一插入模块205,用于若所述第二命令注释语句的类别为插入命令注释语句,通过所述全局变量组将所述插入命令注释语句的命令参数插入日志表,所述插入命令注释语句的命令参数包括与所述插入命令注释语句对应的SQL语句的日志信息。The first insert module 205 is configured to insert the command parameter of the insert command comment sentence into the log table through the global variable group if the type of the second command comment sentence is the insert command comment sentence, the insert command comment sentence The command parameter of includes the log information of the SQL statement corresponding to the insert command comment statement.
在一具体实施例中,所述通过所述全局变量组将所述插入命令注释语句的命令参数插入日志表包括:In a specific embodiment, the inserting the command parameter of the insert command comment statement into the log table through the global variable group includes:
查询预设的命令标识-全局变量表,确定所述全局变量组中所述插入命令注释语句的命令标识对应的全局变量;Query the preset command identifier-global variable table, and determine the global variable corresponding to the command identifier of the inserted command comment sentence in the global variable group;
将所述插入命令注释语句的命令参数赋值给所述全局变量组中所述插入命令注释语句的命令标识对应的全局变量,其中所述插入命令注释语句的命令参数与所述插入命令注释语句的命令标识一一对应;Assign the command parameter of the insert command comment sentence to the global variable corresponding to the command identifier of the insert command comment sentence in the global variable group, wherein the command parameter of the insert command comment sentence is the same as that of the insert command comment sentence. One-to-one correspondence between command identifiers;
根据所述全局变量组生成第一日志插入语句;Generating a first log insertion statement according to the global variable group;
执行所述第一日志插入语句,将所述全局变量组中所述插入命令注释语句的命令标识对应的全局变量插入所述日志表。The first log insert statement is executed, and the global variable corresponding to the command identifier of the insert command comment statement in the global variable group is inserted into the log table.
例如,插入命令注释语句为“@step_name=backup_table;@step_desc=备份表”。查询预设的命令标识-全局变量表,确定全局变量组中插入命令注释语句的命令标识对应的全局变量为“step_name=null;step_desc=null”。将插入命令注释语句的命令参数“backup_table”赋值给全局变量组中插入命令注释语句的命令标识“@step_name”对应的全局变量“step_name”,将插入命令注释语句的命令参数“备份表”赋值给全局变量组中插入命令注释语句的命令标识“@step_desc”对应的全局变量“step_desc”,赋值后的与插入命令注释语句的命令标识对应的全局变量为“step_name=backup_table;step_desc=备份表”。根据全局变量组“task_name=T001;autocommit=true;task_desc=每天备份一次用户表;step_name=backup_table;step_desc=备份表”生成第一日志插入语句“Insert into etl_task_log(task_name,step_name,step_desc,start_time)values(T001,backup_table,’备份表’,now())”,其中“now()”为获取当前时间的函数。执行第一日志插入语句,将全局变量组中插入命令注释语句的命令标识对应的全局变量插入日志表。For example, insert the command comment statement as "@step_name=backup_table; @step_desc=backup table". Query the preset command ID-global variable table, and determine that the global variable corresponding to the command ID of the command comment statement inserted in the global variable group is "step_name=null; step_desc=null". Assign the command parameter "backup_table" of the inserted command comment statement to the global variable "step_name" corresponding to the command ID "@step_name" of the command comment statement inserted in the global variable group, and assign the command parameter "backup table" of the inserted command comment statement to The global variable "step_desc" corresponding to the command identifier "@step_desc" of the inserted command comment statement in the global variable group, and the global variable corresponding to the command identifier of the inserted command comment statement after assignment is "step_name=backup_table; step_desc=backup table". According to the global variable group "task_name = T001; autocommit = true; task_desc = backup user table once a day; step_name = backup_table; step_desc = backup table" to generate the first log insert statement "Insert into etl_task_log(task_name, step_name, step_desc, start_time) values (T001,backup_table,'backup table',now())", where "now()" is a function to get the current time. The first log insert statement is executed, and the global variable corresponding to the command identifier of the command comment statement inserted in the global variable group is inserted into the log table.
第二插入模块206,用于读取所述第二命令注释语句对应的SQL语句,执行所述SQL语句。The second insert module 206 is configured to read the SQL statement corresponding to the second command comment statement, and execute the SQL statement.
所述第二命令注释语句对应的SQL语句是不包括所述命令识别字符和所述注释识别字符的代码行。The SQL sentence corresponding to the second command comment sentence is a code line that does not include the command recognition character and the comment recognition character.
执行所述SQL语句就是根据所述SQL语句对数据库进行操作,以实现所述任务配 置文件描述的数据库操作任务,如将给定数据导入数据库中。Executing the SQL statement is to operate the database according to the SQL statement to realize the database operation task described in the task configuration file, such as importing given data into the database.
第二插入模块206,还用于若所述SQL语句执行失败,生成所述SQL语句的执行错误信息,将所述SQL语句的执行错误信息赋值给所述全局变量组中所述执行错误信息对应的全局变量,通过所述全局变量组将所述执行错误信息插入所述日志表。The second insert module 206 is further configured to generate execution error information of the SQL statement if the execution of the SQL statement fails, and assign the execution error information of the SQL statement to the execution error information corresponding to the global variable group The execution error information is inserted into the log table through the global variable group.
在一具体实施例中,生成所述SQL语句的执行错误信息包括:In a specific embodiment, generating execution error information of the SQL statement includes:
(1)将所述SQL语句的执行标识信息赋值为“false”。所述SQL语句的执行标识信息初始值为“true”,将所述SQL语句的执行标识信息赋值为“false”,表明所述SQL语句执行失败。(1) Assign the execution identification information of the SQL statement to "false". The initial value of the execution identification information of the SQL statement is "true", and the execution identification information of the SQL statement is assigned a value of "false", indicating that the execution of the SQL statement failed.
(2)判断所述SQL语句中的参数是否正确,若所述SQL语句中的参数不正确,生成第一执行错误信息。可以判断所述SQL语句中的参数的数据类型是否正确,以及判断所述SQL语句中的参数的数值是否为预设值。若所述SQL语句中的参数的数据类型不正确,或者所述SQL语句中的参数的参数不是预设值,则所述SQL语句中的参数不正确,生成第一执行错误信息。(2) Determine whether the parameters in the SQL statement are correct, and if the parameters in the SQL statement are incorrect, generate a first execution error message. It can be judged whether the data type of the parameter in the SQL statement is correct, and whether the value of the parameter in the SQL statement is a preset value. If the data type of the parameter in the SQL statement is incorrect, or the parameter of the parameter in the SQL statement is not a preset value, the parameter in the SQL statement is incorrect, and a first execution error message is generated.
(3)判断所述SQL语句中的表是否正确,若所述SQL语句中的表不正确,生成第二执行错误信息。可以判断所述SQL语句中的表是否存在,以及判断是否有所述SQL语句中的表的访问权限,若所述SQL语句中的表不存在,或者没有所述SQL语句中的表的访问权限,则所述SQL语句中的表不正确,生成第二执行错误信息。(3) Determine whether the table in the SQL statement is correct, and if the table in the SQL statement is incorrect, generate a second execution error message. It can be judged whether the table in the SQL statement exists, and whether there is access permission to the table in the SQL statement, if the table in the SQL statement does not exist, or there is no access permission to the table in the SQL statement , The table in the SQL statement is incorrect, and a second execution error message is generated.
(4)若所述SQL语句中的参数正确且所述SQL语句中的表正确,生成第三执行错误信息。若所述SQL语句中的参数正确且所述SQL语句中的表正确,表示执行所述SQL语句的过程中出现了其他错误,则生成第三执行错误信息。(4) If the parameters in the SQL statement are correct and the tables in the SQL statement are correct, a third execution error message is generated. If the parameters in the SQL statement are correct and the tables in the SQL statement are correct, it means that other errors have occurred during the execution of the SQL statement, and a third execution error message is generated.
将所述SQL语句的执行错误信息赋值给所述全局变量组中所述执行错误信息对应的全局变量就是将所述执行错误信息转换为字符串赋值给所述全局变量组中与所述执行错误信息对应的全局变量。例如,将包括执行标识信息“false”、第一执行错误信息“false001”、第二执行错误信息“false002”转换为字符串“false$false001$false002”赋值给全局变量组中与执行错误信息对应的全局变量“status=false$false001$false002”。或者,将包括执行标识信息“false”、第三执行错误信息“false003”转换为字符串“false$false003”赋值给全局变量组中与执行错误信息对应的全局变量“status=false$false003”,其中“status”为与执行错误信息对应的全局变量。Assigning the execution error information of the SQL statement to the global variable corresponding to the execution error information in the global variable group is to convert the execution error information into a string and assign it to the global variable group and the execution error The global variable corresponding to the information. For example, convert the execution identification information "false", the first execution error information "false001", and the second execution error information "false002" into the string "false$false001$false002" and assign them to the global variable group corresponding to the execution error information The global variable "status=false$false001$false002". Or, converting the execution identification information "false" and the third execution error information "false003" into a character string "false$false003" and assigning it to the global variable "status=false$false003" corresponding to the execution error information in the global variable group, Among them, "status" is a global variable corresponding to the execution error message.
所述通过所述全局变量组将所述执行错误信息插入所述日志表包括:The inserting the execution error information into the log table through the global variable group includes:
(1)根据所述全局变量组生成第二日志插入语句。举例来说,根据所述全局变量组“task_name=T001;autocommit=true;task_desc=每天备份一次用户表;step_name= backup_table;step_desc=备份表;status=false$false003”生成第二日志插入语句“Insert into etl_task_log(task_name,step_name,step_desc,start_time,status)values(T001,backup_table,’备份表’,now(),false$false003)”。(1) Generate a second log insertion statement according to the global variable group. For example, according to the global variable group "task_name=T001; autocommit=true; task_desc= backup user table once a day; step_name= backup_table; step_desc= backup table; status=false$false003" to generate the second log insert statement "Insert" into etl_task_log(task_name,step_name,step_desc,start_time,status)values(T001,backup_table,'backup table',now(),false$false003)".
(2)执行所述第二日志插入语句,将所述全局变量中所述执行错误信息对应的全局变量插入所述日志表。(2) Execute the second log insertion statement, and insert the global variable corresponding to the execution error information in the global variable into the log table.
例如,执行“Insert into etl_task_log(task_name,step_name,step_desc,start_time,status)values(T001,backup_table,’备份表’,now(),false$false003)”,将所述全局变量中所述执行错误信息对应的全局变量插入所述日志表。For example, execute "Insert into etl_task_log(task_name,step_name,step_desc,start_time,status)values(T001,backup_table,'backup table',now(),false$false003)", and set the execution error information in the global variable The corresponding global variable is inserted into the log table.
实施例二的日志插入装置20设定任务配置文件,所述任务配置文件包括第一命令注释语句,第二命令注释语句和与所述第二命令注释语句对应的SQL语句;读取所述第一命令注释语句,解析所述第一命令注释语句的命令标识和命令参数;根据所述第一命令注释语句的命令标识和命令参数初始化所述任务配置文件对应的全局变量组;读取所述第二命令注释语句,解析所述第二命令注释语句的命令标识和命令参数,根据所述第二命令注释语句的命令标识判断所述第二命令注释语句的类别;若所述第二命令注释语句的类别为插入命令注释语句,通过所述全局变量组将所述插入命令注释语句的命令参数插入日志表,所述插入命令注释语句的命令参数包括与所述插入命令注释语句对应的SQL语句的日志信息;读取所述第二命令注释语句对应的SQL语句,执行所述SQL语句;若所述SQL语句执行失败,生成所述SQL语句的执行错误信息,将所述SQL语句的执行错误信息赋值给所述全局变量组中所述执行错误信息对应的全局变量,通过所述全局变量组将所述执行错误信息插入所述日志表。实施例二能够提升将SQL语句执行错误信息插入日志表的效率。The log insertion device 20 of the second embodiment sets a task configuration file, the task configuration file includes a first command comment sentence, a second command comment sentence and a SQL sentence corresponding to the second command comment sentence; reads the first command comment sentence A command comment sentence, parsing the command identifier and command parameter of the first command comment sentence; initialize the global variable group corresponding to the task configuration file according to the command identifier and command parameter of the first command comment sentence; read the The second command comment sentence, parse the command identifier and command parameter of the second command comment sentence, and judge the category of the second command comment sentence according to the command identifier of the second command comment sentence; if the second command comment The category of the sentence is the insert command comment sentence, the command parameter of the insert command comment sentence is inserted into the log table through the global variable group, and the command parameter of the insert command comment sentence includes the SQL sentence corresponding to the insert command comment sentence Read the SQL statement corresponding to the comment statement of the second command, execute the SQL statement; if the SQL statement fails to execute, generate the execution error information of the SQL statement, and the execution error of the SQL statement The information is assigned to the global variable corresponding to the execution error information in the global variable group, and the execution error information is inserted into the log table through the global variable group. The second embodiment can improve the efficiency of inserting SQL statement execution error information into the log table.
在另一实施例中,所述日志插入装置20还可以包括:提交模块,用于若所述第二命令注释语句的类别为提交命令注释语句,则判断所述提交命令注释语句中的命令参数是否为“true”;若所述提交命令注释语句中的命令参数为“true”,则提交所述SQL语句对应的数据库事务。In another embodiment, the log insertion device 20 may further include: a submit module, configured to determine the command parameters in the submit command comment sentence if the type of the second command comment sentence is a submit command comment sentence Whether it is "true"; if the command parameter in the submit command comment statement is "true", then the database transaction corresponding to the SQL statement is submitted.
在另一实施例中,所述日志插入装置20还可以包括:输出模块,用于若所述SQL语句执行失败,则判断所述第一命令注释语句中用于控制输出日志信息的命令参数是否为“true”,若所述第一命令注释语句中用于控制输出日志信息的命令参数为“true”,则输出所述日志表中所述SQL语句的执行失败信息。In another embodiment, the log insertion device 20 may further include: an output module, configured to determine whether the command parameter used to control the output of the log information in the first command comment statement if the SQL statement fails to execute Is "true", if the command parameter used to control the output of log information in the first command comment statement is "true", then the execution failure information of the SQL statement in the log table is output.
在另一实施例中,所述日志插入装置20还可以包括:第一判断模块,用于在所述根据所述第一命令注释语句的命令标识和命令参数初始化所述任务配置文件对应的全局 变量组之前,判断所述第一命令注释语句中的命令标识是否包含在所述命令标识-全局变量表中。若所述第一命令注释语句中的命令标识包含在所述命令标识-全局变量表中,则所述初始化模块203根据所述第一命令注释语句的命令标识和命令参数初始化所述任务配置文件对应的全局变量组。In another embodiment, the log insertion device 20 may further include: a first judgment module configured to initialize the global corresponding to the task configuration file according to the command identifier and command parameters of the first command comment statement. Before the variable group, it is judged whether the command identifier in the first command comment sentence is included in the command identifier-global variable table. If the command identifier in the first command comment sentence is included in the command identifier-global variable table, the initialization module 203 initializes the task configuration file according to the command identifier and command parameters of the first command comment sentence The corresponding global variable group.
在另一实施例中,所述日志插入装置20还可以包括:第二判断模块,用于在所述根据所述第二命令注释语句的命令标识判断所述第二命令注释语句的类别之前,判断所述第二命令注释语句中的命令标识是否包含在所述命令标识-全局变量表中。若所述第二命令注释语句中的命令标识包含在所述命令标识-全局变量表中,则所述第二解析模块204根据所述第二命令注释语句的命令标识判断所述第二命令注释语句的类别。In another embodiment, the log insertion device 20 may further include: a second judgment module, configured to, before judging the category of the second command comment sentence according to the command identifier of the second command comment sentence, It is determined whether the command identifier in the second command comment sentence is included in the command identifier-global variable table. If the command identifier in the second command comment sentence is included in the command identifier-global variable table, the second parsing module 204 determines the second command comment according to the command identifier of the second command comment sentence The category of the statement.
实施例三Example three
本实施例提供一种非易失性可读存储介质,该非易失性可读存储介质上存储有计算机可读指令,该计算机可读指令被处理器执行时实现上述日志插入方法实施例中的步骤,例如图1所示的步骤S101-S107;或者,该计算机可读指令被处理器执行时实现上述装置实施例中各模块的功能,例如图2中的模块201-206。This embodiment provides a non-volatile readable storage medium having computer readable instructions stored on the non-volatile readable storage medium, and when the computer readable instructions are executed by a processor, the above log insertion method embodiment is implemented For example, the steps S101-S107 shown in FIG. 1; or, when the computer-readable instructions are executed by the processor, the functions of the modules in the above-mentioned device embodiment are realized, for example, the modules 201-206 in FIG.
实施例四Example four
图3为本申请实施例四提供的计算机装置的示意图。所述计算机装置30包括存储器301、处理器302以及存储在所述存储器301中并可在所述处理器302上运行的计算机可读指令303,例如日志插入程序。所述处理器302执行所述计算机可读指令303时实现上述日志插入方法实施例中的步骤,例如图1所示的步骤S101-S107;或者,该计算机可读指令被处理器执行时实现上述装置实施例中各模块的功能,例如图2中的模块201-206。FIG. 3 is a schematic diagram of a computer device provided in Embodiment 4 of this application. The computer device 30 includes a memory 301, a processor 302, and computer-readable instructions 303 stored in the memory 301 and running on the processor 302, such as a log insertion program. When the processor 302 executes the computer-readable instruction 303, the steps in the log insertion method embodiment are implemented, for example, steps S101-S107 shown in FIG. 1; or, the computer-readable instruction is executed by the processor to implement the foregoing steps. The function of each module in the device embodiment is, for example, the modules 201-206 in FIG. 2.
示例性的,所述计算机可读指令303可以被分割成一个或多个模块,所述一个或者多个模块被存储在所述存储器301中,并由所述处理器302执行,以完成本方法。例如,所述计算机可读指令303可以被分割成图2中的设定模块201、第一解析模块202、初始化模块203、第二解析模块204、第一插入模块205、第二插入模块206,各模块具体功能参见实施例二。Exemplarily, the computer-readable instruction 303 may be divided into one or more modules, and the one or more modules are stored in the memory 301 and executed by the processor 302 to complete the method . For example, the computer-readable instruction 303 can be divided into the setting module 201, the first analysis module 202, the initialization module 203, the second analysis module 204, the first insertion module 205, and the second insertion module 206 in FIG. 2. For specific functions of each module, refer to Embodiment 2.
所述计算机装置30可以是桌上型计算机、笔记本、掌上电脑及云端服务器等计算设备。本领域技术人员可以理解,所述示意图3仅仅是计算机装置30的示例,并不构成对计算机装置30的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件,例如所述计算机装置30还可以包括输入输出设备、网络接入设备、总线等。The computer device 30 may be a computing device such as a desktop computer, a notebook, a palmtop computer, and a cloud server. Those skilled in the art can understand that the schematic diagram 3 is only an example of the computer device 30 and does not constitute a limitation on the computer device 30. It may include more or less components than those shown in the figure, or combine certain components, or be different. For example, the computer device 30 may also include input and output devices, network access devices, buses, etc.
所称处理器302可以是中央处理单元(Central Processing Unit,CPU),还可以是其他 通用处理器、数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现场可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。通用处理器可以是微处理器或者该处理器302也可以是任何常规的处理器等,所述处理器302是所述计算机装置30的控制中心,利用各种接口和线路连接整个计算机装置30的各个部分。The so-called processor 302 may be a central processing unit (Central Processing Unit, CPU), other general-purpose processors, digital signal processors (Digital Signal Processor, DSP), application specific integrated circuits (ASIC), Field-Programmable Gate Array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor 302 can also be any conventional processor, etc. The processor 302 is the control center of the computer device 30 and connects the entire computer device 30 with various interfaces and lines. Various parts.
所述存储器301可用于存储所述计算机可读指令303,所述处理器302通过运行或执行存储在所述存储器301内的计算机可读指令或模块,以及调用存储在存储器301内的数据,实现所述计算机装置30的各种功能。所述存储器301可主要包括存储程序区和存储数据区,其中,存储程序区可存储操作系统、至少一个功能所需的应用程序(比如声音播放功能、图像播放功能等)等;存储数据区可存储根据计算机装置30的使用所创建的数据。此外,存储器301可以包括非易失性存储器,例如硬盘、内存、插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)、至少一个磁盘存储器件、闪存器件、或其他非易失性固态存储器件。The memory 301 may be used to store the computer-readable instructions 303, and the processor 302 executes or executes the computer-readable instructions or modules stored in the memory 301, and calls data stored in the memory 301 to implement Various functions of the computer device 30. The memory 301 may mainly include a program storage area and a data storage area. The program storage area may store an operating system, an application program required by at least one function (such as a sound playback function, an image playback function, etc.), etc.; The data created according to the use of the computer device 30 is stored. In addition, the memory 301 may include non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a Secure Digital (SD) card, a flash memory card (Flash Card), At least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device.
所述计算机装置30集成的模块如果以软件功能模块的形式实现并作为独立的产品销售或使用时,可以存储在一个非易失性可读存储介质中。基于这样的理解,本申请实现上述实施例方法中的全部或部分流程,也可以通过计算机可读指令来指令相关的硬件来完成,所述的计算机可读指令可存储于一非易失性可读存储介质中,该计算机可读指令在被处理器执行时,可实现上述各个方法实施例的步骤。其中,所述计算机可读指令可以为源代码形式、对象代码形式、可执行文件或某些中间形式等。所述非易失性可读存储介质可以包括:能够携带所述计算机可读指令代码的任何实体或装置、记录介质、U盘、移动硬盘、磁碟、光盘、只读存储器(ROM,Read-Only Memory)。If the integrated module of the computer device 30 is implemented in the form of a software function module and sold or used as an independent product, it may be stored in a non-volatile readable storage medium. Based on this understanding, this application implements all or part of the processes in the above-mentioned embodiments and methods, and can also be completed by instructing relevant hardware through computer-readable instructions. The computer-readable instructions can be stored in a non-volatile memory. In the read storage medium, when the computer-readable instructions are executed by the processor, the steps of the foregoing method embodiments can be implemented. Wherein, the computer-readable instructions may be in the form of source code, object code, executable file, or some intermediate forms, etc. The non-volatile readable storage medium may include: any entity or device capable of carrying the computer-readable instruction code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, read-only memory (ROM, Read- Only Memory).
在本申请所提供的几个实施例中,应该理解到,所揭露的系统,装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述模块的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式。In the several embodiments provided in this application, it should be understood that the disclosed system, device, and method may be implemented in other ways. For example, the device embodiments described above are only illustrative. For example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation.
最后应说明的是,以上实施例仅用以说明本申请的技术方案而非限制,尽管参照较佳实施例对本申请进行了详细说明,本领域的普通技术人员应当理解,可以对本申请的技术方案进行修改或等同替换,而不脱离本申请技术方案的精神和范围。Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the application and not to limit them. Although the application has been described in detail with reference to the preferred embodiments, those of ordinary skill in the art should understand that the technical solutions of the application can be Make modifications or equivalent replacements without departing from the spirit and scope of the technical solution of the present application.

Claims (20)

  1. 一种日志插入方法,其特征在于,所述方法包括:A log insertion method, characterized in that the method includes:
    设定任务配置文件,所述任务配置文件包括第一命令注释语句,第二命令注释语句和与所述第二命令注释语句对应的SQL语句;Setting a task configuration file, the task configuration file including a first command comment statement, a second command comment statement, and a SQL statement corresponding to the second command comment statement;
    读取所述第一命令注释语句,解析所述第一命令注释语句的命令标识和命令参数;Read the first command comment sentence, and parse the command identifier and command parameters of the first command comment sentence;
    根据所述第一命令注释语句的命令标识和命令参数初始化所述任务配置文件对应的全局变量组;Initialize the global variable group corresponding to the task configuration file according to the command identifier and the command parameter of the first command comment statement;
    读取所述第二命令注释语句,解析所述第二命令注释语句的命令标识和命令参数,根据所述第二命令注释语句的命令标识判断所述第二命令注释语句的类别;Read the second command comment sentence, parse the command identifier and command parameter of the second command comment sentence, and determine the type of the second command comment sentence according to the command identifier of the second command comment sentence;
    若所述第二命令注释语句的类别为插入命令注释语句,通过所述全局变量组将所述插入命令注释语句的命令参数插入日志表,所述插入命令注释语句的命令参数包括与所述插入命令注释语句对应的SQL语句的日志信息;If the category of the second command comment sentence is an insert command comment sentence, insert the command parameter of the insert command comment sentence into the log table through the global variable group, and the command parameter of the insert command comment sentence includes the same as the insert command comment sentence. The log information of the SQL statement corresponding to the command comment statement;
    读取所述第二命令注释语句对应的SQL语句,执行所述SQL语句;Read the SQL statement corresponding to the second command comment statement, and execute the SQL statement;
    若所述SQL语句执行失败,生成所述SQL语句的执行错误信息,将所述SQL语句的执行错误信息赋值给所述全局变量组中所述执行错误信息对应的全局变量,通过所述全局变量组将所述执行错误信息插入所述日志表。If the execution of the SQL statement fails, the execution error information of the SQL statement is generated, and the execution error information of the SQL statement is assigned to the global variable corresponding to the execution error information in the global variable group, through the global variable The group inserts the execution error information into the log table.
  2. 如权利要求1所述的方法,其特征在于,所述根据所述第一命令注释语句的命令标识和命令参数初始化所述任务配置文件对应的全局变量组包括:The method according to claim 1, wherein the initializing the global variable group corresponding to the task configuration file according to the command identifier and the command parameter of the first command comment statement comprises:
    将所述全局变量组中的全局变量初始化为空值;Initializing the global variables in the global variable group to a null value;
    查询预设的命令标识-全局变量表,判断所述全局变量组中是否包含所述第一命令注释语句的命令标识对应的全局变量;Query the preset command identifier-global variable table, and determine whether the global variable group contains the global variable corresponding to the command identifier of the first command comment sentence;
    若所述全局变量组中包含所述第一命令注释语句的命令标识对应的全局变量,则将所述第一命令注释语句的命令标识对应的命令参数赋值给所述全局变量组中所述第一命令注释语句的命令标识对应的全局变量。If the global variable group contains the global variable corresponding to the command identifier of the first command comment sentence, the command parameter corresponding to the command identifier of the first command comment sentence is assigned to the first command parameter in the global variable group. The command identification of a command comment statement corresponds to the global variable.
  3. 如权利要求1所述的方法,其特征在于,所述通过所述全局变量组将所述插入命令注释语句的命令参数插入日志表包括:The method according to claim 1, wherein the inserting the command parameter of the insert command comment statement into the log table through the global variable group comprises:
    查询预设的命令标识-全局变量表,确定所述全局变量组中所述插入命令注释语句的命令标识对应的全局变量;Query the preset command identifier-global variable table, and determine the global variable corresponding to the command identifier of the inserted command comment sentence in the global variable group;
    将所述插入命令注释语句的命令参数赋值给所述全局变量组中所述插入命令注释语句的命令标识对应的全局变量;Assigning the command parameter of the insert command comment sentence to the global variable corresponding to the command identifier of the insert command comment sentence in the global variable group;
    根据所述全局变量组生成第一日志插入语句;Generating a first log insertion statement according to the global variable group;
    执行所述第一日志插入语句,将所述全局变量组中所述插入命令注释语句的命令标识对应的全局变量插入所述日志表。The first log insert statement is executed, and the global variable corresponding to the command identifier of the insert command comment statement in the global variable group is inserted into the log table.
  4. 如权利要求1所述的方法,其特征在于,所述生成所述SQL语句的执行错误信息包括:The method according to claim 1, wherein said generating execution error information of said SQL statement comprises:
    将所述SQL语句的执行标识信息赋值为“false”;Assigning the execution identification information of the SQL statement to "false";
    判断所述SQL语句中的参数是否正确,若所述SQL语句中的参数不正确,生成第一执行错误信息;Determine whether the parameters in the SQL statement are correct, and if the parameters in the SQL statement are incorrect, generate a first execution error message;
    判断所述SQL语句中的表是否正确,若所述SQL语句中的表不正确,生成第二执行错误信息;Determine whether the table in the SQL statement is correct, and if the table in the SQL statement is incorrect, generate a second execution error message;
    若所述SQL语句中的参数正确且所述SQL语句中的表正确,生成第三执行错误信息。If the parameters in the SQL statement are correct and the tables in the SQL statement are correct, a third execution error message is generated.
  5. 如权利要求1所述的方法,其特征在于,所述通过所述全局变量组将所述执行错误信息插入所述日志表包括:The method according to claim 1, wherein the inserting the execution error information into the log table through the global variable group comprises:
    根据所述全局变量组生成第二日志插入语句;Generating a second log insertion statement according to the global variable group;
    执行所述第二日志插入语句,将所述全局变量中所述执行错误信息对应的全局变量插入所述日志表。The second log insertion statement is executed, and the global variable corresponding to the execution error information in the global variable is inserted into the log table.
  6. 如权利要求1-5中任一项所述的方法,其特征在于,所述方法还包括:The method according to any one of claims 1-5, wherein the method further comprises:
    若所述第二命令注释语句的类别为提交命令注释语句,则判断所述提交命令注释语句中的命令参数是否为“true”;If the category of the second command comment sentence is a submit command comment sentence, it is determined whether the command parameter in the submit command comment sentence is "true";
    若所述提交命令注释语句中的命令参数为“true”,则提交所述SQL语句对应的数据库事务。If the command parameter in the comment statement of the submit command is "true", then the database transaction corresponding to the SQL statement is submitted.
  7. 如权利要求1-5中任一项所述的方法,其特征在于,所述方法还包括:The method according to any one of claims 1-5, wherein the method further comprises:
    若所述SQL语句执行失败,则判断所述第一命令注释语句中用于控制输出日志信息的命令参数是否为“true”;If the execution of the SQL statement fails, it is determined whether the command parameter used to control the output log information in the first command comment statement is "true";
    若所述第一命令注释语句中用于控制输出日志信息的命令参数为“true”,则输出所述日志表中所述SQL语句的执行失败信息。If the command parameter used to control the output of log information in the first command comment statement is "true", then the execution failure information of the SQL statement in the log table is output.
  8. 一种日志插入装置,其特征在于,所述装置包括:A log insertion device, characterized in that the device includes:
    设定模块,用于设定任务配置文件,所述任务配置文件包括第一命令注释语句,第二命令注释语句和与所述第二命令注释语句对应的SQL语句;A setting module for setting a task configuration file, the task configuration file including a first command comment statement, a second command comment statement, and a SQL statement corresponding to the second command comment statement;
    第一解析模块,用于读取所述第一命令注释语句,解析所述第一命令注释语句的命令标识和命令参数;The first parsing module is configured to read the first command comment sentence and parse the command identifier and command parameters of the first command comment sentence;
    初始化模块,用于根据所述第一命令注释语句的命令标识和命令参数初始化所述任务配置文件对应的全局变量组;An initialization module, configured to initialize the global variable group corresponding to the task configuration file according to the command identifier and command parameters of the first command comment statement;
    第二解析模块,用于读取所述第二命令注释语句,解析所述第二命令注释语句的命令标识和命令参数,根据所述第二命令注释语句的命令标识判断所述第二命令注释语句的类别;The second parsing module is configured to read the second command comment sentence, parse the command identifier and command parameter of the second command comment sentence, and determine the second command comment according to the command identifier of the second command comment sentence Type of sentence;
    第一插入模块,用于若所述第二命令注释语句的类别为插入命令注释语句,通过所述全局变量组将所述插入命令注释语句的命令参数插入日志表,所述插入命令注释语句的命令参数包括与所述插入命令注释语句对应的SQL语句的日志信息;The first insert module is used to insert the command parameter of the insert command comment sentence into the log table through the global variable group if the type of the second command comment sentence is the insert command comment sentence. The command parameter includes log information of the SQL statement corresponding to the insert command comment statement;
    第二插入模块,用于读取所述第二命令注释语句对应的SQL语句,执行所述SQL语句,若所述SQL语句执行失败,生成所述SQL语句的执行错误信息,将所述SQL语句的执行错误信息赋值给所述全局变量组中所述执行错误信息对应的全局变量,通过所述全局变量组将所述执行错误信息插入所述日志表。The second insert module is used to read the SQL statement corresponding to the second command comment statement, execute the SQL statement, if the SQL statement fails to execute, generate the execution error information of the SQL statement, and convert the SQL statement The execution error information of is assigned to the global variable corresponding to the execution error information in the global variable group, and the execution error information is inserted into the log table through the global variable group.
  9. 一种计算机装置,其特征在于,所述计算机装置包括处理器和存储器,所述处理器用于执行所述存储器中存储的计算机可读指令以实现以下步骤:A computer device, wherein the computer device includes a processor and a memory, and the processor is configured to execute computer-readable instructions stored in the memory to implement the following steps:
    设定任务配置文件,所述任务配置文件包括第一命令注释语句,第二命令注释语句和与所述第二命令注释语句对应的SQL语句;Setting a task configuration file, the task configuration file including a first command comment statement, a second command comment statement, and a SQL statement corresponding to the second command comment statement;
    读取所述第一命令注释语句,解析所述第一命令注释语句的命令标识和命令参数;Read the first command comment sentence, and parse the command identifier and command parameters of the first command comment sentence;
    根据所述第一命令注释语句的命令标识和命令参数初始化所述任务配置文件对应的全局变量组;Initialize the global variable group corresponding to the task configuration file according to the command identifier and the command parameter of the first command comment statement;
    读取所述第二命令注释语句,解析所述第二命令注释语句的命令标识和命令参数,根据所述第二命令注释语句的命令标识判断所述第二命令注释语句的类别;Read the second command comment sentence, parse the command identifier and command parameter of the second command comment sentence, and determine the type of the second command comment sentence according to the command identifier of the second command comment sentence;
    若所述第二命令注释语句的类别为插入命令注释语句,通过所述全局变量组将所述插入命令注释语句的命令参数插入日志表,所述插入命令注释语句的命令参数包括与所述插入命令注释语句对应的SQL语句的日志信息;If the category of the second command comment sentence is an insert command comment sentence, insert the command parameter of the insert command comment sentence into the log table through the global variable group, and the command parameter of the insert command comment sentence includes the same as the insert command comment sentence. The log information of the SQL statement corresponding to the command comment statement;
    读取所述第二命令注释语句对应的SQL语句,执行所述SQL语句;Read the SQL statement corresponding to the second command comment statement, and execute the SQL statement;
    若所述SQL语句执行失败,生成所述SQL语句的执行错误信息,将所述SQL语句的执行错误信息赋值给所述全局变量组中所述执行错误信息对应的全局变量,通过所述全局变量组将所述执行错误信息插入所述日志表。If the execution of the SQL statement fails, the execution error information of the SQL statement is generated, and the execution error information of the SQL statement is assigned to the global variable corresponding to the execution error information in the global variable group, through the global variable The group inserts the execution error information into the log table.
  10. 如权利要求9所述的计算机装置,其特征在于,所述处理器执行所述存储器中存储的计算机可读指令以实现所述根据所述第一命令注释语句的命令标识和命令参数初始化所述任务配置文件对应的全局变量组时,包括:The computer device according to claim 9, wherein the processor executes computer-readable instructions stored in the memory to implement the initialization of the command identifier and command parameters according to the first command comment statement The global variable group corresponding to the task configuration file includes:
    将所述全局变量组中的全局变量初始化为空值;Initializing the global variables in the global variable group to a null value;
    查询预设的命令标识-全局变量表,判断所述全局变量组中是否包含所述第一命令注释语句的命令标识对应的全局变量;Query the preset command identifier-global variable table, and determine whether the global variable group contains the global variable corresponding to the command identifier of the first command comment sentence;
    若所述全局变量组中包含所述第一命令注释语句的命令标识对应的全局变量,则将所述第一命令注释语句的命令标识对应的命令参数赋值给所述全局变量组中所述第一命令注释语句的命令标识对应的全局变量。If the global variable group contains the global variable corresponding to the command identifier of the first command comment sentence, the command parameter corresponding to the command identifier of the first command comment sentence is assigned to the first command parameter in the global variable group. The command identification of a command comment statement corresponds to the global variable.
  11. 如权利要求9所述的计算机装置,其特征在于,所述处理器执行所述存储器中存储的计算机可读指令以实现所述通过所述全局变量组将所述插入命令注释语句的命令参数插入日志表时,包括:The computer device according to claim 9, wherein the processor executes computer-readable instructions stored in the memory to implement the insertion of the command parameter of the insert command comment statement through the global variable group The log table includes:
    查询预设的命令标识-全局变量表,确定所述全局变量组中所述插入命令注释语句的命令标识对应的全局变量;Query the preset command identifier-global variable table, and determine the global variable corresponding to the command identifier of the inserted command comment sentence in the global variable group;
    将所述插入命令注释语句的命令参数赋值给所述全局变量组中所述插入命令注释语句的命令标识对应的全局变量;Assigning the command parameter of the insert command comment sentence to the global variable corresponding to the command identifier of the insert command comment sentence in the global variable group;
    根据所述全局变量组生成第一日志插入语句;Generating a first log insertion statement according to the global variable group;
    执行所述第一日志插入语句,将所述全局变量组中所述插入命令注释语句的命令标识对应的全局变量插入所述日志表。The first log insert statement is executed, and the global variable corresponding to the command identifier of the insert command comment statement in the global variable group is inserted into the log table.
  12. 如权利要求9所述的计算机装置,其特征在于,所述处理器执行所述存储器中存储的计算机可读指令以实现所述生成所述SQL语句的执行错误信息时,包括:9. The computer device according to claim 9, wherein when the processor executes the computer-readable instructions stored in the memory to implement the generation of the execution error information of the SQL statement, the method comprises:
    将所述SQL语句的执行标识信息赋值为“false”;Assigning the execution identification information of the SQL statement to "false";
    判断所述SQL语句中的参数是否正确,若所述SQL语句中的参数不正确,生成第一执行错误信息;Determine whether the parameters in the SQL statement are correct, and if the parameters in the SQL statement are incorrect, generate a first execution error message;
    判断所述SQL语句中的表是否正确,若所述SQL语句中的表不正确,生成第二执行错误信息;Determine whether the table in the SQL statement is correct, and if the table in the SQL statement is incorrect, generate a second execution error message;
    若所述SQL语句中的参数正确且所述SQL语句中的表正确,生成第三执行错误信息。If the parameters in the SQL statement are correct and the tables in the SQL statement are correct, a third execution error message is generated.
  13. 如权利要求9所述的计算机装置,其特征在于,所述处理器执行所述存储器中存储的计算机可读指令以实现所述通过所述全局变量组将所述执行错误信息插入所述日志表时,包括:The computer device of claim 9, wherein the processor executes computer-readable instructions stored in the memory to implement the inserting the execution error information into the log table through the global variable group When including:
    根据所述全局变量组生成第二日志插入语句;Generating a second log insertion statement according to the global variable group;
    执行所述第二日志插入语句,将所述全局变量中所述执行错误信息对应的全局变量插入所述日志表。The second log insertion statement is executed, and the global variable corresponding to the execution error information in the global variable is inserted into the log table.
  14. 如权利要求9-13中任一项所述的计算机装置,其特征在于,所述处理器执行所述存储器中存储的计算机可读指令时还实现以下步骤:The computer device according to any one of claims 9-13, wherein the processor further implements the following steps when executing the computer-readable instructions stored in the memory:
    若所述第二命令注释语句的类别为提交命令注释语句,则判断所述提交命令注释语句中的命令参数是否为“true”;If the category of the second command comment sentence is a submit command comment sentence, it is determined whether the command parameter in the submit command comment sentence is "true";
    若所述提交命令注释语句中的命令参数为“true”,则提交所述SQL语句对应的数据库事务。If the command parameter in the comment statement of the submit command is "true", then the database transaction corresponding to the SQL statement is submitted.
  15. 一种非易失性可读存储介质,所述非易失性可读存储介质上存储有计算机可读指令,其特征在于,所述计算机可读指令被处理器执行时实现以下步骤:A non-volatile readable storage medium having computer readable instructions stored on the non-volatile readable storage medium, characterized in that, when the computer readable instructions are executed by a processor, the following steps are implemented:
    设定任务配置文件,所述任务配置文件包括第一命令注释语句,第二命令注释语句和与所述第二命令注释语句对应的SQL语句;Setting a task configuration file, the task configuration file including a first command comment statement, a second command comment statement, and a SQL statement corresponding to the second command comment statement;
    读取所述第一命令注释语句,解析所述第一命令注释语句的命令标识和命令参数;Read the first command comment sentence, and parse the command identifier and command parameters of the first command comment sentence;
    根据所述第一命令注释语句的命令标识和命令参数初始化所述任务配置文件对应的全局变量组;Initialize the global variable group corresponding to the task configuration file according to the command identifier and the command parameter of the first command comment statement;
    读取所述第二命令注释语句,解析所述第二命令注释语句的命令标识和命令参数,根据所述第二命令注释语句的命令标识判断所述第二命令注释语句的类别;Read the second command comment sentence, parse the command identifier and command parameter of the second command comment sentence, and determine the type of the second command comment sentence according to the command identifier of the second command comment sentence;
    若所述第二命令注释语句的类别为插入命令注释语句,通过所述全局变量组将所述插入命令注释语句的命令参数插入日志表,所述插入命令注释语句的命令参数包括与所述插入命令注释语句对应的SQL语句的日志信息;If the category of the second command comment sentence is an insert command comment sentence, insert the command parameter of the insert command comment sentence into the log table through the global variable group, and the command parameter of the insert command comment sentence includes the same as the insert command comment sentence. The log information of the SQL statement corresponding to the command comment statement;
    读取所述第二命令注释语句对应的SQL语句,执行所述SQL语句;Read the SQL statement corresponding to the second command comment statement, and execute the SQL statement;
    若所述SQL语句执行失败,生成所述SQL语句的执行错误信息,将所述SQL语句的执行错误信息赋值给所述全局变量组中所述执行错误信息对应的全局变量,通过所述全局变量组将所述执行错误信息插入所述日志表。If the execution of the SQL statement fails, the execution error information of the SQL statement is generated, and the execution error information of the SQL statement is assigned to the global variable corresponding to the execution error information in the global variable group, through the global variable The group inserts the execution error information into the log table.
  16. 如权利要求15所述的存储介质,其特征在于,所述计算机可读指令被所述处理器执行以实现所述根据所述第一命令注释语句的命令标识和命令参数初始化所述任务配置文件对应的全局变量组时,包括:The storage medium of claim 15, wherein the computer-readable instructions are executed by the processor to implement the initialization of the task configuration file according to the command identifier and command parameters of the first command comment statement The corresponding global variable group includes:
    将所述全局变量组中的全局变量初始化为空值;Initializing the global variables in the global variable group to a null value;
    查询预设的命令标识-全局变量表,判断所述全局变量组中是否包含所述第一命令注释语句的命令标识对应的全局变量;Query the preset command identifier-global variable table, and determine whether the global variable group contains the global variable corresponding to the command identifier of the first command comment sentence;
    若所述全局变量组中包含所述第一命令注释语句的命令标识对应的全局变量,则将所述第一命令注释语句的命令标识对应的命令参数赋值给所述全局变量组中所述第一命令注释语句的命令标识对应的全局变量。If the global variable group contains the global variable corresponding to the command identifier of the first command comment sentence, the command parameter corresponding to the command identifier of the first command comment sentence is assigned to the first command parameter in the global variable group. The command identification of a command comment statement corresponds to the global variable.
  17. 如权利要求15所述的存储介质,其特征在于,所述计算机可读指令被所述处理器执行以实现所述通过所述全局变量组将所述插入命令注释语句的命令参数插入日志表时,包 括:The storage medium according to claim 15, wherein the computer-readable instructions are executed by the processor to implement when the command parameters of the insert command comment statement are inserted into the log table through the global variable group ,include:
    查询预设的命令标识-全局变量表,确定所述全局变量组中所述插入命令注释语句的命令标识对应的全局变量;Query the preset command identifier-global variable table, and determine the global variable corresponding to the command identifier of the inserted command comment sentence in the global variable group;
    将所述插入命令注释语句的命令参数赋值给所述全局变量组中所述插入命令注释语句的命令标识对应的全局变量;Assigning the command parameter of the insert command comment sentence to the global variable corresponding to the command identifier of the insert command comment sentence in the global variable group;
    根据所述全局变量组生成第一日志插入语句;Generating a first log insertion statement according to the global variable group;
    执行所述第一日志插入语句,将所述全局变量组中所述插入命令注释语句的命令标识对应的全局变量插入所述日志表。The first log insert statement is executed, and the global variable corresponding to the command identifier of the insert command comment statement in the global variable group is inserted into the log table.
  18. 如权利要求15所述的存储介质,其特征在于,所述计算机可读指令被所述处理器执行以实现所述生成所述SQL语句的执行错误信息时,包括:15. The storage medium according to claim 15, wherein when the computer-readable instruction is executed by the processor to implement the generation of the execution error message of the SQL statement, it comprises:
    将所述SQL语句的执行标识信息赋值为“false”;Assigning the execution identification information of the SQL statement to "false";
    判断所述SQL语句中的参数是否正确,若所述SQL语句中的参数不正确,生成第一执行错误信息;Determine whether the parameters in the SQL statement are correct, and if the parameters in the SQL statement are incorrect, generate a first execution error message;
    判断所述SQL语句中的表是否正确,若所述SQL语句中的表不正确,生成第二执行错误信息;Determine whether the table in the SQL statement is correct, and if the table in the SQL statement is incorrect, generate a second execution error message;
    若所述SQL语句中的参数正确且所述SQL语句中的表正确,生成第三执行错误信息。If the parameters in the SQL statement are correct and the tables in the SQL statement are correct, a third execution error message is generated.
  19. 如权利要求15所述的存储介质,其特征在于,所述计算机可读指令被所述处理器执行以实现所述通过所述全局变量组将所述执行错误信息插入所述日志表时,包括:The storage medium according to claim 15, wherein when the computer-readable instructions are executed by the processor to implement the inserting the execution error information into the log table through the global variable group, it comprises :
    根据所述全局变量组生成第二日志插入语句;Generating a second log insertion statement according to the global variable group;
    执行所述第二日志插入语句,将所述全局变量中所述执行错误信息对应的全局变量插入所述日志表。The second log insertion statement is executed, and the global variable corresponding to the execution error information in the global variable is inserted into the log table.
  20. 如权利要求15-19中任一项所述的存储介质,其特征在于,所述计算机可读指令被所述处理器执行时还实现以下步骤:19. The storage medium according to any one of claims 15-19, wherein the computer-readable instructions further implement the following steps when being executed by the processor:
    若所述第二命令注释语句的类别为提交命令注释语句,则判断所述提交命令注释语句中的命令参数是否为“true”;If the category of the second command comment sentence is a submit command comment sentence, it is determined whether the command parameter in the submit command comment sentence is "true";
    若所述提交命令注释语句中的命令参数为“true”,则提交所述SQL语句对应的数据库事务。If the command parameter in the comment statement of the submit command is "true", then the database transaction corresponding to the SQL statement is submitted.
PCT/CN2019/117234 2019-08-07 2019-11-11 Log insertion method and apparatus, computer apparatus and storage medium WO2021022702A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910727085.6 2019-08-07
CN201910727085.6A CN110633258B (en) 2019-08-07 2019-08-07 Log insertion method, device, computer device and storage medium

Publications (1)

Publication Number Publication Date
WO2021022702A1 true WO2021022702A1 (en) 2021-02-11

Family

ID=68969308

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/117234 WO2021022702A1 (en) 2019-08-07 2019-11-11 Log insertion method and apparatus, computer apparatus and storage medium

Country Status (2)

Country Link
CN (1) CN110633258B (en)
WO (1) WO2021022702A1 (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112988524A (en) * 2021-03-12 2021-06-18 长鑫存储技术有限公司 Early warning method and device for service flow direction, storage medium and computer equipment
CN116701339A (en) * 2023-08-07 2023-09-05 拓锐科技有限公司 Data analysis processing method based on event log file

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040044637A1 (en) * 2002-08-30 2004-03-04 Thomas Vachuska Apparatus and method using reflection to generate database commands at runtime
CN104391995A (en) * 2014-12-15 2015-03-04 北京趣拿软件科技有限公司 SQL (Structured Query Language) statement auditing method, and database operation and maintenance method and system
CN108959571A (en) * 2018-07-04 2018-12-07 上海达梦数据库有限公司 Operation method, device, terminal device and the storage medium of SQL statement
CN109284282A (en) * 2018-10-22 2019-01-29 北京极数云舟科技有限公司 One kind being based on MySQL database O&M method and system

Family Cites Families (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6775683B2 (en) * 2001-11-27 2004-08-10 Ge Financial Assurance Holdings, Inc. Method and system for performing processing data
US7552147B2 (en) * 2005-09-02 2009-06-23 International Business Machines Corporation System and method for minimizing data outage time and data loss while handling errors detected during recovery
CN101464890B (en) * 2008-12-30 2012-05-23 中兴通讯股份有限公司 Mixed log generation method and resolution method
CN105608086B (en) * 2014-11-17 2021-07-27 中兴通讯股份有限公司 Transaction processing method and device for distributed database system
US10133614B2 (en) * 2015-03-24 2018-11-20 Ca, Inc. Anomaly classification, analytics and resolution based on annotated event logs
CN105446743A (en) * 2015-12-12 2016-03-30 天津南大通用数据技术股份有限公司 System and method for automatically generating SQL sentences
CN108733543B (en) * 2017-04-24 2021-11-12 北京京东尚科信息技术有限公司 Log analysis method and device, electronic equipment and readable storage medium
CN109918260A (en) * 2019-01-24 2019-06-21 平安科技(深圳)有限公司 A kind of monitoring method and device of item code

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040044637A1 (en) * 2002-08-30 2004-03-04 Thomas Vachuska Apparatus and method using reflection to generate database commands at runtime
CN104391995A (en) * 2014-12-15 2015-03-04 北京趣拿软件科技有限公司 SQL (Structured Query Language) statement auditing method, and database operation and maintenance method and system
CN108959571A (en) * 2018-07-04 2018-12-07 上海达梦数据库有限公司 Operation method, device, terminal device and the storage medium of SQL statement
CN109284282A (en) * 2018-10-22 2019-01-29 北京极数云舟科技有限公司 One kind being based on MySQL database O&M method and system

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112988524A (en) * 2021-03-12 2021-06-18 长鑫存储技术有限公司 Early warning method and device for service flow direction, storage medium and computer equipment
CN112988524B (en) * 2021-03-12 2022-10-11 长鑫存储技术有限公司 Early warning method and device for service flow direction, storage medium and computer equipment
CN116701339A (en) * 2023-08-07 2023-09-05 拓锐科技有限公司 Data analysis processing method based on event log file
CN116701339B (en) * 2023-08-07 2023-10-17 拓锐科技有限公司 Data analysis processing method based on event log file

Also Published As

Publication number Publication date
CN110633258A (en) 2019-12-31
CN110633258B (en) 2022-08-12

Similar Documents

Publication Publication Date Title
US7620959B2 (en) Reflection-based processing of input parameters for commands
US6442684B1 (en) Determining a current machine state of software
JP5690349B2 (en) Managing record format information
CN110347598B (en) Test script generation method and device, server and storage medium
CN108762743B (en) Data table operation code generation method and device
US9009175B2 (en) System and method for database migration and validation
US10394756B2 (en) System and method for customizing archive of a device driver generator tool for a user
WO2019134287A1 (en) Version information management method, electronic device and readable storage medium
WO2020258674A1 (en) Script file verification method and apparatus, server and storage medium
WO2023040056A1 (en) Multi-parser-based method and device for parsing and positioning heterogeneous data source operation resource
WO2021022702A1 (en) Log insertion method and apparatus, computer apparatus and storage medium
WO2023109074A1 (en) Method and apparatus for implementing linkage function, device, storage medium, and program
WO2021022703A1 (en) Software project reconstruction method and device, and computer device and storage medium
US8595559B2 (en) Method and apparatus for model-based testing of a graphical user interface
CN111782207A (en) Method, device and equipment for generating task stream code and storage medium
US10055330B2 (en) Feature file validation tool
CN114443039A (en) Input parameter verification method and device, electronic equipment and storage medium
CN113330425A (en) Remote diagnostics of computing devices
JP6516343B2 (en) Application user interface automatic test method, electronic device, system and storage medium
US20190317877A1 (en) Application state monitoring
WO2022111209A1 (en) Data acquisition method and apparatus, data acquisition device and readable storage medium
WO2021042532A1 (en) Database information analysis method and apparatus, computer apparatus, and storage medium
US11144287B2 (en) Compile time validation of programming code
US7917893B2 (en) Using a system of annotations to generate views and adapters
WO2024055862A1 (en) Document review method and apparatus for implementing ia by combining rpa and ai, and electronic device

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19940633

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19940633

Country of ref document: EP

Kind code of ref document: A1