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

📄 selval.htm

📁 The goal of this library is to make ODBC recordsets look just like an STL container. As a user, you
💻 HTM
字号:
<html>


<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>SelVal</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>SelVal</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><font size="2" face="Courier New">SelVal</font> is a function object
(this can be 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 to to validate a user defined <font size="2"
face="Courier New">DataObj</font> as it is read from the database.
The function returns <font size="2" face="Courier New">true</font>
if the <font size="2" face="Courier New">DataObj </font>contains
a valid set of fields, <font size="2" face="Courier New">false</font>
otherwise. <font size="2" face="Courier New">SelVal </font>is
called on each record read from a database via either <a
href="DBView.htm"><font size="2" face="Courier New">DBView</font></a><font
size="2" face="Courier New"> </font>or <a
href="IndexedDBView.htm"><font size="2"
face="Courier New">IndexedDBView</font></a><font size="2"
face="Courier New">. </font>The default behavior of a <font
size="2" face="Courier New">SelVal </font>can be found in the<font
size="2" face="Courier New"> DefaultSelValidate&lt;DataObj&gt;</font>
template. This particular functor returns<font size="2"
face="Courier New"> true</font> if all of the fields read into
the <font size="2" face="Courier New">BoundIOs </font>have a
value (that is, all fetched columns are non-NULL, tested using <font
size="2" face="Courier New">BoundIO::IsNull()</font>), otherwise
it returns <font size="2" face="Courier New">false</font>.
Through the use of template specialization, you can customize the
default behavior for this functor by writing your own <font
size="2" face="Courier New">DefaultSelValidate&lt;DataObj&gt; </font>for
that class of <font size="2" face="Courier New">DataObj's.</font></p>

<h3>Refinement of</h3>

<p>None.</p>

<h3>Associated types</h3>

<p><a href="BoundIO.htm"><font size="2" face="Courier New">BoundIOs</font></a><font
size="2" face="Courier New">.</font></p>

<h3>Example 1:</h3>
<pre><code><span class="codeComment">//Default SelVal function to make sure fields in a row selected from the database are valid

// Default select validation behavior ... data is valid if and only if
// there are no columns which are null.
// If there are other checks you wish to make, put them in
// your own SelVal functor.
// You can also specialize this template if you wish to have different default behavior
// for your data class.</span>
template&lt;class DataObj&gt; class DefaultSelValidate {
public:
bool operator()(BoundIOs &amp;boundIOs,DataObj &amp;rowbuf)
{
	for (BoundIOs::iterator b_it = boundIOs.begin();
				b_it != boundIOs.end(); b_it++)
	{
		BoundIO &amp;boundIO = (*b_it).second;
		if (boundIO.IsColumn() &amp;&amp; boundIO.IsNull())
			return false;  <span class="codeComment">// found null column ... data is invalid</span>
	}

	return true;	<span class="codeComment">// no nulls found ... data is OK</span>
}
};

</code></pre>

<h3>Example 2:</h3>
<pre><code><span class="codeComment">// Assign valid defaults for null values</span>

class Example
{
  public:					<span class="codeComment">// tablename.columnname:</span>
	int exampleInt;	    			<span class="codeComment">// DB_EXAMPLE.INT_VALUE</span>
	string exampleStr;			<span class="codeComment">// DB_EXAMPLE.STRING_VALUE</span>
	double exampleDouble;			<span class="codeComment">// DB_EXAMPLE.DOUBLE_VALUE</span>
	long exampleLong;			<span class="codeComment">// DB_EXAMPLE.EXAMPLE_LONG</span>
	TIMESTAMP_STRUCT exampleDate;		<span class="codeComment">// DB_EXAMPLE.EXAMPLE_DATE</span>
};

<span class="codeComment">// Validation behavior, assign default values for NULL fields</span>
template&lt;&gt; class dtl::DefaultSelValidate&lt;Example&gt; 
{
public:
bool operator()(BoundIOs &amp;boundIOs, Example &amp;rowbuf) {
	if (boundIOs[&quot;INT_VALUE&quot;].IsNull()) {
		rowbuf.exampleInt = 0;	
	}
	if (boundIOs[&quot;STRING_VALUE&quot;].IsNull()) {
		rowbuf.exampleStr = &quot;&quot;;	
	}
	if (boundIOs[&quot;DOUBLE_VALUE&quot;].IsNull()) {
		rowbuf.exampleDouble = 0;	
	}
	if (boundIOs[&quot;EXAMPLE_LONG&quot;].IsNull()) {
		rowbuf.exampleLong = 0;	
	}
	if (boundIOs[&quot;EXAMPLE_DATE&quot;].IsNull()) {
		const TIMESTAMP_STRUCT defaultDate = {2000, 1, 1, 0, 0, 0, 0};
		rowbuf.exampleDate = defaultDate;	
	}

	<span class="codeComment">// Now check that values are in acceptable range
	// Return false/failure if values out of range</span>
	if (rowbuf.exampleDouble &gt; 100)
		return false;

	return true;	// data is OK
}

};</code></pre>

<p>&nbsp;</p>

<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">SelVal</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"> SelVal</font>.</td>
        <td valign="top">&nbsp;</td>
    </tr>
    <tr>
        <td valign="top">Assignment operator</td>
        <td valign="top"><pre>X&amp; operator=(const X&amp;b)</pre>
        </td>
        <td valign="top">&nbsp; </td>
        <td valign="top">Assignment copy</td>
        <td valign="top">&nbsp;</td>
    </tr>
    <tr>
        <td valign="top">Validate operator</td>
        <td valign="top"><pre>void operator()(BoundIOs &amp;boundIOs, DataObj &amp;rowbuf))</pre>
        </td>
        <td valign="top">&nbsp; </td>
        <td valign="top">This operator takes a <font size="2"
        face="Courier New">BoundIOs</font> object and a reference
        to a <font size="2" face="Courier New">rowbuf</font>
        holding a user defined data object. The job of the
        function is to validate the user defined data object and/or
        make any default assignments in the data object in the
        case of <font size="2" face="Courier New">NULL</font>
        fields. On exit, the function should return <font
        size="2" face="Courier New">true</font> if it was able to
        validate the data object, <font size="2"
        face="Courier New">false </font>otherwise.</td>
        <td valign="top">The fields in <font size="2"
        face="Courier New">DataObj </font>that are bound to query
        parameters should be initialized with valid values if the
        function returns <font size="2" face="Courier New">true</font>.</td>
    </tr>
</table>

<h3>Notes</h3>
<p>None.</p>

<h3>See also</h3>

<p><a href="BoundIO.htm"><font size="2" face="Courier New">BoundIOs</font></a><font
size="2" face="Courier New">, </font><a href="BCA.htm"><font
size="2" face="Courier New">BCA</font></a><font size="2"
face="Courier New">, </font><a href="BPA.htm"><font size="2"
face="Courier New">BPA</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>


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