dbase: Database system functions

Here are the low level functions for handling the database.

Future development

There is room for improvements to the speed of some of this functions. In the final version of the language some checks could be thrown out. But meanwhile it is better to check everything twice so errors can be dealt with.

Known bugs

Handling of longer indexes Indexes that get too long don't behave right. It a record is edited there is one record overwritten and the old record is left. It looks like the routine to fetch the next record is not correct for the new leafs in the index tree.

Global dbstate [Read Add Edit Update] 
  
Routine showidxs Show then contence of the indexes to a table
    table number Table to use
  
Routine ptrinfo Get the contence of a pointer in readable form
    ptr pointer The pointer to read
    returns: string A string with the contence
  
Routine getrec Get the recordnumber part of a pointer
    ptr pointer The pointer
    index number 
    returns: number 
  
Routine tablelen get the length of a table
    table number the table
    returns: number the length or 0 if no table found
  
Routine maxbranch 
    index number 
    returns: number 
  
Routine maxleaf 
    branch number 
    index number 
    returns: number 
  
Global log stream 
  
Routine initdb initiate the database
    tables number the current number of tables
    indexes number the current number of indexes
  
Routine addrecord adds a record to a table
    table number the table to use
    returns: pointer a field-pointer to the new record
  
Routine cpyrecord adds a record to a table
    ptr pointer pointer to the current record
    table number the table to alter
    returns: pointer a pointer to the new record
  
Routine deleterecord deletes the contents of a record
    record number the record to delete
    table number the table to use
  
Routine changeindex change the value in an index
    ptr pointer 
    rec number 
    index number 
  
Routine searchindex calculate new search position
    current number position where was searched last
    level byte level of the search from 1 till last=current
    check byte is the current value higher or lower or the same
    max number number of elements in the index
    returns: number new position to search from or null when end
  
Routine getrecptr get a pointer to a record number
    rec number 
    table number 
    returns: pointer the created pointer
  
Routine getpointer get a pointer value
    branch number 
    leaf number 
    index number 
    returns: pointer the created pointer
  
Routine getbranch 
    ptr pointer 
    returns: number 
  
Routine ptrmin1 
    ptr pointer 
    index number 
    returns: pointer 
  
Routine recalcptr 
    ptr pointer 
    index number 
    returns: pointer 
  
Routine ptrplus1 
    ptr pointer 
    index number 
    returns: pointer 
  
Routine subptr 
    val number 
    index number 
    branch number 
    diff number 
  
Routine addptr 
    val number 
    index number 
    branch number 
    leaf number 
    old number 
  
Routine addindex add record to an index
    ptr pointer pointer to the new position in the index
    rec number record number to add
    index number the index to add to
  
Routine mergeleft 
    ptr pointer pointer to the old position in the index
    index number the index to delet from
  
Routine mergeright 
    ptr pointer pointer to the old position in the index
    index number the index to delet from
  
Routine deleteindex add record to an index
    ptr pointer pointer to the old position in the index
    index number the index to delet from
  
Copyright (C) 2001 Jurjen J. Stellingwerff