📄 logginghandleruse.htm
字号:
<pre><code><span class="codeComment">// Example Code Using LoggingHandler on a DBView
// test of failed SelValidate() when reading data</span>
void TestBadSelValidate()
{
vector<Example> results;
<span class="codeComment">// construct view
// DBView<Example> is actually DBView<Example,
// DefaultParamObj<Example> > thanks to the default
// argument to the DBView template
// use our bad BCA which references a nonexistent column name in DB_EXAMPLE</span>
DBView<Example>
view("DB_EXAMPLE", BCAExampleObj(),
"WHERE INT_VALUE BETWEEN (?) AND (?) AND "
"STRING_VALUE = (?) OR EXAMPLE_DATE < (?) ORDER BY EXAMPLE_LONG",
BPAExampleObj(), BadSelValidate());
<span class="codeComment">// loop through query results and add them to our vector
// in this loop, read_it.GetLastCount() records read from DB</span>
DBView<Example>::select_iterator read_it = view.begin();
<span class="codeComment">// set parameter values for the WHERE clause in our SQL query</span>
read_it.Params().lowIntValue = 2;
read_it.Params().highIntValue = 8;
read_it.Params().strValue = "Example";
TIMESTAMP_STRUCT paramDate = {2000, 1, 1, 0, 0, 0, 0};
read_it.Params().dateValue = paramDate;
for ( ; read_it != view.end(); read_it++)
{
try
{
<span class="codeComment">// note that the read_iterator::GetLastCount() is incremented in operator++()
// remember that the record is fetched and thus the count incremented
// before operator*() is applied to the read_iterator</span>
cout << "Reading element #" << read_it.GetLastCount() << endl;
cout << "read_it->exampleInt = " << read_it->exampleInt << endl;
cout << "read_it->exampleStr = " << read_it->exampleStr << endl;
results.push_back(*read_it);
}
catch (RootException &ex)
{
cout << "Caught Exception!!!!" << endl;
cout << ex.what() << endl;
}
}
LoggingHandler<Example> handler =
read_it.get_io_handler((LoggingHandler<Example> *) NULL);
typedef LoggingHandler<Example>::LoggedTriple LoggedTriple;
vector<LoggedTriple> errors = handler.GetLog();
for (vector<LoggedTriple>::iterator log_it = errors.begin(); log_it != errors.end();
log_it++)
{
LoggedTriple error = *log_it;
cout << "Error msg = " << error.errmsg << endl;
cout << "Example = " << error.dataObj << endl;
}
}
</code></pre>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -