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

📄 dynamicindexeddbviewexample.htm

📁 The goal of this library is to make ODBC recordsets look just like an STL container. As a user, you
💻 HTM
字号:
<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&lt;ParamObjExample&gt; dynamic_view(&quot;DB_EXAMPLE&quot;,
	 &quot;INT_VALUE, STRING_VALUE, DOUBLE_VALUE, EXAMPLE_LONG,  EXAMPLE_DATE&quot;,
	 &quot;WHERE INT_VALUE BETWEEN (?) AND (?) OR &quot;
	  &quot;STRING_VALUE = (?) OR EXAMPLE_DATE &lt;= (?) ORDER BY EXAMPLE_LONG&quot;,
	  BPAExampleObj());

 DynamicIndexedDBView&lt; DynamicDBView&lt;ParamObjExample&gt; &gt;  
	 indexed_view(dynamic_view, 
         &quot;UNIQUE PrimaryIndex; STRING_VALUE;&quot;
         &quot;IndexLongDate; 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>
 DynamicIndexedDBView&lt; DynamicDBView&lt;ParamObjExample&gt; &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()) {
  variant_row replacement;
  replacement = *idxview_it;
  replacement[&quot;STRING_VALUE&quot;] =   string(&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;
 DynamicIndexedDBView&lt; DynamicDBView&lt;ParamObjExample&gt; &gt;::indexed_pair 
   pr = indexed_view.equal_range_AK(&quot;IndexLongDate&quot;, long_criteria, date_criteria);

 idxview_it = pr.first;

 cout << "*** Size before erase calls: " &lt;&lt; indexed_view.size() &lt;&lt; " ***" &lt;&lt; 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&lt; DynamicDBView&lt;ParamObjExample&gt; &gt;::indexed_iterator deleteMe="idxview_it;" 
   idxview_it++; 
   indexed_view.erase(deleteMe); 
 } 
 cout &lt;&lt; "*** Size after erase calls: " &lt;&lt; indexed_view.size() &lt;&lt; " ***" &lt;&lt; endl; 
 
 <span class="codeComment">// Finally, insert a new item into the container </span>
 pair&lt;DynamicIndexedDBView&lt; DynamicDBView&lt;ParamObjExample&gt; &gt;::iterator, bool&gt; ins_pr; 
 
 variant_row r(indexed_view.DataObj()); 
 r["INT_VALUE"]=459; 
 r["STRING_VALUE"]=string(&quot;Unique String #1&quot;); 
 r["DOUBLE_VALUE"]=3.5; 
 r["EXAMPLE_LONG"]=1; 
 r["EXAMPLE_DATE"]=date_criteria; 
 ins_pr=indexed_view.insert(r);
 cout &lt;&lt; "insertion succeded=" &lt;&lt;  (ins_pr.second == true ? " true": " false") &lt;&lt; endl; 
}</code></pre>

⌨️ 快捷键说明

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