Copyright 2008 Marc Spoor, Axel Waggershauser
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).
As easy as that.
makeDefaults to make install.
make lib Builds the dbfacade.so 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.
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.
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.