Recent

Author Topic: Random Access Database TRaDB  (Read 5174 times)

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Random Access Database TRaDB
« on: April 07, 2015, 09:45:08 pm »
Random Access Database is an open-source implementation of an object oriented database using fixed length records. It is written in Free Pascal with Lazarus 1.4. Although random access files are rarely used these days, I felt the need to write this implementation mainly because of three reasons:

    1. It is by far the simplest way to do database programming because it uses the native programming language.
    2. It is by far the fastest database having only one pointer / record-id.
    3. There is zero fragmentation of the database file because deleted record spaces can easily be re-used.

Of course, there is also a downside. Random Access files use fixed-length records, which means records have a fixed size thus fixed-length fields, and cannot be changed as flexibly as for example sql-records, where you can instantly add, remove or change any field you want. Random Access databases need to be converted into a new data-structure in order to accomplish any change. This is not difficult or complicated at all, but it requires more work. Still, I believe it is worth the effort because any other database implementation is much more complicated to setup, and usually requires knowledge of a specific database language, such as SQL.

Just to show you how easy it is to set up and use TRaDB in Free Pascal, consider the following example:

Code: [Select]
// setup data structure
type
  TPerson = packed record
    FirstName : string[30];
    SurName : string[30];
    Address : string[40];
    Phone : string[15];
    EmailAddress : string[40];
  end;

var
  Person: TPerson;
  PersonDB: TRaDB;
..
// setup database
PersonDB := TRaDB.Create;
with PersonDB do
  begin
    Name := 'AddressBook';
    FileName := 'addressbook.rdb';
    RecordSize := SizeOf(Person);
  end;
..
// open database
if not PersonDB.Open then
  halt; // error

// add data
with Person do
  begin
    FirstName := 'John';
    SurName := 'Smith';
    ..
  end;

// add record
if PersonDB.AddRecord(@Person) then
  ; // record added successfully

PersonDB.Close;

Download here: http://www.ditrianum.org/tools/TRaDB.tar.gz
Manual: http://www.ditrianum.org/tools/TRaDB.pdf
« Last Edit: October 17, 2017, 02:56:25 pm by Munair »
keep it simple

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Random Access Database TRaDB
« Reply #1 on: April 07, 2015, 10:02:50 pm »
what it has that existing solution do not have? specifically the old turbo power b-tree filer http://sourceforge.net/projects/tpbtreefiler/?source=directory ?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: Random Access Database TRaDB
« Reply #2 on: April 07, 2015, 10:20:21 pm »
For those who do not need networking and just want a simple solution to store data. Nothing more, nothing less. Very straight forward and very easy to implement.
keep it simple

 

TinyPortal © 2005-2018