Structured query language statement scanning method and device, equipment and storage medium
By parsing the application source code to generate extensible markup language files and determining scanning rules, the problem of SQL and database brand compatibility detection was solved, enabling multi-dimensional personalized scanning and prediction of SQL execution efficiency.
Patent Information
- Application Number
- CN202510945752.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-09
- Publication Date
- 2025-10-24
AI Technical Summary
Existing technologies cannot accurately detect SQL and database brand compatibility, resulting in the inability to perform personalized analysis and in-depth detection.
By parsing the application source code, we obtain the Structured Query Language (SCL) statements, table object information, and database brand. We then use the target brand to drive the parsing of SQL statements to generate an abstract syntax tree and an Extensible Markup Language (XML) file. Combining multi-dimensional information, we determine the scanning rules and finally scan the XML file.
It enables multi-dimensional personalized scanning, improves the accuracy and flexibility of SQL statement writing quality detection, can predict the execution efficiency of SQL runtime, and detect the compatibility of SQL within the application with the connected database brand.
Smart Images

Figure CN120832360A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of database detection, and particularly relates to a structured query language statement scanning method and device, equipment and a storage medium. BACKGROUND
[0002] With the development of information technology, databases have been widely used in various information management systems. As an important tool for database operation, the performance and standardization of structured query language (SQL) statements have an important influence on system running efficiency and data security. In actual development, SQL statements often face various optimization needs and personalized scanning needs. In order to improve the quality and execution efficiency of SQL statements, developers need to comprehensively scan and analyze SQL. The analysis of SQL not only needs to focus on the syntax structure, but also needs to consider the multi-dimensional information of database table fields, indexes, partitions, etc. Only through comprehensive analysis, can potential performance bottlenecks and standardization problems be better identified.
[0003] The traditional SQL scanning technology mainly relies on static analysis, which usually detects potential problems by scanning the original text of the SQL statement. However, the method of static analysis has great limitations. Since it depends on the original text of the SQL statement, it cannot integrate specific information of the database, such as database brand, table structure and index, and cannot reflect the actual situation of the database environment. Static analysis cannot perform personalized analysis according to the actual database environment, resulting in the inability to deeply detect whether the SQL is completely compatible with the connected database brand.
[0004] The above content is only used to assist in understanding the technical solutions of the present application, and does not represent the acknowledgement of the above content as prior art. SUMMARY
[0005] The main purpose of the present application is to provide a structured query language statement scanning method, device, equipment and storage medium, which aims to solve the technical problem of being unable to accurately detect the compatibility of SQL and database brand in the database environment.
[0006] To achieve the above purpose, the present application provides a structured query language statement scanning method, which comprises:
[0007] parsing the application source code to obtain a structured query language statement, table object information and a database brand;
[0008] obtaining a target brand driver according to the database brand, and parsing the structured query language statement according to the target brand driver to obtain an abstract syntax tree;
[0009] generating an extensible markup language file according to the structured query language statement, the abstract syntax tree and the table object information;
[0010] determining a scanning rule according to the abstract syntax tree, the table object information and the database brand;
[0011] scanning the extensible markup language file according to the scanning rule to obtain a target scanning result.
[0012] In an embodiment, the step of generating an extensible markup language file according to the structured query language statement, the abstract syntax tree and the table object information comprises:
[0013] parsing the structured query language statement to obtain command information of the structured query language statement;
[0014] extracting table structure, index information, partition information, table record number and keyword information according to the table object information;
[0015] generating an extensible markup language file according to the abstract syntax tree, the command information, the table structure, the index information, the partition information, the table record number and the keyword information.
[0016] In an embodiment, the step of parsing the application source code to obtain the structured query language statement, the table object information and the database brand comprises:
[0017] parsing the application source code to obtain the structured query language statement and database connection information;
[0018] obtaining the database brand and the database name according to the database connection information;
[0019] extracting table names from the structured query language statement;
[0020] obtaining table object information through the database name and the table names.
[0021] In an embodiment, the step of determining a scanning rule according to the abstract syntax tree, the table object information and the database brand comprises:
[0022] determining current operation instructions and keyword information according to the abstract syntax tree;
[0023] determining index information, data table information and field information according to the table object information;
[0024] determining a scanning rule according to the current operation instructions, the keyword information, the data table information, the database brand, the field information and the index information.
[0025] In an embodiment, the step of determining the scan rule according to the current operation instruction, the keyword information, the data table information, the database brand, the field information and the index information comprises:
[0026] determining an index consistency rule according to the current operation instruction, the keyword information and the data table information;
[0027] determining an index use rule according to the current operation instruction and the index information;
[0028] determining a disable operation word rule according to the database brand, the data table information, the field information and the index information;
[0029] determining a primary key index limitation rule according to the field information and the index information;
[0030] extracting a resume condition information according to the keyword information, and determining a keyword consistency rule according to the keyword information and the resume condition information;
[0031] determining the scan rule according to the index consistency rule, the index use rule, the disable operation word rule, the primary key index limitation rule and the keyword consistency rule.
[0032] In an embodiment, the step of scanning the extensible markup language file according to the scan rule to obtain a target scan result comprises:
[0033] scanning the extensible markup language file according to the scan rule to obtain a rule scan result;
[0034] performing a running efficiency risk scan on the extensible markup language file to obtain a running efficiency risk scan result;
[0035] obtaining the target scan result according to the rule scan result and the running efficiency risk scan result.
[0036] In an embodiment, the step of performing the running efficiency risk scan on the extensible markup language file to obtain the running efficiency risk scan result comprises:
[0037] obtaining a condition keyword and a table record number according to the extensible markup language file;
[0038] determining whether table partition information exists in the extensible markup language file;
[0039] when the table partition information exists in the extensible markup language file, determining whether a partition key attribute is contained in the condition keyword;
[0040] determining whether the table record number is greater than or equal to a preset threshold value when the partition key attribute is contained in the condition keyword;
[0041] determining whether index field information is contained in the condition keyword when the table record number is greater than or equal to the preset threshold value or the table partition information is not present in the extensible markup language file;
[0042] determining that the running efficiency risk scanning result is no running efficiency risk when index field information is contained in the condition keyword or the table record number is less than the preset threshold value;
[0043] determining that the running efficiency risk scanning result is running efficiency risk when the partition key attribute is not contained in the condition keyword or the index field information is not contained in the condition keyword.
[0044] In addition, to achieve the above object, the present application further provides a structured query language statement scanning device, which comprises: a code parsing module, configured to parse application source code to obtain a structured query language statement, table object information and a database brand;
[0045] a statement parsing module, configured to obtain a target brand driver according to the database brand, and parse the structured query language statement according to the target brand driver to obtain an abstract syntax tree;
[0046] a file forming module, configured to generate an extensible markup language file according to the structured query language statement, the abstract syntax tree and the table object information;
[0047] a rule determining module, configured to determine a scanning rule according to the abstract syntax tree, the table object information and the database brand;
[0048] a statement scanning module, configured to scan the extensible markup language file according to the scanning rule to obtain a target scanning result.
[0049] In addition, to achieve the above object, the present application further provides a structured query language statement scanning device, which comprises a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the computer program is configured to implement the steps of the structured query language statement scanning method as described above.
[0050] In addition, to achieve the above object, the present application further provides a storage medium, which is a computer readable storage medium, and the storage medium stores a computer program, wherein the computer program is executed by a processor to implement the steps of the structured query language statement scanning method as described above.
[0051] Further, to achieve the above object, the present application also provides a computer program product comprising a computer program which, when executed by a processor, implements the steps of the structured query language statement scanning method as described above.
[0052] The one or more technical solutions proposed in the present application have at least the following technical effects:
[0053] As the application source code is parsed to obtain the structured query language statement, the table object information and the database brand, the target brand driver is obtained according to the database brand, and the abstract syntax tree is parsed from the structured query language statement, the structured query language statement, the abstract syntax tree and the table object information are generated into an extensible markup language file, the scanning rule is determined according to the abstract syntax tree, the table object information and the database brand, and finally the extensible markup language file is scanned according to the scanning rule; the application source code is parsed to obtain multi-dimensional information and integrated to generate an extensible markup language file, and the integrated information contains sufficient details to support the recognition of various tag semantics; the integration of multi-dimensional information and the scanning rule determined based thereon solve the problem that the lack of multi-dimensional information integration capability leads to the inability to meet diversified scanning requirements; in addition, by parsing the database brand and determining the scanning rule based thereon, the problem that the lack of real mapping between SQL and the database brand leads to the inability to detect the compatibility of SQL with the connected specific database brand is solved; compared with the prior art, the effect of supporting multi-dimensional personalized scanning to improve the accuracy and flexibility of SQL statement writing quality detection, predictable SQL runtime execution efficiency and the detection of whether the SQL in the application program is completely compatible with the connected database brand is achieved. BRIEF DESCRIPTION OF DRAWINGS
[0054] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and serve to explain the principles of the present application together with the specification.
[0055] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the accompanying drawings needed to be used in the embodiments or prior art description will be briefly introduced as follows, and obviously, other drawings can also be obtained by those skilled in the art without creative labor.
[0056] Figure 1 A flowchart is provided for the structured query language statement scanning method embodiment one of the present application;
[0057] Figure 2 A flowchart is provided for the structured query language statement scanning method embodiment two of the present application;
[0058] Figure 3 Efficiency scanning flowchart provided for the second embodiment of the structured query language sentence scanning method of the present application;
[0059] Figure 4 Brief flowchart of the structured query language sentence scanning method provided for the second embodiment of the present application;
[0060] Figure 5 Module structure diagram of the structured query language sentence scanning device of the present application;
[0061] Figure 6 Device structure diagram of the hardware running environment involved in the structured query language sentence scanning method of the present application.
[0062] The object, function features and advantages of the present application will be further explained with reference to the accompanying drawings in conjunction with the embodiments. DETAILED DESCRIPTION
[0063] It should be understood that the specific embodiments described herein are merely intended to explain the technical solutions of the present application, and are not used to limit the present application.
[0064] In order to better understand the technical solutions of the present application, the following will be described in detail in conjunction with the accompanying drawings and specific embodiments.
[0065] The main solution of the present application is: parsing the application source code to obtain a structured query language sentence, table object information and a database brand; obtaining a target brand driver according to the database brand, and parsing the structured query language sentence according to the target brand driver to obtain an abstract syntax tree; generating an extensible markup language file according to the structured query language sentence, the abstract syntax tree and the table object information; determining a scanning rule according to the abstract syntax tree, the table object information and the database brand; and scanning the extensible markup language file according to the scanning rule to obtain a target scanning result.
[0066] In the present embodiment, for the convenience of description, the following will be described with the recognition structured query language sentence scanning device as the execution subject.
[0067] Since the prior art cannot accurately detect the SQL and database brand compatibility of the database environment, the present application provides a solution, which adopts parsing the application source code to obtain the structured query language statement, table object information and database brand, obtains the target brand driver according to the database brand and parses the structured query language statement to obtain the abstract syntax tree, generates the extensible markup language file according to the structured query language statement, the abstract syntax tree and the table object information, determines the scanning rule according to the abstract syntax tree, the table object information and the database brand, and finally scans the extensible markup language file according to the scanning rule; the application source code is parsed to obtain multi-dimensional information and integrated to generate the extensible markup language file, and the integrated information contains sufficient details to support the recognition of various tag semantics; the integration of multi-dimensional information and the scanning rule determined based thereon solve the problem that the lack of multi-dimensional information integration capability leads to the inability to meet the diversified scanning requirements; in addition, by parsing the database brand and determining the scanning rule based thereon, the problem that the lack of real mapping of SQL and database brand leads to the inability to detect the compatibility of SQL and the connected specific database brand is solved; compared with the prior art, the present application realizes the effects of supporting multi-dimensional personalized scanning to improve the accuracy and flexibility of SQL statement writing quality detection, predict the SQL runtime execution efficiency and detect whether the SQL in the application program is completely compatible with the connected database brand.
[0068] It should be noted that the execution subject of the present embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device, a structured query language statement scanning device, etc. capable of realizing the above functions. The present embodiment and the following embodiments will be described below taking the structured query language statement scanning device as an example.
[0069] Based on this, the present embodiment provides a structured query language statement scanning method, which is described in detail with reference to Figure 1 , Figure 1 The flowchart of the first embodiment of the structured query language statement scanning method of the present application is shown in FIG. 1.
[0070] In the present embodiment, the structured query language statement scanning method comprises steps S10-S50:
[0071] Step S10, the application source code is parsed to obtain the structured query language statement, the table object information and the database brand;
[0072] It should be noted that the application source code refers to the original code constituting the application program, which contains various instructions, logic and data definitions for realizing the application function.
[0073] Further, the structured query language (Structured Query Language, SQL) statement, that is, the SQL statement, is a standardized language used for interacting with the database, and is used to perform database operations such as querying, inserting, updating, and deleting.
[0074] In addition, the table object information is detailed attribute and structure information of a table in the database, including table fields, table indexes, table partition information, and table record counts.
[0075] In addition, the database brand refers to the manufacturer or product name of the database management system, such as Tencent Distributed SQL (TDSQL), MySQL Relational Database Management System (MySQL), Oracle Database (Oracle), and the like. Different brands of databases may differ in syntax support, functional characteristics, and the like.
[0076] It can be understood that the application source code is parsed to extract structured query language statements, table object information, and database brands. By parsing the part related to database operations in the application source code, such as MyBatis Persistence Framework (MyBatis) files, the SQL statements contained therein are obtained; from the database configuration or connection information of the source code, the database brand connected by the application is determined; and according to the parsed database name and the table name involved in the SQL statement, the corresponding table object information, that is, the table fields, indexes, partitions, record counts, and the like, are further obtained.
[0077] In a feasible implementation, step S10 can include steps S11-S14:
[0078] Step S11, the application source code is parsed to obtain structured query language statements and database connection information;
[0079] It should be noted that the database connection information is the configuration details in the application source code for establishing a connection with the database, including the network address of the database, the port number, the login username, the password, and the database identifier to be connected, and the like. The database connection information is a necessary parameter for the application to communicate with the database.
[0080] It can be understood that the application source code is comprehensively parsed to extract two types of key information. On the one hand, the part of the source code related to database operation, such as the MyBatis file, is parsed to obtain the structured query language statement contained therein; on the other hand, the database configuration part in the source code is parsed to extract the database connection information used to connect the database, which will be used to determine the related attributes of the database subsequently.
[0081] In step S12, the database brand and the database name are obtained according to the database connection information.
[0082] It should be noted that the database name refers to the identification of the specific database connected by the application program under a specific database brand, which is used to distinguish different databases on the same database server, for example, there may be transaction databases, user databases and other databases with different names under the TDSQL brand.
[0083] It can be understood that two key information are extracted from the database connection information. One is to determine the database brand connected by the application program, which can usually be obtained from the driver configuration or database type identification of the connection information; the other is to extract the specific database name, which clearly indicates the specific database where the data operated by the application program is located.
[0084] In step S13, the table name is extracted from the structured query language statement.
[0085] It should be noted that the table name is the unique identification name of the table in the database, which is used to specify the target table in the SQL statement, and is composed of letters, numbers or specific symbols.
[0086] It can be understood that the structured query language statement is analyzed to recognize and extract the name of the table involved in the statement. The table name can be extracted by parsing the syntax structure of the SQL statement to locate the name after the keyword such as FROM, INTO, etc. representing the table.
[0087] In step S14, the table object information is obtained through the database name and the table name.
[0088] It should be noted that the table object information is the detailed structure and attribute information of a specific table in the database, including the fields, table indexes, table partition information and table record number, etc.
[0089] It can be understood that the database name and the table name are used to query and obtain the table object information of the table in the corresponding database. Specifically, the specific database is located through the database name, and then the corresponding table is found in the database according to the table name, and the detailed information of the table such as the fields, indexes, partitions and record number is extracted.
[0090] Step S20, obtaining a target brand driver according to the database brand, and parsing the structured query language statement according to the target brand driver to obtain an abstract syntax tree;
[0091] It should be noted that the target brand driver is a driver corresponding to a specific database brand, used to support operations such as parsing of SQL statements of the brand database. Different brands of databases have their corresponding drivers, such as TDSQL driver, MySQL driver, etc., which can understand the syntax rules and characteristics of the brand database.
[0092] Further, the abstract syntax tree (Abstract Syntax Code, AST) is a tree-shaped data structure formed by decomposing the SQL statement according to the syntax rules. Each node in the tree represents a syntax component in the SQL statement, such as keywords, table names, field names, operators, etc., which can clearly show the syntax structure and logical relationship of the SQL statement.
[0093] It can be understood that, according to the database brand, the step of obtaining the corresponding target brand driver is to parse the structured query language statement using the open source framework (druid) and the target brand driver pair to generate an abstract syntax tree. By using the target brand driver corresponding to the database brand to parse the SQL statement, the abstract syntax tree generated can accurately reflect the syntax interpretation of the brand database on the SQL statement.
[0094] Step S30, generating an extensible markup language file according to the structured query language statement, the abstract syntax tree, and the table object information;
[0095] It should be noted that the extensible markup language (Extensible Markup Language, XML) file is a markup language file used to store and transmit data. Its structure is composed of custom tags, has good extensibility and readability, and can integrate different types of information together in a certain format.
[0096] It can be understood that the structured query language statement abstract syntax tree and the table object information are integrated into an extensible markup language file. The XML file organizes different types of information through preset tags, for example, using <mapper>The tag contains the SQL original text in MyBatis, and <sql>The tag includes information of an abstract syntax tree, and the table object information such as a field, an index, a partition, etc. is included in a <custom> tag. For example, for the SQL of REPLACE INTO DWM_TRANS_ROUTE_T(... ) VALUES(... ), the XML file generated in the <custom> tag includes information of a table object as shown in Table 1 below. <sql>The node can contain abstract syntax tree information such as SQLReplaceStatement, <custom>The node contains index information of the table, such as a primary key index PRIMARY, a unique index, and the like.
[0097] In an implementable embodiment, step S30 can include steps S31-S33:
[0098] Step S31, parsing the structured query language statement to obtain command information of the structured query language statement;
[0099] It should be noted that the command information refers to a key part in the SQL statement for specifying an operation type, that is, indicating a specific operation to be performed by the SQL statement, for example, SELECT corresponding to a query operation, INSERT corresponding to an insertion operation, REPLACE INTO corresponding to a replacement operation, and the like.
[0100] It can be understood that the structured query language statement is parsed to recognize and extract the command information therein. Specifically, the operation type of the SQL statement is determined by analyzing the beginning part or core operation word of the SQL statement. The extraction of the command information helps to clearly determine the operation type of the SQL statement, provides a basis for differentiating organization of different operation types of SQL when generating the extensible markup language file subsequently, and ensures that the XML file can accurately reflect the core operation intention of the SQL.
[0101] Step S32, extracting table structure, index information, partition information, table record number, and keyword information according to the table object information;
[0102] It should be noted that the table structure refers to the basic framework of the table, which is mainly composed of table fields, that is, columns contained in the table and corresponding data types, constraints, and the like.
[0103] In addition, the index information refers to detailed contents of indexes in the table for accelerating query speed, including index name, contained field, index type, and the like.
[0104] In addition, the partition information refers to a division manner and related attributes of table data, that is, information about how the data table is stored in a scattered manner according to a specific rule, such as a partition key.
[0105] In addition, the table record number refers to a total row number of data contained in the table, reflecting the size of the table.
[0106] In addition, the keyword information refers to database keywords or reserved words involved in the table, that is, words with specific meanings reserved by the database system, such as ADD, ALTER, and the like in some databases.
[0107] It can be understood that a plurality of key parts are extracted from the table object information. First, the table structure is extracted, that is, the fields contained in the table and their attributes are determined; the index information is extracted, that is, the names, contained fields and types of all indexes in the table are determined; the partition information is extracted, that is, the partition mode of the table data is understood; the table record number is extracted, that is, the data size of the table is mastered; and the keyword information is extracted, that is, the database keywords or reserved words involved in the table are identified.
[0108] In step S33, an extensible markup language file is generated according to the abstract syntax tree, the command information, the table structure, the index information, the partition information, the table record number and the keyword information.
[0109] It can be understood that the abstract syntax tree, the command information, the table structure, the index information, the partition information, the table record number and the keyword information are integrated to generate an extensible markup language file. Specifically, different types of information are respectively placed in corresponding labels through a preset label system. For example, the content of the abstract syntax tree is contained in a specific label, the command information is contained in another label, and the table structure, the index information, the partition information, the table record number and the keyword information are sequentially contained in corresponding labels.
[0110] In step S40, a scanning rule is determined according to the abstract syntax tree, the table object information and the database brand.
[0111] It should be noted that the scanning rule is a judgment condition for detecting whether the SQL statement conforms to the specification, whether there is an efficiency risk or a compatibility problem, and can query and judge the multi-dimensional information in the XML file. In this embodiment, the scanning rule can be an XPATH scanning rule.
[0112] It can be understood that the rule for scanning is determined in combination with the abstract syntax tree, the table object information and the database brand. For example, for a specification that "replaceinto statement is not allowed when the table simultaneously contains primary key and unique index" in TDSQL database, it is analyzed whether the SQLReplaceStatement node exists in the abstract syntax tree, representing the replaceinto command, whether the primary key index (indexType="P") and the unique index (indexType="U") simultaneously exist in the table object information, and whether the database brand is TDSQL, and the scanning rule is written accordingly.
[0113] In a possible implementation, step S40 can include steps S41-S43.
[0114] In step S41, the current operation instruction and the keyword information are determined according to the abstract syntax tree.
[0115] It can be understood that the abstract syntax tree is analyzed to identify and determine the current operation instruction and the keyword information. The node structure of the abstract syntax tree contains the syntax details of the SQL statement. By parsing the nodes, the part representing the operation type can be located to determine the current operation instruction; meanwhile, the words with specific syntax meaning are extracted from the nodes to obtain the keyword information.
[0116] In step S42, the index information, the data table information and the field information are determined according to the table object information.
[0117] It should be noted that the data table information is the basic description about the table itself, including the table name, the database to which the table belongs, the storage engine of the table, the partition mode and other information related to the whole table.
[0118] In addition, the field information is the detailed attribute of each column in the table, including the field name, the data type, the constraint condition (such as non-empty and unique) and the like.
[0119] It can be understood that the index information, the data table information and the field information are extracted and determined from the table object information. Specifically, the index-related content in the table object information is screened out to obtain the index information; the basic description content of the table is extracted to form the data table information; and the attribute of each column in the table is collected to determine the field information.
[0120] In step S43, the scan rule is determined according to the current operation instruction, the keyword information, the data table information, the database brand, the field information and the index information.
[0121] It can be understood that the scan rule is formulated by comprehensively considering the current operation instruction, the keyword information, the data table information, the database brand, the field information and the index information. For example, when the current operation instruction is REPLACE INTO, the database brand is TDSQL, and the primary key index and the unique index exist in the index information, the scan rule that the REPLACE INTO statement is not allowed to be used when the table simultaneously exists the primary key and the unique index can be formulated in combination with the data table information and the field information; for another example, according to the feature that the database brand TDSQL does not support the add_months function, the scan rule that the SQL statement is determined to be incompatible if the add_months keyword is contained in the SQL statement can be formulated in combination with the keyword information.
[0122] In a feasible implementation, step S43 can include steps S431-S436.
[0123] In step S431, the index consistency rule is determined according to the current operation instruction, the keyword information and the data table information.
[0124] It should be noted that the index consistency rule is a rule for detecting whether the index usage in the SQL statement is consistent with the table name (including alias)
[0125] It can be understood that the index consistency rule is formulated in combination with the current operation instruction, keyword information and data table information. For example, when the current operation instruction is a query operation and the keyword information contains a hint specifying an index, the table name (or alias) involved in the hint is extracted and compared with the table name (or alias) in the data table information, and accordingly the rule is determined: when the hint specifies an index, the table name (or alias) in the hint needs to be consistent with the table name (or alias) actually used in the SQL statement. If the alias of a table in a certain SQL statement is t1 and the table name specified in the hint is t2, the rule will determine that there is an index consistency problem with this SQL.
[0126] Step S432, determining an index usage rule according to the current operation instruction operation information and the index information;
[0127] It should be noted that the index usage rule is a rule for detecting whether the SQL statement correctly uses the index when performing a specific operation, and ensures that the index can be effectively utilized in the key operation to improve the efficiency of the query or data operation.
[0128] It can be understood that the index usage rule is formulated according to the current operation instruction and the index information. For example, when the current operation instruction is SELECT FOR UPDATE, the requirement of the operation on the index is analyzed, and the rule is determined in combination with the index fields contained in the index information: when the SELECT FOR UPDATE statement is used, the WHERE condition column needs to hit the index; when the current operation instruction is ORDER BY, the index field suitable for sorting is determined according to the index information: the field after ORDER BY needs to be indexed to avoid additional sorting operations. If the WHERE condition column of a certain SELECT FOR UPDATE statement does not contain any index field, it will be determined that there is an index usage problem with this SQL.
[0129] Step S433, determining a disabled operation word rule according to the database brand, the data table information, the field information and the index information;
[0130] It should be noted that the disabled operation word rule is a rule for detecting whether the SQL statement uses a keyword or reserved word that is not supported or prohibited by the database brand, and the keyword or reserved word that needs to be disabled may cause the SQL statement to execute incorrectly or not meet the specification.
[0131] It can be understood that the disabled operation word rule is formulated in combination with the database brand, the data table information, the field information and the index information. For example, for the TDSQL / MySQL database brand, the keywords and reserved words not supported thereby are collected, and according to this, the rule is determined that the library name, the table name, the field name and the index name are prohibited from using the keywords and reserved words of TDSQL / MySQL. If the table name in a certain SQL statement uses the reserved word TABLE of TDSQL, it is determined that the SQL has the disabled operation word problem.
[0132] In step S434, the primary key index limitation rule is determined according to the field information and the index information.
[0133] It should be noted that the primary key index limitation rule is a rule for regulating the use of the primary key index and the unique index, so as to ensure that the SQL statement meets a specific constraint condition in the operation involving the primary key and the unique index, and avoid data consistency problems or operation abnormities.
[0134] It can be understood that the primary key index limitation rule is formulated according to the field information and the index information. For example, when the primary key index and the unique index exist simultaneously in the index information, in combination with the constraint characteristics of the primary key and the unique index field in the field information, the rule is determined that the REPLACE INTO statement is not allowed to be used when the table simultaneously exists the primary key and the unique index; according to the non-updatable nature of the primary key field, the rule is determined that the primary key and the unique index field are not allowed to be updated; according to the requirement of data uniqueness for the deletion operation, the rule is determined that the WHERE condition of the deletion statement needs to contain the primary key or the unique index. If a certain SQL statement performs the REPLACE INTO operation on the table simultaneously existing the primary key and the unique index, the rule will determine that the SQL has the primary key index use problem.
[0135] In step S435, the continuation condition information is extracted according to the keyword information, and the keyword consistency rule is determined according to the keyword information and the continuation condition information.
[0136] It should be noted that the continuation condition information refers to the condition related to data continuation in the SQL statement, which usually involves specific fields or logical judgments, and is used to ensure the accuracy and continuity of data continuation.
[0137] Further, the keyword consistency rule is a rule for detecting whether the continuation condition and the sorting field remain consistent, so as to ensure that the sorting basis matches the continuation condition in the data continuation process, and avoid data confusion or errors.
[0138] It can be understood that the continuation condition information, i.e., the condition field related to data continuation, is extracted from the keyword information; then, in combination with the field related to sorting in the keyword information, the keyword consistency rule is determined. For example, the continuation condition TRANS_SEQ>100 in the WHERE clause is extracted from the keyword information, and the ORDER BY field is TRANS_SEQ, and accordingly the rule is determined: the continuation condition and the ORDER BY field need to be consistent. If the continuation condition field of a certain SQL statement is TRANS_SEQ, and the ORDER BY field is MERCHANT_ORDER_NBR, then the rule will determine that there is a keyword inconsistency problem in this SQL.
[0139] In step S436, the scanning rule is determined according to the index consistency rule, the index usage rule, the disabled operation word rule, the primary key index limitation rule, and the keyword consistency rule.
[0140] It can be understood that the index consistency rule, the index usage rule, the disabled operation word rule, the primary key index limitation rule, and the keyword consistency rule are integrated to form a complete scanning rule. Specifically, various special rules are organized according to certain logic to ensure that the scanning rule can comprehensively cover the detection needs of the SQL statement in terms of index usage consistency, index effective utilization, disabled word usage, primary key constraint, keyword consistency, etc.
[0141] Further, in determining the scanning rule, in addition to the above-mentioned various rules, more rules can be included according to actual needs, and it is not limited to the existing rule types. For example, a rule for using a precompiled function according to a business scenario can be included; for the characteristics of a specific database brand, rules such as TDSQL, MySQL do not support the use of add_months, decode functions, TDSQL does not support (+) or fulljoin for table connection, TDSQL uses the fixed number of 2 for the input parameter of instr(string function), TDSQL, MySQL do not support the lengthb() function to get the byte(length) length, TDSQL, MySQL require the input parameter number of lpad(string padding function) to be 3, TDSQL, MySQL can only have 1 input parameter for ltrim(string processing function), TDSQL does not support the mergeinto(merge statement) rule, TDSQL, MySQL do not support the use of dbms_random.value to get a random number, and the HINT(index position error) index position error causes the specified index to be invalid rule, etc. By including these rules, the coverage of SQL scanning can be further expanded, and the comprehensiveness and applicability of scanning can be improved.
[0142] Step S50, scanning the extensible markup language file according to the scanning rule to obtain a target scanning result.
[0143] It should be noted that the target scanning result is a conclusion obtained by scanning the XML file according to the scanning rule, including whether the SQL statement conforms to the specification, whether there is a risk of running efficiency, whether it is compatible with the database brand, etc., which can provide a basis for optimizing the SQL statement.
[0144] It can be understood that the extensible markup language file is scanned by using the scanning rule, and whether the SQL statement has a problem is judged according to the scanning result.
[0145] The embodiment provides a structured query language statement scanning method, which adopts the technical means of parsing the application source code to obtain the structured query language statement, the table object information and the database brand, obtaining the target brand driver according to the database brand and parsing the structured query language statement to obtain an abstract syntax tree, combining the structured query language statement, the abstract syntax tree and the table object information to generate an extensible markup language file, and determining the scanning rule according to the abstract syntax tree, the table object information and the database brand, and finally scanning the extensible markup language file according to the scanning rule to obtain a target scanning result, solving the problems of limited traditional SQL scanning and parsing capability, inability to effectively integrate multi-dimensional information and lack of real mapping of SQL and the database brand, and achieving the beneficial effects of supporting multi-dimensional personalized scanning, predictable SQL runtime execution efficiency and detecting whether the SQL in the application program is completely compatible with the connected database brand.
[0146] Based on the first embodiment of the application, in the second embodiment of the application, the same or similar contents as the above-mentioned first embodiment can be referred to the above introduction, and will not be repeated hereinafter. On this basis, please refer to Figure 2 , the step S50 of the structured query language statement scanning method comprises steps S51-S53:
[0147] Step S51, scanning the extensible markup language file according to the scanning rule to obtain a rule scanning result;
[0148] It should be noted that the rule scanning result is a result obtained by scanning the extensible markup language file by using the scanning rule, reflecting the situation of the SQL statement in terms of specification compliance, efficiency risk, compatibility, etc., such as whether it violates the index use rule, whether there is a function incompatible with the database brand, etc.
[0149] It can be understood that the extensible markup language file is comprehensively scanned by using the determined scanning rule. Specifically, the SQL statement, abstract syntax tree, table object information and the like contained in the XML file are matched and detected by the scanning rule.
[0150] In step S52, the extensible markup language file is scanned for a running efficiency risk to obtain a running efficiency risk scanning result.
[0151] It should be noted that the running efficiency risk scanning refers to analyzing the information contained in the extensible markup language file to identify the risk of low execution efficiency of the structured query language statement at runtime, such as the case that the query condition does not hit the index, the table record number is too large, and the like.
[0152] Further, the running efficiency risk scanning result is a conclusion obtained after the running efficiency risk scanning, reflecting whether the structured query language statement exists the execution efficiency risk at runtime, such as whether the query is slow due to not hitting the index, whether the operation speed is affected due to the table record number being too large, and the like.
[0153] It can be understood that the extensible markup language file is scanned for a running efficiency risk. Specifically, the information contained in the XML file is analyzed to identify the risk of low execution efficiency of the structured query language statement at runtime, such as the case that the query condition does not hit the index, the table record number is too large, and the like. <custom>The node contains table index information, table partition information, table record number and other contents, and in combination with an abstract syntax tree corresponding to the structured query language statement, determines whether the query condition of the structured query language statement hits the index, whether the structured query language statement contains a partition key, and whether the table record number exceeds a threshold value.
[0154] In a possible implementation, step S52 can include steps S521-S527.
[0155] In step S521, condition keywords and table record numbers are obtained according to the extensible markup language file.
[0156] It should be noted that the condition keywords are keywords used for filtering data in the WHERE clause of the structured query language statement, that is, fields or expressions involved in the query condition.
[0157] It can be understood that two types of keywords are extracted from the extensible markup language file. On the one hand, the structured query language statement contained in the XML file is parsed, and the WHERE clause is located to extract the condition keywords used for filtering data. On the other hand, the table record number of the corresponding table is obtained from the table object information of the XML file.
[0158] In step S522, it is determined whether table partition information exists in the extensible markup language file.
[0159] It should be noted that the table partition information refers to information related to storage of table data divided into multiple sub-tables according to a specific rule (such as field value range, list, etc.).
[0160] It can be understood that the table object information part of the extensible markup language file is checked to determine whether the table partition information is contained therein. Specifically, the XML file is viewed to determine whether the table partition information is contained in the table object information. <custom>Whether there is a label and content related to table partition under the node, if there is, it indicates that the table has partition setting, if not, it indicates that the table is not partitioned. For example, check the XML file in <custom>whether there are nodes under <partition>The sub-node and the corresponding partition definition, if any, determine that the table partition information exists, otherwise, the table partition information does not exist.
[0161] In step S523, it is determined whether the partition key attribute is contained in the condition keyword when the table partition information exists in the extensible markup language file.
[0162] It should be noted that the partition key attribute refers to the attribute of the field as the basis for table partitioning, including the name, data type and other characteristics of the field.
[0163] It can be understood that the attribute of the partition key is determined from the table partition information, and then it is checked whether the condition keyword contains the partition key field.
[0164] In step S524, it is determined whether the table record number is greater than or equal to a preset threshold when the condition keyword contains the partition key attribute.
[0165] It should be noted that the preset threshold is a critical value for judging whether the table record number is too large, which can be 10,000 in this embodiment. When the table record number exceeds this value, it is generally considered that the table data volume is large, which may affect the query efficiency.
[0166] It can be understood that when the condition keyword contains the partition key attribute, the table record number is compared with the preset threshold to determine whether the table record number is greater than or equal to the preset threshold.
[0167] In step S525, it is determined whether the index field information is contained in the condition keyword when the table record number is greater than or equal to the preset threshold or the table partition information does not exist in the extensible markup language file.
[0168] It can be understood that when the table record number is greater than or equal to the preset threshold, or the table partition information does not exist in the extensible markup language file, it is checked in this step whether the index field information is contained in the condition keyword. Specifically, the index field list is obtained from the table object information of the XML file, and then it is checked whether the condition keyword contains the field in the list.
[0169] In step S526, it is determined that the running efficiency risk scanning result is no running efficiency risk when the index field information is contained in the condition keyword or the table record number is less than the preset threshold.
[0170] It's understandable that when the condition keyword includes index field information, or the number of table records is less than a preset threshold, the efficiency risk scan result is determined to be no efficiency risk. For example, if the condition keyword includes an index field, the query can be accelerated by the index; if the table has 5,000 records, which is less than the preset threshold of 10,000, the data volume is small and query efficiency is not too low. Therefore, in both cases, no efficiency risk is determined.
[0171] Step S527 : When the condition keyword does not include a partition key attribute or the condition keyword does not include index field information, determining that the operation efficiency risk scan result is that an operation efficiency risk exists.
[0172] It's understandable that when the condition keyword doesn't include the partition key attribute or the condition keyword doesn't include index field information, the efficiency risk scan result is determined to be present. For example, if a table is partitioned but the condition keyword doesn't include the partition key attribute, the query may require scanning all partitions. If the table has a large number of records and the condition keyword doesn't include index field information, the query may require a full table scan. Both situations lead to low execution efficiency and are therefore considered to be present.
[0173] Step S53: obtaining a target scanning result according to the rule scanning result and the operation efficiency risk scanning result.
[0174] It's understandable that the rule scan results and the operational efficiency risk scan results are integrated to form the target scan results. Specifically, the issues involved in both types of results are summarized and organized by type or severity, clearly presenting the various issues with the Structured Query Language statements. By integrating the rule scan results and the operational efficiency risk scan results, the target scan results can comprehensively reflect the quality and potential risks of the Structured Query Language statements, helping to improve the reliability and applicability of Structured Query Language statements from multiple dimensions, including standardization, compatibility, and efficiency.
[0175] Reference Figure 3 , Figure 3 This is a schematic diagram of the efficiency scanning process of the second embodiment of the structured query language statement scanning method of this application.
[0176] like Figure 3 As shown, first determine whether there is table partition information. If not, determine that there is an operational efficiency risk and the process ends. If so, check whether the where condition contains the partition key attribute. If not, determine that there is an operational efficiency risk and the process ends. If so, check whether the number of table records exceeds the threshold. If not, determine that it meets the specification requirements and the process ends. If so, check whether the where condition contains index field information. If not, determine that there is an operational efficiency risk and the process ends. If so, determine that it meets the specification requirements and the process ends.
[0177] The embodiment provides a structured query language statement scanning method, which solves the problem that the SQL statement cannot be comprehensively evaluated in terms of specification compliance, running efficiency and compatibility in the prior art by adopting the technical means of rule scanning and running efficiency risk scanning on an extensible markup language file, and achieves the beneficial effects of more comprehensively and accurately identifying potential risks of the SQL statement and improving the quality and running efficiency of the SQL statement. Specifically, the rule scanning result is obtained by scanning the extensible markup language file according to a scanning rule, and whether the SQL statement is in compliance with a specification and whether there are compatibility problems can be detected; the running efficiency risk scanning result is obtained by performing running efficiency risk scanning on the extensible markup language file, and the risk of low execution efficiency that may exist when the SQL statement is running, such as a query condition not hitting an index or a large number of table records, can be identified. The rule scanning result and the running efficiency risk scanning result are integrated to form a target scanning result, so that the quality and potential risks of the SQL statement are comprehensively reflected, and the reliability and applicability of the SQL statement can be improved from multiple dimensions such as specification, compatibility and efficiency.
[0178] Exemplarily, in order to help understand the implementation process of the structured query language statement scanning method obtained after the above embodiment one, please refer to Figure 4 , Figure 4 A brief flowchart of a structured query language statement scanning method is provided, and specifically,
[0179] Starting from application source code parsing and SQL specification text, after the application source code parsing, the dependent database is parsed on one hand, and the MyBatis file is processed on the other hand; the MyBatis file is parsed to obtain static SQL, then the table information dependent on the SQL is parsed, and the database brand and table object information are obtained; the obtained database brand scheme is used for parsing the SQL into an AST syntax tree, and the table object information is used for assembling a complete XML file; at the same time, the SQL specification text is used for writing an XPath2 scanning rule, the rule is used for performing specification scanning on the XML file according to the rule, and finally the scanning result is output.
[0180] It should be noted that the above examples are only used for understanding the present application and do not constitute a limitation on the structured query language statement scanning method of the present application, and more forms of simple transformation based on the technical concept are within the protection scope of the present application.
[0181] The present application also provides a structured query language statement scanning device, please refer to Figure 5 , the structured query language statement scanning device comprises:
[0182] The code parsing module 10 is configured to parse the application source code to obtain a structured query language statement, table object information, and a database brand;
[0183] The statement parsing module 20 is configured to obtain a target brand driver according to the database brand, and parse the structured query language statement according to the target brand driver to obtain an abstract syntax tree.
[0184] The file forming module 30 is configured to generate an extensible markup language file according to the structured query language statement, the abstract syntax tree, and the table object information.
[0185] The rule determining module 40 is configured to determine a scanning rule according to the abstract syntax tree, the table object information, and the database brand.
[0186] The statement scanning module 50 is configured to scan the extensible markup language file according to the scanning rule to obtain a target scanning result.
[0187] The structured query language statement scanning device provided in the application adopts the structured query language statement scanning method in the above embodiments, and can solve the technical problem that the compatibility of SQL and a database brand cannot be accurately detected in a database environment. Compared with the prior art, the structured query language statement scanning device provided in the application has the same beneficial effects as the structured query language statement scanning method provided in the above embodiments, and other technical features in the structured query language statement scanning device are the same as the features disclosed in the above embodiments, which will not be repeated here.
[0188] In an embodiment, the file forming module 30 is further configured to parse the structured query language statement to obtain command information of the structured query language statement; extract table structure, index information, partition information, table record number, and keyword information according to the table object information; and generate an extensible markup language file according to the abstract syntax tree, the command information, the table structure, the index information, the partition information, the table record number, and the keyword information.
[0189] In an embodiment, the code parsing module 10 is further configured to parse the application source code to obtain a structured query language statement and database connection information; obtain a database brand and a database name according to the database connection information; extract a table name from the structured query language statement; and obtain table object information through the database name and the table name.
[0190] In an embodiment, the rule determining module 40 is further configured to determine, according to the abstract syntax tree, a current operation instruction and keyword information; determine, according to the table object information, index information, data table information, and field information; and determine, according to the current operation instruction, the keyword information, the data table information, the database brand, the field information, and the index information, a scan rule.
[0191] In an embodiment, the rule determining module 40 is further configured to determine, according to the current operation instruction, the keyword information, and the data table information, an index consistency rule; determine, according to the current operation instruction operation information and the index information, an index usage rule; determine, according to the database brand, the data table information, the field information, and the index information, a disable operation word rule; determine, according to the field information and the index information, a primary key index limitation rule; extract continuation condition information according to the keyword information, and determine, according to the keyword information and the continuation condition information, a keyword consistency rule; and determine, according to the index consistency rule, the index usage rule, the disable operation word rule, the primary key index limitation rule, and the keyword consistency rule, a scan rule.
[0192] In an embodiment, the statement scanning module 50 is further configured to scan, according to the scan rule, the extensible markup language file to obtain a rule scanning result; perform a running efficiency risk scan on the extensible markup language file to obtain a running efficiency risk scan result; and obtain, according to the rule scanning result and the running efficiency risk scan result, a target scan result.
[0193] In an embodiment, the statement scanning module 50 is further configured to obtain, according to the extensible markup language file, a condition keyword and a table record number; determine whether table partition information exists in the extensible markup language file; when the table partition information exists in the extensible markup language file, determine whether a partition key attribute is included in the condition keyword; when the partition key attribute is included in the condition keyword, determine whether the table record number is greater than or equal to a preset threshold; when the table record number is greater than or equal to the preset threshold or the table partition information does not exist in the extensible markup language file, determine whether index field information is included in the condition keyword; when the index field information is included in the condition keyword or the table record number is less than the preset threshold, determine that the running efficiency risk scan result is free of running efficiency risk; and when the partition key attribute is not included in the condition keyword or the index field information is not included in the condition keyword, determine that the running efficiency risk scan result is of running efficiency risk.
[0194] The application provides a structured query language sentence scanning device, the structured query language sentence scanning device comprising: at least one processor; and a memory connected with the at least one processor in communication; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the structured query language sentence scanning method in the above embodiment one.
[0195] Reference will now be made to the following description Figure 6 which illustrates a structural diagram of a structured query language sentence scanning device suitable for implementing the embodiments of the application. The structured query language sentence scanning device in the embodiments of the application can include, but is not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), and the like, and fixed terminals such as digital TVs, desktop computers, and the like. Figure 6 The illustrated structured query language sentence scanning device is merely an example and should not impose any limitation on the functions and use range of the embodiments of the application.
[0196] As Figure 6 As shown, the structured query language sentence scanning device can include a processing device 1001 (e.g., a central processing unit, a graphics processing unit, etc.) that can perform various appropriate actions and processes according to programs stored in a ROM (Read Only Memory) 1002 or programs loaded from a storage device 1003 into a RAM (Random Access Memory) 1004. In the RAM 1004, various programs and data required for the structured query language sentence scanning device to operate are also stored. The processing device 1001, the ROM 1002, and the RAM 1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: input devices 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; the storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the structured query language sentence scanning device to communicate with other devices wirelessly or by wire to exchange data. Although the structured query language sentence scanning device having various systems is shown in the figure, it should be understood that all the shown systems are not required to be implemented or possessed. More or fewer systems can be alternatively implemented or possessed.
[0197] In particular, according to the embodiments disclosed in the present application, the processes described above with reference to the flowcharts can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product comprising a computer program carried on a computer readable medium, the computer program containing program codes for executing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network through the communication device, or installed from the storage device 1003, or installed from the ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the methods of the embodiments disclosed in the present application are performed.
[0198] The structured query language sentence scanning device provided by the present application adopts the structured query language sentence scanning method in the above-mentioned embodiments, and can solve the technical problem that the database environment in which the SQL and the database brand compatibility cannot be accurately detected. Compared with the prior art, the structured query language sentence scanning device provided by the present application has the same beneficial effects as the structured query language sentence scanning method provided by the above-mentioned embodiments, and other technical features in the structured query language sentence scanning device are the same as the features disclosed in the previous embodiment method, which will not be described here.
[0199] It should be understood that various parts of the present application can be realized in hardware, software, firmware or a combination thereof. In the above description of embodiments, specific functional, structural, material or characteristic features are combined in a manner known per se; however, each feature can also be implemented individually or in a different combination.
[0200] The above description is only specific embodiments of the present application, but the protection scope of the present application is not limited thereto, and any person skilled in the art can easily think of changes or replacements within the technical scope disclosed by the present application, which should be covered by the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
[0201] The present application provides a computer readable storage medium having stored thereon computer readable program instructions (i.e. computer programs) for performing the structured query language statement scanning method in the above-described embodiments.
[0202] The computer readable storage medium provided by the present application may, for example, be a U disk, but is not limited to an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, system or device, or any combination of the above. More specific examples of the computer readable storage medium can include, but are not limited to, an electrical connection having one or more conductive wires, a portable computer diskette, a hard disk, a RAM (Random Access Memory), a ROM (Read Only Memory), an erasable programmable ROM (EPROM) or flash memory, an optical fiber, a CD-ROM (CD-Read Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present embodiment, the computer readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, system or device. The program code contained on the computer readable storage medium can be transmitted in any suitable medium, including but not limited to electrical wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0203] The above computer readable storage medium can be contained in the structured query language statement scanning device; or can exist separately and not be assembled into the structured query language statement scanning device.
[0204] The computer readable storage medium described above carries one or more programs, when the one or more programs are executed by the structured query language statement scanning device, the structured query language statement scanning device is caused to: parse application source code to obtain a structured query language statement, table object information and a database brand; obtain a target brand driver according to the database brand, and parse the structured query language statement according to the target brand driver to obtain an abstract syntax tree; generate an extensible markup language file according to the structured query language statement, the abstract syntax tree and the table object information; determine a scanning rule according to the abstract syntax tree, the table object information and the database brand; and scan the extensible markup language file according to the scanning rule to obtain a target scanning result.
[0205] Computer program code for carrying out operations of the present application can be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C++ or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code can execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection can be made to an external computer (for example, through the Internet using an Internet Service Provider).
[0206] The flow diagrams and the block diagrams in the drawings are illustrations of architectures, functionalities, and operations of possible implementations of systems, methods, and computer program products according to various embodiments of the present application. In this regard, each block in the flow diagrams or block diagrams can represent a module, a procedure, or a part of code, which comprises one or more executable instructions for implementing the specified functions. It should also be noted that in some alternative implementations, the functions noted in the blocks can occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently or in the reverse order, depending on the functionality involved. It is also noted that each block in the block diagrams and / or flow diagrams and combinations of blocks in the block diagrams and / or flow diagrams can be implemented by special-purpose hardware-based systems that perform the specified functions or operations, or combinations of special-purpose hardware and computer instructions.
[0207] The modules described in the embodiments of the present application can be implemented in the form of software or in the form of hardware. In some cases, the names of the modules do not constitute a limitation on the modules themselves.
[0208] The readable storage medium provided by the present application is a computer readable storage medium, which stores computer readable program instructions (i.e., a computer program) for executing the structured query language statement scanning method described above, and can solve the technical problem of the database environment in which SQL and database brand compatibility cannot be accurately detected. Compared with the prior art, the computer readable storage medium provided by the present application has the same beneficial effects as the structured query language statement scanning method provided by the above embodiments, and will not be described here.
[0209] The present application also provides a computer program product comprising a computer program, which, when executed by a processor, implements the steps of the structured query language statement scanning method as described above.
[0210] The computer program product provided by the present application can solve the technical problem of the database environment in which SQL and database brand compatibility cannot be accurately detected. Compared with the prior art, the computer program product provided by the present application has the same beneficial effects as the structured query language statement scanning method provided by the above embodiments, and will not be described here.
[0211] The above only describes some embodiments of the present application, and does not limit the patent scope of the present application. Any equivalent structural transformation made by using the content of the present application specification and drawings, or direct / indirect application in other related technical fields is included in the patent protection scope of the present application.< / partition> < / custom> < / custom> < / custom> < / custom> < / sql> < / sql> < / mapper>
Claims
1. A structured query language statement scanning method, characterized by, The method comprises: parsing the application source code to obtain a structured query language statement, table object information, and a database brand; obtaining a target brand driver according to the database brand, and parsing the structured query language statement according to the target brand driver to obtain an abstract syntax tree; generating an extensible markup language file according to the structured query language statement, the abstract syntax tree, and the table object information; determining a scanning rule according to the abstract syntax tree, the table object information, and the database brand; scanning the extensible markup language file according to the scanning rule to obtain a target scanning result.
2. The method of claim 1, wherein, The step of generating an extensible markup language file according to the structured query language statement, the abstract syntax tree, and the table object information comprises: parsing the structured query language statement to obtain command information of the structured query language statement; extracting table structure, index information, partition information, table record number, and keyword information according to the table object information; generating an extensible markup language file according to the abstract syntax tree, the command information, the table structure, the index information, the partition information, the table record number, and the keyword information.
3. The method of claim 1, wherein, The step of parsing the application source code to obtain a structured query language statement, table object information, and a database brand comprises: parsing the application source code to obtain a structured query language statement and database connection information; obtaining a database brand and a database name according to the database connection information; extracting a table name from the structured query language statement; obtaining table object information through the database name and the table name.
4. The method of claim 1, wherein, The step of determining a scanning rule according to the abstract syntax tree, the table object information, and the database brand comprises: determining a current operation instruction and keyword information according to the abstract syntax tree; determining index information, data table information, and field information according to the table object information; determining a scanning rule according to the current operation instruction, the keyword information, the data table information, the database brand, the field information, and the index information.
5. The method of claim 4, wherein, The step of determining a scanning rule according to the current operation instruction, the keyword information, the data table information, the database brand, the field information, and the index information comprises: determining an index consistency rule according to the current operation instruction, the keyword information, and the data table information; determining an index use rule according to the current operation instruction operation information and the index information; determining a disabled operation word rule according to the database brand, the data table information, the field information, and the index information; determining a primary key index limitation rule according to the field information and the index information; extracting a continuation condition information according to the keyword information, and determining a keyword consistency rule according to the keyword information and the continuation condition information; determining a scanning rule according to the index consistency rule, the index use rule, the disabled operation word rule, the primary key index limitation rule, and the keyword consistency rule.
6. The method of claim 1, wherein, The step of scanning the Extensible Markup Language file according to the scanning rule to obtain a target scanning result comprises: scanning the Extensible Markup Language file according to the scanning rule to obtain a rule scanning result; performing a running efficiency risk scan on the Extensible Markup Language file to obtain a running efficiency risk scan result; obtaining a target scanning result according to the rule scanning result and the running efficiency risk scan result.
7. The method of claim 6, wherein, The step of performing a running efficiency risk scan on the Extensible Markup Language file to obtain a running efficiency risk scan result comprises: obtaining a condition keyword and a table record number from the Extensible Markup Language file; determining whether table partition information exists in the Extensible Markup Language file; when the table partition information exists in the Extensible Markup Language file, determining whether a partition key attribute is included in the condition keyword; when the partition key attribute is included in the condition keyword, determining whether the table record number is greater than or equal to a preset threshold value; when the table record number is greater than or equal to the preset threshold value or the table partition information does not exist in the Extensible Markup Language file, determining whether index field information is included in the condition keyword; when the index field information is included in the condition keyword or the table record number is less than the preset threshold value, determining that the running efficiency risk scan result is free of running efficiency risk; when the partition key attribute is not included in the condition keyword or the index field information is not included in the condition keyword, determining that the running efficiency risk scan result is of running efficiency risk.
8. A structured query language statement scanning apparatus, characterized by, The device comprises: a code parsing module configured to parse application source code to obtain a Structured Query Language statement, table object information, and a database brand; a statement parsing module configured to obtain a target brand driver according to the database brand, and parse the Structured Query Language statement according to the target brand driver to obtain an abstract syntax tree; a file forming module configured to generate an Extensible Markup Language file according to the Structured Query Language statement, the abstract syntax tree, and the table object information; a rule determining module configured to determine a scanning rule according to the abstract syntax tree, the table object information, and the database brand; a statement scanning module configured to scan the Extensible Markup Language file according to the scanning rule to obtain a target scanning result.
9. A structured query language statement scanning device, characterized by, The device comprises a memory, a processor, and a computer program stored on the memory and executable on the processor, and the computer program is configured to implement the steps of the Structured Query Language statement scanning method according to any one of claims 1 to 7.
10. A storage medium, characterized by The storage medium is a computer readable storage medium, and the storage medium stores a computer program, and the computer program is executed by a processor to implement the steps of the Structured Query Language statement scanning method according to any one of claims 1 to 7.
