📄 boundio.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>BoundIO and BoundIOs</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>BoundIO and BoundIOs</h1>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td><img src="utilities.gif" width="194" height="38"></td>
<td align="right"><img src="type.gif" width="194"
height="39"></td>
</tr>
<tr>
<td valign="top"><b>Category</b>: utilities</td>
<td align="right" valign="top"><b>Component type</b>:
type</td>
</tr>
</table>
<h3>Description</h3>
<p>A <font size="2" face="Courier New">BoundIO </font>is an
object used to hold an association between a field in a query and
a field in a user defined data object. The <font size="2"
face="Courier New">BoundIO</font> class is held in a private
member of the <a href="DBView.htm"><font size="2"
face="Courier New">DBView</font></a><font size="2"
face="Courier New"> </font>template called the <font size="2"
face="Courier New">BoundIOs </font>object which is an STL <a
href="http://www.sgi.com/tech/stl/Map.html"><font size="2"
face="Courier New">map</font></a><font size="2"
face="Courier New"><string, BoundIO></font> that holds a
set of <font size="2" face="Courier New">BoundIO</font> objects that
are mapped by SQL field name. As an end user, the four places you
will encouter a <font size="2" face="Courier New">BoundIO </font>are
when writing <a href="BCA.htm"><font size="2" face="Courier New">BCA</font></a>
, <a href="BPA.htm"><font size="2" face="Courier New">BPA</font></a>,
<a href="InsVal.htm"><font size="2" face="Courier New">InsVal</font></a>
or <a href="SelVal.htm"><font size="2" face="Courier New">SelVal</font></a>
functions.</p>
<h3>Definition</h3>
<p>Defined in the <font size="2" face="Courier New">BoundIO.h </font><font
size="3">header file. </font></p>
<h3>Refinement of</h3>
<p>None.</p>
<h3>Associated types</h3>
<p>None.</p>
<h3>Example 1:</h3>
<pre><code><span class="codeComment">Functor to bind SQL columns to a data object</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>
};</pre>
<pre>class BCAExampleObj
{
public:
void operator()(BoundIOs &boundIOs, Example &rowbuf)
{
boundIOs["INT_VALUE"] == rowbuf.exampleInt;
boundIOs["STRING_VALUE"] == rowbuf.exampleStr;
boundIOs["DOUBLE_VALUE"] == rowbuf.exampleDouble;
boundIOs["EXAMPLE_LONG"] == rowbuf.exampleLong;
boundIOs["EXAMPLE_DATE"] == rowbuf.exampleDate;
}
};
</code></pre>
<p> </p>
<h3>Example 2:</h3>
<pre><code><span class="codeComment">//BPA Functor to bind SQL parameters to a data object</span>
<span class="codeComment">// "Example" class to hold rows from our database table</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>
Example(int exInt, const string &exStr, double exDouble, long exLong,
const TIMESTAMP_STRUCT &exDate) :
exampleInt(exInt), exampleStr(exStr), exampleDouble(exDouble), exampleLong(exLong),
exampleDate(exDate)
{ }
};
<span class="codeComment">// Create an association between table columns and fields in our object</span>
class BCAExampleObj
{
public:
void operator()(BoundIOs &cols, Example &rowbuf)
{
cols["INT_VALUE"] == rowbuf.exampleInt;
cols["STRING_VALUE"] == rowbuf.exampleStr;
cols["DOUBLE_VALUE"] == rowbuf.exampleDouble;
cols["EXAMPLE_LONG"] == rowbuf.exampleLong;
cols["EXAMPLE_DATE"] == rowbuf.exampleDate;
}
}
class ExampleParamObj
{
public:
int lowIntValue;
int highIntValue;
string strValue;
TIMESTAMP_STRUCT dateValue;
};
class BPAParamObj
{
public:
void operator()(BoundIOs &boundIOs, ExampleParamObj &paramObj)
{
boundIOs[0] == paramObj.lowIntValue;
boundIOs[1] == paramObj.highIntValue;
boundIOs[2] == paramObj.strValue;
boundIOs[3] == paramObj.dateValue;
}
};
<span class="codeComment">// read some Example objects from the database and return a vector of</span>
<span class="codeComment">// the results, use BPA to set join parameters</span>
vector<Example> ReadData()
{
vector<Example> results;
<span class="codeComment">// construct view</span>
DBView<Example, ExampleParamObj>
view("DB_EXAMPLE", BCAExampleObj(),
"WHERE INT_VALUE BETWEEN (?) AND (?) AND "
"STRING_VALUE = (?) OR EXAMPLE_DATE < (?) ORDER BY EXAMPLE_LONG",
BPAParamObj());
<span class="codeComment">// loop through query results and add them to our vector</span>
<span class="codeComment">// in this loop, read_it.GetLastCount() records read from DB</span>
DBView<Example, ExampleParamObj>::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++)
{
cout << "Reading element #" << read_it.GetLastCount() << endl;
results.push_back(*read_it);
cout << "read_it->exampleInt = " << read_it->exampleInt << endl;
cout << "read_it->exampleStr = " << read_it->exampleStr << endl;
}
return results;
}
</code></pre>
<p> </p>
<h3>Example 3:</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<class DataObj> class DefaultSelValidate {
public:
bool operator()(BoundIOs &boundIOs,DataObj &rowbuf)
{
for (BoundIOs::iterator b_it = boundIOs.begin();
b_it != boundIOs.end(); b_it++)
{
BoundIO &boundIO = (*b_it).second;
if (boundIO.IsColumn() && 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>Public base classes: BoundIO</h3>
<p>None.</p>
<h3>Public base classes: BoundIOs</h3>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -