Database operation statement generation method and device, electronic equipment and storage medium

CN118820268BActive Publication Date: 2026-10-30FUTU NETWORK TECH (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410793000.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-19
Publication Date
2026-10-30
Estimated Expiration
2044-06-19

AI Technical Summary

Technical Problem

[0003]本公开实施例提供一种方案,以解决相关技术中,在编写数据库操作语句时,一般基于人工编写这些SQL函数相关的代码,这些SQL函数相关的代码较多且复杂,消耗时间较长,编写SQL函数相关的代码的效率较低的问题

Benefits of technology

[0019]本公开提供的技术方案,获取数据库对应的查询条件结构体;解析所述查询条件结构体,得到所述查询条件结构体的结构体字段和结构体标签;基于所述结构体字段和所述结构体标签,构建与所述查询条件结构体对应的条件对象;基于所述条件对象生成数据库操作语句,所述数据库操作语句用于对所述数据库中的待操作数据进行相应的操作。本公开各实施例提供的技术方案,无需人工编写数据库操作语句相关的代码,而是通过解析获取的数据库对应的查询条件结构体,可以得到结构体字段和结构体标签,进而构建出条件对象,并通过条件对象生成数据库操作语句,大大节省了编写数据库操作语句的时间,提高了编写SQL函数相关的代码的效率。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118820268B_ABST
    Figure CN118820268B_ABST
Patent Text Reader

Abstract

The present disclosure discloses a database operation statement generation method and device, electronic equipment and storage medium. The method comprises: obtaining a query condition structure body corresponding to a database; parsing the query condition structure body to obtain a structure body field and a structure body label of the query condition structure body; constructing a condition object corresponding to the query condition structure body based on the structure body field and the structure body label; and generating a database operation statement based on the condition object, the database operation statement being used for performing corresponding operations on to-be-operated data in the database. The technical scheme provided by the present disclosure does not require manual writing of a database operation statement, greatly saves time, and improves the efficiency of writing code related to the database operation statement.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure belongs to the field of information processing technology, and in particular relates to a method, apparatus, electronic device and storage medium for generating database operation statements. Background Technology

[0002] In database development, it is often necessary to perform data operations such as adding, deleting, modifying, and querying data in the database. In such cases, it is necessary to write SQL (Structured Query Language) functions corresponding to the data operations. In related technologies, these SQL function-related codes are generally written manually. This code is often extensive and complex, time-consuming, and inefficient. Summary of the Invention

[0003] This disclosure provides a solution to address the problem in the related art where, when writing database operation statements, the code related to these SQL functions is generally written manually, which is often extensive, complex, and time-consuming, resulting in low efficiency in writing such code.

[0004] Firstly, this disclosure provides a method for generating database operation statements, the method comprising:

[0005] Retrieve the query condition structure corresponding to the database;

[0006] Parse the query condition structure to obtain the structure fields and structure tags of the query condition structure;

[0007] Based on the structure fields and the structure tags, construct a condition object corresponding to the query condition structure;

[0008] Database operation statements are generated based on the condition object, and these statements are used to perform corresponding operations on the data to be operated on in the database.

[0009] Secondly, this disclosure provides a database operation statement generation apparatus, the apparatus comprising:

[0010] The retrieval unit is used to retrieve the query condition structure corresponding to the database.

[0011] The parsing unit is used to parse the query condition structure to obtain the structure fields and structure tags of the query condition structure.

[0012] A construction unit is used to construct a condition object corresponding to the query condition structure based on the structure fields and the structure tags;

[0013] The generation unit is used to generate database operation statements based on the condition object, and the database operation statements are used to perform corresponding operations on the data to be operated on in the database.

[0014] Thirdly, this disclosure provides an electronic device, including:

[0015] Processor; and

[0016] Memory for storing the executable instructions of the processor;

[0017] The processor is configured to execute the first aspect or any method in a possible implementation of the first aspect by executing the executable instructions.

[0018] Fourthly, embodiments of this disclosure provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the methods in the first aspect or any possible implementations of the first aspect.

[0019] The technical solution provided in this disclosure involves obtaining a query condition structure corresponding to a database; parsing the query condition structure to obtain its structure fields and structure tags; constructing a condition object corresponding to the query condition structure based on the structure fields and structure tags; and generating database operation statements based on the condition objects. These database operation statements are used to perform corresponding operations on the data to be operated on in the database. The technical solutions provided in the embodiments of this disclosure eliminate the need for manually writing database operation statement code. Instead, by parsing the obtained query condition structure corresponding to the database, structure fields and structure tags can be obtained, and a condition object can be constructed. Database operation statements are then generated from the condition object, significantly saving time in writing database operation statements and improving the efficiency of writing SQL function-related code. Attached Figure Description

[0020] To more clearly illustrate the technical solutions in the embodiments or related technologies of this disclosure, the accompanying drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. In the drawings:

[0021] Figure 1 This is a flowchart illustrating a database operation statement generation method according to an embodiment of the present disclosure.

[0022] Figure 2 This is a schematic diagram of the structure of a database operation statement generation device provided in an embodiment of the present disclosure;

[0023] Figure 3 This is a schematic diagram of the structure of an electronic device provided in one embodiment of the present disclosure. Detailed Implementation

[0024] Embodiments of this disclosure are described in detail below, with examples of embodiments illustrated in the accompanying drawings. The embodiments described below with reference to the accompanying drawings are exemplary and intended to explain this disclosure, and should not be construed as limiting this disclosure.

[0025] The terms "first" and "second," etc., used in the specification, claims, and drawings of this disclosure are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that embodiments of the present disclosure described herein can be implemented, for example, in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0026] The database operation statement generation method provided in this disclosure can run on a terminal device or a server. The terminal device can be a local terminal device. The server can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms.

