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

📄 testexceptions.cpp

📁 The goal of this library is to make ODBC recordsets look just like an STL container. As a user, you
💻 CPP
📖 第 1 页 / 共 2 页
字号:

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

	PrintSeparator(cout);
}

void TestBadBCAUpdate()
{
	// construct view
	DBView<Example> view("DB_EXAMPLE", 
		BadBCAExampleObj(), "WHERE INT_VALUE BETWEEN (?) AND (?) AND "
		"STRING_VALUE = (?) OR EXAMPLE_DATE = (?)", BPAExampleObj());
		
	// build an updater for the view
	DBView<Example>::update_iterator 
		exampleUpdater;
	
	exampleUpdater = view;

	// set data fields we want to update to their desired values
	// exampleStr to "Updated" and sampleLong to 0
	Example updateMe;

	try
	{
		updateMe.exampleStr = "Updated";
	    updateMe.exampleLong = 25;

	    TIMESTAMP_STRUCT today = {2000, 9, 29, 0, 0, 0, 0};

	    updateMe = Example(2121, "Dereferenced", 99.99, 25, today);

		*exampleUpdater = updateMe;
    
		// now set the parameters indicating which rows we want the update applied
		exampleUpdater.Params().lowIntValue = 5;
		exampleUpdater.Params().highIntValue = 13;
		exampleUpdater.Params().strValue = "Find Me";

		TIMESTAMP_STRUCT paramDate = {1999, 11, 11, 0, 0, 0, 0};
		exampleUpdater.Params().dateValue = paramDate;

		// execute the update
		exampleUpdater++;

		cout << exampleUpdater.GetLastCount() << " rows updated!" << endl;
	}
	catch (RootException &ex)
	{
		cout << "Exception caught!" << endl;
		cout << ex.what() << endl;
	}

	try
	{
		// now can perform other updates using the same updater object
		// make sure to put in your new values for both the data and parameter values
		// for the update
		// set data fields we want to update to their desired values
		// exampleStr to "Second Update" and exampleLong to 66
		TIMESTAMP_STRUCT tomorrow = {2000, 9, 30, 0, 0, 0, 0};
		updateMe = Example(2222, "Second Update", 0.11111, 66, tomorrow);
		updateMe.exampleLong = 66;

		*exampleUpdater = updateMe;

		// now set the parameters indicating which rows we want the update applied
		exampleUpdater.Params().lowIntValue = 21;
		exampleUpdater.Params().highIntValue = 30;
		exampleUpdater.Params().strValue = "To find";

		TIMESTAMP_STRUCT otherParamDate = {2001, 10, 31, 0, 0, 0, 0};
		exampleUpdater.Params().dateValue = otherParamDate;

		// execute the update
		exampleUpdater++;

		cout << exampleUpdater.GetLastCount() << " rows updated!" << endl;
	}
	catch (RootException &ex)
	{
		cout << "Exception caught!" << endl;
		cout << ex.what() << endl;
	}

	LoggingHandler<Example> handler = 
		exampleUpdater.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;
	}

	PrintSeparator(cout);
}

void TestBadUpdateValidate()
{
	PrintHeader(cout, "TestBadUpdateValidate()");

	// construct view
	DBView<Example> view("DB_EXAMPLE", 
		BCAExampleObj(), "WHERE INT_VALUE BETWEEN (?) AND (?) AND "
		"STRING_VALUE = (?) OR EXAMPLE_DATE = (?)", BPAExampleObj(), 
		DefaultSelValidate<Example>(), BadInsValidate());
		
	// build an updater for the view
	DBView<Example>::update_iterator 
		exampleUpdater;
	
	exampleUpdater = view;

	// set data fields we want to update to their desired values

	Example updateMe;

	TIMESTAMP_STRUCT today = {2000, 9, 29, 0, 0, 0, 0};

	// should be rejected ... operator++() will do nothing
	updateMe = Example(7, "Rejected", 99.99, 25, today);

	try
	{
	  *exampleUpdater = updateMe;
    }
	catch (RootException &ex)
	{
	  cout << "Exception caught!" << endl;
	  cout << ex.what() << endl;
	}

	// now set the parameters indicating which rows we want the update applied
	exampleUpdater.Params().lowIntValue = 5;
	exampleUpdater.Params().highIntValue = 33;
	exampleUpdater.Params().strValue = "Example";

	TIMESTAMP_STRUCT paramDate = {1999, 11, 11, 0, 0, 0, 0};
	exampleUpdater.Params().dateValue = paramDate;

	// execute the update
	exampleUpdater++;

	cout << exampleUpdater.GetLastCount() << " rows updated!" << endl;

	// now can perform other updates using the same updater object
	// make sure to put in your new values for both the data and parameter values
	// for the update
	// set data fields we want to update to their desired values
	// exampleStr to "Second Update" and exampleLong to 66
	TIMESTAMP_STRUCT tomorrow = {2000, 9, 30, 0, 0, 0, 0};
	updateMe = Example(2222, "Accepted", 0.11111, 66, tomorrow);

	try
	{
		*exampleUpdater = updateMe;
    }
	catch (RootException &ex)
	{
	  cout << "Exception caught!" << endl;
	  cout << ex.what() << endl;
	}

	// now set the parameters indicating which rows we want the update applied
	exampleUpdater.Params().lowIntValue = 31;
	exampleUpdater.Params().highIntValue = 34;
	exampleUpdater.Params().strValue = "Example";

	TIMESTAMP_STRUCT otherParamDate = {1995, 7, 31, 0, 0, 0, 0};
    exampleUpdater.Params().dateValue = otherParamDate;

	// execute the update
	exampleUpdater++;

	cout << exampleUpdater.GetLastCount() << " rows updated!" << endl;

	LoggingHandler<Example> handler = 
		exampleUpdater.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;
	}

	PrintSeparator(cout);
}

