dbviewdeletedata.htm

来自「The goal of this library is to make ODBC」· HTM 代码 · 共 100 行

HTM
100 行
字号
<pre><code><span class="codeComment">// Delete objects from the database via a delete_iterator</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)
	{ }

};

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;
	}
};

class ExampleParamObj
{
    public:
       	int lowIntValue;
	string strValue;
};

class BPAParamObj
{
public:
	void operator()(BoundIOs &amp;boundIOs, ExampleParamObj &amp;paramObj)
	{
		boundIOs[0] == paramObj.strValue;
		boundIOs[1] == paramObj.lowIntValue;
	}

};


<span class="codeComment">// Delete rows matching the specified Example objects from the database</span>
void DeleteData()
{
	<span class="codeComment">// construct view</span>
	DBView&lt;Example, ExampleParamObj&gt;
	view(&quot;DB_EXAMPLE&quot;, BCAExampleObj(), &quot;OR STRING_VALUE = (?) OR INT_VALUE = (?)&quot;, BPAParamObj());

	<span class="codeComment">// build a deleter for the view

	// *** SQL Query Generated for this delete_iterator:&quot; ***
	// *** (Note: All column and field names that were generated by the BCA are alphabetized due to our implementation) ***
 	// &quot;DELETE FROM DB_EXAMPLE WHERE EXAMPLE_DATE = (?) AND STRING_VALUE = (?) &quot;
	// &quot;OR STRING_VALUE = (?) OR INT_VALUE = (?)&quot;</span>

	DBView&lt;Example, ExampleParamObj, BCAExampleObj, BPAParamObj&gt;::delete_iterator
	exampleDeleter = view;

	<span class="codeComment">// now set the parameters indicating which rows we want to delete</span>
	exampleDeleter-&gt;exampleStr = &quot;Example&quot;;

	TIMESTAMP_STRUCT y2k = {2000, 1, 1, 0, 0, 0, 0};
	exampleDeleter-&gt;exampleDate = y2k;

	exampleDeleter.Params().strValue = &quot;Find Me&quot;;
	exampleDeleter.Params().lowIntValue = 18;

	<span class="codeComment">// execute the delete</span>
	exampleDeleter++;

	cout &lt;&lt; exampleDeleter.GetLastCount()
	&lt;&lt; &quot; rows deleted!&quot; &lt;&lt; endl;

	<span class="codeComment">// now can perform other deletes using the same deleter object
	// make sure to put in your new values for the parameters
	// for the delete

	// now set the parameters indicating which rows we want to delete</span>

	TIMESTAMP_STRUCT today = {1999, 9, 29, 0, 0, 0, 0};
	*exampleDeleter = Example(3, &quot;operator-&gt;()works&quot;, 0.0, 0, today);

	<span class="codeComment">// execute the delete</span>
	exampleDeleter++;

	cout &lt;&lt; exampleDeleter.GetLastCount()
	     &lt;&lt; &quot; rows deleted!&quot; &lt;&lt; endl;
}
</code></pre>

⌨️ 快捷键说明

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