Database sequence acquisition method and device, storage medium and electronic equipment

By caching database sequence values ​​in the database driver and returning them in sequence, the performance problems caused by frequent interactions with the database by customer systems are solved, and higher system throughput and processing efficiency are achieved.

CN119829648APending Publication Date: 2025-04-15JINZHUAN INFORMATION TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411903939.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-23
Publication Date
2025-04-15

AI Technical Summary

Technical Problem

The customer system frequently interacts with the database when acquiring the database sequence, resulting in low system throughput and long processing time.

Method used

Reduce frequent interactions with the database by building SQL query statements.

Benefits of technology

The caching mechanism reduces the number of interactions between the client and the database, reduces network latency, and improves the system throughput and the processing efficiency of a single service.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119829648A_ABST
    Figure CN119829648A_ABST
Patent Text Reader

Abstract

The invention relates to a database sequence obtaining method and device, a storage medium and electronic equipment. The method comprises the following steps: receiving a query request for querying a sequence value of a target sequence of a database issued by a client; constructing a first SQL query statement according to the query request; the first SQL query statement is sent to a database, so that the database executes the first SQL query statement and returns a first sequence value set, and the first sequence value set comprises M sequence values, starting from the first sequence value, of the target sequence; and caching the first sequence value set, returning the first sequence value in the first sequence value set to the client, and returning each sequence value in the first sequence value set to the client in sequence under the condition that a query request is received every time until all sequence values in the first sequence value set are returned. The technical problems of low system throughput and long processing time consumption caused by frequent interaction with the database when the client system obtains the database sequence are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of database technology, and in particular to a method, device, storage medium and electronic device for obtaining a database sequence. Background Art

[0002] In many traditional legacy systems, the business code of the client system usually relies on the sequence in the database to ensure the uniqueness of the field content. In this system design, the business code generates a unique identifier through the database sequence mechanism to ensure the consistency and integrity of the data when performing insert or update operations. The specific implementation method is usually: the system first obtains a sequence value, then splices the sequence value into the SQL statement of the database, and performs the corresponding operation through the database. However, when processing large quantities of business data, since it is necessary to interact with the database every time to obtain a new sequence value, frequent database access will lead to limited system throughput and significantly increase the time for single business processing. This design has a certain negative impact on performance and response speed, especially in scenarios with huge data volume and frequent operations, the bottleneck of the database is more obvious, limiting the overall processing efficiency of the system. Summary of the invention

[0003] The present application provides a method, device, storage medium and electronic device for obtaining a database sequence, so as to solve the technical problem that when a client system obtains a database sequence, it frequently interacts with the database, resulting in low system throughput and long processing time.

[0004] In a first aspect, the present application provides a method for obtaining a database sequence, which is applied to a database driver, comprising: receiving a query request for a sequence value of a target sequence of a database issued by a client; constructing a first SQL query statement according to the query request, wherein the first SQL query statement is used to query M sequence values ​​of the target sequence starting from the first sequence value, and the M is a positive integer; sending the first SQL query statement to the database, so that the database executes the first SQL query statement and returns a first sequence value set, wherein the first sequence value set includes the M sequence values ​​of the target sequence starting from the first sequence value; caching the first sequence value set, returning the first sequence value in the first sequence value set to the client, and returning each sequence value in the first sequence value set to the client in sequence each time the query request is received until all sequence values ​​in the first sequence value set are returned.

[0005] In a second aspect, the present application provides a database sequence acquisition device, which is applied to database driving, including: a receiving module, which is used to receive a query request for a sequence value of a target sequence of a database issued by a client; a building module, which is used to build a first SQL query statement according to the above query request, wherein the above first SQL query statement is used to query M sequence values ​​of the above target sequence starting from the first sequence value, and the above M is a positive integer; a first sending module, which is used to send the above first SQL query statement to the above database, so that the above database executes the above first SQL query statement and returns a first sequence value set, wherein the above first sequence value set includes M sequence values ​​of the above target sequence starting from the first sequence value; a second sending module, which is used to cache the above first sequence value set, return the first sequence value in the above first sequence value set to the above client, and return each sequence value in the above first sequence value set to the above client in sequence each time the above query request is received, until all sequence values ​​in the above first sequence value set are returned.

[0006] As an optional example, the above-mentioned device also includes: a partitioning module, which is used to partition a shared memory area from the memory before receiving a query request for the sequence value of the target sequence of the query database sent by the client, wherein the above-mentioned shared memory area is used to store the sequence value set returned by the above-mentioned database.

[0007] As an optional example, the second sending module includes: a first sending unit, used to return the Nth sequence value in the first sequence value set to the client when the query request is received for the Nth time, wherein N is a positive integer greater than 1 and less than or equal to M.

[0008] As an optional example, the above-mentioned device also includes: a third sending module, which is used to obtain a new first sequence value set from the above-mentioned database again when the above-mentioned query request is received for the M+1th time after all sequence values ​​in the above-mentioned first sequence value set are returned, and return each sequence value in the above-mentioned new first sequence value set to the above-mentioned client in sequence each time the above-mentioned query request is received until all sequence values ​​of the above-mentioned target sequence are returned.

[0009] As an optional example, the third sending module includes: a construction unit, configured to construct a second SQL query statement when receiving the query request for the M+1th time, wherein the second SQL query statement is used to query the P sequence values ​​of the target sequence after the target sequence value, and the target sequence value is the last sequence value in the first sequence value set, wherein P is a positive integer; a second sending unit, configured to send the second SQL query statement to the database, so that the database executes the second SQL query statement and returns a second sequence value set, wherein the second sequence value set includes the P sequence values ​​of the target sequence after the target sequence value; and a cache unit, configured to cache the second sequence value set.

[0010] As an optional example, the third sending module includes: a third sending unit, used to return the QMth sequence value in the second sequence value set to the client when the query request is received for the Qth time, wherein Q is a positive integer greater than M and less than or equal to P.

[0011] As an optional example, the above-mentioned device also includes: a determination module, which is used to determine whether the above-mentioned database is available after receiving a query request for the sequence value of the target sequence of the query database sent by the client; a fourth sending module, which is used to return a prompt message when it is determined that the above-mentioned database is not available, wherein the above-mentioned prompt message is used to prompt the above-mentioned client that the above-mentioned database is unavailable.

[0012] In a third aspect, the present application provides a storage medium storing a computer program, wherein the computer program executes the above-mentioned method for obtaining the database sequence when executed by a processor.

[0013] In a fourth aspect, the present application further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute the above-mentioned method for acquiring a database sequence through the computer program.

[0014] The above technical solution provided by the embodiment of the present application has the following advantages compared with the prior art:

[0015] The present application adopts a method of receiving a query request for a sequence value of a target sequence of a query database issued by a client; constructing a first SQL query statement according to the query request, wherein the first SQL query statement is used to query M sequence values ​​of the target sequence starting from the first sequence value, and the M is a positive integer; sending the first SQL query statement to the database, so that the database executes the first SQL query statement and returns a first sequence value set, wherein the first sequence value set includes M sequence values ​​of the target sequence starting from the first sequence value; caching the first sequence value set, returning the first sequence value in the first sequence value set to the client, and returning each sequence value in the first sequence value set to the client in sequence each time the query request is received until all sequence values ​​in the first sequence value set are returned. In the method, the client sends a query request to the database through a database driver, and the database driver constructs an SQL query statement according to the request, queries the database and returns a batch of continuous sequence values, caches these sequence values, and then returns them to the application in sequence until all sequence values ​​in the cache are used up. This achieves the goal of reducing the frequent interactions between the client and the database through the caching mechanism, reducing network latency, and improving the throughput of the client system and the processing efficiency of a single business, thereby solving the technical problem of low system throughput and long processing time caused by frequent interactions between the client system and the database when obtaining database sequences. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0017] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0018] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.

[0019] Figure 1 is a flowchart of an optional method for obtaining a database sequence according to an embodiment of the present application;

[0020] Figure 2is a schematic structural diagram of an optional database sequence acquisition device according to an embodiment of the present application;

[0021] Figure 3 is a schematic diagram of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0022] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0023] The disclosure below provides many different embodiments or examples to realize the different structures of the present application. In order to simplify the disclosure of the present application, the parts and settings of specific examples are described below. Of course, they are only examples, and the purpose is not to limit the present application. In addition, the present application can repeat reference numbers and / or letters in different examples. This repetition is for the purpose of simplification and clarity, and does not itself indicate the relationship between the various embodiments and / or settings discussed.

[0024] According to a first aspect of an embodiment of the present application, a method for obtaining a database sequence is provided, which is applied to a database driver, and optionally, Figure 1 As shown, the above method includes:

[0025] S102, receiving a query request for querying a sequence value of a target sequence in a database sent by a client;

[0026] S104, constructing a first SQL query statement according to the query request, wherein the first SQL query statement is used to query M sequence values ​​of the target sequence starting from the first sequence value, where M is a positive integer;

[0027] S106, sending the first SQL query statement to the database, so that the database executes the first SQL query statement and returns a first sequence value set, wherein the first sequence value set includes M sequence values ​​of the target sequence starting from the first sequence value;

[0028] S108, cache the first sequence value set, return the first sequence value in the first sequence value set to the client, and return each sequence value in the first sequence value set to the client in order each time a query request is received until all sequence values ​​in the first sequence value set are returned.

[0029] Optionally, in this embodiment, a sequence value is quickly obtained through a database driver. Specifically, a client (i.e., a business application) sends a query request to a database through a database driver, the goal of which is to obtain the value of a sequence of a specific database. The request includes the name of the target sequence and the number of sequence values ​​required. For example, a client may request to obtain 100 values ​​of seq_user_id. According to the received query request, the database driver constructs an SQL query statement (a first SQL query statement) for querying the M consecutive sequence values ​​of the target sequence starting from the first position, where M is a positive integer representing the number of sequences requested by the client. The database driver sends the constructed first SQL query statement to the database through a hint method. The database executes the query and returns the requested M sequence values. The returned sequence values ​​are sequentially increasing, starting from the first sequence of the target sequence. The database driver caches the M sequence values ​​returned by the database into memory for subsequent requests, thereby reducing frequent interactions with the database and improving performance. The database driver takes the first sequence value in the sequence value set from the cache and returns it to the client. The client can use this sequence value for business operations (for example, as a primary key when inserting data into the database). Whenever the client initiates a new query request, the database driver will continue to return the next sequence value in sequence from the cache until all sequence values ​​in the cache are used up. The client does not need to initiate a new sequence query request to the database every time. When all sequence values ​​in the cache have been returned to the client, the database driver will query the database again to obtain multiple new sequence values ​​and update the cache.

[0030] Optionally, in this embodiment, the frequency of business applications querying the database for sequence values ​​each time is reduced through a database-driven caching mechanism. Business applications can reuse the sequence values ​​in the cache multiple times, avoiding interaction with the database for each request, and significantly reducing the burden on the database. Due to the reduction in the number of database interactions, the throughput of the business system is improved. When processing large quantities of data, frequent database queries may become a bottleneck, and the caching mechanism can avoid this problem and improve the processing capacity of the overall system. Business operations (such as data insertion or updating) no longer need to query the sequence every time, so they can be executed more quickly, greatly shortening the processing time of a single business and improving the efficiency of the overall system. The caching mechanism of sequence values ​​can handle multiple client requests, adapt to high-concurrency application scenarios, avoid frequent database access, and thus improve the processing capacity of the system in a high-concurrency environment.

