Welcome Guest. Please Login or Register. Apr 5th, 2018, 10:15pm
ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018. Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.
If you require a dump of the post on your message board, please come to the support board and request it.
Database style
« Thread started on: Sep 20th, 2010, 05:54am »
Hi All,
I'm writing - or rewriting - a program which uses variable length, and variable quantity of records and fields.
In my original version (written with Richard's BBCBasic for DOS) I used a single DB file with constant length records and fields. However, a recent version used individual files for each record (I know this isn't the norm). This was practical for a few records - a hundred or so - but as the number of records is getting larger, there is a radical slowing of the searching. (Other problems also occured with the seperation of records into individual files.)
I would like the new program to use just a single DB file (with maybe an index). But with the variable lengths of rec and field (and number of fields!) I am at a loss how it normally works and how I should proceed. What format and manipulation of the DB file should I use?
The code listed there is also supplied with BB4W as the example program FILING\F-INDEX.BBC. I should mention that it was written many years ago for BBC BASIC (86), by Doug Mounter, so may not represent the 'state of the art' in BBC BASIC coding!
The technique used is to have two files: a data file and an index file. It makes efficient use of the storage when the database is first created, but this gradually gets worse as records are edited. Because the record lengths are variable, editing a record involves deleting the original record from the index (and wasting the space it occupied in the data file) and adding a new record containing the edited data.
As edits take place more and more of the data file consists of 'dead' records which simply waste space. Therefore it's usual to perform a periodic 'clean up' in which the data file is rewritten with all the dead records removed, and the index file adjusted to suit. Obviously this can be time consuming when the database is large, so will probably be an overnight 'batch' job.
It's issues such as these that suggest you might be better off with a commercial database package such as MySQL or SQLite (which can be driven from BBC BASIC), especially if you anticipate the database getting very large. See for example the BB4W library SQLite3: