Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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...

What I have tried:

Python
 #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'))
Posted
Updated 21-Jan-21 18:42pm

1 solution

This code has no parameters and therefore if you're getting that error, its not from here.

Although I dont see you constructing this object

cursor.execute(query, (database,))


So I wonder if it existed before and had a parameter added elsewhere?
 
Share this answer
 
v2
Comments
pythonHumanBot 22-Jan-21 8:04am    
ok, I changed the last part to:
cursor = connection.cursor()
cursor.execute(query)
db.session.commit()

So, now no error but the database doesn't update

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900