Skip to content

Commit

Permalink
Update code examples in documentation.
Browse files Browse the repository at this point in the history
Update listings of data_type and exchange_type enumerations.
Close #47
  • Loading branch information
mloskot committed Feb 27, 2013
1 parent 4aff358 commit 1e6a691
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 37 deletions.
16 changes: 12 additions & 4 deletions doc/backends.html
Expand Up @@ -37,7 +37,7 @@ <h2>Backends reference</h2>
// data types, as seen by the user
enum data_type
{
dt_string, dt_date, dt_double, dt_integer, dt_long_long
dt_string, dt_date, dt_double, dt_integer, dt_long_long, dt_unsigned_long_long
};

// the enum type for indicator variables
Expand All @@ -46,9 +46,17 @@ <h2>Backends reference</h2>
// data types, as used to describe exchange format
enum exchange_type
{
x_char, x_cstring, x_stdstring, x_short, x_integer,
x_long_long, x_double, x_stdtm, x_statement,
x_rowid, x_blob
x_char,
x_stdstring,
x_short,
x_integer,
x_long_long,
x_unsigned_long_long,
x_double,
x_stdtm,
x_statement,
x_rowid,
x_blob
};

struct cstring_descriptor
Expand Down
74 changes: 42 additions & 32 deletions doc/exchange.html
Expand Up @@ -418,6 +418,9 @@ <h4 id="dynamic">Dynamic resultset binding</h4>
case dt_long_long:
doc &lt;&lt; r.get&lt;long long&gt;(i);
break;
case dt_unsigned_long_long:
doc &lt;&lt; r.get&lt;unsigned long long&gt;(i);
break;
case dt_date:
std::tm when = r.get&lt;std::tm&gt;(i);
doc &lt;&lt; asctime(&amp;when);
Expand Down Expand Up @@ -456,6 +459,10 @@ <h4 id="dynamic">Dynamic resultset binding</h4>
<td><code>dt_long_long</code></td>
<td><code>long long</code></td>
</tr>
<tr>
<td><code>dt_unsigned_long_long</code></td>
<td><code>unsigned long long</code></td>
</tr>
<tr>
<td><code>dt_string</code></td>
<td><code>std::string</code></td>
Expand Down Expand Up @@ -499,8 +506,8 @@ <h4 id="custom_types">Extending SOCI to support custom (user-defined) C++ types<
<ul>
<li><code>double</code></li>
<li><code>int</code></li>
<li><code>unsigned long</code></li>
<li><code>long long</code></li>
<li><code>unsigned long long</code></li>
<li><code>std::string</code></li>
<li><code>char</code></li>
<li><code>std::tm</code></li>
Expand Down Expand Up @@ -615,38 +622,41 @@ <h4 id="object_relational">Object-relational mapping</h4>

namespace soci
{
template&lt;&gt; struct TypeConversion&lt;Person&gt;
{
typedef values base_type;
static void from_base(values const &amp; v, indicator /* ind */, Person &amp; p)
template&lt;&gt;
struct type_conversion&lt;Person&gt;
{
p.id = v.get&lt;int&gt;("ID");
p.firstName = v.get&lt;std::string&gt;("FIRST_NAME");
p.lastName = v.get&lt;std::string&gt;("LAST_NAME");

// p.gender will be set to the default value "unknown"
// when the column is null:
p.gender = v.get&lt;std::string&gt;("GENDER", "unknown");

// alternatively, the indicator can be tested directly:
// if (v.indicator("GENDER") == i_null)
// {
// p.gender = "unknown";
// }
// else
// {
// p.gender = v.get&lt;std::string&gt;("GENDER");
// }
}
static void to_base(const Person &amp; p, values &amp; v, indicator &amp; ind)
{
v.set("ID", p.id);
v.set("FIRST_NAME", p.firstName);
v.set("LAST_NAME", p.lastName);
v.set("GENDER", p.gender, p.gender.empty() ? i_null : i_ok);
ind = i_ok;
}
};
typedef values base_type;

static void from_base(values const &amp; v, indicator /* ind */, Person &amp; p)
{
p.id = v.get&lt;int&gt;("ID");
p.firstName = v.get&lt;std::string&gt;("FIRST_NAME");
p.lastName = v.get&lt;std::string&gt;("LAST_NAME");

// p.gender will be set to the default value "unknown"
// when the column is null:
p.gender = v.get&lt;std::string&gt;("GENDER", "unknown");

// alternatively, the indicator can be tested directly:
// if (v.indicator("GENDER") == i_null)
// {
// p.gender = "unknown";
// }
// else
// {
// p.gender = v.get&lt;std::string&gt;("GENDER");
// }
}

static void to_base(const Person &amp; p, values &amp; v, indicator &amp; ind)
{
v.set("ID", p.id);
v.set("FIRST_NAME", p.firstName);
v.set("LAST_NAME", p.lastName);
v.set("GENDER", p.gender, p.gender.empty() ? i_null : i_ok);
ind = i_ok;
}
};
}
</pre>

Expand Down
2 changes: 1 addition & 1 deletion doc/reference.html
Expand Up @@ -48,7 +48,7 @@ <h3 id="commontypes">commonly used types</h3>

<pre class="example">
// data types, as seen by the user
enum data_type { dt_string, dt_date, dt_double, dt_integer, dt_long_long };
enum data_type { dt_string, dt_date, dt_double, dt_integer, dt_long_long, dt_unsigned_long_long };

// the enum type for indicator variables
enum indicator { i_ok, i_null, i_truncated };
Expand Down

0 comments on commit 1e6a691

Please sign in to comment.