dtl


DBView<DataObj, ParamObj>::select_update_iterator

Category: iterators Component type: type

Description

DBView<DataObj, ParamObj>::select_update_iterator is an input/output iterator that allows you to read records from a DBView (Input Iterator) and update those same records using assignment to the iterator (Output Iterator). The select_update_iterator uses a select_iterator to march through the records in the view and then executes an update on the call to operator=(const DataObj &) if the contents of the row have been changed (note that this proxy operator=() is the only time the DataObj *can* change). The next record is read on operator++().

Definition

Defined in the select_update_iterator.h header file.

Example:





// example showing use of std::transform() with a select_update_iterator



// functor used in the transform example

class AddOneToExampleLong : public std::unary_function<Example, Example>

{

public:

	Example operator()(const Example &example)

	{

		Example result(example);

		result.exampleLong++;

		return result;

	}



};



// add one to the value of the exampleLong field for all rows in the table

void TransformSelectUpdate()

{

   DBView<Example> view("DB_EXAMPLE");



   DBView<Example>::select_update_iterator read_update_it = view.begin();

   std::transform(view.begin(), view.end(), read_update_it, AddOneToExampleLong());

}

Template parameters

Parameter Description Default
DataObj The type of object that will be written to 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::select_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> 

Model of

Input Iterator, Output Iterator

Type requirements

DataObj and ParamObj must each fulfill the following requirements:.

Public base classes

iterator<forward_iterator_tag, DataObj>

Members

Member Where defined Description
DBView::select_update_iterator() select_update_iterator Default constructor.
DBView::select_update_iterator(DBView<DataObj, ParamObj> &view) select_update_iterator Creates a select_update_iterator which refers to view.
DBView::select_update_iterator(const DBView::select_update_iterator&) Input Iterator, Output Iterator. The copy constructor.
DBView::select_update_iterator(const DBView::select_iterator&) select_update_iterator Conversion constructor from a read-only select_iterator.
DBView::select_update_iterator& operator=(const DBView::select_update_iterator&) Input Iterator, Output Iterator. The assignment operator.
DBView::select_update_iterator& operator=(const DataObj &dataObj) Output Iterator Proxy assignment. *it = dataObj will update the record with the new value of dataObj in the database.
DBView::select_update_iterator& operator*() Input Iterator, Output Iterator Dereferencing operator. Returns the iterator itself as a proxy which can be used both for input and output. The expression dataObj = *it will assign the value of the current row into dataObj. *it = dataObj will update the record referred to with the new value dataObj.
operator DataObj() select_update_iterator Conversion operator invoked implicitly by select_update_iterator::operator*() when reading objects from the view.
DBView::select_update_iterator& operator++() Input Iterator, Output Iterator Preincrement. Reads the next row from the DBView.
DataObjPtr operator++(int) Input Iterator, Output Iterator Postincrement. Reads the next row from the DBView. Returns a proxy in order to remember the DataObj for future dereference operations in the same expression
friend bool operator==(const DBView::select_update_iterator &i1, const DBView::select_update_iterator &i2) Input Iterator Returns whether the two iterators are equal, that is, do they refer to the same DataObj?
friend bool operator!=(const DBView::select_update_iterator &i1, const DBView::select_update_iterator &i2) Input Iterator Returns whether the two iterators are not equal. Equivalent to !(i1 == i2).
void swap(DBView::select_update_iterator &other) select_update_iterator Swap *this with other.
void SetKey(const string &KeyFields) select_update_iterator Set the list of fields which represents the key for the row. All rows which match the key fields for the old value of the row get updated if the iterator is assigned a new value. (i.e. typical output iterator behaviour *output_iterator = new_value; output_iterator++; In this case assignment triggers an update operation against the database. ) KeyFields is a comma separated list of the key fields that the iterator is to use when updating the table: "field1, field2, ..., fieldN". If this function is not called on the select_update_iterator, then the select_update_iterator will attempt to automatically determine a unique identifier for rows in the table using the autokeys functionality. See Key Mode for more details.

See also

select_iterator, update_iterator, Output Iterator, Input Iterator.


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