📄 dynamicindexeddbview.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>DynamicIndexedDBView <DynamicView></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>DynamicIndexedDBView <DynamicView></h1>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td><img src="containers.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>: containers</td>
<td align="right" valign="top"><b>Component type</b>:
type</td>
</tr>
</table>
<h3>Description</h3>
<p>The <font size="2" face="Courier New">DynamicIndexedDBView</font>
container is a refinement of <a href="IndexedDBView.htm"><font
size="2" face="Courier New">IndexedDBView</font></a> used for
queries where the number and types of the fields in the query is
unknown until runtime. <font size="2" face="Courier New">DynamicIndexedDBView</font>
specializes the <a href="IndexedDBView.htm"><font size="2"
face="Courier New">IndexedDBView</font></a> template to use a <font
size="2" face="Courier New">variant_row </font>object to hold
rows from the query. The <font size="2" face="Courier New">variant_row
</font>object provides a mechanism to hold an arbitrary number of
fields with values of arbitrary types. Individual fields within
the row are accessed by using methods from the <font size="2"
face="Courier New">variant_row</font> object.</p>
<h3>Refinement of</h3>
<p><a href="IndexedDBView.htm"><font size="2" face="Courier New">IndexedDBView</font></a>.
</p>
<h3>Associated types</h3>
<p>None, except for those defined by <a href="IndexedDBView.htm"><font
size="2" face="Courier New">IndexedDBView</font></a><font
size="2" face="Courier New">.</font></p>
<h3>Example:</h3>
<p><pre><code><span class="codeComment">// Using a DynamicIndexedDBView to read, update and insert records in a database.
// Dynamic IndexedDBView example
// ... classes as in </code><a href="IndexedDBViewExample.htm"><code>IndexedDBView example</code></a> <code> ....</span>
void DynamicIndexedViewExample()
{
DynamicDBView<ParamObjExample> dynamic_view("DB_EXAMPLE",
"INT_VALUE, STRING_VALUE, DOUBLE_VALUE, EXAMPLE_LONG, EXAMPLE_DATE",
"WHERE INT_VALUE BETWEEN (?) AND (?) OR "
"STRING_VALUE = (?) OR EXAMPLE_DATE <= (?) ORDER BY EXAMPLE_LONG",
BPAExampleObj());
DynamicIndexedDBView< DynamicDBView<ParamObjExample> >
indexed_view(dynamic_view,
"UNIQUE PrimaryIndex; STRING_VALUE;"
"IndexLongDate; EXAMPLE_LONG, EXAMPLE_DATE",
BOUND, USE_ALL_FIELDS, cb_ptr_fun(SetParamsExample));
<span class="codeComment">// Find the item where the STRING_VALUE matches the string "Foozle"</span>
DynamicIndexedDBView< DynamicDBView<ParamObjExample> >::indexed_iterator idxview_it = indexed_view.find(string("Foozle"));
<span class="codeComment">// Update the item with the key of "Foozle", to read "Fizzle" instead</span>
if (idxview_it != indexed_view.end()) {
variant_row replacement;
replacement = *idxview_it;
replacement["STRING_VALUE"] = string("Fizzle");
indexed_view.replace(idxview_it, replacement);
}
<span class="codeComment">// Now find a second set of items using AlternateIndex
// The STL convention for equal_range is to return a pair consisting of:
// 1. an iterator referring to the beginning of the list of found items
// 2. an iterator pointing to the end of the list of found items.
// We will remove all items in this range.</span>
const TIMESTAMP_STRUCT date_criteria = {2000, 1, 1, 0, 0, 0, 0};
long long_criteria = 33;
DynamicIndexedDBView< DynamicDBView<ParamObjExample> >::indexed_pair
pr = indexed_view.equal_range_AK("IndexLongDate", long_criteria, date_criteria);
idxview_it = pr.first;
cout << "*** Size before erase calls: " << indexed_view.size() << " ***" << endl;
<span class="codeComment">// Remove all rows that matched the criteria in our equal_range_AK lookup </span>
while (idxview_it !="pr.second)" {
<span class="codeComment">// as iterator is invalidated upon an erase(), use a temporary iterator
// to point to DataObj to erase
// increment idxview_it before we erase so it will still be valid
// when we erase the DataObj </span>
DynamicIndexedDBView< DynamicDBView<ParamObjExample> >::indexed_iterator deleteMe="idxview_it;"
idxview_it++;
indexed_view.erase(deleteMe);
}
cout << "*** Size after erase calls: " << indexed_view.size() << " ***" << endl;
<span class="codeComment">// Finally, insert a new item into the container </span>
pair<DynamicIndexedDBView< DynamicDBView<ParamObjExample> >::iterator, bool> ins_pr;
variant_row r(indexed_view.DataObj());
r["INT_VALUE"]=459;
r["STRING_VALUE"]=string("Unique String #1");
r["DOUBLE_VALUE"]=3.5;
r["EXAMPLE_LONG"]=1;
r["EXAMPLE_DATE"]=date_criteria;
ins_pr=indexed_view.insert(r);
cout << "insertion succeded=" << (ins_pr.second == true ? " true": " false") << endl;
}</code></pre>
</p>
<h3>Public base classes</h3>
<p><font size="2" face="Courier New">IndexedDBView<DynamicView></font></p>
<h3>Template parameters</h3>
<table border="1">
<tr>
<th>Parameter </th>
<th>Description </th>
<th>Default </th>
</tr>
<tr>
<td valign="top"><tt>DynamicView</tt> </td>
<td valign="top">The type of the dynamic SQL view (usually
a <a href="DynamicDBView.htm"><font size="2"
face="Courier New">DynamicDBView</font></a><font size="2"
face="Courier New"> </font>instantiation which will be
used as the underlying view for the<font size="2"
face="Courier New"> DynamicIndexedDBView</font>).</td>
<td valign="top"> </td>
</tr>
</table>
<p> </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"> DynamicIndexedDBView</font> </td>
</tr>
<tr>
<td valign="top"><tt>a</tt> </td>
<td valign="top">Object of type <tt>X</tt> </td>
</tr>
<tr>
<td valign="top"><tt>t</tt> </td>
<td valign="top">Object of type <tt>X::value_type</tt> </td>
</tr>
<tr>
<td valign="top"><tt>p</tt>, <tt>q</tt> </td>
<td valign="top">Object of type <tt>X::iterator</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(
DynamicDBView<...> &view,
const string &IndexNamesAndFields,
BoundMode bm = UNBOUND,
KeyMode km = USE_ALL_FIELDS,
SetParamsFn IndexedDBViewParam = NULL)</pre>
</td>
<td valign="top"> </td>
<td valign="top">This is exactly the same constructor as
that used by <font size="2" face="Courier New">IndexedDBView</font>.
The only difference is that the view passed in must be of
type <a href="DynamicDBView.htm"><font size="2"
face="Courier New">DynamicDBView</font></a> rather than a
regular <a href="DBView.htm"><font size="2"
face="Courier New">DBView</font></a>. See <a
href="IndexedDBView.htm"><font size="2"
face="Courier New">IndexedDBView</font></a><font size="2"
face="Courier New"> </font>for details on the constructor.</td>
<td valign="top">The size of the container is <font
size="4" face="Times New Roman"><tt>0. Rows are operated
on by obtaining the appropriate iterator from the
container.</tt></font></td>
</tr>
</table>
<h3>Members</h3>
<p>As per <a href="IndexedDBView.htm"><font size="2"
face="Courier New">IndexedDBView</font></a> with the following
changes.</p>
<table border="1">
<tr>
<th>Member </th>
<th>Where defined </th>
<th>Description </th>
</tr>
<tr>
<td valign="top"><pre><tt>X a(
DynamicDBView<...> &view,
const string &IndexNamesAndFields,
BoundMode bm = UNBOUND,
KeyMode km = USE_ALL_FIELDS,
SetParamsFn IndexedDBViewParam = DefaultSetParams<ParamObj>())</tt></pre>
</td>
<td valign="top"><a
href="http://www.sgi.com/tech/stl/Container.html">Container</a>
</td>
<td valign="top">Creates an empty <font size="2"
face="Courier New">DynamicIndexedDBView</font>. </td>
</tr>
<tr>
<td valign="top"><tt>variant_row DataObj() const </tt></td>
<td valign="top"> </td>
<td valign="top">Returns an empty <font size="2"
face="Courier New">variant_row </font>object which values
can be assigned to for use by insertion or update
iterators.</td>
</tr>
<tr>
<td valign="top"><tt>X &operator=(const X &other)</tt></td>
<td valign="top"> </td>
<td valign="top">Assignment operator.</td>
</tr>
<tr>
<td valign="top"><tt>void swap(X &other)</tt></td>
<td valign="top"> </td>
<td valign="top">Swap <font size="2" face="Courier New">*this</font>
with <tt>other</tt>.</td>
</tr>
</table>
<h3>See also</h3>
<p><a href="IndexedDBView.htm"><font size="2" face="Courier New">IndexedDBView</font></a><font
size="2" face="Courier New">, </font><a href="DynamicDBView.htm"><font
size="2" face="Courier New">DynamicDBView</font></a>, <a
href="http://www.sgi.com/tech/stl/AssociativeContainer.html">Associative
Container</a>, <a
href="http://www.sgi.com/tech/stl/MultipleAssociativeContainer.html">Multiple
Associative Container</a>, <a
href="http://www.sgi.com/tech/stl/UniqueSortedAssociativeContainer.html">Unique
Sorted Associative Container</a>, <a
href="http://www.sgi.com/tech/stl/MultipleSortedAssociativeContainer.html">Multiple
Sorted Associative Container</a> <!--start footer--> </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 + -