📄 logginghandler.htm
字号:
<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<DataObj, ParamObj></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<DataObj, ParamObj></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(""), dataObj(), paramObj() { }
LoggedTriple(const string &msg, const DataObj &data, const ParamObj &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<Example> results;
<span class="codeComment">// construct view
// DBView<Example> is actually DBView<Example,
// DefaultParamObj<Example> > thanks to the default
// argument to the DBView template
// use our bad BCA which references a nonexistent column name in DB_EXAMPLE</span>
DBView<Example>
view("DB_EXAMPLE", BCAExampleObj(),
"WHERE INT_VALUE BETWEEN (?) AND (?) AND "
"STRING_VALUE = (?) OR EXAMPLE_DATE < (?) ORDER BY EXAMPLE_LONG",
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<Example>::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 = "Example";
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 << "Reading element #" << read_it.GetLastCount() << endl;
cout << "read_it->exampleInt = " << read_it->exampleInt << endl;
cout << "read_it->exampleStr = " << read_it->exampleStr << endl;
results.push_back(*read_it);
}
catch (RootException &ex)
{
cout << "Caught Exception!!!!" << endl;
cout << ex.what() << endl;
}
}
LoggingHandler<Example> handler =
read_it.get_io_handler((LoggingHandler<Example> *) NULL);
typedef LoggingHandler<Example>::LoggedTriple LoggedTriple;
vector<LoggedTriple> errors = handler.GetLog();
for (vector<LoggedTriple>::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 + -