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

📄 variant_row.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>variant_row</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>variant_row</h1>



















<table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td><img src="utilities.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>: utilities</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">variant_row </font>class
provides a mechanism to hold an arbitrary number of fields with
values of arbitrary types. This class is used primarily by
dynamic queries where the number and the types of the fields
returned by a query are unknown.</p>

<h3>Definition</h3>

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

<h3>Refinement of</h3>

<p>None.</p>

<h3>Associated types</h3>

<p><a href="variant_field.htm"><font size="2" face="Courier New">variant_field</font></a><font
size="2" face="Courier New">, TypeTranslation</font>.</p>

<h3>Example:</h3>
<pre><code><span class="codeComment">// Manipulating fields in a variant_row</span>

void variant_row_example(void) {

	TIMESTAMP_STRUCT test_date = {1999, 9, 29, 0, 0, 0, 0};

	vector&lt;TypeTranslation&gt; types;
	vector&lt;string&gt; names;
	int i;
	string s;
	TypeTranslation vt0=TypeTranslation(typeid(int).name(), C_INT, SQL_INTEGER, SQL_C_SLONG,
				TypeTranslation::TYPE_PRIMITIVE, sizeof(int)), 
			vt1=TypeTranslation(typeid(string).name(), C_STRING, SQL_VARCHAR, SQL_C_CHAR,
				TypeTranslation::TYPE_COMPLEX, sizeof(string));

	types.push_back(vt0);
	names.push_back(&quot;int&quot;);

	types.push_back(vt1);
	names.push_back(&quot;string&quot;);

	variant_row r(types, names);
	
	
	r[&quot;int&quot;] = (int)r[&quot;int&quot;] + 5;
	i = (int)r[&quot;int&quot;];
	
	s = (string) r[&quot;int&quot;];

	r[&quot;int&quot;] = test_date;
	s = (string) r[&quot;int&quot;];

	<span class="codeComment">// Print out the column names</span>
	vector&lt;string&gt; colNames = r.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 column values</span>
	for (i = 0; i &lt; r.size(); i++)
		cout &lt;&lt; r[i] &lt;&lt; &quot; &quot;;
	cout &lt;&lt; endl;


};
</code></pre>
<h3>Public base classes</h3>

