views:

205

answers:

5

I am writing a simple C++ application which might be installed on Linux or Windows, and which will connect to a database. I want my application to be compatible at least with Oracle and MySQL (or PostgreSQL).

Which C or C++ library would you recommend to handle the database queries: I am open to any library, whether it's very thin (just execute SQL queries) or very fat (a whole object persistence layer, clustering, etc.).

One library per answer, please. A little description (pros & cons) would be great. Thanks a lot.

A: 

Seriously? Data Providers.

Nothing beats customizing your data calls for each database. Generic solutions tend to have too many compromises IMO.

Mystere Man
It's the lowest common denominator syndrome.
cletus
MiniQuark
No, it doesn't require .NET. It's a pattern that is used frequently in .NET but can be applied to anything.
Mystere Man
+1  A: 

This is exactly what ODBC was designed for. Yes, it was designed by Microsoft, but there are implementations on just about every platform and for just about every database product now.

Graeme Perrow
Yes, I saw ODBC and unixODBC, but I felt it was pretty heavy-weight, and I have found that it impacts performance quite a bit. Would you agree?
MiniQuark
I wouldn't touch ODBC unless I had to...
Anonymous
ODBC performance cost is considerable compared to using the library of your database directly, but it do works with a lot of small and big database engines.
total
+3  A: 

I enjoy using SOCI, it's very C++ like. When it comes to performance with respect to Oracle database, it's comparable with native OCI. It provides backend to some RDBMS:

  • Oracle
  • PostgreSQL
  • MySQL

And some more in the CVS repository.

It's fairly simple to use, the documentation is thorough and rationale is pretty clear. It supports connection pooling, has nice extensible way of converting between datatypes.

Anonymous
Very nice! I didn't know about that one. I'll wait a day or two before I accept your answer to see if other suggestions are comparable, but so far this is the best option for my project. Thanks a lot. :-)
MiniQuark
+1  A: 

I use SQLAPI++ and it's a great product. You can try it for free, it's simple to get started and their support is fantastic.

http://www.sqlapi.com/

Rob
Looks good. Too bad it's not Open Source, but the price looks reasonable. Thanks for the link.
MiniQuark
+1  A: 

I really liked QtSql

  • It has the advantage of being well designed and cross platform.
  • Disadvantage is that you have to pay for the license if your application is not open source.

You don't have to use a QT GUI, but if you need a GUI library too it's wonderful.
If your application is commercial and you don't need the rest of the QT library, I would use something else.

total
Interesting insight, thanks. I appreciate your comments.
MiniQuark