[0031] As an optional example, before receiving a query request for querying a sequence value of a target sequence in a database from a client, the method further includes:

[0032] A shared memory area is divided from the memory, where the shared memory area is used to store a sequence value set returned by the database.

[0033] Optionally, in this embodiment, the database driver divides a specific memory area from the memory as a shared memory area, and this shared memory area is specifically used to store the sequence value set returned by the database. A shared memory area is a memory area that can be accessed by multiple processes or threads. In a multi-process or multi-threaded environment, multiple client programs can access and read this shared memory area at the same time to ensure efficient data sharing and communication. When the database executes a query request and returns multiple sequence values, these sequence values ​​are cached in the shared memory area. For example, the client requests 100 sequence values. When the database returns these 100 sequence values, the database driver will store them in the shared memory area at one time. The shared memory area can store multiple sequence sets according to the system design, allocate space on demand, and ensure that each request can obtain the required sequence value in time. When the client needs a new sequence value, it no longer directly requests the database, but reads the cached sequence value from the shared memory area. Each time the client obtains a sequence value, the database driver will return the sequence value from the shared memory area in order until the cached value is exhausted.

[0034] As an optional example, in the case where a query request is received each time, returning each sequence value in the first sequence value set to the client in order includes:

[0035] When the query request is received for the Nth time, the Nth sequence value in the first sequence value set is returned to the client, where N is a positive integer greater than 1 and less than or equal to M.

[0036] Optionally, in this embodiment, whenever the client initiates a query request to the database driver, the database driver first checks the cached sequence value set (i.e., the sequence value set previously obtained and cached from the database). If there is already a sequence value in the cache, the driver returns the corresponding sequence value from the cache in order. Assuming that the database returns M sequence values ​​in the first query and caches them in the shared memory area, the structure of the sequence value set may be an array or list from seq_1 to seq_M. For the Nth (N is a positive integer greater than 1 and less than or equal to M) query request received, the database driver will return the Nth sequence value in the cache. For example: the first request returns the first sequence value in the cache; the second request returns the second sequence value in the cache; the third request returns the third sequence value in the cache, and so on. The database driver returns each sequence value one by one in the order in the cache, ensuring that the sequence values ​​returned by each query request are in increasing order, avoiding duplication or loss of sequence values. When a client requests multiple sequence values ​​(for example, when inserting data in batches), a different sequence value is returned for each query, ensuring the uniqueness and continuity of the data.

[0037] Optionally, in this embodiment, by caching and providing sequence values ​​in order, it is avoided that each query must wait for the response of the database, thereby improving the response speed, and the client can quickly obtain a unique, sequentially increasing sequence value for data insertion or update.

[0038] As an optional example, after all sequence values ​​in the first sequence value set are returned, the method further includes:

[0039] When a query request is received for the M+1th time, a new set of first sequence values ​​is obtained from the database again, and each time a query request is received, each sequence value in the new set of first sequence values ​​is returned to the client in order until all sequence values ​​of the target sequence are returned.

[0040] Optionally, in this embodiment, assuming that the database returns M sequence values ​​and caches them in the shared memory area during the initial query, when all these M sequence values ​​have been returned to the client, the sequence values ​​in the cache will be exhausted. In this case, the database driver layer will detect that the cache is empty and prepare to re-acquire a new set of sequence values ​​through the database. The driver layer will initiate a new query request and request a new batch of sequence values ​​from the database. For example, at the time of the M+1 query request, the database driver constructs a new SQL query statement and requests the database to obtain the next batch of M sequence values ​​of the target sequence. The database executes the SQL query and returns a new set of sequence values, and the database driver caches these values ​​in the shared memory area. After receiving the new set of sequence values, the database driver will return each sequence value in the new cache to the client in order. Assuming that the database returns M new sequence values ​​(such as seq_101 to seq_200), the database driver will return these sequence values ​​to the client in sequence. When the client continues to initiate query requests, the new sequence values ​​returned will be the values ​​in these new caches until the new sequence values ​​are exhausted. This process is cyclic: whenever the sequence values ​​in the cache are used up, the database driver will send a query request to the database again to obtain a new set of sequence values, and continue to return them to the client in order. This ensures that the system can continue to provide sequence values ​​to the client in the long run without frequent access to the database, and only needs to obtain a new set of sequence values ​​on demand.