[0027] In database development, it's frequently necessary to perform data operations such as adding, deleting, modifying, and querying data within the database. This requires writing corresponding SQL (Structured Query Language) functions. Currently, these SQL function codes are typically written manually, which is lengthy, complex, and time-consuming, resulting in low efficiency.

[0028] Taking the application of this database operation statement generation method to a server as an example, when a user wants to construct a specific database operation statement, the corresponding query condition structure can be obtained from the database. This query condition structure is then parsed to obtain its structure fields and tags. Subsequently, the corresponding condition object is constructed using these structure fields and tags. Finally, the database operation statement is generated from the condition object. This process eliminates the need for manual writing of the corresponding database operation statements, significantly saving time and improving the efficiency of writing database operation statements.

[0029] The technical solutions of this disclosure and how they solve the aforementioned technical problems will be described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of this disclosure will now be described with reference to the accompanying drawings.

[0030] Figure 1 This is a flowchart illustrating a database operation statement generation method provided as an exemplary embodiment of the present disclosure. This method is applicable to various devices with data processing capabilities. Taking the application of this method to a server as an example, the solution includes at least the following steps S101-S104:

[0031] S101, retrieve the query condition structure corresponding to the database.

[0032] In some embodiments, the query condition structure is a structure in the Go language, which is used to define the conditions for querying or modifying data; that is, the query condition structure is used to define how to operate the database.

[0033] Specifically, the query condition structure can include multiple structure fields and structure tags. By assigning values ​​to different structure fields and structure tags, the query condition structure can be parsed to generate database operation statements, such as query statements, based on the field values ​​of the structure fields and the tag values ​​of the structure tags, so as to query data or perform operations on data in the database.

[0034] Specifically, the system can receive the query condition structure defined by the user object through a visual interface, as well as the assignment information of the user object to this query condition structure. The query condition structure and its assignment information are then used as the final query condition structure. By defining the query condition structure, subsequent query operations with the same query conditions but different corresponding condition values ​​only require modifying the assignment information of the query condition structure to quickly generate the corresponding database operation statement, such as the query statement, thus improving data query efficiency.

[0035] S102, parse the query condition structure to obtain the structure fields and structure tags of the query condition structure.

[0036] Specifically, to better understand struct fields and struct tags, the following lists relevant struct tags and struct fields:

[0037] Structure fields are used to indicate the names of the fields that are being manipulated in the database. In other words, structure fields define which fields in the database are being queried.

[0038] Structure tags can include operator tags, condition control tags, and database field name tags. Structure tags are used to indicate what kind of conditional query should be performed on the field name indicated by the structure field.

[0039] The operator label `op` refers to the operator that controls the `where` clause. Common operators include: =, ! =, `in`, `not in`, >, <, >=, <=, between, like, like%x, like x%, like%x% etc. In some embodiments, the default operator is either `in` or `=`.

[0040] The condition control tag `type` indicates whether a field name is used as a query condition in a query operation. In some embodiments, common condition control tags include `ignore`, `normal`, and `all`. Specifically, `ignore` means ignoring the field, i.e., not using it as a query condition; `normal` means using the field as a query condition when it is not null, and not using it when it is null; `all` means using it as a query condition in all cases.

[0041] The `column` tag in the database field name field specification indicates the query field in the conditional query. When the `column` tag is empty, the default query field is a structure field from the query structure. When the `column` tag is not empty, the value of the `column` tag is used as the query field. For example, if the `column` tag is "name", it means that the field name "name" is the query field, and the query will search for data that matches the query conditions under the field name "name".

[0042] In some embodiments, to accommodate different query operations, the query condition structure also includes an operation type definition field, used to define different query operations to be performed based on the query condition structure. For example, the operation type definition field includes Page, GroupBy, OrderBy, Columns, and Wherees, etc.; where:

[0043] Page represents a structure type used to indicate the pagination query operation based on the query condition structure. The Page structure includes PageNum and PageSize, which are used to represent the pagination parameters of the pagination query.

[0044] GroupBy is used to instruct the execution of a grouped query operation based on the query condition structure;

[0045] OrderBy is used to instruct a sorting operation to be performed based on the query condition structure;

[0046] Columns are used to indicate the query fields used for querying based on the query condition structure;

[0047] The WHERE clause is used to indicate the query conditions based on the query condition structure.

[0048] In some embodiments, after obtaining the query condition structure corresponding to the database, the method further includes steps S11-S12:

[0049] S11, Obtain the structural condition function corresponding to the query condition structure.

[0050] S12, call the structure condition function, modify the query condition structure through the structure condition function, and generate a new query condition structure.

[0051] In some embodiments, to ensure that the obtained query condition structure meets the user's needs, structure condition functions can be used to assign or modify the structure fields or structure tags in the query condition structure. This allows for the creation or updating of the query condition structure, thereby enabling rapid modification of the corresponding database operation statements and improving data query efficiency. Specifically, by calling the corresponding structure condition function, the structure fields and / or structure tags in the query condition structure can be modified to obtain a new query condition structure.

[0052] For example, if the original structure field is "name: Xiaoming", after calling the corresponding structure condition function, the structure field is modified to "name: Xiaoliu", and the modified query condition structure containing the structure field "name: Xiaoliu" becomes the new query condition structure.

[0053] In some embodiments, parsing the query condition structure to obtain the structure fields and structure tags of the query condition structure includes: parsing the new query condition structure to obtain the structure fields and structure tags of the new query condition structure.

[0054] S103, Based on the structure fields and the structure tags, construct a condition object corresponding to the query condition structure.

[0055] In some embodiments, the structure tag includes at least one of the following tags: operator tag, condition control tag, and database field name tag.

[0056] Here, a condition object refers to an object obtained by converting a query condition structure, which is used to construct the database operation statement corresponding to the query condition structure. In some embodiments, the condition object includes a condition attribute field and an operation type field. The condition attribute field is used to record condition operation information, such as the condition operator, the name of the database field on which the condition operator acts, and the condition value corresponding to the condition operator. The operation type field is used to record some special operation type related information, such as pagination query operation, grouping query operation, sorting operation, and other condition operation information.

[0057] For example, a condition object includes two attribute fields: the condition attribute field conArr and the operation type field typeCond.

[0058] The conditional attribute field conArr is an array of conditional operation structures, which includes three fields: op, field, and value.

[0059] Specifically, the op field is used to indicate the type of conditional operator in the conditional expression, which may include, but is not limited to: =, ! =, in, not int, >, >=, <, <=, and other conditional operators.

[0060] The Field field is used to indicate the name of the database field on which the conditional operator is applied, indicating which field in the database the condition is evaluated on.

[0061] The Value field is used to indicate the condition value corresponding to the conditional operator, representing the value of the condition evaluation.

[0062] The `TypeCond` field defines several special operation types, including but not limited to `Page`, `GroupBy`, `OrderBy`, `Columns`, and `Wheres` fields. Understandably, when the `TypeCond` field has a value, the corresponding function in `gorm` will be called to construct the SQL statement based on the information in the `TypeCond` field.

