⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logginghandler.htm

📁 The goal of this library is to make ODBC recordsets look just like an STL container. As a user, you
💻 HTM
📖 第 1 页 / 共 2 页
字号:

		cout << "Error msg = " << error.errmsg << endl;
		cout << "Example = " << error.dataObj << endl;
	}

}
</code></pre>
 </p>
<p><pre><code><span class="codeComment">// Example Code Using LoggingHandler on an IndexedDBView

const TIMESTAMP_STRUCT then = {2000, 12, 15, 0, 0, 0, 0};

<span class="codeComment">// Example of using an IndexDBView to try to insert Example objects and print out
// any errors that occurred</span>
void IndexedViewExample()
{
	typedef DBView&lt;Example, ParamObjExample&gt; DBV;

	DBV view(&quot;DB_EXAMPLE&quot;, DefaultBCA&lt;Example&gt;(), 
	  &quot;WHERE INT_VALUE BETWEEN (?) AND (?) OR &quot;
	  &quot;STRING_VALUE = (?) OR EXAMPLE_DATE &lt;= (?) ORDER BY EXAMPLE_LONG&quot;,
	  BPAExampleObj());

	IndexedDBView&lt;DBV&gt; indexed_view(view, &quot;PrimaryIndex; STRING_VALUE; UNIQUE AlternateIndex; EXAMPLE_LONG, 
		EXAMPLE_DATE&quot;, BOUND, USE_ALL_FIELDS, cb_ptr_fun(SetParamsExample));
   		

	try
	{

	<span class="codeComment">// Insert new items into the container</span>
	pair&lt;IndexedDBView&lt;DBV&gt;::iterator, bool&gt; ins_pr;

	ins_pr = indexed_view.insert(Example(459, &quot;Unique String #1&quot;, 3.4, 1, date_criteria));

	cout &lt;&lt; &quot;insertion succeded = &quot; &lt;&lt; (ins_pr.second == true ? &quot;true&quot;: &quot;false&quot;) &lt;&lt; endl;

	ins_pr = indexed_view.insert(Example(311, &quot;&quot;, 3.99, 91, then)); <span class="codeComment">// should fail on InsValidate()</span>
   
	cout &lt;&lt; &quot;insertion succeded = &quot; &lt;&lt; (ins_pr.second == true ? &quot;true&quot;: &quot;false&quot;) &lt;&lt; endl;
	
	ins_pr = indexed_view.insert(Example(222, &quot;Positron&quot;, -34.77, 29, then)); <span class="codeComment">// should fail (ditto)</span>
	
	cout &lt;&lt; &quot;insertion succeded = &quot; &lt;&lt; (ins_pr.second == true ? &quot;true&quot;: &quot;false&quot;) &lt;&lt; endl;
	}
	
	catch (...)
	{
	typedef LoggingHandler&lt;Example, ParamObjExample&gt;::LoggedTriple LoggedTriple;
 
	<span class="codeComment">// retrieve the LoggingHandler object from the IndexedDBView</span>
	LoggingHandler&lt;Example, ParamObjExample&gt; log_handler = 
		indexed_view.get_io_handler((LoggingHandler&lt;Example, ParamObjExample&gt; *) NULL);

	<span class="codeComment">// the log is a vector of (error message, DataObj, ParamObj) triples,
	// (error message, Example object, ParamObjExample object) in this case
	// the error itself along with the relevant DataObj and ParamObj that resulted with
	// the error</span>
	vector&lt;LoggedTriple&gt; error_log = log_handler.GetLog();

	<span class="codeComment">// nothing to do if no errors occurred</span>
	if (error_log.empty())
		return;

	cout &lt;&lt; &quot;*** Error Log in IndexedViewExample(): &quot; &lt;&lt; error_log.size() &lt;&lt; &quot; errors recorded! ***&quot;
	     &lt;&lt; endl;

	<span class="codeComment">// print out the errors</span>
	for (vector&lt;LoggedTriple&gt;::const_iterator log_it = error_log.begin(); 
		log_it != error_log.end(); log_it++)
	{
	   cout &lt;&lt; &quot;*** Error Log Entry ***&quot; &lt;&lt; endl;
	   cout &lt;&lt; &quot;* error message *&quot; &lt;&lt; endl;
	   cout &lt;&lt; (*log_it).errmsg &lt;&lt; endl;
	   cout &lt;&lt; &quot;* relevant Example object *&quot; &lt;&lt; endl;
	   cout &lt;&lt; (*log_it).dataObj &lt;&lt; endl;
	}

	}	
}</pre>

 </p>

<h3>Public Base Classes</h3>

<p>None.</p>

<h3>Template parameters</h3>

<table border="1">
<TBODY>    <tr>
        <th>Parameter </th>
        <th>Description </th>
        <th>Default </th>
    </tr>
    <tr>
        <td valign="top"><tt>DataObj</tt> </td>
        <td valign="top">The value type of objects in a <font
        size="2" face="Courier New">DBView</font>. </td>
        <td valign="top">&nbsp; </td>
    </tr>
    <tr>
        <td valign="top"><tt>ParamObj</tt> </td>
        <td valign="top">The type of object used to specify the
        postfix parameters to the <font size="2"
        face="Courier New">DBView</font>.</td>
        <td valign="top"><font size="2" face="Courier New">DefaultParamObj&lt;DataObj&gt;</font>&nbsp;
        </td>
    </tr>
</TBODY></table>

<p>&nbsp;</p>

<h3>Notation</h3>

<table border="0">
    <tr>
        <td valign="top"><tt>X</tt> </td>
        <td valign="top">A type that is a model of <font size="2"
        face="Courier New">LoggingHandler</font></td>
    </tr>
    <tr>
        <td valign="top"><tt>a</tt> </td>
        <td valign="top">Object of type <tt>X</tt> </td>
    </tr>
</table>

<h3>Expression semantics</h3>

<table border="1">
    <tr>
        <th>Name </th>
        <th>Expression </th>
        <th>Precondition </th>
        <th>Semantics </th>
        <th>Postcondition </th>
    </tr>
    <tr>
        <td valign="top">Default constructor </td>
        <td valign="top"><pre>X a()</pre>
        </td>
        <td valign="top">&nbsp; </td>
        <td valign="top">Construct the function object.</td>
        <td valign="top">&nbsp;</td>
    </tr>
    <tr>
        <td valign="top">Copy constructor </td>
        <td valign="top"><pre>X a(constX &amp;b)</pre>
        </td>
        <td valign="top">&nbsp; </td>
        <td valign="top">Copy construct the <font size="2"
        face="Courier New">LoggingHandler</font>.</td>
        <td valign="top">&nbsp;</td>
    </tr>
    <tr>
        <td>Assignment Operator</td>
        <td><font size="2" face="Courier New">X operator=(const X
        &amp;b)</font></td>
        <td>&nbsp;</td>
        <td>Assign the <font size="2" face="Courier New">LoggingHandler</font>.</td>
        <td>&nbsp;</td>
    </tr>
    <tr>
        <td valign="top">Log exception operator</td>
        <td valign="top"><pre>dtl_ios_base::MeansOfRecovery operator()(RootException &amp;ex, dtl_ios_base &amp;base, DataObj &amp;data, ParamObj &amp;params)</pre>
        </td>
        <td valign="top">&nbsp; </td>
        <td valign="top">This operator takes references to the
        thrown <font size="2" face="Courier New">RootException</font>
        object, the <font size="2" face="Courier New">dtl_ios_base</font>
        (iterator) which threw, and the <font size="2"
        face="Courier New">DataObj </font>and <font size="2"
        face="Courier New">ParamObj </font>relevant to the
        exception. Logs the exception to the vector of<font
        size="2" face="Courier New"> </font><font size="1"
        face="Courier New">LoggedTriple's</font><font size="2"> </font>and
        then tells the iterator to suppress the error (<font
        size="2" face="Courier New">dtl_ios_base::SUPPRESS_ERROR</font>).
        </td>
        <td valign="top">&nbsp;</td>
    </tr>
    <tr>
        <td valign="top">Get <b>copy</b> of exception log</td>
        <td valign="top"><pre>vector&lt;LoggedTriple&gt; GetLog() const</pre>
        </td>
        <td valign="top">&nbsp; </td>
        <td valign="top">Returns the logged exceptions as a
        vector of <font size="1" face="Courier New">LoggedTriple's.</font>
	Note that all copies of this handler share the same error log vector.</td>
        <td valign="top">&nbsp;</td>
    </tr>
</table>

<p>&nbsp;</p>

<h3>See also</h3>

<p><a href="AlwaysThrowsHandler.htm"><font size="2"
face="Courier New">AlwaysThrowsHandler</font></a><font size="2"
face="Courier New">, </font><a href="IOHandler.htm"><font
size="2" face="Courier New">IOHandler</font></a><font size="2"
face="Courier New">, </font><a href="DBView.htm"><font size="2"
face="Courier New">DBView</font></a><font size="2"
face="Courier New">, </font><a href="IndexedDBView.htm"><font
size="2" face="Courier New">IndexedDBView</font></a><a
href="IndexedDBView.htm"><font size="2"><!--start footer--></font></a></p>

<p>
<hr>

<p><a href="index.htm"><img src="dtl_home.gif" alt="[DTL Home]"
width="54" height="54"></a> <br>
</p>

<p>Copyright 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -