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

📄 joinexample.cpp

📁 The goal of this library is to make ODBC recordsets look just like an STL container. As a user, you
💻 CPP
字号:
// join example data class ... note the class declaration is now free of any of these DB// abstractions// Initial: 9/5/2000 - MG// Reviewed: 11/12/2000 - CJ// Edited: 12/20/2000 - MG - added namespace support#include "JoinExample.h"using namespace dtl;void SetParamsJoinExample(JoinParamObj &params){	// assign paramteter values	params.intValue = 3;	params.strValue = "Join Example";	params.sampleInt = 1;	params.sampleStr = "Joined Tables";}// let's read some JoinExample objects from the database and return a vector of// the resultsvector<JoinExample> ReadJoinedData(){	vector<JoinExample> results;	// assume connection has been declared somewhere as:	// DBConnection conn("UID=txupz;PWD=txupz;DSN=posp;");	// construct view	// note here that we use a custom parameter object class for JoinExample	// rather than DefaultParamObj<JoinExample>	// we also use a custom SelValidate function here: IntValuePosSelValidate	DBView<JoinExample, JoinParamObj> view("DB_EXAMPLE, DB_SAMPLE", 		DefaultBCA<JoinExample>(),		"WHERE (INT_VALUE = (?) AND STRING_VALUE = (?)) AND "		"(SAMPLE_INT = (?) OR SAMPLE_STR = (?)) ORDER BY SAMPLE_LONG",		BPAJoinParamObj(), IntValuePosSelValidate());	// loop through query results and add them to our vector	// read_it.GetLastCount() records read in this loop	DBView<JoinExample, JoinParamObj>::select_iterator		read_it = view.begin();	// assign paramteter values	read_it.Params().intValue = 3;	read_it.Params().strValue = "Join Example";	read_it.Params().sampleInt = 1;	read_it.Params().sampleStr = "Joined Tables";	for ( ;  read_it != view.end();  read_it++)    {				// 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				cout << "Reading element #" << read_it.GetLastCount() << endl;		results.push_back(*read_it);		cout << *read_it << endl;	}	return results;}// read JoinExamples from indexed view to make sure data gets in IndexedDBView's// internal list<DataObj> properlyvector<JoinExample> ReadJoinedDataFromIndexedView(){	DBView<JoinExample, JoinParamObj>		view("DB_EXAMPLE, DB_SAMPLE", 		DefaultBCA<JoinExample>(),		"WHERE (INT_VALUE = (?) AND STRING_VALUE = (?)) AND "		"(SAMPLE_INT = (?) OR SAMPLE_STR = (?)) ORDER BY SAMPLE_LONG",		BPAJoinParamObj(), IntValuePosSelValidate());	// 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<JoinExample, JoinParamObj> > 		indexed_view(view, "IndexLong; SAMPLE_LONG", 		UNBOUND, USE_ALL_FIELDS, cb_ptr_fun(SetParamsJoinExample));	vector<JoinExample> results_from_indexed_view;	// populate results vector with the data from the indexed view	for (IndexedDBView<DBView<JoinExample, JoinParamObj> >::iterator 		    data_it = indexed_view.begin(); data_it != indexed_view.end(); data_it++)	{		results_from_indexed_view.push_back(*data_it);	}	cout << "*** IndexedDBView size is: " << results_from_indexed_view.size() << " ***" << endl; 	return results_from_indexed_view;}// read Examples from indexed view that have the given DataObj as (primary) keyvector<JoinExample> ReadJoinedFilteredDataPK(JoinExample &key){   	DBView<JoinExample, JoinParamObj>		view("DB_EXAMPLE, DB_SAMPLE", 		BCAJoinExampleObj(),		"WHERE (INT_VALUE = (?) AND STRING_VALUE = (?)) AND "		"(SAMPLE_INT = (?) OR SAMPLE_STR = (?)) ORDER BY SAMPLE_LONG",		BPAJoinParamObj(), IntValuePosSelValidate());	// 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<JoinExample, JoinParamObj> > 		indexed_view(view, "IndexLong; SAMPLE_LONG",		UNBOUND, USE_ALL_FIELDS, cb_ptr_fun(SetParamsJoinExample));	vector<JoinExample> 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<JoinExample, JoinParamObj> >::indexed_pair 		    pr = indexed_view.equal_range(key);	IndexedDBView<DBView<JoinExample, JoinParamObj> >::indexed_iterator		    idx_data_it = pr.first;	IndexedDBView<DBView<JoinExample, JoinParamObj> >::indexed_iterator			end_it = pr.second;	IndexedDBView<DBView<JoinExample, JoinParamObj> >::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		JoinExample &idx_data = *idx_data_it;		filtered_results.push_back(idx_data);	}	cout << filtered_results.size() << " results found!" << endl;	return filtered_results;}

⌨️ 快捷键说明

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