dtl


// Using a DBView to insert rows into a database





// ... Class definitions for Example and BCAExample as per our ReadData example .....



// Specialization of DefaultInsValidate for Example

// This defines a business rule we wish to enforce for all 

// Example objects before they are allowed to be inserted into the database

template<> class dtl::DefaultInsValidate<Example> 

{

public:



	bool operator()(BoundIOs &boundIOs, Example &rowbuf) {	

		// data is valid if rowbuf.exampleStr is nonempty and

		// rowbuf.exampleDouble is 

		// between 0 and 100 (like a percentage)

		return (rowbuf.exampleStr.length() > 0 &&  rowbuf.exampleDouble >= 0.0 

			&& rowbuf.exampleLong  <= 100.0);

	}

};





// Insert rows from the vector<Example> parameter into the database

void WriteData(const vector<Example> &examples)

{

	DBView<Example> view("DB_EXAMPLE");

	DBView<Example>::insert_iterator write_it = view;



	// loop through vector and write Example objects to DB

	copy(examples.begin(), examples.end(), write_it);

}


[DTL Home]

Copyright © 2002, Michael Gradman and Corwin Joy.

Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appears in all copies and that both that copyright notice and this permission notice appear in supporting documentation. Corwin Joy and Michael Gradman make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.

SourceForge Logo

This site written using the ORB. [The ORB]