<p>None.</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">variant_row</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">Creates an empty <font size="2"
        face="Courier New">variant_row</font><font size="3">. The
        type and number of fields is not set so an empty </font><font
        size="2" face="Courier New">variant_row</font><font
        size="3"> ca</font>nnot be used until is has been copy or
        assignment constructed from another row.</td>
        <td valign="top">The row is empty.</td>
    </tr>
    <tr>
        <td valign="top">Alterante constructor </td>
        <td valign="top"><pre>X a(vector&lt;TypeTranslation&gt; 
  &amp;types, vector&lt;string&gt; &amp;names)</pre>
        </td>
        <td valign="top">&nbsp; </td>
        <td valign="top">Creates a <font size="2"
        face="Courier New">variant_row</font> to hold an array of
        types as specified in <font size="2" face="Courier New">types</font>
        with field names given by <font size="2"
        face="Courier New">names</font>. In practice, you should
        never need to use this. Instead we recommend that you get
        any raw rowbuf object that you need by calling the <font
        size="2" face="Courier New">DataObj()</font> method of <a
        href="DynamicDBView.htm"><font size="2"
        face="Courier New">DynamicDBView</font></a> or <a
        href="DynamicIndexedDBView.htm"><font
        size="2" face="Courier New">DynamicIndexedDBView</font></a>
        to get a variant_row constructed for you that matches the
        columns in your query. See <a href="#1">[1]</a> for
        details about <font size="2" face="Courier New">TypeTranslation</font>.</td>
        <td valign="top">The row is initialized to be able to
        hold the given types and access these fields using the
        specified names.</td>
    </tr>
    <tr>
        <td valign="top">Copy constructor </td>
        <td valign="top"><pre>X a(const X &amp;b)</pre>
        </td>
        <td valign="top">&nbsp; </td>
        <td valign="top">Creates a <font size="2"
        face="Courier New">variant_row</font> to hold an array of
        types as specified in<font size="2" face="Courier New"> b</font>.
        The types, field names and values stored in <font
        size="2" face="Courier New">b</font> are copied into <font
        size="2" face="Courier New">a</font>.</td>
        <td valign="top">The row is initialized to be able to
        hold the types and fields given in <font size="2"
        face="Courier New">b</font>. The data held in b is copied
        to<font size="2" face="Courier New"> a</font>.</td>
    </tr>
    <tr>
        <td valign="top">Get field types</td>
        <td valign="top"><pre>vector&lt;TypeTranslation&gt; GetTypes</pre>
        </td>
        <td valign="top">&nbsp; </td>
        <td valign="top">Returns a vector listing the type of
        each field in <font size="2" face="Courier New">variant_row</font>
        in the order that these fields occur. See <a href="#1">[1]</a>
        for details about <font size="2" face="Courier New">TypeTranslation.</font></td>
        <td valign="top">&nbsp;</td>
    </tr>
    <tr>
        <td valign="top">Get field names</td>
        <td valign="top"><pre>vector&lt;string&gt; GetFields()</pre>
        </td>
        <td valign="top">&nbsp; </td>
        <td valign="top">Returns a vector listing the name of
        each field in <font size="2" face="Courier New">variant_row
        </font>in the order that these fields occur.</td>
        <td valign="top">&nbsp;</td>
    </tr>
    <tr>
        <td valign="top">Get number of fields</td>
        <td valign="top"><pre>size_t size()</pre>
        </td>
        <td valign="top">&nbsp; </td>
        <td valign="top">Returns the number of fields in the <font
        size="2" face="Courier New">variant_row</font>.</td>
        <td valign="top">&nbsp;</td>
    </tr>
    <tr>
        <td valign="top">Get field by number </td>
        <td valign="top"><pre>variant_field operator[](int i)</pre>
        </td>
        <td valign="top">&nbsp; </td>
        <td valign="top">Retrieves field number<font size="2"
        face="Courier New"> i</font> from the variant_row object.
        Fields are numbered starting at 0. The field is returned
        as a <a href="variant_field.htm"><font size="2"
        face="Courier New">variant_field</font></a> object.</td>
        <td valign="top">&nbsp;</td>
    </tr>
    <tr>
        <td valign="top">Get field by name</td>
        <td valign="top"><pre>variant_field operator[](const string &amp;f)</pre>
        </td>
        <td valign="top">&nbsp; </td>
        <td valign="top">Retrieves the field with the name given
        by the string f from the <font size="2"
        face="Courier New">variant_row </font>object. Fields are
        numbered starting at 0. The field is returned as a <a
        href="variant_field.htm"><font size="2"
        face="Courier New">variant_field</font></a> object.</td>
        <td valign="top">&nbsp;</td>
    </tr>
</table>

<h3>Notes</h3>

<p><a name="1">[1]</a> <font size="2" face="Courier New">TypeTranslation</font>
is an internal structure that is used by the library to translate
between C types and SQL types. Details of the mapping that we use
may be found in <font size="2" face="Courier New">bind_basics.h</font>
and <font size="2" face="Courier New">bind_basics.cpp</font>.
Typically, one would not read types directly off of this vector
but would instead use type information functions exposed by the <font
size="2" face="Courier New">variant_field</font> object.</p>

<h3>See also</h3>

<p><a href="variant_field.htm"><font size="2" face="Courier New">variant_field</font></a><font
size="2" face="Courier New">, </font><a
href="DynamicDBView.htm"><font size="2"
face="Courier New">DynamicDBView</font></a><font size="2"
face="Courier New">, </font><a
href="DynamicIndexedDBView.htm"><font size="2"
face="Courier New">DynamicIndexedDBView</font></a><font size="2"
face="Courier New"> </font><font size="2"><!--start footer--></font></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 + -