A direct access database system

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

A direct access database system

Post by Henko »

Back in the late sixties (1966-1969) i was a Fortran programmer on one of the first IBM 360 series mainframes in the Netherlands. For those who have little idea about the hardware in those days: the 360/30 CPU was a 32-bit system, running at about 1 Megaherz, internal memory was 64 Kbytes, 4 removable discdrives at 7.2 Mbytes each, some tape-units, and a lineprinter. All this in a computerroom of some 100 m2.
Hence, capacity was at a premium, which affected programming style and data organization.
One such consequence was that files always had to reside on disc (DASD in IBM talk). Loading data files in large arrays for processing was mostly out of the question.
For that reason we used a standard IBM file organization, ISAM, ("indexed sequential access method"), when we needed direct access to records in the file, or BDAM ("basic direct access method") with an extra, self written, layer for logical access.
This last method is described herafter, and the method is interesting enough (for me, that is) to do the coding once again, but now in SmartBasic.

The basic organization is shown in the following picture.
IMG_1316.JPG
IMG_1316.JPG (1.08 MiB) Viewed 6329 times
The DB (database) consists of a number of fixed length "slots". One slot contains one record. The "logical" access consists of a key, which may be one field or a combination of fields out of the record. This key is as such added to the slot. Finally, a link field is added to enable a "linked list" mechanism. So, a slot contains 3 strings.
Physical access is by a simple adress (or file-pointer) in the linear adress space of the file. It is simply: adress = slotnumber x slotsize.
The mapping of the (large) logical key-space into the relatively small slotnumber-space is done with a hashing algorithm. The input is a lengthy complex key, out comes a simple slotnumber which fits in what is called the "primary" area of the DB.
It is always possible that two or even more different logical keys are mapped into the same slotnumber. Those "synonimes" are then placed into a "secondary" or "overflow" area, connected with the parent record in the primary area using a linked list method see figure).

The advantage of packing the fields of a record in one string is that the "low level" functions to create and maintain the DB are independent from the actual record
lay-out. I will gradually provide some basic functions, starting with creation of a DB and adding records to the DB. Later on: deletion of records, getting records for updates and write them back. "Low level" : those functions handle entire records in the form of a string. It's to the user to do the user interface and to assemble and disassemble the string from and into the specific record lay-out. Just for testing I use a testcase in the form of some "personnel" records with a simple lay-out: Surname, name, department, age, salary. In my testprogram, the test-DB is fed 9 records from a read_data construct, instead from a normal "add record" panel.
The number of slots might be chosen between 1x and 2x the expected amount of records to be stored in the DB. At 1x #records, about 60% of the records will be placed in the primary area and 40% in the overflow area (causing a few extra accesses to the DB).

