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

📄 indexeddbview.htm

📁 The goal of this library is to make ODBC recordsets look just like an STL container. As a user, you
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<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>IndexedDBView &lt;View&gt;</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>IndexedDBView &lt;View&gt;</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">IndexedDBView </font>Container
is a refinement of a <a
href="http://www.sgi.com/tech/stl/UniqueAssociativeContainer.html">Unique
Associative Container</a> with the property that elements may be
bound to an underlying database and may be indexed by one or more
criteria.</p>

<h3>Definition</h3>

<p>Defined in the <font size="2" face="Courier New">IndexedDBView.h
</font><font size="3">header file.</font></p>

<h3>Refinement of</h3>

<p><a
href="http://www.sgi.com/tech/stl/UniqueAssociativeContainer.html">Unique
Associative Container</a> </p>

<h3>Associated types</h3>

<p>None, except for those defined by <a
href="http://www.sgi.com/tech/stl/UniqueAssociativeContainer.html">Unique
Associative Container</a>. </p>

<h3>Example</h3>

<p><pre><code><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">// Parameter object to hold parameters for dynamic SQL query below </span>
class ParamObjExample
{
    public:
	int lowIntValue;
	int highIntValue;
	string strValue;
	TIMESTAMP_STRUCT dateValue;
};

<span class="codeComment">// Create an association between table columns and fields in our object</span>
class BCAExampleObj
{
public:
	void operator()(BoundIOs &amp;boundIOs, Example &amp;rowbuf)
    {
	   boundIOs[&quot;INT_VALUE&quot;]	== rowbuf.exampleInt;
	   boundIOs[&quot;STRING_VALUE&quot;]	== rowbuf.exampleStr;
	   boundIOs[&quot;DOUBLE_VALUE&quot;]	== rowbuf.exampleDouble;
	   boundIOs[&quot;EXAMPLE_LONG&quot;]	== rowbuf.exampleLong;
	   boundIOs[&quot;EXAMPLE_DATE&quot;]	== rowbuf.exampleDate;
	}
};

<span class="codeComment">// Create an association between query parameters and fields in our parameters 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;
	}

};

<span class="codeComment">// Set parameters function for Example ... used by IndexedDBView&lt;Example&gt; to set dynamic query parameters
// Dynamic query parameters are indicated by (?) in our query string for the IndexedDBView</span>
void SetParamsExample(ParamObjExample &amp;params)
{
	<span class="codeComment">// set parameter values</span>
	params.lowIntValue = 2;
	params.highIntValue = 8;
	params.strValue = &quot;Example&quot;;
	
	TIMESTAMP_STRUCT paramDate = {2000, 1, 1, 0, 0, 0, 0};
	params.dateValue = paramDate;
}


<span class="codeComment">// Example of using an IndexDBView to read, insert and update records in a container / database</span>
void IndexedViewExample()
{
	typedef DBView&lt;Example, ParamObjExample&gt; DBV;

	DBV view(&quot;DB_EXAMPLE&quot;,   BCAExampleObj(), 
	  &quot;WHERE INT_VALUE BETWEEN (?) AND (?) OR &quot;
	  &quot;STRING_VALUE = (?) OR EXAMPLE_DATE &lt;= (?) ORDER BY EXAMPLE_LONG&quot;,
	  BPAExampleObj());

	IndexedDBView&lt;DBV&gt; indexed_view(view, &quot;UNIQUE PrimaryIndex; STRING_VALUE; AlternateIndex; EXAMPLE_LONG, EXAMPLE_DATE&quot;, 
	  BOUND, USE_ALL_FIELDS, cb_ptr_fun(SetParamsExample));
   		

	<span class="codeComment">// Find the item where the STRING_VALUE matches the string &quot;Foozle&quot;</span>
	IndexedDBView&lt;DBV&gt;::indexed_iterator idxview_it = indexed_view.find(string(&quot;Foozle&quot;));
		

	<span class="codeComment">// Update the item with the key of &quot;Foozle&quot;, to read &quot;Fizzle&quot; instead</span>
	if (idxview_it != indexed_view.end()) {
		Example replacement;
		replacement = *idxview_it;
		replacement.exampleStr = &quot;Fizzle&quot;;
		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;
	IndexedDBView&lt;DBV&gt;::indexed_pair pr = indexed_view.equal_range_AK (&quot;AlternateIndex&quot;, long_criteria, date_criteria);

	idxview_it = pr.first;

	cout &lt;&lt; &quot;*** Size before erase calls: &quot; &lt;&lt; indexed_view.size() &lt;&lt; &quot; ***&quot;
	&lt;&lt; endl;
		
	<span class="codeComment">// Remove all items that match 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>
		IndexedDBView&lt;DBV&gt;::indexed_iterator deleteMe = idxview_it;

		idxview_it++;

		indexed_view.erase(deleteMe);

	}

	cout &lt;&lt; &quot;*** Size after erase calls: &quot; &lt;&lt; indexed_view.size() &lt;&lt; &quot; ***&quot;
			&lt;&lt; endl;


	<span class="codeComment">// Finally, insert a new item into the container</span>
	pair&lt;IndexedDBView&lt;DBV&gt;::iterator, bool&gt; ins_pr;

	ins_pr = indexed_view.insert(Example(459, &quot;Unique String #1&quot;, 3.4, 1, date_criteria));

	cout &lt;&lt; &quot;insertion succeded = &quot; &lt;&lt; (ins_pr.second == true ? &quot;true&quot;: &quot;false&quot;) &lt;&lt; endl;

}
</code></pre> </p>

<h3>Public Base Classes</h3>

<p>None.</p>

<h3>Template parameters</h3>

<table border="1">
    <tr>
        <th>Parameter </th>
        <th>Description </th>
        <th>Default </th>
    </tr>
    <tr>
        <td valign="top"><tt>View</tt> </td>
        <td valign="top">The type of the SQL view (usually a <a
        href="DBView.htm"><font size="2" face="Courier New">DBView</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"> IndexedDBView</font>).</td>
        <td valign="top">&nbsp; </td>
    </tr>
</table>

<p>&nbsp;</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">IndexedDBView </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>k</tt> </td>
        <td valign="top">Object of type <tt>X::key_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>
    <tr>
        <td valign="top"><tt>f1, f2, ..., fn</tt></td>
        <td valign="top">A primitive C type such as <font
        size="2" face="Courier New">int, double, float,</font>...
        or STL <font size="2" face="Courier New">string</font></td>
    </tr>
    <tr>
        <td valign="top"><tt>s</tt></td>
        <td valign="top">A STL <font size="2" face="Courier New">string</font></td>
    </tr>
</table>

<h3>Valid expressions</h3>

<p>In addition to the expressions defined in <a
href="http://www.sgi.com/tech/stl/UniqueAssociativeContainer.html">Unique
Associative Container</a>, the following expressions must be
valid. </p>

<table border="1">
    <tr>
        <th>Name </th>
        <th>Expression </th>
        <th>Type requirements </th>
        <th>Return type </th>
    </tr>
    <tr>
        <td valign="top">Default constructor </td>
        <td valign="top"><pre>X a( 
 DBView&lt;...&gt; &amp;view, 
 const string &amp;IndexNamesAndFields,
 BoundMode bm = UNBOUND, 
 KeyMode km = USE_ALL_FIELDS, 
 SetParamsFn IndexedDBViewParam = DefaultSetParams&lt;ParamObj&gt;())
</pre>
        </td>
        <td valign="top">&nbsp; </td>
        <td valign="top">&nbsp; </td>
    </tr>
    <tr>
        <td valign="top">Find alternate key</td>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -