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

📄 example.cpp

📁 The goal of this library is to make ODBC recordsets look just like an STL container. As a user, you
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	// here, we are not too concerned about the indices themselves	// we're just testing to see if the DataObj's are stored properly in the	// indexed view's internal list    IndexedDBView<DBView<Example> > 		indexed_view(view,		"IndexString; STRING_VALUE; IndexTwoFields; STRING_VALUE, EXAMPLE_DATE",		UNBOUND, USE_ALL_FIELDS, cb_ptr_fun(SetParamsExample));   		vector<Example> filtered_results;	// the return value consists of a pair: 1. an iterator referring to the found items	// and 2. an iterator pointing to the end of the list of found items 	IndexedDBView<DBView<Example> >::indexed_pair 		pr = indexed_view.equal_range_AK("IndexTwoFields", strVal, dateVal);	IndexedDBView<DBView<Example> >::indexed_iterator 		idx_data_it = pr.first;	IndexedDBView<DBView<Example> >::indexed_iterator		end_it = pr.second;	IndexedDBView<DBView<Example> >::indexed_iterator		find_it = indexed_view.find_AK("IndexTwoFields", strVal, dateVal);	if (idx_data_it == find_it)		cout << "Iterator integrity satisfied!" << endl;	// need to be able to iterate through found results	for ( ; idx_data_it != end_it; idx_data_it++)	{		// first * dereferences the iterator, returning a DataObj *		// second * dereferences the DataObj *, yielding a DataObj		Example &idx_data = *idx_data_it;		filtered_results.push_back(idx_data);	}	cout << filtered_results.size() << " results found!" << endl;	return filtered_results;}// read Example objects using the passed in// uses a two field keyvector<Example> ReadTwoFieldKeyByName(Example &key){   	DBView<Example> view("DB_EXAMPLE", 		BCAExampleObj(), "WHERE INT_VALUE BETWEEN (?) AND (?) AND "		"STRING_VALUE = (?) OR EXAMPLE_DATE <= (?) ORDER BY EXAMPLE_LONG",		BPAExampleObj());	// set up indexed view with two field index    IndexedDBView<DBView<Example> > 		indexed_view(view,		"IndexTwoFields; STRING_VALUE, EXAMPLE_DATE; IndexLong; EXAMPLE_LONG",		UNBOUND, USE_ALL_FIELDS, cb_ptr_fun(SetParamsExample));   		vector<Example> filtered_results;	// the return value consists of a pair: 1. an iterator referring to the found items	// and 2. an iterator pointing to the end of the list of found items 	IndexedDBView<DBView<Example> >::indexed_pair		pr = indexed_view.equal_range_AK("IndexTwoFields", key);	IndexedDBView<DBView<Example> >::indexed_iterator		idx_data_it = pr.first;	IndexedDBView<DBView<Example> >::indexed_iterator		end_it = pr.second;	IndexedDBView<DBView<Example> >::indexed_iterator		find_it = indexed_view.find_AK("IndexTwoFields", key);	if (idx_data_it == find_it)		cout << "Iterator integrity satisfied!" << endl;	// need to be able to iterate through found results	for ( ; idx_data_it != end_it; idx_data_it++)	{		// first * dereferences the iterator, returning a DataObj *		// second * dereferences the DataObj *, yielding a DataObj		Example &idx_data = *idx_data_it;		filtered_results.push_back(idx_data);	}	cout << filtered_results.size() << " results found!" << endl;	return filtered_results;}// read Example objects using the PK// uses a two field keyvector<Example> ReadTwoFieldKeyPK(Example &key){   	DBView<Example> view("DB_EXAMPLE", 		BCAExampleObj(), "WHERE INT_VALUE BETWEEN (?) AND (?) AND "		"STRING_VALUE = (?) OR EXAMPLE_DATE <= (?) ORDER BY EXAMPLE_LONG",		BPAExampleObj());	// set up indexed view with two field index    IndexedDBView<DBView<Example> >		indexed_view(view,		"IndexTwoFields; STRING_VALUE, EXAMPLE_DATE; IndexLong; EXAMPLE_LONG",		UNBOUND, USE_ALL_FIELDS, cb_ptr_fun(SetParamsExample));   		vector<Example> filtered_results;	// the return value consists of a pair: 1. an iterator referring to the found items	// and 2. an iterator pointing to the end of the list of found items 	IndexedDBView<DBView<Example> >::indexed_pair		pr = indexed_view.equal_range(key);	IndexedDBView<DBView<Example> >::indexed_iterator		idx_data_it = pr.first;	IndexedDBView<DBView<Example> >::indexed_iterator		end_it = pr.second;	IndexedDBView<DBView<Example> >::indexed_iterator		find_it = indexed_view.find(key);	if (idx_data_it == find_it)		cout << "Iterator integrity satisfied!" << endl;	// need to be able to iterate through found results	for ( ; idx_data_it != end_it; idx_data_it++)	{		// first * dereferences the iterator, returning a DataObj *		// second * dereferences the DataObj *, yielding a DataObj		Example &idx_data = *idx_data_it;		filtered_results.push_back(idx_data);	}	cout << filtered_results.size() << " results found!" << endl;	return filtered_results;}// same as above, but as PKvector<Example> ReadTwoFieldKeyDFAndPK(const string &strVal, const TIMESTAMP_STRUCT &dateVal){   	DBView<Example> view("DB_EXAMPLE", 		BCAExampleObj(), "WHERE INT_VALUE BETWEEN (?) AND (?) AND "		"STRING_VALUE = (?) OR EXAMPLE_DATE <= (?) ORDER BY EXAMPLE_LONG",		BPAExampleObj());	// here, we are not too concerned about the indices themselves	// we're just testing to see if the DataObj's are stored properly in the	// indexed view's internal list    IndexedDBView<DBView<Example> >		indexed_view(view,		"IndexTwoFields; STRING_VALUE, EXAMPLE_DATE; IndexLong; EXAMPLE_LONG",		UNBOUND, USE_ALL_FIELDS, cb_ptr_fun(SetParamsExample));   		vector<Example> filtered_results;	// the return value consists of a pair: 1. an iterator referring to the found items	// and 2. an iterator pointing to the end of the list of found items 	IndexedDBView<DBView<Example> >::indexed_pair		pr = indexed_view.equal_range(strVal, dateVal);	IndexedDBView<DBView<Example> >::indexed_iterator		idx_data_it = pr.first;	IndexedDBView<DBView<Example> >::indexed_iterator 		end_it = pr.second;	IndexedDBView<DBView<Example> >::indexed_iterator		find_it = indexed_view.find(strVal, dateVal);	if (idx_data_it == find_it)		cout << "Iterator integrity satisfied!" << endl;	// need to be able to iterate through found results	for ( ; idx_data_it != end_it; idx_data_it++)	{		// first * dereferences the iterator, returning a DataObj *		// second * dereferences the DataObj *, yielding a DataObj		Example &idx_data = *idx_data_it;		filtered_results.push_back(idx_data);	}	cout << filtered_results.size() << " results found!" << endl;	return filtered_results;}// test the insertion of Example objects into IndexedDBView using *unbound* modevoid TestUnboundInsert(){   	DBView<Example> view("DB_EXAMPLE", 		DefaultBCA<Example>(), "WHERE INT_VALUE BETWEEN (?) AND (?) AND "		"STRING_VALUE = (?) OR EXAMPLE_DATE <= (?) ORDER BY EXAMPLE_LONG",		BPAExampleObj());	// here, we are not too concerned about the indices themselves	// we're just testing to see if the DataObj's are stored properly in the	// indexed view's internal list    IndexedDBView<DBView<Example> >		indexed_view(view,		"Unique IndexLongDate; EXAMPLE_LONG, EXAMPLE_DATE; IndexString; STRING_VALUE;",		UNBOUND, USE_ALL_FIELDS, cb_ptr_fun(SetParamsExample));		// insert some Example objects into the indexed view	cout << "*** Size before inserts: " << indexed_view.size() << " ***" << endl;	const TIMESTAMP_STRUCT date1 = {1993, 2, 28, 0, 0, 0, 0};	const TIMESTAMP_STRUCT date2 = {1995, 7, 31, 0, 0, 0, 0};	const TIMESTAMP_STRUCT date3 = {1998, 11, 30, 0, 0, 0, 0};	pair<IndexedDBView<DBView<Example> >::iterator, bool> ins_pr;		ins_pr = indexed_view.insert(Example(459, "Unique String #1", 3.4, 1, date1));	cout << "insertion result = " << ins_pr.second << endl;	ins_pr = indexed_view.insert(Example(444, "Unique String #2", 23.45, 11, date2));	cout << "insertion result = " << ins_pr.second << endl;		ins_pr = indexed_view.insert(Example(411, "Unique String #3", 98.76, 11, date2));	cout << "insertion result = " << ins_pr.second << endl;		ins_pr = indexed_view.insert(Example(1323, "Example", 2.22, 11, date1));	cout << "insertion result = " << ins_pr.second << endl;	cout << "*** Size after inserts: " << indexed_view.size() << " ***" << endl;	// clear and refetch to prove we're in unbound mode	indexed_view.clear();	cout << "*** Size after refetching: " << indexed_view.size() << " ***" << endl;}void TestUnboundErase(){   	DBView<Example> view("DB_EXAMPLE", 		BCAExampleObj(), "WHERE INT_VALUE BETWEEN (?) AND (?) AND "		"STRING_VALUE = (?) OR EXAMPLE_DATE <= (?) ORDER BY EXAMPLE_LONG",		BPAExampleObj());    IndexedDBView<DBView<Example> >		indexed_view(view,		"IndexString; STRING_VALUE; IndexLongDate; EXAMPLE_LONG, EXAMPLE_DATE",		UNBOUND, USE_ALL_FIELDS, cb_ptr_fun(SetParamsExample));   		cout << "*** Size before erase calls: " << indexed_view.size() << " ***"		<< endl;	// the return value consists of a pair: 1. an iterator referring to the found items	// and 2. an iterator pointing to the end of the list of found items 	// we'll remove the DataObj's in this range	IndexedDBView<DBView<Example> >::indexed_pair 		pr = indexed_view.equal_range(string("Example"));	IndexedDBView<DBView<Example> >::indexed_iterator idxview_it = pr.first;		// remove the DataObj's in the range	while (idxview_it != pr.second)	{		// as iterator is invalidated upon an erase(), use a temporary iterator		// to point to DataObj to erase		// increment idxview_it before we erase so it will still be valid		// when we erase the DataObj		IndexedDBView<DBView<Example> >::indexed_iterator deleteMe = idxview_it;		idxview_it++;		indexed_view.erase(deleteMe);	}	cout << "*** Size after erase calls: " << indexed_view.size() << " ***"		<< endl;	// clear and refetch to prove we're in unbound mode	indexed_view.clear();	cout << "*** Size after refetching: " << indexed_view.size() << " ***" << endl;}// test the insertion of Example objects into IndexedDBView using *bound* modevoid TestBoundInsert(){   	DBView<Example> view("DB_EXAMPLE", 		DefaultBCA<Example>(), "WHERE INT_VALUE BETWEEN (?) AND (?) AND "		"STRING_VALUE = (?) OR EXAMPLE_DATE <= (?) ORDER BY EXAMPLE_LONG",		BPAExampleObj());	// here, we are not too concerned about the indices themselves	// we're just testing to see if the DataObj's are stored properly in the	// indexed view's internal list    IndexedDBView<DBView<Example> >		indexed_view(view,		"Unique IndexLongDate; EXAMPLE_LONG, EXAMPLE_DATE; IndexString; STRING_VALUE;",		BOUND, USE_ALL_FIELDS, cb_ptr_fun(SetParamsExample));		// insert some Example objects into the indexed view	cout << "*** Size before inserts: " << indexed_view.size() << " ***" << endl;	const TIMESTAMP_STRUCT date1 = {1993, 2, 28, 0, 0, 0, 0};	const TIMESTAMP_STRUCT date2 = {1995, 7, 31, 0, 0, 0, 0};	const TIMESTAMP_STRUCT date3 = {1998, 11, 30, 0, 0, 0, 0};	pair<IndexedDBView<DBView<Example> >::iterator, bool> ins_pr;		ins_pr = indexed_view.insert(Example(459, "Unique String #1", 3.4, 1, date1));	cout << "insertion result = " << ins_pr.second << endl;	ins_pr = indexed_view.insert(Example(444, "Unique String #2", 23.45, 4554, date2));	cout << "insertion result = " << ins_pr.second << endl;		ins_pr = indexed_view.insert(Example(411, "Unique String #3", 98.76, 888, date2));	cout << "insertion result = " << ins_pr.second << endl;		ins_pr = indexed_view.insert(Example(1323, "Example", 2.22, 1116, date1));	cout << "insertion result = " << ins_pr.second << endl;	cout << "*** Size after inserts: " << indexed_view.size() << " ***" << endl;	// clear and refetch to prove we're in bound mode	indexed_view.clear();	cout << "*** Size after refetching: " << indexed_view.size() << " ***" << endl;}// test the erasing of Example objects from the IndexedDBView using *bound* mode// using all fieldsvoid TestBoundEraseUAF(){   	DBView<Example> view("DB_EXAMPLE", 		BCAExampleObj(), "WHERE INT_VALUE BETWEEN (?) AND (?) AND "		"STRING_VALUE = (?) OR EXAMPLE_DATE <= (?) ORDER BY EXAMPLE_LONG",		BPAExampleObj());    IndexedDBView<DBView<Example> >		indexed_view(view,		"IndexString; STRING_VALUE; IndexLongDate; EXAMPLE_LONG, EXAMPLE_DATE",		BOUND, USE_ALL_FIELDS, cb_ptr_fun(SetParamsExample));   		cout << "*** Size before erase calls: " << indexed_view.size() << " ***"		<< endl;	// the return value consists of a pair: 1. an iterator referring to the found items	// and 2. an iterator pointing to the end of the list of found items 	// we'll remove the DataObj's in this range	IndexedDBView<DBView<Example> >::indexed_pair 		pr = indexed_view.equal_range(string("Example"));	IndexedDBView<DBView<Example> >::indexed_iterator idxview_it = pr.first;		// remove the DataObj's in the range	while (idxview_it != pr.second)	{		// as iterator is invalidated upon an erase(), use a temporary iterator		// to point to DataObj to erase		// increment idxview_it before we erase so it will still be valid		// when we erase the DataObj		IndexedDBView<DBView<Example> >::indexed_iterator deleteMe = idxview_it;

⌨️ 快捷键说明

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