dtl
Category: iterators | Component type: type |
DBView<DataObj, ParamObj>::delete_iterator is an Output Iterator that performs the deletion of objects of type DataObj from a particular DBView (and thus the database). The actual DataObj that the delete_iterator references specifies the parameters of what DataObj's to delete from the database. To specify more parameters to refine the delete, define a ParamObj and BPA in the underlying DBView. The delete_iterator generates the following SQL statement to delete records from the database: "DELETE FROM " + tablename_from_view + " WHERE " + "<field1_from_BCA>=(?) AND <field2_from_BCA>=(?) AND ... " + posfix_clause_from_view. (But see BuildSpecialQry for how to override this.) The first set of parameters in the WHERE clause from the BCA will be automatically bound to fields in the DataObj. These parameters are set automatically upon assignment to the delete_iterator. Any additional parameters in the postfix clause will be bound to the ParamObj. Note that all of the restrictions of an Output Iterator must be obeyed, including the restrictions on the ordering of operator* and operator++ operations.
Defined in the delete_iterator.h header file.
// 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;
}
Parameter | Description | Default |
---|---|---|
DataObj | The type of object that will be updated in the DBView. This object will be bound through use of the BCA to the appropriate columns in the database. The set of value types of an DBView::update_iterator consists of a single type, DataObj. | |
ParamObj | The type of object that will be used to specify the postfix parameters to the DBView. | DefaultParamObj<DataObj> |
DataObj and ParamObj must each fulfill the following requirements:.
DB_iterator<DataObj, ParamObj>, iterator<output_iterator_tag, DataObj>
Member | Where defined | Description |
---|---|---|
DBView::delete_iterator() | delete_iterator | Default constructor. |
DBView::delete_iterator(DBView<DataObj, ParamObj> &view) | delete_iterator | See below. |
DBView::delete_iterator(const DBView::delete_iterator&) | Output Iterator | The copy constructor |
DBView::delete_iterator& operator=(const DBView delete_iterator&) | Output Iterator | The assignment operator |
DBView::delete_iterator& operator*(), DBView::delete_iterator& operator=(const DataObj &data) | Output Iterator | Proxy operators necessary to emulate *it = data. Return *this. |
DBView::delete_iterator& operator++() | Output Iterator | Preincrement. Deletes all DataObj's matching the parameters specified by the DataObj referenced by the iterator (and meeting the postfix clause). See Note [1]. |
const DBView::delete_iterator operator++(int) | Output Iterator | Preincrement. Deletes all DataObj's matching the parameters specified by the DataObj referenced by the iterator (and meeting the postfix clause). See Note [1]. |
void swap(DBView::delete_iterator &other) | DBView::delete_iterator | See below. |
These members are not defined in the Output Iterator requirements or in DB_iterator<DataObj, ParamObj>, but are specific to DBView::delete_iterator.
Function | Description |
---|---|
DBView::delete_iterator(DBView<DataObj, ParamObj> &view) | Creates an delete_iterator which refers to view. |
void swap(DBView::delete_iterator &other) | Swap *this with other. |
[1] operator++() is the operation that actually applies the delete to the database via the DBView. Each DBView::delete_iterator internally owns a DBStmt object which is allocated and prepared when the underlying ODBC statement handle is first needed and not before. The handle is not opened until absolutely needed in order to make copying and assigning these iterators an inexpensive operation. The DBStmt is executed once on each call to operator++(), whether the prefix or postfix version.
DB_iterator,
Output
Iterator, Input
Iterator.
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.