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

📄 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 页
字号:
	}	cout << "*** Size after erase calls: " << indexed_view.size() << " ***"		<< endl;	// Finally, insert a new item into the container	pair<DynamicIndexedDBView< DynamicDBView<> >::iterator, bool> ins_pr;	variant_row r(indexed_view.DataObj());	r["INT_VALUE"] = 459;	r["STRING_VALUE"] = string("Unique String #1");	r["DOUBLE_VALUE"] = 3.5;	r["EXAMPLE_LONG"] = 1;	r["EXAMPLE_DATE"] = date_criteria;	ins_pr = indexed_view.insert(r);	cout << "insertion succeded = " << (ins_pr.second == true ? "true": "false") << endl;}// Example of using an IndexDBView to read, insert and update recordsvoid IndexedViewExample(){   	DBView<Example> view("DB_EXAMPLE", 		BCAExampleObj(), "WHERE INT_VALUE BETWEEN (?) AND (?) OR "		"STRING_VALUE = (?) OR EXAMPLE_DATE <= (?) ORDER BY EXAMPLE_LONG",		BPAExampleObj());    IndexedDBView<DBView<Example> >		indexed_view(view,		"IndexString; STRING_VALUE; Unique IndexLongDate; EXAMPLE_LONG, EXAMPLE_DATE",		BOUND, USE_ALL_FIELDS, cb_ptr_fun(SetParamsExample));   		// Find the item where the STRING_VALUE matches the string "Foozle"	IndexedDBView<DBView<Example> >::indexed_iterator idxview_it = indexed_view.find(string("Foozle"));;		// Update the item with the key of "Foozle", to read "Fizzle" instead	if (idxview_it != indexed_view.end()) {		Example replacement;		replacement = *idxview_it;		replacement.exampleStr = "Fizzle";		indexed_view.replace(idxview_it, replacement);	}	// Now find a second set of items using the alternate index, IndexLongDate	// The STL convention for equal_range is that the return value consists of a pair:  	// 1. an iterator referring to the beginning of the list of found items	// and 2. an iterator pointing to the end of the list of found items 	// We will remove all DataObj's in this range	const TIMESTAMP_STRUCT date_criteria = {2000, 1, 1, 0, 0, 0, 0};	long long_criteria = 33;	IndexedDBView<DBView<Example> >::indexed_pair 		pr = indexed_view.equal_range_AK("IndexLongDate", long_criteria, date_criteria);	idxview_it = pr.first;	cout << "*** Size before erase calls: " << indexed_view.size() << " ***"		<< endl;		// Remove all DataObj that matched the criteria in our equal_range_AK lookup	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;	// Finally, insert a new item into the container	pair<IndexedDBView<DBView<Example> >::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;}// read Examples from indexed view to make sure data gets in IndexedDBView's// internal list<DataObj> properlyvector<Example> ReadDataFromIndexedView(){	//BCAExampleObj	//DefaultBCA<Example>, BCAExample	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,		"IndexString; STRING_VALUE; IndexLongDate; EXAMPLE_LONG, EXAMPLE_DATE",		UNBOUND, USE_ALL_FIELDS, cb_ptr_fun(SetParamsExample));   		vector<Example> results_from_indexed_view;	// populate results vector with the data from the indexed view	for (IndexedDBView<DBView<Example> >::iterator 			data_it = indexed_view.begin(); data_it != indexed_view.end(); data_it++)	{		results_from_indexed_view.push_back(*data_it);	}	cout << "*** IndexedDBView says size is: " << indexed_view.size() << " ***" << endl;	cout << "*** Results say size is: " << results_from_indexed_view.size() << " ***" << endl; 	// test instantiation of comparison operators	cout << "indexed_view == indexed_view " << (indexed_view == indexed_view) << endl;	cout << "indexed_view != indexed_view " << (indexed_view != indexed_view) << endl;	cout << "indexed_view <  indexed_view " << (indexed_view <  indexed_view) << endl;	cout << "indexed_view >  indexed_view " << (indexed_view >  indexed_view) << endl;	cout << "indexed_view <= indexed_view " << (indexed_view <= indexed_view) << endl;	cout << "indexed_view >= indexed_view " << (indexed_view >= indexed_view) << endl;	return results_from_indexed_view;}// read Examples from indexed view that have the given DataObj as (primary) keyvector<Example> ReadFilteredDataPK(Example &key){   	DBView<Example> view("DB_EXAMPLE", 		BCAExampleObj(), "WHERE INT_VALUE BETWEEN (?) AND (?) AND "		"STRING_VALUE = (?) OR EXAMPLE_DATE <= (?) ORDER BY EXAMPLE_LONG");	// 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; IndexLongDate; EXAMPLE_LONG, 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(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;}// read Example objects using the index IndexString by namevector<Example> ReadFilteredDataByName(Example &key){   	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> >		swap_test(view,		"IndexLongDate; EXAMPLE_LONG, EXAMPLE_DATE; IndexString; STRING_VALUE",		UNBOUND, USE_ALL_FIELDS, cb_ptr_fun(SetParamsExample));	IndexedDBView<DBView<Example> >		indexed_view;	indexed_view.swap(swap_test);   		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("IndexString", 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("IndexString", 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 << "Swap test!" << endl;	indexed_view.swap(swap_test);	pr = swap_test.equal_range_AK("IndexString", key);	idx_data_it = pr.first;	end_it = pr.second;	find_it = swap_test.find_AK("IndexString", key);		if (idx_data_it == find_it)		cout << "Iterator integrity satisfied!" << endl;	vector<Example> swap_results;	// 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;		swap_results.push_back(idx_data);	}	if (filtered_results == swap_results)		cout << "Swap test successful!!!!" << endl;	cout << filtered_results.size() << " results found!" << endl;	return filtered_results;}// read Example objects using the index IndexString by name, but using the// datafield rather than the objectvector<Example> ReadDataIdxByStrUseDF(const string &strVal){   	DBView<Example> view("DB_EXAMPLE", 		BCAExampleObj(), "WHERE INT_VALUE BETWEEN (?) AND (?) AND "		"STRING_VALUE = (?) OR EXAMPLE_DATE <= (?) ORDER BY EXAMPLE_LONG");	// 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; IndexLongDate; EXAMPLE_LONG, 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("IndexString", strVal);	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("IndexString", strVal);	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 string as a datafield value for the PK// using IndexString as PKvector<Example> ReadDataIdxByStrUseDFAndPK(const string &strVal){   	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,		"IndexString; STRING_VALUE; IndexLongDate; EXAMPLE_LONG, 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(strVal);	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);	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 string and date values as fields in a keyvector<Example> ReadTwoFieldKeyByNameDF(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());

⌨️ 快捷键说明

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