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

📄 dynamicdbview.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>DynamicDBView &lt;ParamObj&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>DynamicDBView &lt;ParamObj&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">DynamicDBView </font>container
is a refinement of <a href="DBView.htm"><font size="2"
face="Courier New">DBView</font></a><font size="2"
face="Courier New"> </font>used for queries where the number and
types of the fields in the query is unknown until runtime. <font
size="2" face="Courier New">DynamicDBView</font> specialises the <a
href="DBView.htm"><font size="2" face="Courier New">DBView</font></a><font
size="2" face="Courier New"> </font>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="DBView.htm"><font size="2" face="Courier New">DBView</font></a>.
</p>

<h3>Associated types</h3>

<p>None, except for those defined by <a href="DBView.htm"><font
size="2" face="Courier New">DBView</font></a><font size="2"
face="Courier New">.</font></p>

<h3>Example 1:</h3>
<pre><code><span class="codeComment">// Using a DynamicDBView to read rows from the database.

// Read the contents of a table and print the resulting rows</span>
void SimpleDynamicRead() {

	<span class="codeComment">// Our query will be &quot;SELECT * FROM DB_EXAMPLE&quot;</span>
	DynamicDBView&lt;&gt; view(&quot;DB_EXAMPLE&quot;, &quot;*&quot;);

	<span class="codeComment">// NOTE: We need to construct r from the view itself since we
	// don't know what fields the table will contain.
	// We therefore make a call to the DataObj() function to have the
	// table return us a template row with the correct number of fields
	// and field types.
	// We use this construction since we can't be guaranteed that the table
	// is non-empty &amp; we want to still display column names in this case.</span>
	variant_row s(view.DataObj());

	<span class="codeComment">// Print out the column names</span>
	vector&lt;string&gt; colNames = s.GetNames();
	for (vector&lt;string&gt;::iterator name_it = colNames.begin(); name_it != colNames.end(); name_it++)
	{
		cout &lt;&lt; (*name_it) &lt;&lt; &quot; &quot;;
	}
	cout &lt;&lt; endl;

	<span class="codeComment">// Print out all rows and columns from our query</span>
	DynamicDBView&lt;&gt;::select_iterator print_it = view.begin();
	for (print_it = view.begin(); print_it != view.end(); print_it++)
	{
		variant_row r = *print_it;
		for (size_t i = 0; i &lt; r.size(); i++)
		{
			cout &lt;&lt; r[i] &lt;&lt; &quot; &quot;;
		}
		cout &lt;&lt; endl;
	}
}</code></pre>
<h3>Example 2:</h3>
<pre><code><span class="codeComment">// Using a DynamicDBView to insert records into the database.

// Insert two rows into a table with unknown fields</span>
void SimpleDynamicWrite() {
	TIMESTAMP_STRUCT paramDate = {2012, 12, 23, 0, 0, 0, 0}; 
	<span class="codeComment">// Mayan DOOMSDAY! End of the Mayan 5126 year long calendar cycle starting from May 1, 3094 B.C.
	// Date is 13.13.13.0.0.0.0  4 Ahaw, 3 K'ank'in</span>
	
	DynamicDBView&lt;&gt; view(&quot;DB_EXAMPLE&quot;, &quot;*&quot;);

	DynamicDBView&lt;&gt;::insert_iterator write_it = view;

	<span class="codeComment">// NOTE: We need to construct r from the view itself since we
	// don't know what fields the table will contain.
	// We therefore make a call to the DataObj() function to have the
	// table return us a template row with the correct number of fields
	// and field types.</span>
	variant_row r(view.DataObj());

	<span class="codeComment">// Prepare the number of the beast!
	// Set all fields to the value 6,
	// except for the last column which is a date and cannot
	// currently accept numeric values</span>
	for (size_t i = 0; i &lt; r.size()-1; i++)
	{
		 r[i] = 6;
	}
	r[i] = paramDate;  <span class="codeComment">// set the Doomsdate</span>

	<span class="codeComment">// insert the number</span>
	*write_it = r;
	write_it++;

	<span class="codeComment">// Prepare the number of angels who stand before
	// the throne of God!
	// Set all fields to the value 7,
	// except for the last column which is a date and cannot
	// currently accept numeric values</span>
	for (i = 0; i &lt; r.size()-1; i++)
	{
		 r[i] = 7;
	}
	r[i] = paramDate;

	<span class="codeComment">// insert the number</span>
	*write_it = r;
	write_it++;
}
</code></pre>
<h3>Public base classes</h3>