Currently there are 4 functions that are normally used by the user:
- create_db(filename,DBname,slotsize,expected # of records) for creating a new DB
- db(filename) for opening an existing DB
- add_rec(key,record) for adding records to the DB
- get_rec$(key) for retrieving record with key <key>

The other functions are "low level" functions, used by the above mentioned functions.

Coming up: edit_rec(...) and del_rec(...)

Code: Select all

first_time=0
dim field$(5)   ' test DB has staff records with 5 fields
f$="testdb"

if first_time then
  create_db(f$,"Test_database",50,10)
  for i=0 to 8
    read rec$
    split rec$ to field$,n with " "  ' to extract the key
    key$=field$(1)
    add_rec(key$,rec$)
    next i
  data "John Friedman    sales      32  4500  "
  data " Betty Longa     ledger     28  3700"
  data " Ann Strady    sales      43  5300  "
  data "John-John Brady  production 25  3250  "
  data "   Lydia Carter  sales      36  3300 "
  data "  Peter Pan    R&D    48   4100"
  data " Reginald Nobody  production  23 3100  "
  data " Mary Poppins  sales  29  3650 "
  data " Elly Sunshine   production  32 3560 "
  end if
db(f$)     ' open database f$
do
  input "Name? ": key$
  if key$="stop" or key$="Stop" then break
  record$=get_record$(key$)
  if record$="not found" then
    print ! print record$ ! continue
    end if
  split record$ to field$,n with " "
  print
  print "surname    - " & field$(0)
  print "name       - " & field$(1)
  print "department - " & field$(2)
  print "age        - " & field$(3)
  print "salary     - " & field$(4)
  until forever
end


' Create a direct access database with fixed length slots
' fn$      - filename on "disc"
' db_name$ - database name for readability
' S_size   - slotsize for key + record + link fields
' N_rec    - estimated max. # of records
'
def create_db(fn$,db_name$,S_size,N_rec)
N_prim=N_rec          ' # of slots in primary area
S_free=N_rec+1        ' initial first free slot
'
dim slot(S_size)
if file_exists(fn$) then file fn$ delete
'
   ' create space for the database
for i=0 to N_prim ! file fn$ writedim slot ! next i
'
   ' write slot number 0 with meta data
file fn$ setpos 0
file fn$ writeline db_name$,str$(S_size),str$(N_prim),str$(S_free)
'
   ' init the slots in the primary area
for i=1 to N_rec
  file fn$ setpos S_size*i
  file fn$ writeline "","","0"
  next i
db(fn$)
end def

def db(fn$)       ' open database f$ (read meta data in slot 0)
file fn$ setpos 0
file fn$ readline db_name$,size$,prim$,free$
S_size=size$ ! N_prim=prim$ ! S_free=free$
end def

def add_rec(key$,rec$)
adr=get_adr(key$)
if adr>0 then return -1    ' record with same key already present
if adr<0 then              ' free slot in primary area
  adr=-adr
  file db.fn$ setpos adr*db.S_size
  file db.fn$ writeline key$,rec$,"0"
  return adr
  end if
new=hash(key$)
file db.fn$ setpos new*db.S_size
file db.fn$ readline aux$,trec$,link$
rec_to=get_1st_free()
file db.fn$ setpos rec_to*db.S_size ! file db.fn$ writeline "   "
file db.fn$ setpos rec_to*db.S_size
file db.fn$ writeline key$,rec$,link$
file db.fn$ setpos new*db.S_size
file db.fn$ writeline aux$,trec$,str$(rec_to)
put_1st_free(rec_to+1)
end def

' retrieve record with key <key$> from the DB
' returns <not found> if not found
'
def get_record$(key$)
slot=get_adr(key$)
if slot>0 then 
  file db.fn$ setpos slot*db.S_size
  file db.fn$ readline t$,rec$,t$
  return rec$
  else
  return "not found"
  end if
end def

' find adress of record with given key
' key$ - the key on which to search
' function returns one of 3 values:
' adr > 0 : record found in slot <adr>    (update or delete record)
' adr = 0 : no record found with that key  (error key or add new record)
' adr < 0 : not found, but slot <abs(adr)> is free (add new record)
'
def get_adr(key$)
adr=hash(key$)
while adr>0
  file db.fn$ setpos adr*db.S_size
  file db.fn$ readline aux$,rec$,link$
  if aux$=key$ then return adr
  if aux$="" then return -adr
  adr=val(link$)
  end while
return 0
end def

' returns the adress of the first free slot
'
def get_1st_free()
file db.fn$ setpos 0
file db.fn$ readline t$,t$,t$,t$
return val(t$)
end def

' edits the adress of the first free slot
'
def put_1st_free(adr)
file db.fn$ setpos 0
file db.fn$ readline  t1$,t2$,t3$,t4$
file db.fn$ setpos 0
file db.fn$ writeline t1$,t2$,t3$,str$(adr)
return
end def

' transform key tt$ into a DB adress (slotnumber)
'
def hash(tt$)
nt=len(tt$) ! adr=1
for i=0 to nt-1 ! adr+=asc(mid$(tt$,i,1))-32 ! adr*=7 ! next i
return 1+adr%db.N_prim
end def


Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: A direct access database system

Post by Henko »

The variable "first_time" should be set at value 1 the first time, instead of 0

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: A direct access database system

Post by Henko »

Henko wrote:Back in the late sixties (1966-1969) i was a Fortran programmer on one of the first IBM 360 series mainframes in the Netherlands. For those who have little idea about the hardware in those days: the 360/30 CPU was a 32-bit system, running at about 1 Megaherz, internal memory was 64 Kbytes, 4 removable discdrives at 7.2 Mbytes each, some tape-units, and a lineprinter. All this in a computerroom of some 100 m2.
Hence, capacity was at a premium, which affected programming style and data organization.
One such consequence was that files always had to reside on disc (DASD in IBM talk). Loading data files in large arrays for processing was mostly out of the question.
For that reason we used a standard IBM file organization, ISAM, ("indexed sequential access method"), when we needed direct access to records in the file, or BDAM ("basic direct access method") with an extra, self written, layer for logical access.
This last method is described herafter, and the method is interesting enough (for me, that is) to do the coding once again, but now in SmartBasic.

The basic organization is shown in the following picture.

IMG_1316.JPG

The DB (database) consists of a number of fixed length "slots". One slot contains one record. The "logical" access consists of a key, which may be one field or a combination of fields out of the record. This key is as such added to the slot. Finally, a link field is added to enable a "linked list" mechanism. So, a slot contains 3 strings.
Physical access is by a simple adress (or file-pointer) in the linear adress space of the file. It is simply: adress = slotnumber x slotsize.
The mapping of the (large) logical key-space into the relatively small slotnumber-space is done with a hashing algorithm. The input is a lengthy complex key, out comes a simple slotnumber which fits in what is called the "primary" area of the DB.
It is always possible that two or even more different logical keys are mapped into the same slotnumber. Those "synonimes" are then placed into a "secondary" or "overflow" area, connected with the parent record in the primary area using a linked list method see figure).

The advantage of packing the fields of a record in one string is that the "low level" functions to create and maintain the DB are independent from the actual record
lay-out. I will gradually provide some basic functions, starting with creation of a DB and adding records to the DB. Later on: deletion of records, getting records for updates and write them back. "Low level" : those functions handle entire records in the form of a string. It's to the user to do the user interface and to assemble and disassemble the string from and into the specific record lay-out. Just for testing I use a testcase in the form of some "personnel" records with a simple lay-out: Surname, name, department, age, salary. In my testprogram, the test-DB is fed 9 records from a read_data construct, instead from a normal "add record" panel.
The number of slots might be chosen between 1x and 2x the expected amount of records to be stored in the DB. At 1x #records, about 60% of the records will be placed in the primary area and 40% in the overflow area (causing a few extra accesses to the DB).

Currently there are 4 functions that are normally used by the user:
- create_db(filename,DBname,slotsize,expected # of records) for creating a new DB
- db(filename) for opening an existing DB
- add_rec(key,record) for adding records to the DB
- get_rec$(key) for retrieving record with key <key>

The other functions are "low level" functions, used by the above mentioned functions.

Coming up: edit_rec(...) and del_rec(...)

Code: Select all

first_time=1   
dim field$(5)   ' test DB has staff records with 5 fields
f$="testdb"

if first_time then
  create_db(f$,"Test_database",50,10)
  for i=0 to 8
    read rec$
    split rec$ to field$,n with " "  ' to extract the key
    key$=field$(1)
    add_rec(key$,rec$)
    next i
  data "John Friedman    sales      32  4500  "
  data " Betty Longa     ledger     28  3700"
  data " Ann Strady    sales      43  5300  "
  data "John-John Brady  production 25  3250  "
  data "   Lydia Carter  sales      36  3300 "
  data "  Peter Pan    R&D    48   4100"
  data " Reginald Nobody  production  23 3100  "
  data " Mary Poppins  sales  29  3650 "
  data " Elly Sunshine   production  32 3560 "
  end if
db(f$)     ' open database f$
do
  input "Name? ": key$
  if key$="stop" or key$="Stop" then break
  record$=get_record$(key$)
  if record$="not found" then
    print ! print record$ ! continue
    end if
  split record$ to field$,n with " "
  print
  print "surname    - " & field$(0)
  print "name       - " & field$(1)
  print "department - " & field$(2)
  print "age        - " & field$(3)
  print "salary     - " & field$(4)
  until forever
end


' Create a direct access database with fixed length slots
' fn$      - filename on "disc"
' db_name$ - database name for readability
' S_size   - slotsize for key + record + link fields
' N_rec    - estimated max. # of records
'
def create_db(fn$,db_name$,S_size,N_rec)
N_prim=N_rec          ' # of slots in primary area
S_free=N_rec+1        ' initial first free slot
'
dim slot(S_size)
if file_exists(fn$) then file fn$ delete
'
   ' create space for the database
for i=0 to N_prim ! file fn$ writedim slot ! next i
'
   ' write slot number 0 with meta data
file fn$ setpos 0
file fn$ writeline db_name$,str$(S_size),str$(N_prim),str$(S_free)
'
   ' init the slots in the primary area
for i=1 to N_rec
  file fn$ setpos S_size*i
  file fn$ writeline "","","0"
  next i
db(fn$)
end def

def db(fn$)       ' open database f$ (read meta data in slot 0)
file fn$ setpos 0
file fn$ readline db_name$,size$,prim$,free$
S_size=size$ ! N_prim=prim$ ! S_free=free$
end def

def add_rec(key$,rec$)
adr=get_adr(key$)
if adr>0 then return -1    ' record with same key already present
if adr<0 then              ' free slot in primary area
  adr=-adr
  file db.fn$ setpos adr*db.S_size
  file db.fn$ writeline key$,rec$,"0"
  return adr
  end if
new=hash(key$)
file db.fn$ setpos new*db.S_size
file db.fn$ readline aux$,trec$,link$
rec_to=get_1st_free()
file db.fn$ setpos rec_to*db.S_size ! file db.fn$ writeline "   "
file db.fn$ setpos rec_to*db.S_size
file db.fn$ writeline key$,rec$,link$
file db.fn$ setpos new*db.S_size
file db.fn$ writeline aux$,trec$,str$(rec_to)
put_1st_free(rec_to+1)
end def

' retrieve record with key <key$> from the DB
' returns <not found> if not found
'
def get_record$(key$)
slot=get_adr(key$)
if slot>0 then 
  file db.fn$ setpos slot*db.S_size
  file db.fn$ readline t$,rec$,t$
  return rec$
  else
  return "not found"
  end if
end def

' find adress of record with given key
' key$ - the key on which to search
' function returns one of 3 values:
' adr > 0 : record found in slot <adr>    (update or delete record)
' adr = 0 : no record found with that key  (error key or add new record)
' adr < 0 : not found, but slot <abs(adr)> is free (add new record)
'
def get_adr(key$)
adr=hash(key$)
while adr>0
  file db.fn$ setpos adr*db.S_size
  file db.fn$ readline aux$,rec$,link$
  if aux$=key$ then return adr
  if aux$="" then return -adr
  adr=val(link$)
  end while
return 0
end def

' returns the adress of the first free slot
'
def get_1st_free()
file db.fn$ setpos 0
file db.fn$ readline t$,t$,t$,t$
return val(t$)
end def

' edits the adress of the first free slot
'
def put_1st_free(adr)
file db.fn$ setpos 0
file db.fn$ readline  t1$,t2$,t3$,t4$
file db.fn$ setpos 0
file db.fn$ writeline t1$,t2$,t3$,str$(adr)
return
end def

' transform key tt$ into a DB adress (slotnumber)
'
def hash(tt$)
nt=len(tt$) ! adr=1
for i=0 to nt-1 ! adr+=asc(mid$(tt$,i,1))-32 ! adr*=7 ! next i
return 1+adr%db.N_prim
end def


User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: A direct access database system

Post by rbytes »

This will be very useful. I had started on a database and set it aside. I'm glad I waited, because your routines will be much faster.

I haven't had much time to explore, but I did try entering some names that exist in the program and got a "not found" for each. Possibly it only searches using keys, but I'm not sure without further searching what to use as the key.

Maybe you could give a few quick notes about how to use the program. :)
The only thing that gets me down is gravity...

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: A direct access database system

