I created a refresh database button in my web/flask form, but when I try to refresh, I get this error message:
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The
current statement uses 0, and there are 1 supplied.
I tried all the various combinations in cursor.execute(query, (database,)) but I just couldn't figure out how to fix it...
#refresh portfolio stats
@app.route('/refresh', methods = ['GET','POST'])
def refresh():
if request.method == 'POST':
database = "data.sqlite"
connection = sql.connect(database)
query = ''' UPDATE
portfolio_table
SET
portfolio_cost_total = (SELECT SUM(product_cost_total)
FROM product_table)
WHERE
portfolio_table.portfolio_id = '1' '''
cursor = connection.cursor()
cursor.execute(query, (database,))
db.session.commit()
#df = pd.read_sql_query(query, connection)
#df.head()
return redirect(url_for('index'))
question from:
https://stackoverflow.com/questions/65839701/updating-a-table-with-a-sum-of-another-table-throws-incorrect-number-of-bindings 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…