Home > Delphi, Linux, Object Pascal, Quartex Pascal, Smart Mobile Studio > TDBF, your free, open source, Delphi database engine!

TDBF, your free, open source, Delphi database engine!

November 7, 2014 Leave a comment Go to comments
We need a light database

We need a light database

One of Delphi’s strengths has always been it’s support for databases. Even back in the day I remember C++ users looking over my shoulders at how easy it was for me to create a database application, while they themselves had to commit proverbial warfare on some bulky, esoteric API just to store lists. So when it comes to databases Delphi programmers have been spoiled rotten with an impressive menu of drivers and native engines.

But as always there is a catch, and that catch used to be that you had to ship the BDE with your applications (which at the time was “wow, that simple?” factor. The basic and C guys had it much worse) if you were going to work with Interbase, Paradox or DBase – which were the heroes back then.

Like many others I decided to skip the whole BDE and opt for a native, embedded database engine. Meaning a full database system written in Delphi itself as opposed to C/C++ (which really is the paradox here, since working with databases under C++ was a bit like shaving with a cheese grinder: slightly amusing but mostly painful). And I mean no disrespect to any Delphi database engine author, but DBISAM was king, only topped by ElevateDB which is it’s successor (and very much alive and kicking to this day). So if you want a solid database engine which is embedded (meaning: compiled into your program) ElevateDB is worth every penny.

At the end of the day, what Delphi had (and still has to some extent) to offer is:

  • Pretty much the best support for popular databases out of the box (read: drivers)
  • A wide variety of database engines written in Delphi

As you probably guess, none of these options are really free. And those that are free, like FireBird, requires a lot of reading or studying of code to get working. Now please don’t get me wrong, I really want to avoid any debate situation where some Firebird guy wants to protect his favorite database. The point is simply this: if you know absolutely nothing about Firebird or Interbase and you just want a quick “drop in” component which gives you database capabilities, then Firebird can be pretty daunting. It’s a serious piece of software engineering which means you should know what you are doing and have the time to learn exactly that.

Take myself as an example: I spent a whole day trying to connect to a FB database, only to discover way into the dark hours that there were in fact two different FB versions. Had this been explained in right at the start I could have spent my day making my actual database rather than googling for error codes and exception identifiers. Secondly, the Firebird team should ship a simple Delphi demo complete with the embedded version – ready to be used by anyone.

And last but not least, FireBird doesn’t always play nice with Interbase components – and getting everything to work out of the box (I ended up with Zeos component set) can’t really be compared to the smooth sailing that is ElevateDB or DBISAM. There you just install, drop the components on a form or datamodule — voila, that’s it.

Shooting sparrows with a canons

While all of this is well and good, with plenty of drivers and support for popular technology from mySQL to MSSQL to Firebird and whatnot, dont you find it to be overkill? I mean for small projects?

For instance, I was writing a simple movie collection program a few years back, which downloaded the movie cover online and figured out things like what year the movie was made etc. based on name and online sources. My database needs very humble to say the least, something between 5 to 100 megabytes maximum. My first “test” database did not take up more than 30 megabytes (using TClientDataset which bloats everything by storing data as variant no matter what).

So where is the alternative? Do I really need to fork out $300 for a native Delphi engine just to store between 5 and 100 megabytes of data in a sequential, indexed and searchable way? And if I go for the “free” alternatives, how many hours do I have to work just to get the database engine working in the first place? Having played around with mySQL embedded, SQL Server light and Firebird – sticking to Windows and using ElevateDB seemed like the best option.

But having seen what ships with Visual Studio, Mono C# and even Lazarus/FreePascal I felt outright annoyed that Embarcadero had absolutely no free, built-in (so to speak) alternative. The only possible alternative was TClientDataset, which is perfect in terms of functionality (you rarely need SQL when dealing with such a small amount of non-complex data) — but it’s not a disk based table and quickly eats up memory once you start stuffing blobs into it.

I wanted a small, compact and humble database solution that may not be the fastest gun in the west, but at least you could trust it to scale properly and be written in such a way that it’s portable.

TDBF to the rescue

For the past couple of years I have held an eye on the database segment of Delphi, hoping that someone out there had either written a native Delphi database engine which was free and open-source, or that someone had taken the time to compile SQLite to .lib files and turned it into a TDataset descendant. The closest thing I came to a good clean production of SQLite was from Synopse — but just when I thought I had finally found what I was looking for, they decided to include it in their mORMot framework — adding a lot of dependencies which I quite frankly did not want.

As my search continued, I finally stumbled across a project which fit my needs! It’s a very small piece of database kit called TDBF, written in Delphi and compiles straight into your exe file.

To quote the Sourceforge website:

TDBF is a freeware native data access component for Borland Delphi, C++Builder and Kylix, and for FreePascal. It allows you to create very compact database programs that don’t need any special installer programs. In fact the code to access your database is compiled in your project executable file.
It takes only a few kilobytes in your executable and doesn’t need any other external files to run.