void TestBadBCADelete()
{

	PrintHeader(cout, "TestBadBCADelete()");

	// construct view
	DBView<Example>
		view("DB_EXAMPLE", 
		BadDelBCAExampleObj(), "OR STRING_VALUE = (?) OR INT_VALUE = (?)", 
		DelBPAExampleObj());

	view.set_io_handler(AlwaysThrowsHandler<Example>());

	// build a deleter for the view
	DBView<Example>::delete_iterator exampleDeleter;
	
	try
	{
		exampleDeleter = view;

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

	    TIMESTAMP_STRUCT y2k = {2000, 1, 1, 0, 0, 0, 0};
	
	    *exampleDeleter = Example(0, "Example", 0.0, 0, y2k);

	    exampleDeleter.Params().strValue = "Find Me";
	    exampleDeleter.Params().lowIntValue = 18;
	    // execute the delete
	    exampleDeleter++;

	    cout << exampleDeleter.GetLastCount() << " rows deleted!" << endl;
	}
	catch (RootException &ex)
	{
		cout << "Exception caught!" << endl;
		cout << ex.what() << endl;
	}

	try
	{
	// 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

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

	// execute the delete
	exampleDeleter++;

	cout << exampleDeleter.GetLastCount() << " rows deleted!" << endl;
	}

	catch (RootException &ex)
	{
		cout << "Exception caught!" << endl;
		cout << ex.what() << endl;
	}

	PrintSeparator(cout);
}

void TestBadBPADelete()
{

	PrintHeader(cout, "TestBadBPADelete()");

	// construct view
	DBView<Example>
		view("DB_EXAMPLE", 
		DelBCAExampleObj(), "OR STRING_VALUE = (?) OR INT_VALUE = (?)", 
		BadDelBPAExampleObj());

	// view.set_io_handler(AlwaysThrowsHandler<Example>());

	// build a deleter for the view
	DBView<Example>::delete_iterator exampleDeleter;

	try
	{
		exampleDeleter = view;

	    // now set the parameters indicating which rows we want to delete
	    TIMESTAMP_STRUCT y2k = {2000, 1, 1, 0, 0, 0, 0};
	
	    *exampleDeleter = Example(0, "Example", 0.0, 0, y2k);

	    exampleDeleter.Params().strValue = "Find Me";
	    exampleDeleter.Params().lowIntValue = 18;
	    // execute the delete
	    exampleDeleter++;

	    cout << exampleDeleter.GetLastCount() << " rows deleted!" << endl;
	}
	catch (RootException &ex)
	{
		cout << "Exception caught!" << endl;
		cout << ex.what() << endl;
	}

	try
	{
	// 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

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

	// execute the delete
	exampleDeleter++;

	cout << exampleDeleter.GetLastCount() << " rows deleted!" << endl;
	}

	catch (RootException &ex)
	{
		cout << "Exception caught!" << endl;
		cout << ex.what() << endl;
	}

	LoggingHandler<Example> handler = 
		exampleDeleter.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;
	}

	PrintSeparator(cout);
}

⌨️ 快捷键说明

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