Sophie

Sophie

distrib > Fedora > 18 > x86_64 > by-pkgid > b3a1f4d91c26f535919e39e25606614a > files > 1184

wt-doc-3.2.3-1.fc18.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Wt: Wt::Dbo::Session Class Reference</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Wt
   &#160;<span id="projectnumber">3.2.3</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="inherits.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="namespaceWt.html">Wt</a>      </li>
      <li class="navelem"><a class="el" href="namespaceWt_1_1Dbo.html">Dbo</a>      </li>
      <li class="navelem"><a class="el" href="classWt_1_1Dbo_1_1Session.html">Session</a>      </li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a>  </div>
  <div class="headertitle">
<div class="title">Wt::Dbo::Session Class Reference<div class="ingroups"><a class="el" href="group__dbo.html">Database Objects (Wt::Dbo)</a></div></div>  </div>
</div>
<div class="contents">
<!-- doxytag: class="Wt::Dbo::Session" -->
<p>A database session.  
 <a href="classWt_1_1Dbo_1_1Session.html#details">More...</a></p>

<p><code>#include &lt;Wt/Dbo/Session&gt;</code></p>

<p><a href="classWt_1_1Dbo_1_1Session-members.html">List of all members.</a></p>
<table class="memberdecls">
<tr><td colspan="2"><h2><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a55c41a33e862729b80837347da199b20"></a><!-- doxytag: member="Wt::Dbo::Session::Session" ref="a55c41a33e862729b80837347da199b20" args="()" -->
&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1Dbo_1_1Session.html#a55c41a33e862729b80837347da199b20">Session</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Creates a database session. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1Dbo_1_1Session.html#aac2f9332076fff93cde45ba1c8d15fa3">~Session</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Destructor.  <a href="#aac2f9332076fff93cde45ba1c8d15fa3"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1Dbo_1_1Session.html#aedcc21944ce9c2bbb2fe2b5ef1860776">setConnection</a> (<a class="el" href="classWt_1_1Dbo_1_1SqlConnection.html">SqlConnection</a> &amp;connection)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Sets a dedicated connection.  <a href="#aedcc21944ce9c2bbb2fe2b5ef1860776"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1Dbo_1_1Session.html#a63ab17e16c9b721c94e6e9f67c5c255d">setConnectionPool</a> (<a class="el" href="classWt_1_1Dbo_1_1SqlConnectionPool.html">SqlConnectionPool</a> &amp;pool)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Sets a connection pool.  <a href="#a63ab17e16c9b721c94e6e9f67c5c255d"></a><br/></td></tr>
<tr><td class="memTemplParams" colspan="2">template&lt;class C &gt; </td></tr>
<tr><td class="memTemplItemLeft" align="right" valign="top">void&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="classWt_1_1Dbo_1_1Session.html#a22b4750b2665de1381b1fedec7020c75">mapClass</a> (const char *tableName)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Maps a class to a database table.  <a href="#a22b4750b2665de1381b1fedec7020c75"></a><br/></td></tr>
<tr><td class="memTemplParams" colspan="2">template&lt;class C &gt; </td></tr>
<tr><td class="memTemplItemLeft" align="right" valign="top">const char *&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="classWt_1_1Dbo_1_1Session.html#af9c98695dec252ab838918145dd033a1">tableName</a> () const </td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns the mapped table name for a class.  <a href="#af9c98695dec252ab838918145dd033a1"></a><br/></td></tr>
<tr><td class="memTemplParams" colspan="2">template&lt;class C &gt; </td></tr>
<tr><td class="memTemplItemLeft" align="right" valign="top"><a class="el" href="classWt_1_1Dbo_1_1ptr.html">ptr</a>&lt; C &gt;&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="classWt_1_1Dbo_1_1Session.html#abfbd5bea3a6b964e833c893434e38c8f">add</a> (<a class="el" href="classWt_1_1Dbo_1_1ptr.html">ptr</a>&lt; C &gt; &amp;<a class="el" href="classWt_1_1Dbo_1_1ptr.html">ptr</a>)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Persists a transient object.  <a href="#abfbd5bea3a6b964e833c893434e38c8f"></a><br/></td></tr>
<tr><td class="memTemplParams" colspan="2">template&lt;class C &gt; </td></tr>
<tr><td class="memTemplItemLeft" align="right" valign="top"><a class="el" href="classWt_1_1Dbo_1_1ptr.html">ptr</a>&lt; C &gt;&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="classWt_1_1Dbo_1_1Session.html#af7c3e4b7dda270944f88f1bafaa210c6">add</a> (C *obj)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Persists a transient object.  <a href="#af7c3e4b7dda270944f88f1bafaa210c6"></a><br/></td></tr>
<tr><td class="memTemplParams" colspan="2">template&lt;class C &gt; </td></tr>
<tr><td class="memTemplItemLeft" align="right" valign="top"><a class="el" href="classWt_1_1Dbo_1_1ptr.html">ptr</a>&lt; C &gt;&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="classWt_1_1Dbo_1_1Session.html#acb4b7f2191237c16f14a3689915e164b">load</a> (const typename <a class="el" href="structWt_1_1Dbo_1_1dbo__traits.html">dbo_traits</a>&lt; C &gt;::IdType &amp;id, bool forceReread=false)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Loads a persisted object.  <a href="#acb4b7f2191237c16f14a3689915e164b"></a><br/></td></tr>
<tr><td class="memTemplParams" colspan="2">template&lt;class C , typename BindStrategy  = DynamicBinding&gt; </td></tr>
<tr><td class="memTemplItemLeft" align="right" valign="top"><a class="el" href="classWt_1_1Dbo_1_1Query.html">Query</a>&lt; <a class="el" href="classWt_1_1Dbo_1_1ptr.html">ptr</a>&lt; C &gt;, BindStrategy &gt;&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="classWt_1_1Dbo_1_1Session.html#a1a9aff98561cd85ee82a11a57e1e7a74">find</a> (const std::string &amp;condition=std::string())</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Finds database objects.  <a href="#a1a9aff98561cd85ee82a11a57e1e7a74"></a><br/></td></tr>
<tr><td class="memTemplParams" colspan="2">template&lt;class Result , typename BindStrategy  = DynamicBinding&gt; </td></tr>
<tr><td class="memTemplItemLeft" align="right" valign="top"><a class="el" href="classWt_1_1Dbo_1_1Query.html">Query</a>&lt; Result, BindStrategy &gt;&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="classWt_1_1Dbo_1_1Session.html#a8cad70bef9cffd6613107d5cd3aeb16a">query</a> (const std::string &amp;sql)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Creates a query.  <a href="#a8cad70bef9cffd6613107d5cd3aeb16a"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="el" href="classWt_1_1Dbo_1_1Call.html">Call</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1Dbo_1_1Session.html#a42b1d61b66e996eff474d677a10d5b8f">execute</a> (const std::string &amp;sql)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Executs an Sql command.  <a href="#a42b1d61b66e996eff474d677a10d5b8f"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1Dbo_1_1Session.html#aba79d84c7c91faae06f954e6d3d390ab">createTables</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Creates the database schema.  <a href="#aba79d84c7c91faae06f954e6d3d390ab"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a89c36de3c02f83e621dda5d149dd7b9b"></a><!-- doxytag: member="Wt::Dbo::Session::tableCreationSql" ref="a89c36de3c02f83e621dda5d149dd7b9b" args="()" -->
std::string&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1Dbo_1_1Session.html#a89c36de3c02f83e621dda5d149dd7b9b">tableCreationSql</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns database creation SQL. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1Dbo_1_1Session.html#a4c1fedb21e4e1cc44b182a34e8ebb4ef">dropTables</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Drops the database schema.  <a href="#a4c1fedb21e4e1cc44b182a34e8ebb4ef"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1Dbo_1_1Session.html#ab896d119f1e0fb79adffe2282b92ef17">flush</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Flushes the session.  <a href="#ab896d119f1e0fb79adffe2282b92ef17"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1Dbo_1_1Session.html#a68d1bf89fc8a6991856b6d7992b2d14b">rereadAll</a> (const char *tableName=0)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Rereads all objects.  <a href="#a68d1bf89fc8a6991856b6d7992b2d14b"></a><br/></td></tr>
</table>
<hr/><a name="details" id="details"></a><h2>Detailed Description</h2>
<div class="textblock"><p>A database session. </p>
<p>A database session manages meta data about the mapping of C++ classes to database tables, and keeps track of a working set of in-memory objects (objects which are referenced from your code or from within a transaction).</p>
<p>It also manages an active transaction, which you need to access database objects.</p>
<p>You can provide the session with a dedicated database connection using <a class="el" href="classWt_1_1Dbo_1_1Session.html#aedcc21944ce9c2bbb2fe2b5ef1860776" title="Sets a dedicated connection.">setConnection()</a>, or with a connection pool (from which it will take a connection while processing a transaction) using <a class="el" href="classWt_1_1Dbo_1_1Session.html#a63ab17e16c9b721c94e6e9f67c5c255d" title="Sets a connection pool.">setConnectionPool()</a>. In either case, the session does not take ownership of the connection or connection pool.</p>
<p>A session will typically be a long-lived object in your application. </p>
</div><hr/><h2>Constructor &amp; Destructor Documentation</h2>
<a class="anchor" id="aac2f9332076fff93cde45ba1c8d15fa3"></a><!-- doxytag: member="Wt::Dbo::Session::~Session" ref="aac2f9332076fff93cde45ba1c8d15fa3" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">Wt::Dbo::Session::~Session </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Destructor. </p>
<p>A session must survive all database objects that have been loaded through it, and will warning during this destructor if there are still database objects that are being referenced from a ptr. </p>

