CN117632712A - Application database use detection method and device - Google Patents

Application database use detection method and device Download PDF

Info

Publication number
CN117632712A
CN117632712A CN202311585912.5A CN202311585912A CN117632712A CN 117632712 A CN117632712 A CN 117632712A CN 202311585912 A CN202311585912 A CN 202311585912A CN 117632712 A CN117632712 A CN 117632712A
Authority
CN
China
Prior art keywords
statement
application program
target application
database table
index
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311585912.5A
Other languages
Chinese (zh)
Inventor
段文平
李洪
高洪
任江华
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Chongqing Seres New Energy Automobile Design Institute Co Ltd
Original Assignee
Chongqing Seres New Energy Automobile Design Institute Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Chongqing Seres New Energy Automobile Design Institute Co Ltd filed Critical Chongqing Seres New Energy Automobile Design Institute Co Ltd
Priority to CN202311585912.5A priority Critical patent/CN117632712A/en
Publication of CN117632712A publication Critical patent/CN117632712A/en
Pending legal-status Critical Current

Links

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application relates to the technical field of program development and provides a database use detection method and device of an application program. The method comprises the following steps: acquiring a target application program; acquiring an original SQL sentence of a target application program based on the target application program; analyzing whether special statement problems or repeated statement problems exist in the original SQL statement; acquiring database table information corresponding to a target application program based on the target application program; based on the database table information, analyzing whether the database table index of the target application program has an index problem or not; if the special statement problem or the repeated statement problem or the index problem exists, outputting a corresponding detection result. According to the method and the device, the detection result corresponding to the target application program is obtained through analysis, and the detection result indicates the improper use problem of the database in the current target application program for the developer, so that the developer optimizes the target application program according to the detection result, and the use efficiency of the application program on the database is improved.

Description

Application database use detection method and device
Technical Field
The present disclosure relates to the field of program development technologies, and in particular, to a method and an apparatus for detecting database usage of an application program.
Background
The vehicle-mounted device based on the Android system has certain limit on computing resources and storage space, so that application programs on the vehicle-mounted device are required to consider the occupation problems of the computing resources and the storage space, and particularly the application programs which are required to store a large amount of user data are required. The SQLite database is the only choice for storing data of the application program of the Android system, and application developers have different capabilities and experiences for using the SQLite database, and under the condition of limited computing resources and storage space, the improper use of the SQLite database can cause various anomalies of the application program, such as slow running, blocking and the like of the application program, so that the user experience is poor.
Therefore, how to provide a solution to the above technical problem is a problem that needs to be solved by those skilled in the art.
Disclosure of Invention
In view of this, the embodiments of the present application provide a method and apparatus for detecting database usage of an application program, so as to solve the problem of improper use of the SQLite database in the prior art.
In a first aspect of an embodiment of the present application, there is provided a method for detecting database usage of an application program, including:
acquiring a target application program;
acquiring an original SQL sentence of a target application program based on the target application program;
analyzing whether special statement problems or repeated statement problems exist in the original SQL statement; the special sentence problem is that a preset word segment exists in the original SQL sentence, the repeated sentence problem is that the original SQL sentence has a state that an execution sentence is not in use with a precompiled sentence, and the occurrence frequency of the execution sentence in the SQL sentence exceeds a preset frequency;
acquiring database table information corresponding to a target application program based on the target application program;
based on the database table information, analyzing whether the database table index of the target application program has an index problem or not; the indexing problem includes that a database table index is not established or is not effective;
if the special statement problem or the repeated statement problem or the index problem exists, outputting a corresponding detection result.
In a second aspect of the embodiments of the present application, there is provided a database usage detection apparatus for an application program, including:
the program acquisition module is used for acquiring a target application program;
the statement acquisition module is used for acquiring an original SQL statement of the target application program based on the target application program;
the statement analysis module is used for analyzing whether special statement problems or repeated statement problems exist in the original SQL statement; the special sentence problem is that a preset word segment exists in the original SQL sentence, the repeated sentence problem is that the original SQL sentence has a state that an execution sentence is not in use with a precompiled sentence, and the occurrence frequency of the execution sentence in the SQL sentence exceeds a preset frequency;
the database table acquisition module is used for acquiring database table information corresponding to the target application program based on the target application program;
the database table analysis module is used for analyzing whether the database table index of the target application program has an index problem or not based on the database table information; the indexing problem includes that a database table index is not established or is not effective;
and the result output module is used for outputting a corresponding detection result if a special statement problem or a repeated statement problem or an index problem exists.
In a third aspect of the embodiments of the present application, there is provided an electronic device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, the processor implementing the steps of the above method when executing the computer program.
In a fourth aspect of the embodiments of the present application, there is provided a readable storage medium storing a computer program which, when executed by a processor, implements the steps of the above method.
Compared with the prior art, the beneficial effects of the embodiment of the application at least comprise: according to the method and the device, whether the target application program has any one of a special statement problem, a repeated statement problem and an index problem is determined by analyzing the original SQL statement or database table information of the target application program, so that a corresponding detection result is output, the detection result indicates an improper problem of database use in the current target application program to a developer, the target application program is optimized by the developer according to the detection result, and therefore the use efficiency of the application program on the database is improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following description will briefly introduce the drawings that are needed in the embodiments or the description of the prior art, it is obvious that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
Fig. 1 is a schematic view of an application scenario according to an embodiment of the present application;
FIG. 2 is a flowchart of a method for detecting database usage of an application according to an embodiment of the present application;
FIG. 3 is a schematic diagram of a database usage detection device of an application according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth, such as particular system configurations, techniques, etc. in order to provide a thorough understanding of the embodiments of the present application. It will be apparent, however, to one skilled in the art that the present application may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present application with unnecessary detail.
A method and apparatus for detecting database usage of an application according to embodiments of the present application will be described in detail with reference to the accompanying drawings.
Fig. 1 is a schematic view of an application scenario according to an embodiment of the present application. The application scenario may include a first terminal device 101, a second terminal device 102, a third terminal device 103, a server 104, and a network 105.
The first terminal device 101 may be hardware or software. When the first terminal device 101 is hardware, it may be various electronic devices having a display screen and supporting communication with the server 104, including but not limited to smartphones, tablets, laptop portable computers, desktop computers, and the like; when the first terminal apparatus 101 is software, it may be installed in the electronic apparatus as above. The first terminal device 101 may be implemented as a plurality of software or software modules, or may be implemented as a single software or software module, which is not limited in this embodiment of the present application. Further, various applications, such as a data processing application, an instant messaging tool, social platform software, a search class application, a shopping class application, and the like, may be installed on the first terminal device 101.
The second terminal device 102 may be hardware or software. When the second terminal device 102 is hardware, it may be a variety of electronic devices having a display screen and supporting communication with the server 104, including but not limited to smartphones, tablets, laptop and desktop computers, and the like; when the second terminal device 102 is software, it may be installed in the electronic device as above. The second terminal device 102 may be implemented as a plurality of software or software modules, or may be implemented as a single software or software module, which is not limited in this embodiment of the present application. Further, various applications may be installed on the second terminal device 102, such as a data processing application, an instant messaging tool, social platform software, a search class application, a shopping class application, and the like.
The third terminal device 103 may be hardware or software. When the third terminal device 103 is hardware, it may be various electronic devices having a display screen and supporting communication with the server 104, including but not limited to smartphones, tablets, laptop and desktop computers, etc.; when the third terminal device 103 is software, it may be installed in the electronic device as above. The third terminal device 103 may be implemented as a plurality of software or software modules, or may be implemented as a single software or software module, which is not limited in this embodiment of the present application. Further, various applications, such as a data processing application, an instant messaging tool, social platform software, a search class application, a shopping class application, and the like, may be installed on the third terminal device 103.
The server 104 may be a server that provides various services, for example, a background server that receives a request transmitted from a terminal device with which communication connection is established, and the background server may perform processing such as receiving and analyzing the request transmitted from the terminal device and generate a processing result. The server 104 may be a server, a server cluster formed by a plurality of servers, or a cloud computing service center, which is not limited in this embodiment of the present application.
The server 104 may be hardware or software. When the server 104 is hardware, it may be various electronic devices that provide various services to the first terminal device 101, the second terminal device 102, and the third terminal device 103. When the server 104 is software, it may be a plurality of software or software modules providing various services to the first terminal device 101, the second terminal device 102, and the third terminal device 103, or may be a single software or software module providing various services to the first terminal device 101, the second terminal device 102, and the third terminal device 103, which is not limited in this embodiment of the present application.
The network 105 may be a wired network using coaxial cable, twisted pair and optical fiber connection, or may be a wireless network that can implement interconnection of various communication devices without wiring, for example, bluetooth (Bluetooth), near field communication (Near Field Communication, NFC), infrared (Infrared), etc., which is not limited in the embodiment of the present application.
It should be noted that the specific types, numbers and combinations of the first terminal device 101, the second terminal device 102, the third terminal device 103, the server 104 and the network 105 may be adjusted according to the actual requirements of the application scenario, which is not limited in the embodiment of the present application.
Fig. 2 is a flowchart of a method for detecting database usage of an application according to an embodiment of the present application. The database usage detection method of the application program of fig. 2 may be performed by the first terminal device or the second terminal device or the third terminal device or the server of fig. 1. As shown in fig. 2, the database usage detection method of the application program includes:
s201: acquiring a target application program;
s202: acquiring an original SQL sentence of a target application program based on the target application program;
s203: analyzing whether special statement problems or repeated statement problems exist in the original SQL statement; the special sentence problem is that a preset word segment exists in the original SQL sentence, the repeated sentence problem is that the original SQL sentence has a state that an execution sentence is not in use with a precompiled sentence, and the occurrence frequency of the execution sentence in the SQL sentence exceeds a preset frequency;
s204: acquiring database table information corresponding to a target application program based on the target application program;
s205: based on the database table information, analyzing whether the database table index of the target application program has an index problem or not; the indexing problem includes that a database table index is not established or is not effective;
s206: if the special statement problem or the repeated statement problem or the index problem exists, outputting a corresponding detection result.
It can be understood that after the target application program is obtained, according to the original SQL statement of the target application program, whether a special statement problem or a repeated statement problem exists in the original SQL statement can be analyzed, according to the database table information of the target application program, whether an index problem exists in the database table index can be analyzed, and once the special statement problem, the repeated statement problem or the index problem exists, the current target application program can be judged to be in a state to be optimized, so that a detection result corresponding to the problem to be optimized is output.
It will be appreciated that the method of the present embodiment may be implemented in a programming language integrated into an SDK (Software Development Kit ).
Specifically, since the target application is designed and written by other developers, the original SQL statement about the target application cannot be directly obtained in this embodiment, so this embodiment needs to register a preset callback function, and the original SQL statement is obtained by using the preset callback function, and thus the process of obtaining the original SQL statement of the target application includes:
and executing the target application program, and calling a preset callback function, wherein the preset callback function is registered in the sqlite3_profile method in advance and is used for returning to an original SQL statement in the target application program.
It can be appreciated that the sqlite3_profile method has the following mechanism: in the code of the target application program, the sqlite3_profile method in the android_run.so of the PLT (GOT) HOOK function HOOK system is used, and after each SQL statement of the target application program is completed to be executed, a callback function registered in the sqlite3_profile method is called. Therefore, in this embodiment, a callback function capable of returning to the original SQL statement, that is, a preset callback function, is registered in the sqlite3_profile method, and when the system executes the target application program, the preset callback function is automatically called by the hook sqlite3_profile method, so that the original SQL statement is obtained.
Further, for the analysis of the original SQL statement, two main aspects are:
one aspect is whether there is a special sentence problem, i.e. whether there is a preset word segment, e.g. a select word segment. Select is one of the most commonly used statements of SQLite because of its convenience, but Select causes serious performance problems for the target application during running, and for the Android platform, select projects all columns, each column occupies relatively large memory, and in fact, the scope of the query does not involve all columns, and in most cases, all columns of the database table do not need to be returned. Therefore, the use of select reduces the performance of the target application, so that after detecting the select word segment, the method of this embodiment may record the corresponding execution statement as a special execution statement into the detection result, i.e. the process of analyzing whether there is a special statement problem in the original SQL statement, including:
analyzing whether a select word segment exists in the original SQL sentence;
if yes, confirming that the special statement problem exists in the original SQL statement, taking the execution statement containing the select word segment as the special execution statement, and recording the special execution statement into a detection result.
Of course, in addition to the select word segment, the preset word segment may be set to other specific word segments that may be related to the database table and affect the performance of the target application, which is not limited herein.
On the other hand, the analysis of the original SQL statement has the problem of repeated statement, and the problem of repeated statement mainly aims at the execution statement which occurs for a plurality of times, can use the precompiled statement state prepared statement to improve the execution efficiency and does not use the precompiled statement state. The execution statements appearing many times here do not require the same real parameters, and the real parameters of each execution statement may be different, so long as the execution statement itself is ensured to be the same. The embodiment detects the execution statement, if the detection result is recorded as the repeated execution statement, the developer can use the precompiled statement state for the repeated execution statement after seeing the detection result, thereby improving the execution efficiency of the execution statement. The process of analyzing whether the repeated sentence problem exists in the original SQL sentence comprises the following steps:
analyzing whether executing sentences which do not use the state of the precompiled sentences and occur for more than the preset times exist in the continuous executing sentences with the preset number in the original SQL sentences;
if yes, confirming that the repeated sentence problem exists in the original SQL sentence, taking the execution sentence which does not use the pre-compiled sentence state and has the occurrence frequency exceeding the preset frequency as the repeated execution sentence, and recording the repeated execution sentence into a detection result.
It can be understood that regarding whether the execution statement is repeated, a determination range, that is, a continuous execution statement with a preset number of execution statements may be set, taking the preset number of execution statements as 20 and the preset number of execution statements as 3 as an example, when the number of times of the same execution statement in the continuous 20 execution statements exceeds 3 times, and the execution statement appearing many times is not in use of the precompiled statement state, the execution statement is considered as a repeated execution statement. The precompiled sentence state can show the improvement of efficiency only when being used in the executing sentences with higher repetition times, so that the limitation of the preset times and the preset number is to improve the accuracy of determining the repeatedly executed sentences, if the preset number is too large or the preset times is lower, the repeatedly executed sentences with lower repetition times or more scattered occurrence positions can be generated, and even if the precompiled sentence state is used in the repeatedly executed sentences, the execution efficiency is not obviously improved. Therefore, the preset number of pieces and the preset number of times need to be set according to the specific effect of the state of the precompiled sentence, which is not limited here.
It can be understood that after the target application program is executed, the sqlite3_profile method is called, related information about the database table can be obtained through the pragma command, and further analysis of the database table index is performed by using the pragma command, specifically, based on the database table information, a process of analyzing whether the database table index of the target application program has an index problem or not includes:
and analyzing whether the index problem exists in the database table index of the target application program through the pragma command based on the database table information.
Further, the indexing problem mainly includes that no database table index is established or the database table index is not effective.
If the database table is not built with the database table index, the whole table scanning is needed when the specific data query appears in the execution statement, so that the information efficiency of the SQLite database table is low, the query speed is slow, and regarding the problem, whether the database table index is built for the database table corresponding to the database table name can be checked through a pragma index_list ('database table name') command, if the return result of the command is not built with the index, the corresponding return result is recorded into the detection result, and the database table index can be added for the database table pertinently after the developer sees the detection result, so that the effect of returning the search result more quickly when searching the database table information is achieved.
If the database TABLE index is not validated, namely, although the database TABLE index is established for the database TABLE, the database TABLE index is not used when the actual execution statement inquires data, but global scanning is performed instead, at the moment, a scanning return result in the database TABLE information needs to be analyzed, if the scanning return result is SCAN TABLE T (token scanning, T is the name of the database TABLE), the database TABLE index is not validated, the inquiry is global searching, and the efficiency is lower; if the scan return result includes xxindex, xx is a column name, then the database table index is indicated to be effective.
Thus, the process of analyzing whether there is an index problem with the database table index of the target application by the pragma command based on the database table information includes:
analyzing whether a database table index of the target application program exists or not through a pragma index_list command based on the database table information; if not, judging that the target application program does not establish the database table index;
and acquiring a scanning return result in the database table information, and if the scanning return result is different from the corresponding database table index, judging that the database table index is not effective.
Further, among the database table indexes, only the largest index may be reserved for indexes whose index ranges are repeated, and it is not necessary to use all the database table indexes, for example, when a name column conditional query is satisfied when a name column index combination exists, if there is a name column database table index, the name column database table index is included in the name column database table index, and the name column database table index may be deleted. The indexing problem thus also includes an indexing redundancy problem, a process of analyzing whether an indexing problem exists in a database table index of a target application program based on database table information, including:
analyzing whether all database table indexes have the condition that the index range of the first index is contained by the index range of the second index;
if yes, judging that the index redundancy problem exists, and recording the first index as a redundant index into a detection result.
It can be understood that according to the analysis of the target application program in steps S201-S205, it is obtained whether any problem of the special statement problem, the repeated statement problem or the index problem exists in the current target application program, and once the problem exists, a detection result is generated and output according to the problem, and a developer sees that specific content in the detection result can perform targeted optimization on the current SQL statement of the target application program, thereby improving the execution efficiency of the target application program.
According to the method, whether the target application program has any one of a special statement problem, a repeated statement problem and an index problem is determined by analyzing the original SQL statement or database table information of the target application program, so that a corresponding detection result is output, and the detection result indicates the improper problem of database use in the current target application program to a developer, so that the developer optimizes the target application program according to the detection result, and the use efficiency of the application program on the database is improved.
Any combination of the above optional solutions may be adopted to form an optional embodiment of the present application, which is not described herein in detail. It should be understood that the sequence number of each step in the foregoing embodiment does not mean that the execution sequence of each process should be determined by the function and the internal logic of each process, and should not limit the implementation process of the embodiment of the present application in any way.
The following are device embodiments of the present application, which may be used to perform method embodiments of the present application. For details not disclosed in the device embodiments of the present application, please refer to the method embodiments of the present application.
Fig. 3 is a schematic diagram of a database usage detection device of an application according to an embodiment of the present application. As shown in fig. 3, the database usage detection device of the application program includes:
a program acquisition module 301, configured to acquire a target application program;
the statement acquiring module 302 is configured to acquire an original SQL statement of a target application program based on the target application program;
a statement analysis module 303, configured to analyze whether a special statement problem or a repeated statement problem exists in the original SQL statement; the special sentence problem is that a preset word segment exists in the original SQL sentence, the repeated sentence problem is that the original SQL sentence has a state that an execution sentence is not in use with a precompiled sentence, and the occurrence frequency of the execution sentence in the SQL sentence exceeds a preset frequency;
the database table obtaining module 304 is configured to obtain database table information corresponding to a target application program based on the target application program;
a database table analysis module 305, configured to analyze whether an index problem exists in a database table index of the target application program based on the database table information; the indexing problem includes that a database table index is not established or is not effective;
the result output module 306 is configured to output a corresponding detection result if there is a special statement problem or a repeat statement problem or an index problem.
According to the device, whether the target application program has any one of a special statement problem, a repeated statement problem and an index problem is determined by analyzing the original SQL statement or database table information of the target application program, so that a corresponding detection result is output, and the detection result indicates the improper problem of database use in the current target application program to a developer, so that the developer optimizes the target application program according to the detection result, and the use efficiency of the application program on the database is improved.
In an exemplary embodiment, the process of analyzing whether a special statement problem exists in an original SQL statement includes:
analyzing whether a select word segment exists in the original SQL sentence;
if yes, confirming that the special statement problem exists in the original SQL statement, taking the execution statement containing the select word segment as the special execution statement, and recording the special execution statement into a detection result.
In an exemplary embodiment, the process of analyzing whether there is a repeat statement problem in the original SQL statement includes:
analyzing whether executing sentences which do not use the state of the precompiled sentences and occur for more than the preset times exist in the continuous executing sentences with the preset number in the original SQL sentences;
if yes, confirming that the repeated sentence problem exists in the original SQL sentence, taking the execution sentence which does not use the pre-compiled sentence state and has the occurrence frequency exceeding the preset frequency as the repeated execution sentence, and recording the repeated execution sentence into a detection result.
In an exemplary embodiment, a process for analyzing whether an index problem exists in a database table index of a target application program based on database table information includes:
and analyzing whether the index problem exists in the database table index of the target application program through the pragma command based on the database table information.
In an exemplary embodiment, the process of analyzing whether an index problem exists in a database table index of a target application program through a pragma command based on database table information includes:
analyzing whether a database table index of the target application program exists or not through a pragma index_list command based on the database table information; if not, judging that the target application program does not establish the database table index;
and acquiring a scanning return result in the database table information, and if the scanning return result is different from the corresponding database table index, judging that the database table index is not effective.
In an exemplary embodiment, the indexing problem further includes an indexing redundancy problem, and the process of analyzing whether the database table index of the target application program has the indexing problem based on the database table information includes:
analyzing whether all database table indexes have the condition that the index range of the first index is contained by the index range of the second index;
if yes, judging that the index redundancy problem exists, and recording the first index as a redundant index into a detection result.
In an exemplary embodiment, based on the target application program, a process of acquiring an original SQL statement of the target application program includes:
and executing the target application program, and calling a preset callback function, wherein the preset callback function is registered in the sqlite3_profile method in advance and is used for returning to an original SQL statement in the target application program.
Fig. 4 is a schematic diagram of an electronic device 4 provided in an embodiment of the present application. As shown in fig. 4, the electronic apparatus 4 of this embodiment includes: a processor 401, a memory 402 and a computer program 403 stored in the memory 402 and executable on the processor 401. The steps of the various method embodiments described above are implemented by processor 401 when executing computer program 403. Alternatively, the processor 401, when executing the computer program 403, performs the functions of the modules/units in the above-described apparatus embodiments.
The electronic device 4 may be a desktop computer, a notebook computer, a palm computer, a cloud server, or the like. The electronic device 4 may include, but is not limited to, a processor 401 and a memory 402. It will be appreciated by those skilled in the art that fig. 4 is merely an example of the electronic device 4 and is not limiting of the electronic device 4 and may include more or fewer components than shown, or different components.
The processor 401 may be a central processing unit (Central Processing Unit, CPU) or other general purpose processor, digital signal processor (Digital Signal Processor, DSP), application specific integrated circuit (Application Specific Integrated Circuit, ASIC), field programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, or the like.
The memory 402 may be an internal storage unit of the electronic device 4, for example, a hard disk or a memory of the electronic device 4. The memory 402 may also be an external storage device of the electronic device 4, for example, a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash Card (Flash Card) or the like, which are provided on the electronic device 4. Memory 402 may also include both internal storage units and external storage devices of electronic device 4. The memory 402 is used to store computer programs and other programs and data required by the electronic device.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-described division of the functional units and modules is illustrated, and in practical application, the above-described functional distribution may be performed by different functional units and modules according to needs, i.e. the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-described functions. The functional units and modules in the embodiment may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit, where the integrated units may be implemented in a form of hardware or a form of a software functional unit.
The integrated modules/units, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a readable storage medium, such as a computer readable storage medium. Based on such understanding, the present application implements all or part of the flow in the method of the above embodiment, or may be implemented by a computer program to instruct related hardware, where the computer program may be stored in a readable storage medium, where the computer program may implement the steps of the method embodiments described above when executed by a processor. The computer program may comprise computer program code, which may be in source code form, object code form, executable file or in some intermediate form, etc. The readable storage medium may include: any entity or device capable of carrying computer program code, a recording medium, a U disk, a removable hard disk, a magnetic disk, an optical disk, a computer Memory, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), an electrical carrier signal, a telecommunications signal, a software distribution medium, and so forth.
The above embodiments are only for illustrating the technical solution of the present application, and are not limiting thereof; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present application, and are intended to be included in the scope of the present application.

Claims (10)

1. A database usage detection method for an application program, comprising:
acquiring a target application program;
acquiring an original SQL sentence of the target application program based on the target application program;
analyzing whether a special statement problem or a repeated statement problem exists in the original SQL statement; the special sentence problem is that a preset word segment exists in the original SQL sentence, the repeated sentence problem is that an execution sentence unused precompiled sentence state exists in the original SQL sentence, and the occurrence frequency of the execution sentence in the SQL sentence exceeds a preset frequency;
acquiring database table information corresponding to the target application program based on the target application program;
analyzing whether the database table index of the target application program has an index problem or not based on the database table information; the indexing problem includes that a database table index is not established or is not validated;
and if the special statement problem or the repeated statement problem or the index problem exists, outputting a corresponding detection result.
2. The method of claim 1, wherein the process of analyzing whether a special statement problem exists in the original SQL statement comprises:
analyzing whether a select word segment exists in the original SQL sentence;
if yes, confirming that a special statement problem exists in the original SQL statement, taking an execution statement containing the select word segment as a special execution statement, and recording the special execution statement into a detection result.
3. The method of claim 1, wherein the process of analyzing whether there is a repeat statement problem in the original SQL statement comprises:
analyzing whether executing sentences which do not use the state of the precompiled sentences and occur for more than the preset times exist in the continuous executing sentences with the preset number in the original SQL sentences;
if yes, confirming that the repeated statement problem exists in the original SQL statement, taking the execution statement which does not use the pre-compiled statement state and has the occurrence frequency exceeding the preset frequency as the repeated execution statement, and recording the repeated execution statement into a detection result.
4. The method of claim 1, wherein analyzing whether the database table index of the target application has an index problem based on the database table information comprises:
and analyzing whether the index problem exists in the database table index of the target application program or not through a pragma command based on the database table information.
5. The method of claim 4 wherein analyzing, based on the database table information, whether an index problem exists with a database table index of the target application via a pragma command comprises:
analyzing whether a database table index of the target application program exists or not through a pragma index_list command based on the database table information; if not, judging that the target application program does not establish a database table index;
and acquiring a scanning return result in the database table information, and if the scanning return result is different from the corresponding database table index, judging that the database table index is not effective.
6. The method of claim 1, wherein the indexing problem further comprises an indexing redundancy problem, and wherein analyzing whether the database table index of the target application has an indexing problem based on the database table information comprises:
analyzing whether all the database table indexes have the condition that the index range of the first index is contained by the index range of the second index;
if yes, judging that the index redundancy problem exists, and recording the first index as a redundancy index into a detection result.
7. The method according to any one of claims 1 to 6, wherein the process of obtaining the original SQL statement of the target application based on the target application comprises:
and executing the target application program, and calling a preset callback function, wherein the preset callback function is registered in the sqlite3_profile method in advance and is used for returning to an original SQL statement in the target application program.
8. A database usage detection apparatus for an application program, comprising:
the program acquisition module is used for acquiring a target application program;
the statement acquisition module is used for acquiring an original SQL statement of the target application program based on the target application program;
the statement analysis module is used for analyzing whether special statement problems or repeated statement problems exist in the original SQL statement; the special sentence problem is that a preset word segment exists in the original SQL sentence, the repeated sentence problem is that an execution sentence unused precompiled sentence state exists in the original SQL sentence, and the occurrence frequency of the execution sentence in the SQL sentence exceeds a preset frequency;
the database table acquisition module is used for acquiring database table information corresponding to the target application program based on the target application program;
the database table analysis module is used for analyzing whether the index problem exists in the database table index of the target application program or not based on the database table information; the indexing problem includes that a database table index is not established or is not validated;
and the result output module is used for outputting a corresponding detection result if the special statement problem or the repeated statement problem or the index problem exists.
9. An electronic device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that the processor implements the steps of the method according to any of claims 1 to 7 when the computer program is executed.
10. A readable storage medium storing a computer program, characterized in that the computer program when executed by a processor implements the steps of the method according to any one of claims 1 to 7.
CN202311585912.5A 2023-11-24 2023-11-24 Application database use detection method and device Pending CN117632712A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311585912.5A CN117632712A (en) 2023-11-24 2023-11-24 Application database use detection method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311585912.5A CN117632712A (en) 2023-11-24 2023-11-24 Application database use detection method and device

