CN101192226A - Data access method based on fixed length record database - Google Patents
Data access method based on fixed length record database Download PDFInfo
- Publication number
- CN101192226A CN101192226A CNA2006101607657A CN200610160765A CN101192226A CN 101192226 A CN101192226 A CN 101192226A CN A2006101607657 A CNA2006101607657 A CN A2006101607657A CN 200610160765 A CN200610160765 A CN 200610160765A CN 101192226 A CN101192226 A CN 101192226A
- Authority
- CN
- China
- Prior art keywords
- database
- record
- data
- file
- method based
- 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
Links
Images
Abstract
The invention provides a data access method based on a fixed length record database, including the following steps: a database file is created and written in header information; the header information includes a file header, database definition information and a record state table; according to a designated file name of the database, the database is opened and then a database instance pointer is returned; data access of the database is completed; the database is closed and all modification on the database is written back to a storage entity. Compared with the prior variable length database, the invention provides a fixed length record database with excellent random access performance and the delete and update operation in data access in particularly.
Description
Technical field
The present invention relates to the database technical field of portable terminal, be specifically related to a kind of data of database access method based on fixed-length record.
Background technology
Database is a portable terminal active data way to manage the most, restriction in view of the mobile terminal stores space, to safeguard polytype batch data in the past, mainly take following dual mode: based on the data access of memory sectors with based on the database access of variable-length record.
First kind of mode needs the DASD driver, is not easy to very much the transplanting and the maintenance of code, also causes the waste of storage space easily, so seldom use now.
The second way, adopt the variable-length record database, can avoid the waste of storage space effectively, and the database based on file is also easily transplanted, but enhancing along with mobile terminal function, the data volume that needs to safeguard significantly increases, and the variable-length record database also shows especially day by day to the performance impact of portable terminal, mainly shows following several respects:
1, data random access inefficiency: this is elongated data-base recording storage mode decision, and random access needs traversing operation; Though can improve speed by setting up indexed mode, concordance list needs often to safeguard to keep synchronous.
2, data modification inefficiency: variable-length record is when revising, and increase just need be appended to tail of file as fruit volume, and old record mark is invalid; After the multi-pass operations, can form a large amount of invalid record, the database volume also can increase.
3, database often needs to tighten, influence the Performance And Reliability of mobile terminal device, revise the defective of inefficiency in order to overcome aforementioned data, need squeeze out invalid record by tightening, but this process may cause that big section of database file is moved, may cause that equipment does not have response for a long time, this process is forced to interrupt and causes that the possibility of DBASE Destrong is also bigger.
In view of above the deficiencies in the prior art, need more efficiently data maintenance means at present, can realize the efficient access and the access of data in enormous quantities.
Summary of the invention
In order to overcome the defective of in the prior art database being safeguarded, the invention provides a kind of data of database access method based on fixed-length record.
The present invention specifically is achieved in that
A kind of data of database access method based on fixed-length record comprises the steps:
The 1st step, create database file, and write head information, described header comprises, file header, database description information, recording status table, and described file header comprises version database this shop;
The 2nd step, according to the filename in data designated storehouse, open database, open return data storehouse example pointer behind the database;
And according to database version and database description information, the memory instance of structure important information;
In the 3rd step, database is carried out data access;
In the 4th step, closing database all is written back to storage entity with all modifications to database.
In described the 1st step:
Described file header adopts the special marking sign, also comprises the word length of the computer system of creating file, high low level order, and described file header is the unit visit with the byte;
Described database description information is used for the database of record key message, comprises the dominant record number, single record size, current effective record number, record type;
Described recording status table is used for representing the state of all records in the current database.
Described recording status table comprises entry;
Described entry comprises entry head and record data body,
Described entry head, the actual size of expression record data body.
Described the 2nd step comprises the steps:
Can control whether create the non-existent database of specified file name according to the requirement of the parameter of opening database;
When opening database, also need to check,, then return failure if when incompatible version or not in valid format occurring to database version, validity.
In described the 3rd step database being carried out data access, can be to increase record, specifically comprises the steps:
Whether have invalid record position can carry out data storage, if find, then new record is write the invalid record position according to the data-recording status table if at first searching, otherwise, need behind file, append the space and write new record;
It is occupied to identify this position to upgrade the recording status table, and guarantees the synchronous of recording status table memory instance.
In described the 3rd step database being carried out data access, can be deletion record, is specially:
Recording status table correspondence position is changed to invalid, real recorded content can be determined whether according to the demand of parameter wiping, if decision is wiped, then writes down shared zone with full zero padding.
In described the 3rd step database being carried out data access, can be to upgrade data-base recording, is specially:
Calculate this according to the id of database description information and record and be recorded in actual shifts in the database file;
This record is write old record position;
Write down pairing recording status table position according to this, it is changed to effectively.
In described the 3rd step database being carried out data access, can be to search data-base recording, is specially:
According to the skew that the id of database description information and record calculates record, locating file is to this deviation post, and the size that reads fixed-length record arrives input buffering, thereby finishes searching of record.
In described the 3rd step database being carried out data access, can be to enumerate data-base recording, is specially:
Deciding according to input parameter is to enumerate one by one or begin to enumerate from the id of the record of appointment since 0 according to the id of record, up to traveling through full number according to the storehouse,
After enumerating a record, according to the skew that the id of database description information and record calculates record, locating file arrives this deviation post,
The size that reads fixed-length record arrives input buffering, thereby finishes enumerating of record.
Provide the total query function of record obtaining the data-base recording number,
Described data-base recording sum is to add up according to the recording status table.
Adopt the method for the invention, have following beneficial effect:
Increase, delete and the modification data for frequently needing, and when record size difference can be not excessive, database of the present invention can provide excellent random access performance, and it is less that data random access times is write down what influence of number, and what this advantage embodied when data volume is big is more obvious;
For the bigger application of data volume, the stochastic retrieval performance of data is influenced by the file system management mode only, to the file system based on the chain type storage organization, can be big with the data quantitative change, performance descends gradually, but the chain type storage is also relevant with the block size that chain is safeguarded, the big more performance of piece descends slow more; To file system based on the tabular form storage organization, the performance that the data quantitative change causes greatly descends very little especially, do not have difference because one-level table inquiry is consuming time, the possibility that the also only many read procedures of secondary table, three grades of tables use in embedded system is just littler.
In a word, no matter which kind of file system management mode, with respect to traditional elongated database, the method for the invention provides the random access performance of excellent performance to the database of fixed-length record, particularly deletes and upgrades operation.
Description of drawings
Fig. 1 is the basic storage organization synoptic diagram of database;
Fig. 2 is the database synoptic diagram after creating;
Fig. 3 is the view of the 1st record of database update;
Fig. 4 deletes the view of the 5th record for database;
Fig. 5 is the view of the 5th record of database lookup;
Fig. 6 is the synoptic diagram of data-recording status table;
Fig. 7 is the process flow diagram that the present invention is based on the data of database access method of fixed-length record.
Embodiment
Below in conjunction with accompanying drawing the method for the invention is described in detail:
As shown in Figure 1, be the basic storage organization of database.
File header identifies with special marking, comprises information such as version number, so that database is judged its validity when opening; Also comprise the word length of the computer system of creating file, high low level sequential scheduling, the file header part must be the unit visit with the byte.
Database description information is used for the database of record key message, as the dominant record number, and single record size, current effective record number, record type etc.;
The recording status table is used for representing the state of all records in the current database, as effective, invalid, the space is unallocated etc.
Entry comprises entry head and record data body, and the entry head shows the actual size of record data body.
Database is provided as application program general data storage means is provided, and memory contents is not carried out any restriction and hypothesis, can be text, numeral, picture, audio frequency and video or binary stream etc.; At different application, database can carry out expanded function easily, as increasing record retrieval, ordering, verification, enciphering/deciphering etc.
Database file adopts segmented mode to preserve various information, can to different application the suitable parameters setting be set easily, to avoid or to reduce the space and waste.
What database code was transplanted to that different platform mainly considers is the modification of file system access mode, and other operation belongs to platform independence substantially; The database file head has stipulated must to be the unit visit with the byte, and this has just been avoided word length and the different influence that brings of vertical parallax between the different platform.
The database file head comprises version information, so that can be backward compatible after the edition upgrading, can not cause database file parsing problem.
Increase, delete and the modification data for frequently needing, and when record size difference can be not excessive, the notebook data storehouse can provide excellent random access performance, and it is less that data random access times is write down what influence of number, and this means that also data volume more can embody its advantage when big.
For the bigger application of data volume, the stochastic retrieval performance of data is influenced by the file system management mode only.To file system based on the chain type storage organization, can descend gradually with the big performance of data quantitative change, but the chain type storage to be also relevant with the block size that chain is safeguarded, the big more performance of piece descends slow more; To file system based on the tabular form storage organization, the performance that the data quantitative change causes greatly descends very little especially, do not have difference because one-level table inquiry is consuming time, the possibility that the also only many read procedures of secondary table, three grades of tables use in embedded system is just littler.
No matter which kind of file system management mode, with respect to traditional elongated database, the notebook data storehouse can both provide excellent performance random access performance, particularly deletes, upgrades operation.
As shown in Figure 7, the operation steps of the method for the invention comprises:
The 1st step, create database file, and write head information, described header comprises file header, database description information, recording status table, described file header comprises version database this shop;
The 2nd step, according to the filename in data designated storehouse, open database, open return data storehouse example pointer behind the database, and according to database version and database description information, the memory instance of structure important information;
In the 3rd step, database is carried out data access;
In the 4th step, closing database all is written back to storage entity with all modifications to database.
The detail operations step of described database comprises:
Before using, creates database database file earlier, and write head information, comprising file header, database description information and complete data-recording status table, be sky in the state table this moment, and the space of entry is not distributed, and the database after the establishment is as shown in Figure 2.
(1) database increase/deletion record process
A, open database:
According to data designated library file name, open database, can control whether create the non-existent database of specified file name according to the requirement of opening parameter.Open database and also comprise inspections such as database version, validity, when incompatible version or not in valid format occurring, can return failure.According to version and database description information, the memory instance of structure important information is opened return data storehouse, back example pointer and is manipulated for other so that random access performance efficiently to be provided in addition.
B, interpolation record:
When increasing record, at first search an invalid record position and store according to the data-recording status table; If find then new record write the invalid record position; Otherwise need behind file, append the space and write new record.After upgrading or appending, it is occupied to identify this position all to need to upgrade the recording status table, and guarantee recording status table memory instance synchronously, the state that database adds the 1st record is as shown in Figure 3.
C, deletion record:
During notebook data storehouse deletion record, operate very simple, only need be changed to invalid getting final product to recording status table correspondence position, real recorded content can determine whether according to the demand of parameter wiping, erase process writes down shared zone with full zero padding exactly, and the state that database is deleted the 5th record as shown in Figure 4.
D, closing database:
After finishing visit, need closing database, main operation is exactly to guarantee normally closing of database file, with and all modifications all be written back to storage entity.
(2) database update/search/enumerate recording process:
Opening and closing database is the prerequisite of all operations, and particular content is the same, because be fixed-length record, need not to worry that new record can't write the position of old record.At first calculate this during renewal and be recorded in actual shifts in the database file according to the id of database description information and record, new record is write old record position, should write down pairing recording status table position then, it was changed to effectively same Fig. 3 of state of the 1st record of database update.
Search procedure also is the skew of calculating record according to the id of database description information and record, and locating file is to this deviation post, and the size that reads fixed-length record arrives input buffering, thereby finishes searching of record.Same Fig. 5 of state of the 5th record of database lookup.
It is to enumerate one by one or from specifying id to begin to enumerate since 0 according to id that enumeration process decides according to input parameter, up to the traversal full number according to the storehouse.After enumerating a certain record, operation and search procedure are just the same.
(3) database non-productive operation process:
For the ease of obtaining the data-base recording number, provide record total query function, different with the general data storehouse, the number of record is not a certain position that directly is stored in database, but adds up according to the recording status table, as shown in Figure 6, have 5 effective records, 2 invalid record, other spaces are still unallocated, can guarantee that like this sum that obtains is accurately, and the invalid data that brings when helping to reject the database abnormal operation.
The database that the present invention realized is based on fixed-length record, and this has also limited its range of application, such as inapplicable data volume seldom, record only increases and need not revise or a situation that record size difference is excessive, the notebook data storehouse just is difficult to embody its advantage, as daily record data.
Claims (10)
1. the data of database access method based on fixed-length record is characterized in that, comprises the steps:
The 1st step, create database file, and write head information, described header comprises file header, database description information, recording status table, described file header comprises version database this shop;
The 2nd step, according to the filename in data designated storehouse, open database, open return data storehouse example pointer behind the database, and according to database version and database description information, the memory instance of structure important information;
In the 3rd step, database is carried out data access;
In the 4th step, closing database all is written back to storage entity with all modifications to database.
2. the data of database access method based on fixed-length record as claimed in claim 1 is characterized in that, in the 1st step:
Described file header adopts the special marking sign, also comprises the word length of the computer system of creating file, high low level order;
Described file header is the unit visit with the byte;
Described database description information is used for the database of record key message, comprises the dominant record number, single record size, current effective record number, record type;
Described recording status table is used for representing the state of all records in the current database.
3. the data of database access method based on fixed-length record as claimed in claim 2 is characterized in that:
Described recording status table comprises entry;
Described entry comprises entry head and record data body;
Described entry head, the actual size of expression record data body.
4. the data of database access method based on fixed-length record as claimed in claim 1 is characterized in that, described the 2nd step comprises the steps:
Can control whether create the non-existent database of specified file name according to the requirement of the parameter of opening database;
When opening database, also need to check,, then return failure if when incompatible version or not in valid format occurring to database version, validity.
5. the data of database access method based on fixed-length record as claimed in claim 1 is characterized in that, in described the 3rd step database is carried out data access, can be to increase record, specifically comprises the steps:
Whether have invalid record position can carry out data storage, if find, then new record is write the invalid record position according to the data-recording status table if at first searching, otherwise, need behind file, append the space and write new record;
It is occupied to identify this position to upgrade the recording status table, and guarantees the synchronous of recording status table memory instance.
6. the data of database access method based on fixed-length record as claimed in claim 1 is characterized in that, in described the 3rd step database is carried out data access, can be deletion record, is specially:
Recording status table correspondence position is changed to invalid, real recorded content can be determined whether according to the demand of parameter wiping, if decision is wiped, then writes down shared zone with full zero padding.
7. the data of database access method based on fixed-length record as claimed in claim 1 is characterized in that: in described the 3rd step database being carried out data access, can be to upgrade data-base recording, is specially:
Calculate this according to the id of database description information and record and be recorded in actual shifts in the database file;
This record is write old record position;
Write down pairing recording status table position according to this, it is changed to effectively.
8. the data of database access method based on fixed-length record as claimed in claim 1 is characterized in that, in described the 3rd step database is carried out data access, can be to search data-base recording, is specially:
According to the skew that the id of database description information and record calculates record, locating file is to this deviation post, and the size that reads fixed-length record arrives input buffering, thereby finishes searching of record.
9. the data of database access method based on fixed-length record as claimed in claim 1 is characterized in that: in described the 3rd step database being carried out data access, can be to enumerate data-base recording, is specially:
Deciding according to input parameter is to enumerate one by one or begin to enumerate from the id of the record of appointment since 0 according to the id of record, up to traveling through full number according to the storehouse,
After enumerating a record, according to the skew that the id of database description information and record calculates record, locating file arrives this deviation post,
The size that reads fixed-length record arrives input buffering, thereby finishes enumerating of record.
10. the data of database access method based on fixed-length record as claimed in claim 1 is characterized in that:
Provide the total query function of record obtaining the data-base recording number,
Described data-base recording sum is to add up according to the recording status table.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CNA2006101607657A CN101192226A (en) | 2006-12-01 | 2006-12-01 | Data access method based on fixed length record database |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CNA2006101607657A CN101192226A (en) | 2006-12-01 | 2006-12-01 | Data access method based on fixed length record database |
Publications (1)
Publication Number | Publication Date |
---|---|
CN101192226A true CN101192226A (en) | 2008-06-04 |
Family
ID=39487222
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CNA2006101607657A Pending CN101192226A (en) | 2006-12-01 | 2006-12-01 | Data access method based on fixed length record database |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN101192226A (en) |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102708194A (en) * | 2012-05-16 | 2012-10-03 | 河南辉煌科技股份有限公司 | Access method of binary file |
CN103778188A (en) * | 2013-12-31 | 2014-05-07 | 网秦(北京)科技有限公司 | Method and equipment for inquiring and/or maintaining data in library file |
CN113641709A (en) * | 2021-08-11 | 2021-11-12 | 杭州安恒信息技术股份有限公司 | Database data writing method, database data reading method and database |
CN114546942A (en) * | 2022-01-28 | 2022-05-27 | 苏州浪潮智能科技有限公司 | Database data reading method and device, terminal and storage medium |
-
2006
- 2006-12-01 CN CNA2006101607657A patent/CN101192226A/en active Pending
Cited By (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102708194A (en) * | 2012-05-16 | 2012-10-03 | 河南辉煌科技股份有限公司 | Access method of binary file |
CN102708194B (en) * | 2012-05-16 | 2016-02-10 | 河南辉煌科技股份有限公司 | The access method of binary file |
CN103778188A (en) * | 2013-12-31 | 2014-05-07 | 网秦(北京)科技有限公司 | Method and equipment for inquiring and/or maintaining data in library file |
CN113641709A (en) * | 2021-08-11 | 2021-11-12 | 杭州安恒信息技术股份有限公司 | Database data writing method, database data reading method and database |
CN114546942A (en) * | 2022-01-28 | 2022-05-27 | 苏州浪潮智能科技有限公司 | Database data reading method and device, terminal and storage medium |
CN114546942B (en) * | 2022-01-28 | 2024-01-19 | 苏州浪潮智能科技有限公司 | Database data reading method, device, terminal and storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN102184229B (en) | Memory data storage method of huge RFID (Radio Frequency Identification Device) label information | |
US9507821B2 (en) | Mail indexing and searching using hierarchical caches | |
CN105373541B (en) | The processing method and system of the data operation request of database | |
CN107870973A (en) | A kind of document storage system accelerated multi-path monitoring and played back simultaneously | |
CN103294615B (en) | A kind of method for storing set-top box users information | |
US20160055189A1 (en) | Database Storage System based on Optical Disk Library, and Method Using Same | |
EP1973044A1 (en) | Method for accessing the data in xml file | |
CN100507919C (en) | FAT file system and its processing method | |
CN104270605B (en) | A kind of processing method and processing device of video monitoring data | |
CN101707633A (en) | Message-oriented middleware persistent message storing method based on file system | |
CN108763531A (en) | A kind of MDVR document storage systems and its operation method | |
CN103810246A (en) | Index building method and device and index query method and device | |
CN101192226A (en) | Data access method based on fixed length record database | |
CN105447168A (en) | Method for restoring and recombining fragmented files in MP4 format | |
CN103500206A (en) | Storage method and device based on file storage data | |
US8386539B2 (en) | Variable length data storage device, variable length data storage method, variable length data reading method, and a program for the same | |
CN101303667B (en) | Method and device for establishing magnetic disk null cluster table and seeking magnetic disk null cluster | |
CN100543748C (en) | A kind of method and system of utilizing file allocation table to carry out the file tracking | |
CN103902228A (en) | Variable-length data accessing method | |
CN101996161B (en) | A kind of old version data processing method of electronic document and device | |
CN105653385B (en) | A kind of vehicle-mounted kinescope method | |
CN101853278A (en) | Application method of data storage system | |
CN108140047B (en) | Data processing apparatus and method, and data container structure | |
CN108776578B (en) | Method and system for rapidly merging objects | |
US7672982B2 (en) | Systems, methods, and computer-usable medium for defragmenting a windows NT file system volume |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C02 | Deemed withdrawal of patent application after publication (patent law 2001) | ||
WD01 | Invention patent application deemed withdrawn after publication |
Open date: 20080604 |