When I try to update the users portfolio I receive a runtime error from passing in 'when' as date('now')
. Please can someone tell what I should be doing. Here is part of my buy function code.
# calculate total price
total = quote["price"]*amount
cash = db.execute("SELECT cash FROM users WHERE id = :id", id = session["user_id"])[0]["cash"]
# check if user has sufficient cash and update portfolio
if(cash >= total):
db.execute("INSERT INTO portfolio (id, price, number, symbol, when) VALUES (:id, :price, :number, :symbol, date('now'))", id = session["user_id"], price = quote["price"], number = amount, symbol = quote["symbol"])
db.execute("UPDATE users SETS cash = cash - :price WHERE id = :id", price = amount, id = session["user_id"])
else:
return apology("insufficient cash for chosen stock")
# Redirect user to home page
return redirect("/")
sqlite3 finance.db
, do.schema portfolio
). I think calling your first fieldid
is a bad choice, as this is anid
from tableusers
, souser_id
would be more appropriate.portfolio.id
as being misleading,users.id
is fine.