[go: up one dir, main page]

CN112015831A - Method, device and equipment for operating relational database based on C language - Google Patents

Method, device and equipment for operating relational database based on C language Download PDF

Info

Publication number
CN112015831A
CN112015831A CN202010943481.5A CN202010943481A CN112015831A CN 112015831 A CN112015831 A CN 112015831A CN 202010943481 A CN202010943481 A CN 202010943481A CN 112015831 A CN112015831 A CN 112015831A
Authority
CN
China
Prior art keywords
language
data structure
operation instruction
language data
relational database
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010943481.5A
Other languages
Chinese (zh)
Inventor
张清森
陈俊灵
李方明
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Green Connection Technology Co ltd
Ugreen Group Ltd
Original Assignee
Shenzhen Green Connection Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Green Connection Technology Co ltd filed Critical Shenzhen Green Connection Technology Co ltd
Priority to CN202010943481.5A priority Critical patent/CN112015831A/en
Publication of CN112015831A publication Critical patent/CN112015831A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/20Software design

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Software Systems (AREA)
  • Mathematical Physics (AREA)
  • Computational Linguistics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the invention provides a method, a device and equipment for operating a relational database based on C language. The method comprises the following steps: creating a database table of a relational database and a corresponding C language data structure body; determining a mapping structure between the database table and the C language data structure, and adding the mapping structure into the C language data structure; acquiring an operation instruction of a user, and calling a preset operation interface according to the operation instruction; generating an SQL statement according to a Structured Query Language (SQL) grammar rule and the operation instruction through the preset operation interface; and performing corresponding operation processing on the relational database according to the SQL statement. According to the method provided by the embodiment of the invention, the mapping structure body between the database table and the C language data structure body and the preset operation interface are adopted, so that the operation is simplified, and the workload is reduced.

Description

基于C语言对关系型数据库进行操作的方法、装置及设备Method, device and device for operating relational database based on C language

技术领域technical field

本发明涉及数据库技术领域,具体涉及一种基于C语言对关系型数据库进行操作的方法、装置及设备。The invention relates to the technical field of databases, in particular to a method, device and device for operating a relational database based on C language.

背景技术Background technique

关系型数据库是指采用了关系模型来组织数据的数据库,其以行和列的形式存储数据,以便于用户理解。通常采用结构化查询语言(Structured Query Language,简称:SQL)对关系型数据库进行增加、删除、修改和查询等操作。A relational database refers to a database that uses a relational model to organize data, storing data in the form of rows and columns for easy understanding by users. Usually, a Structured Query Language (SQL) is used to perform operations such as adding, deleting, modifying, and querying a relational database.

以小型轻量级的SQLite数据库为例,基于C语言对其进行的任何操作均需编写相应的SQL语句来实现,甚至于对操作结果也需要编写相应的函数和数据结构来处理和输出。这种方式不仅操作繁琐,而且会大幅增加工作人员的工作量。Taking a small and lightweight SQLite database as an example, any operation on it based on C language needs to be implemented by writing corresponding SQL statements, and even corresponding functions and data structures need to be written for processing and outputting the operation results. This method is not only cumbersome to operate, but also greatly increases the workload of the staff.

由于C语言既不是面向对象语言,也不是动态语言,针对现有基于C语言实现的关系型数据库的操作方法中操作繁琐、工作量大的问题,目前尚未提出有效的解决方案。Since C language is neither an object-oriented language nor a dynamic language, there is no effective solution to the problems of cumbersome operation and heavy workload in the existing operation method of relational database based on C language.

发明内容SUMMARY OF THE INVENTION

本发明实施例提供一种基于C语言对关系型数据库进行操作的方法、装置及设备,用以解决现有基于C语言实现的关系型数据库的操作方法操作繁琐、工作量大的问题。Embodiments of the present invention provide a method, device and device for operating a relational database based on C language, so as to solve the problems of complicated operation and heavy workload of the existing operating method of relational database implemented based on C language.

第一方面,本发明实施例提供一种基于C语言对关系型数据库进行操作的方法,包括:In a first aspect, an embodiment of the present invention provides a method for operating a relational database based on the C language, including:

创建关系型数据库的数据库表和对应的C语言数据结构体;Create database tables of relational databases and corresponding C language data structures;

确定所述数据库表和所述C语言数据结构体之间的映射结构体,并将所述映射结构体加入所述C语言数据结构体;Determine the mapping structure between the database table and the C language data structure, and add the mapping structure to the C language data structure;

获取用户的操作指令,并根据所述操作指令调用预设操作接口;Obtain the user's operation instruction, and call the preset operation interface according to the operation instruction;

通过所述预设操作接口,根据结构化查询语言SQL语法规则和所述操作指令生成SQL语句;Through the preset operation interface, the SQL statement is generated according to the structured query language SQL grammar rules and the operation instruction;

根据所述SQL语句对所述关系型数据库进行相应的操作处理。Corresponding operation processing is performed on the relational database according to the SQL statement.

一种实施例中,所述确定所述数据库表和所述C语言数据结构体之间的映射结构体,包括:In an embodiment, the determining the mapping structure between the database table and the C language data structure includes:

确定所述数据库表中表字段和所述C语言数据结构体中成员字段之间的对应关系;Determine the correspondence between the table field in the database table and the member field in the C language data structure;

根据预设规则计算所述C语言数据结构体中各成员字段的内存地址;Calculate the memory address of each member field in the C language data structure according to the preset rule;

将所述对应关系和所述内存地址存储至所述映射结构体。storing the correspondence and the memory address in the mapping structure.

一种实施例中,所述根据结构化查询语言SQL语法规则和所述操作指令生成SQL语句,包括:In an embodiment, the generating an SQL statement according to the structured query language SQL grammar rules and the operation instruction includes:

根据所述操作指令中的操作标识确定所述SQL语句的操作类型;Determine the operation type of the SQL statement according to the operation identifier in the operation instruction;

根据所述映射结构体将所述操作指令中的C语言数据结构体对象转化为数据库表中的数据对象;Convert the C language data structure object in the operation instruction into a data object in the database table according to the mapping structure;

将所述数据对象作为所述SQL语句的参数。Use the data object as a parameter of the SQL statement.

一种实施例中,所述根据所述映射结构体将所述操作指令中的C语言数据结构体对象转化为数据库表中的数据对象,包括:In one embodiment, converting the C language data structure object in the operation instruction into the data object in the database table according to the mapping structure includes:

根据所述操作指令中的C语言数据结构体对象中各成员字段的内存地址,获取所述操作指令中的C语言数据结构体对象中各成员字段;According to the memory address of each member field in the C language data structure object in the described operation instruction, obtain each member field in the C language data structure object in the described operation instruction;

根据所述数据库表中表字段和所述C语言数据结构体中成员字段之间的对应关系,确定所述操作指令中的C语言数据结构体对象中各成员字段所对应的数据库表中的表字段;According to the correspondence between the table fields in the database table and the member fields in the C language data structure, determine the table in the database table corresponding to each member field in the C language data structure object in the operation instruction field;

根据数据类型,将所述操作指令中的C语言数据结构体对象中各数据成员转换为对应的数据库表中的表字段数据。According to the data type, each data member in the C language data structure object in the operation instruction is converted into table field data in the corresponding database table.

一种实施例中,若所述操作指令中的操作标识指示的操作为增加操作、删除操作或者修改操作时,则所述方法还包括返回操作执行结果状态;In one embodiment, if the operation indicated by the operation identifier in the operation instruction is an addition operation, a deletion operation or a modification operation, the method further includes returning the operation execution result status;

