BBC BASIC for Windows
« Database style »

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.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Database style  (Read 1738 times)
Matt
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 210
xx 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?

Matt
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Database style
« Reply #1 on: Sep 20th, 2010, 08:43am »

on Sep 20th, 2010, 05:54am, Matt wrote:
I am at a loss how it normally works and how I should proceed.

The main Help documentation discusses this issue, in the section entitled 'Disk Files... Indexed data files':

http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin9.html#indexed

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:

http://bb4w.wikispaces.com/Libraries

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls