SOCI
Simple Oracle Call Interface (and more)

Documentation and tutorial


Library structure, files and compilation
Errors
Connections and simple queries
Exchanging data
Statements, procedures and transactions
Beyond SOCI
Backends reference
Rationale FAQ


The following (complete!) example is purposedly provided without any explanation. Parts that use the SOCI library are bold.

#include "soci.h"
#include <iostream>
#include <istream>
#include <ostream>
#include <string>
#include <exception>

using namespace SOCI;
using namespace std;

bool getName(string &name)
{
cout << "Enter name: ";
return cin >> name;
}

int main()
{
try
{
Session sql("oracle", "service=mydb user=john password=secret");

int count;
sql << "select count(*) from phonebook", into(count);
cout << "We have " << count << " entries in the phonebook.\n";

string name;
while (getName(name))
{
string phone;
eIndicator ind;
sql << "select phone from phonebook where name = :name", into(phone, ind), use(name);
if (ind == eOK)
{
cout << "The phone number is " << phone << '\n';
}
else
{
cout << "There is no phone for " << name << '\n';
}
}
}
catch (exception const &e)
{
cerr << "Error: " << e.what() << '\n';
}
}


Next (Library structure, files and compilation)


Copyright © 2004-2006 Maciej Sobczak, Stephen Hutton