I am trying to implement Buy in pset7. When I buy shares from different companies, the db updates ok. However, if I try to buy more shares for a company I already hold stock in, it does not update. I am assuming it has something to do with how I have set up the unique fields in the db. I created a composite index on the id and symbol fields and made it unique. In applications.py I check whether a user holds particular shares and then either insert or update a row. I set out what I think is the relevant code below. Any help would be greatly appreciated.
else: #check whether the user already holds these shares rows = db.execute("SELECT * FROM portfolio WHERE id =:id AND symbol = :symbol", id = session['user_id'], symbol = quote) #if shares already held, update holding if len(rows) != 0: portfolio = db.execute("UPDATE portfolio SET shares = shares + new_shares WHERE id = :id", id = session['user_id']) #if new holding, input relevant info in db else: portfolio = db.execute("INSERT INTO portfolio (id, symbol, shares, price) VALUES (:id, :symbol, :shares, :price)", id = session['user_id'], symbol = quote['symbol'], shares = new_shares, price = quote['price'])