[0063] Specifically, the Page field can be a structure that indicates the execution of a pagination query operation, including the pageNum and pageSize fields, which represent the parameters of the pagination query, respectively. For example, if the Page field of the condition object is "pageNum:10,pageSize=100", calling the corresponding function of gorm can construct the SQL statement based on the condition object as: limt100,(10-1)*100.

[0064] The GroupBy field can be an array of strings used to indicate the grouping operation to be performed; for example, if the condition object includes a GroupBy field of: ["id", "name"], it is used to indicate grouping according to the values ​​of the "id" field and the "name" field. Calling the corresponding function in gorm can construct the SQL statement: "group by id,name".

[0065] The OrderBy field can be a string that indicates the sorting operation to be performed. For example, if the value of the OrderBy field is ["id","name"], it indicates that the sorting should be performed according to the values ​​of the "id" and "name" fields. The corresponding function in gorm will be called, and the SQL statement "order by id,name" can be constructed based on this condition object.

[0066] The Columns field is a string array used to indicate the conditional query operation to be performed; for example, the field value of the Columns field is ["id", "name"], which indicates that the fields "id" and "name" are used as condition fields for the query, and the corresponding function of gorm is called. Based on this condition object, the SQL statement can be constructed as: "Select id,name".

[0067] The Wheres field is a string that indicates the conditional query operation to be performed. For example, if the value of the Wheres field is: id>=100 or id<10, then after calling gorm, the concatenated SQL condition statement will be "and(id>=100 or id<10)".

[0068] The WHERE clause is a keyword in SQL conditional statements used to filter and refine query results. Using the WHERE clause, you can specify one or more conditions to filter data in a table, returning only rows that meet the conditions. The WHERE clause is typically placed after the SELECT clause to facilitate filtering and refining the query results.

[0069] The condition object can implement the construction of most sub-statements and control statements corresponding to query conditions in database operation statements through the field condition attribute field and the operation type field. Specifically, the structure field, structure tag and operation type definition field in the query condition structure can be obtained. Further, the valid target structure field is determined from the structure fields according to the database field name tag, and the operator tag and condition control tag corresponding to the target structure field are obtained, so as to generate the condition attribute field based on the target structure field and the operator tag corresponding to the target structure field. Meanwhile, the operation type field is generated according to the operation type definition field, and finally the condition object is constructed according to the condition attribute field and the operation type field.

[0070] To better understand the present solution, a specific embodiment is provided below, wherein the query condition structure is {Namestring`orm:"op:="`}, which indicates that the structure field is Name, the structure field Name is of the string type, and the structure tag is "op:=", which indicates that the condition operator is "=". When the condition structure is assigned the value "Xiao Ming", after parsing the query condition structure to obtain the structure field and the structure tag, the condition object "Op:=, Field:Name, Value:Xiao Ming" can be constructed.

[0071] Further, the condition object also provides a series of condition adding functions, such as AddEqual, AddNotEqual, AddBetween, AddIn, AddNotIn, AddGT, AddLT, AddGTE, AddLTE, AddLike, AddLeftLike, AddRightLike, AddAllLike, AddPage, AddColumn, etc. After obtaining the structure field and the structure tag of the query condition structure, the condition adding function can be called to convert the condition attribute field and the operation type field, so as to construct the condition object.

[0072] To better understand the present solution, a specific embodiment is provided as follows:

[0073] If the determined structure fields are "name" and "Xiao Ming", and the structure tag is the operator tag op, and the operator tag op includes the operator "=", the condition attribute field can be generated based on the structure fields and the structure tag, specifically "name='Xiao Ming'", and then by calling the AddEqual function, the constructed condition object is AddEqual("Name", "Xiao Ming").

[0074] In some embodiments, after constructing the condition object corresponding to the query condition structure based on the structure field and the structure tag, the method further includes steps S21-S22:

[0075] S21, acquiring an object condition function corresponding to the condition object.

[0076] S22, invoking the object condition function, modifying the condition parameter of the condition object through the object condition function, and generating a new condition object.

[0077] In some embodiments, generating a database operation statement based on the condition object includes: generating the database operation statement based on the new condition object.

[0078] Specifically, in order to ensure that the query condition object meets the user's requirements, after constructing a query condition object of "name = 'Xiaoming'", if the query condition object does not meet the user's requirements, the query condition object may be modified, which requires invoking the object condition function corresponding to the condition object to modify the value in the query condition object, for example, modifying "=" to "!=", so as to obtain a new query condition object "name != 'Xiaoming'".

[0079] S104, generating a database operation statement based on the condition object.

[0080] After the condition object is acquired, the condition attribute field and the operation type field in the condition object may be traversed, and the database operation statement is constructed based on the condition attribute field and the operation type field in the condition object.

[0081] Specifically, when performing database-related operations, the condition attribute field and the operation type field are traversed, and the database operation function statement of the gorm component is invoked, so as to finally construct a database operation statement (SQL condition statement). Still taking the condition attribute field "Op:=, Field: Name, Value: Xiaoming" as an example, the invocable add condition function AddEqual based on the condition object is called to construct the condition object AddEqual("Name", "Xiaoming"), and then the database operation statement is generated based on the condition object and the database operation function statement: select name from tableA where name = "Xiaoming".

[0082] Wherein, the database operation statement is configured to perform a corresponding operation on to-be-operated data in the database.

[0083] In some embodiments, the database operation function statement includes any one of the following: an add function statement, a delete function statement, an update function statement, and a query function statement.

[0084] In some embodiments, before obtaining the query condition structure corresponding to the database, the method further includes steps S31-S32:

[0085] S31, Obtain the database model structure and database connection of the database.

[0086] In some embodiments, the database model structure refers to a data type used in programming to describe the structure of a data table. In relational databases, a data table typically consists of multiple fields, each with its own data type and constraints. To facilitate operations on the data table, users can define a structure to describe its structure, including information such as table name, field names, data types, and constraints.

[0087] Specifically, the database model structure is the model structure of the underlying component gorm. The structure field names of the model structure represent the column names of the database, the type of the structure field represents the column type of the database, and there are also some labels that represent specific definitions of the database, such as primary key labels, index labels, etc.

[0088] In some embodiments, a database operation object refers to an object used in a program to manipulate the database. It is typically a class or structure that encapsulates functions such as database connection, transaction management, and SQL execution. Database operation objects can be used to perform various database operations, such as querying, inserting, updating, and deleting.

[0089] Specifically, the database connection refers to the actual database instance connected to when manipulating the database.

[0090] S32, Create a database operation object for the database based on the database model structure and the database connection.

[0091] In some embodiments, when performing data operations on the database, such as query operations, a database model structure can be defined in advance. Subsequently, this database model structure only needs to be passed to the API methods provided by gorm; there is no need to write SQL conditional statements. gorm will automatically parse this database model structure and generate the corresponding SQL conditional statements, thereby realizing the database operation. This method is suitable for non-transactional operations.

[0092] The process of parsing the database model structure can be found in the process of parsing the query condition structure described above, and will not be repeated here.

[0093] In some embodiments, the database model structure and the database connection are suitable for transaction operations.

[0094] A transaction operation refers to a group of database operations that are treated as a single logical unit, either all of which succeed or all fail and are rolled back.

[0095] In some embodiments, generating database operation statements based on the condition object includes:

[0096] The database operation object of the database is invoked, and the database operation object generates database operation statements based on the condition object and the database operation function statements encapsulated in the database operation object.

[0097] In some embodiments, the step of calling the database operation object generates a database operation statement based on the condition object and the database operation function statement encapsulated by the database operation object, including steps S41-S42:

[0098] S41, determine the multiple operation structures contained in the condition object.

[0099] S42, call the database operation object of the database, and generate database operation statements through the database operation object based on the multiple operation structures and the database operation function statements encapsulated by the database operation object.

[0100] In some embodiments, the database operation function statement is a wrapper around the gorm database operation function. For example, `create` simply calls the gorm `create` function, except that the parameters of the `create` function are determined based on a condition object. To better understand this solution, the following are examples of database operation functions for querying data in the gorm component:

[0101] The Get function is used to query data; the parameters in the Get function include: cond, ret, and err.

[0102] Here, cond is a condition object used to indicate the condition information when performing a conditional query.

[0103] `ret` is a structure pointer used to indicate the returned data, which can be used to retrieve the data obtained from the query.

[0104] err is the return value used to check for errors.

[0105] In some embodiments, the database operation functions further include: insert function, update function, and delete function.

[0106] The above embodiments will be further explained below with reference to specific application scenarios. Specifically, a query condition structure can be pre-constructed, as shown below:

[0107] Typeuserstruct{

[0108] IDint64'orm:"op:="'

[0109] name string'orm:"op:!="'

[0110] age[]int64'orm:"op:between"'

[0111] birthday string'orm:"type:ignore"'

[0112] name[]string'orm:"columns:name"'

[0113] Column}

[0114] Furthermore, based on this conditional structure, the structure is assigned values ​​as follows:

[0115] user:=User{

[0116] ID:1

[0117] name: "Xiao Ming"

[0118] age:[]int64{18,20}

[0119] birthday: "2024-6-1"

[0120] name:[]string{“Xiaoming”,”Zhang San”}

[0121] Column:Column{"ID","name"}}

[0122] The query condition structure indicates that the structure fields include ID, name, age, sex, birthday, etc., the structure tags include operator tags op: "=", "between", "!=", etc., as well as a condition control tag "ignore", which indicates that the birthday field is not used as a condition, and the operation type definition field includes "Column"; after parsing the query condition structure to obtain the structure fields and structure tags, the condition attribute fields "Op:=, Field:ID, Value:1", "Op:!=, Field:name, Value:Xiao Ming", "Op:between, Field:age, Value:{18,20}", and the operation type field "Column{"ID","name"}" can be constructed; further, based on the condition attribute fields and the operation type field, the database operation object of the database is invoked, and the database operation statement is generated by the database operation object according to the condition object and the encapsulated database operation function statement of the database operation object; taking the condition attribute field "Op:=, Field:ID, Value:1" in the above condition object as an example, the AddEqual function can be invoked based on the condition object to construct the condition object: AddEqual("ID","1"), and then the gorm component function orm.NewQueryCond().AddEqual("ID","4") is invoked to construct the database operation statement. Taking the condition attribute field "Op:!=, Field:name, Value:Xiao Ming" in the above condition object as another example, the AddNotEqual function can be invoked based on the condition object to construct the condition object: AddNotEqual("Name","Xiao Ming"); then, the gorm component function orm.NewQueryCond().AddNotEqual("Name","Xiao Ming") is invoked to construct the database operation statement.

[0123] It can be understood that the database operation statement that can be constructed based on the above query condition structure is specifically as follows:

[0124] Select ID, name from user where ID = 1 and name != Xiao Ming and age >= 18 and age <= 18 and name in ("Xiao Ming", "Zhang San").

[0125] The technical solution provided in this disclosure involves obtaining a query condition structure corresponding to a database; parsing the query condition structure to obtain its structure fields and structure tags; constructing a condition object corresponding to the query condition structure based on the structure fields and structure tags; and generating database operation statements based on the condition objects. These database operation statements are used to perform corresponding operations on the data to be operated on in the database. The technical solutions provided in the embodiments of this disclosure eliminate the need for manually writing database operation statement code. Instead, by parsing the obtained query condition structure corresponding to the database, structure fields and structure tags can be obtained, and a condition object can be constructed. Database operation statements are then generated from the condition object, significantly saving time in writing database operation statements and improving the efficiency of writing SQL function-related code.

[0126] Figure 2 A schematic diagram of the structure of a database operation statement generation apparatus provided as an exemplary embodiment of this disclosure;

[0127] The device includes: an acquisition unit 201, a parsing unit 202, a construction unit 203, and a generation unit 204;

[0128] The acquisition unit 201 is used to acquire the query condition structure corresponding to the database.

[0129] Parsing unit 202 is used to parse the query condition structure to obtain the structure fields and structure tags of the query condition structure;

[0130] Construction unit 203 is used to construct a condition object corresponding to the query condition structure based on the structure fields and the structure tags;

[0131] The generation unit 204 is used to generate database operation statements based on the condition object, and the database operation statements are used to perform corresponding operations on the data to be operated on in the database.

[0132] In some embodiments, before obtaining the query condition structure corresponding to the database, the apparatus is further configured to:

[0133] Obtain the database model structure and database connection of the database;

[0134] The database operation object of the database is created based on the database model structure and the database connection;

[0135] In some embodiments, the apparatus for generating database operation statements based on the condition object is further configured to:

[0136] The database operation object of the database is invoked, and the database operation object generates database operation statements based on the condition object and the database operation function statements encapsulated in the database operation object.

[0137] In some embodiments, after constructing a condition object corresponding to the query condition structure based on the structure fields and the structure tags, the apparatus is further configured to:

[0138] Retrieve the object condition function corresponding to the condition object;

[0139] Call the object condition function to modify the condition parameters of the condition object and generate a new condition object;

[0140] Generating database operation statements based on the condition object includes: generating database operation statements based on the new condition object.

[0141] In some embodiments, after obtaining the query condition structure corresponding to the database, the apparatus is further configured to:

[0142] Obtain the structure condition function corresponding to the query condition structure;

[0143] The structure condition function is called to modify the query condition structure and generate a new query condition structure.

[0144] Parsing the query condition structure to obtain the structure fields and structure tags of the query condition structure includes: parsing the new query condition structure to obtain the structure fields and structure tags of the new query condition structure.

[0145] In some embodiments, the database operation function statements include any one of the following: add function statements, delete function statements, modify function statements, and query function statements.

[0146] In some embodiments, the database operation object that invokes the database generates a database operation statement based on the condition object and the database operation function statement encapsulated by the database operation object. The device is further configured to:

[0147] Determine the multiple operational structures contained in the condition object;

[0148] The database operation object generates database operation statements based on the multiple operation structures and the database operation function statements encapsulated within the database operation object.

[0149] In some embodiments, the structure tag includes at least one of the following tags: operator tag, condition control tag, and database field name tag.

[0150] The technical solution provided in this disclosure involves obtaining a query condition structure corresponding to a database; parsing the query condition structure to obtain its structure fields and structure tags; constructing a condition object corresponding to the query condition structure based on the structure fields and structure tags; and generating database operation statements based on the condition objects. These database operation statements are used to perform corresponding operations on the data to be operated on in the database. The technical solutions provided in the embodiments of this disclosure eliminate the need for manually writing database operation statement code. Instead, by parsing the obtained query condition structure corresponding to the database, structure fields and structure tags can be obtained, and a condition object can be constructed. Database operation statements are then generated from the condition object, significantly saving time in writing database operation statements and improving the efficiency of writing SQL function-related code.

[0151] It should be understood that the device embodiments and method embodiments can correspond to each other, and similar descriptions can be referred to the method embodiments. To avoid repetition, they will not be repeated here. Specifically, the device can execute the above method embodiments, and the foregoing and other operations and / or functions of each module in the device correspond to the corresponding processes in the various methods in the above method embodiments, which will not be repeated here for the sake of brevity.

[0152] The apparatus of this disclosure embodiment has been described above from the perspective of functional modules in conjunction with the accompanying drawings. It should be understood that this functional module can be implemented in hardware, in software instructions, or in a combination of hardware and software modules. Specifically, the steps of the method embodiments in this disclosure can be completed by integrated logic circuits in the processor's hardware and / or by software instructions. The steps of the method disclosed in this disclosure embodiment can be directly embodied as being executed by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. Optionally, the software module can reside in a mature storage medium in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. This storage medium is located in memory, and the processor reads information from the memory and, in conjunction with its hardware, completes the steps in the above method embodiments.

[0153] Figure 3 This is a schematic block diagram of an electronic device provided in an embodiment of this disclosure. The electronic device may include:

[0154] The system includes a memory 301 for storing computer programs and a processor 302 for transferring program code to the processor 302. In other words, the processor 302 can retrieve and run the computer program from the memory 301 to implement the methods described in this embodiment.

[0155] For example, the processor 302 can be used to execute the above-described method embodiments according to instructions in the computer program.

[0156] In some embodiments of this disclosure, the processor 302 may include, but is not limited to:

[0157] General-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.

[0158] In some embodiments of this disclosure, the memory 301 includes, but is not limited to:

[0159] Volatile memory and / or non-volatile memory. Non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDR SDRAM), Enhanced Synchronous DRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), and Direct Rambus RAM (DR RAM).

[0160] In some embodiments of this disclosure, the computer program may be divided into one or more modules, which are stored in the memory 301 and executed by the processor 302 to perform the method provided in this disclosure. The one or more modules may be a series of computer program instruction segments capable of performing a specific function, which describe the execution process of the computer program in the electronic device.

[0161] like Figure 3 As shown, the electronic device may further include:

[0162] Transceiver 303, which can be connected to processor 302 or memory 301.

[0163] The processor 302 can control the transceiver 303 to communicate with other devices; specifically, it can send information or data to other devices or receive information or data sent by other devices. The transceiver 303 may include a transmitter and a receiver. The transceiver 303 may further include antennas, and the number of antennas may be one or more.

[0164] It should be understood that the various components in the electronic device are connected through a bus system, which includes a data bus, a power bus, a control bus, and a status signal bus.

[0165] This disclosure also provides a computer storage medium storing a computer program thereon, which, when executed by a computer, enables the computer to perform the methods of the above-described method embodiments. Alternatively, embodiments of this disclosure also provide a computer program product containing instructions that, when executed by a computer, cause the computer to perform the methods of the above-described method embodiments.

[0166] When implemented using software, it can be implemented wholly or partially as a computer program product. This computer program product includes one or more computer instructions. When these computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this disclosure are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., digital video disc (DVD)), or a semiconductor medium (e.g., solid-state disk (SSD)).

[0167] Those skilled in the art will recognize that the modules and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this disclosure.

[0168] In the embodiments provided in this disclosure, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple modules or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or modules may be electrical, mechanical, or other forms.

[0169] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. For example, the functional modules in the various embodiments of this disclosure may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.

[0170] The above are merely specific embodiments of this disclosure, but the scope of protection of this disclosure is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this disclosure should be included within the scope of protection of this disclosure. Therefore, the scope of protection of this disclosure should be determined by the scope of the claims.

Claims

1. A method for generating database operation statements, characterized in that, The method includes: Retrieve the query condition structure corresponding to the database; Parse the query condition structure to obtain the structure fields and structure tags of the query condition structure; Based on the structure fields and the structure tags, construct a condition object corresponding to the query condition structure; Database operation statements are generated based on the condition object, and the database operation statements are used to perform corresponding operations on the data to be operated on in the database. Before obtaining the query condition structure corresponding to the database, the method further includes: Obtain the database model structure and database connection of the database; The database operation object of the database is created based on the database model structure and the database connection; The generation of database operation statements based on the condition object includes: The database operation object of the database is invoked, and the database operation object generates a database operation statement based on the condition object and the database operation function statement encapsulated by the database operation object. After constructing a condition object corresponding to the query condition structure based on the structure fields and the structure tags, the method further includes: Retrieve the object condition function corresponding to the condition object; Call the object condition function to modify the condition parameters of the condition object and generate a new condition object; Generating database operation statements based on the condition object includes: generating database operation statements based on the new condition object; After obtaining the query condition structure corresponding to the database, the method further includes: Obtain the structure condition function corresponding to the query condition structure; The structure condition function is called to modify the query condition structure and generate a new query condition structure. Parsing the query condition structure to obtain the structure fields and structure tags of the query condition structure includes: parsing the new query condition structure to obtain the structure fields and structure tags of the new query condition structure.

2. The method according to claim 1, characterized in that, The database operation object that invokes the database generates database operation statements based on the condition object and the database operation function statements encapsulated within the database operation object, including: Determine the multiple operational structures contained in the condition object; The database operation object generates database operation statements based on the multiple operation structures and the database operation function statements encapsulated within the database operation object.

3. The method according to claim 1, characterized in that, The database operation function statements include any of the following: add function statement, delete function statement, modify function statement, and query function statement.

4. The method according to claim 1, characterized in that, The structure tags include at least one of the following tags: operator tags, condition control tags, and database field name tags.

5. A database operation statement generation device, characterized in that, The apparatus for implementing the method as described in any one of claims 1-4 includes: The retrieval unit is used to retrieve the query condition structure corresponding to the database. The parsing unit is used to parse the query condition structure to obtain the structure fields and structure tags of the query condition structure. A construction unit is used to construct a condition object corresponding to the query condition structure based on the structure fields and the structure tags; The generation unit is used to generate database operation statements based on the condition object, and the database operation statements are used to perform corresponding operations on the data to be operated on in the database.

6. An electronic device, characterized in that, include: processor; as well as Memory for storing the executable instructions of the processor; The processor is configured to execute the method of any one of claims 1-4 by executing the executable instructions.

7. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method described in any one of claims 1-4.

Citation Information

Patent Citations

  • Method and configuration for generating query condition in annotation way

    CN103020064A

  • System and method for managing presentation of query results

    US20070143245A1