[odb-users] Native query error

Gunjur Munireddy Prashanth / LOKISA Smart Energy GmbH GPrashanth at prosolartec.de
Fri Sep 6 08:48:40 EDT 2013


Hello Boris,

Thank you,
Sorry, I could not understand completely
Can you explain what this line does exactly

float avg = db->query<OddDay_mod_il2_avg> ().begin ()->value;

 

-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com] 
Sent: Freitag, 6. September 2013 13:38
To: Gunjur Munireddy Prashanth / LOKISA Smart Energy GmbH
Cc: odb-users at codesynthesis.com
Subject: Re: [odb-users] Native query error

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



-----
E-Mail ist virenfrei.
Von AVG überprüft - www.avg.de
Version: 2013.0.3392 / Virendatenbank: 3222/6641 - Ausgabedatum: 05.09.2013 



More information about the odb-users mailing list