dtl




// example showing how to call aggregate functions such as count(*), sum(*)



class Aggregator

{

   int count;

   double sum;

};



void AggregateExample()

{



   // count # of records in table DB_EXAMPLE

   // and grab sum of the DOUBLE_VALUE column



   Aggregator rowbuf;

   DBView<Aggregator> view_agg("DB_EXAMPLE", BCA(rowbuf, 

      COLS["COUNT(*)"] >> rowbuf.count && 

      COLS["SUM(DOUBLE_VALUE)"] >> rowbuf.sum)

   );



   Aggregator result = *view_agg.begin();

   cout << "There are " << result.count << " records in DB_EXAMPLE" << endl;

   cout << "The sum of the DOUBLE_VALUE column is " << result.sum << 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.

SourceForge Logo

This site written using the ORB. [The ORB]