Publications (1)

Publication Number Publication Date
CN117632712A true CN117632712A (en) 2024-03-01

Family

ID=90028049

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311585912.5A Pending CN117632712A (en) 2023-11-24 2023-11-24 Application database use detection method and device

Country Status (1)

Country Link
CN (1) CN117632712A (en)

Similar Documents

Publication Publication Date Title
CN111352902A (en) Log processing method and device, terminal equipment and storage medium
CN108959279B (en) Data processing method, data processing device, readable medium and electronic equipment
CN109359118B (en) Data writing method and device
CN111125107A (en) Data processing method, device, electronic equipment and medium
CN113157731A (en) Symbol analysis method, device, equipment and storage medium
CN115599386A (en) Code generation method, device, equipment and storage medium
CN110888972A (en) Sensitive content identification method and device based on Spark Streaming
US20180314683A1 (en) Method and device for processing natural language
CN106502707B (en) Code generation method and device
CN108959294B (en) Method and device for accessing search engine
CN116955198A (en) Rule set determining method and device
CN110866031B (en) Database access path optimization method and device, computing equipment and medium
CN108021464B (en) Bottom-pocketing processing method and device for application response data
CN117632712A (en) Application database use detection method and device
CN115809193A (en) Front-end reverse abnormal data robustness detection method, device and storage medium
CN113626558B (en) Intelligent recommendation-based field standardization method and system
CN114637969A (en) Target object authentication method and device
CN113688160A (en) Data processing method, processing device, electronic device and storage medium
CN109857632B (en) Test method, test device, terminal equipment and readable storage medium
CN109543079B (en) Data query method and device, computing equipment and storage medium
CN109656805B (en) Method and device for generating code link for business analysis and business server
CN112907198A (en) Service state circulation maintenance method and device and electronic equipment
CN110750569A (en) Data extraction method, device, equipment and storage medium
CN113840020B (en) Positioning method and device based on IP address information, electronic equipment and storage medium
CN115994151B (en) Data request changing method, device, electronic equipment and computer readable medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination