Summary of the invention
In view of the foregoing deficiencies of prior art, the purpose of the present invention is to provide databases in a kind of embedded system
Management method and system, it is multiple for solving database purchase present in data base administration in embedded system in the prior art
The problem that miscellaneous, data are easily lost, are caused system burden big using database.
In order to achieve the above objects and other related objects, the present invention provides data base administration side in a kind of embedded system
Method, data base management method includes: when database carries out data storage, by data by every record in the embedded system
Form be stored in a table and define it is described every record format and attribute;When accessing the database, with memory
Shared mode accesses the database and in permission of the application to the access database using locking operation.
As a preferred solution of the present invention, data base management method further includes defining data in the embedded system
Object ID and the object ID is stored in header file.
As a preferred solution of the present invention, the attribute for defining every record includes definition for searching or positioning
The Record ID of any one subobject of any object or object in database, the Record ID by predefined API into
Row filling.
As a preferred solution of the present invention, the Record ID is defined using the format of array.
As a preferred solution of the present invention, the array is one-dimension array, two-dimensional array, three-dimensional array or four dimensions
Group.
To achieve the above object, described embedded the present invention also provides data base management system in a kind of embedded system
Data base management system includes: database storage module, including table data store unit, the table data store unit in system
Form for recording data by every is stored in a table and defines the format and attribute of every record;Database
Access modules access database and in the permission for having application to the access database for being arranged in a manner of memory sharing
Locking operation is carried out to the database.
As a preferred solution of the present invention, the database storage module further includes object ID storage unit, is used for
It defines the object ID of data and the object ID is stored in header file.
As a preferred solution of the present invention, in the table data store unit, the category of every record is defined
Property include definition for search or location database in any one subobject of any object or object Record ID, it is described
Record ID is filled by predefined API.
As a preferred solution of the present invention, the Record ID is defined using the format of array.
As a preferred solution of the present invention, the array is one-dimension array, two-dimensional array, three-dimensional array or four dimensions
Group.
As described above, data base management method and system in a kind of embedded system of the invention, have below beneficial to effect
Fruit:
1, the present invention stores increasingly complex data for convenience, while managing for convenience, using the side of one whole table
Formula carries out data storage, and all data exist in the form that a rule records, and every format recorded and length are not fixed
, such form that data are stored is simpler, while saving a large amount of system memory space, while using record
ID form can be in order to storing complicated data structure.
2, the present invention calls database by way of calling system shared drive, improves having for system data storage
The high efficiency of effect property and management reduces the operation burden of system;It joined database protection mechanism simultaneously, improve data behaviour
Make security and reliability.
Specific embodiment
Illustrate embodiments of the present invention below by way of specific specific example, those skilled in the art can be by this specification
Other advantages and efficacy of the present invention can be easily understood for disclosed content.The present invention can also pass through in addition different specific realities
The mode of applying is embodied or practiced, the various details in this specification can also based on different viewpoints and application, without departing from
Various modifications or alterations are carried out under spirit of the invention.
It is existing for solving the purpose of the present invention is to provide data base management method and system in a kind of embedded system
The complexity of database purchase present in data base administration, data are easily lost, are led using database in embedded system in technology
The problem for causing system burden big.Data base management method and system in a kind of embedded system of the invention described in detail below
Principle and embodiment, so that those skilled in the art is not needed creative work and be appreciated that a kind of embedded system of the invention
Data base management method and system in system.
The present embodiment provides data base management method and system in a kind of embedded system, the present embodiment relate to current household without
The gateway of line router, database purchase framework and the access mechanism being primarily implemented in embedded wireless gateway system.
The major function of the present embodiment is to realize the storage and management of database in embedded wireless gateway equipment, based on working as
Demand of the system structure and application program of the characteristics of preceding Linux system and software to database, the present embodiment are designed and are mentioned
Data framework and access mechanism entirely different in a set of and traditional embedded system are gone out.The present embodiment is mainly used in small-sized
Embedded home gateway product realize on the basis of embedded system characteristic and the characteristic of software application in family
A kind of new, optimization, being more in line with gateway database purchase and access mechanism in gateway.
The present embodiment designs and the database purchase framework of a set of embedded system and access mechanism proposed is mainly realized
Complicated data structure stores and accesses, by designing the method for calling of a set of effective storage form and shared drive,
To realize that each application program of system effectively, is reliably accessed and managed to data in database.The present embodiment provides a kind of embedding
Data base management method in embedded system, specifically, as shown in Figure 1, data base management method includes in the embedded system
Following steps.
The form that data are recorded by every is stored in a table simultaneously by step S11 when database carries out data storage
Define the format and attribute of every record.Using the form of whole table, it is convenient for storage and management, while saves system money
Source.
Specifically, in the present embodiment, the attribute for defining every record is used to search including definition or location data
The Record ID of any one subobject of any object or object, the Record ID are filled out by predefined API in library
It fills.The present embodiment can be in order to storing complicated data structure by Record ID.
Further, the Record ID is defined using the format of array, wherein the array is one-dimension array, two dimension
Array, three-dimensional array or four-dimensional array.
Traditional database purchase form using multiple tables form, but for relative complex data structure,
This mode has the obvious disadvantage that, is not easy to manage.
That is, storage architecture designed in data base management method in embedded system in the present embodiment is for side
Just increasingly complex data are stored, while being managed for convenience, by the way of one whole table, all data are remembered with a rule
The form of record exists, the format and length of every record be not it is fixed, such form for making storage is simpler, simultaneously
A large amount of system memory space is saved, also can store more complicated data structure.
In addition, in the present embodiment, data base management method further includes the object for defining data in the embedded system
The object ID is simultaneously stored in header file by ID.In the present embodiment in embedded system in data base management method, determine
It after storage form, needs to define the format and determinant attribute of every record, comes easily accessible and management database, embedded system
Middle that the basic object saved is needed to be generally structure, a structure is exactly the object of a database.It is each right
As having a corresponding ID, i.e. object ID, all object IDs are all defined and are stored in fixed header file.Introducing pair
As ID purpose mainly be convenient in the database to the lookup of object and positioning, to operate on it.It is transported in system
During row, application program can carry out object using specific API according to object ID that get, set etc. is needed to operate, operation
Minimum unit be an object, i.e. a structure.Only obtaining entire structure later could be to therein
Some parameter or variable are operated.
For some special objects, for example there are also the data structures of subobject below for object, in the process for being saved in table
In, definition and the Record ID assigned use the form of array, can at most support 4 dimension groups, judge specifically to need to operate with this
Which object.
Step S12 is accessed the database in a manner of memory sharing and visited in application when accessing the database
Using locking operation when asking the permission of the database.In the present embodiment, application program calls number by way of shared drive
According to library, the operation burden of system is reduced;The protection mechanism that joined locking to the shared drive of database improves data behaviour
Make security and reliability.
Database is one piece of shared memory space in memory, and any process or thread can pass through its API Access
It.But the critical resource under a multi-process environment, its any access must all be locked, it is visited in critical zone
Ask operation.When application process needs to access database, it can apply for the movement locked first, once other processes or thread release
The shared drive of database, then lock success, can enter critical zone and access to critical resource.But if at this moment other
Database is used in process, i.e. critical resource discharges not yet, then the function will be the process or line for calling the function
Journey is hung up, and critical resource release is waited.
Apply needing to find the object of operation to after the permission of access database and record existing address and position,
For simple data structure, the corresponding unique object ID of each data structure, therefore lookup object ID can be first passed through
Header file, to find the object ID for needing operation data structure, and then the position of storage is found in the table of database, carry out
The operation such as get, set.
For relative complex data structure, then only use object ID search and position an object be clearly it is inadequate,
Its some example that can not search and position a multi-instance object.Therefore, the Record ID is introduced.It can according to Record ID
With any object in lookup or location database or any one subobject of object.However, Record ID is for applying journey
Sequence be it is opaque, need through specifically defined API, Record ID can be just filled, to obtain operation object in database
Specific seat in table.To carry out the operation such as get, set.
To realize data base management method in above-mentioned embedded system, the present embodiment correspondence provides a kind of embedded system
Data base management system in system, as shown in Fig. 2, data base management system 1 includes: database purchase mould in the embedded system
Block 11 and database access module 12.
Database storage module 11 includes table data store unit 111 and object ID storage unit 112.
The table data store unit 111 is used to for the form that data are recorded by every being stored in a table and defines institute
The format and attribute for stating every record are convenient for storage and management using the form of whole table, while saving system resource.
Specifically, in the present embodiment, in the table data store unit 111, the attribute of every record is defined
Including define for search or location database in any one subobject of any object or object Record ID, the note
Record ID is filled by predefined API.The present embodiment can be in order to storing complicated data structure by Record ID.
Further, the Record ID is defined using the format of array, wherein the array is one-dimension array, two dimension
Array, three-dimensional array or four-dimensional array.
The object ID storage unit 112 is used to define the object ID of data and the object ID is stored in header file
In.
Traditional database purchase form using multiple tables form, but for relative complex data structure,
This mode has the obvious disadvantage that, is not easy to manage.
That is, storage architecture designed in data base management method in embedded system in the present embodiment is for side
Just increasingly complex data are stored, while being managed for convenience, by the way of one whole table, all data are remembered with a rule
The form of record exists, the format and length of every record be not it is fixed, such form for making storage is simpler, simultaneously
A large amount of system memory space is saved, also can store more complicated data structure.
In addition, in the present embodiment, data base management method further includes the object for defining data in the embedded system
The object ID is simultaneously stored in header file by ID.In the present embodiment in embedded system in data base management method, determine
It after storage form, needs to define the format and determinant attribute of every record, comes easily accessible and management database, embedded system
Middle that the basic object saved is needed to be generally structure, a structure is exactly the object of a database.It is each right
As having a corresponding ID, i.e. object ID, all object IDs are all defined and are stored in fixed header file.Introducing pair
As ID purpose mainly be convenient in the database to the lookup of object and positioning, to operate on it.It is transported in system
During row, application program can carry out object using specific API according to object ID that get, set etc. is needed to operate, operation
Minimum unit be an object, i.e. a structure.Only obtaining entire structure later could be to therein
Some parameter or variable are operated.
For some special objects, for example there are also the data structures of subobject below for object, in the process for being saved in table
In, definition and the Record ID assigned use the form of array, can at most support 4 dimension groups, judge specifically to need to operate with this
Which object.
Database access module 12 is accessed database for setting in a manner of memory sharing and is having application to access institute
Locking operation is carried out to the database when stating the permission of database.In the present embodiment, side that application program passes through shared drive
Formula calls database, reduces the operation burden of system;It joined the protection mechanism of locking to the shared drive of database, improve
Data manipulation security and reliability.
The database access module 12 includes locking unit, for when there is permission of the application to the access database
Locking operation is carried out to the database.Database is one piece of shared memory space in memory, and any process or thread are all
Can by its API Access it.But the critical resource under a multi-process environment, its any access must all be locked,
It accesses to it operation in critical zone.Application process can apply for the movement locked first when needing to access database, once its
His process or thread release the shared drive of database, then lock success, can enter critical zone and carry out to critical resource
Access.But if at this moment database is used in other process, i.e. critical resource discharges not yet, then the function will be calling
The process or thread suspension of the function wait critical resource release.
The database access module 12 further includes searching unit, the existing ground of object and record for finding operation
Location and position.Apply needing to find the object of operation to after the permission of access database and record existing address and position,
For simple data structure, the corresponding unique object ID of each data structure, therefore lookup object ID can be first passed through
Header file, to find the object ID for needing operation data structure, and then the position of storage is found in the table of database, carry out
The operation such as get, set.
For relative complex data structure, then only use object ID search and position an object be clearly it is inadequate,
Its some example that can not search and position a multi-instance object.Therefore, the Record ID is introduced.It can according to Record ID
With any object in lookup or location database or any one subobject of object.However, Record ID is for applying journey
Sequence be it is opaque, need through specifically defined API, Record ID can be just filled, to obtain operation object in database
Specific seat in table.To carry out the operation such as get, set.
In conclusion the present invention stores increasingly complex data for convenience, while managing for convenience, using one whole
The mode of table carries out data storage, and all data exist in the form that a rule records, and every format recorded and length are not
Be it is fixed, such form that data are stored is simpler, while saving a large amount of system memory space, adopts simultaneously
It can be in order to store complicated data structure, in addition, the present invention is by way of calling system shared drive with Record ID form
Database is called, the validity of system data storage and the high efficiency of management are improved, reduces the operation burden of system;Together
When joined database protection mechanism, improve data manipulation security and reliability.So the present invention effectively overcomes existing skill
Various shortcoming in art and have high industrial utilization value.
The above-described embodiments merely illustrate the principles and effects of the present invention, and is not intended to limit the present invention.It is any ripe
The personage for knowing this technology all without departing from the spirit and scope of the present invention, carries out modifications and changes to above-described embodiment.Cause
This, institute is complete without departing from the spirit and technical ideas disclosed in the present invention by those of ordinary skill in the art such as
At all equivalent modifications or change, should be covered by the claims of the present invention.