Select statements are the most commonly used SQL statements. This chapter shows you how you can make use of DAME to access the database using select statements. First of all we revisit the earlier example and modify it to get the value into a local variable. Then we will look into an example using a C++ class and initializing the class using DAME by accessing the data from database. We will look under the hood of the code generated by DAME to understand how best we can make use its capabilities. We will look into some examples where a select returns multiple records. We will also look at some standard containers and how DAME can be used along with these. Finally, we round-off this discussion with constructing a std::map object using DAME
In the previous example, we used a function to use the return value from our select statement to print the number of employees from the database. However, in real-life situations we might like to get the return value in to a variable and make use of the value at some other times. For the sake of clarity the code from the previous example is reproduced:
template<Iterator> GetEmployeeCount (Iterator it) ; edb.GetEmployeeCount (std::ptr_fun(&Print)) ;
For saving the information into a variable we need a object that can support operator() (int). The DAME utlity consists of an adapter named make_single that does exactly this.
#include <dame/utility.hpp> ... int count ; edb.GetEmployeeCount (Dame::make_single (&count)) ;