?? bpa.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>BPA</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>BPA</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>A <font size="2" face="Courier New">BPA</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()</font></a>)
that is called to create an association between the parameters in a SQL statement and the
fields in a user defined parameter object that is used to hold
individual values to pass to the query.</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>.</p>
<h3>Example 1:</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 2:</h3>
<pre><code><span class="codeComment">//Function object to bind SQL parameters to a data object</span>
class BPAExampleObj
{
public:
void operator()(BoundIOs &boundIOs, ParamObjExample &paramObj)
{
boundIOs[0] == paramObj.lowIntValue;
boundIOs[1] == paramObj.highIntValue;
boundIOs[2] == paramObj.strValue;
boundIOs[3] == paramObj.dateValue;
}
};
</code></pre>
<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">BPA</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"> </td>
<td valign="top">Construct the function object.</td>
<td valign="top"> </td>
</tr>
<tr>
<td valign="top">Copy constructor </td>
<td valign="top"><pre>X a(constX &b)</pre>
</td>
<td valign="top"> </td>
<td valign="top">Copy construct the <font size="2"
face="Courier New">BPA</font>.</td>
<td valign="top"> </td>
</tr>
<tr>
<td valign="top">Assignment operator</td>
<td valign="top"><pre>X& operator=(const X&b)</pre>
</td>
<td valign="top"> </td>
<td valign="top">Assignment copy</td>
<td valign="top"> </td>
</tr>
<tr>
<td valign="top">Bind columns operator</td>
<td valign="top"><pre>void operator()(BoundIOs &boundIOs, ParamObj &parambuf)</pre>
</td>
<td valign="top"> </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">parambuf </font>holding
a user defined parameter object. The job of the bind
parameters operator is to create an association between
parameters in a SQL view as designated by a <font
size="2" face="Courier New">"(?)" </font>and
fields in a user defined parameter object. This
association is usually created by invoking the following
cantrip:<p><font size="2" face="Courier New">boundIOs[SQL
Parameter Number] == parambuf.FieldName </font></p>
<p>for each parameter in the SQL query. For details on
this syntax see <a href="BoundIO.htm"><font size="2"
face="Courier New">BoundIOs</font></a><font size="2"
face="Courier New">. </font>The parameters to be bound
must be statically allocated members of the <font
size="2" face="Courier New">ParamObj</font> (there are
some exceptions - see<font size="2" face="Courier New"> </font><a
href="BoundIO.htm"><font size="2" face="Courier New">BoundIOs</font></a><font
size="2" face="Courier New"> </font>for details). At the
end of the operation, all parameters to be bound in the
SQL query must be in the <a href="BoundIO.htm"><font
size="2" face="Courier New">BoundIOs</font></a><font
size="2" face="Courier New"> </font>container. When <font
size="2" face="Courier New">operator()</font> is called,
the <font size="2" face="Courier New">BoundIOs </font>container
<strong>will not </strong>be empty, but will typically
contain any previously bound fields from the <a
href="BCA.htm"><font size="2" face="Courier New">BCA</font></a><font
size="2" face="Courier New">.</font></p>
</td>
<td valign="top"><a href="BoundIO.htm"><font size="2"
face="Courier New">BoundIOs</font></a> contains a
complete list of parameter in the SQL query which are
bound to the <font size="2" face="Courier New">ParamObj</font>.</td>
</tr>
</table>
<p> </p>
<h3>Notes</h3>
<p>None.</p>
<h3>See also</h3>
<p><a href="BCA.htm"><font size="2" face="Courier New">BCA</font></a><font
size="2" face="Courier New">, </font><a href="BoundIO.htm"><font
size="2" face="Courier New">BoundIOs</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 + -