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

📄 insval.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>InsVal</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>InsVal</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">InsVal </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> before it is inserted into 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">InsVal</font> is
called on each record inserted or updated into the database via
either <a href="DBView.htm"><font size="2"
face="Courier New">DBView</font></a> 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">InsVal </font>can be found in the<font
size="2" face="Courier New"> DefaultInsValidate&lt;DataObj&gt;</font>
template. This functor always assumes the object is valid and
thus returns<font size="2" face="Courier New"> true</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">DefaultInsValidate&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 InsVal function

// Insertion is by default, always valid.
// If any RI constraints are violated,
// DB will return errors when the actual insert is performed
// which occurs after InsValidate returns.
// If there are certain business rule constraints you wish to enforce, put them in
// your own InsValidate 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 DefaultInsValidate {
public:
bool operator()(DataObj &amp;rowbuf)
{
	return true;
}
};
</code></pre>
<h3>Example 2:</h3>
<pre><code><span class="codeComment">// Enforce business rule for inserted rows</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">// specialization of DefaultInsValidate for Example
// can have any number of InsValidate functions for a single data class just as with
// ParamObj's ... below is general business rule constraint we wish to enforce for all Examples</span>
template&lt;&gt; class dtl::DefaultInsValidate&lt;Example&gt; {
public: 
bool operator()(Example &amp;rowbuf)
{
	<span class="codeComment">// data is valid if rowbuf.exampleStr is nonempty and rowbuf.exampleDouble is 
	// between 0 and 100 (like a percentage)</span>
	return (rowbuf.exampleStr.length() &gt; 0 &amp;&amp; rowbuf.exampleDouble &gt;= 0.0 &amp;&amp;
		rowbuf.exampleLong &lt;= 100.0);
}
};
</code></pre>
<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"> InsVal</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(const X &amp;b)</pre>
        </td>
        <td valign="top">&nbsp; </td>
        <td valign="top">Copy construct the<font size="2"
        face="Courier New"> InsVal.</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()(DataObj &amp;rowbuf)</pre>
        </td>
        <td valign="top">&nbsp; </td>
        <td valign="top">This operator takes a reference to a <font
        size="2" face="Courier New">rowbuf </font>holding a user
        defined data object. The job of the operator is to
        validate this <font size="2" face="Courier New">DataObj</font>.
        On exit, the operator 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>should contain 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><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 + -