若所述操作指令中的操作标识指示的操作为查询操作时,则所述方法还包括:If the operation indicated by the operation identifier in the operation instruction is a query operation, the method further includes:

根据生成的SQL语句从所述关系型数据库中获取查询结果数据;Obtain query result data from the relational database according to the generated SQL statement;

根据所述映射结构体将所述查询结果数据转化为所述C语言数据结构体中的数据。The query result data is converted into data in the C language data structure according to the mapping structure.

一种实施例中,所述根据所述映射结构体将所述查询结果数据转化为所述C语言数据结构体中的数据,包括:In an embodiment, converting the query result data into data in the C language data structure according to the mapping structure includes:

根据所述数据库表中表字段和所述C语言数据结构体中成员字段之间的对应关系,确定所述查询结果数据中各表字段所对应的C语言数据结构体中的成员字段;According to the correspondence between the table fields in the database table and the member fields in the C language data structure, determine the member fields in the C language data structure corresponding to each table field in the query result data;

根据各表字段和所对应的成员字段的数据类型,进行数值转换;Perform numerical conversion according to the data type of each table field and the corresponding member field;

根据所述C语言数据结构体中各成员字段的内存地址,将数值转换后的查询结果数据存入相应的成员字段中。According to the memory address of each member field in the C language data structure, the query result data after the numerical conversion is stored in the corresponding member field.

一种实施例中,所述根据结构化查询语言SQL语法规则和所述操作指令生成SQL语句之前,所述方法还包括:In one embodiment, before generating the SQL statement according to the structured query language SQL grammar rules and the operation instruction, the method further includes:

通过所述预设操作接口扫描所述操作指令的数据结构体对象中的各个成员,根据预定义的正则表达式检测所述操作指令中是否存在语法错误。Each member of the data structure object of the operation instruction is scanned through the preset operation interface, and whether there is a syntax error in the operation instruction is detected according to a predefined regular expression.

第二方面,本发明实施例提供一种基于C语言对关系型数据库进行操作的装置,包括:In a second aspect, an embodiment of the present invention provides an apparatus for operating a relational database based on the C language, including:

创建模块,用于创建关系型数据库的数据库表和对应的C语言数据结构体;Create a module for creating database tables and corresponding C language data structures of relational databases;

确定模块,用于确定所述数据库表和所述C语言数据结构体之间的映射结构体,并将所述映射结构体加入所述C语言数据结构体;A determination module, for determining a mapping structure between the database table and the C language data structure, and adding the mapping structure to the C language data structure;

调用模块,用于获取用户的操作指令,并根据所述操作指令调用预设操作接口;a calling module, used for obtaining the user's operation instruction, and calling the preset operation interface according to the operation instruction;

生成模块,用于通过所述预设操作接口,根据结构化查询语言SQL语法规则和所述操作指令生成SQL语句;A generating module, configured to generate an SQL statement according to the structured query language SQL grammar rules and the operation instruction through the preset operation interface;

处理模块,用于根据所述SQL语句对所述关系型数据库进行相应的操作处理。The processing module is configured to perform corresponding operation processing on the relational database according to the SQL statement.

第三方面,本发明实施例提供一种电子设备,包括:In a third aspect, an embodiment of the present invention provides an electronic device, including:

至少一个处理器和存储器;at least one processor and memory;

存储器存储计算机执行指令;memory stores computer-executed instructions;

至少一个处理器执行存储器存储的计算机执行指令,使得至少一个处理器执行如第一方面任一项所述的基于C语言对关系型数据库进行操作的方法。The at least one processor executes the computer-executed instructions stored in the memory, so that the at least one processor executes the method for operating a relational database based on the C language according to any one of the first aspects.

第四方面,本发明实施例提供一种计算机可读存储介质,所述计算机可读存储介质中存储有计算机执行指令,计算机执行指令被处理器执行时用于实现如第一方面任一项所述的基于C语言对关系型数据库进行操作的方法。In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, where computer-executable instructions are stored in the computer-readable storage medium, and when the computer-executable instructions are executed by a processor, are used to implement any one of the first aspect. The method for operating relational database based on C language.

本发明实施例提供的基于C语言对关系型数据库进行操作的方法、装置及设备,通过创建关系型数据库的数据库表和对应的C语言数据结构体;确定所述数据库表和所述C语言数据结构体之间的映射结构体,并将所述映射结构体加入所述C语言数据结构体;获取用户的操作指令;并根据所述操作指令调用预设操作接口;通过所述预设操作接口,根据结构化查询语言SQL语法规则和所述操作指令生成SQL语句;根据所述SQL语句对所述关系型数据库进行相应的操作处理,基于C语言实现了对关系型数据库的高效操作。通过数据库表和C语言数据结构体之间的映射结构体以及预设操作接口,简化了操作,减少了工作量。The method, device and device for operating a relational database based on C language provided by the embodiments of the present invention, by creating a database table of a relational database and a corresponding C language data structure; determining the database table and the C language data The mapping structure between the structures, and adding the mapping structure to the C language data structure; obtaining the user's operation instruction; and calling the preset operation interface according to the operation instruction; through the preset operation interface , generate SQL statements according to the structured query language SQL syntax rules and the operation instructions; perform corresponding operation processing on the relational database according to the SQL statements, and realize efficient operations on the relational database based on the C language. Through the mapping structure between the database table and the C language data structure and the preset operation interface, the operation is simplified and the workload is reduced.

附图说明Description of drawings

图1为本发明提供的基于C语言对关系型数据库进行操作的方法一实施例的流程图;1 is a flowchart of an embodiment of a method for operating a relational database based on C language provided by the present invention;

图2为本发明提供的基于C语言对关系型数据库进行操作的方法又一实施例的流程图;2 is a flowchart of another embodiment of a method for operating a relational database based on C language provided by the present invention;

图3为本发明提供的基于C语言对关系型数据库进行操作的装置一实施例的结构示意图;3 is a schematic structural diagram of an embodiment of an apparatus for operating a relational database based on C language provided by the present invention;

图4为本发明提供的电子设备一实施例的结构示意图。FIG. 4 is a schematic structural diagram of an embodiment of an electronic device provided by the present invention.

具体实施方式Detailed ways

下面通过具体实施方式结合附图对本发明作进一步详细说明。其中不同实施方式中类似元件采用了相关联的类似的元件标号。在以下的实施方式中,很多细节描述是为了使得本申请能被更好的理解。然而,本领域技术人员可以毫不费力的认识到,其中部分特征在不同情况下是可以省略的,或者可以由其他元件、材料、方法所替代。在某些情况下,本申请相关的一些操作并没有在说明书中显示或者描述,这是为了避免本申请的核心部分被过多的描述所淹没,而对于本领域技术人员而言,详细描述这些相关操作并不是必要的,他们根据说明书中的描述以及本领域的一般技术知识即可完整了解相关操作。The present invention will be further described in detail below through specific embodiments in conjunction with the accompanying drawings. Wherein similar elements in different embodiments have used associated similar element numbers. In the following embodiments, many details are described so that the present application can be better understood. However, those skilled in the art will readily recognize that some of the features may be omitted under different circumstances, or may be replaced by other elements, materials, and methods. In some cases, some operations related to the present application are not shown or described in the specification, in order to avoid the core part of the present application from being overwhelmed by excessive description, and for those skilled in the art, these are described in detail. The relevant operations are not necessary, and they can fully understand the relevant operations according to the descriptions in the specification and general technical knowledge in the field.

另外,说明书中所描述的特点、操作或者特征可以以任意适当的方式结合形成各种实施方式。同时,方法描述中的各步骤或者动作也可以按照本领域技术人员所能显而易见的方式进行顺序调换或调整。因此,说明书和附图中的各种顺序只是为了清楚描述某一个实施例,并不意味着是必须的顺序,除非另有说明其中某个顺序是必须遵循的。Additionally, the features, acts, or characteristics described in the specification may be combined in any suitable manner to form various embodiments. At the same time, the steps or actions in the method description can also be exchanged or adjusted in order in a manner obvious to those skilled in the art. Therefore, the various sequences in the specification and drawings are only for the purpose of clearly describing a certain embodiment and are not meant to be a necessary order unless otherwise stated, a certain order must be followed.

本文中为部件所编序号本身,例如“第一”、“第二”等,仅用于区分所描述的对象,不具有任何顺序或技术含义。而本申请所说“连接”、“联接”,如无特别说明,均包括直接和间接连接(联接)。The serial numbers themselves, such as "first", "second", etc., for the components herein are only used to distinguish the described objects, and do not have any order or technical meaning. The "connection" and "connection" mentioned in this application, unless otherwise specified, include both direct and indirect connections (connections).

需要说明的是,本发明实施例提供的基于C语言对关系型数据库进行操作的方法可以应用于任何需要对关系型数据库进行操作的设备中,包括但不限于用户侧设备和网络侧设备。其中,用户侧设备例如可以是计算机、智能手机、平板电脑和个人数字助理等;网络侧设备例如可以是网络附属存储(Network Attached Storage,简称:NAS)设备、网络服务器和基于云计算的由大量计算机或网络服务器构成的服务器组等。It should be noted that the method for operating a relational database based on the C language provided by the embodiment of the present invention can be applied to any device that needs to operate a relational database, including but not limited to user-side equipment and network-side equipment. Wherein, the user-side device may be, for example, a computer, a smart phone, a tablet computer, a personal digital assistant, etc.; the network-side device may be, for example, a network attached storage (Network Attached Storage, NAS for short) device, a network server, and a large number of cloud-based computing devices. A server group composed of computers or network servers, etc.

图1为本发明提供的基于C语言对关系型数据库进行操作的方法一实施例的流程图。如图1所示,本实施例提供的基于C语言对关系型数据库进行操作的方法,可以包括:FIG. 1 is a flowchart of an embodiment of a method for operating a relational database based on the C language provided by the present invention. As shown in FIG. 1, the method for operating a relational database based on the C language provided by this embodiment may include:

S101、创建关系型数据库的数据库表和对应的C语言数据结构体。S101. Create a database table of a relational database and a corresponding C language data structure.

本实施例中可以根据待处理的数据创建关系型数据库的数据库表和对应的C语言数据结构体。具体地,可以根据待处理的数据确定数据库表中的表字段以及相应的数据类型;根据数据库表中的表字段以及数据类型确定对应的C语言数据结构体。下面通过一个具体的示例进行说明:In this embodiment, a database table of a relational database and a corresponding C language data structure can be created according to the data to be processed. Specifically, table fields and corresponding data types in the database table may be determined according to the data to be processed; and corresponding C language data structures may be determined according to the table fields and data types in the database table. The following is a concrete example to illustrate:

以SQLite数据库为例,可以采用如下SQL语句创建数据库表,其中包括各个数据库表字段的数据类型和名称:Taking the SQLite database as an example, you can use the following SQL statement to create a database table, including the data type and name of each database table field:

Figure BDA0002674458110000051
Figure BDA0002674458110000051

Figure BDA0002674458110000061
Figure BDA0002674458110000061

针对上述所创建的数据库表,可以通过如下定义确定与之对应的C语言数据结构体,其中包括各成员字段的数据类型和名称:For the database table created above, the corresponding C language data structure can be determined by the following definitions, including the data type and name of each member field:

Figure BDA0002674458110000062
Figure BDA0002674458110000062

Figure BDA0002674458110000071
Figure BDA0002674458110000071

S102、确定所述数据库表和所述C语言数据结构体之间的映射结构体,并将所述映射结构体加入所述C语言数据结构体。S102. Determine a mapping structure between the database table and the C language data structure, and add the mapping structure to the C language data structure.

在创建数据库表和对应的C语言数据结构体之后,便可以确定所述数据库表和所述C语言数据结构体之间的映射结构体。数据库表与C语言数据结构体之间的映射结构体,仅仅映射需要进行数据库操作的字段。After the database table and the corresponding C language data structure are created, the mapping structure between the database table and the C language data structure can be determined. The mapping structure between the database table and the C language data structure only maps the fields that need to be operated on the database.

在一种可选的实施方式中,确定所述数据库表和所述C语言数据结构体之间的映射结构体可以包括:确定所述数据库表中表字段和所述C语言数据结构体中成员字段之间的对应关系;根据预设规则计算所述C语言数据结构体中各成员字段的内存地址;将所述对应关系和所述内存地址存储至所述映射结构体。In an optional implementation manner, determining the mapping structure between the database table and the C language data structure may include: determining a table field in the database table and a member in the C language data structure The corresponding relationship between the fields is calculated; the memory address of each member field in the C language data structure is calculated according to a preset rule; the corresponding relationship and the memory address are stored in the mapping structure.

例如对于步骤S101中的示例,数据库表中数据类型为INTEGER的表字段`birthday`与C语言数据结构体中数据类型为UInt32的成员字段birthday相对应;例如可以根据C语言数据结构体中各成员字段的数据类型和顺序确定内存地址。具体地,通过如下的field_map_user,就可以实现反射,从而在数据库表与C语言数据结构体之间建立关系。For example, for the example in step S101, the table field `birthday` whose data type is INTEGER in the database table corresponds to the member field birthday whose data type is UInt32 in the C language data structure; The data type and order of the fields determine the memory address. Specifically, through the following field_map_user, reflection can be implemented to establish a relationship between the database table and the C language data structure.

Figure BDA0002674458110000072
Figure BDA0002674458110000072

Figure BDA0002674458110000081
Figure BDA0002674458110000081

S103、获取用户的操作指令,并根据所述操作指令调用预设操作接口。S103: Acquire an operation instruction of the user, and call a preset operation interface according to the operation instruction.

当该方法应用于用户侧设备时,例如可以通过用户侧设备的输入装置获取用户的操作指令;当该方法应用于网络侧设备时,例如可以通过通信模块获取用户的操作指令。操作指令中可以包括操作标识和C语言数据结构体对象。其中,操作标识例如可以用于指示进行增加操作、删除操作、修改操作或者查询操作等。When the method is applied to the user-side device, for example, the user's operation instruction can be obtained through the input device of the user-side device; when the method is applied to the network-side device, the user's operation instruction can be obtained, for example, through the communication module. The operation instruction may include an operation identifier and a C language data structure object. Wherein, the operation identifier may be used to instruct, for example, an addition operation, a deletion operation, a modification operation, or a query operation, and the like.

本实施例中可以预先基于C语言实现一些用于对数据库进行操作的操作接口,即预设操作接口。预设操作接口例如可以包括用于增加数据的操作接口、用于删除数据的操作接口、用于修改数据的操作接口和用于查询数据的操作接口等。当操作指令中的操作标识用于指示进行增加操作时,则调用预设的用于增加数据的操作接口。In this embodiment, some operation interfaces for operating the database, that is, preset operation interfaces, may be implemented in advance based on the C language. The preset operation interface may include, for example, an operation interface for adding data, an operation interface for deleting data, an operation interface for modifying data, an operation interface for querying data, and the like. When the operation identifier in the operation instruction is used to instruct the addition operation, the preset operation interface for adding data is called.

S104、通过所述预设操作接口,根据结构化查询语言SQL语法规则和所述操作指令生成SQL语句。S104. Generate an SQL statement according to the structured query language SQL syntax rules and the operation instruction through the preset operation interface.

一种可选的实施方式中,根据结构化查询语言SQL语法规则和所述操作指令生成SQL语句,可以包括:根据所述操作指令中的操作标识确定所述SQL语句的操作类型;根据所述映射结构体将所述操作指令中的C语言数据结构体对象转化为数据库表中的数据对象;将所述数据对象作为所述SQL语句的参数。In an optional implementation manner, generating the SQL statement according to the structured query language SQL grammar rules and the operation instruction may include: determining the operation type of the SQL statement according to the operation identifier in the operation instruction; The mapping structure converts the C language data structure object in the operation instruction into the data object in the database table; the data object is used as the parameter of the SQL statement.

其中,根据所述映射结构体将所述操作指令中的C语言数据结构体对象转化为数据库表中的数据对象,具体可以包括:根据所述操作指令中的C语言数据结构体对象中各成员字段的内存地址,获取所述操作指令中的C语言数据结构体对象中各成员字段;根据所述数据库表中表字段和所述C语言数据结构体中成员字段之间的对应关系,确定所述操作指令中的C语言数据结构体对象中各成员字段所对应的数据库表中的表字段;根据数据类型,将所述操作指令中的C语言数据结构体对象中各数据成员转换为对应的数据库表中的表字段数据。Wherein, converting the C language data structure object in the operation instruction into the data object in the database table according to the mapping structure may specifically include: according to each member of the C language data structure object in the operation instruction The memory address of the field is obtained, and each member field in the C language data structure object in the operation instruction is obtained; according to the corresponding relationship between the table field in the database table and the member field in the C language data structure, determine all the member fields. The table field in the database table corresponding to each member field in the C language data structure object in the operation instruction; according to the data type, each data member in the C language data structure object in the operation instruction is converted into a corresponding Table field data in a database table.

当用户需要对SQLite数据库进行增删改查操作时,输入操作指令。设备在接收到操作指令之后,可以创建数据结构体对象,根据需要把映射结构体加入数据结构体对象中,然后根据语法规则把增删改查的条件和相应的数据填入“数据结构体”对象的各个成员字段,调用预设操作接口把这个构造好的“数据结构体”对象传入。最后再根据操作对象是单表、多表、跨库、需要什么样的查询结果等不同条件传入多个不同的目标“映射结构体”到预设操作接口。预设操作接口扫描“映射结构体”中保存的每一个“数据结构体”成员,根据成员的内存地址使用类似动态语言的“反射机制”获取到“数据结构体”的对应成员,根据成员的不同数据类型从“数据结构体”对象成员中获取值,转换成SQLite数据库对应的数据类型和数据值。最后根据SQL语言语法规则,根据增、删、改、查、单表、多表、跨库、是否有查询条件、是否排序等不同情况,构造对应操作的SQL语句。When the user needs to add, delete, modify, and query the SQLite database, enter the operation command. After the device receives the operation command, it can create a data structure object, add the mapping structure to the data structure object as needed, and then fill in the "data structure" object with the conditions of additions, deletions, modifications and inspections and the corresponding data according to the grammar rules. Each member field of , call the preset operation interface to pass in the constructed "data structure" object. Finally, according to different conditions such as single-table, multi-table, cross-database, and what kind of query results are required for the operation object, multiple different target "mapping structures" are passed to the preset operation interface. The preset operation interface scans each "data structure" member saved in the "mapped structure", and uses the "reflection mechanism" similar to dynamic language to obtain the corresponding member of the "data structure" according to the memory address of the member. Different data types obtain values from the "data structure" object members and convert them into the corresponding data types and data values of the SQLite database. Finally, according to the grammar rules of the SQL language, according to the different situations such as addition, deletion, modification, query, single table, multi-table, cross-database, whether there are query conditions, and whether to sort, construct the SQL statement corresponding to the operation.

S105、根据所述SQL语句对所述关系型数据库进行相应的操作处理。S105. Perform corresponding operation processing on the relational database according to the SQL statement.

本实施例中在生成SQL语句之后,则根据所述SQL语句对所述关系型数据库进行相应的操作处理即可。In this embodiment, after the SQL statement is generated, it is sufficient to perform corresponding operation processing on the relational database according to the SQL statement.

以针对NAS设备中的数据库进行操作为例,对于文件管理功能来说,可以根据使用场景不同而设置不同条件来查询文件,如查询某一个用户下的所有文件,查询某个用户的某个目录下的文件,查询某个用户的文件名中包含"xxx"关键字的文件等,对于文件的增删改查操作非常多。现有技术中,不仅需要创建数据库表和数据结构体,而且需要很多个函数分别来对应上述的操作。而本申请中,在创建数据库表和数据结构体之后,只需要创建一个映射结构体,便可以通过预设操作接口来实现上述所有操作。Taking the operation of the database in the NAS device as an example, for the file management function, you can set different conditions to query files according to different usage scenarios, such as querying all files under a user, querying a directory of a user There are many operations for adding, deleting, modifying, and querying files, such as files under a certain user's file name, and files containing the "xxx" keyword in the file name. In the prior art, not only database tables and data structures need to be created, but also many functions are needed to respectively correspond to the above operations. In the present application, after creating the database table and the data structure, only one mapping structure needs to be created, and then all the above operations can be implemented through the preset operation interface.

本实施例提供的基于C语言对关系型数据库进行操作的方法,通过数据库表和C语言数据结构体之间的映射结构体以及预设操作接口,简化了操作,减少了工作量,基于C语言实现了对关系型数据库的高效操作。The method for operating a relational database based on the C language provided by this embodiment simplifies the operation and reduces the workload through the mapping structure between the database table and the C language data structure and the preset operation interface, and is based on the C language. Efficient operation of relational database is realized.

在上述实施例的基础上,为了提高操作的安全性,本实施例中在根据结构化查询语言SQL语法规则和所述操作指令生成SQL语句之前,还通过所述预设操作接口扫描所述操作指令的数据结构体对象中的各个成员,根据预定义的正则表达式检测所述操作指令中是否存在语法错误。具体的,预设操作接口首先扫描“映射结构体”各个成员和“数据结构体”对象中传入的数据、接口条件、排序和目标“映射结构体”等,根据预定义的多个正则表达式检测是否存在语法错误,用于语法检测的正则表达式可以根据单表、多表、跨库、需要什么样的查询结果等不同条件确定。On the basis of the above embodiment, in order to improve the security of the operation, in this embodiment, before generating the SQL statement according to the SQL syntax rules of the structured query language and the operation instruction, the operation is also scanned through the preset operation interface Each member in the data structure object of the instruction detects whether there is a syntax error in the operation instruction according to a predefined regular expression. Specifically, the preset operation interface first scans each member of the "mapping structure" and the incoming data in the "data structure" object, interface conditions, sorting and target "mapping structure", etc., according to the predefined multiple regular expressions The regular expression used for syntax detection can be determined according to different conditions such as single-table, multi-table, cross-database, and what kind of query results are required.

在上述实施例的基础上,本实施例针对不同的操作指令进行了差异化处理。具体的,若所述操作指令中的操作标识指示的操作为增加操作、删除操作或者修改操作时,则所述方法还包括返回操作执行结果状态;若所述操作指令中的操作标识指示的操作为查询操作时,则所述方法还包括:根据生成的SQL语句从所述关系型数据库中获取查询结果数据;根据所述映射结构体将所述查询结果数据转化为所述C语言数据结构体中的数据。其中,根据所述映射结构体将所述查询结果数据转化为所述C语言数据结构体中的数据,包括:根据所述数据库表中表字段和所述C语言数据结构体中成员字段之间的对应关系,确定所述查询结果数据中各表字段所对应的C语言数据结构体中的成员字段;根据各表字段和所对应的成员字段的数据类型,进行数值转换;根据所述C语言数据结构体中各成员字段的内存地址,将数值转换后的查询结果数据存入相应的成员字段中。On the basis of the foregoing embodiment, the present embodiment performs differentiated processing for different operation instructions. Specifically, if the operation indicated by the operation identifier in the operation instruction is an addition operation, a deletion operation or a modification operation, the method further includes returning the operation execution result status; if the operation indicated by the operation identifier in the operation instruction is an operation When it is a query operation, the method further includes: obtaining query result data from the relational database according to the generated SQL statement; converting the query result data into the C language data structure according to the mapping structure data in . Wherein, converting the query result data into data in the C language data structure according to the mapping structure includes: according to the relationship between the table field in the database table and the member field in the C language data structure The corresponding relationship, determine the member field in the C language data structure corresponding to each table field in the query result data; carry out numerical conversion according to the data type of each table field and the corresponding member field; according to the C language The memory address of each member field in the data structure, and the query result data after numerical conversion is stored in the corresponding member field.

图2为本发明提供的基于C语言对关系型数据库进行操作的方法又一实施例的流程图。如图2所示,在图1所示实施例的基础上,本实施例提供的方法还可以包括:FIG. 2 is a flowchart of another embodiment of a method for operating a relational database based on the C language provided by the present invention. As shown in FIG. 2, on the basis of the embodiment shown in FIG. 1, the method provided in this embodiment may further include:

S201、判断操作指令中的操作标识指示的操作是否为查询操作。若是,则执行步骤S202;若否,则执行步骤S206。S201. Determine whether the operation indicated by the operation identifier in the operation instruction is a query operation. If yes, go to step S202; if not, go to step S206.

S202、根据生成的SQL语句从关系型数据库中获取查询结果数据。S202. Obtain query result data from a relational database according to the generated SQL statement.

S203、根据数据库表中表字段和C语言数据结构体中成员字段之间的对应关系,确定查询结果数据中各表字段所对应的C语言数据结构体中的成员字段。S203 , according to the correspondence between the table fields in the database table and the member fields in the C language data structure, determine the member fields in the C language data structure corresponding to each table field in the query result data.

S204、根据各表字段和所对应的成员字段的数据类型,进行数值转换。S204. Perform numerical conversion according to the data types of each table field and the corresponding member field.

S205、根据C语言数据结构体中各成员字段的内存地址,将数值转换后的查询结果数据存入相应的成员字段中,完成对数据库的查询操作。S205 , according to the memory addresses of each member field in the C language data structure, store the query result data after the numerical conversion into the corresponding member field, and complete the query operation on the database.

S206、继续判断操作指令中的操作标识指示的操作是否为增加操作、删除操作或者修改操作。若是,则继续执行步骤S207。S206. Continue to determine whether the operation indicated by the operation identifier in the operation instruction is an addition operation, a deletion operation or a modification operation. If yes, continue to step S207.

S207、返回操作执行结果状态,完成对数据库的增加操作、删除操作或者修改操作。S207 , returning the operation execution result status, and completing the addition operation, deletion operation or modification operation to the database.

本实施例提供的基于C语言对关系型数据库进行操作的方法,在上述实施例的基础上,进一步地通过映射结构体实现的反射机制,将从数据库中获取的查询结果数据转换为数据结构体中的成员数据。The method for operating a relational database based on the C language provided by this embodiment, on the basis of the above embodiment, further converts the query result data obtained from the database into a data structure through the reflection mechanism implemented by the mapping structure member data in .

图3为本发明提供的基于C语言对关系型数据库进行操作的装置一实施例的结构示意图。如图3所示,本实施例提供的基于C语言对关系型数据库进行操作的装置30可以包括:创建模块301、确定模块302、调用模块303、生成模块304和处理模块305。FIG. 3 is a schematic structural diagram of an embodiment of an apparatus for operating a relational database based on the C language provided by the present invention. As shown in FIG. 3 , the apparatus 30 for operating a relational database based on C language provided in this embodiment may include: a creating module 301 , a determining module 302 , a calling module 303 , a generating module 304 and a processing module 305 .

创建模块301,用于创建关系型数据库的数据库表和对应的C语言数据结构体;A creation module 301 is used to create a database table of a relational database and a corresponding C language data structure;

确定模块302,用于确定所述数据库表和所述C语言数据结构体之间的映射结构体,并将所述映射结构体加入所述C语言数据结构体;A determination module 302, configured to determine a mapping structure between the database table and the C language data structure, and add the mapping structure to the C language data structure;

调用模块303,用于获取用户的操作指令,并根据所述操作指令调用预设操作接口;The calling module 303 is used to obtain the operation instruction of the user, and call the preset operation interface according to the operation instruction;

生成模块304,用于通过所述预设操作接口,根据结构化查询语言SQL语法规则和所述操作指令生成SQL语句;A generating module 304, configured to generate an SQL statement according to the structured query language SQL syntax rules and the operation instruction through the preset operation interface;

处理模块305,用于根据所述SQL语句对所述关系型数据库进行相应的操作处理。The processing module 305 is configured to perform corresponding operation processing on the relational database according to the SQL statement.

本实施例提供的基于C语言对关系型数据库进行操作的装置可用于执行图1对应的方法实施例的技术方案,其实现原理和技术效果类似,此处不再赘述。The apparatus for operating a relational database based on the C language provided in this embodiment can be used to execute the technical solution of the method embodiment corresponding to FIG. 1 , and the implementation principles and technical effects thereof are similar, and are not repeated here.

一种实施例中,确定模块302用于确定所述数据库表和所述C语言数据结构体之间的映射结构体,具体可以包括:In one embodiment, the determining module 302 is configured to determine the mapping structure between the database table and the C language data structure, which may specifically include:

确定所述数据库表中表字段和所述C语言数据结构体中成员字段之间的对应关系;Determine the correspondence between the table field in the database table and the member field in the C language data structure;

根据预设规则计算所述C语言数据结构体中各成员字段的内存地址;Calculate the memory address of each member field in the C language data structure according to the preset rule;

将所述对应关系和所述内存地址存储至所述映射结构体。storing the correspondence and the memory address in the mapping structure.

一种实施例中,生成模块304用于根据结构化查询语言SQL语法规则和所述操作指令生成SQL语句,具体可以包括:In one embodiment, the generating module 304 is configured to generate the SQL statement according to the structured query language SQL syntax rules and the operation instruction, which may specifically include:

根据所述操作指令中的操作标识确定所述SQL语句的操作类型;Determine the operation type of the SQL statement according to the operation identifier in the operation instruction;

根据所述映射结构体将所述操作指令中的C语言数据结构体对象转化为数据库表中的数据对象;Convert the C language data structure object in the operation instruction into a data object in the database table according to the mapping structure;

