// Update objects in the database via an update_iterator
// using a dynamic view


class BPAParamObj
{
public:
	void operator()(BoundIOs &boundIOs, variant_row &paramObj)
	{
	  boundIOs[0] == paramObj._int();
	  boundIOs[1] == paramObj._int();
	  boundIOs[2] == paramObj._string();
	  boundIOs[3] == paramObj._timestamp();
	  boundIOs.BindVariantRow(paramObj);
	}

};


// update example rows (with new values) meeting a query in the database
// using a dynamic view
void UpdateDynamicData()
{ 
	// construct view
	DynamicDBView<variant_row>
	   view("DB_EXAMPLE", "*",
	   "WHERE INT_VALUE BETWEEN (?) AND (?) AND "
	   "STRING_VALUE = (?) OR EXAMPLE_DATE = (?)", BPAParamObj());

	// build an updater for the view

	// *** SQL Query Generated for this update_iterator:" ***
	// "UPDATE DB_EXAMPLE SET DOUBLE_VALUE = (?), EXAMPLE_DATE = (?), EXAMPLE_LONG = (?), INT_VALUE = (?), "
	// "STRING_VALUE = (?) WHERE INT_VALUE BETWEEN (?) AND (?) AND STRING_VALUE = (?) OR EXAMPLE_DATE = (?)"
	
	DynamicDBView<variant_row>::update_iterator exampleUpdater = view;

	// set data fields we want to update to their desired values
	variant_row updateMe(view.GetDataObj());

	updateMe["STRING_VALUE"] = string("Updated");
	updateMe["EXAMPLE_LONG"] = 25;

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

	updateMe["EXAMPLE_DATE"] = today;
	updateMe["INT_VALUE"] = 2121;

	updateMe["EXAMPLE_DOUBLE"] = 99.99;

	// now set the parameters indicating which rows
	// we want the update applied
	variant_row &params = exampleUpdater.Params();
	params[0] = 5;
	params[1] = 13;
	params[2] = string("Find Me");

	TIMESTAMP_STRUCT paramDate = {1999, 11, 11, 0,0, 0, 0};
	params[3] = paramDate;

	// execute the update
	*exampleUpdater = updateMe;
	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_DATE"] = tomorrow;
	updateMe["INT_VALUE"] = 2222;
	updateMe["STRING_VALUE"] = string("Second Update");
	updateMe["EXAMPLE_DOUBLE"] = 0.11111;
	updateMe["EXAMPLE_LONG"] = 66;
	
	// now set the parameters indicating which rows
	we want the update applied
	params[0] = 21;
	params[1] = 30;
	params[2] = string("To find");

	TIMESTAMP_STRUCT otherParamDate = {2001, 10, 31,0, 0, 0, 0};
	params[3] = otherParamDate;

	// execute the update
	*exampleUpdater = updateMe;
	exampleUpdater++;

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