📄 update_iterator.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>DBView<DataObj, ParamObj>::update_iterator</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>DBView<DataObj, ParamObj>::update_iterator</h1>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td><img src="iterator.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>: iterators</td>
<td align="right" valign="top"><b>Component type</b>:
type</td>
</tr>
</table>
<h3>Description</h3>
<p><tt>DBView<DataObj, ParamObj>::update_iterator</tt>
is an <a
href="http://www.sgi.com/tech/stl/OutputIterator.html">Output
Iterator</a> that performs the updating of objects of type <font
size="2" face="Courier New">DataObj</font> in a particular <font
size="2" face="Courier New">DBView</font><font size="2"> </font>(and
thus the database). The actual <font size="2" face="Courier New">DataObj
</font><font size="3">that the</font><font size="4"> </font><font
size="2" face="Courier New">update_iterator</font><font size="2">
</font>references is the new value that any records meeting the
iterator's SQL query. The <font size="2" face="Courier New">update_iterator
</font>generates this SQL query to perform the update as: <font
size="2" face="Courier New">"UPDATE " +
tablename_from_view + "SET " + "<field1_fromBCA>=(?),
<field2_fromBCA>=(?), ... " + posfix_clause_from_view</font>.
The parameters in the <font size="2" face="Courier New">SET </font><font
size="3">clause from the </font><a href="BCA.htm"><tt>BCA</tt></a><tt>
</tt><font size="3">are automatically bound by the </font><tt>update_iterator
</tt><font size="3">to the fields in the </font><font size="2"
face="Courier New">DataObj. </font><font size="3">These
parameters are set automatically upon assignment to the </font><font
size="2" face="Courier New">update_iterator.</font><font size="3">
All parameters in the postfix clause will be bound to the</font><font
size="2" face="Courier New"> ParamObj. </font>Note that all of
the restrictions of an <a
href="http://www.sgi.com/tech/stl/OutputIterator.html">Output
Iterator</a> must be obeyed, including the restrictions on the
ordering of <tt>operator*</tt> and <tt>operator++</tt> operations.
</p>
<h3>Definition</h3>
<p>Defined in the <font size="2" face="Courier New">update_iterator.h</font>
header file. </p>
<h3>Example:</h3>
<pre><code><span class="codeComment">//Update objects in the database via an update_iterator</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)
{ }
};
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;
}
};
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">// update Example object (with new values) meeting a query in the database</span>
void UpdateData()
{
<span class="codeComment">// construct view</span>
DBView<Example, ExampleParamObj>
view("DB_EXAMPLE", BCAExampleObj(),
"WHERE INT_VALUE BETWEEN (?) AND (?) AND "
"STRING_VALUE = (?) OR EXAMPLE_DATE = (?)", BPAParamObj());
<span class="codeComment">// build an updater for the view
// *** SQL Query Generated for this update_iterator:" ***
// *** (Note: All column and field names arealphabetized due to our implementation) ***
// "UPDATE DB_EXAMPLE SET DOUBLE_VALUE = (?), EXAMPLE_DATE = (?), EXAMPLE_LONG = (?), INT_VALUE = (?), "
// "STRING_VALUE = (?) WHERE INT_VALUE BETWEEN (?) AND (?) AND STRING_VALUE = (?) OR EXAMPLE_DATE = (?)"
</span>
DBView<Example, ExampleParamObj>::update_iterator
exampleUpdater = view;
<span class="codeComment">// set data fields we want to update to their desired values
// exampleStr to "Updated" andsampleLong to 0</span>
Example updateMe;
updateMe.exampleStr = "Updated";
updateMe.exampleLong = 25;
TIMESTAMP_STRUCT today = {2000, 9, 29, 0, 0, 0,0};
updateMe = Example(2121, "Updated", 99.99, 25, today);
*exampleUpdater = updateMe;
<span class="codeComment">// now set the parameters indicating which rows</span>
we want the update applied
exampleUpdater.Params().lowIntValue = 5;
exampleUpdater.Params().highIntValue = 13;
exampleUpdater.Params().strValue = "FindMe";
TIMESTAMP_STRUCT paramDate = {1999, 11, 11, 0,0, 0, 0};
exampleUpdater.Params().dateValue = paramDate;
<span class="codeComment">// execute the update</span>
exampleUpdater++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -