0

RuntimeError: too many statements at once

I am getting the above error message while trying to implement buy.

@login_required def index(): return apology("Login Required") @app.route("/buy", methods=["GET", "POST"]) @login_required def buy(): """Buy shares of stock.""" if request.method == "GET": return render_template("buyform.html")

else:
    if not request.form.get("stock"):
        return apology("must provide stock symbol")

    elif not request.form.get("nshares"):
        return apology("must provide no. of shares you would like to purchase")

    elif lookup(request.form.get("stock")) == None:
        return apology("Invalid Stock")

    else:
        username = db.execute("SELECT username FROM users where id = :id1", id1 = session["user_id"])[0]["username"]
        sharep = (lookup(request.form.get("stock"))['price'])
        nshares = request.form.get("nshares")
        cashr = sharep*float(nshares)
        cash = db.execute("SELECT cash FROM users where id = :id1", id1 = session["user_id"])[0]["cash"]
        name = (lookup(request.form.get("stock"))['name'])
        symbol = request.form.get("stock")
        if cash >= cashr:
            balance = cash - cashr
            db.execute("INSERT INTO history (username, name, symbol, sharep, nshares, total, balance, type) VALUES(:username, :name; :symbol, :sharep, :nshares, :total, :balance, 'BOUGHT')", username = username, name = name, symbol = symbol, sharep = sharep, nshares = nshares, total = cashr, balance = balance)
            db.execute("UPDATE users SET cash = :cash where id = :id1", cash = balance, id1 = session["user_id"])
            rows = db.execute("SELECT * FROM portfolio WHERE username = :username AND symbol = :symbol", username=username, symbol = symbol)
            if len(rows) == 1:
                existing = db.execute("SELECT shares FROM portfolio where username = :username AND symbol = :symbol", username=username, symbol = symbol)[0]["shares"]
                db.execute("UPDATE portfolio SET shares = :shares where username = :username AND symbol = :symbol", shares = existing+nshares, username=username, symbol = symbol)
            else:
                db.execute("INSERT INTO portfolio (username, name, symbol, shares) VALUES(:username, :name, :symbol, :shares)", username = username, name = name, symbol = symbol, shares = nshares)

            return apology ("Bought")    #tmeporary

        else:
            return apology("You can't afford")
1
  • Add the full runtime error. What function generates the error?
    – ChrisG
    Commented Jul 22, 2017 at 12:31

1 Answer 1

1

Just a small typo here :name;. Easy to miss, hard to find. (; is the sql delimiter, so "it" thinks you are trying to run 2 sqls).

3
  • Damn!! You're good. Thanks a lot!! You made my day!! Commented Jul 25, 2017 at 7:49
  • You're welcome. Now you can make my day; read this Commented Jul 25, 2017 at 11:14
  • Wow and they still didn't mark your answer right.... Commented Jun 26, 2020 at 1:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .