SQL statement testing methods, devices, electronic equipment, and readable storage media
By analyzing Sql test instructions, converting or packaging Sql statements, the code testing process is simplified, the problem of complex and time-consuming testing process in the existing technology is solved, and the testing efficiency is improved.
Patent Information
- Application Number
- CN202111157611.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-30
- Publication Date
- 2025-04-22
- Estimated Expiration
- 2041-09-30
AI Technical Summary
The existing code testing methods are complex and time-consuming, resulting in inefficient testing.
By obtaining Sql test instructions, parsing test types and scopes, converting Sql statements into script format for logical testing, or packaging them into code packages for scanning and testing, simplifying the test process.
One-click testing of Sql code is implemented, simplifying the testing process and improving testing efficiency.
Smart Images

Figure CN113886244B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of software testing technology, and in particular to a SQL statement testing method, device, electronic device and computer-readable storage medium. Background Art
[0002] During the software development process, the logic of the underlying code is closely linked. Therefore, if there are problems such as different logic and incomplete data in the underlying code after development is completed, it will lead to the loss of the entire software function, resulting in a slow and inefficient repair or re-development process. Therefore, testing of the underlying code in the early development process has become an indispensable part of the development process.
[0003] Existing code testing methods mostly convert the code to be tested into a preset form, and test the code through different databases or script libraries and other platforms with testing functions. In the existing methods, the testing process is relatively lengthy, and when multiple code tests are required, a lot of time is consumed in the testing process, which reduces the efficiency of the test. Therefore, how to simplify the code testing process has become a problem that needs to be solved urgently. Summary of the invention
[0004] The present invention provides a SQL statement testing method, device and computer-readable storage medium, the main purpose of which is to solve the problem of complex process when performing code testing.
[0005] To achieve the above object, the present invention provides a SQL statement testing method, comprising:
[0006] Obtaining a SQL test instruction, and parsing the test type and test scope from the SQL test instruction;
[0007] When the test type is the same as the preset logic test type, converting the SQL statements within the test scope into a script format;
[0008] Use the preset database to perform logic tests on the SQL statements converted into script format, and display the results of the logic tests in a window;
[0009] When the test type is the same as the preset scan test type, the SQL statements within the test scope are packaged into a code package;
[0010] The code package is sent to a preset scanning platform for scanning test, the scanning test result returned by the preset scanning platform is obtained, and the scanning test result is displayed in a window.
[0011] Optionally, parsing the test type and test scope from the Sql test instruction includes:
[0012] Split the Sql test instruction into an instruction header and an instruction body;
[0013] parse the test type field from the instruction header using a preset parser, and determine the test type of the Sql test instruction according to the test type field;
[0014] Detecting whether the instruction body includes a message field;
[0015] When the instruction body contains a message field, the instruction body is deserialized to obtain a test range parameter, and the test range of the Sql test instruction is determined according to the test range parameter;
[0016] When the instruction body does not contain a message field, the instruction body is character string segmented to obtain a test range parameter, and the test range of the Sql test instruction is determined according to the test range parameter.
[0017] Optionally, the deserializing the instruction body to obtain the test range parameter includes:
[0018] Extracting the data content type in the instruction body;
[0019] Selecting a decoder corresponding to the data content type to deserialize the instruction body to obtain the data content;
[0020] Perform parameter analysis on the data content to obtain test range parameters.
[0021] Optionally, performing string segmentation on the instruction body to obtain a test range parameter includes:
[0022] The instruction body is segmented according to a preset string separator, and the segmented strings are numbered according to their positions in the instruction body;
[0023] The character string at a preset position in the instruction body is parsed to obtain a test range parameter.
[0024] Optionally, converting the SQL statements within the test scope into a script format includes:
[0025] Construct a blank Sql document, construct a main function in the Sql document, and write the Sql statements within the test scope into the main function;
[0026] The file type of the Sql document is converted into a script type to obtain a Sql statement in a script format.
[0027] Optionally, the using a preset database to perform a logic test on the SQL statement converted into a script format includes:
[0028] Obtaining login information of a preset database, using the login information to log in to the preset database, and calling an execution function of the preset database;
[0029] Utilize the execution function to execute the Sql statement converted into the script format to obtain the execution result;
[0030] Determining whether the execution result meets the expected result;
[0031] If the execution result does not match the expected result, a logical error in the SQL statement is determined;
[0032] If the execution result is consistent with the expected result, it is determined that the logic of the Sql statement is correct.
[0033] Optionally, sending the code package to a preset scanning platform for scanning testing includes:
[0034] Using a preset scanning platform to scan the data structure of the Sql statements in the code package to obtain the data structure of the Sql statements in the code package;
[0035] Determining whether the data structure conforms to a preset standard structure;
[0036] When the data structure conforms to the standard structure, the scanning test result of the complete Sql statement structure is output;
[0037] When the data structure does not conform to the standard structure, a scan test result indicating that the Sql statement structure is incomplete is output.
[0038] In order to solve the above problem, the present invention also provides a SQL statement testing device, the device comprising:
[0039] An instruction parsing module is used to obtain a SQL test instruction and parse the test type and test scope from the SQL test instruction;
[0040] The first test module is used for converting the SQL statements in the test range into a script format when the test type is the same as the preset logic test type, performing a logic test on the SQL statements converted into the script format using a preset database, and displaying the results of the logic test in a window;
[0041] The second test module is used to package the SQL statements within the test scope into a code package when the test type is the same as the preset scan test type, send the code package to the preset scan platform for scan testing, obtain the scan test results returned by the preset scan platform, and display the scan test results in a window.
[0042] In order to solve the above problem, the present invention further provides an electronic device, the electronic device comprising:
[0043] at least one processor; and,
[0044] a memory communicatively connected to the at least one processor; wherein,
[0045] The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the above-mentioned SQL statement testing method.
[0046] In order to solve the above problem, the present invention also provides a computer-readable storage medium, in which at least one computer program is stored. The at least one computer program is executed by a processor in an electronic device to implement the above-mentioned SQL statement testing method.
[0047] The embodiment of the present invention can obtain a Sql test instruction, determine the test type and test range to be performed based on the analysis of the Sql test instruction, and then select the Sql code according to the test range, and perform a response test on the selected Sql code according to the test type, thereby realizing a one-click test of the Sql code without the need for additional test processes, simplifying the test process, and improving the test efficiency. Therefore, the Sql statement test method, device, electronic device, and computer-readable storage medium proposed by the present invention can solve the problem of complex processes when performing code testing. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 A flowchart of a SQL statement testing method provided by an embodiment of the present invention;
[0049] Figure 2 A schematic diagram of a flow chart for parsing a test type and a test range from a SQL test instruction provided by an embodiment of the present invention;
[0050] Figure 3 A schematic diagram of a flow chart of performing a logic test according to an embodiment of the present invention;
[0051] Figure 4 A functional module diagram of a SQL statement testing device provided by an embodiment of the present invention;
[0052] Figure 5 A schematic diagram of the structure of an electronic device for implementing the Sql statement testing method provided by an embodiment of the present invention.
[0053] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0054] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0055] The embodiment of the present application provides a method for testing a SQL statement. The execution subject of the SQL statement testing method includes but is not limited to at least one of the electronic devices such as a server, a terminal, etc. that can be configured to execute the method provided by the embodiment of the present application. In other words, the SQL statement testing method can be executed by software or hardware installed on a terminal device or a server device, and the software can be a blockchain platform. The server includes but is not limited to: a single server, a server cluster, a cloud server or a cloud server cluster, etc. The server can be an independent server, or it can be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and big data and artificial intelligence platforms.
[0056] Reference Figure 1 The figure is a flow chart of a SQL statement testing method provided by an embodiment of the present invention.
[0057] In this embodiment, the Sql statement testing method includes:
[0058] S1. Obtain a SQL test instruction, and parse the test type and test scope from the SQL test instruction.
[0059] In the embodiment of the present invention, the Sql test instruction refers to an instruction statement obtained to test all or part of the code in the Sql file pre-stored in a database, blockchain node or network cache, etc.
[0060] In detail, the Sql test instructions uploaded by the user through the client, cloud server, etc. can be obtained.
[0061] In the embodiment of the present invention, the Sql test instruction may be parsed by using a parser that responds to the instruction type of the Sql test instruction to obtain the test type and test range included in the Sql test instruction.
[0062] In the embodiment of the present invention, Figure 2 As shown, the test type and test scope are parsed from the Sql test instruction, including:
[0063] S21, splitting the Sql test instruction into an instruction header and an instruction body;
[0064] S22, using a preset parser to parse a test type field from the instruction header, and determining a test type of the SQL test instruction according to the test type field;
[0065] S23, detecting whether the instruction body contains a message field;
[0066] When the instruction body includes a message field, S24 is executed to deserialize the instruction body to obtain a test range parameter, and the test range of the Sql test instruction is determined according to the test range parameter;
[0067] When the instruction body does not include a message field, S25 is executed to segment the instruction body into strings to obtain a test range parameter, and the test range of the Sql test instruction is determined according to the test range parameter.
[0068] In detail, since the generated Sql test instruction often has a fixed format, the instruction can be split into an instruction header and an instruction body according to the format when the Sql test instruction is generated.
[0069] Specifically, the instruction header can be parsed using a preset parser with instruction parsing function to obtain the test type field contained in the instruction header, and then the test type corresponding to the test type field can be retrieved from a preset field-type comparison table based on the parsed test type field.
[0070] In the embodiment of the present invention, a computer statement (Java statement, Python statement) having a message field detection function can be used to detect whether the instruction body contains a message field;
[0071] Alternatively, a calculation statement with a field extraction function is used to extract the message field from the instruction body. If the message field cannot be extracted from the instruction body, it is determined that the instruction body does not contain the message field. If the message field can be extracted from the instruction body, it is determined that the instruction body contains the message field.
[0072] For example, a calculation statement with a field extraction function is used to extract the message field from the instruction body. If the return value is a null value (such as NULL), it is determined that the message field cannot be extracted from the instruction body, and it is determined that the instruction body does not contain the message field. If the return value is not a null value (such as a string), it is determined that the message field can be extracted from the instruction body, and it is determined that the instruction body contains the message field.
[0073] In the embodiment of the present invention, the deserialization of the instruction body to obtain the test range parameter includes:
[0074] Extracting the data content type in the instruction body;
[0075] Selecting a decoder corresponding to the data content type to deserialize the instruction body to obtain the data content;
[0076] Perform parameter analysis on the data content to obtain test range parameters.
[0077] In this embodiment, a computer statement with a data content type extraction function may be used to extract the data content type in the instruction body.
[0078] In detail, the data content type is the content-type of the instruction body, and the data content type is used to indicate the data type of the data carried by the message field in the instruction body.
[0079] For example, when the instruction body is an image verification code requesting to log in to a ticket purchase website, the data type is image; or, when the instruction body is an account and password requesting to log in to a payment website, the data type is text.
[0080] Specifically, since the information corresponding to the data being tested will generate the message field of the Sql test instruction in the form of a binary byte stream when the Sql test instruction performs data testing, so that the Sql test instruction can perform data testing according to the message field, a preset decoder can be used to deserialize the instruction body containing the message field in the form of a binary byte stream to convert the data in the message field in the instruction body into its original state.
[0081] In this embodiment, by selecting a decoder corresponding to the data content type to deserialize the instruction body, the efficiency of deserializing the instruction body can be improved.
[0082] For example, when testing the function of a user logging into a certain page, the Sql statement related information of functions such as inputting a user name and a user password is formed into a message field of a Sql test instruction in the form of a binary byte stream, so that when the function of requesting a login to the page is tested using the Sql test instruction, the page responds to the login according to the user name and user password in the message field of the Sql test instruction; a decoder capable of deserializing text type data can be used to deserialize the instruction body, so as to convert the user name and user password in the form of a binary byte stream into data content in the form of text.
[0083] In this embodiment, after the data content is acquired, a preset model may be used to perform parameter analysis on the data content to obtain a test range parameter.
[0084] For example, when the data content is of text type, the data content can be analyzed using an NLP (Neuro-Linguistic Programming) model to obtain the test range parameters in the data content; when the data content is of image type, the data content can be analyzed using an OCR (Optical Character Recognition) model to obtain the test range parameters in the data content; when the data content is of audio type, the data content can be analyzed using an ASR (Automatic Speech Recognition) model to obtain the test range parameters in the data content.
[0085] Furthermore, when the instruction body does not include a message field, the embodiment of the present invention can obtain the test range parameter by performing character string segmentation on the instruction body.
[0086] In the embodiment of the present invention, the step of performing character string segmentation on the instruction body to obtain the test range parameter includes:
[0087] The instruction body is segmented according to a preset string separator, and the segmented strings are numbered according to their positions in the instruction body;
[0088] The character string at a preset position in the instruction body is parsed to obtain a test range parameter.
[0089] In detail, the string separator may be predefined by a user, and the string separator is used to separate different strings in the instruction body.
[0090] For example, there is an instruction body dqw<dfqwf<4r3fcf<fwq, where "<" is the string delimiter. Therefore, the instruction body can be split into four strings: dqw, dfqwf, 4r3fcf, and fwq through this string delimiter.
[0091] Since instruction bodies are often generated according to established standard protocols (such as HTTP protocol, RDP protocol, etc.), the meanings expressed by strings at different positions in the instruction body are relatively fixed. Therefore, the instruction body can be divided, and the strings at preset positions can be parsed to obtain test range parameters.
[0092] For example, there is an instruction body dqw<dfqwf<4r3fcf<fwq. Numbering the separated strings according to their positions in the instruction body, we get: 1: dqw, 2: dfqwf, 3: 4r3fcf, and 4: fwq. Among them, the second string and the fourth string are the strings containing test range parameters. Therefore, a parser can be used to parse the strings at preset positions in the instruction body to obtain test range parameters.
[0093] In the embodiments of the present invention, the test range parameters can be parameters such as code line number range, code field range, etc. For example, if the test range parameter is the code line number range (1, 10), then the test range corresponding to this test range parameter is the 1st to 10th lines in the Sql code.
[0094] S2. Determine whether the test type is the same as a preset logical test type or a preset scanning test type.
[0095] In the embodiments of the present invention, the test type can be compared with the preset logical test type and the preset scanning test type to determine whether the test type is the same as the preset logical test type or the preset scanning test type.
[0096] When the test type is the same as the preset logical test type, then execute S3. Convert the Sql statements within the test range into script format.
[0097] In the embodiments of the present invention, when the test type is the same as the preset logical test type, it can be determined that this Sql test instruction is used to perform a logical test on Sql statements. Therefore, before performing the logical test, the Sql statements within the test range can be converted into script format to facilitate subsequent logical tests.
[0098] In the embodiments of the present invention, the conversion of the Sql statements within the test range into script format includes:
[0099] Construct a blank Sql document, construct a main function in the Sql document, and write the Sql statements within the test scope into the main function;
[0100] The file type of the Sql document is converted into a script type to obtain a Sql statement in a script format.
[0101] In detail, the blank Sql document includes but is not limited to a txt document, a Mime document, etc. that can be used to record Sql statements.
[0102] Specifically, the executableness of a simple Sql statement is relatively poor, so a blank Sql document can be constructed, and a main function can be constructed in the Sql document to write the Sql statements within the test scope into the main function to obtain a Sql function with high executableness. The main function is a function that needs to be called to execute the Sql statements within the test scope, which can ensure the normal execution of the Sql statements within the test scope.
[0103] Furthermore, the embodiment of the present invention can modify the document type of the Sql document to an executable file type such as shell, bat, etc.
[0104] For example, the suffix of the Sql document is modified to ".shell" or ".bat", thereby modifying the Sql document into a script format.
[0105] S4. Use the preset database to perform logic tests on the SQL statements converted into the script format, and display the results of the logic tests in a window.
[0106] In the embodiment of the present invention, a preset database may be used to execute the Sql statement in the script format to implement a logic test on the Sql statement.
[0107] In detail, the database includes but is not limited to Mysql database, Oracle database, etc.
[0108] In the embodiment of the present invention, the SQL statement converted into the script format is logically tested using a preset database, that is, the SQL statement converted into the script format is executed using the database to determine whether the execution result is consistent with the expected result.
[0109] In the embodiment of the present invention, Figure 3 As shown, the use of a preset database to perform a logic test on the Sql statement converted into a script format includes:
[0110] S31, obtaining login information of a preset database, using the login information to log in to the preset database, and calling an execution function of the preset database;
[0111] S32, using the execution function to execute the Sql statement converted into the script format to obtain an execution result;
[0112] S33, judging whether the execution result meets the expected result;
[0113] If the execution result does not match the expected result, executing S34, determining the logical error of the Sql statement;
[0114] If the execution result is consistent with the expected result, S35 is executed to determine whether the logic of the Sql statement is correct.
[0115] In detail, the login information includes but is not limited to user name, password and other information for logging in or connecting to the preset database. The ssh (Secure Shell) protocol can be used to generate a login instruction based on the login information to log in to the preset database and call the execution function of the preset database, and then use the execution function to execute the Sql statement converted into a script format to obtain an execution result.
[0116] Specifically, it can be determined whether the execution result meets the expected result. When the execution result meets the expected result, it indicates a logically correct test result of the Sql statement. When the execution result meets the expected result, it indicates a logically incorrect test result of the Sql statement.
[0117] In the embodiment of the present invention, after the logic test is executed, the test result of the logic test can be displayed in the form of a window on a display screen or a web page of the client to facilitate user viewing.
[0118] When the test type is the same as the preset scan test type, S5 is executed to package the SQL statements within the test scope into a code package.
[0119] In an embodiment of the present invention, when the test type is the same as a preset scan test type, it can be determined that the Sql test instruction is used to perform a scan test on the Sql statement. Therefore, before performing the scan test, the Sql statements within the test scope can be packaged into a code package to facilitate subsequent scan testing.
[0120] The embodiment of the present invention can use the OEM (OEMDataPack, OEM data packaging) tool to package the Sql statements within the test range to obtain a code package. The OEM tool is a lightweight data packaging tool. Using the OEM tool to package the Sql statements within the test range can improve the efficiency of data packaging of the standard data.
[0121] S6. Send the code package to a preset scanning platform for scanning test, obtain the scanning test result returned by the preset scanning platform, and display the scanning test result in a window.
[0122] In an embodiment of the present invention, the code package may be sent to a preset scanning platform for scanning testing, and the scanning test result returned by the preset scanning platform may be obtained, wherein the scanning platform includes but is not limited to an SQM scanning platform and a pikachu scanning platform.
[0123] In detail, the scanning test refers to scanning the code package using a preset scanning platform to analyze whether the data structure of the code in the code package is complete, whether the code is written correctly, etc.
[0124] In the embodiment of the present invention, the step of sending the code package to a preset scanning platform for scanning testing includes:
[0125] Using a preset scanning platform to scan the data structure of the Sql statements in the code package to obtain the data structure of the Sql statements in the code package;
[0126] Determining whether the data structure conforms to a preset standard structure;
[0127] When the data structure conforms to the standard structure, the scanning test result of the complete Sql statement structure is output;
[0128] When the data structure does not conform to the standard structure, a scan test result indicating that the Sql statement structure is incomplete is output.
[0129] In an embodiment of the present invention, the result of the scanning test performed by the preset scanning platform on the code package can be obtained and the result can be displayed in a window, wherein the step of displaying the scanning test result in a window is consistent with the step of displaying the result of the logic test in a window in S4, and will not be repeated here.
[0130] The embodiment of the present invention can obtain a Sql test instruction, determine the test type and test range to be performed based on the analysis of the Sql test instruction, and then select the Sql code according to the test range, and perform a response test on the selected Sql code according to the test type, thereby realizing a one-click test of the Sql code without the need for additional test processes, simplifying the test process, and improving the test efficiency. Therefore, the Sql statement testing method proposed by the present invention can solve the problem of complex processes when performing code testing.
[0131] like Figure 4 , which is a functional module diagram of a SQL statement testing device provided by an embodiment of the present invention.
[0132] The SQL statement testing device 100 of the present invention can be installed in an electronic device. According to the functions to be implemented, the SQL statement testing device 100 can include an instruction parsing module 101, a first test module 102 and a second test module 103. The module of the present invention can also be called a unit, which refers to a series of computer program segments that can be executed by an electronic device processor and can complete fixed functions, which are stored in the memory of the electronic device.
[0133] In this embodiment, the functions of each module / unit are as follows:
[0134] The instruction parsing module 101 is used to obtain the Sql test instruction and parse the test type and test scope from the Sql test instruction;
[0135] The first test module 102 is used to convert the SQL statements in the test range into a script format when the test type is the same as the preset logic test type, perform a logic test on the SQL statements converted into the script format using a preset database, and display the results of the logic test in a window;
[0136] The second test module 103 is used to package the SQL statements within the test scope into a code package when the test type is the same as the preset scan test type, send the code package to the preset scan platform for scan testing, obtain the scan test results returned by the preset scan platform, and display the scan test results in a window.
[0137] In detail, each module described in the SQL statement testing device 100 in the embodiment of the present invention is used in the same manner as described above. Figures 1 to 3 The technical means are the same as the Sql statement testing method described in, and can produce the same technical effects, so I will not go into details here.
[0138] like Figure 5FIG. 1 is a schematic diagram of the structure of an electronic device for implementing a SQL statement testing method provided by an embodiment of the present invention.
[0139] The electronic device 1 may include a processor 10, a memory 11, a communication bus 12, and a communication interface 13, and may also include a computer program stored in the memory 11 and executable on the processor 10, such as a SQL statement test program.
[0140] In some embodiments, the processor 10 may be composed of an integrated circuit, for example, a single packaged integrated circuit, or a plurality of packaged integrated circuits with the same or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and combinations of various control chips. The processor 10 is the control core (ControlUnit) of the electronic device, and uses various interfaces and lines to connect various components of the entire electronic device, and executes or executes programs or modules stored in the memory 11 (for example, executing a SQL statement test program, etc.), and calls data stored in the memory 11 to execute various functions of the electronic device and process data.
[0141] The memory 11 includes at least one type of readable storage medium, and the readable storage medium includes a flash memory, a mobile hard disk, a multimedia card, a card-type memory (for example, an SD or DX memory, etc.), a magnetic memory, a disk, an optical disk, etc. In some embodiments, the memory 11 may be an internal storage unit of an electronic device, such as a mobile hard disk of the electronic device. In other embodiments, the memory 11 may also be an external storage device of an electronic device, such as a plug-in mobile hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device. Further, the memory 11 may also include both an internal storage unit of the electronic device and an external storage device. The memory 11 may not only be used to store application software and various types of data installed in the electronic device, such as the code of a Sql statement test program, etc., but may also be used to temporarily store data that has been output or is to be output.
[0142] The communication bus 12 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. The bus is configured to realize connection and communication between the memory 11 and at least one processor 10, etc.
[0143] The communication interface 13 is used for communication between the above-mentioned electronic device and other devices, including a network interface and a user interface. Optionally, the network interface may include a wired interface and / or a wireless interface (such as a WI-FI interface, a Bluetooth interface, etc.), which is generally used to establish a communication connection between the electronic device and other electronic devices. The user interface may be a display (Display), an input unit (such as a keyboard (Keyboard)), and optionally, the user interface may also be a standard wired interface, a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an OLED (Organic Light-Emitting Diode, organic light-emitting diode) touch device, etc. Among them, the display may also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the electronic device and to display a visual user interface.
[0144] Figure 5 Only an electronic device with components is shown, and those skilled in the art will understand that Figure 5 The structure shown does not constitute a limitation on the electronic device 1, and may include fewer or more components than shown in the figure, or combine certain components, or arrange the components differently.
[0145] For example, although not shown, the electronic device may also include a power source (such as a battery) for supplying power to each component. Preferably, the power source may be logically connected to the at least one processor 10 through a power management device, so that the power management device can realize functions such as charging management, discharging management, and power consumption management. The power source may also include one or more DC or AC power sources, recharging devices, power failure detection circuits, power converters or inverters, power status indicators, and other arbitrary components. The electronic device may also include a variety of sensors, Bluetooth modules, Wi-Fi modules, etc., which will not be repeated here.
[0146] It should be understood that the embodiment is for illustration only and the scope of the patent application is not limited to this structure.
[0147] The SQL statement test program stored in the memory 11 in the electronic device 1 is a combination of multiple instructions. When running in the processor 10, it can achieve:
[0148] Obtaining a SQL test instruction, and parsing the test type and test scope from the SQL test instruction;
[0149] When the test type is the same as the preset logic test type, converting the SQL statements within the test scope into a script format;
[0150] Use the preset database to perform logic tests on the SQL statements converted into script format, and display the results of the logic tests in a window;
[0151] When the test type is the same as the preset scan test type, the SQL statements within the test scope are packaged into a code package;
[0152] The code package is sent to a preset scanning platform for scanning test, the scanning test result returned by the preset scanning platform is obtained, and the scanning test result is displayed in a window.
[0153] Specifically, the specific implementation method of the processor 10 for the above instructions can refer to the description of the relevant steps in the corresponding embodiment of the accompanying drawings, which will not be repeated here.
[0154] Furthermore, if the module / unit integrated in the electronic device 1 is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. The computer-readable storage medium can be volatile or non-volatile. For example, the computer-readable medium can include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a mobile hard disk, a magnetic disk, an optical disk, a computer memory, and a read-only memory (ROM).
[0155] The present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor of an electronic device, the computer program can implement:
[0156] Obtaining a SQL test instruction, and parsing the test type and test scope from the SQL test instruction;
[0157] When the test type is the same as the preset logic test type, converting the SQL statements within the test scope into a script format;
[0158] Use the preset database to perform logic tests on the SQL statements converted into script format, and display the results of the logic tests in a window;
[0159] When the test type is the same as the preset scan test type, the SQL statements within the test scope are packaged into a code package;
[0160] The code package is sent to a preset scanning platform for scanning test, the scanning test result returned by the preset scanning platform is obtained, and the scanning test result is displayed in a window.
[0161] In the several embodiments provided by the present invention, it should be understood that the disclosed devices, apparatuses and methods can 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.
[0162] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0163] In addition, each functional module in each embodiment of the present invention may be integrated into one processing unit, each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional modules.
[0164] It is obvious to those skilled in the art that the present invention is not limited to the details of the above exemplary embodiments, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention.
[0165] Therefore, no matter from which point of view, the embodiments should be regarded as illustrative and non-restrictive, and the scope of the present invention is limited by the appended claims rather than the above description, so it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention. Any attached figure mark in the claims should not be regarded as limiting the claims involved.
[0166] The blockchain referred to in this invention is a new application mode of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0167] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0168] In addition, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices stated in the system claim can also be implemented by one unit or device through software or hardware. The words first, second, etc. are used to indicate names, and do not indicate any particular order.
[0169] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present invention.
Claims
1. A SQL statement testing method, characterized in that: The method comprises: Obtaining a Sql test instruction, parsing a test type and a test range from the Sql test instruction, including: splitting the Sql test instruction into an instruction header and an instruction body, parsing a test type field from the instruction header using a preset parser, determining the test type of the Sql test instruction according to the test type field, detecting whether the instruction body contains a message field, when the instruction body contains a message field, deserializing the instruction body to obtain a test range parameter, determining the test range of the Sql test instruction according to the test range parameter, when the instruction body does not contain a message field, performing string segmentation on the instruction body to obtain a test range parameter, and determining the test range of the Sql test instruction according to the test range parameter, wherein the test range parameter at least includes a code line range parameter and a code field range parameter; When the test type is the same as the preset logic test type, converting the SQL statements within the test scope into a script format, including: constructing a blank SQL document, constructing a main function in the SQL document, and writing the SQL statements within the test scope into the main function, converting the file type of the SQL document into a script type, and obtaining the SQL statements in the script format; Use the preset database to perform logic tests on the SQL statements converted into script format, and display the results of the logic tests in a window; When the test type is the same as the preset scan test type, the SQL statements within the test scope are packaged into a code package; The code package is sent to a preset scanning platform for scanning test, the scanning test result returned by the preset scanning platform is obtained, and the scanning test result is displayed in a window.
2. The SQL statement testing method according to claim 1, characterized in that: The deserialization process is performed on the instruction body to obtain the test range parameter, including: Extracting the data content type in the instruction body; Selecting a decoder corresponding to the data content type to deserialize the instruction body to obtain the data content; Perform parameter analysis on the data content to obtain test range parameters.
3. The SQL statement testing method according to claim 1, characterized in that: The step of performing character string segmentation on the instruction body to obtain a test range parameter includes: The instruction body is segmented according to a preset string separator, and the segmented strings are numbered according to their positions in the instruction body; The character string at a preset position in the instruction body is parsed to obtain a test range parameter.
4. The SQL statement testing method according to claim 1, characterized in that: The method of using a preset database to perform a logic test on the SQL statement converted into a script format includes: Obtaining login information of a preset database, using the login information to log in to the preset database, and calling an execution function of the preset database; Utilize the execution function to execute the Sql statement converted into the script format to obtain the execution result; Determining whether the execution result meets the expected result; If the execution result does not match the expected result, a logical error in the SQL statement is determined; If the execution result is consistent with the expected result, it is determined that the logic of the Sql statement is correct.
5. The SQL statement testing method according to any one of claims 1 to 4, characterized in that: The sending the code package to a preset scanning platform for scanning testing includes: Using a preset scanning platform to scan the data structure of the Sql statements in the code package to obtain the data structure of the Sql statements in the code package; Determining whether the data structure conforms to a preset standard structure; When the data structure conforms to the standard structure, the scanning test result of the complete Sql statement structure is output; When the data structure does not conform to the standard structure, a scan test result indicating that the Sql statement structure is incomplete is output.
6. A SQL statement testing device, characterized in that: The device comprises: An instruction parsing module, used for obtaining a Sql test instruction, parsing a test type and a test range from the Sql test instruction, comprising: splitting the Sql test instruction into an instruction header and an instruction body, parsing a test type field from the instruction header using a preset parser, determining the test type of the Sql test instruction according to the test type field, detecting whether the instruction body contains a message field, when the instruction body contains a message field, deserializing the instruction body to obtain a test range parameter, determining the test range of the Sql test instruction according to the test range parameter, when the instruction body does not contain a message field, performing string segmentation on the instruction body to obtain a test range parameter, and determining the test range of the Sql test instruction according to the test range parameter, wherein the test range parameter at least includes a code line range parameter and a code field range parameter; The first test module is used to convert the SQL statements in the test scope into a script format when the test type is the same as the preset logic test type, including: constructing a blank SQL document, constructing a main function in the SQL document, and writing the SQL statements in the test scope into the main function, converting the file type of the SQL document into a script type, and obtaining the SQL statements in the script format; The second test module is used to package the SQL statements within the test scope into a code package when the test type is the same as the preset scan test type, send the code package to the preset scan platform for scan testing, obtain the scan test results returned by the preset scan platform, and display the scan test results in a window.
7. An electronic device, characterized in that: The electronic device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the SQL statement testing method as described in any one of claims 1 to 5.
8. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the SQL statement testing method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Multi-data packaging method and device, electronic equipment and computer readable storage medium
CN112596717A
Data test method and device based on data difference, equipment and storage medium
CN113434413A