SOCI is a database access library for C++ that makes the illusion of embedding SQL queries in the regular C++ code, staying entirely within the Standard C++.

The idea is to provide C++ programmers a way to access SQL databases in the most natural and intuitive way. If you find existing libraries too difficult for your needs or just distracting, SOCI can be a good alternative.

The simplest motivating code example for the SQL query that is supposed to retrieve a single row is:

int id = ...;
string name;
int salary;

sql << "select name, salary from persons where id = " << id,
       into(name), into(salary);

and the following benefits from extensive support for object-relational mapping:

int id = ...;
Person p;

sql << "select first_name, last_name, date_of_birth "
       "from persons where id = " << id,
       into(p);

Integration with STL is also supported:

Rowset<string> rs = (sql.prepare << "select name from persons");
copy(rs.begin(), rs.end(), ostream_iterator<string>(cout, "\n"));

SOCI offers also extensive integration with Boost datatypes (optional, tuple and fusion) and flexible support for user-defined datatypes.

Even though SOCI is mainly a C++ library, it also allows to use it from other programming languages. Currently the package contains the Ada binding, with more bindings likely to come in the future.

Starting from its 2.0.0 release, SOCI uses the plug-in architecture for backends - this allows to target various database servers. Currently (3.2.2), the following database systems are supported:

  • DB2
  • Firebird
  • MySQL
  • ODBC (generic backend)
  • Oracle
  • PostgreSQL
  • SQLite3

The intent of the library is to cover as many database technologies as possible. For this, the project has to rely on volunteer contributions from other programmers, who have expertise with the existing database interfaces and would like to help writing dedicated backends.
If you are interested in participating, please contact the project admin.

The SOCI library is distributed under the terms of the Boost Software License.

All SOCI downloads are hosted on SourceForge.net servers. The current stable release (3.2.2) can be downloaded here, and all previous releases are available here.

The development of SOCI happens on GitHub. All repositories live under the SOCI organization where all Git repositories are available.

The main Git repository with SOCI source code can be cloned with:

$ git clone git://github.com/SOCI/soci.git

The Issues tracker is open for bug reports and patches submission.

The best way to contribute to SOCI is to follow the typical GitHub workflow: fork SOCI, apply your edits and submit Pull Request.
Feel free to join SOCI development!

To meet other users, please consider subscribing to the SOCI-users mailing list. There is also SOCI-devel mailing list available dedicated to development discussions only.

There is also community-driven Wiki and FAQ hosted at GitHub, where everybody is welcome to contribute.

Fork us on GitHub