[odb-users] Native query error

Boris Kolpackov boris at codesynthesis.com
Fri Sep 6 13:56:06 EDT 2013

Hi Gunjur,

Gunjur Munireddy Prashanth / LOKISA Smart Energy GmbH <GPrashanth at prosolartec.de> writes:

> Can you explain what this line does exactly
> float avg = db->query<OddDay_mod_il2_avg> ().begin ()->value;

Well, that's a shortcut for running a query, getting the result,
and then iterating over it. Here are these three steps performed

typedef odb::result<OddDay_mod_il2_avg> result;

result r = db->query<OddDay_mod_il2_avg> ();
result::iterator i (r.begin ());
float avg = i->value;

Because we know there will be exactly one element in the result
set, we can use the shortcut version I showed earlier. You can
read more about queries, result, etc., in Chapter 4, "Querying
the Database" in the ODB manual.


More information about the odb-users mailing list