将所述数据对象作为所述SQL语句的参数。Use the data object as a parameter of the SQL statement.

一种实施例中,生成模块304用于根据所述映射结构体将所述操作指令中的C语言数据结构体对象转化为数据库表中的数据对象,具体可以包括:In an embodiment, the generating module 304 is configured to convert the C language data structure object in the operation instruction into the data object in the database table according to the mapping structure, which may specifically include:

根据所述操作指令中的C语言数据结构体对象中各成员字段的内存地址,获取所述操作指令中的C语言数据结构体对象中各成员字段;According to the memory address of each member field in the C language data structure object in the described operation instruction, obtain each member field in the C language data structure object in the described operation instruction;

根据所述数据库表中表字段和所述C语言数据结构体中成员字段之间的对应关系,确定所述操作指令中的C语言数据结构体对象中各成员字段所对应的数据库表中的表字段;According to the correspondence between the table fields in the database table and the member fields in the C language data structure, determine the table in the database table corresponding to each member field in the C language data structure object in the operation instruction field;

根据数据类型,将所述操作指令中的C语言数据结构体对象中各数据成员转换为对应的数据库表中的表字段数据。According to the data type, each data member in the C language data structure object in the operation instruction is converted into table field data in the corresponding database table.

一种实施例中,基于C语言对关系型数据库进行操作的装置30还可以包括后处理模块(图中未示出),用于若所述操作指令中的操作标识指示的操作为增加操作、删除操作或者修改操作时,返回操作执行结果状态;若所述操作指令中的操作标识指示的操作为查询操作时,根据生成的SQL语句从所述关系型数据库中获取查询结果数据;根据所述映射结构体将所述查询结果数据转化为所述C语言数据结构体中的数据。In an embodiment, the apparatus 30 for operating the relational database based on the C language may further include a post-processing module (not shown in the figure), for if the operation indicated by the operation identifier in the operation instruction is an increase operation, When a deletion operation or a modification operation is performed, the operation execution result status is returned; if the operation indicated by the operation identifier in the operation instruction is a query operation, the query result data is obtained from the relational database according to the generated SQL statement; according to the The mapping structure converts the query result data into data in the C language data structure.

一种实施例中,后处理模块用于根据所述映射结构体将所述查询结果数据转化为所述C语言数据结构体中的数据,具体可以包括:In an embodiment, the post-processing module is configured to convert the query result data into data in the C language data structure according to the mapping structure, which may specifically include:

根据所述数据库表中表字段和所述C语言数据结构体中成员字段之间的对应关系,确定所述查询结果数据中各表字段所对应的C语言数据结构体中的成员字段;According to the correspondence between the table fields in the database table and the member fields in the C language data structure, determine the member fields in the C language data structure corresponding to each table field in the query result data;

根据各表字段和所对应的成员字段的数据类型,进行数值转换;Perform numerical conversion according to the data type of each table field and the corresponding member field;

根据所述C语言数据结构体中各成员字段的内存地址,将数值转换后的查询结果数据存入相应的成员字段中。According to the memory address of each member field in the C language data structure, the query result data after the numerical conversion is stored in the corresponding member field.

一种实施例中,基于C语言对关系型数据库进行操作的装置30还可以包括检测模块(图中未示出),用于在根据结构化查询语言SQL语法规则和所述操作指令生成SQL语句之前,通过所述预设操作接口扫描所述操作指令的数据结构体对象中的各个成员,根据预定义的正则表达式检测所述操作指令中是否存在语法错误。In an embodiment, the apparatus 30 for operating a relational database based on the C language may further include a detection module (not shown in the figure) for generating SQL statements according to the structured query language SQL syntax rules and the operation instructions. Before, each member of the data structure object of the operation instruction is scanned through the preset operation interface, and whether there is a syntax error in the operation instruction is detected according to a predefined regular expression.

本发明实施例还提供一种电子设备40,请参见图4所示,本发明实施例仅以图4为例进行说明,并不表示本发明仅限于此。图4为本发明提供的电子设备一实施例的结构示意图。本实施例提供的电子设备包括但不限于:计算机、智能手机、平板电脑、个人数字助理、服务器和服务器组。如图4所示,本实施例提供的电子设备40可以包括:存储器401、处理器402和总线403。其中,总线403用于实现各元件之间的连接。The embodiment of the present invention further provides an electronic device 40 . Please refer to FIG. 4 . The embodiment of the present invention only uses FIG. 4 as an example for description, which does not mean that the present invention is limited to this. FIG. 4 is a schematic structural diagram of an embodiment of an electronic device provided by the present invention. The electronic devices provided in this embodiment include, but are not limited to, computers, smart phones, tablet computers, personal digital assistants, servers, and server groups. As shown in FIG. 4 , the electronic device 40 provided in this embodiment may include: a memory 401 , a processor 402 and a bus 403 . Among them, the bus 403 is used to realize the connection between various components.

存储器401中存储有计算机程序,计算机程序被处理器402执行时可以实现上述任一方法实施例提供的基于C语言对关系型数据库进行操作的方法的技术方案。A computer program is stored in the memory 401, and when the computer program is executed by the processor 402, the technical solution of the method for operating a relational database based on the C language provided by any of the above method embodiments can be implemented.

其中,存储器401和处理器402之间直接或间接地电性连接,以实现数据的传输或交互。例如,这些元件相互之间可以通过一条或者多条通信总线或信号线实现电性连接,如可以通过总线403连接。存储器401中存储有实现基于C语言对关系型数据库进行操作的方法的计算机程序,包括至少一个可以软件或固件的形式存储于存储器401中的软件功能模块,处理器402通过运行存储在存储器401内的软件程序以及模块,从而执行各种功能应用以及数据处理。The memory 401 and the processor 402 are electrically connected directly or indirectly to realize data transmission or interaction. For example, these elements can be electrically connected to each other through one or more communication buses or signal lines, such as the bus 403 . A computer program for implementing a method for operating a relational database based on C language is stored in the memory 401, including at least one software function module that can be stored in the memory 401 in the form of software or firmware, and the processor 402 is stored in the memory 401 by running software programs and modules that perform various functional applications and data processing.

存储器401可以是,但不限于,随机存取存储器(Random Access Memory,简称:RAM),只读存储器(Read Only Memory,简称:ROM),可编程只读存储器(ProgrammableRead-Only Memory,简称:PROM),可擦除只读存储器(Erasable Programmable Read-OnlyMemory,简称:EPROM),电可擦除只读存储器(Electric Erasable Programmable Read-Only Memory,简称:EEPROM)等。其中,存储器401用于存储程序,处理器402在接收到执行指令后,执行程序。进一步地,上述存储器401内的软件程序以及模块还可包括操作系统,其可包括各种用于管理系统任务(例如内存管理、存储设备控制、电源管理等)的软件组件和/或驱动,并可与各种硬件或软件组件相互通信,从而提供其他软件组件的运行环境。The memory 401 can be, but is not limited to, a random access memory (Random Access Memory, referred to as: RAM), a read-only memory (Read Only Memory, referred to as: ROM), a programmable read-only memory (Programmable Read-Only Memory, referred to as: PROM) ), Erasable Programmable Read-Only Memory (EPROM for short), Electrical Erasable Programmable Read-Only Memory (EEPROM for short), etc. The memory 401 is used for storing the program, and the processor 402 executes the program after receiving the execution instruction. Further, the software programs and modules in the above-mentioned memory 401 may also include an operating system, which may include various software components and/or drivers for managing system tasks (such as memory management, storage device control, power management, etc.), and Can communicate with various hardware or software components to provide an operating environment for other software components.

处理器402可以是一种集成电路芯片,具有信号的处理能力。上述的处理器402可以是通用处理器,包括中央处理器(Central Processing Unit,简称:CPU)、网络处理器(Network Processor,简称:NP)等。可以实现或者执行本发明实施例中的公开的各方法、步骤及逻辑框图。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。可以理解,图4的结构仅为示意,还可以包括比图4中所示更多或者更少的组件,或者具有与图4所示不同的配置。图4中所示的各组件可以采用硬件和/或软件实现。The processor 402 may be an integrated circuit chip with signal processing capability. The aforementioned processor 402 may be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU for short), a network processor (Network Processor, NP for short). Various methods, steps, and logical block diagrams disclosed in the embodiments of the present invention can be implemented or executed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. It can be understood that the structure of FIG. 4 is only for illustration, and may also include more or less components than those shown in FIG. 4 , or have different configurations from those shown in FIG. 4 . The components shown in FIG. 4 may be implemented in hardware and/or software.

本文参照了各种示范实施例进行说明。然而,本领域的技术人员将认识到,在不脱离本文范围的情况下,可以对示范性实施例做出改变和修正。例如,各种操作步骤以及用于执行操作步骤的组件,可以根据特定的应用或考虑与系统的操作相关联的任何数量的成本函数以不同的方式实现(例如一个或多个步骤可以被删除、修改或结合到其他步骤中)。Descriptions are made herein with reference to various exemplary embodiments. However, those skilled in the art will recognize that changes and modifications may be made to the exemplary embodiments without departing from the scope of this document. For example, various operational steps, and components for performing operational steps, may be implemented in different ways depending on the particular application or considering any number of cost functions associated with the operation of the system (eg, one or more steps may be deleted, modified or incorporated into other steps).

另外,如本领域技术人员所理解的,本文的原理可以反映在计算机可读存储介质上的计算机程序产品中,该可读存储介质预装有计算机可读程序代码。任何有形的、非暂时性的计算机可读存储介质皆可被使用,包括磁存储设备(硬盘、软盘等)、光学存储设备(CD-ROM、DVD、Blu Ray盘等)、闪存和/或诸如此类。这些计算机程序指令可被加载到通用计算机、专用计算机或其他可编程数据处理设备上以形成机器,使得这些在计算机上或其他可编程数据处理装置上执行的指令可以生成实现指定的功能的装置。这些计算机程序指令也可以存储在计算机可读存储器中,该计算机可读存储器可以指示计算机或其他可编程数据处理设备以特定的方式运行,这样存储在计算机可读存储器中的指令就可以形成一件制造品,包括实现指定功能的实现装置。计算机程序指令也可以加载到计算机或其他可编程数据处理设备上,从而在计算机或其他可编程设备上执行一系列操作步骤以产生一个计算机实现的进程,使得在计算机或其他可编程设备上执行的指令可以提供用于实现指定功能的步骤。Additionally, as understood by those skilled in the art, the principles herein may be reflected in a computer program product on a computer-readable storage medium preloaded with computer-readable program code. Any tangible, non-transitory computer-readable storage medium may be used, including magnetic storage devices (hard disks, floppy disks, etc.), optical storage devices (CD-ROMs, DVDs, Blu Ray disks, etc.), flash memory, and/or the like . These computer program instructions may be loaded on a general purpose computer, special purpose computer or other programmable data processing apparatus to form a machine such that execution of the instructions on the computer or other programmable data processing apparatus may generate means for implementing the specified functions. These computer program instructions may also be stored in a computer-readable memory that instructs a computer or other programmable data processing device to operate in a particular manner, such that the instructions stored in the computer-readable memory form a piece of Articles of manufacture, including implementing means for implementing specified functions. Computer program instructions may also be loaded on a computer or other programmable data processing device to perform a series of operational steps on the computer or other programmable device to produce a computer-implemented process such that a process executed on the computer or other programmable device Instructions may provide steps for implementing specified functions.

以上应用了具体个例对本发明进行阐述,只是用于帮助理解本发明,并不用以限制本发明。对于本发明所属技术领域的技术人员,依据本发明的思想,还可以做出若干简单推演、变形或替换。The above specific examples are used to illustrate the present invention, which are only used to help understand the present invention, and are not intended to limit the present invention. For those skilled in the art to which the present invention pertains, according to the idea of the present invention, several simple deductions, modifications or substitutions can also be made.

Claims (10)

1. A method for operating a relational database based on a C language, comprising:
creating a database table of a relational database and a corresponding C language data structure body;
determining a mapping structure between the database table and the C language data structure, and adding the mapping structure into the C language data structure;
acquiring an operation instruction of a user, and calling a preset operation interface according to the operation instruction;
generating an SQL statement according to a Structured Query Language (SQL) grammar rule and the operation instruction through the preset operation interface;
and performing corresponding operation processing on the relational database according to the SQL statement.
2. The method of claim 1, wherein said determining a mapping structure between said database table and said C language data structure comprises:
determining the corresponding relation between the table fields in the database table and the member fields in the C language data structure;
calculating the memory address of each member field in the C language data structure according to a preset rule;
and storing the corresponding relation and the memory address to the mapping structure.
3. The method of claim 2, wherein generating the SQL statement according to the structured query language SQL syntax rules and the operation instructions comprises:
determining the operation type of the SQL statement according to the operation identifier in the operation instruction;
converting the C language data structure object in the operation instruction into a data object in a database table according to the mapping structure;
and taking the data object as a parameter of the SQL statement.
4. The method of claim 3, wherein the converting the C language data structure object in the operation instruction into a data object in a database table according to the mapping structure comprises:
acquiring each member field in the C language data structure object in the operation instruction according to the memory address of each member field in the C language data structure object in the operation instruction;
determining table fields in the database table corresponding to all member fields in the C language data structure object in the operation instruction according to the corresponding relation between the table fields in the database table and the member fields in the C language data structure;
and converting each data member in the C language data structure object in the operation instruction into table field data in a corresponding database table according to the data type.
5. The method of claim 2,
if the operation indicated by the operation identifier in the operation instruction is an adding operation, a deleting operation or a modifying operation, the method further comprises returning to an operation execution result state;
if the operation indicated by the operation identifier in the operation instruction is a query operation, the method further includes:
acquiring query result data from the relational database according to the generated SQL statement;
and converting the query result data into data in the C language data structure according to the mapping structure.
6. The method of claim 5, wherein said translating said query result data into data in said C language data structure according to said mapping structure comprises:
determining member fields in the C language data structure corresponding to the table fields in the query result data according to the corresponding relation between the table fields in the database table and the member fields in the C language data structure;
performing numerical value conversion according to the data types of each table field and the corresponding member field;
and storing the query result data after the numerical value conversion into the corresponding member fields according to the memory addresses of the member fields in the C language data structure.
7. The method of any of claims 1-6, wherein prior to generating the SQL statement according to the Structured Query Language (SQL) syntax rules and the operation instructions, the method further comprises:
and scanning each member in the data structure object of the operation instruction through the preset operation interface, and detecting whether a syntax error exists in the operation instruction according to a predefined regular expression.
8. An apparatus for operating a relational database based on a C language, comprising:
the creating module is used for creating a database table of the relational database and a corresponding C language data structure body;
the determining module is used for determining a mapping structure between the database table and the C language data structure and adding the mapping structure into the C language data structure;
the calling module is used for acquiring an operation instruction of a user and calling a preset operation interface according to the operation instruction;
the generating module is used for generating an SQL statement according to the SQL grammar rule of the structured query language and the operation instruction through the preset operation interface;
and the processing module is used for carrying out corresponding operation processing on the relational database according to the SQL statement.
9. An electronic device, comprising: at least one processor and memory;
the memory stores computer-executable instructions;
the at least one processor executing the computer-executable instructions stored by the memory causes the at least one processor to perform the method of operating a relational database based on the C language of any one of claims 1-7.
10. A computer-readable storage medium having stored thereon computer-executable instructions for implementing a method for operating a relational database based on C language according to any one of claims 1 to 7 when executed by a processor.
CN202010943481.5A 2020-09-09 2020-09-09 Method, device and equipment for operating relational database based on C language Pending CN112015831A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010943481.5A CN112015831A (en) 2020-09-09 2020-09-09 Method, device and equipment for operating relational database based on C language

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010943481.5A CN112015831A (en) 2020-09-09 2020-09-09 Method, device and equipment for operating relational database based on C language

