Almost! You just have to collect the returned value (NOT TESTED):

row = wx_manager.getSql("SELECT windDir,pressure FROM %s WHERE windDir IS
NOT null ORDER BY dateTime DESC LIMIT 1" % wx_manager.archive)

print "Wind is ", row[0], "; pressure is ", row[1]


If you expect more than one row, you should use genSql:

result_set = wx_manager.genSql("SELECT windDir,pressure FROM %s WHERE
windDir IS NOT null ORDER BY dateTime DESC LIMIT 10" % wx_manager.archive)

for (row in result_set):

  print "Wind is ", row[0], "; pressure is ", row[1]


-tk

On Sat, Feb 17, 2018 at 8:56 AM, Tryphon Cosinus <tryphoncosi...@gmail.com>
wrote:

> Hello,
>
> I want to execute a SQL request on weewx.sdb inside a custom service
> engine.
>
> For example, I want to know the pressure the last time the wind direction
> was recorded as NOT NULL. The suitable SQL request is :
>
> SELECT windDir,pressure FROM archive WHERE windDir IS NOT null ORDER BY
> dateTime DESC LIMIT 1
>
> Parsing the customization guide, I feel I can follow The
> database/Programming interface section. Well, I do not know how to
> implement exactly what I need:
>
>
> wx_manager    = db_lookup()        # Get default binding
> # Sample query:
> wx_manager.getSql("SELECT windDir,pressure FROM %s WHERE windDir IS NOT null 
> ORDER BY dateTime DESC LIMIT 1" % wx_manager.archive)
>
>
>
> I do not know enough in Python to understand how to collect the SQL result
> i.e. the values of the fields winDir and pressure.
>
> Any idea?
>
> Thank you.
>
> --
> You received this message because you are subscribed to the Google Groups
> "weewx-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to weewx-user+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to weewx-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to