Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open source libraries for abstracting database access in C++?

Tags:

c++

database

I'm looking for options for abstracting database server details away from my application (in c++), I'd like to write my code to be independent of the actual database backend. I know MySQL has a nice library, but I don't want to be tied to a single database implementation. Are there good options for this?

like image 838
gct Avatar asked Jan 21 '10 03:01

gct


3 Answers

SOCI is good. Supports multiple databases, works well, modern C++ style API, works with boost.

like image 90
janm Avatar answered Oct 22 '22 14:10

janm


My opinion is to forget about a cross-database driver, and focus on finding or creating a cross-database Data Access Layer. A few reaons:

  • Complex queries (read: anything that's not a toy) invariably end up using one or two database-specific features. LIMIT and OFFSET for example, commonly used for paging, isn't universal.
  • Sooner or later you'll want bulk insertion, and you'll want it to be as fast as possible, because 3 hours is better than 6 hours. Every database has a different "optimum" way to do this, so your DAL will need to special-case this anyways.
  • Different databases may expose different constraint mechanisms—even custom column types—that can be be worth taking advantage of where possible (PostgreSQL is wonderful for this).
  • If you want to do any application level caching, you'll need a DAL anyways.

So, go ahead and use libmysql by itself - just hide it behind a compiler firewall in your DAL, and be prepared to swap it out later. You can protect yourself from shifting infrastructure without having to use a lowest-common-denominator SQL wrapper.

If that doesn't jive with you, check out SQLAPI++.

like image 21
Tom Avatar answered Oct 22 '22 13:10

Tom


many apps use odbc (via unixODBC for instance), there's also otl. on windows you could use ado.net from managed c++ or the old ado com interfaces...

like image 23
jspcal Avatar answered Oct 22 '22 13:10

jspcal