Lazarus

Announcements => Third party => Topic started by: munair on April 07, 2015, 09:45:08 pm

Title: Random Access Database TRaDB
Post by: munair 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 (http://www.ditrianum.org/tools/TRaDB.tar.gz)
Manual: http://www.ditrianum.org/tools/TRaDB.pdf (http://www.ditrianum.org/tools/TRaDB.pdf)
Title: Re: Random Access Database TRaDB
Post by: taazz 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 ?
Title: Re: Random Access Database TRaDB
Post by: munair 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.
TinyPortal © 2005-2018