mirror of
https://github.com/allankoechke/soci.git
synced 2026-11-30 10:58:24 +00:00
Some pedantic corrections.
This commit is contained in:
56
doc.html
56
doc.html
@@ -151,16 +151,16 @@ these types is used. </p>
|
||||
|
||||
<h4><a name="staticBulk"></a>Static type binding for bulk operations</h4>
|
||||
|
||||
Bulk inserts, updates, and selects are supported through the following std::vector based into and use types:
|
||||
Bulk inserts, updates, and selects are supported through the following <code>std::vector</code> based into and use types:
|
||||
<ul>
|
||||
<li><code>std::vector<char></code></li>
|
||||
<li><code>std::vector<short></code></li>
|
||||
<li><code>std::vector<int></code></li>
|
||||
<li><code>std::vector<unsigned long></code></li>
|
||||
<li><code>std::vector<double></code></li>
|
||||
<li><code>std::vector<std::string></code></li>
|
||||
<li><code>std::vector<std::tm></code></li>
|
||||
<li><code>std::vector<std::time_t></code></li>
|
||||
<li><code>std::vector<char></code></li>
|
||||
<li><code>std::vector<short></code></li>
|
||||
<li><code>std::vector<int></code></li>
|
||||
<li><code>std::vector<unsigned long></code></li>
|
||||
<li><code>std::vector<double></code></li>
|
||||
<li><code>std::vector<std::string></code></li>
|
||||
<li><code>std::vector<std::tm></code></li>
|
||||
<li><code>std::vector<std::time_t></code></li>
|
||||
</ul>
|
||||
|
||||
Use of the vector based types mirrors that of the standard types, with the size of the vector used to specify the number of records to process at a time. See below for examples.
|
||||
@@ -343,7 +343,7 @@ sql << "select * from test_boost", into(r);
|
||||
assert(r.get<date>(0) == dIn);
|
||||
|
||||
std::vector<date> datesIn;
|
||||
for(int i=2; i<12; ++i)
|
||||
for (int i = 2; i != 12; ++i)
|
||||
{
|
||||
date d(1999, boost::gregorian::Feb, i);
|
||||
datesIn.push_back(d);
|
||||
@@ -402,18 +402,18 @@ attribute set to null. </p>
|
||||
<p>
|
||||
Indicator variables can also be used in conjunction with vector based insert, update, and select statements:</p>
|
||||
<pre>
|
||||
std::vector<string> names;
|
||||
std::vector<eIndicator> inds;
|
||||
std::vector<string> names;
|
||||
std::vector<eIndicator> inds;
|
||||
sql << "select name from person where id = 7", into(names, inds);
|
||||
</pre>
|
||||
|
||||
The following example inserts null for each value of name:
|
||||
<pre>
|
||||
std::vector<int> ids;
|
||||
std::vector<string> names;
|
||||
std::vector<eIndicator> nameIndicators;
|
||||
std::vector<int> ids;
|
||||
std::vector<string> names;
|
||||
std::vector<eIndicator> nameIndicators;
|
||||
|
||||
for(int i=0; i<10; ++i)
|
||||
for (int i = 0; i != 10; ++i)
|
||||
{
|
||||
ids.push_back(i);
|
||||
nameIndicators.push_back(eNull);
|
||||
@@ -442,19 +442,21 @@ member of <code>Session</code> class): </p>
|
||||
method indicates the number of times the statement has to be executed.
|
||||
Here, it is executed <i>once</i> in each body of the loop. </p>
|
||||
<p>
|
||||
Further performance improvements may be possible by having the underlying database API group operations together to reduce network roundtrips. SOCI makes such bulk operations possible by supporting std::vector based types:
|
||||
Further performance improvements may be possible by having the underlying database API group operations together to reduce network roundtrips. SOCI makes such bulk operations possible by supporting <code>std::vector</code> based types:
|
||||
</p>
|
||||
<pre>
|
||||
// Example 3.
|
||||
const int BATCH_SIZE = 25;
|
||||
std::vector<int> valsIn;
|
||||
for (int i=0; i<BATCH_SIZE; ++i)
|
||||
for (int i = 0; i != BATCH_SIZE; ++i)
|
||||
{
|
||||
ids.push_back(i);
|
||||
}
|
||||
|
||||
Statement st = (sql.prepare <<
|
||||
"insert into numbers(value) values(:val)",
|
||||
use(valsIn);)
|
||||
for(int i=0; i<4; ++i)
|
||||
use(valsIn));
|
||||
for (int i = 0; i != 4; ++i)
|
||||
{
|
||||
st.execute(1);
|
||||
}
|
||||
@@ -472,31 +474,33 @@ calls perform the actual data retrieval and cursor traversal. The
|
||||
end-of-cursor condition is indicated by the <code>fetch</code>
|
||||
function returning <code>false</code>. </p>
|
||||
<p>
|
||||
It is further possible to select records in batches into std::vector based types, with the size of the vector specifying the number of records to retrieve in each round trip:
|
||||
It is further possible to select records in batches into <code>std::vector</code> based types, with the size of the vector specifying the number of records to retrieve in each round trip:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
std::vector<int> valsOut(100);
|
||||
std::vector<int> valsOut(100);
|
||||
sql << "select val from numbers", into(valsOut);
|
||||
</pre>
|
||||
<p>
|
||||
The Statement::execute() and Statement::fetch() functions can also be used to repeatedly select all rows returned by a query into a vector based type:
|
||||
The <code>Statement::execute()</code> and <code>Statement::fetch()</code> functions can also be used to repeatedly select all rows returned by a query into a vector based type:
|
||||
</p>
|
||||
<pre>
|
||||
std::vector<int> valsOut(30);
|
||||
Statement st = (sql.prepare <<
|
||||
"select value from numbers",
|
||||
into(valsOut);)
|
||||
into(valsOut));
|
||||
st.execute();
|
||||
while(st.fetch())
|
||||
while (st.fetch())
|
||||
{
|
||||
std::vector<int>::iterator pos;
|
||||
for(; pos != valsOut.end(); ++pos)
|
||||
{
|
||||
cout << *pos << '\n';
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
<p>
|
||||
Assuming there are 100 rows returned by the query, the above code will retrieve and print all of them. Since the output vector was created with size 30, it will take (at least) 4 calls to fetch() to retrieve all 100 values. Each call to fetch() can potentially resize the vector to a size less than its initial size - how often this happens depends on the underlying database implementation.
|
||||
Assuming there are 100 rows returned by the query, the above code will retrieve and print all of them. Since the output vector was created with size 30, it will take (at least) 4 calls to <code>fetch()</code> to retrieve all 100 values. Each call to <code>fetch()</code> can potentially resize the vector to a size less than its initial size - how often this happens depends on the underlying database implementation.
|
||||
|
||||
</p>
|
||||
<h2><a name="procedures"></a>Stored procedures</h2>
|
||||
|
||||
Reference in New Issue
Block a user