</div>
</div>
<hr/><h2>Member Function Documentation</h2>
<a class="anchor" id="abfbd5bea3a6b964e833c893434e38c8f"></a><!-- doxytag: member="Wt::Dbo::Session::add" ref="abfbd5bea3a6b964e833c893434e38c8f" args="(ptr&lt; C &gt; &amp;ptr)" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;class C &gt; </div>
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classWt_1_1Dbo_1_1ptr.html">ptr</a>&lt; C &gt; Wt::Dbo::Session::add </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classWt_1_1Dbo_1_1ptr.html">ptr</a>&lt; C &gt; &amp;&#160;</td>
          <td class="paramname"><em>ptr</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Persists a transient object. </p>
<p>The transient object pointed to by <code>ptr</code> is added to the session, and will be persisted when the session is flushed.</p>
<p>A transient object is usually a newly created object which want to add to the database.</p>
<p>The method returns <code>ptr</code>. </p>

</div>
</div>
<a class="anchor" id="af7c3e4b7dda270944f88f1bafaa210c6"></a><!-- doxytag: member="Wt::Dbo::Session::add" ref="af7c3e4b7dda270944f88f1bafaa210c6" args="(C *obj)" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;class C &gt; </div>
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classWt_1_1Dbo_1_1ptr.html">ptr</a>&lt; C &gt; Wt::Dbo::Session::add </td>
          <td>(</td>
          <td class="paramtype">C *&#160;</td>
          <td class="paramname"><em>obj</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Persists a transient object. </p>
<p>This is an overloaded method for convenience, and is implemented as: </p>
<div class="fragment"><pre class="fragment"> <span class="keywordflow">return</span> <a class="code" href="classWt_1_1Dbo_1_1Session.html#abfbd5bea3a6b964e833c893434e38c8f" title="Persists a transient object.">add</a>(ptr&lt;C&gt;(obj));
</pre></div><p>The method returns a database pointer to the object. </p>

</div>
</div>
<a class="anchor" id="aba79d84c7c91faae06f954e6d3d390ab"></a><!-- doxytag: member="Wt::Dbo::Session::createTables" ref="aba79d84c7c91faae06f954e6d3d390ab" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Wt::Dbo::Session::createTables </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Creates the database schema. </p>
<p>This will create the database schema of the mapped tables. Schema creation will fail if one or more tables already existed.</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classWt_1_1Dbo_1_1Session.html#a22b4750b2665de1381b1fedec7020c75" title="Maps a class to a database table.">mapClass()</a>, <a class="el" href="classWt_1_1Dbo_1_1Session.html#a4c1fedb21e4e1cc44b182a34e8ebb4ef" title="Drops the database schema.">dropTables()</a> </dd></dl>

</div>
</div>
<a class="anchor" id="a4c1fedb21e4e1cc44b182a34e8ebb4ef"></a><!-- doxytag: member="Wt::Dbo::Session::dropTables" ref="a4c1fedb21e4e1cc44b182a34e8ebb4ef" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Wt::Dbo::Session::dropTables </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Drops the database schema. </p>
<p>This will drop the database schema. Dropping the schema will fail if one or more tables did not exist.</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classWt_1_1Dbo_1_1Session.html#aba79d84c7c91faae06f954e6d3d390ab" title="Creates the database schema.">createTables()</a> </dd></dl>

</div>
</div>
<a class="anchor" id="a42b1d61b66e996eff474d677a10d5b8f"></a><!-- doxytag: member="Wt::Dbo::Session::execute" ref="a42b1d61b66e996eff474d677a10d5b8f" args="(const std::string &amp;sql)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classWt_1_1Dbo_1_1Call.html">Call</a> Wt::Dbo::Session::execute </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp;&#160;</td>
          <td class="paramname"><em>sql</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Executs an Sql command. </p>
<p>This executs an Sql command. It differs from <a class="el" href="classWt_1_1Dbo_1_1Session.html#a8cad70bef9cffd6613107d5cd3aeb16a" title="Creates a query.">query()</a> in that no result is expected from the call.</p>
<p>Usage example: </p>
<div class="fragment"><pre class="fragment"> session.execute(<span class="stringliteral">&quot;update user set name = ? where name = ?&quot;</span>).bind(<span class="stringliteral">&quot;Bart&quot;</span>).bind(<span class="stringliteral">&quot;Sarah&quot;</span>);
</pre></div> 
</div>
</div>
<a class="anchor" id="a1a9aff98561cd85ee82a11a57e1e7a74"></a><!-- doxytag: member="Wt::Dbo::Session::find" ref="a1a9aff98561cd85ee82a11a57e1e7a74" args="(const std::string &amp;condition=std::string())" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;class C , typename BindStrategy &gt; </div>
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classWt_1_1Dbo_1_1Query.html">Query</a>&lt; <a class="el" href="classWt_1_1Dbo_1_1ptr.html">ptr</a>&lt; C &gt;, BindStrategy &gt; Wt::Dbo::Session::find </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp;&#160;</td>
          <td class="paramname"><em>condition</em> = <code>std::string()</code></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Finds database objects. </p>
<p>This method creates a query for finding objects of type <code>C</code>.</p>
<p>When passing an empty <code>condition</code> parameter, it will return all objects of type <code>C</code>. Otherwise, it will add the condition, by generating an SQL <em>where</em> clause.</p>
<p>The <code>BindStrategy</code> specifies how you want to bind parameters to your query (if any).</p>
<p>When using <code><a class="el" href="structWt_1_1Dbo_1_1DynamicBinding.html">DynamicBinding</a></code> (which is the default), you will defer the binding until the query is run. This has the advantage that you can compose the query definition using helper methods provided in the query object, you can keep the query around and run the query multiple times, perhaps with different parameter values or to scroll through the query results.</p>
<p>When using <code><a class="el" href="structWt_1_1Dbo_1_1DirectBinding.html">DirectBinding</a></code>, the query must be specified entirely using the <code>condition</code>, and can be run only once. This method does have the benefit of binding parameters directly to the underlying prepared statement.</p>
<p>This method is convenient when you are querying only results from a single table. For more generic query support, see <a class="el" href="classWt_1_1Dbo_1_1Session.html#a8cad70bef9cffd6613107d5cd3aeb16a" title="Creates a query.">query()</a>.</p>
<p>Usage example: </p>
<div class="fragment"><pre class="fragment"> <span class="comment">// Bart is missing, let&#39;s find him.</span>
 <a class="code" href="classWt_1_1Dbo_1_1ptr.html" title="A smart pointer for a database object.">Wt::Dbo::ptr&lt;User&gt;</a> bart = session.find&lt;User&gt;().where(<span class="stringliteral">&quot;name = ?&quot;</span>).bind(<span class="stringliteral">&quot;Bart&quot;</span>);

 <span class="comment">// Find all users, order by name</span>
 <span class="keyword">typedef</span> <a class="code" href="classWt_1_1Dbo_1_1collection.html" title="An STL container for iterating query results.">Wt::Dbo::collection&lt; Wt::Dbo::ptr&lt;User&gt;</a> &gt; Users;
 Users users = session.<a class="code" href="classWt_1_1Dbo_1_1collection.html#a6b8aa118fad63539958ea8532ae37d68" title="Returns the query that backs the collection.">find</a>&lt;User&gt;().orderBy(<span class="stringliteral">&quot;name&quot;</span>);
</pre></div><p>In the <code>condition</code>, parameters can be bound using '?' as a positional placeholder: each occurence of '?' (as a lexical token) is replaced by a bound parameter. This is actually done by most of the backends themselves using prepared statements and parameter binding. Parameter binding is possible for all types for which <a class="el" href="structWt_1_1Dbo_1_1sql__value__traits.html" title="Traits class for value types.">sql_value_traits</a> is specialized.</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classWt_1_1Dbo_1_1Session.html#a8cad70bef9cffd6613107d5cd3aeb16a" title="Creates a query.">query()</a> </dd></dl>

</div>
</div>
<a class="anchor" id="ab896d119f1e0fb79adffe2282b92ef17"></a><!-- doxytag: member="Wt::Dbo::Session::flush" ref="ab896d119f1e0fb79adffe2282b92ef17" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Wt::Dbo::Session::flush </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Flushes the session. </p>
<p>This flushes all modified objects to the database. This does not commit the transaction.</p>
<p>Normally, you need not to call this method as the session is flushed automatically before committing a transaction, or before running a query (to be sure to take into account pending modifications). </p>

</div>
</div>
<a class="anchor" id="acb4b7f2191237c16f14a3689915e164b"></a><!-- doxytag: member="Wt::Dbo::Session::load" ref="acb4b7f2191237c16f14a3689915e164b" args="(const typename dbo_traits&lt; C &gt;::IdType &amp;id, bool forceReread=false)" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;class C &gt; </div>
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classWt_1_1Dbo_1_1ptr.html">ptr</a>&lt; C &gt; Wt::Dbo::Session::load </td>
          <td>(</td>
          <td class="paramtype">const typename <a class="el" href="structWt_1_1Dbo_1_1dbo__traits.html">dbo_traits</a>&lt; C &gt;::IdType &amp;&#160;</td>
          <td class="paramname"><em>id</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool&#160;</td>
          <td class="paramname"><em>forceReread</em> = <code>false</code>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Loads a persisted object. </p>
<p>This method returns a database object with the given object id. If the object was already loaded in the session, the loaded object is returned, otherwise the object is loaded from the database.</p>
<p>If <code>forceReread</code> is set to <code>true</code>, then a fresh copy is loaded from the database. This is almost equivalent to calling <a class="el" href="classWt_1_1Dbo_1_1ptr.html#abb1db71ef910748437d69bf11a04eb6e">reread()</a> on the returned object, except that it will not result in two database reads in case the object was in fact not yet loaded in the session.</p>
<p>Throws an <a class="el" href="classWt_1_1Dbo_1_1ObjectNotFoundException.html" title="Exception thrown when trying to load a non-existing object.">ObjectNotFoundException</a> when the object was not found.</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classWt_1_1Dbo_1_1ptr.html#a71d848cf0e8eaa1a4e01b11ae2f1e865" title="Returns the object id.">ptr::id()</a> </dd></dl>

</div>
</div>
<a class="anchor" id="a22b4750b2665de1381b1fedec7020c75"></a><!-- doxytag: member="Wt::Dbo::Session::mapClass" ref="a22b4750b2665de1381b1fedec7020c75" args="(const char *tableName)" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;class C &gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">void Wt::Dbo::Session::mapClass </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>tableName</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Maps a class to a database table. </p>
<p>The class <code>C</code> is mapped to table with name <code>tableName</code>. You need to map classes to tables.</p>
<p>You may provide a schema-qualified table name, if the underlying database supports this, eg. <code>"myschema.users"</code>. </p>

</div>
</div>
<a class="anchor" id="a8cad70bef9cffd6613107d5cd3aeb16a"></a><!-- doxytag: member="Wt::Dbo::Session::query" ref="a8cad70bef9cffd6613107d5cd3aeb16a" args="(const std::string &amp;sql)" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;class Result , typename BindStrategy &gt; </div>
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classWt_1_1Dbo_1_1Query.html">Query</a>&lt; Result, BindStrategy &gt; Wt::Dbo::Session::query </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp;&#160;</td>
          <td class="paramname"><em>sql</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Creates a query. </p>
<p>The sql statement should be a complete SQL statement, starting with a "select ". The items listed in the "select" must match the <code>Result</code> type. An item that corresponds to a database object (ptr) is substituted with the selection of all the fields in the dbo.</p>
<p>For example, the following query (class User is mapped onto table 'user'): </p>
<div class="fragment"><pre class="fragment"> session.query&lt; ptr&lt;User&gt; &gt;(<span class="stringliteral">&quot;select u from user u&quot;</span>).where(<span class="stringliteral">&quot;u.name = ?&quot;</span>).bind(<span class="stringliteral">&quot;Bart&quot;</span>);
</pre></div><p> is the more general version of: </p>
<div class="fragment"><pre class="fragment"> session.find&lt;User&gt;().where(<span class="stringliteral">&quot;name = ?&quot;</span>).bind(<span class="stringliteral">&quot;Bart&quot;</span>);
</pre></div><p>Note that "u" in this query will be expanded to select the fields of the user table (u.id, u.version, u.name, ...). The same expansion happens when using an alias in <a class="el" href="classWt_1_1Dbo_1_1Query.html#a07d81e1a0d504eca1b428b04f7855c3d" title="Sets the grouping field(s).">Query::groupBy()</a>.</p>
<p>The additional flexibility offered by query() over <a class="el" href="classWt_1_1Dbo_1_1Session.html#a1a9aff98561cd85ee82a11a57e1e7a74" title="Finds database objects.">find()</a> is however that it may support other result types.</p>
<p>Thus, it may return plain values: </p>
<div class="fragment"><pre class="fragment"> session.query&lt;<span class="keywordtype">int</span>&gt;(<span class="stringliteral">&quot;select count(1) from ...&quot;</span>);
</pre></div><p>Or Boost.Tuple for an arbitrary combination of result values:</p>
<div class="fragment"><pre class="fragment"> session.query&lt; boost::tuple&lt;int, int&gt; &gt;(<span class="stringliteral">&quot;select A.id, B.id from table_a A, table_b B&quot;</span>).where(<span class="stringliteral">&quot;...&quot;</span>);
</pre></div><p>A tuple may combine any kind of object that is supported as a result, including database objects (see also <a class="el" href="structWt_1_1Dbo_1_1ptr__tuple.html" title="A utility class for defining a tuple of database objects.">ptr_tuple</a>): </p>
<div class="fragment"><pre class="fragment"> session.query&lt; boost::tuple&lt;ptr&lt;A&gt;, ptr&lt;B&gt; &gt; &gt;(<span class="stringliteral">&quot;select A, B from table_a A, table_b B&quot;</span>).where(<span class="stringliteral">&quot;...&quot;</span>);
</pre></div><p>The <code>BindStrategy</code> specifies how you want to bind parameters to your query (if any).</p>
<p>When using <code><a class="el" href="structWt_1_1Dbo_1_1DynamicBinding.html">DynamicBinding</a></code> (which is the default), you will defer the binding until the query is run. This has the advantage that you can compose the query using helper methods provided in the <a class="el" href="classWt_1_1Dbo_1_1Query.html" title="A database query.">Query</a> object, you can keep the query around and run the query multiple times, perhaps with different parameter values or to scroll through the query results.</p>
<p>When using <code><a class="el" href="structWt_1_1Dbo_1_1DirectBinding.html">DirectBinding</a></code>, the query must be specified entirely using the <code>sql</code>, and can be run only once. This method does have the benefit of binding parameters directly to the underlying prepared statement.</p>
<p>This method uses <a class="el" href="structWt_1_1Dbo_1_1query__result__traits.html" title="Traits class for result types.">query_result_traits</a> to unmarshal the query result into the <code>Result</code> type.</p>
<p>In the <code>sql</code> query, parameters can be bound using '?' as the positional placeholder: each occurence of '?' (as a lexical token) is replaced by a bound parameter. This is actually done by most of the backends themselves using prepared statements and parameter binding. Parameter binding is possible for all types for which <a class="el" href="structWt_1_1Dbo_1_1sql__value__traits.html" title="Traits class for value types.">sql_value_traits</a> is specialized.</p>
<dl class="note"><dt><b>Note:</b></dt><dd>The query must be a ASCII-7 string: UTF-8 is not supported by the underlying query parser. To add a non-English string to the query use parameter binding instead (which prevents against SQL injection attacks at the same time) instead of string concatenation. </dd></dl>

</div>
</div>
<a class="anchor" id="a68d1bf89fc8a6991856b6d7992b2d14b"></a><!-- doxytag: member="Wt::Dbo::Session::rereadAll" ref="a68d1bf89fc8a6991856b6d7992b2d14b" args="(const char *tableName=0)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Wt::Dbo::Session::rereadAll </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>tableName</em> = <code>0</code></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Rereads all objects. </p>
<p>This rereads all objects from the database, possibly discarding unflushed modifications. This is a catch-all solution for a <a class="el" href="classWt_1_1Dbo_1_1StaleObjectException.html" title="Exception thrown when Wt::Dbo detects a concurrent modification">StaleObjectException</a>.</p>
<p>If a <code>tableName</code> is given, then only objects of that table are reread.</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classWt_1_1Dbo_1_1ptr.html#abb1db71ef910748437d69bf11a04eb6e" title="Rereads the database version.">ptr::reread()</a> </dd></dl>

</div>
</div>
<a class="anchor" id="aedcc21944ce9c2bbb2fe2b5ef1860776"></a><!-- doxytag: member="Wt::Dbo::Session::setConnection" ref="aedcc21944ce9c2bbb2fe2b5ef1860776" args="(SqlConnection &amp;connection)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Wt::Dbo::Session::setConnection </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classWt_1_1Dbo_1_1SqlConnection.html">SqlConnection</a> &amp;&#160;</td>
          <td class="paramname"><em>connection</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Sets a dedicated connection. </p>
<p>The connection will be used exclusively by this session.</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classWt_1_1Dbo_1_1Session.html#a63ab17e16c9b721c94e6e9f67c5c255d" title="Sets a connection pool.">setConnectionPool()</a> </dd></dl>

</div>
</div>
<a class="anchor" id="a63ab17e16c9b721c94e6e9f67c5c255d"></a><!-- doxytag: member="Wt::Dbo::Session::setConnectionPool" ref="a63ab17e16c9b721c94e6e9f67c5c255d" args="(SqlConnectionPool &amp;pool)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Wt::Dbo::Session::setConnectionPool </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classWt_1_1Dbo_1_1SqlConnectionPool.html">SqlConnectionPool</a> &amp;&#160;</td>
          <td class="paramname"><em>pool</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Sets a connection pool. </p>
<p>The connection pool is typically shared with other sessions.</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classWt_1_1Dbo_1_1Session.html#aedcc21944ce9c2bbb2fe2b5ef1860776" title="Sets a dedicated connection.">setConnection()</a> </dd></dl>

</div>
</div>
<a class="anchor" id="af9c98695dec252ab838918145dd033a1"></a><!-- doxytag: member="Wt::Dbo::Session::tableName" ref="af9c98695dec252ab838918145dd033a1" args="() const " -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;class C &gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">const char * Wt::Dbo::Session::tableName </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td> const</td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Returns the mapped table name for a class. </p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classWt_1_1Dbo_1_1Session.html#a22b4750b2665de1381b1fedec7020c75" title="Maps a class to a database table.">mapClass()</a> </dd></dl>

</div>
</div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<hr size="1"><address style="text-align: right; margin: 3px"><small>
Generated on Thu Nov 1 2012 for <a href="http://www.webtoolkit.eu/wt">the
C++ Web Toolkit (Wt)</a> by&nbsp;<a
href="http://www.doxygen.org/index.html"><img src="doxygen.png"
alt="doxygen" border="0" style="vertical-align: middle; display:
inline-block; height: 2em"></a> 1.7.5.1</small></address>
</body>
</html>