Hi Pat,

Have a look at the genSql() method in the Manager class in manager.py (it's 
immediately below the getSql() method). It is essentially the same as your 
code but available through a single call. I guess it depends on your code, 
but if I prefer to use 'WeeWX API' calls where possible, protects you if 
things (in WeeWX) change in the future.

Gary


On Saturday, 4 August 2018 02:56:33 UTC+10, Pat O'Brien wrote:
>
> I ended up using some code from weecfg/database.py and it works. It feels 
> a bit like a hack (or I got lucky), and would love to clean it up if 
> there's a way? 
>
> Let me know
>
>
>         import weewx.manager
>
>         if 'StdArchive' in self.generator.config_dict:
>             db_binding = self.generator.config_dict['StdArchive'].get(
> 'data_binding','wx_binding')
>         else:
>             db_binding = 'wx_binding'
>         
>         dbm = weewx.manager.open_manager_with_config(self.generator.
> config_dict,db_binding)
>         _cursor = dbm.connection.cursor()
>         try:
>             for row in _cursor.execute(rain_data_sql):
>                 print row
>         finally:
>             _cursor.close()
>
>
> Thanks
>
>
>
> On Friday, August 3, 2018 at 12:03:02 PM UTC-4, Pat O'Brien wrote:
>>
>> I'm looking to get a bunch of rows from a getSql call in a search list 
>> extension so I can loop through the data, but the getSql is only returning 
>> 1 row. 
>>
>> Running this query on the database directly (this is tailored for 
>> sqlite), I get 214 rows returned
>>
>> SELECT strftime("%m %d, %Y", datetime(dateTime, "unixepoch")) as date, 
>> ROUND( sum, 2 ) FROM archive_day_rain WHERE strftime("%Y", datetime(
>> dateTime, "unixepoch")) = "2018"
>>
>> Running it using db_lookup().getSql with the query above, I only get 1 
>> row. 
>>
>> Any insight on how to get all 214 rows into the SLE so I can process it?
>>
>

Reply via email to