Post by Henko »

The keys of the records are the names, i.e. the second field. Try Poppins, Brady, Friedman, etc. (Case sensitive!)

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: A direct access database system

Post by Henko »

Made some code simplifications an added a few functions: delete record, update record and DB dump to quickly inspect the content of the DB.
As i may use this tool myself i will provide some "user" functions for manipulating the content of the DB. Those user interface functions will be based on the page mechanism and will use Dutchman's idea about prompt & input in one field. These new functions are of course dependent on the specific record-layout of my little testDB. They can serve as templates.

Code: Select all

first_time=1
f$="testdb"
if first_time then init_db(f$)

db(f$)     ' open database f$
edit_rec("Brady")
' disp_rec()
' del_rec("Carter")
db_dump()
end


' Create a direct access database with fixed length slots
' fn$      - filename on "disc"
' db_name$ - database name for readability
' S_size   - slotsize for key + record + link fields
' N_rec    - estimated max. # of records
'
def create_db(fn$,db_name$,S_size,N_rec)
N_prim=N_rec          ' # of slots in primary area
S_free=N_rec+1        ' initial first free slot
'
dim slot(S_size)
if file_exists(fn$) then file fn$ delete
'
   ' create space for the database
for i=0 to N_prim ! file fn$ writedim slot ! next i
'
   ' write slot number 0 with meta data
