I'm trying to put a negative integer into my sqlite database but it's not being inserted for some reason.
I get the error:
TypeError: can't multiply sequence by non-int of type 'float'
And when I checked with printing the value, I find that it's empty.
This is the command I use to insert to the table:
db.execute(
"INSERT INTO history (id,date,symbol,shares,price) VALUES (?,?,?,?,?)",
session["user_id"],
time,
request.form.get("symbol").upper(),
request.form.get("shares") * -1,
price,
)
request.form.get("shares") is a number input from a HTML form.
And I use this to make the table:
db.execute(
"CREATE TABLE history (id int, date varchar(255), symbol varchar(9), shares int, price int)"
)
I've tried surrounding request.form.get("shares") with an int() but it didn't work.
Positive integers work fine.
CodePudding user response:
The reason is exactly what the error is saying. The returned data from the request form is returning a non digit type. If you try doing
print(type(request.form.get("shares")
You can see the type of the result and work from there. What @Jack Deeth said in his answer will work. You can also always do the math before insert and declare as an int beforehand.
