1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
<link rel="stylesheet" type="text/css" href="style.css" />
<title>SOCI</title>
</head>
<body>
<p class="banner">SOCI - The C++ Database Access Library</p>
<h1>Documentation and tutorial</h1>
<div class="navigation">
<a href="structure.html">Library structure, files and compilation</a><br />
<a href="errors.html">Errors</a><br />
<a href="basics.html">Connections and simple queries</a><br />
<a href="exchange.html">Exchanging data</a><br />
<a href="statements.html">Statements, procedures and transactions</a><br />
<a href="beyond.html">Beyond SOCI</a><br />
<a href="reference.html">Client interface reference</a><br />
<a href="backends.html">Backends reference</a><br />
<a href="rationale.html">Rationale FAQ</a><br /><br />
<a href="backends/index.html">Existing backends and supported platforms</a>
</div>
<p>The following (complete!) example is purposedly provided without any explanation.</p>
<pre class="example">
#include "soci.h"
#include "soci-oracle.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';
}
}
</pre>
<table class="foot-links" border="0" cellpadding="2" cellspacing="2">
<tr>
<td class="foot-link-left"></td>
<td class="foot-link-right">
<a href="structure.html">Next (Library structure, files and compilation)</a>
</td>
</tr>
</table>
<p class="copyright">Copyright © 2004-2006 Maciej Sobczak, Stephen Hutton</p>
</body>
</html>
|