[odb-users] Native query error
Boris Kolpackov
boris at codesynthesis.com
Fri Sep 6 07:38:29 EDT 2013
Hi Gunjur,
Gunjur Munireddy Prashanth / LOKISA Smart Energy GmbH <GPrashanth at prosolartec.de> writes:
> I am using native sql query to get the average of a column and I get
> the average has 1.0000
>
> float avg = db->execute("SELECT AVG(mod_il2) FROM OddDay");
For SELECT the database::execute() function returns the number of
rows selected. You are expecting it to return the first column from
the first row.
To handle a query like this with ODB you will need to use a view.
For example:
#pragma db view query("SELECT AVG(mod_il2) FROM OddDay")
struct OddDay_mod_il2_avg
{
float value;
};
float avg = db->query<OddDay_mod_il2_avg> ().begin ()->value;
For more information on views, see Chapter 9, "Views" in the ODB Manual.
Boris
More information about the odb-users
mailing list