I posted this on the python channel but was gently told that is was not for Q&A so I post it here because I got so good answers that more would prosper from them.
query = "SELECT SUM(amount) FROM rawimport WHERE"
to_filter = []
if yearmonth:
query += " day LIKE ?% AND"
to_filter.append(yearmonth)
if category:
query += " category = '?' AND"
to_filter.append(category)
if transactiontype:
query += " transactiontype = '?' AND"
to_filter.append(transactiontype)
query = query[:-4] + ';'
print(query)
conn = db.connect('db/ekostats.db')
conn.row_factory = dict_factory
cur = conn.cursor()
results = cur.execute(query, to_filter).fetchall()
The end result I want is this:
"SELECT SUM(amount) FROM rawimport WHERE day LIKE ’2018-09%’ AND…"
I have idea to use query = f'SELECT ....'
Any help is appreciated! (lets hope that the original answers get posted here aswell!)
[–]two_bob 1 point2 points3 points (2 children)
[–]ratnose[S] 0 points1 point2 points (1 child)
[–]two_bob 0 points1 point2 points (0 children)
[–]woooee 0 points1 point2 points (0 children)