[0041] Optionally, in this embodiment, after all sequence values ​​in the cache are returned, the system can continue to obtain new sequence values ​​from the database to ensure the continuity of the sequence, and the business process will not be interrupted due to the exhaustion of the cache. Even when the sequence value cache is exhausted, the database driver will query the database in batches to avoid triggering a single query operation of the database for each request. This method of obtaining sequence values ​​in batches still reduces the number of interactions with the database and reduces the burden on the database.

[0042] As an optional example, when a query request is received for the M+1th time, obtaining a new first sequence value set from the database again includes:

[0043] In the case where the query request is received for the M+1th time, a second SQL query statement is constructed, wherein the second SQL query statement is used to query P sequence values ​​of the target sequence after the target sequence value, the target sequence value is the last sequence value in the first sequence value set, wherein P is a positive integer;

[0044] Sending a second SQL query statement to a database, so that the database executes the second SQL query statement and returns a second sequence value set, wherein the second sequence value set includes P sequence values ​​of the target sequence after the target sequence value;

[0045] A second set of sequence values ​​is cached.

[0046] Optionally, in this embodiment, when the M+1th query request arrives, the database driver checks whether the sequence value in the current cache has been used up. If there is no sequence value in the cache, the database driver will initiate a new query to the database to obtain the subsequent sequence value of the target sequence. The database driver constructs a second SQL query statement, the purpose of which is to obtain the P sequence values ​​after the target sequence value. Specifically: the target sequence value is the last sequence value in the first sequence value set, that is, the end value of the previous batch of sequence value sets. P is a positive integer, which represents the number of sequence values ​​to be obtained after the target sequence value. For example, P=100 means that the database driver will query the 100 sequence values ​​immediately following the target sequence value from the database. The database driver sends the constructed second SQL query statement to the database, and the database executes the query statement to return the P sequence values ​​of the target sequence starting from the current end sequence value (the last sequence value in the first sequence value set). The second sequence value set returned by the database includes P new sequence values ​​of the target sequence, and the database driver caches these new sequence values ​​in the shared memory area. The database driver then continues to return each sequence value in the second sequence value set to the client in order until these sequence values ​​are completely consumed.

[0047] As an optional example, in the case where a query request is received each time, returning each sequence value in the new first sequence value set to the client in order includes:

[0048] When the query request is received for the Qth time, the QMth sequence value in the second sequence value set is returned to the client, where Q is a positive integer greater than M and less than or equal to P.

[0049] Optionally, in this embodiment, each time a query request is received, the database driver first checks the current sequence cache. If the sequence value in the cache is obtained from the second sequence value set, the database driver will continue to return the sequence value in sequence from the cache. Assume that the database driver has obtained the second sequence value set from the database and cached these values. The second sequence value set contains P sequence values ​​after the target sequence value. For example, the values ​​of the second sequence value set may be seq_101, seq_102, ..., seq_200. Assume that the current query request is the Qth, where Q is a positive integer, and Q>M, and Q<=P (that is, the range of Q is within the valid range of the second sequence value set). At this time, the database driver will select and return the corresponding sequence value from the second sequence value set according to the value of Q. Specifically, the driver will return the QMth sequence value in the second sequence value set in the Qth query request. For example, assuming Q=150 and M=100, the data driver will return the 50th sequence value (that is, seq_150) from the second sequence value set. The (QM) here is to ensure that the corresponding sequence values ​​are correctly retrieved from the second sequence value set. M is the size of the sequence value set returned from the database for the first time. When Q>M, the second query request needs to return the sequence values ​​in sequence starting from the second sequence value set. Therefore, by calculating QM, the corresponding sequence value position in the second sequence value set can be determined. Until all sequence values ​​in the second sequence value set are returned to the client in sequence, the database driver will continue to provide the next sequence value from the cache until the batch of sequence values ​​is exhausted. If all sequence values ​​in the second sequence value set have been returned, the database driver will continue the process by requesting a new sequence value set from the database again.

