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

📄 bpa.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>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">// &quot;Example&quot; 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 &amp;exStr, double exDouble, long exLong,
		const TIMESTAMP_STRUCT &amp;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 &amp;cols, Example &amp;rowbuf)
    	{
	   cols[&quot;INT_VALUE&quot;] == rowbuf.exampleInt;
	   cols[&quot;STRING_VALUE&quot;] == rowbuf.exampleStr;
	   cols[&quot;DOUBLE_VALUE&quot;] == rowbuf.exampleDouble;
	   cols[&quot;EXAMPLE_LONG&quot;] == rowbuf.exampleLong;
	   cols[&quot;EXAMPLE_DATE&quot;] == rowbuf.exampleDate;
	}
}

class ExampleParamObj
{
    public:
       	int lowIntValue;
	int highIntValue;
	string strValue;
	TIMESTAMP_STRUCT dateValue;
};

class BPAParamObj
{
public:
	void operator()(BoundIOs &amp;boundIOs, ExampleParamObj &amp;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&lt;Example&gt; ReadData()
{
	vector&lt;Example&gt; results;

	<span class="codeComment">// construct view</span>
	
	DBView&lt;Example, ExampleParamObj&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;,
		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&lt;Example, ExampleParamObj&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;;
	
	TIMESTAMP_STRUCT paramDate = {2000, 1, 1, 0, 0, 0, 0};
	read_it.Params().dateValue = paramDate;

	for ( ; read_it != view.end();  read_it++)
	{
		cout &lt;&lt; &quot;Reading element #&quot; &lt;&lt; read_it.GetLastCount() &lt;&lt; endl;
		results.push_back(*read_it);

		cout &lt;&lt; &quot;read_it-&gt;exampleInt = &quot; &lt;&lt; read_it-&gt;exampleInt &lt;&lt; endl;
		cout &lt;&lt; &quot;read_it-&gt;exampleStr = &quot; &lt;&lt; read_it-&gt;exampleStr &lt;&lt; endl;
		
	}
	
	return results;
}
</code></pre>
<p>&nbsp;</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 &amp;boundIOs, ParamObjExample &amp;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">&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">BPA</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">Bind columns operator</td>
        <td valign="top"><pre>void operator()(BoundIOs &amp;boundIOs, ParamObj &amp;parambuf)</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">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">&quot;(?)&quot; </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>&nbsp;</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 + -