1. Computing

Embedded SQL in C++ With SOCI

By February 13, 2013

Follow me on:

The traditional way of doing SQL for Relational Databases in C++ is something like this:

con.Connect(
        "testDB", // database name
        "user", // user name
        "password", // password
        DBClient) ;
con.Execute("Select * from test where users = 0") ;
//... handle data
con.Disconnect() ;

All within a Try Catch exception handler.

SOCI lets you do it like this:

string name;
int salary;

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

Which you have to admit is a lot easier to understand. SOCI is an open source library with dual licencing and works with MySQL, ODBC, Oracle, PostgreSQL and SQLite3

Comments
Comments are closed for this post.
Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

©2014 About.com. All rights reserved.