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

📄 iohandler.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>IOHandler&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>IOHandler&lt;DataObj, ParamObj&gt;</h1>


















<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>
<h3>Description</h3>

<p>An <font size="2" face="Courier New">IOHandler</font> is a
function object (or a wrapped function pointer if you use 
<a href="cb_ptr_fun.htm"> <font size="2" face="Courier New">cb_ptr_fun_w_ret()</font></a>) 
that is called when exceptions are thrown in <font
size="2" face="Courier New">DB_iterator</font> operations. The
handler uses the state of the iterator passed in to decide how to
process the exception. After performing its work, the handler
tells the iterator whether to suppress the error (<font size="2"
face="Courier New">dtl_ios_base::SUPPRESS_ERROR</font>) or
to re-throw the exception (<font size="2"
face="Courier New">dtl_ios_base::THROW_EXCEPTION</font>). To use
the <font size="2" face="Courier New">IOHandler </font>facility,
declare your own handler class as shown in the examples below. To install a handler, 
pass your handler to the iterator's set_io_handler() function.
For example, suppose your handler is of type <font size="2"
face="Courier New">MyHandler&lt;DataObj, ParamObj&gt; </font> and you wish to pass it
to an iterator called <font size="2" face="Courier New">DB_iterator&lt;DataObj,
ParamObj&gt;&nbsp;it</font>.  You would use <font size="2" face="Courier New">set_io_handler()</font><font
size="3"> by saying:</font><font size="2" face="Courier New"> it.set_io_handler(MyHandler&lt;DataObj,
ParamObj&gt;()). </font><font size="3">Later on, you may need to
extract things such as an error log from your handler or other
state information. To query your handler,
extract it by invoking</font><font size="2" face="Courier New">
it.get_io_handler((MyHandler *) NULL).</font><font
size="3"> The dummy pointer is passed in to tell the compiler the
type of the result of </font><font size="2" face="Courier New">get_io_handler().
</font><font size="3">You can also set a default handler for a </font><font
size="2" face="Courier New">DBView</font><font size="3"> so that all
newly created iterators over that view will use this default handler if they don't
explicitly install their own handler. To set the default handlder for a </font><font size="2"
face="Courier New">DBView</font><font size="3"> call the get_io_handler() and set_io_handler()
methods for the </font><font size="2"
face="Courier New">DBView</font><font size="3">.  The handler for a </font><font
size="2" face="Courier New">DBView </font><font size="3">defaults
to  </font><a href="LoggingHandler.htm"><font
size="2" face="Courier New">LoggingHandler</font></a>
</font><font
size="3">, which logs errors to a vector.  Finally, if you are working with an </font><font
size="2" face="Courier New">IndexedDBView </font><font
size="3">you can call </font><font
size="2" face="Courier New">IndexedDBView::get_io_handler()</font><font
size="3"> to get the handler of the underlying</font><font
size="2" face="Courier New"> DBView</font><font
size="3"> that it uses.</font></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="LoggingHandler.htm"><font
size="2" face="Courier New">LoggingHandler</font></a><font
size="2" face="Courier New">.</font></p>

<h3>Example 1:</h3>

<p><h3> A good example of an IOHandler: LoggingHandler</h3>

<pre><code>
<span class="codeComment">// *** Note: this is the actual LoggingHandler template from the DTL code ***

// this handler logs exceptions to a vector
// then tells caller to reperform the action</span>
template&lt;class DataObj, class ParamObj = DefaultParamObj&lt;DataObj&gt;&nbsp;&gt; class LoggingHandler
{
public:
	struct LoggedTriple
	{
		string errmsg;
		DataObj dataObj;
		ParamObj paramObj;

		LoggedTriple() : errmsg(""), dataObj(), paramObj() { }

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

private:
	CountedPtr&lt;vector&lt;LoggedTriple&gt;&nbsp;&gt; errorLog;<span class="codeComment">// all copies of the handler will share this error log</span>
	
public:

	LoggingHandler() :
		  errorLog() { }
	
	dtl_ios_base::MeansOfRecovery
		operator()(RootException &amp;ex, dtl_ios_base &amp;base,
			DataObj &amp;data, ParamObj &amp;params)
	{
		<span class="codeComment">// log the error</span>
		errorLog.push_back(LoggedTriple(ex.what(), data, params));
		
		<span class="codeComment">// tell the program to continue</span>
		return dtl_ios_base::SUPPRESS_ERROR;
	}

	vector&lt;LoggedTriple&gt; GetLog() const
	{
		return errorLog;
	}

};
</code></pre>

<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;;
	

⌨️ 快捷键说明

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