Listing 8

// Using the search class with boost::posix_time::ptime
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/posix_time/ptime.hpp>

using boost::posix_time::to_iso_string;
using boost::posix_time::ptime;
#include <string>
#include <dti/database.h>
using namespace dti::db;

struct Person
{
    std::string name_;
    int         age_;
    ptime       time_of_birth_;
    double      weight_;
    short       height_;

    BEGIN_DB_BINDING  
        DB_BIND_COLUMN_NAME( name_         , "Name"       )
        DB_BIND_COLUMN_NAME( age_          , "Age"        )
        DB_BIND_COLUMN_NAME( time_of_birth_, "TimeOfBirth" )
        DB_BIND_COLUMN_NAME( weight_       , "Weight"     )
        DB_BIND_COLUMN_NAME( height_       , "Height"     ) 
    END_DB_BINDING

    friend std::ostream& operator<<(std::ostream & os, const Person & r)
    {
        os << r.name_     << " " 
           << r.age_      << " " 
           << to_iso_string(r. time_of_birth_)  << " " 
           << r.weight_   << " "
           << r.height_   << " "
           ;
        return os;
    }
};
int main()
{
  try
  {
    database db("MyLife", "sa", "");
    { 
      search<Person> s(db, "Select * from Persons");
      std::copy( s, s.end(), std::ostream_iterator<Person>( std::cout, "\n" ) );
    }
  }
  catch(db_error & e)
  {
    std::cerr << e.what() << std::endl;
  }
}