Data query method, device, apparatus, and storage medium
Patent Information
- Application Number
- CN202211075873.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-02
- Publication Date
- 2026-09-11
- Estimated Expiration
- 2042-09-02
AI Technical Summary
[0004]本发明的主要目的在于提供了一种数据查询方法、装置、设备及存储介质,旨在解决现有技术数据库替换时工作量大,替换效率不高的技术问题
[0027]This invention intercepts data query requests sent from a target terminal to a target database; extracts the query statement from the data query request and converts the query statement into a target query statement recognizable by the target database; retrieves data query results from the target database based on the target query statement, and sends the data query results to the target terminal. Because this invention intercepts data query requests sent from a target terminal to a target database, extracts the query statement from the data query request, converts the query statement into a target query statement recognizable by the target database, and retrieves data query results from the target database based on the target query statement, compared to existing methods that require replacing the query statement in the terminal when replacing the database, the above method of this invention can convert the query statement into a target query statement recognizable by the target database, thus improving the efficiency of database replacement.
Smart Images

Figure CN115525671B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a data query method, apparatus, device, and storage medium. Background Technology
[0002] Currently, most enterprises use relational databases or other databases. However, with the rapid development of domestic databases, many enterprises will adopt them at a certain stage of development or at the request of clients. If a project involves dozens or even hundreds of application systems, it requires replacing the database connection information and structured query language for each system. Furthermore, the different languages used by different systems increase the difficulty of this replacement process. Therefore, how to efficiently replace databases has become a pressing technical problem that needs to be solved.
[0003] The above content is only used to help understand the technical solution of the present invention and does not represent an admission that the above content is prior art. Summary of the Invention
[0004] The main objective of this invention is to provide a data query method, apparatus, device, and storage medium, aiming to solve the technical problems of large workload and low efficiency in database replacement in the prior art.
[0005] To achieve the above objectives, the present invention provides a data query method, the method comprising the following steps: Intercept data query requests sent from the target terminal to the target database; Extract the query statement from the data query request and convert the query statement into a target query statement that the target database can recognize; The data query results are obtained from the target database according to the target query statement, and the data query results are sent to the target terminal.
[0006] Optionally, the step of extracting the query statement from the data query request and converting the query statement into a target query statement recognizable by the target database includes: Extract the query statement from the data query request; Identify the statements in the query that the target database cannot recognize and need to be replaced; The statement to be replaced is subjected to syntax transformation to convert the query statement into a target query statement that can be recognized by the target database.
[0007] Optionally, the step of performing syntax transformation on the statement to be replaced includes: Obtain the start and end positions of the statement to be replaced in the query statement; Obtain the target statement corresponding to the statement to be replaced; The statement to be replaced is grammatically transformed based on the start position, the end position, and the target statement.
[0008] Optionally, the step of obtaining the target statement corresponding to the statement to be replaced includes: Obtain the original database corresponding to the target terminal; Obtain the statement mapping table between the target database and the original database; The target statement corresponding to the statement to be replaced is found according to the statement mapping table.
[0009] Optionally, before the step of intercepting the data query request sent by the target terminal to the target database, the method further includes: Obtain the database connection information for the target database; Connect to the target database based on the database connection information.
[0010] Optionally, the database connection information includes the target database's data source information and data-driven information; The step of connecting to the target database based on the database connection information includes: Connect to the target database based on the data source information and the data-driven information.
[0011] Optionally, the step of obtaining data query results from the target database according to the target query statement and sending the data query results to the target terminal includes: Retrieve data query results from the target database based on the target query statement; Obtain the data protocol of the original database corresponding to the target terminal; The data query results are encoded and disguised according to the data protocol to generate the target data query results; The target data query results are sent to the target terminal.
[0012] Optionally, before the step of intercepting the data query request sent by the target terminal to the target database, the method further includes: Obtain the original database connection information corresponding to the original database of the target terminal; Connect to the original database based on the original database connection information; Obtain the data to be migrated from the original database; The data to be migrated is migrated to the target database.
[0013] Optionally, the step of migrating the data to be migrated to the target database includes: Obtain the table structure information of the data to be migrated; Create a data table in the target database based on the table structure information; The data to be migrated is migrated to the target database based on the created data table.
[0014] Optionally, the step of extracting the query statement from the data query request includes: The data packet corresponding to the data query request is decoded to obtain decoded data; Extract the query statement from the decoded data.
[0015] Furthermore, to achieve the above objectives, the present invention also provides a data query device, the device comprising: The interception module is used to intercept data query requests sent by the target terminal to the target database; The statement conversion module is used to extract the query statement from the data query request and convert the query statement into a target query statement that can be recognized by the target database. The query module is used to retrieve data query results from the target database according to the target query statement, and send the data query results to the target terminal.
[0016] Optionally, the statement conversion module is further configured to extract the query statement from the data query request; Identify the statements in the query that the target database cannot recognize and need to be replaced; The statement to be replaced is subjected to syntax transformation to convert the query statement into a target query statement that can be recognized by the target database.
[0017] Optionally, the statement conversion module is further configured to obtain the start and end positions of the statement to be replaced in the query statement; Obtain the target statement corresponding to the statement to be replaced; The statement to be replaced is grammatically transformed based on the start position, the end position, and the target statement.
[0018] Optionally, the statement conversion module is further configured to obtain the original database corresponding to the target terminal; Obtain the statement mapping table between the target database and the original database; The target statement corresponding to the statement to be replaced is found according to the statement mapping table.
[0019] Optionally, the interception module is further configured to obtain database connection information of the target database; Connect to the target database based on the database connection information.
[0020] Optionally, the interception module is further configured to connect to the target database based on the data source information and the data-driven information.
[0021] Optionally, the query module is further configured to obtain data query results from the target database based on the target query statement; Obtain the data protocol of the original database corresponding to the target terminal; The data query results are encoded and disguised according to the data protocol to generate the target data query results; The target data query results are sent to the target terminal.
[0022] Optionally, the interception module is further configured to obtain the original database connection information of the original database corresponding to the target terminal; Connect to the original database based on the original database connection information; Obtain the data to be migrated from the original database; The data to be migrated is migrated to the target database.
[0023] Optionally, the interception module is further configured to obtain the table structure information of the data to be migrated; Create a data table in the target database based on the table structure information; The data to be migrated is migrated to the target database based on the created data table.
[0024] Optionally, the statement conversion module is further configured to decode the data packet corresponding to the data query request to obtain decoded data; Extract the query statement from the decoded data.
[0025] Furthermore, to achieve the above objectives, the present invention also proposes a data query device, the device comprising: a memory, a processor, and a data query program stored in the memory and executable on the processor, the data query program being configured to implement the steps of the data query method described above.
[0026] In addition, to achieve the above objectives, the present invention also proposes a storage medium storing a data query program, which, when executed by a processor, implements the steps of the data query method described above.
[0027] This invention intercepts data query requests sent from a target terminal to a target database; extracts the query statement from the data query request and converts the query statement into a target query statement recognizable by the target database; retrieves data query results from the target database based on the target query statement, and sends the data query results to the target terminal. Because this invention intercepts data query requests sent from a target terminal to a target database, extracts the query statement from the data query request, converts the query statement into a target query statement recognizable by the target database, and retrieves data query results from the target database based on the target query statement, compared to existing methods that require replacing the query statement in the terminal when replacing the database, the above method of this invention can convert the query statement into a target query statement recognizable by the target database, thus improving the efficiency of database replacement. Attached Figure Description
[0028] Figure 1 This is a schematic diagram of the structure of the data query device in the hardware operating environment involved in the embodiments of the present invention; Figure 2 This is a flowchart illustrating the first embodiment of the data query method of the present invention; Figure 3 This is a flowchart illustrating the second embodiment of the data query method of the present invention; Figure 4 This is a flowchart illustrating the third embodiment of the data query method of the present invention; Figure 5 This is a structural block diagram of the first embodiment of the data query device of the present invention.
[0029] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0030] It should be understood that the specific embodiments described herein are for illustrative purposes only and are not intended to limit the scope of the invention.
[0031] Reference Figure 1 , Figure 1 This is a schematic diagram of the data query device structure in the hardware operating environment involved in the embodiments of the present invention.
[0032] like Figure 1As shown, the data query device may include: a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. The communication bus 1002 is used to enable communication between these components. The user interface 1003 may include a display screen or an input unit such as a keyboard; optionally, the user interface 1003 may also include a standard wired interface or a wireless interface. The network interface 1004 may optionally include a standard wired interface or a wireless interface (such as a Wireless-Fidelity (Wi-Fi) interface). The memory 1005 may be high-speed random access memory (RAM) or stable non-volatile memory (NVM), such as a disk drive. The memory 1005 may also optionally be a storage device independent of the aforementioned processor 1001.
[0033] Those skilled in the art will understand that Figure 1 The structure shown does not constitute a limitation on the data query device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0034] like Figure 1 As shown, the memory 1005, which serves as a storage medium, may include an operating system, a network communication module, a user interface module, and a data query program.
[0035] exist Figure 1 In the data query device shown, the network interface 1004 is mainly used for data communication with the network server; the user interface 1003 is mainly used for data interaction with the user; the processor 1001 and the memory 1005 in the data query device of the present invention can be set in the data query device, and the data query device calls the data query program stored in the memory 1005 through the processor 1001 and executes the data query method provided in the embodiment of the present invention.
[0036] Based on the aforementioned data query device, this embodiment of the invention provides a data query method, referring to... Figure 2 , Figure 2 This is a flowchart illustrating the first embodiment of the data query method of the present invention.
[0037] In this embodiment, the data query method includes the following steps: Step S10: Intercept the data query request sent by the target terminal to the target database.
[0038] It should be noted that the executing entity in this embodiment can be a computing service device with data processing, network communication, and program execution functions, such as a mobile phone, tablet computer, or personal computer, or an electronic device or database replacement agent program capable of performing the above functions. The following description uses the database replacement agent program as an example to illustrate this embodiment and the subsequent embodiments.
[0039] It should be noted that the target terminal can be a system whose database connection needs to be changed. For example, if system A originally connected to a MySQL database and needs to change the connected MySQL database to a domestic database such as Yifangyun or Dameng, then system A can be referred to as the target terminal, and Yifangyun or Dameng can be referred to as the target database. The data query request can be a data query or CRUD (Create, Read, Update, Delete) request containing structured query language sent by the target terminal to the target database.
[0040] Furthermore, to improve the efficiency of database replacement, before step S10, the following steps may be included: obtaining the original database connection information of the original database corresponding to the target terminal; connecting to the original database according to the original database connection information; obtaining the data to be migrated in the original database; and migrating the data to be migrated to the target database.
[0041] It should be noted that the original database can be the database corresponding to the target terminal before the database was changed. The original database connection information can be the information connecting to the original database, including information such as the DataSource and drive classpath in JDBC. The data to be migrated can be all the data in the original database. The process of migrating the data to be migrated to the target database can involve obtaining the table structure information of the data to be migrated; creating a data table in the target database based on the table structure information; and migrating the data to be migrated to the target database based on the created data table.
[0042] It should be noted that the table structure information can be the table information when the data to be migrated is stored in the original database, and the creation of a data table in the target database based on the table structure information can be the creation of the same data table in the target database to store the data to be migrated, with reference to the table structure information.
[0043] Step S20: Extract the query statement from the data query request and convert the query statement into a target query statement that the target database can recognize.
[0044] It should be noted that extracting the query statement from the data query request can be achieved by first decoding the data packet corresponding to the data query request to obtain decoded data, and then extracting the structured query language from the decoded data. Converting the query statement into a target query statement recognizable by the target database can be achieved by finding the target statement in a pre-defined syntax mapping table between the original database and the target database, and then replacing the query statement with the target statement to obtain the target query statement recognizable by the target database. The syntax mapping table can be a pre-set mapping table of structured query languages between the original database and the target database. For example, refer to Tables 1 and 2 below. Table 1 is the syntax mapping table between MySQL and Kingbase databases, and Table 2 is the syntax mapping table between MySQL and DM databases. Table 1 - Syntax Mapping Table between MySQL Database and Kingbase Database
[0045] 046]、
[0046] Table 2 is a syntax mapping table between MySQL database and DM database.
[0047]
[0048]
[0049]
[0050]
[0051] Step S30: Obtain the data query result from the target database according to the target query statement, and send the data query result to the target terminal.
[0052] It should be noted that obtaining the data query result from the target database based on the target query statement can be done by querying the target database based on the target query statement to obtain the data query result corresponding to the target query statement.
[0053] Furthermore, to ensure that the target terminal is unaware of the database replacement, step S30 may include: obtaining data query results from the target database according to the target query statement; obtaining the data protocol of the original database corresponding to the target terminal; encoding and disguising the data query results according to the data protocol to generate target data query results; and sending the target data query results to the target terminal.
[0054] It should be noted that the data protocol can be the data interaction protocol of the original database, and the encoding and disguise of the data query result according to the data protocol can be to encode the data query result according to the data protocol and disguise the data query result as the protocol of the original database and return it to the target terminal.
[0055] This embodiment intercepts data query requests sent from a target terminal to a target database; extracts the query statement from the data query request and converts the query statement into a target query statement recognizable by the target database; retrieves data query results from the target database based on the target query statement, and sends the data query results to the target terminal. Because this embodiment intercepts data query requests sent from a target terminal to a target database; extracts the query statement from the data query request and converts the query statement into a target query statement recognizable by the target database; and retrieves data query results from the target database based on the target query statement, compared to existing methods that require replacing the query statement in the terminal when replacing the database, this embodiment can convert the query statement into a target query statement recognizable by the target database, thus improving the efficiency of database replacement.
[0056] refer to Figure 3 , Figure 3 This is a flowchart illustrating the second embodiment of the data query method of the present invention.
[0057] Based on the first embodiment described above, in this embodiment, step S20 includes: Step S201: Extract the query statement from the data query request.
[0058] It should be noted that the query statement extracted from the data query request can be a structured query language extracted from the data query request.
[0059] Step S202: Determine the statements to be replaced in the query statement that the target database cannot recognize.
[0060] It should be noted that the process of identifying the replacement statements in the query statement that the target database cannot recognize can be achieved by using a database sharding proxy to extract the replacement statements in the query statement that cannot be recognized by the target database.
[0061] Step S203: Perform syntax conversion on the statement to be replaced to convert the query statement into a target query statement that can be recognized by the target database.
[0062] It should be noted that the syntax conversion of the statement to be replaced can be performed by querying the target statement corresponding to the statement to be replaced based on the syntax mapping table, and then replacing the statement to be replaced according to the target statement, so as to convert the query statement into a target query statement that can be recognized by the target database.
[0063] Furthermore, in order to improve the conversion efficiency of query statements and thus improve the efficiency of database replacement, the step of performing syntax conversion on the statement to be replaced includes: obtaining the start position and end position of the statement to be replaced in the query statement; obtaining the target statement corresponding to the statement to be replaced; and performing syntax conversion on the statement to be replaced based on the start position, the end position, and the target statement.
[0064] It should be noted that obtaining the start and end positions of the statement to be replaced in the query statement can be achieved by using a sharding proxy to determine these positions. The target statement corresponding to the statement to be replaced is then used to replace the statement to be replaced based on the start and end positions, resulting in the replaced target query statement. The step of obtaining the target statement corresponding to the statement to be replaced includes: obtaining the original database corresponding to the target terminal; obtaining a statement mapping table between the target database and the original database; and searching for the target statement corresponding to the statement to be replaced based on the statement mapping table. The statement mapping table can refer to the syntax mapping table in the above embodiments.
[0065] In practice, the database replacement agent uses StringBuilder's append method to concatenate statements when replacing the statements to be replaced. Each concatenation point can be set through an SQLToken object. Since the default SQLToken cannot set the concatenation position, it is set through BaseSetStopReplaceToke. BaseSetStopReplaceToke mainly contains the following properties: startIndex (start position), stopIndex (end position), and value (the SQL content to be replaced). When the part to be replaced, i.e., the statement to be replaced, is determined, the start and end positions of the statement to be replaced in the query statement are obtained, and then the entire statement to be replaced is put into the token. See the following implementation code for reference: context.getFunctionReplaceGenerator().addToken(newBaseSetStopReplaceToken(index,indexStopIndex,getTargetSql())); Iterate through the tokens when regenerating the SQL. for (SQLToken each : context.getSqlTokens()) { result.append(getComposableSQLTokenText((ComposableSQLToken) each)); result.append(getConjunctionText(each)); } Statement replacement using substring private String getConjunctionText(final SQLToken sqlToken) { Return context.getSql().substring(getStartIndex(sqlToken),getStopIndex(sqlToken)); } This embodiment extracts the query statement from the data query request; identifies the statements in the query statement that the target database cannot recognize and needs to be replaced; and performs syntax conversion on the statements to be replaced to convert the query statement into a target query statement that the target database can recognize. This embodiment can perform syntax conversion on the statements to be replaced that the target database cannot recognize, convert the query statement into a target query statement that the target database can recognize, and obtain data query results from the target database based on the target query statement, thereby improving the database replacement efficiency when changing databases.
[0066] refer to Figure 4 , Figure 4 This is a flowchart illustrating the third embodiment of the data query method of the present invention.
[0067] Based on the above embodiments, in this embodiment, before step S10, the method further includes: Step S01: Obtain the database connection information of the target database.
[0068] It should be noted that the database connection information includes the JDBC information of the target database required for connecting to the target database, including the target database's data source information and data driver information. The data source information can be the database's DataSource information. The data driver information can be the drive classpath information.
[0069] Step S02: Connect to the target database according to the database connection information.
[0070] It should be noted that connecting to the target database based on the database connection information can be based on the data source information and the data-driven information.
[0071] In practical implementation, the database replacement agent replaces the DataSource and Drive classpaths of the JDBC connection to the database with those of a domestic database based on the ShardingSphere extension point, and modifies the URL and version number resolution. For example, when the original database is a MySQL database and the target database is a DM database, the specific implementation code could be: / / Configure MySQL SQL syntax parsing public DatabaseType getTrunkDatabaseType() { return DatabaseTypeRegistry.getActualDatabaseType("MySQL"); } / / Set the URL header information for parsing the DM database public Collection <string>getJdbcUrlPrefixes() { return Arrays.asList("jdbc:dm:"); } / / Set the JDBC DataSource to the DataSource of DM JDBC public Optional <string>getDataSourceClassName() { return Optional.of("dm.jdbc.driver.DmdbDataSource"); } / / Set the JDBC Driver to the JDBC Driver of DM. public String getDriverClassName() { return "dm.jdbc.driver.DmDriver"; The above modifications enable the parsing of MySQL syntax and the calling of DM's JDBC for SQL queries. The URL parsing part is also modified to identify DM's URL.
[0072] When the original database is a MySQL database and the target database is the Renmin University of China Kingbase database, the specific implementation code can be: / / Configure MySQL SQL syntax parsing public DatabaseType getTrunkDatabaseType() { return DatabaseTypeRegistry.getActualDatabaseType("MySQL"); } / / Set the URL header information for parsing the Renmin University of China's Kingbase database public Collection <string>getJdbcUrlPrefixes() { return Arrays.asList("jdbc:kingbase8:"); } / / Set the JDBC DataSource to the DataSource of DM JDBC public Optional <string>getDataSourceClassName() { return Optional.of("com.kingbase8.ds.KBSimpleDataSource"); } / / Set the JDBC Driver to the JDBC Driver of DM. public String getDriverClassName() { return "com.kingbase8.Driver"; } It should be understood that in order to connect to the target database, it is also necessary to replace the classpaths of XAConnection and XADataSource for connecting to the database with the target database based on the ShardingSphere extension point. For example, when the target database is DM database, the core code for adaptation and modification is as follows: / / Set the JDBC Connection to the DM JDBC Connection. private Class <connection>getJDBCConnectionClass() { return(Class <connection>) Class.forName("dm.jdbc.driver.DmdbConnection"); } / / Set the JDBC XAConnection to the DaMeng JDBC XAConnection private Constructor<?> getXAConnectionConstructor() { Return Class.forName("dm.jdbc.driver.DmdbXAConnection").getConstructor(Class.forName("dm.jdbc.driver.DmdbConnection")); } / / Set the JDBC XADataSource to the DaMeng JDBC XADataSource public Collection <string>getXADriverClassName() { return Collections.singletonList("dm.jdbc.driver.DmdbXADataSource"); } This embodiment obtains the database connection information of the target database, which includes the target database's data source information and data-driven information. The target database is then connected based on the data source information and data-driven information. Furthermore, during database replacement, data query requests to the original database can be forwarded to the target database without modifying the structured query statements in the target terminal, thus improving the efficiency of database replacement.
[0073] Reference Figure 5 , Figure 5 This is a structural block diagram of the first embodiment of the data query device of the present invention.
[0074] like Figure 5 As shown, the data query device proposed in this embodiment of the invention includes: Interception module 10 is used to intercept data query requests sent by the target terminal to the target database; The statement conversion module 20 is used to extract the query statement from the data query request and convert the query statement into a target query statement that the target database can recognize; The query module 30 is used to obtain data query results from the target database according to the target query statement, and send the data query results to the target terminal.
[0075] This embodiment intercepts data query requests sent from a target terminal to a target database; extracts the query statement from the data query request and converts the query statement into a target query statement recognizable by the target database; retrieves data query results from the target database based on the target query statement, and sends the data query results to the target terminal. Because this embodiment intercepts data query requests sent from a target terminal to a target database; extracts the query statement from the data query request and converts the query statement into a target query statement recognizable by the target database; and retrieves data query results from the target database based on the target query statement, compared to existing methods that require replacing the query statement in the terminal when replacing the database, this embodiment can convert the query statement into a target query statement recognizable by the target database, thus improving the efficiency of database replacement.
[0076] It should be noted that the workflow described above is merely illustrative and does not limit the scope of protection of this invention. In practical applications, those skilled in the art can select some or all of the workflow to achieve the purpose of this embodiment according to actual needs, and no restrictions are imposed here.
[0077] In addition, for technical details not described in detail in this embodiment, please refer to the data query method provided in any embodiment of the present invention, which will not be repeated here.
[0078] Based on the first embodiment of the data query device of the present invention described above, a second embodiment of the data query device of the present invention is proposed.
[0079] In this embodiment, the statement conversion module 20 is also used to extract the query statement from the data query request; Identify the statements in the query that the target database cannot recognize and need to be replaced; The statement to be replaced is subjected to syntax transformation to convert the query statement into a target query statement that can be recognized by the target database.
[0080] Furthermore, the statement conversion module 20 is also used to obtain the start and end positions of the statement to be replaced in the query statement; Obtain the target statement corresponding to the statement to be replaced; The statement to be replaced is grammatically transformed based on the start position, the end position, and the target statement.
[0081] Furthermore, the statement conversion module 20 is also used to obtain the original database corresponding to the target terminal; Obtain the statement mapping table between the target database and the original database; The target statement corresponding to the statement to be replaced is found according to the statement mapping table.
[0082] Furthermore, the interception module 10 is also used to obtain the database connection information of the target database; Connect to the target database based on the database connection information.
[0083] Furthermore, the interception module 10 is also used to connect to the target database based on the data source information and the data-driven information.
[0084] Furthermore, the query module 30 is also used to obtain data query results from the target database based on the target query statement; Obtain the data protocol of the original database corresponding to the target terminal; The data query results are encoded and disguised according to the data protocol to generate the target data query results; The target data query results are sent to the target terminal.
[0085] Furthermore, the interception module 10 is also used to obtain the original database connection information of the original database corresponding to the target terminal; Connect to the original database based on the original database connection information; Obtain the data to be migrated from the original database; The data to be migrated is migrated to the target database.
[0086] Furthermore, the interception module 10 is also used to obtain the table structure information of the data to be migrated; Create a data table in the target database based on the table structure information; The data to be migrated is migrated to the target database based on the created data table.
[0087] Furthermore, the statement conversion module 20 is also used to decode the data packet corresponding to the data query request to obtain decoded data; Extract the query statement from the decoded data.
[0088] Other embodiments or specific implementations of the data query device of the present invention can be referred to the above-described method embodiments, and will not be repeated here.
[0089] Furthermore, embodiments of the present invention also propose a storage medium storing a data query program, which, when executed by a processor, implements the steps of the data query method described above.
[0090] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or system. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or system that includes that element.
[0091] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0092] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as read-only memory / random access memory, magnetic disk, optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of the present invention.
[0093] The above are merely preferred embodiments of the present invention and do not limit the scope of the patent. Any equivalent structural or procedural transformations made based on the description and drawings of the present invention, or direct or indirect applications in other related technical fields, are similarly included within the scope of patent protection of the present invention.< / string> < / connection> < / connection> < / string> < / string> < / string> < / string>
Claims
1. A data query method, characterized in that, The data query method includes the following steps: Intercept data query requests sent from the target terminal to the target database; Extract the query statement from the data query request and convert the query statement into a target query statement that the target database can recognize; Retrieve data query results from the target database based on the target query statement; Obtain the data protocol of the original database corresponding to the target terminal; The data query results are encoded and disguised according to the data protocol to generate target data query results, and the target data query results are sent to the target terminal. The step of converting the query statement into a target query statement that the target database can recognize includes: Extract the statements to be replaced from the query statements that the target database cannot recognize using the database sharding and table partitioning tools; Obtain the start and end positions of the statement to be replaced in the query statement; Based on the syntax mapping table between the original database and the target database corresponding to the data query request, query the target statement corresponding to the statement to be replaced; The statement to be replaced is syntactically transformed based on the start position, the end position, and the target statement to obtain a target query statement that can be recognized by the target database.
2. The data query method as described in claim 1, characterized in that, Before the step of intercepting the data query request sent by the target terminal to the target database, the method further includes: Obtain the database connection information of the target database; Connect to the target database based on the database connection information.
3. The data query method as described in claim 2, characterized in that, The database connection information includes the target database's data source information and data-driven information; The step of connecting to the target database based on the database connection information includes: Connect to the target database based on the data source information and the data-driven information.
4. The data query method according to any one of claims 1-3, characterized in that, Before the step of intercepting the data query request sent by the target terminal to the target database, the method further includes: Obtain the original database connection information corresponding to the original database of the target terminal; Connect to the original database based on the original database connection information; Obtain the data to be migrated from the original database; The data to be migrated is migrated to the target database.
5. The data query method as described in claim 4, characterized in that, The step of migrating the data to be migrated to the target database includes: Obtain the table structure information of the data to be migrated; Create a data table in the target database based on the table structure information; The data to be migrated is migrated to the target database based on the created data table.
6. The data query method according to any one of claims 1-3, characterized in that, The step of extracting the query statement from the data query request includes: The data packet corresponding to the data query request is decoded to obtain decoded data; Extract the query statement from the decoded data.
7. A data query device, characterized in that, The data query device includes: The interception module is used to intercept data query requests sent by the target terminal to the target database; The statement conversion module is used to extract the query statement from the data query request and convert the query statement into a target query statement that can be recognized by the target database. The query module is used to obtain data query results from the target database based on the target query statement; Obtain the data protocol of the original database corresponding to the target terminal; The data query results are encoded and disguised according to the data protocol to generate target data query results, and the target data query results are sent to the target terminal. The step of converting the query statement into a target query statement that the target database can recognize includes: Extract the statements to be replaced from the query statements that the target database cannot recognize using the database sharding and table partitioning tools; Obtain the start and end positions of the statement to be replaced in the query statement; Based on the syntax mapping table between the original database and the target database corresponding to the data query request, query the target statement corresponding to the statement to be replaced; The statement to be replaced is syntactically transformed based on the start position, the end position, and the target statement to obtain a target query statement that can be recognized by the target database.
8. The data query device as described in claim 7, characterized in that, The interception module is also used to obtain database connection information of the target database; Connect to the target database based on the database connection information.
9. The data query device according to any one of claims 7-8, characterized in that, The database connection information includes the target database's data source information and data-driven information. The interception module is also used to connect to the target database based on the data source information and the data-driven information.
10. The data query device according to any one of claims 7-8, characterized in that, The interception module is also used to obtain the original database connection information of the original database corresponding to the target terminal; Connect to the original database based on the original database connection information; Obtain the data to be migrated from the original database; The data to be migrated is migrated to the target database.
11. A data query device, characterized in that, The device includes: a memory, a processor, and a data query program stored in the memory and executable on the processor, the data query program being configured to implement the steps of the data query method as described in any one of claims 1 to 6.
12. A storage medium, characterized in that, The storage medium stores a data query program, which, when executed by a processor, implements the steps of the data query method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Data query method and data query device
CN113282610A
Database migration method and device, equipment and readable medium
CN113407514A