Publications (1)

Publication Number Publication Date
CN112015831A true CN112015831A (en) 2020-12-01

Family

ID=73522331

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010943481.5A Pending CN112015831A (en) 2020-09-09 2020-09-09 Method, device and equipment for operating relational database based on C language

Country Status (1)

Country Link
CN (1) CN112015831A (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113190218A (en) * 2021-04-28 2021-07-30 中国邮政储蓄银行股份有限公司 Target operation function generation method and device
CN113641745A (en) * 2021-08-18 2021-11-12 上海通联金融服务有限公司 Method for operating database across language platforms
CN114218278A (en) * 2021-12-16 2022-03-22 建信金融科技有限责任公司 Data table field query method and system of http interface
CN114296696A (en) * 2021-12-29 2022-04-08 中国电信股份有限公司 Business function operation method and device, storage medium and electronic device
CN114691110A (en) * 2022-03-30 2022-07-01 中国农业银行股份有限公司 Database statement generation method and device and electronic equipment

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103699620A (en) * 2013-12-19 2014-04-02 珠海世纪鼎利通信科技股份有限公司 Method and system for achieving database operation by utilizing object relational mapping (ORM) frame in object orientation
CN104395845A (en) * 2012-06-22 2015-03-04 欧姆龙株式会社 Control device
CN106021253A (en) * 2015-03-31 2016-10-12 欧姆龙株式会社 Programmable logic controller, data collection apparatus, database access method, and database access program
CN108920566A (en) * 2018-06-21 2018-11-30 吉林亿联银行股份有限公司 Operating method, device and the equipment of a kind of pair of SQLite database
CN109522319A (en) * 2018-11-12 2019-03-26 北京懿医云科技有限公司 Data mapping method and device, electronic equipment, storage medium based on DSL
CN111095194A (en) * 2018-03-15 2020-05-01 欧姆龙株式会社 Control system, controller and control method
CN111095195A (en) * 2018-03-15 2020-05-01 欧姆龙株式会社 Controller, control method, and control program

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104395845A (en) * 2012-06-22 2015-03-04 欧姆龙株式会社 Control device
CN103699620A (en) * 2013-12-19 2014-04-02 珠海世纪鼎利通信科技股份有限公司 Method and system for achieving database operation by utilizing object relational mapping (ORM) frame in object orientation
CN106021253A (en) * 2015-03-31 2016-10-12 欧姆龙株式会社 Programmable logic controller, data collection apparatus, database access method, and database access program
CN111095194A (en) * 2018-03-15 2020-05-01 欧姆龙株式会社 Control system, controller and control method
CN111095195A (en) * 2018-03-15 2020-05-01 欧姆龙株式会社 Controller, control method, and control program
CN108920566A (en) * 2018-06-21 2018-11-30 吉林亿联银行股份有限公司 Operating method, device and the equipment of a kind of pair of SQLite database
CN109522319A (en) * 2018-11-12 2019-03-26 北京懿医云科技有限公司 Data mapping method and device, electronic equipment, storage medium based on DSL

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113190218A (en) * 2021-04-28 2021-07-30 中国邮政储蓄银行股份有限公司 Target operation function generation method and device
CN113641745A (en) * 2021-08-18 2021-11-12 上海通联金融服务有限公司 Method for operating database across language platforms
CN113641745B (en) * 2021-08-18 2024-01-26 上海通联金融服务有限公司 Method for operating database by cross-language platform
CN114218278A (en) * 2021-12-16 2022-03-22 建信金融科技有限责任公司 Data table field query method and system of http interface
CN114218278B (en) * 2021-12-16 2025-10-21 建信金融科技有限责任公司 HTTP interface data table field query method and system
CN114296696A (en) * 2021-12-29 2022-04-08 中国电信股份有限公司 Business function operation method and device, storage medium and electronic device
CN114691110A (en) * 2022-03-30 2022-07-01 中国农业银行股份有限公司 Database statement generation method and device and electronic equipment

Similar Documents

Publication Publication Date Title
CN112015831A (en) Method, device and equipment for operating relational database based on C language
CN113051268B (en) Data query method, data query device, electronic device and storage medium
CN108519967B (en) Chart visualization method and device, terminal and storage medium
CN111949648B (en) In-memory cache data systems and data indexing methods
JP7047228B2 (en) Data query methods, devices, electronic devices, readable storage media, and computer programs
CN112395305A (en) SQL statement analysis method and device, electronic equipment and storage medium
CN115328939A (en) Method for processing query statement by database, storage medium and computer equipment
CN110175174B (en) Data query method, device, equipment and storage medium
CN108959294B (en) A method and apparatus for accessing a search engine
CN110647562B (en) A data query method and device, electronic device, and storage medium
US20160012042A1 (en) Converting Data Objects from Multi- to Single-Source Database Environment
CN113407565B (en) Cross-database data query method, device and equipment
CN105447035A (en) Data scanning method and apparatus
CN116303542A (en) SQL statement execution method and device, computer equipment, storage medium
CN112307062B (en) Database aggregation query method, device and system
CN113448995B (en) Database operation method and device, system, electronic device and storage medium
US10599487B1 (en) Adaptable data source connection strings
CN116467372A (en) Automatic database conversion method and device, electronic equipment and storage medium
US9201937B2 (en) Rapid provisioning of information for business analytics
WO2025139355A1 (en) Code analysis
CN109542912B (en) Interval data storage method, device, server and storage medium
CN109697234B (en) Multi-attribute information query method, device, server and medium for entity
CN111177234A (en) Device and method for rapidly processing document type data file
CN110109892A (en) A kind of data migration method, device and electronic equipment
CN117149825A (en) Route search method, device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
CB02 Change of applicant information

Address after: 518109 1st-6th floor, 1st floor, 6th floor, No.7 office building, yuan plant area, Longcheng industry and trade, Gaofeng community, Dalang street, Longhua District, Shenzhen, Guangdong Province

Applicant after: Shenzhen lvlian Technology Co.,Ltd.

Address before: 518109 1st-6th floor, 1st floor, 6th floor, No.7 office building, yuan plant area, Longcheng industry and trade, Gaofeng community, Dalang street, Longhua District, Shenzhen, Guangdong Province

Applicant before: SHENZHEN GREEN CONNECTION TECHNOLOGY Co.,Ltd.

CB02 Change of applicant information
RJ01 Rejection of invention patent application after publication

Application publication date: 20201201

RJ01 Rejection of invention patent application after publication