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

📄 dbviewwritedata.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 DBView to insert rows into a database</span>


<span class="codeComment">// ... Class definitions for Example and BCAExample as per our </span><a
href="DBViewReadData.htm">ReadData</a> <span class="codeComment">example .....

// Specialization of DefaultInsValidate for Example
// This defines a business rule we wish to enforce for all 
// Example objects before they are allowed to be inserted into the database</span>
template&lt;&gt; class dtl::DefaultInsValidate&lt;Example&gt; 
{
public:

	bool operator()(Example &amp;rowbuf) {	
		<span class="codeComment">// data is valid if rowbuf.exampleStr is nonempty and
		// rowbuf.exampleDouble is 
		// between 0 and 100 (like a percentage)</span>
		return (rowbuf.exampleStr.length() &gt; 0 &amp;&amp;  rowbuf.exampleDouble &gt;= 0.0 
			&amp;&amp; rowbuf.exampleLong  &lt;= 100.0);
	}
};


<span class="codeComment">// Insert rows from the vector&lt;Example&gt; parameter into the database</span>
void WriteData(const vector&lt;Example&gt; &amp;examples)
{
	DBView&lt;Example&gt; view(&quot;DB_EXAMPLE&quot;);

	<span class="codeComment">// loop through vector and write Example objects to DB</span>
	// write_it.GetCount() records written in loop

	DBView&lt;Example&gt;::insert_iterator write_it = view;

	for (vector&lt;Example&gt;::const_iterator ex_it = examples.begin(); ex_it != examples.end(); ex_it++, write_it++)
	{
		*write_it = *ex_it;
	 	cout &lt;&lt; &quot;Writing element #&quot; &lt;&lt; write_it.GetCount() + 1&lt;&lt; endl;
	}
}
</code></pre>

⌨️ 快捷键说明

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