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
fields
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; CALCULATING OR 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; CALCULATING OR 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; CALCULATING OR 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

Method, device and equipment for operating relational database based on C language
Technical Field
The invention relates to the technical field of databases, in particular to a method, a device and equipment for operating a relational database based on C language.
Background
A relational database refers to a database that employs a relational model to organize data, storing data in rows and columns for easy understanding by a user. Structured Query Language (SQL) is usually used to add, delete, modify, and Query a relational database.
Taking a small lightweight SQLite database as an example, any operation performed on the SQLite database based on the C language needs to be implemented by writing a corresponding SQL statement, and even for an operation result, a corresponding function and a corresponding data structure need to be written for processing and outputting. This kind of mode not only complex operation can increase staff's work load by a wide margin moreover.
Because the C language is neither an object-oriented language nor a dynamic language, an effective solution is not proposed at present against the problems of complex operation and large workload in the existing operation method of the relational database implemented based on the C language.
Disclosure of Invention
The embodiment of the invention provides a method, a device and equipment for operating a relational database based on C language, which are used for solving the problems of complex operation and large workload of the conventional operation method of the relational database based on C language.
In a first aspect, an embodiment of the present invention provides a method for operating a relational database based on a C language, including:
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.
In one embodiment, the determining the mapping structure between the database table and the C language data structure includes:
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.
In one embodiment, the generating an SQL statement according to the SQL syntax rule of the structured query language and the operation instruction includes:
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.
In one embodiment, the 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:
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.
In one embodiment, if the operation indicated by the operation identifier in the operation instruction is an add operation, a delete operation, or a modify operation, the method further includes 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.
In one embodiment, the converting the query result data into the data in the C language data structure according to the mapping structure includes:
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.
In one embodiment, before generating the SQL statement according to the SQL syntax rule of the structured query language and the operation instruction, the method further includes:
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.
In a second aspect, an embodiment of the present invention provides an apparatus for operating a relational database based on a C language, including:
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.
In a third aspect, an embodiment of the present invention provides an electronic device, including:
at least one processor and memory;
the memory stores computer-executable instructions;
the at least one processor executes computer-executable instructions stored by the memory to cause the at least one processor to perform a method of operating a relational database based on the C language as set forth in any one of the first aspects.
In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, where computer-executable instructions are stored, and when executed by a processor, the computer-executable instructions are configured to implement the method for operating a relational database based on C language according to any one of the first aspect.
According to the method, the device and the equipment for operating the relational database based on the C language, which are provided by the embodiment of the invention, the database table of the relational database and the corresponding C language data structure body are created; 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; 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, and realizing efficient operation on the relational database based on C language. Through the mapping structure body between the database table and the C language data structure body and the preset operation interface, the operation is simplified, and the workload is reduced.
Drawings
FIG. 1 is a flowchart of an embodiment of a method for operating a relational database based on C language according to the present invention;
FIG. 2 is a flowchart of a method for operating a relational database based on C language according to another embodiment of the present invention;
FIG. 3 is a schematic structural diagram of an apparatus for operating a relational database based on C language according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of an embodiment of an electronic device provided in the present invention.
Detailed Description
The present invention will be described in further detail with reference to the following detailed description and accompanying drawings. Wherein like elements in different embodiments are numbered with like associated elements. In the following description, numerous details are set forth in order to provide a better understanding of the present application. However, those skilled in the art will readily recognize that some of the features may be omitted or replaced with other elements, materials, methods in different instances. In some instances, certain operations related to the present application have not been shown or described in detail in order to avoid obscuring the core of the present application from excessive description, and it is not necessary for those skilled in the art to describe these operations in detail, so that they may be fully understood from the description in the specification and the general knowledge in the art.
Furthermore, the features, operations, or characteristics described in the specification may be combined in any suitable manner to form various embodiments. Also, the various steps or actions in the method descriptions may be transposed or transposed in order, as will be apparent to one of ordinary skill in the art. Thus, the various sequences in the specification and drawings are for the purpose of describing certain embodiments only and are not intended to imply a required sequence unless otherwise indicated where such sequence must be followed.
The numbering of the components as such, e.g., "first", "second", etc., is used herein only to distinguish the objects as described, and does not have any sequential or technical meaning. The term "connected" and "coupled" when used in this application, unless otherwise indicated, includes both direct and indirect connections (couplings).
It should be noted that the method for operating a relational database based on C language provided by the embodiment of the present invention may be applied to any device that needs to operate a relational database, including but not limited to a user-side device and a network-side device. The user-side device may be, for example, a computer, a smart phone, a tablet computer, a personal digital assistant, and the like; the Network-side device may be, for example, a Network Attached Storage (NAS) device, a Network server, a server group composed of a large number of computers or Network servers based on cloud computing, and the like.
Fig. 1 is a flowchart of an embodiment of a method for operating a relational database based on C language according to the present invention. As shown in fig. 1, the method for operating a relational database based on a C language provided in this embodiment may include:
s101, creating a database table of a relational database and a corresponding C language data structure.
In this embodiment, a database table of a relational database and a corresponding C language data structure may be created according to data to be processed. Specifically, table fields and corresponding data types in a database table can be determined according to the data to be processed; and determining a corresponding C language data structure according to the table fields and the data types in the database table. The following is illustrated by a specific example:
taking the SQLite database as an example, the following SQL statements may be used to create database tables, including the data types and names of the various database table fields:
Figure BDA0002674458110000051
Figure BDA0002674458110000061
for the created database table, the corresponding C language data structure can be determined by the following definitions, wherein the data type and name of each member field are included:
Figure BDA0002674458110000062
Figure BDA0002674458110000071
s102, 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.
After creating a database table and a corresponding C language data structure, a mapping structure between the database table and the C language data structure may be determined. And the mapping structure between the database table and the C language data structure only maps fields needing to perform database operation.
In an alternative embodiment, determining the mapping structure between the database table and the C language data structure may include: 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.
For example, for the example in step S101, the table field 'birthday' with the data type of integrar in the database table corresponds to the member field birthday with the data type of UInt32 in the C-language data structure; for example, the memory address can be determined according to the data type and the sequence of each member field in the C language data structure. Specifically, reflection can be implemented by field _ map _ user as follows, thereby establishing a relationship between the database table and the C language data structure.
Figure BDA0002674458110000072
Figure BDA0002674458110000081
S103, obtaining an operation instruction of a user, and calling a preset operation interface according to the operation instruction.
When the method is applied to the user side equipment, for example, an operation instruction of a user can be acquired through an input device of the user side equipment; when the method is applied to the network side device, for example, the operation instruction of the user can be acquired through the communication module. The operation instruction can comprise an operation identifier and a C language data structure body object. The operation identifier may be used to indicate to perform an add operation, a delete operation, a modify operation, a query operation, or the like, for example.
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 interfaces 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. And when the operation identifier in the operation instruction is used for indicating to perform the adding operation, calling a preset operation interface for adding data.
And S104, generating an SQL statement according to the SQL grammar rule of the structured query language and the operation instruction through the preset operation interface.
In an alternative embodiment, generating the SQL statement according to the SQL syntax rule of the structured query language and the operation instruction may include: 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.
Converting the C language data structure object in the operation instruction into a data object in a database table according to the mapping structure, which may specifically include: 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.
And when the user needs to perform the operations of increasing, deleting, modifying and checking the SQLite database, inputting an operation instruction. After receiving the operation instruction, the device can create a data structure object, add the mapping structure into the data structure object as required, then fill the conditions of adding and deleting, modifying and checking and the corresponding data into each member field of the data structure object according to the grammar rule, and call a preset operation interface to transmit the constructed data structure object. And finally, a plurality of different target 'mapping structure bodies' are transmitted to a preset operation interface according to different conditions that the operation object is a single table, a plurality of tables, a cross-database, what query result is needed and the like. The preset operation interface scans each 'data structure' member stored in the 'mapping structure', acquires the corresponding member of the 'data structure' by using a 'reflection mechanism' similar to a dynamic language according to the memory address of the member, acquires a value from the 'data structure' object member according to different data types of the member, and converts the value into a data type and a data value corresponding to the SQLite database. And finally, constructing SQL sentences corresponding to the operation according to different conditions such as addition, deletion, modification, check, single table, multiple tables, cross-database, query condition, sequencing and the like according to the SQL language grammar rules.
And S105, performing corresponding operation processing on the relational database according to the SQL statement.
In this embodiment, after the SQL statement is generated, corresponding operation processing may be performed on the relational database according to the SQL statement.
Taking the operation for the database in the NAS device as an example, for the file management function, different conditions may be set according to different usage scenarios to query the file, for example, query all the files under a certain user, query the files under a certain directory of a certain user, query the files containing the "xxx" keyword in the file name of a certain user, and the like, and the operations for adding and deleting the files are very many. In the prior art, not only a database table and a data structure body need to be created, but also a plurality of functions are needed to respectively correspond to the operations. In the present application, after the database table and the data structure are created, all the operations can be implemented through the preset operation interface only by creating one mapping structure.
According to the method for operating the relational database based on the C language, provided by the embodiment, 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, the workload is reduced, and the efficient operation of the relational database is realized based on the C language.
On the basis of the above embodiment, in order to improve the security of the operation, in this embodiment, before generating an SQL statement according to a Structured Query Language (SQL) syntax rule and the operation instruction, each member in a data structure object of the operation instruction is also scanned through the preset operation interface, and whether a syntax error exists in the operation instruction is detected according to a predefined regular expression. Specifically, the preset operation interface firstly scans data, interface conditions, sequences, a target "mapping structure" and the like transmitted in each member of the "mapping structure" and the "data structure" object, detects whether grammar errors exist according to a plurality of predefined regular expressions, and the regular expressions used for grammar detection can be determined according to different conditions such as a single table, multiple tables, cross-libraries, what query results are needed, and the like.
On the basis of the above embodiments, the present embodiment performs differentiation processing for different operation instructions. Specifically, if the operation indicated by the operation identifier in the operation instruction is an add operation, a delete operation, or a modify operation, the method further includes 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. Converting the query result data into data in the C language data structure according to the mapping structure, wherein the converting 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.
FIG. 2 is a flowchart illustrating a method for operating a relational database based on C language according to another embodiment of 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, judging whether the operation indicated by the operation identifier in the operation instruction is an inquiry operation. If yes, go to step S202; if not, go to step S206.
S202, acquiring query result data from the relational database according to the generated SQL statement.
S203, determining the 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.
And S204, performing numerical value conversion according to the data types of each table field and the corresponding member field.
And S205, 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, and completing the query operation on the database.
S206, continuously judging whether the operation indicated by the operation identifier in the operation instruction is an adding operation, a deleting operation or a modifying operation. If yes, go on to step S207.
And S207, returning to the operation execution result state, and completing the operation of adding, deleting or modifying the database.
Based on the above embodiments, the method for operating a relational database based on C language further converts query result data obtained from the database into member data in a data structure through a reflection mechanism implemented by a mapping structure.
Fig. 3 is a schematic structural diagram of an apparatus for operating a relational database based on C language according to an embodiment of the present invention. As shown in fig. 3, the apparatus 30 for operating a relational database based on C language provided by the present embodiment may include: a creation module 301, a determination module 302, a calling module 303, a generation module 304, and a processing module 305.
A creating module 301, configured to create a database table of a relational database and a corresponding C language data structure;
a determining 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;
the calling module 303 is configured to obtain an operation instruction of a user, and call a preset operation interface according to the operation instruction;
the generating module 304 is configured to generate, through the preset operation interface, an SQL statement according to the SQL syntax rule of the structured query language and the operation instruction;
the processing module 305 is configured to perform corresponding operation processing on the relational database according to the SQL statement.
The apparatus for operating a relational database based on the C language provided in this embodiment may be used to execute the technical solution of the method embodiment corresponding to fig. 1, and the implementation principle and the technical effect are similar, which are not described herein again.
In an embodiment, the determining module 302 is configured to determine a mapping structure between the database table and the C language data structure, and specifically may include:
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.
In an embodiment, the generating module 304 is configured to generate an SQL statement according to the structured query language SQL syntax rule and the operation instruction, and specifically may include:
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.
In an embodiment, the generating module 304 is configured to convert the C language data structure object in the operation instruction into a data object in a database table according to the mapping structure, and specifically may include:
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.
In one embodiment, the apparatus 30 for operating a relational database based on the C language may further include a post-processing module (not shown in the figure), configured to return to an operation execution result state if the operation indicated by the operation identifier in the operation instruction is an add operation, a delete operation, or a modify operation; if the operation indicated by the operation identifier in the operation instruction is a query operation, 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.
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, and specifically may include:
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.
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), configured to scan, through the preset operation interface, each member in the data structure object of the operation instruction before generating the SQL statement according to the structured query language SQL syntax rule and the operation instruction, and detect whether there is a syntax error in the operation instruction according to a predefined regular expression.
Fig. 4 is a schematic view of an electronic device 40 according to an embodiment of the present invention, which is only illustrated in fig. 4, and the embodiment of the present invention is not limited thereto. Fig. 4 is a schematic structural diagram of an embodiment of an electronic device provided in the present invention. The electronic device provided by the embodiment includes but is not limited to: computers, smart phones, tablets, personal digital assistants, servers, and server groups. As shown in fig. 4, the electronic device 40 provided in this embodiment may include: memory 401, processor 402, and bus 403. The bus 403 is used for connecting the elements.
The memory 401 stores a computer program, and when the computer program is executed by the processor 402, the computer program can implement the technical solution of the method for operating the relational database based on the C language provided by any one of the above-mentioned method embodiments.
Wherein the memory 401 and the processor 402 are electrically connected directly or indirectly to realize data transmission or interaction. For example, the components may be electrically connected to each other via one or more communication buses or signal lines, such as bus 403. The memory 401 stores therein a computer program for implementing a method for operating a relational database based on the C language, which includes at least one software functional module that can be stored in the memory 401 in the form of software or firmware, and the processor 402 executes various functional applications and data processing by running the software programs and modules stored in the memory 401.
The Memory 401 may be, but is not limited to, a Random Access Memory (RAM), a Read Only Memory (ROM), a Programmable Read-Only Memory (PROM), an Erasable Read-Only Memory (EPROM), an electrically Erasable Read-Only Memory (EEPROM), and the like. The memory 401 is used for storing programs, and the processor 402 executes the programs after receiving the execution instructions. Further, the software programs and modules in the memory 401 may also include an operating system, which may include various software components and/or drivers for managing system tasks (e.g., memory management, storage device control, power management, etc.), and may communicate with various hardware or software components to provide an operating environment for other software components.
The processor 402 may be an integrated circuit chip having signal processing capabilities. The Processor 402 may be a general-purpose Processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and so on. The various methods, steps and logic blocks disclosed in the embodiments of the present invention may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. It will be appreciated that the configuration of fig. 4 is merely illustrative and may include more or fewer components than shown in fig. 4 or have a different configuration than shown in fig. 4. The components shown in fig. 4 may be implemented in hardware and/or software.
Reference is made herein 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 hereof. For example, the various operational steps, as well as the components used to perform the operational steps, may be implemented in differing ways depending upon the particular application or consideration of any number of cost functions associated with operation of the system (e.g., one or more steps may be deleted, modified or incorporated into other steps).
Additionally, as will be appreciated by one skilled in the art, the principles herein may be reflected in a computer program product on a computer readable storage medium, which is pre-loaded 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 onto a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions which execute on the computer or other programmable data processing apparatus create means for implementing the functions specified. These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including means for implementing the function specified. The computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified.
The present invention has been described in terms of specific examples, which are provided to aid understanding of the invention and are not intended to be limiting. For a person skilled in the art to which the invention pertains, several simple deductions, modifications or substitutions may be made according to the idea of the invention.

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 (2)