<p><font size="2" face="Courier New">DBView&lt;variant_row,
ParamObj&gt;</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>ParamObj</tt> </td>
        <td valign="top">The type of object that will be used to
        specify the postfix parameters to the <font size="2"
        face="Courier New">DynamicDBView</font>.</td>
        <td valign="top"><font size="2" face="Courier New">DefaultParamObj&lt;variant_row&gt;</font>&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">DynamicDBView </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(const string &amp;tableList, 
const string &amp;fieldList,
const string &amp;postfix = &quot;&quot;, 
const <a href="BPA.htm">BPA</a> &amp;bpa_functor = DefaultBPA&lt;ParamObj&gt;(),
const <a href="SelVal.htm">SelVal</a> sel_val = DefaultSelVal&lt;DataObj&gt;(),
const <a href="InsVal.htm">InsVal</a> ins_val = DefaultInsVal&lt;DataObj&gt;(),
<a href="DBConnection.htm">DBConnection</a> &amp;connection = DBConnection::GetDefaultConnection()</pre>
        </td>
        <td valign="top">&nbsp; </td>
        <td valign="top">Creates an empty container bound to a
        table, using the database connection specified in the
        connection object. The actual queries run againt this
        table are built by the select, insert, update and delete
        iterators (see these iterators for details) but
        essentially follow the following format:<p><font size="2"
        face="Courier New">&quot;SELECT &quot; + fieldList +
        &quot; FROM &quot; + tableList + postfix</font></p>
        <p>In the SQL clause, users may also specify dynamic
        parameters through the use of SQL <font size="2"
        face="Courier New">'(?)'</font> syntax. In this case <font
        size="2" face="Courier New">BPA</font> is a class that is
        used to hold these runtime parameters and <font size="2"
        face="Courier New">bpa_functor</font> is a functor used to
        associate fields in the parameters class with parameter
        fields in the query.</p>
        </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="DBView.htm"><font size="2" face="Courier New">DBView</font></a><font
size="2" face="Courier New"> </font>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(const string &amp;tableList, 
const string &amp;fieldList,
const string &amp;postfix = &quot;&quot;, 
const </tt><a href="BPA.htm"><tt>BPA</tt></a><tt> &amp;bpa_functor = DefaultBPA&lt;ParamObj&gt;(),
const </tt><a href="SelVal.htm"><tt>SelVal</tt></a><tt> sel_val = DefaultSelVal&lt;DataObj&gt;(),
const </tt><a href="InsVal.htm"><tt>InsVal</tt></a><tt> ins_val = DefaultInsVal&lt;DataObj&gt;(),
</tt><a href="DBConnection.htm"><tt>DBConnection</tt></a><tt> &amp;connection = DBConnection::GetDefaultConnection()
</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">DynamicDBView</font>. </td>
    </tr>
    <tr>
        <td valign="top"><tt>variant_row DataObj()</tt> </td>
        <td valign="top">&nbsp;</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>DynamicDBView&lt;ParamObj&gt; &amp;
		operator=(const DynamicDBView&lt;ParamObj&gt; &amp; &other)</tt> </td>
        <td valign="top">&nbsp;</td>
        <td valign="top">Assignment operator.</td>
    </tr>
    <tr>
        <td valign="top"><tt>void swap(DynamicDBView&lt;ParamObj&gt; &amp;other)</tt> </td>
        <td valign="top">&nbsp;</td>
        <td valign="top">Swap <font size="2"
        face="Courier New">*this</font> with <font size="2" face="Courier New"> other.</font>
	</td>
    </tr>
</table>

<h3>See also</h3>

<p><a href="DBView.htm"><font size="2" face="Courier New">DBView</font></a><font
size="2" face="Courier New">,</font> <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>,</p>

<p><a href="BPA.htm"><font size="2" face="Courier New">BPA</font></a><font
size="2" face="Courier New">, </font><a href="SelVal.htm"><font
size="2" face="Courier New">SelVal</font></a><font size="2"
face="Courier New">, </font><a href="InsVal.htm"><font size="2"
face="Courier New">InsVal</font></a><font size="2"
face="Courier New">, </font><a href="DBConnection.htm"><font
size="2" face="Courier New">DBConnection <!--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 + -