dtl


DynamicIndexedDBView <DynamicView>

Category: containers Component type: type

Description

The DynamicIndexedDBView container is a refinement of IndexedDBView used for queries where the number and types of the fields in the query is unknown until runtime. DynamicIndexedDBView specializes the IndexedDBView template to use a variant_row object to hold rows from the query. The variant_row object provides a mechanism to hold an arbitrary number of fields with values of arbitrary types. Individual fields within the row are accessed by using methods from the variant_row object.

Refinement of

IndexedDBView.

Associated types

None, except for those defined by IndexedDBView.

Example:

// Using a DynamicIndexedDBView to read, update and insert records in a database.

// Dynamic IndexedDBView example

// ... classes as in IndexedDBView example  ....

void DynamicIndexedViewExample()
{
 DynamicDBView<ParamObjExample> dynamic_view("DB_EXAMPLE",
	 "INT_VALUE, STRING_VALUE, DOUBLE_VALUE, EXAMPLE_LONG,  EXAMPLE_DATE",
	 "WHERE INT_VALUE BETWEEN (?) AND (?) OR "
	  "STRING_VALUE = (?) OR EXAMPLE_DATE <= (?) ORDER BY EXAMPLE_LONG",
	  BPAExampleObj());

 DynamicIndexedDBView< DynamicDBView<ParamObjExample> >  
	 indexed_view(dynamic_view, 
         "UNIQUE PrimaryIndex; STRING_VALUE;"
         "IndexLongDate; EXAMPLE_LONG, EXAMPLE_DATE",
	 BOUND, USE_ALL_FIELDS, cb_ptr_fun(SetParamsExample));

 // Find the item where the STRING_VALUE matches the string  "Foozle"
 DynamicIndexedDBView< DynamicDBView<ParamObjExample> >::iterator idxview_it =  indexed_view.find(string("Foozle"));


 // Update the item with the key of "Foozle", to read  "Fizzle" instead
 if (idxview_it != indexed_view.end()) {
  variant_row replacement;
  replacement = *idxview_it;
  replacement["STRING_VALUE"] =   string("Fizzle");
  indexed_view.replace(idxview_it, replacement);
 }

 // Now find a second set of items using AlternateIndex
 // The STL convention for equal_range is to return a pair  consisting of: 
 // 1. an iterator referring to the beginning of the list of found  items
 // 2. an iterator pointing to the end of the list of found items. 
 // We will remove all items in this range.
 const TIMESTAMP_STRUCT date_criteria = {2000, 1, 1, 0, 0, 0, 0};
 long long_criteria = 33;
 pair<DynamicIndexedDBView<DynamicDBView<ParamObjExample> >::iterator,
	 DynamicIndexedDBView<DynamicDBView<ParamObjExample> >::iterator>
   	 pr = indexed_view.equal_range_AK("IndexLongDate", long_criteria, date_criteria);

 idxview_it = pr.first;

 cout <<  *** // Remove all rows that matched the criteria in our equal_range_AK lookup 
 while (idxview_it !="pr.second)" { 
   // as iterator is invalidated upon an erase(), use a temporary iterator 
   // to point to DataObj to erase 
   // increment idxview_it before we erase so it will still be valid 
   // when we erase the DataObj 
   DynamicIndexedDBView< DynamicDBView<ParamObjExample> >::iterator deleteMe = idxview_it; 
   idxview_it++; 
   indexed_view.erase(deleteMe); 
 } 
 cout << "*** Size after erase calls: " << indexed_view.size() << " ***" << endl; 
 
 // Finally, insert a new item into the container 
 pair<DynamicIndexedDBView< DynamicDBView<ParamObjExample> >::iterator, bool> ins_pr; 
 
 variant_row r(indexed_view.GetDataObj()); 
 r["INT_VALUE"]=459; 
 r["STRING_VALUE"]=string("Unique String #1"); 
 r["DOUBLE_VALUE"]=3.5; 
 r["EXAMPLE_LONG"]=1; 
 r["EXAMPLE_DATE"]=date_criteria; 
 ins_pr=indexed_view.insert(r);
 cout << "insertion succeded=" <<  (ins_pr.second == true ? " true": " false") << endl; 
}

Public base classes

IndexedDBView<DynamicView>

Template parameters

Parameter Description Default
DynamicView The type of the dynamic SQL view (usually a DynamicDBView instantiation which will be used as the underlying view for the DynamicIndexedDBView).  

 

Notation

X A type that is a model of DynamicIndexedDBView
a Object of type X
t Object of type X::value_type
p, q Object of type X::iterator

Expression semantics

Name Expression Precondition Semantics Postcondition
Main constructor
X a( 
 DynamicDBView<...> &view, 
 const string &IndexNamesAndFields,
 BoundMode bm = UNBOUND, 
 KeyMode km = USE_AUTO_KEY, 
 SetParamsFn IndexedDBViewParam = DefaultSetParams<ParamObj>()))
  This is exactly the same constructor as that used by IndexedDBView. The only difference is that the view passed in must be of type DynamicDBView rather than a regular DBView. See IndexedDBView for details on the constructor. See the Key Mode documentation for more details about the Key Mode setting. The size of the container is 0. Rows are operated on by obtaining the appropriate iterator from the container.
Main constructor accepting an arguments object. X a(Args args)   Same as above based on an arguments object. Construct as above, based on the arguments in the Args object. See the description of IndexedDBView::Args for more details.

Members

As per IndexedDBView with the following changes.

Member Where defined Description
X a( 
 DynamicDBView<...> &view, 
 const string &IndexNamesAndFields,
 BoundMode bm = UNBOUND, 
 KeyMode km = USE_AUTO_KEY, 
 SetParamsFn IndexedDBViewParam = DefaultSetParams<ParamObj>())
DynamicIndexedDBView Creates an DynamicIndexedDBView.
X a(Args args) DynamicIndexedDBView Same as above, but based on an arguments object.
X &operator=(const X &other)   Assignment operator.
void swap(X &other)   Swap *this with other.

See also

IndexedDBView, DynamicDBView, Associative Container, Multiple Associative Container, Unique Sorted Associative Container, Multiple Sorted Associative Container


[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