Issue
Python, PySide, SQLite:
Im probably missing something obvious, but im getting different results with the same (or so i thought) query. I Should be seeing the results of the non-prepared query (afaik).
Thank you for any and all help!
prepared:
filteringCategory = "store"
from_date = '2014-03-01'
to_date = '2014-03-29'
query.prepare("SELECT s.name AS store, SUM(price) AS total_price FROM expenses AS e JOIN expenses_to_store AS ets ON e.expenses_id = ets.expenses_id JOIN store AS s ON ets.store_id = s.store_id WHERE date BETWEEN :from_date AND :to_date GROUP BY :group")
query.bindValue(":from_date", from_date)
query.bindValue(":to_date", to_date)
query.bindValue(":group", filteringCategory)
query.exec_()
non-prepared:
query.exec_("SELECT price, s.name AS store, SUM(price) AS total_price FROM expenses AS e JOIN expenses_to_store AS ets ON e.expenses_id = ets.expenses_id JOIN store AS s ON ets.store_id = s.store_id WHERE date BETWEEN '2014-03-01' AND '2014-03-29' GROUP BY store")
Solution
The problem could be the line:
query.bindValue(":group", filteringCategory)
which is attempting to bind a parameter which is not a value. I don't think binding column or table names is allowed, because that would change the actual structure of the SQL statement.
Instead, you would need to do something like:
"SELECT ... :from_date AND :to_date GROUP BY %s" % filteringCategory
Answered By - ekhumoro
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.