DB Facade

Copyright 2008 Marc Spoor, Axel Waggershauser


Consider writing a program that needs to connect to a database back end. During (or even worse: after) your development you decide to use a different database instead. Wouldn't it be nice not having to read through all the existing code, looking for database specific details? At that point you probably wish you had an intermediate layer for db communication.


DB Facade is exactly that. A facade for various database back ends. It is compiled as a shared library, so it requires no compile time attention. Provided your program only uses SQL statements that can be understood by the new database, changing the back end is only a matter of passing a different string to the factory method.


API documentation is provided and can be compiled with doxygen (make doc).






make install

As easy as that.


make Defaults to make install.

make lib Builds the library.

make doc Compiles a html documentation of the API using doxygen.

make install Duilds and installs the library on your system.

make uninstall Removes the library from your system (undo install).

make clean Removes all expendable files from the current folder, including documentation and compilation results.

make test Compiles a small regression test.

Supported Backends


"The world's most popular open source database."


"The world's most advanced open source database."


"Small. Fast. Reliable. Choose any three."

That's it for the moment. It's fairly simple to add more, though. With less than 300 lines of code you should be able to add pretty much any backend you could think of.


Include the header in your own program:

	include <dbfacade.h>

and compile it with:

	g++ -ldbfacade yourcode.cpp -o YourCode

Inside your code, you can get a connection to the database with:

	std::string dbType = "MySQL"; // change on demand
	dbfacade::DatabasePtr db(dbfacade::Database::getDatabase(dbType));
	db->connect("localhost", "username", "password", "databaseName");

And then you're ready to execute statements such as:

	dbfacade::ResultPtr result(db->sqlSelect("SELECT id, name FROM users"));
	dbfacade::RowPtr row(result->getNextRow());
	std::cout << "id=" << row->getIntAt(0) << std::endl;
	std::cout << "name=" << row->getStringAt(1) << std::endl;

For more sophisticated (and complete) examples on how to use the library, have a look at the regression test code in test.cpp, as it should be complete by its very nature.

Todo / Roadmap

Style Guide

There are no definite rules about the style, only a couple of guidelines:

Generated on Mon Mar 16 20:04:30 2009 for by  doxygen 1.5.5