dtl


// Delete objects from the database via a delete_iterator

class Example
{
  public:                                // tablename.columnname:
	int exampleInt;                 // DB_EXAMPLE.INT_VALUE
	string exampleStr;              // DB_EXAMPLE.STRING_VALUE
	double exampleDouble;           // DB_EXAMPLE.DOUBLE_VALUE
	long exampleLong;               // DB_EXAMPLE.EXAMPLE_LONG
	TIMESTAMP_STRUCT exampleDate;   // DB_EXAMPLE.EXAMPLE_DATE

	Example(int exInt, const string &exStr, double exDouble, long exLong,
		const TIMESTAMP_STRUCT &exDate) :
	   exampleInt(exInt), exampleStr(exStr), exampleDouble(exDouble), exampleLong(exLong),
	   exampleDate(exDate)
	{ }

};

class BCAExampleObj
{
public:
	void operator()(BoundIOs &boundIOs, Example &rowbuf)
	{
		boundIOs["STRING_VALUE"] == rowbuf.exampleStr;
		boundIOs["EXAMPLE_DATE"] == rowbuf.exampleDate;
	}
};


// Delete rows matching the specified Example objects from the database
void DeleteData()
{
	// construct view
	DBView<Example>
	view("DB_EXAMPLE", BCAExampleObj());

	// build a deleter for the view

	// *** SQL Query Generated for this delete_iterator: ***
 	// "DELETE FROM DB_EXAMPLE WHERE EXAMPLE_DATE = (?) AND STRING_VALUE = (?) "
	
	DBView<Example>::delete_iterator exampleDeleter = view;

	Example deleteMe;

	// now set Example object indicating which rows we want to delete
	deleteMe.exampleStr = "Example";

	TIMESTAMP_STRUCT y2k = {2000, 1, 1, 0, 0, 0, 0};
	deleteMe.exampleDate = y2k;

	
	*exampleDeleter = deleteMe;

	// execute the delete
	exampleDeleter++;

	cout << exampleDeleter.GetLastCount() << " rows deleted!" << endl;

	// now can perform other deletes using the same delete iterator
	
	// now set Example object and params indicating which rows we want to delete

	TIMESTAMP_STRUCT today = {1999, 9, 29, 0, 0, 0, 0};
	*exampleDeleter = Example(3, "operator->()works", 0.0, 0, today);

	// execute the delete
	exampleDeleter++;

	cout << exampleDeleter.GetLastCount() << " rows deleted!" << endl;
}

[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.

This site written using the ORB. [The ORB]

1