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

📄 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 页
字号:
<html>

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<title></title>
</head>

<body>


<head>
<style>
CODE {COLOR: #990000;}
.code{COLOR: #990000}
.codeComment{COLOR: #008000}
.codeHighlight{BACKGROUND-COLOR: #FFFF00}
.codeFileName{FONT-WEIGHT: bold;}
</style>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta name="Author" content="Mike Gradman">
<meta name="KeyWords"
content="DTL, Oracle, ODBC, database API, C++, Template Library">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<!--
  -- Copyright 2000
  -- Michael Gradman & Corwin Joy
  --
  -- Permission to use, copy, modify, distribute and sell this software
  -- and its documentation for any purpose is hereby granted without fee,
  -- provided that the above copyright notice appears in all copies and
  -- that both that copyright notice and this permission notice appear
  -- in supporting documentation.  Corwin Joy & Michael Gradman make no
  -- representations about the suitability of this software for any
  -- purpose.  It is provided "as is" without express or implied warranty.
  --
  --
  -- Copyright (c) 1996-1999
  -- Silicon Graphics Computer Systems, Inc.
  --
  -- Permission to use, copy, modify, distribute and sell this software
  -- and its documentation for any purpose is hereby granted without fee,
  -- provided that the above copyright notice appears in all copies and
  -- that both that copyright notice and this permission notice appear
  -- in supporting documentation.  Silicon Graphics makes no
  -- representations about the suitability of this software for any
  -- purpose.  It is provided "as is" without express or implied warranty.
  --
  -- Copyright (c) 1994
  -- Hewlett-Packard Company
  --
  -- Permission to use, copy, modify, distribute and sell this software
  -- and its documentation for any purpose is hereby granted without fee,
  -- provided that the above copyright notice appears in all copies and
  -- that both that copyright notice and this permission notice appear
  -- in supporting documentation.  Hewlett-Packard Company makes no
  -- representations about the suitability of this software for any
  -- purpose.  It is provided "as is" without express or implied warranty.
  --
  -->
<!-- Generated by htmldoc -->
<title>LoggingHandler&lt;DataObj, ParamObj&gt;</title>
</head>

<body bgcolor="#FFFFFF" text="#000000" link="#0000EE"
vlink="#551A8B" alink="#FF0000">

<p><font size="6" face="Bookman Old Style"><em><strong><u>dtl</u></strong></em></font></p>

<p><img src="stat.gif" width="6" height="6"> <!--end header--> <br>
</p>
<h1>LoggingHandler&lt;DataObj, ParamObj&gt;</h1>

<p> 
















<table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td><img src="functors.gif" width="194" height="38"></td>
        <td align="right"><img src="concept.gif" width="194"
        height="39"></td>
    </tr>
    <tr>
        <td valign="top"><b>Category</b>: functors</td>
        <td align="right" valign="top"><b>Component type</b>:
        concept</td>
    </tr>
</table> </p>

<h3>Description</h3>

<p>A <font size="2" face="Courier New">LoggingHandler</font> is
an <font size="2" face="Courier New">IOHandler </font>function
object that is called when exceptions are thrown in <font
size="2" face="Courier New">DB_iterator</font> operations. This
handler simply logs the exceptions that are passed to it and
tells the caller to suppress the error (<font size="2"
face="Courier New">dtl_ios_base::SUPPRESS_ERROR</font>). <font
size="2" face="Courier New">LoggingHandler</font> is <font
size="3">the default handler for a </font><font size="2"
face="Courier New">DBView</font><font size="3">.</font></p>

<h3>Definition</h3>

<p>Defined in the <font size="2" face="Courier New">DBView.h</font><font
size="1" face="Courier New"> </font>header file. </p>

<h3>Associated types</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></p>

<p>The following nested struct is defined.:</p>

<pre>	// log entry describing exception information including stringified exception and relevant DataObj and ParamObj</pre>

<pre>	struct LoggedTriple
	{
		string errmsg; // message describing the exception thrown - usually the stringified exception
		DataObj dataObj; // DataObj relevant to the exception thrown
		ParamObj paramObj; // ParamObj relevant to the exception thrown

		LoggedTriple() : errmsg(&quot;&quot;), dataObj(), paramObj() { }

		LoggedTriple(const string &amp;msg, const DataObj &amp;data, const ParamObj &amp;param) :
		  errmsg(msg), dataObj(data), paramObj(param) { }
	};</pre>

<pre> </pre>

<h3>Example:</h3>

<p><pre><code><span class="codeComment">// Example Code Using LoggingHandler on a DBView

// test of failed SelValidate() when reading data</span>
void TestBadSelValidate()
{
 	vector&lt;Example&gt; results;

	<span class="codeComment">// construct view
	// DBView&lt;Example&gt; is actually DBView&lt;Example, 
	// DefaultParamObj&lt;Example&gt; &gt; thanks to the default 
	// argument to the DBView template

	// use our bad BCA which references a nonexistent column name in DB_EXAMPLE</span>
	DBView&lt;Example&gt;
		view(&quot;DB_EXAMPLE&quot;, BCAExampleObj(),
		&quot;WHERE INT_VALUE BETWEEN (?) AND (?) AND &quot;
		&quot;STRING_VALUE = (?) OR EXAMPLE_DATE &lt; (?) ORDER BY EXAMPLE_LONG&quot;,
		BPAExampleObj(), BadSelValidate());

	<span class="codeComment">// loop through query results and add them to our vector
	// in this loop, read_it.GetLastCount() records read from DB</span>

	DBView&lt;Example&gt;::select_iterator read_it = view.begin();

	<span class="codeComment">// set parameter values for the WHERE clause in our SQL query</span>
	read_it.Params().lowIntValue = 2;
	read_it.Params().highIntValue = 8;
	read_it.Params().strValue = &quot;Example&quot;;
	
	TIMESTAMP_STRUCT paramDate = {2000, 1, 1, 0, 0, 0, 0};
	read_it.Params().dateValue = paramDate;

	for ( ; read_it != view.end(); read_it++)
	{
	try
		{
		  <span class="codeComment">// note that the read_iterator::GetLastCount()  is incremented in operator++()
		  // remember that the record is fetched and thus the count incremented
		  // before operator*() is applied to the read_iterator</span>

		  cout &lt;&lt; &quot;Reading element #&quot; &lt;&lt; read_it.GetLastCount() &lt;&lt; endl;
		  
		  cout &lt;&lt; &quot;read_it-&gt;exampleInt = &quot; &lt;&lt; read_it-&gt;exampleInt &lt;&lt; endl;
		  cout &lt;&lt; &quot;read_it-&gt;exampleStr = &quot; &lt;&lt; read_it-&gt;exampleStr &lt;&lt; endl;
		  
		  results.push_back(*read_it);
		}
		catch (RootException &amp;ex)
		{
		  cout &lt;&lt; &quot;Caught Exception!!!!&quot; &lt;&lt; endl;
		  cout &lt;&lt; ex.what() &lt;&lt; endl;
		}
	}

	LoggingHandler&lt;Example&gt; handler = 
		read_it.get_io_handler((LoggingHandler&lt;Example&gt; *) NULL);

	typedef LoggingHandler&lt;Example&gt;::LoggedTriple LoggedTriple;

	vector&lt;LoggedTriple&gt; errors = handler.GetLog();

	for (vector&lt;LoggedTriple&gt;::iterator log_it = errors.begin(); log_it != errors.end();
			log_it++)
	{
		LoggedTriple error = *log_it;

⌨️ 快捷键说明

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