file fn$ setpos 0
file fn$ writeline db_name$,str$(S_size),str$(N_prim),str$(S_free)
'
   ' init the slots in the primary area
for i=1 to N_rec
  file fn$ setpos S_size*i
  file fn$ writeline "","","0"
  next i
db(fn$)
end def

def db(fn$)       ' open database f$ (read meta data in slot 0)
dim f_name$(5)   ' test DB has staff records with 5 fields
file fn$ setpos 0
file fn$ readline db_name$,size$,prim$,free$
S_size=size$ ! N_prim=prim$ ! S_free=free$
restore to fields
for i=0 to 4 ! read f_name$(i) ! next i
fields:
data "Surname","Name   ","Dept.  ","Age    ","Salary "
end def

def add_rec(key$,rec$)
adr=get_adr(key$)
if adr>0 then return -1    ' record with same key already present
if adr<0 then              ' free slot in primary area
  adr=-adr
  pos(adr)  ! file db.fn$ writeline key$,rec$,"0"
  return adr
  end if
new=hash(key$)
pos(new)    ! file db.fn$ readline aux$,trec$,link$
rec_to=get_1st_free()
pos(rec_to) ! file db.fn$ writeline "   "
pos(rec_to) ! file db.fn$ writeline key$,rec$,link$
pos(new)    ! file db.fn$ writeline aux$,trec$,str$(rec_to)
put_1st_free(rec_to+1)
end def

def edit_rec(key$)
adr=get_adr(key$)
if adr>0 then
  pos(adr) ! file db.fn$ readline key$,rec$,link$
  rec$=user_edit$(rec$)   ' user function to edit fields in rec$
  pos(adr) ! file db.fn$ writeline key$,rec$,link$
  end if
end def

def user_edit$(rec$)
print rec$
return rec$
end def

def del_rec(key$)
prd_adr=hash(key$)
pos(prd_adr) ! file db.fn$ readline prd_key$,prd_rec$,prd_link$
if prd_key$=key$ then
  suc_adr=val(prd_link$)
  if suc_adr=0 then
    pos(prd_adr) ! file db.fn$ writeline "","","0"
    return 0
    end if
  pos(suc_adr) ! file db.fn$ readline suc_key$,suc_rec$,suc_link$
  pos(prd_adr) ! file db.fn$ writeline suc_key$,suc_rec$,suc_link$
  pos(suc_adr) ! file db.fn$ writeline "","","0"
  return 1
  end if
do
  suc_adr=val(prd_link$)
  pos(suc_adr) ! file db.fn$ readline suc_key$,suc_rec$,suc_link$
  if suc_key$=key$ then
    prd_link$=suc_link$
    pos(prd_adr) ! file db.fn$ writeline prd_key$,prd_rec$,prd_link$
    pos(suc_adr) ! file db.fn$ writeline "","","0"
    return 1
    end if
  prd_adr=suc_adr
  pos(prd_adr) ! file db.fn$ readline prd_key$,prd_rec$,prd_link$
  until suc_link$="0"
return 0
end def

' retrieve record with key <key$> from the DB
' returns <not found> if not found
'
def get_record$(key$)
slot=get_adr(key$)
if slot>0 then 
  pos(slot) ! file db.fn$ readline t$,rec$,t$
  return rec$
  else
  return "not found"
  end if
end def

' find adress of record with given key
' key$ - the key on which to search
' function returns one of 3 values:
' adr > 0 : record found in slot <adr>    (update or delete record)
' adr = 0 : no record found with that key  (error key or add new record)
' adr < 0 : not found, but slot <abs(adr)> is free (add new record)
'
def get_adr(key$)
adr=hash(key$)
while adr>0
  pos(adr) ! file db.fn$ readline aux$,rec$,link$
  if aux$=key$ then return adr
  if aux$="" then return -adr
  adr=val(link$)
  end while
return 0
end def

def pos(adr)
file db.fn$ setpos adr*db.S_size
end def

' returns the adress of the first free slot
'
def get_1st_free()
pos(0) ! file db.fn$ readline t$,t$,t$,t$
return val(t$)
end def

' edits the adress of the first free slot
'
def put_1st_free(adr)
pos(0) ! file db.fn$ readline  t1$,t2$,t3$,t4$
pos(0) ! file db.fn$ writeline t1$,t2$,t3$,str$(adr)
return
end def

' transform key tt$ into a DB adress (slotnumber)
'
def hash(tt$)
nt=len(tt$) ! adr=1
for i=0 to nt-1 ! adr+=asc(mid$(tt$,i,1))-32 ! adr*=7 ! next i
return 1+adr%db.N_prim
end def

def disp_rec()
dim field$(5)
do
  input "Name? ": key$
  if key$="stop" or key$="Stop" or key$="" then break
  record$=get_record$(key$)
  if record$="not found" then
    print ! print record$ ! continue
    end if
  split record$ to field$,n with " "
  print
  for i=0 to 4 ! print db.f_name$(i) & " - " & field$(i) ! next i
  until forever
end def

def init_db(f$)
  create_db(f$,"Test_database",50,10)
  restore to staff
  for i=0 to 8
    read rec$
    split rec$ to field$,n with " "  ' to extract the key
    key$=field$(1)
    add_rec(key$,rec$)
    next i
staff:
  data "John Friedman    sales      32  4500  "
  data " Betty Longa     ledger     28  3700"
  data " Ann Strady    sales      43  5300  "
  data "John-John Brady  production 25  3250  "
  data "   Lydia Carter  sales      36  3300 "
  data "  Peter Pan    R&D    48   4100"
  data " Reginald Nobody  production  23 3100  "
  data " Mary Poppins  sales  29  3650 "
  data " Elly Sunshine   production  32 3560 "
end def

def db_dump()
print
f$=db.fn$ ! slot=db.S_size
file f$ setpos 999999 ! nslot=floor(file_pos(f$)/slot)
for i=1 to nslot
pos(i) ! file f$ readline key$,rec$,link$
if key$<>"" then print i;"  ";key$;"  ";rec$;"  ";link$
next i
end def

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: A direct access database system

Post by rbytes »

I uncommented various functions and tried them. Got expected results for most. A surprise when I deleted Carter. When I looked at testdb afterward, most of Carter's record was still there. The key had been shortened to "er", but the fields were not deleted:

er
Lydia Carter sales 36 3300

Is this your intent?

I tried add_rec, but got an error message. I assumed I could format it as add_rec("Flintstone", "Fred Flintstone delivery 42 4400") but got an error. Could you please include an example for add_rec in the next posting? Thanks.

I will start to build an interface to make full use of all of the functions.

Congratulations - this will be a very useful program.
The only thing that gets me down is gravity...

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: A direct access database system

Post by Henko »

rbytes wrote:I uncommented various functions and tried them. Got expected results for most. A surprise when I deleted Carter. When I looked at testdb afterward, most of Carter's record was still there. The key had been shortened to "er", but the fields were not deleted:

er
Lydia Carter sales 36 3300

Is this your intent?

I tried add_rec, but got an error message. I assumed I could format it as add_rec("Flintstone", "Fred Flintstone delivery 42 4400") but got an error. Could you please include an example for add_rec in the next posting? Thanks.

I will start to build an interface to make full use of all of the functions.

Congratulations - this will be a very useful program.
When deleting a record, the slot where it resides is merely marked as empty, is is not necessary to entirely erase it. After deletion, use the function db-dump() to display the actual content of the DB.
I copy/pasted your add_rec statement from here into the testcode (main), but got no error. Fred is nicely added into slot 4. See the dump result.

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: A direct access database system

Post by Henko »

IMG_1319.PNG
IMG_1319.PNG (347.07 KiB) Viewed 6300 times

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: A direct access database system

Post by Henko »

@ rbytes
Notice, that if you make an function for changing fields in a record, you can rewrite the record to the same slot after updating, EXCEPT when you change the key field. The hash algorithm will most probably generate a different slotnumber. Hence, if the key is changed, then the old record must be deleted and the record with the new key must be added with the add_rec(<new key>) function.
I'm looking forward to the user interface you are going to produce. I guess it will be a beauty. :o

Post Reply