Summary of the invention
The shortcoming of prior art in view of the above, the object of the present invention is to provide data base management method and system in a kind of embedded system, for solving the problem that database purchase is complicated, data are easily lost, usage data storehouse causes system burden large existed in data base administration in embedded system in prior art.
For achieving the above object and other relevant objects, the invention provides data base management method in a kind of embedded system, in described embedded system, data base management method comprises: database carry out data store time, data to be stored in a table by the form of every bar record and to define form and the attribute of described every bar record; When accessing described database, the mode shared with internal memory is accessed described database and is adopted when applying for the authority of the described database of access and adds latching operation.
As a preferred embodiment of the present invention, in described embedded system, data base management method also comprises the object ID of definition data and is kept in header file by described object ID.
As a preferred embodiment of the present invention, the attribute defining described every bar record comprises definition for searching or the Record ID of any one subobject of any object or object in location database, and described Record ID is filled by predefined API.
As a preferred embodiment of the present invention, the form of array is adopted to define described Record ID.
As a preferred embodiment of the present invention, described array is one-dimension array, two-dimensional array, three-dimensional array or four-dimensional array.
For achieving the above object, the present invention also provides data base management system (DBMS) in a kind of embedded system, in described embedded system, data base management system (DBMS) comprises: database storage module, comprise table data store unit, described table data store unit is used for data being stored in a table by the form of every bar record and defining form and the attribute of described every bar record; Database access module, for arranging the mode accessing database shared with internal memory and there being application to add latching operation to when accessing the authority of described database to described database.
As a preferred embodiment of the present invention, described database storage module also comprises object ID storage unit, for defining the object ID of data and being kept in header file by described object ID.
As a preferred embodiment of the present invention, in described table data store unit, the attribute defining described every bar record comprises definition for searching or the Record ID of any one subobject of any object or object in location database, and described Record ID is filled by predefined API.
As a preferred embodiment of the present invention, the form of array is adopted to define described Record ID.
As a preferred embodiment of the present invention, described array is one-dimension array, two-dimensional array, three-dimensional array or four-dimensional array.
As mentioned above, data base management method and system in a kind of embedded system of the present invention, have following beneficial effect:
1, the present invention conveniently stores more complicated data, conveniently manage simultaneously, one whole mode table is adopted to carry out data storage, all data exist with the form of a rule record, the form of every bar record and length are not fixing, the form that data are stored like this is more simple, saves a large amount of system memory spaces simultaneously, and employing Record ID form can so that store complicated data structure simultaneously.
2, the present invention comes calling data storehouse by the mode of calling system shared drive, improves the validity of system data storage and the high efficiency of management, reduces the operation burden of system; Add database protection mechanism simultaneously, improve data manipulation safety and reliability.
Embodiment
Below by way of specific instantiation, embodiments of the present invention are described, those skilled in the art the content disclosed by this instructions can understand other advantages of the present invention and effect easily.The present invention can also be implemented or be applied by embodiments different in addition, and the every details in this instructions also can based on different viewpoints and application, carries out various modification or change not deviating under spirit of the present invention.
The object of the present invention is to provide data base management method and system in a kind of embedded system, for solving the problem that database purchase is complicated, data are easily lost, usage data storehouse causes system burden large existed in data base administration in embedded system in prior art.To principle and the embodiment of data base management method and system in a kind of embedded system of the present invention be elaborated below, and make those skilled in the art not need creative work can understand data base management method and system in a kind of embedded system of the present invention.
The present embodiment provides data base management method and system in a kind of embedded system, and the present embodiment relates to the gateway device of current household radio router, is primarily implemented in the database purchase framework in embedded wireless gateway system and access mechanism.
The major function of the present embodiment is the store and management realizing database in embedded wireless gateway equipment, based on the feature of current Linux system and the system architecture of software and application program to the demand of database, the present embodiment designs and proposes diverse data framework and access mechanism in a set of and traditional embedded system.The present embodiment is mainly used in small-sized embedded home gateway product, on the characteristic basis of embedded system characteristic and software application, achieve in home gateway a kind of newly, optimize, the database purchase that more meets gateway device and access mechanism.
The present embodiment designs and the database purchase framework of a set of embedded system proposed and access mechanism mainly achieve storage and the access of complicated data structure, by designing the method for calling of a set of effective file layout and shared drive, realizing each application program of system and data in database are accessed and management effectively, reliably.The present embodiment provides data base management method in a kind of embedded system, and particularly, as shown in Figure 1, in described embedded system, data base management method comprises the following steps.
Step S11, database carry out data store time, data to be stored in a table by the form of every bar record and to define form and the attribute of described every bar record.Adopt whole the form table, be convenient to store and management, save system resource simultaneously.
Particularly, in the present embodiment, the attribute defining described every bar record comprises definition for searching or the Record ID of any one subobject of any object or object in location database, and described Record ID is filled by predefined API.The present embodiment can so that store complicated data structure by Record ID.
Further, adopt the form of array to define described Record ID, wherein, described array is one-dimension array, two-dimensional array, three-dimensional array or four-dimensional array.
The form of what traditional database purchase form adopted is multiple tables, but for the data structure of relative complex, this mode has obvious defect, is not easy to management.
That is, storage architecture designed in data base management method in embedded system in the present embodiment conveniently stores more complicated data, conveniently manage simultaneously, adopt one whole mode table, all data exist with the form of a rule record, and the form of every bar record and length are not fixing, and such form making to store is simpler, save a large amount of system memory spaces simultaneously, also can store comparatively complicated data structure.
In addition, in the present embodiment, in described embedded system, data base management method also comprises the object ID of definition data and is kept in header file by described object ID.In the present embodiment in embedded system in data base management method, after determining file layout, need the form and the determinant attribute that define every bar record, be convenient to access and management database, need the basic object preserved to be generally structure in embedded system, a structure is exactly the object of a database.Each object has corresponding ID, i.e. an object ID, and all object IDs all define and are kept in fixing header file.The object introducing object ID is mainly convenient to searching and locating in a database to object, thus operates on it.In system operation, application program can use specific API to need the operations such as get, set to object according to object ID, and the least unit of operation is an object, i.e. a structure.Could operate some parameters wherein or variable after only obtaining whole structure.
For the object that some are special, such as object also has the data structure of subobject below, and in the process being saved in table, definition and the Record ID given adopt the form of array, can support at most 4 dimension groups, judge specifically need to operate which object with this.
Step S12, when accessing described database, the mode shared with internal memory is accessed described database and is adopted when applying for the authority of the described database of access and adds latching operation.In the present embodiment, application program, by the mode calling data storehouse of shared drive, reduces the operation burden of system; The shared drive of database is added to the protection mechanism locked, improve data manipulation safety and reliability.
Database is one piece of shared memory space in internal memory, any process or thread can by its API Access it.But the critical resource under a multi-process environment, all must lock to its any access, in critical section to its operation that conducts interviews.When application process needs accessing database, first can apply for the action locked, once other process or thread release the shared drive of database, then lock successfully, critical section can be entered critical resource is conducted interviews.If but at this moment other process is just in usage data storehouse, namely critical resource does not also discharge, so this function is by process or the thread suspension of calling this function, waits for critical resource release.
After application to the authority of accessing database, need find the object of operation and record the address and position that exist, for simple data structure, unique object ID that each data structure is corresponding, therefore can first by searching the header file of object ID, find the object ID needing service data structure, and then find the position of storage in the table of database, carry out the operations such as get, set.
For relative complex data structure, then it is obviously inadequate for only using object ID to search and locate an object, and it cannot search and locate some examples of a multi-instance object.Therefore, described Record ID is introduced.Can search according to Record ID or any one subobject of any object or object in location database.But Record ID is opaque for application program, need by specifically defined API, Record ID just can be filled, thus obtains the concrete seat of operand in database table.Thus carry out the operations such as get, set.
For realizing data base management method in above-mentioned embedded system, the present embodiment correspondence provides data base management system (DBMS) in a kind of embedded system, as shown in Figure 2, in described embedded system, data base management system (DBMS) 1 comprises: database storage module 11 and database access module 12.
Database storage module 11 comprises table data store unit 111 and object ID storage unit 112.
Described table data store unit 111, for data to be stored in a table by the form of every bar record and to define form and the attribute of described every bar record, adopts whole the form table, is convenient to store and management, saves system resource simultaneously.
Particularly, in the present embodiment, in described table data store unit 111, the attribute defining described every bar record comprises definition for searching or the Record ID of any one subobject of any object or object in location database, and described Record ID is filled by predefined API.The present embodiment can so that store complicated data structure by Record ID.
Further, adopt the form of array to define described Record ID, wherein, described array is one-dimension array, two-dimensional array, three-dimensional array or four-dimensional array.
Described object ID storage unit 112 is for defining the object ID of data and being kept in header file by described object ID.
The form of what traditional database purchase form adopted is multiple tables, but for the data structure of relative complex, this mode has obvious defect, is not easy to management.
That is, storage architecture designed in data base management method in embedded system in the present embodiment conveniently stores more complicated data, conveniently manage simultaneously, adopt one whole mode table, all data exist with the form of a rule record, and the form of every bar record and length are not fixing, and such form making to store is simpler, save a large amount of system memory spaces simultaneously, also can store comparatively complicated data structure.
In addition, in the present embodiment, in described embedded system, data base management method also comprises the object ID of definition data and is kept in header file by described object ID.In the present embodiment in embedded system in data base management method, after determining file layout, need the form and the determinant attribute that define every bar record, be convenient to access and management database, need the basic object preserved to be generally structure in embedded system, a structure is exactly the object of a database.Each object has corresponding ID, i.e. an object ID, and all object IDs all define and are kept in fixing header file.The object introducing object ID is mainly convenient to searching and locating in a database to object, thus operates on it.In system operation, application program can use specific API to need the operations such as get, set to object according to object ID, and the least unit of operation is an object, i.e. a structure.Could operate some parameters wherein or variable after only obtaining whole structure.
For the object that some are special, such as object also has the data structure of subobject below, and in the process being saved in table, definition and the Record ID given adopt the form of array, can support at most 4 dimension groups, judge specifically need to operate which object with this.
Database access module 12 is for arranging the mode accessing database shared with internal memory and there being application to add latching operation to when accessing the authority of described database to described database.In the present embodiment, application program, by the mode calling data storehouse of shared drive, reduces the operation burden of system; The shared drive of database is added to the protection mechanism locked, improve data manipulation safety and reliability.
Described database access module 12 comprises and adds lock unit, for adding latching operation when there being the authority of applying for the described database of access to described database.Database is one piece of shared memory space in internal memory, any process or thread can by its API Access it.But the critical resource under a multi-process environment, all must lock to its any access, in critical section to its operation that conducts interviews.Application process needs the action first applying for during accessing database locking, once other process or thread release the shared drive of database, then locks successfully, can enter critical section and conduct interviews to critical resource.If but at this moment other process is just in usage data storehouse, namely critical resource does not also discharge, so this function is by process or the thread suspension of calling this function, waits for critical resource release.
Described database access module 12 also comprises searches unit, the address that object and record for finding operation exist and position.After application to the authority of accessing database, need find the object of operation and record the address and position that exist, for simple data structure, unique object ID that each data structure is corresponding, therefore can first by searching the header file of object ID, find the object ID needing service data structure, and then find the position of storage in the table of database, carry out the operations such as get, set.
For relative complex data structure, then it is obviously inadequate for only using object ID to search and locate an object, and it cannot search and locate some examples of a multi-instance object.Therefore, described Record ID is introduced.Can search according to Record ID or any one subobject of any object or object in location database.But Record ID is opaque for application program, need by specifically defined API, Record ID just can be filled, thus obtains the concrete seat of operand in database table.Thus carry out the operations such as get, set.
In sum, the present invention conveniently stores more complicated data, conveniently manage simultaneously, one whole mode table is adopted to carry out data storage, all data exist with the form of a rule record, the form of every bar record and length are not fixing, the form that data are stored like this is simpler, save a large amount of system memory spaces simultaneously, employing Record ID form can so that store complicated data structure simultaneously, in addition, the present invention comes calling data storehouse by the mode of calling system shared drive, improve the validity of system data storage and the high efficiency of management, reduce the operation burden of system, add database protection mechanism simultaneously, improve data manipulation safety and reliability.So the present invention effectively overcomes various shortcoming of the prior art and tool high industrial utilization.
Above-described embodiment is illustrative principle of the present invention and effect thereof only, but not for limiting the present invention.Any person skilled in the art scholar all without prejudice under spirit of the present invention and category, can modify above-described embodiment or changes.Therefore, such as have in art usually know the knowledgeable do not depart from complete under disclosed spirit and technological thought all equivalence modify or change, must be contained by claim of the present invention.