That is spot on perfect for my needs, and I’m guessing others as well. Having a simple “drop in” database which can be used for anything, speed not withstanding, should be considered a primer for any native programming language. I sincerely hope that Embarcadero either pick up this open-source project as a low-end alternative to Interbase Embedded (or perhaps sqLite would be more suitable).

If you visit the website you will find that it has quite a few years of development behind it. Secondly, if you check the SVN you will see that it was updated in 2013 (last year) so you should probably check out the code via SVN, since the website havent been updated in 7 years. But that doesn’t necessarily mean anything bad, there are plenty of components which doesn’t need updates because they work just fine. But I know many people regard “recent updates” as a sign of quality, so I’ll just mention this — the website havent been updated, but the code has (!)

The author has done a great job in keeping it backwards compatible with earlier Delphi releases (all the way to Delphi 3), but personally my absolute lowest possible limit would be Delphi 7, which I consider “classic object pascal” but even that can be discussed right now since we just moved to XE6. Either way, I will probably do a little cleanup of the code to get rid of legacy support and assembler segments.

And that’s another positive point: it’s platform independent from the ground up, designed to compile under both Delphi and freepascal. That is very nice because I am moving more and more code to Linux these days, and having a small and compact database engine which is portable and free is most welcome!

So if you are looking for a simple, clean, functional and free database engine written in object pascal which you can use anywhere — then I sincerely urge you to download and give TDBF a try. I also hope someone out there takes the time to fork this project and keep it alive (I only have time for my own stuff right now) because it’s something the Delphi community needs!

Although it ships with some 15 units, the content of the units is surprisingly small – so you could easily pack it all into a single unit without turning it into a mess. I love it when cool technology fits nicely inside a single unit with no dependencies 🙂

Im actually hoping to port some of it to Smart Mobile Studio later !

Highlights

  • Ships with several localization units (French, English, German, Spanish, Italian and more)
  • Compiles under Delphi and Freepascal
  • Platform independent (Windows, Linux and Unix)
  • No dependencies or external drivers, compiles into your program
  • Very small footprint, only adds a few KB to your exe file
  • Perfect for small projects and mobile applications
  • Compatible with DBase
  • Memo field support (dynamic size fields)
  • Indexing supported, fast lookup and searching
  • Derives from TDataset (standard Delphi database framework)

 Click here to visit the website. See the “SF Project Page” link to view the sourceforge SVN repository

  1. November 7, 2014 at 6:22 am

    Take a further look: our Sqlite wrapper is decoupled from the ORM.
    See http://synopse.info/files/html/api-1.18/SynSQLite3.html

    Our SynDb classes allow even to switch to any other DB, if needed.
    See http://synopse.info/files/html/Synopse%20mORMot%20Framework%20SAD%201.18.html#TITL_27

    TDBF is really old and the underlying DBF format is clearly deprecated, using much more space than Sqlite.

    • Jon Lennart Aasenden
      November 7, 2014 at 6:42 am

      Thanks! I’ll have another peek at it!

  2. November 9, 2014 at 1:41 pm

    First, I’m glad to see people giving ElevateSoft the credit they deserve. I’ve been using them for years, and they continue to rock.

    As for free embedded options in Delphi, SQLite has been supported out of the box for several releases, and IBLite for Windows was (finally) released in XE7. Both are available in all SKUs.

    http://glooscapsoftware.blogspot.ca/2014/10/rad-studio-xe7-stealth-feature-iblite.html

    And, as Arnaud mentioned, Synopse has an open source SQLite wrapper.

    These two databases stand out for me because of cross platform support. I can use either one anywhere my Delphi applications will run.

    • Jon Lennart Aasenden
      November 9, 2014 at 6:32 pm

      Nice, thank you for the information! I will ofcourse check these out and write about them whenever i can!

  3. February 18, 2015 at 9:53 am

    TDBF is part of FreePascal and Lazarus. From here http://wiki.freepascal.org/Lazarus_Tdbf_Tutorial you can read:

    ” No need for installation

    The DbfLaz package is installed by default in both FPC and Lazarus. The DBFLaz package uses the TDbf and associated units in the Free Pascal Free Component Library. In other words, no need to install anything if you have a fairly recent version of Lazarus. ”

    On short, you have Lazarus? Then you also have TDBF.

    • November 27, 2015 at 11:07 am

      which is maybe a bit of a problem…

      Personally I was a short-time TDbf contributor on three points (if my memory serves me):
      * correct support for Russian ( xDBF is a mess with regard to locales )
      * implementation of Master-Detail
      * some Delphi 5 optimizations ( as it was my platform until I moved to xe2 )

      Then this lib was abandoned by many programmers and was defunct with Unicode-based Delphi

      Recently a new maintainer got on for latest Delphi, I wonder how long he will use it though.

      Since Laz and Delphi communities are going more and more apart I expect TDbf/Laz and TDbf/Delphi to eventually diverge beyond compatibility. If there would be TDbf/JS/SMS then it only would happen faster.

      PS. OTOH since most modern browsers have SQLite and so do Android and iOS – what niche is there for TDbf in JS ? data xchange? JSON suits there.

  1. No trackbacks yet.

Leave a comment