// Example Code Using LoggingHandler on an IndexedDBView

const TIMESTAMP_STRUCT then = {2000, 12, 15, 0, 0, 0, 0};

// Example of using an IndexDBView to try to insert Example objects and print out
// any errors that occurred
void IndexedViewExample()
{
	typedef DBView<Example, ParamObjExample> DBV;

	DBV view("DB_EXAMPLE", DefaultBCA<Example>(), 
	  "WHERE INT_VALUE BETWEEN (?) AND (?) OR "
	  "STRING_VALUE = (?) OR EXAMPLE_DATE <= (?) ORDER BY EXAMPLE_LONG",
	  BPAExampleObj());

	IndexedDBView<DBV> indexed_view(view, "PrimaryIndex; STRING_VALUE; UNIQUE AlternateIndex; EXAMPLE_LONG, 
		EXAMPLE_DATE", BOUND, USE_ALL_FIELDS, cb_ptr_fun(SetParamsExample));
   		

	try
	{

	// Insert new items into the container
	pair<IndexedDBView<DBV>::iterator, bool> ins_pr;

	ins_pr = indexed_view.insert(Example(459, "Unique String #1", 3.4, 1, date_criteria));

	cout << "insertion succeded = " << (ins_pr.second == true ? "true": "false") << endl;

	ins_pr = indexed_view.insert(Example(311, "", 3.99, 91, then)); // should fail on InsValidate()
   
	cout << "insertion succeded = " << (ins_pr.second == true ? "true": "false") << endl;
	
	ins_pr = indexed_view.insert(Example(222, "Positron", -34.77, 29, then)); // should fail (ditto)
	
	cout << "insertion succeded = " << (ins_pr.second == true ? "true": "false") << endl;
	}
	
	catch (...)
	{
	typedef LoggingHandler<Example, ParamObjExample>::LoggedTriple LoggedTriple;
 
	// retrieve the LoggingHandler object from the IndexedDBView
	LoggingHandler<Example, ParamObjExample> log_handler = 
		indexed_view.get_io_handler((LoggingHandler<Example, ParamObjExample> *) NULL);

	// the log is a vector of (error message, DataObj, ParamObj) triples,
	// (error message, Example object, ParamObjExample object) in this case
	// the error itself along with the relevant DataObj and ParamObj that resulted with
	// the error
	vector<LoggedTriple> error_log = log_handler.GetLog();

	// nothing to do if no errors occurred
	if (error_log.empty())
		return;

	cout << "*** Error Log in IndexedViewExample(): " << error_log.size() << " errors recorded! ***"
	     << endl;

	// print out the errors
	for (vector<LoggedTriple>::const_iterator log_it = error_log.begin(); 
		log_it != error_log.end(); log_it++)
	{
	   cout << "*** Error Log Entry ***" << endl;
	   cout << "* error message *" << endl;
	   cout << (*log_it).errmsg << endl;
	   cout << "* relevant Example object *" << endl;
	   cout << (*log_it).dataObj << endl;
	}

	}	
}