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 &exStr, double exDouble, long exLong,
const TIMESTAMP_STRUCT &exDate) :
exampleInt(exInt), exampleStr(exStr), exampleDouble(exDouble), exampleLong(exLong),
exampleDate(exDate)
{ }
};
class BCAExampleObj
{
public:
void operator()(BoundIOs &boundIOs, Example &rowbuf)
{
boundIOs["INT_VALUE"] == rowbuf.exampleInt;
boundIOs["STRING_VALUE"] == rowbuf.exampleStr;
boundIOs["DOUBLE_VALUE"] == rowbuf.exampleDouble;
boundIOs["EXAMPLE_LONG"] == rowbuf.exampleLong;
boundIOs["EXAMPLE_DATE"] == rowbuf.exampleDate;
}
};
class ExampleParamObj
{
public:
int lowIntValue;
string strValue;
};
class BPAParamObj
{
public:
void operator()(BoundIOs &boundIOs, ExampleParamObj &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<Example, ExampleParamObj>
view("DB_EXAMPLE", BCAExampleObj(), "OR STRING_VALUE = (?) OR INT_VALUE = (?)", BPAParamObj());
<span class="codeComment">// build a deleter for the view
// *** SQL Query Generated for this delete_iterator:" ***
// *** (Note: All column and field names that were generated by the BCA are alphabetized due to our implementation) ***
// "DELETE FROM DB_EXAMPLE WHERE EXAMPLE_DATE = (?) AND STRING_VALUE = (?) "
// "OR STRING_VALUE = (?) OR INT_VALUE = (?)"</span>
DBView<Example, ExampleParamObj, BCAExampleObj, BPAParamObj>::delete_iterator
exampleDeleter = view;
<span class="codeComment">// now set the parameters indicating which rows we want to delete</span>
exampleDeleter->exampleStr = "Example";
TIMESTAMP_STRUCT y2k = {2000, 1, 1, 0, 0, 0, 0};
exampleDeleter->exampleDate = y2k;
exampleDeleter.Params().strValue = "Find Me";
exampleDeleter.Params().lowIntValue = 18;
<span class="codeComment">// execute the delete</span>
exampleDeleter++;
cout << exampleDeleter.GetLastCount()
<< " rows deleted!" << 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, "operator->()works", 0.0, 0, today);
<span class="codeComment">// execute the delete</span>
exampleDeleter++;
cout << exampleDeleter.GetLastCount()
<< " rows deleted!" << endl;
}
</code></pre>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?