* 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

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 (3)

* 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

Similar Documents

Publication Publication Date Title
CN108519967B (en) Chart visualization method and device, terminal and storage medium
CN107480198B (en) Distributed NewSQL database system and full-text retrieval method
CN108427705B (en) Electronic device, distributed system log query method and storage medium
CN110795455A (en) Dependency relationship analysis method, electronic device, computer device and readable storage medium
CN110351325B (en) Data processing method and related equipment
CN112015831A (en) Method, device and equipment for operating relational database based on C language
CN111443901B (en) Java reflection-based service expansion method and device
CN112579610A (en) Multi-data source structure analysis method, system, terminal device and storage medium
CN117349267B (en) Database migration processing method and system
CN115617773A (en) Data migration method, device and system
CN115016784B (en) Low code application multiplexing method, application analysis system, equipment and storage medium
CN114238381A (en) Data quality checking method, device and computer readable storage medium
CN113626223A (en) Interface calling method and device
CN111190551B (en) Redis data migration system, migration method, migration device and terminal
CN110704325B (en) Data processing method and device, computer storage medium and electronic equipment
CN110362630B (en) Data management method, device, equipment and computer readable storage medium
CN113407565B (en) Cross-database data query method, device and equipment
CN103678396A (en) Data backup method and device based on data models
CN113609128A (en) Method and device for generating database entity class, terminal equipment and storage medium
CN111177234A (en) Device and method for rapidly processing document type data file
CN114385145A (en) Web system back-end architecture design method and computer equipment
CN113868138A (en) Method, system, equipment and storage medium for acquiring test data
CN114115908A (en) Instruction set generation method, program analysis method, device and storage medium
CN109344166B (en) Database monitoring method, computer readable storage medium and terminal device
CN115563183B (en) Query method, query device and program product

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
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.