[0050] As an optional example, after receiving a query request for querying a sequence value of a target sequence in a database from a client, the method further includes:

[0051] Determine whether the database is available;

[0052] When it is determined that the database is unavailable, a prompt message is returned, wherein the prompt message is used to prompt the client that the database is unavailable.

[0053] Optionally, in this embodiment, when the client sends a query request to the database driver, the database driver will first parse the request content to confirm that the request target is a specific sequence and prepare to obtain the relevant sequence value from the database. After receiving the query request, the database driver needs to check whether the database is in an available state. If the database is found to be unavailable during the check (such as network failure, database crash or connection problem, etc.), the database driver will immediately return a prompt message indicating that the database is unavailable and prompting the client to continue processing the request. Once it is determined that the database is unavailable, the database driver will return the prompt message to the client application through the network. After receiving the message, the client can take appropriate measures according to the prompt. By returning a clear error prompt message when the database is unavailable, the system can promptly feedback to the client when a fault occurs, avoiding the client from entering a deadlock or long waiting state, and ensuring the availability and reliability of the system.

[0054] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.

[0055] According to another aspect of the embodiment of the present application, a device for obtaining a database sequence is also provided, which is applied to a database driver, such as Figure 2 As shown, including:

[0056] A receiving module 202 is used to receive a query request for a sequence value of a target sequence in a database sent by a client;

[0057] A construction module 204 is used to construct a first SQL query statement according to the query request, wherein the first SQL query statement is used to query M sequence values ​​starting from the first sequence value of the target sequence, where M is a positive integer;

[0058] A first sending module 206 is used to send a first SQL query statement to a database, so that the database executes the first SQL query statement and returns a first sequence value set, wherein the first sequence value set includes M sequence values ​​of the target sequence starting from the first sequence value;

[0059] The second sending module 208 is used to cache the first sequence value set, return the first sequence value in the first sequence value set to the client, and return each sequence value in the first sequence value set to the client in order each time a query request is received until all sequence values ​​in the first sequence value set are returned.

[0060] It should be noted that the receiving module 202 in this embodiment can be used to execute step S102 in the embodiment of the present application, the building module 204 in this embodiment can be used to execute step S104 in the embodiment of the present application, the first sending module 206 in this embodiment can be used to execute step S106 in the embodiment of the present application, and the second sending module 208 in this embodiment can be used to execute step S108 in the embodiment of the present application.

[0061] As an optional example, the above device further includes:

[0062] The partitioning module is used to partition a shared memory area from the memory before receiving a query request for a sequence value of a target sequence in a database sent by a client, wherein the shared memory area is used to store a sequence value set returned by the database.

[0063] As an optional example, the second sending module includes:

[0064] The first sending unit is used to return the Nth sequence value in the first sequence value set to the client when receiving the query request for the Nth time, where N is a positive integer greater than 1 and less than or equal to M.

[0065] As an optional example, the above device further includes:

[0066] The third sending module is used to obtain a new first sequence value set from the database again when a query request is received for the M+1th time after all sequence values ​​in the first sequence value set are returned, and return each sequence value in the new first sequence value set to the client in sequence each time a query request is received until all sequence values ​​of the target sequence are returned.

[0067] As an optional example, the third sending module includes:

[0068] a construction unit, configured to construct a second SQL query statement when receiving the query request for the M+1th time, wherein the second SQL query statement is used to query P sequence values ​​of the target sequence after the target sequence value, the target sequence value being the last sequence value in the first sequence value set, wherein P is a positive integer;

[0069] a second sending unit, configured to send a second SQL query statement to a database, so that the database executes the second SQL query statement and returns a second sequence value set, wherein the second sequence value set includes P sequence values ​​of the target sequence after the target sequence value;

[0070] The cache unit is used to cache the second sequence value set.

[0071] As an optional example, the third sending module includes:

[0072] The third sending unit is used to return the QMth sequence value in the second sequence value set to the client when receiving the query request for the Qth time, where Q is a positive integer greater than M and less than or equal to P.

[0073] As an optional example, the above device further includes:

[0074] A determination module, configured to determine whether a database is available after receiving a query request for a sequence value of a target sequence in a database sent by a client;

[0075] The fourth sending module is used to return a prompt message when it is determined that the database is unavailable, wherein the prompt message is used to prompt the client that the database is unavailable.

[0076] For other examples of this embodiment, please refer to the above examples and will not be repeated here.

[0077] Figure 3 is a schematic diagram of an optional electronic device according to an embodiment of the present application, such as Figure 3 As shown, it includes a processor 302, a communication interface 304, a memory 306 and a communication bus 308, wherein the processor 302, the communication interface 304 and the memory 306 communicate with each other through the communication bus 308, wherein,

[0078] Memory 306, used for storing computer programs;

[0079] The processor 302 is used to implement the following steps when executing the computer program stored in the memory 306:

[0080] Receive a query request from a client for a sequence value of a target sequence in a database;

[0081] According to the query request, a first SQL query statement is constructed, wherein the first SQL query statement is used to query M sequence values ​​of the target sequence starting from the first sequence value, where M is a positive integer;

[0082] Sending a first SQL query statement to a database, so that the database executes the first SQL query statement and returns a first sequence value set, wherein the first sequence value set includes M sequence values ​​of the target sequence starting from the first sequence value;

[0083] The first sequence value set is cached, the first sequence value in the first sequence value set is returned to the client, and each time a query request is received, each sequence value in the first sequence value set is returned to the client in order until all sequence values ​​in the first sequence value set are returned.

[0084] Optionally, in this embodiment, the communication bus may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3 The communication interface is used for communication between the above electronic device and other devices.

[0085] The memory may include RAM, or may include non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0086] As an example, the memory 306 may include, but is not limited to, the receiving module 202, the building module 204, the first sending module 206, and the second sending module 208 in the device for acquiring the database sequence. In addition, other module units in the device for acquiring the database sequence may also be included but are not limited to, which will not be described in detail in this example.

[0087] The above-mentioned processor can be a general-purpose processor, which can include but not be limited to: CPU (Central Processing Unit), NP (Network Processor), etc.; it can also be DSP (Digital Signal Processing), ASIC (Application Specific Integrated Circuit), FPGA (Field-Programmable Gate Array) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0088] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, and this embodiment will not be described in detail here.

[0089] It can be understood by those skilled in the art that Figure 3 The structure shown is for illustration only. The device for implementing the above-mentioned method for obtaining the database sequence may be a terminal device, which may be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a PDA, a mobile Internet device (Mobile Internet Devices, MID), a PAD, and other terminal devices. Figure 3 The structure of the electronic device is not limited. For example, the electronic device may also include Figure 3 More or fewer components (such as network interfaces, display devices, etc.) shown in, or having Figure 3 Different configurations shown.

[0090] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device through a program, and the program can be stored in a computer-readable storage medium, which can include: a flash drive, ROM, RAM, a magnetic disk or an optical disk, etc.

[0091] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program executes the steps in the above-mentioned method for obtaining a database sequence when executed by a processor.

[0092] Optionally, in this embodiment, a person of ordinary skill in the art may understand that all or part of the steps in the various methods of the above embodiments may be completed by instructing hardware related to the terminal device through a program, and the program may be stored in a computer-readable storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc.

