dtl
// Generate a simple structure to read data from a table called 'db_example'
// with five fields called 'int_value', 'string_value', 'double_value', 'example_long' and 'example_date'.
// Note: the macro must be invoked at namespace scope because templates are
// not allowed to take locally declared classes as template parameters.
// See [temp.arg.type] 14.3.1 in the C++ standard for details.
DTL_TABLE5(db_example,
int, int_value,
std::string, string_value,
double, double_value,
long, example_long,
jtime_c, example_date
);
//Note that the field names in the table are the same as the member names in the structure
vector<db_example_row> ReadData()
{
cout << "Read rows from the database: " << endl;
vector<db_example_row> results;
for (db_example_view::select_iterator read_it = db_example.begin();
read_it != db_example.end(); ++read_it)
{
cout << read_it->int_value << " "
<< read_it->string_value << " "
<< read_it->double_value << " "
<< read_it->example_long << " "
<< read_it->example_date
<< endl;
results.push_back(*read_it);
}
return results;
}
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.