[0093] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0094] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling one or more computer devices (which may be personal computers, servers, or network devices, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application.

[0095] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

[0096] In the several embodiments provided in the present application, it should be understood that the disclosed client can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0097] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0098] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0099] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A method for obtaining a database sequence, characterized in that: Applicable to database drivers, including: Receive a query request from a client for a sequence value of a target sequence in a database; Constructing a first SQL query statement according to the query request, wherein the first SQL query statement is used to query M sequence values ​​of the target sequence starting from the first sequence value, where M is a positive integer; Sending the first SQL query statement to the database, so that the database executes the first SQL query statement and returns a first sequence value set, wherein the first sequence value set includes M sequence values ​​of the target sequence starting from the first sequence value; The first sequence value set is cached, a leading sequence value in the first sequence value set is returned to the client, and each time the query request is received, each sequence value in the first sequence value set is returned to the client in order until all sequence values ​​in the first sequence value set are returned.

2. The method according to claim 1, characterized in that Before receiving a query request for querying a sequence value of a target sequence in a database sent by a client, the method further includes: A shared memory area is divided from the memory, wherein the shared memory area is used to store the sequence value set returned by the database.

3. The method according to claim 1, characterized in that: The returning each sequence value in the first sequence value set to the client in order each time the query request is received comprises: When the query request is received for the Nth time, the Nth sequence value in the first sequence value set is returned to the client, where N is a positive integer greater than 1 and less than or equal to M.

4. The method according to claim 3, characterized in that After all sequence values ​​in the first sequence value set are returned, the method further includes: When the query request is received for the M+1th time, a new first sequence value set is obtained from the database again, and each time the query request is received, each sequence value in the new first sequence value set is returned to the client in sequence until all sequence values ​​of the target sequence are returned.

5. The method according to claim 4, characterized in that When the query request is received for the M+1th time, obtaining a new first sequence value set from the database again includes: In the case where the query request is received for the M+1th time, a second SQL query statement is constructed, wherein the second SQL query statement is used to query P sequence values ​​of the target sequence after the target sequence value, the target sequence value being the last sequence value in the first sequence value set, wherein P is a positive integer; Sending the second SQL query statement to the database, so that the database executes the second SQL query statement and returns a second sequence value set, wherein the second sequence value set includes P sequence values ​​of the target sequence after the target sequence value; The second set of sequence values ​​is cached.

6. The method according to claim 5, characterized in that The returning each sequence value in the new first sequence value set to the client in order each time the query request is received comprises: When the query request is received for the Qth time, the QMth sequence value in the second sequence value set is returned to the client, where Q is a positive integer greater than M and less than or equal to P.

7. The method according to claim 1, characterized in that After receiving a query request for querying a sequence value of a target sequence in a database sent by a client, the method further includes: determining whether the database is available; In the case where it is determined that the database is unavailable, a prompt message is returned, wherein the prompt message is used to prompt the client that the database is unavailable.

8. A device for acquiring a database sequence, characterized in that: Applicable to database drivers, including: A receiving module, used to receive a query request for a sequence value of a target sequence in a database sent by a client; A construction module, configured to construct a first SQL query statement according to the query request, wherein the first SQL query statement is used to query M sequence values ​​of the target sequence starting from the first sequence value, where M is a positive integer; A first sending module, configured to send the first SQL query statement to the database, so that the database executes the first SQL query statement and returns a first sequence value set, wherein the first sequence value set includes M sequence values ​​of the target sequence starting from the first sequence value; A second sending module is used to cache the first sequence value set, return the first sequence value in the first sequence value set to the client, and return each sequence value in the first sequence value set to the client in order each time the query request is received until all sequence values ​​in the first sequence value set are returned.

9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is executed.

10. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to execute the method according to any one of claims 1 to 7 through the computer program.